update_engine: Use clock and fake clock from SystemState

No need to pass clock and fake clock anywhere anymore. This CL makes it
to just use those objects available from SystemState and
FakeSystemState.

BUG=b:171829801
TEST=cros_workon_make --board reef --test update_engine

Change-Id: I9a3cf6dd2057620c11b862d3317b83489c76f3ca
Reviewed-on: https://chromium-review.googlesource.com/c/aosp/platform/system/update_engine/+/2546625
Tested-by: Amin Hassani <ahassani@chromium.org>
Reviewed-by: Jae Hoon Kim <kimjae@chromium.org>
Commit-Queue: Jae Hoon Kim <kimjae@chromium.org>
diff --git a/cros/common_service.cc b/cros/common_service.cc
index 0318999..df63bca 100644
--- a/cros/common_service.cc
+++ b/cros/common_service.cc
@@ -26,7 +26,6 @@
 #include <brillo/strings/string_utils.h>
 #include <policy/device_policy.h>
 
-#include "update_engine/common/clock_interface.h"
 #include "update_engine/common/hardware_interface.h"
 #include "update_engine/common/prefs.h"
 #include "update_engine/common/system_state.h"
@@ -379,7 +378,7 @@
     return false;
   }
 
-  ClockInterface* clock = SystemState::Get()->clock();
+  const auto* clock = SystemState::Get()->clock();
   *out_usec_wallclock = (clock->GetBootTime() - time).InMicroseconds();
   return true;
 }
diff --git a/cros/fake_system_state.cc b/cros/fake_system_state.cc
index 81fa957..e0206f5 100644
--- a/cros/fake_system_state.cc
+++ b/cros/fake_system_state.cc
@@ -22,8 +22,6 @@
 // OOBE is completed even when there's no such marker file, etc.
 FakeSystemState::FakeSystemState()
     : mock_update_attempter_(nullptr),
-      mock_request_params_(),
-      fake_update_manager_(&fake_clock_),
       clock_(&fake_clock_),
       connection_manager_(&mock_connection_manager_),
       hardware_(&fake_hardware_),
diff --git a/cros/metrics_reporter_omaha.cc b/cros/metrics_reporter_omaha.cc
index 65093a1..22c0aa9 100644
--- a/cros/metrics_reporter_omaha.cc
+++ b/cros/metrics_reporter_omaha.cc
@@ -22,7 +22,6 @@
 #include <base/strings/string_number_conversions.h>
 #include <metrics/metrics_library.h>
 
-#include "update_engine/common/clock_interface.h"
 #include "update_engine/common/constants.h"
 #include "update_engine/common/prefs_interface.h"
 #include "update_engine/common/system_state.h"
diff --git a/cros/metrics_reporter_omaha_unittest.cc b/cros/metrics_reporter_omaha_unittest.cc
index b161137..c5cfece 100644
--- a/cros/metrics_reporter_omaha_unittest.cc
+++ b/cros/metrics_reporter_omaha_unittest.cc
@@ -41,12 +41,15 @@
   // Reset the metrics_lib_ to a mock library.
   void SetUp() override {
     FakeSystemState::CreateInstance();
+    fake_clock_ = FakeSystemState::Get()->fake_clock();
     mock_metrics_lib_ = new testing::NiceMock<MetricsLibraryMock>();
     reporter_.metrics_lib_.reset(mock_metrics_lib_);
   }
 
   testing::NiceMock<MetricsLibraryMock>* mock_metrics_lib_;
   MetricsReporterOmaha reporter_;
+
+  FakeClock* fake_clock_;
 };
 
 TEST_F(MetricsReporterOmahaTest, ReportDailyMetrics) {
@@ -59,14 +62,12 @@
 }
 
 TEST_F(MetricsReporterOmahaTest, ReportUpdateCheckMetrics) {
-  FakeClock fake_clock;
   FakePrefs fake_prefs;
 
   // We need to execute the report twice to test the time since last report.
-  FakeSystemState::Get()->set_clock(&fake_clock);
   FakeSystemState::Get()->set_prefs(&fake_prefs);
-  fake_clock.SetWallclockTime(base::Time::FromInternalValue(1000000));
-  fake_clock.SetMonotonicTime(base::Time::FromInternalValue(1000000));
+  fake_clock_->SetWallclockTime(base::Time::FromInternalValue(1000000));
+  fake_clock_->SetMonotonicTime(base::Time::FromInternalValue(1000000));
 
   metrics::CheckResult result = metrics::CheckResult::kUpdateAvailable;
   metrics::CheckReaction reaction = metrics::CheckReaction::kIgnored;
@@ -107,8 +108,8 @@
   reporter_.ReportUpdateCheckMetrics(result, reaction, error_code);
 
   // Advance the clock by 1 minute and report the same metrics again.
-  fake_clock.SetWallclockTime(base::Time::FromInternalValue(61000000));
-  fake_clock.SetMonotonicTime(base::Time::FromInternalValue(61000000));
+  fake_clock_->SetWallclockTime(base::Time::FromInternalValue(61000000));
+  fake_clock_->SetMonotonicTime(base::Time::FromInternalValue(61000000));
   // Allow rollback
   reporter_.ReportUpdateCheckMetrics(result, reaction, error_code);
 }
@@ -175,12 +176,10 @@
 }
 
 TEST_F(MetricsReporterOmahaTest, ReportUpdateAttemptMetrics) {
-  FakeClock fake_clock;
   FakePrefs fake_prefs;
-  FakeSystemState::Get()->set_clock(&fake_clock);
   FakeSystemState::Get()->set_prefs(&fake_prefs);
-  fake_clock.SetWallclockTime(base::Time::FromInternalValue(1000000));
-  fake_clock.SetMonotonicTime(base::Time::FromInternalValue(1000000));
+  fake_clock_->SetWallclockTime(base::Time::FromInternalValue(1000000));
+  fake_clock_->SetMonotonicTime(base::Time::FromInternalValue(1000000));
 
   int attempt_number = 1;
   PayloadType payload_type = kPayloadTypeFull;
@@ -251,8 +250,8 @@
                                        internal_error_code);
 
   // Advance the clock by 1 minute and report the same metrics again.
-  fake_clock.SetWallclockTime(base::Time::FromInternalValue(61000000));
-  fake_clock.SetMonotonicTime(base::Time::FromInternalValue(61000000));
+  fake_clock_->SetWallclockTime(base::Time::FromInternalValue(61000000));
+  fake_clock_->SetMonotonicTime(base::Time::FromInternalValue(61000000));
   reporter_.ReportUpdateAttemptMetrics(attempt_number,
                                        payload_type,
                                        duration,
@@ -527,16 +526,14 @@
 }
 
 TEST_F(MetricsReporterOmahaTest, WallclockDurationHelper) {
-  FakeClock fake_clock;
   base::TimeDelta duration;
   const std::string state_variable_key = "test-prefs";
   FakePrefs fake_prefs;
 
-  FakeSystemState::Get()->set_clock(&fake_clock);
   FakeSystemState::Get()->set_prefs(&fake_prefs);
 
   // Initialize wallclock to 1 sec.
-  fake_clock.SetWallclockTime(base::Time::FromInternalValue(1000000));
+  fake_clock_->SetWallclockTime(base::Time::FromInternalValue(1000000));
 
   // First time called so no previous measurement available.
   EXPECT_FALSE(
@@ -555,14 +552,14 @@
 
   // Advance the clock one second, then we should get 1 sec on the
   // next call and 0 sec on the subsequent call.
-  fake_clock.SetWallclockTime(base::Time::FromInternalValue(2000000));
+  fake_clock_->SetWallclockTime(base::Time::FromInternalValue(2000000));
   EXPECT_TRUE(reporter_.WallclockDurationHelper(state_variable_key, &duration));
   EXPECT_EQ(duration.InSeconds(), 1);
   EXPECT_TRUE(reporter_.WallclockDurationHelper(state_variable_key, &duration));
   EXPECT_EQ(duration.InSeconds(), 0);
 
   // Advance clock two seconds and we should get 2 sec and then 0 sec.
-  fake_clock.SetWallclockTime(base::Time::FromInternalValue(4000000));
+  fake_clock_->SetWallclockTime(base::Time::FromInternalValue(4000000));
   EXPECT_TRUE(reporter_.WallclockDurationHelper(state_variable_key, &duration));
   EXPECT_EQ(duration.InSeconds(), 2);
   EXPECT_TRUE(reporter_.WallclockDurationHelper(state_variable_key, &duration));
@@ -571,23 +568,20 @@
   // There's a possibility that the wallclock can go backwards (NTP
   // adjustments, for example) so check that we properly handle this
   // case.
-  fake_clock.SetWallclockTime(base::Time::FromInternalValue(3000000));
+  fake_clock_->SetWallclockTime(base::Time::FromInternalValue(3000000));
   EXPECT_FALSE(
       reporter_.WallclockDurationHelper(state_variable_key, &duration));
-  fake_clock.SetWallclockTime(base::Time::FromInternalValue(4000000));
+  fake_clock_->SetWallclockTime(base::Time::FromInternalValue(4000000));
   EXPECT_TRUE(reporter_.WallclockDurationHelper(state_variable_key, &duration));
   EXPECT_EQ(duration.InSeconds(), 1);
 }
 
 TEST_F(MetricsReporterOmahaTest, MonotonicDurationHelper) {
   int64_t storage = 0;
-  FakeClock fake_clock;
   base::TimeDelta duration;
 
-  FakeSystemState::Get()->set_clock(&fake_clock);
-
   // Initialize monotonic clock to 1 sec.
-  fake_clock.SetMonotonicTime(base::Time::FromInternalValue(1000000));
+  fake_clock_->SetMonotonicTime(base::Time::FromInternalValue(1000000));
 
   // First time called so no previous measurement available.
   EXPECT_FALSE(reporter_.MonotonicDurationHelper(&storage, &duration));
@@ -605,14 +599,14 @@
 
   // Advance the clock one second, then we should get 1 sec on the
   // next call and 0 sec on the subsequent call.
-  fake_clock.SetMonotonicTime(base::Time::FromInternalValue(2000000));
+  fake_clock_->SetMonotonicTime(base::Time::FromInternalValue(2000000));
   EXPECT_TRUE(reporter_.MonotonicDurationHelper(&storage, &duration));
   EXPECT_EQ(duration.InSeconds(), 1);
   EXPECT_TRUE(reporter_.MonotonicDurationHelper(&storage, &duration));
   EXPECT_EQ(duration.InSeconds(), 0);
 
   // Advance clock two seconds and we should get 2 sec and then 0 sec.
-  fake_clock.SetMonotonicTime(base::Time::FromInternalValue(4000000));
+  fake_clock_->SetMonotonicTime(base::Time::FromInternalValue(4000000));
   EXPECT_TRUE(reporter_.MonotonicDurationHelper(&storage, &duration));
   EXPECT_EQ(duration.InSeconds(), 2);
   EXPECT_TRUE(reporter_.MonotonicDurationHelper(&storage, &duration));
diff --git a/cros/omaha_response_handler_action_unittest.cc b/cros/omaha_response_handler_action_unittest.cc
index 8750724..3de351d 100644
--- a/cros/omaha_response_handler_action_unittest.cc
+++ b/cros/omaha_response_handler_action_unittest.cc
@@ -993,8 +993,7 @@
                          .app_id = kPayloadAppId,
                          .fp = kPayloadFp1});
   // Setup the UpdateManager to disallow the update.
-  FakeClock fake_clock;
-  MockPolicy* mock_policy = new MockPolicy(&fake_clock);
+  MockPolicy* mock_policy = new MockPolicy();
   FakeUpdateManager* fake_update_manager =
       FakeSystemState::Get()->fake_update_manager();
   fake_update_manager->set_policy(mock_policy);
diff --git a/cros/p2p_manager.cc b/cros/p2p_manager.cc
index dc12b35..19e2600 100644
--- a/cros/p2p_manager.cc
+++ b/cros/p2p_manager.cc
@@ -51,6 +51,7 @@
 #include <base/strings/stringprintf.h>
 
 #include "update_engine/common/subprocess.h"
+#include "update_engine/common/system_state.h"
 #include "update_engine/common/utils.h"
 #include "update_engine/update_manager/policy.h"
 #include "update_engine/update_manager/update_manager.h"
@@ -115,7 +116,6 @@
 class P2PManagerImpl : public P2PManager {
  public:
   P2PManagerImpl(Configuration* configuration,
-                 ClockInterface* clock,
                  UpdateManager* update_manager,
                  const string& file_extension,
                  const int num_files_to_keep,
@@ -170,9 +170,6 @@
   // Configuration object.
   unique_ptr<Configuration> configuration_;
 
-  // Object for telling the time.
-  ClockInterface* clock_;
-
   // A pointer to the global Update Manager.
   UpdateManager* update_manager_;
 
@@ -211,13 +208,11 @@
 const char P2PManagerImpl::kTmpExtension[] = ".tmp";
 
 P2PManagerImpl::P2PManagerImpl(Configuration* configuration,
-                               ClockInterface* clock,
                                UpdateManager* update_manager,
                                const string& file_extension,
                                const int num_files_to_keep,
                                const TimeDelta& max_file_age)
-    : clock_(clock),
-      update_manager_(update_manager),
+    : update_manager_(update_manager),
       file_extension_(file_extension),
       num_files_to_keep_(num_files_to_keep),
       max_file_age_(max_file_age) {
@@ -344,8 +339,9 @@
     // If instructed to keep only files younger than a given age
     // (|max_file_age_| != 0), delete files satisfying this criteria
     // right now. Otherwise add it to a list we'll consider for later.
-    if (clock_ != nullptr && max_file_age_ != TimeDelta() &&
-        clock_->GetWallclockTime() - time > max_file_age_) {
+    if (max_file_age_ != TimeDelta() &&
+        SystemState::Get()->clock()->GetWallclockTime() - time >
+            max_file_age_) {
       if (!DeleteP2PFile(name, "file too old"))
         deletion_failed = true;
     } else {
@@ -722,13 +718,11 @@
 }
 
 P2PManager* P2PManager::Construct(Configuration* configuration,
-                                  ClockInterface* clock,
                                   UpdateManager* update_manager,
                                   const string& file_extension,
                                   const int num_files_to_keep,
                                   const TimeDelta& max_file_age) {
   return new P2PManagerImpl(configuration,
-                            clock,
                             update_manager,
                             file_extension,
                             num_files_to_keep,
diff --git a/cros/p2p_manager.h b/cros/p2p_manager.h
index bd359fa..bef7806 100644
--- a/cros/p2p_manager.h
+++ b/cros/p2p_manager.h
@@ -27,7 +27,6 @@
 #include <policy/device_policy.h>
 #include <policy/libpolicy.h>
 
-#include "update_engine/common/clock_interface.h"
 #include "update_engine/common/prefs_interface.h"
 #include "update_engine/update_manager/update_manager.h"
 
@@ -174,7 +173,6 @@
   // performing housekeeping (pass zero to allow files of any age).
   static P2PManager* Construct(
       Configuration* configuration,
-      ClockInterface* clock,
       chromeos_update_manager::UpdateManager* update_manager,
       const std::string& file_extension,
       const int num_files_to_keep,
diff --git a/cros/p2p_manager_unittest.cc b/cros/p2p_manager_unittest.cc
index 8b6d741..b66b08c 100644
--- a/cros/p2p_manager_unittest.cc
+++ b/cros/p2p_manager_unittest.cc
@@ -46,12 +46,12 @@
 #include <policy/libpolicy.h>
 #include <policy/mock_device_policy.h>
 
-#include "update_engine/common/fake_clock.h"
 #include "update_engine/common/prefs.h"
 #include "update_engine/common/subprocess.h"
 #include "update_engine/common/test_utils.h"
 #include "update_engine/common/utils.h"
 #include "update_engine/cros/fake_p2p_manager_configuration.h"
+#include "update_engine/cros/fake_system_state.h"
 #include "update_engine/update_manager/fake_update_manager.h"
 #include "update_engine/update_manager/mock_policy.h"
 
@@ -72,12 +72,13 @@
 // done.
 class P2PManagerTest : public testing::Test {
  protected:
-  P2PManagerTest() : fake_um_(&fake_clock_) {}
-  ~P2PManagerTest() override {}
+  P2PManagerTest() = default;
+  ~P2PManagerTest() override = default;
 
   // Derived from testing::Test.
   void SetUp() override {
     loop_.SetAsCurrent();
+    FakeSystemState::CreateInstance();
     async_signal_handler_.Init();
     subprocess_.Init(&async_signal_handler_);
     test_conf_ = new FakeP2PManagerConfiguration();
@@ -85,12 +86,11 @@
     // Allocate and install a mock policy implementation in the fake Update
     // Manager.  Note that the FakeUpdateManager takes ownership of the policy
     // object.
-    mock_policy_ = new chromeos_update_manager::MockPolicy(&fake_clock_);
+    mock_policy_ = new chromeos_update_manager::MockPolicy();
     fake_um_.set_policy(mock_policy_);
 
     // Construct the P2P manager under test.
     manager_.reset(P2PManager::Construct(test_conf_,
-                                         &fake_clock_,
                                          &fake_um_,
                                          "cros_au",
                                          3,
@@ -110,7 +110,6 @@
   // The P2PManager::Configuration instance used for testing.
   FakeP2PManagerConfiguration* test_conf_;
 
-  FakeClock fake_clock_;
   chromeos_update_manager::MockPolicy* mock_policy_ = nullptr;
   chromeos_update_manager::FakeUpdateManager fake_um_;
 
@@ -149,7 +148,6 @@
   // will be freed.
   test_conf_ = new FakeP2PManagerConfiguration();
   manager_.reset(P2PManager::Construct(test_conf_,
-                                       &fake_clock_,
                                        &fake_um_,
                                        "cros_au",
                                        3,
@@ -207,14 +205,14 @@
 
   // Set the clock just so files with a timestamp before |cutoff_time|
   // will be deleted at housekeeping.
-  fake_clock_.SetWallclockTime(cutoff_time + age_limit);
+  FakeSystemState::Get()->fake_clock()->SetWallclockTime(cutoff_time +
+                                                         age_limit);
 
   // Specifically pass 0 for |num_files_to_keep| to allow any number of files.
   // Note that we need to reallocate the test_conf_ member, whose currently
   // aliased object will be freed.
   test_conf_ = new FakeP2PManagerConfiguration();
   manager_.reset(P2PManager::Construct(test_conf_,
-                                       &fake_clock_,
                                        &fake_um_,
                                        "cros_au",
                                        0 /* num_files_to_keep */,
diff --git a/cros/payload_state.cc b/cros/payload_state.cc
index d7de6e6..028e8fa 100644
--- a/cros/payload_state.cc
+++ b/cros/payload_state.cc
@@ -196,7 +196,7 @@
 
   attempt_type_ = attempt_type;
 
-  ClockInterface* clock = SystemState::Get()->clock();
+  const auto* clock = SystemState::Get()->clock();
   attempt_start_time_boot_ = clock->GetBootTime();
   attempt_start_time_monotonic_ = clock->GetMonotonicTime();
   attempt_num_bytes_downloaded_ = 0;
@@ -628,7 +628,7 @@
 
   int64_t payload_bytes_downloaded = attempt_num_bytes_downloaded_;
 
-  ClockInterface* clock = SystemState::Get()->clock();
+  const auto* clock = SystemState::Get()->clock();
   TimeDelta duration = clock->GetBootTime() - attempt_start_time_boot_;
   TimeDelta duration_uptime =
       clock->GetMonotonicTime() - attempt_start_time_monotonic_;
diff --git a/cros/payload_state_unittest.cc b/cros/payload_state_unittest.cc
index edcb9d6..9370a02 100644
--- a/cros/payload_state_unittest.cc
+++ b/cros/payload_state_unittest.cc
@@ -24,7 +24,6 @@
 
 #include "update_engine/common/constants.h"
 #include "update_engine/common/excluder_interface.h"
-#include "update_engine/common/fake_clock.h"
 #include "update_engine/common/fake_hardware.h"
 #include "update_engine/common/fake_prefs.h"
 #include "update_engine/common/metrics_reporter_interface.h"
@@ -1040,15 +1039,14 @@
   OmahaResponse response;
   response.packages.resize(1);
   PayloadState payload_state;
-  FakeClock fake_clock;
   FakePrefs fake_prefs;
 
   // Set the clock to a well-known time - 1 second on the wall-clock
   // and 2 seconds on the monotonic clock
-  fake_clock.SetWallclockTime(Time::FromInternalValue(1000000));
-  fake_clock.SetMonotonicTime(Time::FromInternalValue(2000000));
+  auto* fake_clock = FakeSystemState::Get()->fake_clock();
+  fake_clock->SetWallclockTime(Time::FromInternalValue(1000000));
+  fake_clock->SetMonotonicTime(Time::FromInternalValue(2000000));
 
-  FakeSystemState::Get()->set_clock(&fake_clock);
   FakeSystemState::Get()->set_prefs(&fake_prefs);
   EXPECT_TRUE(payload_state.Initialize());
 
@@ -1057,8 +1055,8 @@
   // the monotonic clock.
   SetupPayloadStateWith2Urls(
       "Hash8593", true, false, &payload_state, &response);
-  fake_clock.SetWallclockTime(Time::FromInternalValue(8000000));
-  fake_clock.SetMonotonicTime(Time::FromInternalValue(6000000));
+  fake_clock->SetWallclockTime(Time::FromInternalValue(8000000));
+  fake_clock->SetMonotonicTime(Time::FromInternalValue(6000000));
   payload_state.UpdateSucceeded();
   EXPECT_EQ(payload_state.GetUpdateDuration().InMicroseconds(), 7000000);
   EXPECT_EQ(payload_state.GetUpdateDurationUptime().InMicroseconds(), 4000000);
@@ -1071,8 +1069,8 @@
 
   // Advance time a bit (10 secs), simulate download progress and
   // check that durations are updated.
-  fake_clock.SetWallclockTime(Time::FromInternalValue(18000000));
-  fake_clock.SetMonotonicTime(Time::FromInternalValue(16000000));
+  fake_clock->SetWallclockTime(Time::FromInternalValue(18000000));
+  fake_clock->SetMonotonicTime(Time::FromInternalValue(16000000));
   payload_state.DownloadProgress(10);
   EXPECT_EQ(payload_state.GetUpdateDuration().InMicroseconds(), 10000000);
   EXPECT_EQ(payload_state.GetUpdateDurationUptime().InMicroseconds(), 10000000);
@@ -1080,7 +1078,7 @@
   // Now simulate a reboot by resetting monotonic time (to 5000) and
   // creating a new PayloadState object and check that we load the
   // durations correctly (e.g. they are the same as before).
-  fake_clock.SetMonotonicTime(Time::FromInternalValue(5000));
+  fake_clock->SetMonotonicTime(Time::FromInternalValue(5000));
   PayloadState payload_state2;
   EXPECT_TRUE(payload_state2.Initialize());
   payload_state2.SetResponse(response);
@@ -1090,8 +1088,8 @@
 
   // Advance wall-clock by 7 seconds and monotonic clock by 6 seconds
   // and check that the durations are increased accordingly.
-  fake_clock.SetWallclockTime(Time::FromInternalValue(25000000));
-  fake_clock.SetMonotonicTime(Time::FromInternalValue(6005000));
+  fake_clock->SetWallclockTime(Time::FromInternalValue(25000000));
+  fake_clock->SetMonotonicTime(Time::FromInternalValue(6005000));
   payload_state2.UpdateSucceeded();
   EXPECT_EQ(payload_state2.GetUpdateDuration().InMicroseconds(), 17000000);
   EXPECT_EQ(payload_state2.GetUpdateDurationUptime().InMicroseconds(),
@@ -1101,14 +1099,13 @@
 TEST_F(PayloadStateTest, RebootAfterSuccessfulUpdateTest) {
   OmahaResponse response;
   PayloadState payload_state;
-  FakeClock fake_clock;
   FakePrefs fake_prefs;
 
   // Set the clock to a well-known time (t = 30 seconds).
-  fake_clock.SetMonotonicTime(
+  auto* fake_clock = FakeSystemState::Get()->fake_clock();
+  fake_clock->SetMonotonicTime(
       Time::FromInternalValue(30 * Time::kMicrosecondsPerSecond));
 
-  FakeSystemState::Get()->set_clock(&fake_clock);
   FakeSystemState::Get()->set_prefs(&fake_prefs);
   EXPECT_TRUE(payload_state.Initialize());
 
@@ -1124,7 +1121,7 @@
   // (t = 500 seconds). We do this by using a new PayloadState object
   // and checking that it emits the right UMA metric with the right
   // value.
-  fake_clock.SetMonotonicTime(
+  fake_clock->SetMonotonicTime(
       Time::FromInternalValue(500 * Time::kMicrosecondsPerSecond));
   PayloadState payload_state2;
   EXPECT_TRUE(payload_state2.Initialize());
@@ -1512,10 +1509,8 @@
 TEST_F(PayloadStateTest, DisallowP2PAfterDeadline) {
   OmahaResponse response;
   PayloadState payload_state;
-  FakeClock fake_clock;
   FakePrefs fake_prefs;
 
-  FakeSystemState::Get()->set_clock(&fake_clock);
   FakeSystemState::Get()->set_prefs(&fake_prefs);
   EXPECT_TRUE(payload_state.Initialize());
   SetupPayloadStateWith2Urls(
@@ -1523,7 +1518,8 @@
 
   // Set the clock to 1 second.
   Time epoch = Time::FromInternalValue(1000000);
-  fake_clock.SetWallclockTime(epoch);
+  auto* fake_clock = FakeSystemState::Get()->fake_clock();
+  fake_clock->SetWallclockTime(epoch);
 
   // Do an attempt - this will set the timestamp.
   payload_state.P2PNewAttempt();
@@ -1535,7 +1531,7 @@
   EXPECT_TRUE(payload_state.P2PAttemptAllowed());
 
   // Set clock to half the deadline - this should work.
-  fake_clock.SetWallclockTime(
+  fake_clock->SetWallclockTime(
       epoch + TimeDelta::FromSeconds(kMaxP2PAttemptTimeSeconds) / 2);
   EXPECT_TRUE(payload_state.P2PAttemptAllowed());
 
@@ -1544,12 +1540,12 @@
   EXPECT_EQ(epoch, payload_state.GetP2PFirstAttemptTimestamp());
 
   // Set clock to _just_ before the deadline - this should work.
-  fake_clock.SetWallclockTime(
+  fake_clock->SetWallclockTime(
       epoch + TimeDelta::FromSeconds(kMaxP2PAttemptTimeSeconds - 1));
   EXPECT_TRUE(payload_state.P2PAttemptAllowed());
 
   // Set clock to _just_ after the deadline - this should not work.
-  fake_clock.SetWallclockTime(
+  fake_clock->SetWallclockTime(
       epoch + TimeDelta::FromSeconds(kMaxP2PAttemptTimeSeconds + 1));
   EXPECT_FALSE(payload_state.P2PAttemptAllowed());
 }
@@ -1572,9 +1568,7 @@
 TEST_F(PayloadStateTest, P2PStateVarsArePersisted) {
   OmahaResponse response;
   PayloadState payload_state;
-  FakeClock fake_clock;
   FakePrefs fake_prefs;
-  FakeSystemState::Get()->set_clock(&fake_clock);
   FakeSystemState::Get()->set_prefs(&fake_prefs);
   EXPECT_TRUE(payload_state.Initialize());
   SetupPayloadStateWith2Urls(
@@ -1582,7 +1576,7 @@
 
   // Set the clock to something known.
   Time time = Time::FromInternalValue(12345);
-  fake_clock.SetWallclockTime(time);
+  FakeSystemState::Get()->fake_clock()->SetWallclockTime(time);
 
   // New p2p attempt - as a side-effect this will update the p2p state vars.
   payload_state.P2PNewAttempt();
@@ -1600,9 +1594,7 @@
 TEST_F(PayloadStateTest, P2PStateVarsAreClearedOnNewResponse) {
   OmahaResponse response;
   PayloadState payload_state;
-  FakeClock fake_clock;
   FakePrefs fake_prefs;
-  FakeSystemState::Get()->set_clock(&fake_clock);
   FakeSystemState::Get()->set_prefs(&fake_prefs);
 
   EXPECT_TRUE(payload_state.Initialize());
@@ -1611,7 +1603,7 @@
 
   // Set the clock to something known.
   Time time = Time::FromInternalValue(12345);
-  fake_clock.SetWallclockTime(time);
+  FakeSystemState::Get()->fake_clock()->SetWallclockTime(time);
 
   // New p2p attempt - as a side-effect this will update the p2p state vars.
   payload_state.P2PNewAttempt();
diff --git a/cros/real_system_state.cc b/cros/real_system_state.cc
index 0b2b49d..5f89b27 100644
--- a/cros/real_system_state.cc
+++ b/cros/real_system_state.cc
@@ -148,7 +148,6 @@
     return false;
   }
   update_manager_.reset(new chromeos_update_manager::UpdateManager(
-      &clock_,
       base::TimeDelta::FromSeconds(5),
       base::TimeDelta::FromHours(12),
       um_state));
@@ -156,7 +155,6 @@
   // The P2P Manager depends on the Update Manager for its initialization.
   p2p_manager_.reset(
       P2PManager::Construct(nullptr,
-                            &clock_,
                             update_manager_.get(),
                             "cros_au",
                             kMaxP2PFilesToKeep,
diff --git a/cros/update_attempter.cc b/cros/update_attempter.cc
index 6c96253..b98b32c 100644
--- a/cros/update_attempter.cc
+++ b/cros/update_attempter.cc
@@ -44,7 +44,6 @@
 
 #include "update_engine/certificate_checker.h"
 #include "update_engine/common/boot_control_interface.h"
-#include "update_engine/common/clock_interface.h"
 #include "update_engine/common/constants.h"
 #include "update_engine/common/dlcservice_interface.h"
 #include "update_engine/common/download_action.h"
diff --git a/cros/update_attempter_unittest.cc b/cros/update_attempter_unittest.cc
index b348d50..18705bd 100644
--- a/cros/update_attempter_unittest.cc
+++ b/cros/update_attempter_unittest.cc
@@ -37,7 +37,6 @@
 
 #include "update_engine/common/constants.h"
 #include "update_engine/common/dlcservice_interface.h"
-#include "update_engine/common/fake_clock.h"
 #include "update_engine/common/fake_prefs.h"
 #include "update_engine/common/mock_action.h"
 #include "update_engine/common/mock_action_processor.h"
@@ -1330,14 +1329,12 @@
 
 // Checks that we only report daily metrics at most every 24 hours.
 TEST_F(UpdateAttempterTest, ReportDailyMetrics) {
-  FakeClock fake_clock;
   FakePrefs fake_prefs;
-
-  FakeSystemState::Get()->set_clock(&fake_clock);
   FakeSystemState::Get()->set_prefs(&fake_prefs);
+  auto* fake_clock = FakeSystemState::Get()->fake_clock();
 
   Time epoch = Time::FromInternalValue(0);
-  fake_clock.SetWallclockTime(epoch);
+  fake_clock->SetWallclockTime(epoch);
 
   // If there is no kPrefsDailyMetricsLastReportedAt state variable,
   // we should report.
@@ -1346,32 +1343,32 @@
   EXPECT_FALSE(attempter_.CheckAndReportDailyMetrics());
 
   // We should not report if only 10 hours has passed.
-  fake_clock.SetWallclockTime(epoch + TimeDelta::FromHours(10));
+  fake_clock->SetWallclockTime(epoch + TimeDelta::FromHours(10));
   EXPECT_FALSE(attempter_.CheckAndReportDailyMetrics());
 
   // We should not report if only 24 hours - 1 sec has passed.
-  fake_clock.SetWallclockTime(epoch + TimeDelta::FromHours(24) -
-                              TimeDelta::FromSeconds(1));
+  fake_clock->SetWallclockTime(epoch + TimeDelta::FromHours(24) -
+                               TimeDelta::FromSeconds(1));
   EXPECT_FALSE(attempter_.CheckAndReportDailyMetrics());
 
   // We should report if 24 hours has passed.
-  fake_clock.SetWallclockTime(epoch + TimeDelta::FromHours(24));
+  fake_clock->SetWallclockTime(epoch + TimeDelta::FromHours(24));
   EXPECT_TRUE(attempter_.CheckAndReportDailyMetrics());
 
   // But then we should not report again..
   EXPECT_FALSE(attempter_.CheckAndReportDailyMetrics());
 
   // .. until another 24 hours has passed
-  fake_clock.SetWallclockTime(epoch + TimeDelta::FromHours(47));
+  fake_clock->SetWallclockTime(epoch + TimeDelta::FromHours(47));
   EXPECT_FALSE(attempter_.CheckAndReportDailyMetrics());
-  fake_clock.SetWallclockTime(epoch + TimeDelta::FromHours(48));
+  fake_clock->SetWallclockTime(epoch + TimeDelta::FromHours(48));
   EXPECT_TRUE(attempter_.CheckAndReportDailyMetrics());
   EXPECT_FALSE(attempter_.CheckAndReportDailyMetrics());
 
   // .. and another 24 hours
-  fake_clock.SetWallclockTime(epoch + TimeDelta::FromHours(71));
+  fake_clock->SetWallclockTime(epoch + TimeDelta::FromHours(71));
   EXPECT_FALSE(attempter_.CheckAndReportDailyMetrics());
-  fake_clock.SetWallclockTime(epoch + TimeDelta::FromHours(72));
+  fake_clock->SetWallclockTime(epoch + TimeDelta::FromHours(72));
   EXPECT_TRUE(attempter_.CheckAndReportDailyMetrics());
   EXPECT_FALSE(attempter_.CheckAndReportDailyMetrics());
 
@@ -1379,23 +1376,21 @@
   // negative, we report. This is in order to reset the timestamp and
   // avoid an edge condition whereby a distant point in the future is
   // in the state variable resulting in us never ever reporting again.
-  fake_clock.SetWallclockTime(epoch + TimeDelta::FromHours(71));
+  fake_clock->SetWallclockTime(epoch + TimeDelta::FromHours(71));
   EXPECT_TRUE(attempter_.CheckAndReportDailyMetrics());
   EXPECT_FALSE(attempter_.CheckAndReportDailyMetrics());
 
   // In this case we should not update until the clock reads 71 + 24 = 95.
   // Check that.
-  fake_clock.SetWallclockTime(epoch + TimeDelta::FromHours(94));
+  fake_clock->SetWallclockTime(epoch + TimeDelta::FromHours(94));
   EXPECT_FALSE(attempter_.CheckAndReportDailyMetrics());
-  fake_clock.SetWallclockTime(epoch + TimeDelta::FromHours(95));
+  fake_clock->SetWallclockTime(epoch + TimeDelta::FromHours(95));
   EXPECT_TRUE(attempter_.CheckAndReportDailyMetrics());
   EXPECT_FALSE(attempter_.CheckAndReportDailyMetrics());
 }
 
 TEST_F(UpdateAttempterTest, BootTimeInUpdateMarkerFile) {
-  FakeClock fake_clock;
-  fake_clock.SetBootTime(Time::FromTimeT(42));
-  FakeSystemState::Get()->set_clock(&fake_clock);
+  FakeSystemState::Get()->fake_clock()->SetBootTime(Time::FromTimeT(42));
   FakePrefs fake_prefs;
   FakeSystemState::Get()->set_prefs(&fake_prefs);
   attempter_.Init();
@@ -1965,12 +1960,10 @@
   fake_prefs.SetInt64(kPrefsUpdateFirstSeenAt,
                       update_first_seen_at.ToInternalValue());
 
-  FakeClock fake_clock;
   Time update_finished_at =
       update_first_seen_at + TimeDelta::FromDays(kDaysToUpdate);
-  fake_clock.SetWallclockTime(update_finished_at);
+  FakeSystemState::Get()->fake_clock()->SetWallclockTime(update_finished_at);
 
-  FakeSystemState::Get()->set_clock(&fake_clock);
   FakeSystemState::Get()->set_prefs(&fake_prefs);
 
   EXPECT_CALL(*FakeSystemState::Get()->mock_metrics_reporter(),
@@ -1995,12 +1988,9 @@
   fake_prefs.SetInt64(kPrefsUpdateFirstSeenAt,
                       update_first_seen_at.ToInternalValue());
 
-  FakeClock fake_clock;
   Time update_finished_at =
       update_first_seen_at + TimeDelta::FromDays(kDaysToUpdate);
-  fake_clock.SetWallclockTime(update_finished_at);
-
-  FakeSystemState::Get()->set_clock(&fake_clock);
+  FakeSystemState::Get()->fake_clock()->SetWallclockTime(update_finished_at);
   FakeSystemState::Get()->set_prefs(&fake_prefs);
 
   EXPECT_CALL(*FakeSystemState::Get()->mock_metrics_reporter(),