update_engine: Use PrefsInterface from SystemState

There is no need to pass the Pref class around (at least not in cros)
since we have the SystemState as the global context and we can get the
pref from there.

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

Change-Id: I9f5fb8a118fab2ef0e188c42f746dafb1094972c
Reviewed-on: https://chromium-review.googlesource.com/c/aosp/platform/system/update_engine/+/2548740
Tested-by: Amin Hassani <[email protected]>
Commit-Queue: Jae Hoon Kim <[email protected]>
Reviewed-by: Jae Hoon Kim <[email protected]>
diff --git a/common/excluder_interface.h b/common/excluder_interface.h
index 3985bba..1dfd227 100644
--- a/common/excluder_interface.h
+++ b/common/excluder_interface.h
@@ -26,6 +26,8 @@
 
 class PrefsInterface;
 
+// TODO(b/171829801): Move this interface to 'cros' directory. 'aosp' in no way
+// is using this. Not even the stub implementation.
 class ExcluderInterface {
  public:
   virtual ~ExcluderInterface() = default;
@@ -53,7 +55,7 @@
   ExcluderInterface() = default;
 };
 
-std::unique_ptr<ExcluderInterface> CreateExcluder(PrefsInterface* prefs);
+std::unique_ptr<ExcluderInterface> CreateExcluder();
 
 }  // namespace chromeos_update_engine
 
diff --git a/common/excluder_stub.cc b/common/excluder_stub.cc
index a251765..2b987fd 100644
--- a/common/excluder_stub.cc
+++ b/common/excluder_stub.cc
@@ -24,7 +24,7 @@
 
 namespace chromeos_update_engine {
 
-std::unique_ptr<ExcluderInterface> CreateExcluder(PrefsInterface* prefs) {
+std::unique_ptr<ExcluderInterface> CreateExcluder() {
   return std::make_unique<ExcluderStub>();
 }
 
diff --git a/common/system_state.h b/common/system_state.h
index 29b897b..84d026f 100644
--- a/common/system_state.h
+++ b/common/system_state.h
@@ -22,6 +22,7 @@
 #include <base/logging.h>
 
 #include "update_engine/common/clock_interface.h"
+#include "update_engine/common/prefs_interface.h"
 
 namespace chromeos_update_manager {
 
@@ -49,7 +50,6 @@
 class P2PManager;
 class PayloadStateInterface;
 class PowerManagerInterface;
-class PrefsInterface;
 class UpdateAttempter;
 
 // An interface to global system context, including platform resources,
diff --git a/cros/common_service.cc b/cros/common_service.cc
index df63bca..e5ee828 100644
--- a/cros/common_service.cc
+++ b/cros/common_service.cc
@@ -218,12 +218,11 @@
 
 bool UpdateEngineService::SetCohortHint(ErrorPtr* error,
                                         const string& in_cohort_hint) {
-  PrefsInterface* prefs = SystemState::Get()->prefs();
-
   // It is ok to override the cohort hint with an invalid value since it is
   // stored in stateful partition. The code reading it should sanitize it
   // anyway.
-  if (!prefs->SetString(kPrefsOmahaCohortHint, in_cohort_hint)) {
+  if (!SystemState::Get()->prefs()->SetString(kPrefsOmahaCohortHint,
+                                              in_cohort_hint)) {
     LogAndSetError(
         error,
         FROM_HERE,
@@ -236,8 +235,7 @@
 
 bool UpdateEngineService::GetCohortHint(ErrorPtr* error,
                                         string* out_cohort_hint) {
-  PrefsInterface* prefs = SystemState::Get()->prefs();
-
+  const auto* prefs = SystemState::Get()->prefs();
   *out_cohort_hint = "";
   if (prefs->Exists(kPrefsOmahaCohortHint) &&
       !prefs->GetString(kPrefsOmahaCohortHint, out_cohort_hint)) {
@@ -249,9 +247,7 @@
 
 bool UpdateEngineService::SetP2PUpdatePermission(ErrorPtr* error,
                                                  bool in_enabled) {
-  PrefsInterface* prefs = SystemState::Get()->prefs();
-
-  if (!prefs->SetBoolean(kPrefsP2PEnabled, in_enabled)) {
+  if (!SystemState::Get()->prefs()->SetBoolean(kPrefsP2PEnabled, in_enabled)) {
     LogAndSetError(
         error,
         FROM_HERE,
@@ -264,8 +260,7 @@
 
 bool UpdateEngineService::GetP2PUpdatePermission(ErrorPtr* error,
                                                  bool* out_enabled) {
-  PrefsInterface* prefs = SystemState::Get()->prefs();
-
+  const auto* prefs = SystemState::Get()->prefs();
   bool p2p_pref = false;  // Default if no setting is present.
   if (prefs->Exists(kPrefsP2PEnabled) &&
       !prefs->GetBoolean(kPrefsP2PEnabled, &p2p_pref)) {
@@ -293,11 +288,8 @@
 
   // If the policy wasn't loaded yet, then it is still OK to change the local
   // setting because the policy will be checked again during the update check.
-
-  PrefsInterface* prefs = SystemState::Get()->prefs();
-
-  if (!prefs ||
-      !prefs->SetBoolean(kPrefsUpdateOverCellularPermission, in_allowed)) {
+  if (!SystemState::Get()->prefs()->SetBoolean(
+          kPrefsUpdateOverCellularPermission, in_allowed)) {
     LogAndSetError(error,
                    FROM_HERE,
                    string("Error setting the update over cellular to ") +
@@ -326,10 +318,8 @@
   // If the policy wasn't loaded yet, then it is still OK to change the local
   // setting because the policy will be checked again during the update check.
 
-  PrefsInterface* prefs = SystemState::Get()->prefs();
-
-  if (!prefs ||
-      !prefs->SetString(kPrefsUpdateOverCellularTargetVersion,
+  auto* prefs = SystemState::Get()->prefs();
+  if (!prefs->SetString(kPrefsUpdateOverCellularTargetVersion,
                         target_version) ||
       !prefs->SetInt64(kPrefsUpdateOverCellularTargetSize, target_size)) {
     LogAndSetError(
@@ -349,9 +339,8 @@
     *out_allowed = connection_manager->IsUpdateAllowedOver(
         ConnectionType::kCellular, ConnectionTethering::kUnknown);
   } else {
-    PrefsInterface* prefs = SystemState::Get()->prefs();
-
-    if (!prefs || !prefs->Exists(kPrefsUpdateOverCellularPermission)) {
+    const auto* prefs = SystemState::Get()->prefs();
+    if (!prefs->Exists(kPrefsUpdateOverCellularPermission)) {
       // Update is not allowed as user preference is not set or not available.
       *out_allowed = false;
       return true;
diff --git a/cros/common_service_unittest.cc b/cros/common_service_unittest.cc
index a6b0014..0644643 100644
--- a/cros/common_service_unittest.cc
+++ b/cros/common_service_unittest.cc
@@ -24,7 +24,6 @@
 #include <policy/libpolicy.h>
 #include <policy/mock_device_policy.h>
 
-#include "update_engine/common/fake_prefs.h"
 #include "update_engine/cros/fake_system_state.h"
 #include "update_engine/cros/omaha_utils.h"
 
diff --git a/cros/excluder_chromeos.cc b/cros/excluder_chromeos.cc
index 4796525..35154d6 100644
--- a/cros/excluder_chromeos.cc
+++ b/cros/excluder_chromeos.cc
@@ -25,7 +25,6 @@
 #include <base/strings/string_split.h>
 
 #include "update_engine/common/constants.h"
-#include "update_engine/common/prefs.h"
 #include "update_engine/common/system_state.h"
 
 using std::string;
@@ -33,29 +32,30 @@
 
 namespace chromeos_update_engine {
 
-std::unique_ptr<ExcluderInterface> CreateExcluder(PrefsInterface* prefs) {
-  return std::make_unique<ExcluderChromeOS>(prefs);
+std::unique_ptr<ExcluderInterface> CreateExcluder() {
+  return std::make_unique<ExcluderChromeOS>();
 }
 
-ExcluderChromeOS::ExcluderChromeOS(PrefsInterface* prefs) : prefs_(prefs) {}
-
 bool ExcluderChromeOS::Exclude(const string& name) {
-  auto key = prefs_->CreateSubKey({kExclusionPrefsSubDir, name});
-  return prefs_->SetString(key, "");
+  auto* prefs = SystemState::Get()->prefs();
+  auto key = prefs->CreateSubKey({kExclusionPrefsSubDir, name});
+  return prefs->SetString(key, "");
 }
 
 bool ExcluderChromeOS::IsExcluded(const string& name) {
-  auto key = prefs_->CreateSubKey({kExclusionPrefsSubDir, name});
-  return prefs_->Exists(key);
+  auto* prefs = SystemState::Get()->prefs();
+  auto key = prefs->CreateSubKey({kExclusionPrefsSubDir, name});
+  return prefs->Exists(key);
 }
 
 bool ExcluderChromeOS::Reset() {
+  auto* prefs = SystemState::Get()->prefs();
   bool ret = true;
   vector<string> keys;
-  if (!prefs_->GetSubKeys(kExclusionPrefsSubDir, &keys))
+  if (!prefs->GetSubKeys(kExclusionPrefsSubDir, &keys))
     return false;
   for (const auto& key : keys)
-    if (!(ret &= prefs_->Delete(key)))
+    if (!(ret &= prefs->Delete(key)))
       LOG(ERROR) << "Failed to delete exclusion pref for " << key;
   return ret;
 }
diff --git a/cros/excluder_chromeos.h b/cros/excluder_chromeos.h
index 2480066..7d3efc9 100644
--- a/cros/excluder_chromeos.h
+++ b/cros/excluder_chromeos.h
@@ -29,7 +29,7 @@
 // The Chrome OS implementation of the |ExcluderInterface|.
 class ExcluderChromeOS : public ExcluderInterface {
  public:
-  explicit ExcluderChromeOS(PrefsInterface* prefs);
+  ExcluderChromeOS() = default;
   ~ExcluderChromeOS() = default;
 
   // |ExcluderInterface| overrides.
@@ -42,9 +42,6 @@
   ExcluderChromeOS& operator=(const ExcluderChromeOS&) = delete;
   ExcluderChromeOS(ExcluderChromeOS&&) = delete;
   ExcluderChromeOS& operator=(ExcluderChromeOS&&) = delete;
-
- private:
-  PrefsInterface* prefs_;
 };
 
 }  // namespace chromeos_update_engine
diff --git a/cros/excluder_chromeos_unittest.cc b/cros/excluder_chromeos_unittest.cc
index 3602e56..fd70818 100644
--- a/cros/excluder_chromeos_unittest.cc
+++ b/cros/excluder_chromeos_unittest.cc
@@ -16,51 +16,39 @@
 
 #include "update_engine/cros/excluder_chromeos.h"
 
-#include <memory>
-
-#include <base/files/file_util.h>
-#include <base/files/scoped_temp_dir.h>
 #include <gtest/gtest.h>
 
-#include "update_engine/common/prefs.h"
-
-using std::string;
-using std::unique_ptr;
+#include "update_engine/cros/fake_system_state.h"
 
 namespace chromeos_update_engine {
 
+namespace {
 constexpr char kFakeHash[] =
     "71ff43d76e2488e394e46872f5b066cc25e394c2c3e3790dd319517883b33db1";
+}  // namespace
 
 class ExcluderChromeOSTest : public ::testing::Test {
  protected:
-  void SetUp() override {
-    ASSERT_TRUE(tempdir_.CreateUniqueTempDir());
-    ASSERT_TRUE(base::PathExists(tempdir_.GetPath()));
-    ASSERT_TRUE(prefs_.Init(tempdir_.GetPath()));
-    excluder_ = std::make_unique<ExcluderChromeOS>(&prefs_);
-  }
+  void SetUp() override { FakeSystemState::CreateInstance(); }
 
-  base::ScopedTempDir tempdir_;
-  Prefs prefs_;
-  unique_ptr<ExcluderChromeOS> excluder_;
+  ExcluderChromeOS excluder_;
 };
 
 TEST_F(ExcluderChromeOSTest, ExclusionCheck) {
-  EXPECT_FALSE(excluder_->IsExcluded(kFakeHash));
-  EXPECT_TRUE(excluder_->Exclude(kFakeHash));
-  EXPECT_TRUE(excluder_->IsExcluded(kFakeHash));
+  EXPECT_FALSE(excluder_.IsExcluded(kFakeHash));
+  EXPECT_TRUE(excluder_.Exclude(kFakeHash));
+  EXPECT_TRUE(excluder_.IsExcluded(kFakeHash));
 }
 
 TEST_F(ExcluderChromeOSTest, ResetFlow) {
-  EXPECT_TRUE(excluder_->Exclude("abc"));
-  EXPECT_TRUE(excluder_->Exclude(kFakeHash));
-  EXPECT_TRUE(excluder_->IsExcluded("abc"));
-  EXPECT_TRUE(excluder_->IsExcluded(kFakeHash));
+  EXPECT_TRUE(excluder_.Exclude("abc"));
+  EXPECT_TRUE(excluder_.Exclude(kFakeHash));
+  EXPECT_TRUE(excluder_.IsExcluded("abc"));
+  EXPECT_TRUE(excluder_.IsExcluded(kFakeHash));
 
-  EXPECT_TRUE(excluder_->Reset());
-  EXPECT_FALSE(excluder_->IsExcluded("abc"));
-  EXPECT_FALSE(excluder_->IsExcluded(kFakeHash));
+  EXPECT_TRUE(excluder_.Reset());
+  EXPECT_FALSE(excluder_.IsExcluded("abc"));
+  EXPECT_FALSE(excluder_.IsExcluded(kFakeHash));
 }
 
 }  // namespace chromeos_update_engine
diff --git a/cros/fake_system_state.cc b/cros/fake_system_state.cc
index e0206f5..7673b1d 100644
--- a/cros/fake_system_state.cc
+++ b/cros/fake_system_state.cc
@@ -26,8 +26,8 @@
       connection_manager_(&mock_connection_manager_),
       hardware_(&fake_hardware_),
       metrics_reporter_(&mock_metrics_reporter_),
-      prefs_(&mock_prefs_),
-      powerwash_safe_prefs_(&mock_powerwash_safe_prefs_),
+      prefs_(&fake_prefs_),
+      powerwash_safe_prefs_(&fake_powerwash_safe_prefs_),
       payload_state_(&mock_payload_state_),
       update_attempter_(&mock_update_attempter_),
       request_params_(&mock_request_params_),
diff --git a/cros/fake_system_state.h b/cros/fake_system_state.h
index b1d5952..7eb830c 100644
--- a/cros/fake_system_state.h
+++ b/cros/fake_system_state.h
@@ -25,6 +25,7 @@
 #include "update_engine/common/fake_boot_control.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/mock_metrics_reporter.h"
 #include "update_engine/common/mock_prefs.h"
 #include "update_engine/common/system_state.h"
@@ -200,6 +201,16 @@
     return &fake_hardware_;
   }
 
+  inline FakePrefs* fake_prefs() {
+    CHECK(prefs_ == &fake_prefs_);
+    return &fake_prefs_;
+  }
+
+  inline FakePrefs* fake_powerwash_safe_prefs() {
+    CHECK(powerwash_safe_prefs_ == &fake_powerwash_safe_prefs_);
+    return &fake_powerwash_safe_prefs_;
+  }
+
   inline testing::NiceMock<MockMetricsReporter>* mock_metrics_reporter() {
     CHECK(metrics_reporter_ == &mock_metrics_reporter_);
     return &mock_metrics_reporter_;
@@ -245,10 +256,14 @@
   FakeSystemState();
 
   // Default mock/fake implementations (owned).
+  chromeos_update_manager::FakeUpdateManager fake_update_manager_;
   FakeBootControl fake_boot_control_;
   FakeClock fake_clock_;
-  testing::NiceMock<MockConnectionManager> mock_connection_manager_;
   FakeHardware fake_hardware_;
+  FakePrefs fake_prefs_;
+  FakePrefs fake_powerwash_safe_prefs_;
+
+  testing::NiceMock<MockConnectionManager> mock_connection_manager_;
   testing::NiceMock<MockMetricsReporter> mock_metrics_reporter_;
   testing::NiceMock<MockPrefs> mock_prefs_;
   testing::NiceMock<MockPrefs> mock_powerwash_safe_prefs_;
@@ -256,7 +271,6 @@
   testing::NiceMock<MockUpdateAttempter> mock_update_attempter_;
   testing::NiceMock<MockOmahaRequestParams> mock_request_params_;
   testing::NiceMock<MockP2PManager> mock_p2p_manager_;
-  chromeos_update_manager::FakeUpdateManager fake_update_manager_;
   testing::NiceMock<MockPowerManager> mock_power_manager_;
 
   // Pointers to objects that client code can override. They are initialized to
diff --git a/cros/metrics_reporter_omaha_unittest.cc b/cros/metrics_reporter_omaha_unittest.cc
index c5cfece..cdc44cd 100644
--- a/cros/metrics_reporter_omaha_unittest.cc
+++ b/cros/metrics_reporter_omaha_unittest.cc
@@ -25,7 +25,6 @@
 #include <metrics/metrics_library_mock.h>
 
 #include "update_engine/common/fake_clock.h"
-#include "update_engine/common/fake_prefs.h"
 #include "update_engine/cros/fake_system_state.h"
 
 using base::TimeDelta;
@@ -62,10 +61,7 @@
 }
 
 TEST_F(MetricsReporterOmahaTest, ReportUpdateCheckMetrics) {
-  FakePrefs fake_prefs;
-
   // We need to execute the report twice to test the time since last report.
-  FakeSystemState::Get()->set_prefs(&fake_prefs);
   fake_clock_->SetWallclockTime(base::Time::FromInternalValue(1000000));
   fake_clock_->SetMonotonicTime(base::Time::FromInternalValue(1000000));
 
@@ -176,8 +172,6 @@
 }
 
 TEST_F(MetricsReporterOmahaTest, ReportUpdateAttemptMetrics) {
-  FakePrefs fake_prefs;
-  FakeSystemState::Get()->set_prefs(&fake_prefs);
   fake_clock_->SetWallclockTime(base::Time::FromInternalValue(1000000));
   fake_clock_->SetMonotonicTime(base::Time::FromInternalValue(1000000));
 
@@ -528,9 +522,6 @@
 TEST_F(MetricsReporterOmahaTest, WallclockDurationHelper) {
   base::TimeDelta duration;
   const std::string state_variable_key = "test-prefs";
-  FakePrefs fake_prefs;
-
-  FakeSystemState::Get()->set_prefs(&fake_prefs);
 
   // Initialize wallclock to 1 sec.
   fake_clock_->SetWallclockTime(base::Time::FromInternalValue(1000000));
diff --git a/cros/omaha_request_action.cc b/cros/omaha_request_action.cc
index f847194..d67623f 100644
--- a/cros/omaha_request_action.cc
+++ b/cros/omaha_request_action.cc
@@ -346,10 +346,7 @@
 
 // static
 int OmahaRequestAction::GetInstallDate() {
-  PrefsInterface* prefs = SystemState::Get()->prefs();
-  if (prefs == nullptr)
-    return -1;
-
+  auto* prefs = SystemState::Get()->prefs();
   // If we have the value stored on disk, just return it.
   int64_t stored_value;
   if (prefs->GetInt64(kPrefsInstallDateDays, &stored_value)) {
@@ -422,7 +419,7 @@
     if (!dlc_params.send_ping)
       continue;
 
-    PrefsInterface* prefs = SystemState::Get()->prefs();
+    auto* prefs = SystemState::Get()->prefs();
     // Reset the active metadata value to |kPingInactiveValue|.
     auto active_key =
         prefs->CreateSubKey({kDlcPrefsSubDir, dlc_id, kPrefsPingActive});
@@ -518,7 +515,7 @@
 
 // Update the last ping day preferences based on the server daystart
 // response. Returns true on success, false otherwise.
-bool UpdateLastPingDays(OmahaParserData* parser_data, PrefsInterface* prefs) {
+bool UpdateLastPingDays(OmahaParserData* parser_data) {
   int64_t elapsed_seconds = 0;
   TEST_AND_RETURN_FALSE(base::StringToInt64(
       parser_data->daystart_elapsed_seconds, &elapsed_seconds));
@@ -526,6 +523,7 @@
 
   // Remember the local time that matches the server's last midnight
   // time.
+  auto* prefs = SystemState::Get()->prefs();
   Time daystart = Time::Now() - TimeDelta::FromSeconds(elapsed_seconds);
   prefs->SetInt64(kPrefsLastActivePingDay, daystart.ToInternalValue());
   prefs->SetInt64(kPrefsLastRollCallPingDay, daystart.ToInternalValue());
@@ -976,7 +974,7 @@
   // Update the last ping day preferences based on the server daystart response
   // even if we didn't send a ping. Omaha always includes the daystart in the
   // response, but log the error if it didn't.
-  LOG_IF(ERROR, !UpdateLastPingDays(&parser_data, SystemState::Get()->prefs()))
+  LOG_IF(ERROR, !UpdateLastPingDays(&parser_data))
       << "Failed to update the last ping day preferences!";
 
   // Sets first_active_omaha_ping_sent to true (vpd in CrOS). We only do this if
@@ -1357,11 +1355,7 @@
 
 // static
 bool OmahaRequestAction::HasInstallDate() {
-  PrefsInterface* prefs = SystemState::Get()->prefs();
-  if (prefs == nullptr)
-    return false;
-
-  return prefs->Exists(kPrefsInstallDateDays);
+  return SystemState::Get()->prefs()->Exists(kPrefsInstallDateDays);
 }
 
 // static
@@ -1370,10 +1364,7 @@
     InstallDateProvisioningSource source) {
   TEST_AND_RETURN_FALSE(install_date_days >= 0);
 
-  PrefsInterface* prefs = SystemState::Get()->prefs();
-  if (prefs == nullptr)
-    return false;
-
+  auto* prefs = SystemState::Get()->prefs();
   if (!prefs->SetInt64(kPrefsInstallDateDays, install_date_days))
     return false;
 
@@ -1417,7 +1408,7 @@
                      << " as it is not in the request params.";
         continue;
       }
-      PrefsInterface* prefs = SystemState::Get()->prefs();
+      auto* prefs = SystemState::Get()->prefs();
       PersistCohortData(
           prefs->CreateSubKey({kDlcPrefsSubDir, dlc_id, kPrefsOmahaCohort}),
           app.cohort);
@@ -1561,16 +1552,8 @@
 
 bool OmahaRequestAction::IsUpdateAllowedOverCellularByPrefs(
     const OmahaResponse& response) const {
-  PrefsInterface* prefs = SystemState::Get()->prefs();
-
-  if (!prefs) {
-    LOG(INFO) << "Disabling updates over cellular as the preferences are "
-                 "not available.";
-    return false;
-  }
-
+  auto* prefs = SystemState::Get()->prefs();
   bool is_allowed;
-
   if (prefs->Exists(kPrefsUpdateOverCellularPermission) &&
       prefs->GetBoolean(kPrefsUpdateOverCellularPermission, &is_allowed) &&
       is_allowed) {
diff --git a/cros/omaha_request_action.h b/cros/omaha_request_action.h
index 64d9bcb..958633d 100644
--- a/cros/omaha_request_action.h
+++ b/cros/omaha_request_action.h
@@ -49,7 +49,6 @@
 class NoneType;
 class OmahaRequestAction;
 class OmahaRequestParams;
-class PrefsInterface;
 
 // This struct is declared in the .cc file.
 struct OmahaParserData;
diff --git a/cros/omaha_request_action_unittest.cc b/cros/omaha_request_action_unittest.cc
index 7683988..89648eb 100644
--- a/cros/omaha_request_action_unittest.cc
+++ b/cros/omaha_request_action_unittest.cc
@@ -399,7 +399,7 @@
     request_params_.set_dlc_apps_params({});
 
     FakeSystemState::Get()->set_request_params(&request_params_);
-    FakeSystemState::Get()->set_prefs(&fake_prefs_);
+    fake_prefs_ = FakeSystemState::Get()->fake_prefs();
 
     // Setting the default update check params. Lookup |TestUpdateCheck()|.
     tuc_params_ = {
@@ -462,7 +462,7 @@
   // Used by all tests.
   OmahaRequestParams request_params_;
 
-  FakePrefs fake_prefs_;
+  FakePrefs* fake_prefs_;
 
   OmahaRequestActionTestProcessorDelegate delegate_;
 
@@ -504,6 +504,7 @@
   std::string last_active_key_;
   std::string last_rollcall_key_;
 };
+
 bool OmahaRequestActionTest::TestUpdateCheck() {
   brillo::FakeMessageLoop loop(nullptr);
   loop.SetAsCurrent();
@@ -679,9 +680,9 @@
   EXPECT_FALSE(response_.powerwash_required);
   // Omaha cohort attributes are not set in the response, so they should not be
   // persisted.
-  EXPECT_FALSE(fake_prefs_.Exists(kPrefsOmahaCohort));
-  EXPECT_FALSE(fake_prefs_.Exists(kPrefsOmahaCohortHint));
-  EXPECT_FALSE(fake_prefs_.Exists(kPrefsOmahaCohortName));
+  EXPECT_FALSE(fake_prefs_->Exists(kPrefsOmahaCohort));
+  EXPECT_FALSE(fake_prefs_->Exists(kPrefsOmahaCohortHint));
+  EXPECT_FALSE(fake_prefs_->Exists(kPrefsOmahaCohortName));
 }
 
 TEST_F(OmahaRequestActionTest, MultiPackageUpdateTest) {
@@ -899,7 +900,7 @@
   // This test tests that, when device policy is not set, update over cellular
   // is allowed as permission for update over cellular is set to true.
   MockConnectionManager mock_cm;
-  fake_prefs_.SetBoolean(kPrefsUpdateOverCellularPermission, true);
+  fake_prefs_->SetBoolean(kPrefsUpdateOverCellularPermission, true);
   FakeSystemState::Get()->set_connection_manager(&mock_cm);
 
   EXPECT_CALL(mock_cm, GetConnectionProperties(_, _))
@@ -929,8 +930,8 @@
   // A size different from the size in omaha response.
   int64_t diff_size = 999;
 
-  fake_prefs_.SetString(kPrefsUpdateOverCellularTargetVersion, diff_version);
-  fake_prefs_.SetInt64(kPrefsUpdateOverCellularTargetSize, diff_size);
+  fake_prefs_->SetString(kPrefsUpdateOverCellularTargetVersion, diff_version);
+  fake_prefs_->SetInt64(kPrefsUpdateOverCellularTargetSize, diff_size);
   // This test tests cellular (3G) being the only connection type being allowed.
   FakeSystemState::Get()->set_connection_manager(&mock_cm);
 
@@ -963,8 +964,8 @@
   // A size same as the size in omaha response.
   int64_t new_size = fake_update_response_.size;
 
-  fake_prefs_.SetString(kPrefsUpdateOverCellularTargetVersion, new_version);
-  fake_prefs_.SetInt64(kPrefsUpdateOverCellularTargetSize, new_size);
+  fake_prefs_->SetString(kPrefsUpdateOverCellularTargetVersion, new_version);
+  fake_prefs_->SetInt64(kPrefsUpdateOverCellularTargetSize, new_size);
   FakeSystemState::Get()->set_connection_manager(&mock_cm);
 
   EXPECT_CALL(mock_cm, GetConnectionProperties(_, _))
@@ -1155,7 +1156,7 @@
   ASSERT_TRUE(TestUpdateCheck());
 
   int64_t count;
-  ASSERT_TRUE(fake_prefs_.GetInt64(kPrefsUpdateCheckCount, &count));
+  ASSERT_TRUE(fake_prefs_->GetInt64(kPrefsUpdateCheckCount, &count));
   ASSERT_EQ(count, 0);
   EXPECT_TRUE(response_.update_exists);
 }
@@ -1174,7 +1175,7 @@
   ASSERT_FALSE(TestUpdateCheck());
 
   int64_t count;
-  ASSERT_TRUE(fake_prefs_.GetInt64(kPrefsUpdateCheckCount, &count));
+  ASSERT_TRUE(fake_prefs_->GetInt64(kPrefsUpdateCheckCount, &count));
   ASSERT_GT(count, 0);
   EXPECT_FALSE(response_.update_exists);
 }
@@ -1207,11 +1208,11 @@
   tuc_params_.expected_code = ErrorCode::kOmahaUpdateDeferredPerPolicy;
   tuc_params_.expected_check_reaction = metrics::CheckReaction::kDeferring;
 
-  ASSERT_TRUE(fake_prefs_.SetInt64(kPrefsUpdateCheckCount, 5));
+  ASSERT_TRUE(fake_prefs_->SetInt64(kPrefsUpdateCheckCount, 5));
   ASSERT_FALSE(TestUpdateCheck());
 
   int64_t count;
-  ASSERT_TRUE(fake_prefs_.GetInt64(kPrefsUpdateCheckCount, &count));
+  ASSERT_TRUE(fake_prefs_->GetInt64(kPrefsUpdateCheckCount, &count));
   // |count| remains the same, as the decrementing happens in update_attempter
   // which this test doesn't exercise.
   ASSERT_EQ(count, 5);
@@ -1229,7 +1230,7 @@
   FakeSystemState::Get()->fake_clock()->SetWallclockTime(Time::Now());
   tuc_params_.http_response = fake_update_response_.GetUpdateResponse();
 
-  ASSERT_TRUE(fake_prefs_.SetInt64(kPrefsUpdateCheckCount, 5));
+  ASSERT_TRUE(fake_prefs_->SetInt64(kPrefsUpdateCheckCount, 5));
 
   // Verify if we are interactive check we don't defer.
   ASSERT_TRUE(TestUpdateCheck());
@@ -1244,7 +1245,7 @@
   request_params_.set_update_check_count_wait_enabled(false);
   FakeSystemState::Get()->fake_clock()->SetWallclockTime(Time::Now());
 
-  ASSERT_TRUE(fake_prefs_.SetInt64(kPrefsWallClockStagingWaitPeriod, 6));
+  ASSERT_TRUE(fake_prefs_->SetInt64(kPrefsWallClockStagingWaitPeriod, 6));
   // This should not prevent scattering due to staging.
   fake_update_response_.max_days_to_scatter = "0";
   tuc_params_.http_response = fake_update_response_.GetUpdateResponse();
@@ -1283,48 +1284,48 @@
   ASSERT_TRUE(TestUpdateCheck());
 
   string value;
-  EXPECT_TRUE(fake_prefs_.GetString(kPrefsOmahaCohort, &value));
+  EXPECT_TRUE(fake_prefs_->GetString(kPrefsOmahaCohort, &value));
   EXPECT_EQ(fake_update_response_.cohort, value);
 
-  EXPECT_TRUE(fake_prefs_.GetString(kPrefsOmahaCohortHint, &value));
+  EXPECT_TRUE(fake_prefs_->GetString(kPrefsOmahaCohortHint, &value));
   EXPECT_EQ(fake_update_response_.cohorthint, value);
 
-  EXPECT_TRUE(fake_prefs_.GetString(kPrefsOmahaCohortName, &value));
+  EXPECT_TRUE(fake_prefs_->GetString(kPrefsOmahaCohortName, &value));
   EXPECT_EQ(fake_update_response_.cohortname, value);
 
-  EXPECT_TRUE(fake_prefs_.GetString(
-      fake_prefs_.CreateSubKey({kDlcPrefsSubDir, kDlcId1, kPrefsOmahaCohort}),
+  EXPECT_TRUE(fake_prefs_->GetString(
+      fake_prefs_->CreateSubKey({kDlcPrefsSubDir, kDlcId1, kPrefsOmahaCohort}),
       &value));
   EXPECT_EQ(fake_update_response_.dlc_cohort, value);
 
-  EXPECT_TRUE(fake_prefs_.GetString(
-      fake_prefs_.CreateSubKey(
+  EXPECT_TRUE(fake_prefs_->GetString(
+      fake_prefs_->CreateSubKey(
           {kDlcPrefsSubDir, kDlcId1, kPrefsOmahaCohortHint}),
       &value));
   EXPECT_EQ(fake_update_response_.dlc_cohorthint, value);
 
-  EXPECT_TRUE(fake_prefs_.GetString(
-      fake_prefs_.CreateSubKey(
+  EXPECT_TRUE(fake_prefs_->GetString(
+      fake_prefs_->CreateSubKey(
           {kDlcPrefsSubDir, kDlcId1, kPrefsOmahaCohortName}),
       &value));
   EXPECT_EQ(fake_update_response_.dlc_cohortname, value);
 }
 
 TEST_F(OmahaRequestActionTest, CohortsAreUpdated) {
-  EXPECT_TRUE(fake_prefs_.SetString(kPrefsOmahaCohort, "old_value"));
-  EXPECT_TRUE(fake_prefs_.SetString(kPrefsOmahaCohortHint, "old_hint"));
-  EXPECT_TRUE(fake_prefs_.SetString(kPrefsOmahaCohortName, "old_name"));
+  EXPECT_TRUE(fake_prefs_->SetString(kPrefsOmahaCohort, "old_value"));
+  EXPECT_TRUE(fake_prefs_->SetString(kPrefsOmahaCohortHint, "old_hint"));
+  EXPECT_TRUE(fake_prefs_->SetString(kPrefsOmahaCohortName, "old_name"));
   const string dlc_cohort_key =
-      fake_prefs_.CreateSubKey({kDlcPrefsSubDir, kDlcId1, kPrefsOmahaCohort});
-  const string dlc_cohort_hint_key = fake_prefs_.CreateSubKey(
+      fake_prefs_->CreateSubKey({kDlcPrefsSubDir, kDlcId1, kPrefsOmahaCohort});
+  const string dlc_cohort_hint_key = fake_prefs_->CreateSubKey(
       {kDlcPrefsSubDir, kDlcId1, kPrefsOmahaCohortHint});
-  const string dlc_cohort_name_key = fake_prefs_.CreateSubKey(
+  const string dlc_cohort_name_key = fake_prefs_->CreateSubKey(
       {kDlcPrefsSubDir, kDlcId1, kPrefsOmahaCohortName});
   request_params_.set_dlc_apps_params(
       {{request_params_.GetDlcAppId(kDlcId1), {.name = kDlcId1}}});
-  EXPECT_TRUE(fake_prefs_.SetString(dlc_cohort_key, "old_value_dlc"));
-  EXPECT_TRUE(fake_prefs_.SetString(dlc_cohort_hint_key, "old_hint_dlc"));
-  EXPECT_TRUE(fake_prefs_.SetString(dlc_cohort_name_key, "old_name_dlc"));
+  EXPECT_TRUE(fake_prefs_->SetString(dlc_cohort_key, "old_value_dlc"));
+  EXPECT_TRUE(fake_prefs_->SetString(dlc_cohort_hint_key, "old_hint_dlc"));
+  EXPECT_TRUE(fake_prefs_->SetString(dlc_cohort_name_key, "old_name_dlc"));
   fake_update_response_.include_cohorts = true;
   fake_update_response_.cohort = "s/154454/8479665";
   fake_update_response_.cohorthint = "please-put-me-on-beta";
@@ -1340,48 +1341,48 @@
   ASSERT_TRUE(TestUpdateCheck());
 
   string value;
-  EXPECT_TRUE(fake_prefs_.GetString(kPrefsOmahaCohort, &value));
+  EXPECT_TRUE(fake_prefs_->GetString(kPrefsOmahaCohort, &value));
   EXPECT_EQ(fake_update_response_.cohort, value);
 
-  EXPECT_TRUE(fake_prefs_.GetString(kPrefsOmahaCohortHint, &value));
+  EXPECT_TRUE(fake_prefs_->GetString(kPrefsOmahaCohortHint, &value));
   EXPECT_EQ(fake_update_response_.cohorthint, value);
 
-  EXPECT_FALSE(fake_prefs_.GetString(kPrefsOmahaCohortName, &value));
+  EXPECT_FALSE(fake_prefs_->GetString(kPrefsOmahaCohortName, &value));
 
-  EXPECT_TRUE(fake_prefs_.GetString(dlc_cohort_key, &value));
+  EXPECT_TRUE(fake_prefs_->GetString(dlc_cohort_key, &value));
   EXPECT_EQ(fake_update_response_.dlc_cohort, value);
 
-  EXPECT_TRUE(fake_prefs_.GetString(dlc_cohort_hint_key, &value));
+  EXPECT_TRUE(fake_prefs_->GetString(dlc_cohort_hint_key, &value));
   EXPECT_EQ(fake_update_response_.dlc_cohorthint, value);
 
-  EXPECT_FALSE(fake_prefs_.GetString(dlc_cohort_name_key, &value));
+  EXPECT_FALSE(fake_prefs_->GetString(dlc_cohort_name_key, &value));
 }
 
 TEST_F(OmahaRequestActionTest, CohortsAreNotModifiedWhenMissing) {
   tuc_params_.http_response = fake_update_response_.GetUpdateResponse();
 
-  EXPECT_TRUE(fake_prefs_.SetString(kPrefsOmahaCohort, "old_value"));
+  EXPECT_TRUE(fake_prefs_->SetString(kPrefsOmahaCohort, "old_value"));
   const string dlc_cohort_key =
-      fake_prefs_.CreateSubKey({kDlcPrefsSubDir, kDlcId1, kPrefsOmahaCohort});
-  EXPECT_TRUE(fake_prefs_.SetString(dlc_cohort_key, "old_value_dlc"));
+      fake_prefs_->CreateSubKey({kDlcPrefsSubDir, kDlcId1, kPrefsOmahaCohort});
+  EXPECT_TRUE(fake_prefs_->SetString(dlc_cohort_key, "old_value_dlc"));
   ASSERT_TRUE(TestUpdateCheck());
 
   string value;
-  EXPECT_TRUE(fake_prefs_.GetString(kPrefsOmahaCohort, &value));
+  EXPECT_TRUE(fake_prefs_->GetString(kPrefsOmahaCohort, &value));
   EXPECT_EQ("old_value", value);
 
-  EXPECT_FALSE(fake_prefs_.GetString(kPrefsOmahaCohortHint, &value));
-  EXPECT_FALSE(fake_prefs_.GetString(kPrefsOmahaCohortName, &value));
+  EXPECT_FALSE(fake_prefs_->GetString(kPrefsOmahaCohortHint, &value));
+  EXPECT_FALSE(fake_prefs_->GetString(kPrefsOmahaCohortName, &value));
 
-  EXPECT_TRUE(fake_prefs_.GetString(dlc_cohort_key, &value));
+  EXPECT_TRUE(fake_prefs_->GetString(dlc_cohort_key, &value));
   EXPECT_EQ("old_value_dlc", value);
 
-  EXPECT_FALSE(fake_prefs_.GetString(
-      fake_prefs_.CreateSubKey(
+  EXPECT_FALSE(fake_prefs_->GetString(
+      fake_prefs_->CreateSubKey(
           {kDlcPrefsSubDir, kDlcId1, kPrefsOmahaCohortHint}),
       &value));
-  EXPECT_FALSE(fake_prefs_.GetString(
-      fake_prefs_.CreateSubKey(
+  EXPECT_FALSE(fake_prefs_->GetString(
+      fake_prefs_->CreateSubKey(
           {kDlcPrefsSubDir, kDlcId1, kPrefsOmahaCohortName}),
       &value));
 }
@@ -1398,13 +1399,13 @@
   ASSERT_TRUE(TestUpdateCheck());
 
   string value;
-  EXPECT_TRUE(fake_prefs_.GetString(kPrefsOmahaCohort, &value));
+  EXPECT_TRUE(fake_prefs_->GetString(kPrefsOmahaCohort, &value));
   EXPECT_EQ(fake_update_response_.cohort, value);
 
-  EXPECT_TRUE(fake_prefs_.GetString(kPrefsOmahaCohortHint, &value));
+  EXPECT_TRUE(fake_prefs_->GetString(kPrefsOmahaCohortHint, &value));
   EXPECT_EQ(fake_update_response_.cohorthint, value);
 
-  EXPECT_TRUE(fake_prefs_.GetString(kPrefsOmahaCohortName, &value));
+  EXPECT_TRUE(fake_prefs_->GetString(kPrefsOmahaCohortName, &value));
   EXPECT_EQ(fake_update_response_.cohortname, value);
 }
 
@@ -1429,42 +1430,42 @@
   ASSERT_TRUE(TestUpdateCheck());
 
   string value;
-  EXPECT_TRUE(fake_prefs_.GetString(kPrefsOmahaCohort, &value));
+  EXPECT_TRUE(fake_prefs_->GetString(kPrefsOmahaCohort, &value));
   EXPECT_EQ(fake_update_response_.cohort, value);
 
-  EXPECT_TRUE(fake_prefs_.GetString(kPrefsOmahaCohortHint, &value));
+  EXPECT_TRUE(fake_prefs_->GetString(kPrefsOmahaCohortHint, &value));
   EXPECT_EQ(fake_update_response_.cohorthint, value);
 
-  EXPECT_TRUE(fake_prefs_.GetString(kPrefsOmahaCohortName, &value));
+  EXPECT_TRUE(fake_prefs_->GetString(kPrefsOmahaCohortName, &value));
   EXPECT_EQ(fake_update_response_.cohortname, value);
 
-  EXPECT_TRUE(fake_prefs_.GetString(
-      fake_prefs_.CreateSubKey({kDlcPrefsSubDir, kDlcId1, kPrefsOmahaCohort}),
+  EXPECT_TRUE(fake_prefs_->GetString(
+      fake_prefs_->CreateSubKey({kDlcPrefsSubDir, kDlcId1, kPrefsOmahaCohort}),
       &value));
   EXPECT_EQ(fake_update_response_.dlc_cohort, value);
-  EXPECT_TRUE(fake_prefs_.GetString(
-      fake_prefs_.CreateSubKey({kDlcPrefsSubDir, kDlcId2, kPrefsOmahaCohort}),
+  EXPECT_TRUE(fake_prefs_->GetString(
+      fake_prefs_->CreateSubKey({kDlcPrefsSubDir, kDlcId2, kPrefsOmahaCohort}),
       &value));
   EXPECT_EQ(fake_update_response_.dlc_cohort, value);
 
-  EXPECT_TRUE(fake_prefs_.GetString(
-      fake_prefs_.CreateSubKey(
+  EXPECT_TRUE(fake_prefs_->GetString(
+      fake_prefs_->CreateSubKey(
           {kDlcPrefsSubDir, kDlcId1, kPrefsOmahaCohortHint}),
       &value));
   EXPECT_EQ(fake_update_response_.dlc_cohorthint, value);
-  EXPECT_TRUE(fake_prefs_.GetString(
-      fake_prefs_.CreateSubKey(
+  EXPECT_TRUE(fake_prefs_->GetString(
+      fake_prefs_->CreateSubKey(
           {kDlcPrefsSubDir, kDlcId2, kPrefsOmahaCohortHint}),
       &value));
   EXPECT_EQ(fake_update_response_.dlc_cohorthint, value);
 
-  EXPECT_TRUE(fake_prefs_.GetString(
-      fake_prefs_.CreateSubKey(
+  EXPECT_TRUE(fake_prefs_->GetString(
+      fake_prefs_->CreateSubKey(
           {kDlcPrefsSubDir, kDlcId1, kPrefsOmahaCohortName}),
       &value));
   EXPECT_EQ(fake_update_response_.dlc_cohortname, value);
-  EXPECT_TRUE(fake_prefs_.GetString(
-      fake_prefs_.CreateSubKey(
+  EXPECT_TRUE(fake_prefs_->GetString(
+      fake_prefs_->CreateSubKey(
           {kDlcPrefsSubDir, kDlcId2, kPrefsOmahaCohortName}),
       &value));
   EXPECT_EQ(fake_update_response_.dlc_cohortname, value);
@@ -1634,9 +1635,9 @@
   request_params_.set_target_channel("unittest_track&lt;");
   request_params_.set_lts_tag("unittest_hint&lt;");
   request_params_.set_hwid("<OEM MODEL>");
-  fake_prefs_.SetString(kPrefsOmahaCohort, "evil\nstring");
-  fake_prefs_.SetString(kPrefsOmahaCohortHint, "evil&string\\");
-  fake_prefs_.SetString(
+  fake_prefs_->SetString(kPrefsOmahaCohort, "evil\nstring");
+  fake_prefs_->SetString(kPrefsOmahaCohortHint, "evil&string\\");
+  fake_prefs_->SetString(
       kPrefsOmahaCohortName,
       base::JoinString(vector<string>(100, "My spoon is too big."), " "));
   tuc_params_.http_response = "invalid xml>";
@@ -1875,7 +1876,7 @@
   tuc_params_.expected_check_result = metrics::CheckResult::kNoUpdateAvailable;
   tuc_params_.expected_check_reaction = metrics::CheckReaction::kUnset;
   request_params_.set_autoupdate_token(autoupdate_token);
-  fake_prefs_.SetString(kPrefsOmahaCohortHint, omaha_cohort_hint);
+  fake_prefs_->SetString(kPrefsOmahaCohortHint, omaha_cohort_hint);
 
   ASSERT_TRUE(TestUpdateCheck());
 
@@ -1895,7 +1896,7 @@
   tuc_params_.http_response = fake_update_response_.GetNoUpdateResponse();
   tuc_params_.expected_check_result = metrics::CheckResult::kNoUpdateAvailable;
   tuc_params_.expected_check_reaction = metrics::CheckReaction::kUnset;
-  fake_prefs_.SetString(kPrefsOmahaCohortHint, omaha_cohort_hint);
+  fake_prefs_->SetString(kPrefsOmahaCohortHint, omaha_cohort_hint);
 
   ASSERT_TRUE(TestUpdateCheck());
 
@@ -2222,7 +2223,7 @@
   ASSERT_FALSE(TestUpdateCheck());
 
   int64_t timestamp = 0;
-  ASSERT_TRUE(fake_prefs_.GetInt64(kPrefsUpdateFirstSeenAt, &timestamp));
+  ASSERT_TRUE(fake_prefs_->GetInt64(kPrefsUpdateFirstSeenAt, &timestamp));
   EXPECT_EQ(arbitrary_date.ToInternalValue(), timestamp);
   EXPECT_FALSE(response_.update_exists);
 
@@ -2244,7 +2245,7 @@
   ASSERT_TRUE(Time::FromString("1/1/2012", &t1));
   ASSERT_TRUE(Time::FromString("1/3/2012", &t2));
   ASSERT_TRUE(
-      fake_prefs_.SetInt64(kPrefsUpdateFirstSeenAt, t1.ToInternalValue()));
+      fake_prefs_->SetInt64(kPrefsUpdateFirstSeenAt, t1.ToInternalValue()));
   FakeSystemState::Get()->fake_clock()->SetWallclockTime(t2);
 
   tuc_params_.http_response = fake_update_response_.GetUpdateResponse();
@@ -2254,7 +2255,7 @@
 
   // Make sure the timestamp t1 is unchanged showing that it was reused.
   int64_t timestamp = 0;
-  ASSERT_TRUE(fake_prefs_.GetInt64(kPrefsUpdateFirstSeenAt, &timestamp));
+  ASSERT_TRUE(fake_prefs_->GetInt64(kPrefsUpdateFirstSeenAt, &timestamp));
   ASSERT_TRUE(timestamp == t1.ToInternalValue());
 }
 
@@ -2322,7 +2323,7 @@
 // Checks that the initial ping with a=-1 r=-1 is not send when the device
 // was powerwashed.
 TEST_F(OmahaRequestActionTest, PingWhenPowerwashed) {
-  fake_prefs_.SetString(kPrefsPreviousVersion, "");
+  fake_prefs_->SetString(kPrefsPreviousVersion, "");
 
   // Flag that the device was powerwashed in the past.
   FakeSystemState::Get()->fake_hardware()->SetPowerwashCount(1);
@@ -2339,7 +2340,7 @@
 // Checks that the initial ping with a=-1 r=-1 is not send when the device
 // first_active_omaha_ping_sent is set.
 TEST_F(OmahaRequestActionTest, PingWhenFirstActiveOmahaPingIsSent) {
-  fake_prefs_.SetString(kPrefsPreviousVersion, "");
+  fake_prefs_->SetString(kPrefsPreviousVersion, "");
 
   // Flag that the device was not powerwashed in the past.
   FakeSystemState::Get()->fake_hardware()->SetPowerwashCount(0);
@@ -2361,7 +2362,7 @@
 // Checks that the event 54 is sent on a reboot to a new update.
 TEST_F(OmahaRequestActionTest, RebootAfterUpdateEvent) {
   // Flag that the device was updated in a previous boot.
-  fake_prefs_.SetString(kPrefsPreviousVersion, "1.2.3.4");
+  fake_prefs_->SetString(kPrefsPreviousVersion, "1.2.3.4");
 
   tuc_params_.http_response = fake_update_response_.GetNoUpdateResponse();
   tuc_params_.expected_check_result = metrics::CheckResult::kNoUpdateAvailable;
@@ -2378,9 +2379,9 @@
             post_str_.find("previousversion=\"1.2.3.4\"></event>"));
 
   // The previous version flag should have been removed.
-  EXPECT_TRUE(fake_prefs_.Exists(kPrefsPreviousVersion));
+  EXPECT_TRUE(fake_prefs_->Exists(kPrefsPreviousVersion));
   string prev_version;
-  EXPECT_TRUE(fake_prefs_.GetString(kPrefsPreviousVersion, &prev_version));
+  EXPECT_TRUE(fake_prefs_->GetString(kPrefsPreviousVersion, &prev_version));
   EXPECT_TRUE(prev_version.empty());
 }
 
@@ -2537,29 +2538,29 @@
 
   // Check that we parse elapsed_days in the Omaha Response correctly.
   // and that the kPrefsInstallDateDays value is written to.
-  EXPECT_FALSE(fake_prefs_.Exists(kPrefsInstallDateDays));
+  EXPECT_FALSE(fake_prefs_->Exists(kPrefsInstallDateDays));
   EXPECT_TRUE(InstallDateParseHelper("42", &response_));
   EXPECT_TRUE(response_.update_exists);
   EXPECT_EQ(42, response_.install_date_days);
-  EXPECT_TRUE(fake_prefs_.Exists(kPrefsInstallDateDays));
+  EXPECT_TRUE(fake_prefs_->Exists(kPrefsInstallDateDays));
   int64_t prefs_days;
-  EXPECT_TRUE(fake_prefs_.GetInt64(kPrefsInstallDateDays, &prefs_days));
+  EXPECT_TRUE(fake_prefs_->GetInt64(kPrefsInstallDateDays, &prefs_days));
   EXPECT_EQ(prefs_days, 42);
 
   // If there already is a value set, we shouldn't do anything.
   EXPECT_TRUE(InstallDateParseHelper("7", &response_));
   EXPECT_TRUE(response_.update_exists);
   EXPECT_EQ(7, response_.install_date_days);
-  EXPECT_TRUE(fake_prefs_.GetInt64(kPrefsInstallDateDays, &prefs_days));
+  EXPECT_TRUE(fake_prefs_->GetInt64(kPrefsInstallDateDays, &prefs_days));
   EXPECT_EQ(prefs_days, 42);
 
   // Note that elapsed_days is not necessarily divisible by 7 so check
   // that we round down correctly when populating kPrefsInstallDateDays.
-  EXPECT_TRUE(fake_prefs_.Delete(kPrefsInstallDateDays));
+  EXPECT_TRUE(fake_prefs_->Delete(kPrefsInstallDateDays));
   EXPECT_TRUE(InstallDateParseHelper("23", &response_));
   EXPECT_TRUE(response_.update_exists);
   EXPECT_EQ(23, response_.install_date_days);
-  EXPECT_TRUE(fake_prefs_.GetInt64(kPrefsInstallDateDays, &prefs_days));
+  EXPECT_TRUE(fake_prefs_->GetInt64(kPrefsInstallDateDays, &prefs_days));
   EXPECT_EQ(prefs_days, 21);
 
   // Check that we correctly handle elapsed_days not being included in
@@ -2574,7 +2575,7 @@
 TEST_F(OmahaRequestActionTest, GetInstallDateWhenNoPrefsNorOOBE) {
   FakeSystemState::Get()->fake_hardware()->UnsetIsOOBEComplete();
   EXPECT_EQ(OmahaRequestAction::GetInstallDate(), -1);
-  EXPECT_FALSE(fake_prefs_.Exists(kPrefsInstallDateDays));
+  EXPECT_FALSE(fake_prefs_->Exists(kPrefsInstallDateDays));
 }
 
 // If OOBE is complete and happened on a valid date (e.g. after Jan
@@ -2585,7 +2586,7 @@
   Time oobe_date = Time::FromTimeT(42);  // Dec 31, 1969 16:00:42 PST.
   FakeSystemState::Get()->fake_hardware()->SetIsOOBEComplete(oobe_date);
   EXPECT_EQ(OmahaRequestAction::GetInstallDate(), -1);
-  EXPECT_FALSE(fake_prefs_.Exists(kPrefsInstallDateDays));
+  EXPECT_FALSE(fake_prefs_->Exists(kPrefsInstallDateDays));
 }
 
 // Then check with a valid date. The date Jan 20, 2007 0:00 PST
@@ -2594,10 +2595,10 @@
   Time oobe_date = Time::FromTimeT(1169280000);  // Jan 20, 2007 0:00 PST.
   FakeSystemState::Get()->fake_hardware()->SetIsOOBEComplete(oobe_date);
   EXPECT_EQ(OmahaRequestAction::GetInstallDate(), 14);
-  EXPECT_TRUE(fake_prefs_.Exists(kPrefsInstallDateDays));
+  EXPECT_TRUE(fake_prefs_->Exists(kPrefsInstallDateDays));
 
   int64_t prefs_days;
-  EXPECT_TRUE(fake_prefs_.GetInt64(kPrefsInstallDateDays, &prefs_days));
+  EXPECT_TRUE(fake_prefs_->GetInt64(kPrefsInstallDateDays, &prefs_days));
   EXPECT_EQ(prefs_days, 14);
 }
 
@@ -2607,20 +2608,20 @@
 // there's a prefs file, we should still get 14.
 TEST_F(OmahaRequestActionTest, GetInstallDateWhenOOBECompletedDateChanges) {
   // Set a valid date in the prefs first.
-  EXPECT_TRUE(fake_prefs_.SetInt64(kPrefsInstallDateDays, 14));
+  EXPECT_TRUE(fake_prefs_->SetInt64(kPrefsInstallDateDays, 14));
 
   Time oobe_date = Time::FromTimeT(1170144000);  // Jan 30, 2007 0:00 PST.
   FakeSystemState::Get()->fake_hardware()->SetIsOOBEComplete(oobe_date);
   EXPECT_EQ(OmahaRequestAction::GetInstallDate(), 14);
 
   int64_t prefs_days;
-  EXPECT_TRUE(fake_prefs_.GetInt64(kPrefsInstallDateDays, &prefs_days));
+  EXPECT_TRUE(fake_prefs_->GetInt64(kPrefsInstallDateDays, &prefs_days));
   EXPECT_EQ(prefs_days, 14);
 
   // If we delete the prefs file, we should get 28 days.
-  EXPECT_TRUE(fake_prefs_.Delete(kPrefsInstallDateDays));
+  EXPECT_TRUE(fake_prefs_->Delete(kPrefsInstallDateDays));
   EXPECT_EQ(OmahaRequestAction::GetInstallDate(), 28);
-  EXPECT_TRUE(fake_prefs_.GetInt64(kPrefsInstallDateDays, &prefs_days));
+  EXPECT_TRUE(fake_prefs_->GetInt64(kPrefsInstallDateDays, &prefs_days));
   EXPECT_EQ(prefs_days, 28);
 }
 
@@ -2809,11 +2810,11 @@
   ASSERT_TRUE(TestUpdateCheck());
 
   EXPECT_TRUE(response_.update_exists);
-  EXPECT_TRUE(fake_prefs_.Exists(kPrefsUpdateFirstSeenAt));
+  EXPECT_TRUE(fake_prefs_->Exists(kPrefsUpdateFirstSeenAt));
 
   int64_t stored_first_seen_at_time;
-  EXPECT_TRUE(fake_prefs_.GetInt64(kPrefsUpdateFirstSeenAt,
-                                   &stored_first_seen_at_time));
+  EXPECT_TRUE(fake_prefs_->GetInt64(kPrefsUpdateFirstSeenAt,
+                                    &stored_first_seen_at_time));
   EXPECT_EQ(now.ToInternalValue(), stored_first_seen_at_time);
 }
 
@@ -2831,7 +2832,7 @@
   ASSERT_TRUE(TestUpdateCheck());
 
   EXPECT_FALSE(response_.update_exists);
-  EXPECT_FALSE(fake_prefs_.Exists(kPrefsUpdateFirstSeenAt));
+  EXPECT_FALSE(fake_prefs_->Exists(kPrefsUpdateFirstSeenAt));
 }
 
 TEST_F(OmahaRequestActionTest, InstallTest) {
@@ -3099,14 +3100,14 @@
 
   int64_t temp_int;
   // If there was no ping, the metadata files shouldn't exist yet.
-  EXPECT_FALSE(fake_prefs_.GetInt64(active_key_, &temp_int));
-  EXPECT_FALSE(fake_prefs_.GetInt64(last_active_key_, &temp_int));
-  EXPECT_FALSE(fake_prefs_.GetInt64(last_rollcall_key_, &temp_int));
+  EXPECT_FALSE(fake_prefs_->GetInt64(active_key_, &temp_int));
+  EXPECT_FALSE(fake_prefs_->GetInt64(last_active_key_, &temp_int));
+  EXPECT_FALSE(fake_prefs_->GetInt64(last_rollcall_key_, &temp_int));
 }
 
 TEST_F(OmahaRequestActionDlcPingTest, StorePingReplyActiveTest) {
   // Create Active value
-  fake_prefs_.SetInt64(active_key_, 0);
+  fake_prefs_->SetInt64(active_key_, 0);
 
   OmahaRequestParams::AppParams app_param = {
       .active_counting_type = OmahaRequestParams::kDateBased,
@@ -3119,17 +3120,17 @@
   int64_t temp_int;
   string temp_str;
   ASSERT_TRUE(TestUpdateCheck());
-  EXPECT_TRUE(fake_prefs_.GetInt64(active_key_, &temp_int));
+  EXPECT_TRUE(fake_prefs_->GetInt64(active_key_, &temp_int));
   EXPECT_EQ(temp_int, kPingInactiveValue);
-  EXPECT_TRUE(fake_prefs_.GetString(last_active_key_, &temp_str));
+  EXPECT_TRUE(fake_prefs_->GetString(last_active_key_, &temp_str));
   EXPECT_EQ(temp_str, "4763");
-  EXPECT_TRUE(fake_prefs_.GetString(last_rollcall_key_, &temp_str));
+  EXPECT_TRUE(fake_prefs_->GetString(last_rollcall_key_, &temp_str));
   EXPECT_EQ(temp_str, "4763");
 }
 
 TEST_F(OmahaRequestActionDlcPingTest, StorePingReplyInactiveTest) {
   // Create Active value
-  fake_prefs_.SetInt64(active_key_, 0);
+  fake_prefs_->SetInt64(active_key_, 0);
 
   OmahaRequestParams::AppParams app_param = {
       .active_counting_type = OmahaRequestParams::kDateBased,
@@ -3140,16 +3141,16 @@
       {{request_params_.GetDlcAppId(dlc_id_), app_param}});
 
   // Set the previous active value to an older value than 4763.
-  fake_prefs_.SetString(last_active_key_, "555");
+  fake_prefs_->SetString(last_active_key_, "555");
 
   int64_t temp_int;
   ASSERT_TRUE(TestUpdateCheck());
-  EXPECT_TRUE(fake_prefs_.GetInt64(active_key_, &temp_int));
+  EXPECT_TRUE(fake_prefs_->GetInt64(active_key_, &temp_int));
   EXPECT_EQ(temp_int, kPingInactiveValue);
   string temp_str;
-  EXPECT_TRUE(fake_prefs_.GetString(last_active_key_, &temp_str));
+  EXPECT_TRUE(fake_prefs_->GetString(last_active_key_, &temp_str));
   EXPECT_EQ(temp_str, "555");
-  EXPECT_TRUE(fake_prefs_.GetString(last_rollcall_key_, &temp_str));
+  EXPECT_TRUE(fake_prefs_->GetString(last_rollcall_key_, &temp_str));
   EXPECT_EQ(temp_str, "4763");
 }
 
diff --git a/cros/omaha_request_builder_xml_unittest.cc b/cros/omaha_request_builder_xml_unittest.cc
index 1ef0278..76a7241 100644
--- a/cros/omaha_request_builder_xml_unittest.cc
+++ b/cros/omaha_request_builder_xml_unittest.cc
@@ -24,7 +24,6 @@
 #include <base/strings/stringprintf.h>
 #include <gtest/gtest.h>
 
-#include "update_engine/common/fake_prefs.h"
 #include "update_engine/cros/fake_system_state.h"
 
 using std::pair;
@@ -374,23 +373,8 @@
   constexpr char kDlcId[] = "test-dlc-id";
   params_.set_dlc_apps_params(
       {{params_.GetDlcAppId(kDlcId), {.name = kDlcId}}});
-  auto* mock_prefs = FakeSystemState::Get()->mock_prefs();
   OmahaEvent event(OmahaEvent::kTypeUpdateDownloadStarted);
   OmahaRequestBuilderXml omaha_request{&event, false, false, 0, 0, 0, ""};
-  // OS App ID Expectations.
-  EXPECT_CALL(*mock_prefs, Exists(kPrefsOmahaCohort));
-  EXPECT_CALL(*mock_prefs, Exists(kPrefsOmahaCohortName));
-  EXPECT_CALL(*mock_prefs, Exists(kPrefsOmahaCohortHint));
-  // DLC App ID Expectations.
-  EXPECT_CALL(*mock_prefs,
-              Exists(PrefsInterface::CreateSubKey(
-                  {kDlcPrefsSubDir, kDlcId, kPrefsOmahaCohort})));
-  EXPECT_CALL(*mock_prefs,
-              Exists(PrefsInterface::CreateSubKey(
-                  {kDlcPrefsSubDir, kDlcId, kPrefsOmahaCohortName})));
-  EXPECT_CALL(*mock_prefs,
-              Exists(PrefsInterface::CreateSubKey(
-                  {kDlcPrefsSubDir, kDlcId, kPrefsOmahaCohortHint})));
   const string request_xml = omaha_request.GetRequest();
 
   // Check that no cohorts are in the request.
@@ -405,23 +389,22 @@
   const string kDlcId = "test-dlc-id";
   params_.set_dlc_apps_params(
       {{params_.GetDlcAppId(kDlcId), {.name = kDlcId}}});
-  FakePrefs fake_prefs;
-  FakeSystemState::Get()->set_prefs(&fake_prefs);
+  auto* fake_prefs = FakeSystemState::Get()->fake_prefs();
   OmahaEvent event(OmahaEvent::kTypeUpdateDownloadStarted);
   OmahaRequestBuilderXml omaha_request{&event, false, false, 0, 0, 0, ""};
   // DLC App ID Expectations.
   const string dlc_cohort_key = PrefsInterface::CreateSubKey(
       {kDlcPrefsSubDir, kDlcId, kPrefsOmahaCohort});
   const string kDlcCohortVal = "test-cohort";
-  EXPECT_TRUE(fake_prefs.SetString(dlc_cohort_key, kDlcCohortVal));
+  EXPECT_TRUE(fake_prefs->SetString(dlc_cohort_key, kDlcCohortVal));
   const string dlc_cohort_name_key = PrefsInterface::CreateSubKey(
       {kDlcPrefsSubDir, kDlcId, kPrefsOmahaCohortName});
   const string kDlcCohortNameVal = "test-cohortname";
-  EXPECT_TRUE(fake_prefs.SetString(dlc_cohort_name_key, kDlcCohortNameVal));
+  EXPECT_TRUE(fake_prefs->SetString(dlc_cohort_name_key, kDlcCohortNameVal));
   const string dlc_cohort_hint_key = PrefsInterface::CreateSubKey(
       {kDlcPrefsSubDir, kDlcId, kPrefsOmahaCohortHint});
   const string kDlcCohortHintVal = "test-cohortval";
-  EXPECT_TRUE(fake_prefs.SetString(dlc_cohort_hint_key, kDlcCohortHintVal));
+  EXPECT_TRUE(fake_prefs->SetString(dlc_cohort_hint_key, kDlcCohortHintVal));
   const string request_xml = omaha_request.GetRequest();
 
   EXPECT_EQ(1,
diff --git a/cros/omaha_request_params_unittest.cc b/cros/omaha_request_params_unittest.cc
index fdbb834..2d67ec0 100644
--- a/cros/omaha_request_params_unittest.cc
+++ b/cros/omaha_request_params_unittest.cc
@@ -25,7 +25,6 @@
 #include <gtest/gtest.h>
 
 #include "update_engine/common/constants.h"
-#include "update_engine/common/fake_prefs.h"
 #include "update_engine/common/platform_constants.h"
 #include "update_engine/common/test_utils.h"
 #include "update_engine/common/utils.h"
@@ -46,7 +45,6 @@
     ASSERT_TRUE(tempdir_.CreateUniqueTempDir());
     params_.set_root(tempdir_.GetPath().value());
     FakeSystemState::CreateInstance();
-    FakeSystemState::Get()->set_prefs(&fake_prefs_);
     SetLockDown(false);
   }
 
@@ -56,8 +54,6 @@
   }
 
   OmahaRequestParams params_;
-  FakePrefs fake_prefs_;
-
   base::ScopedTempDir tempdir_;
 };
 
diff --git a/cros/omaha_response_handler_action_unittest.cc b/cros/omaha_response_handler_action_unittest.cc
index 3de351d..c9b46b1 100644
--- a/cros/omaha_response_handler_action_unittest.cc
+++ b/cros/omaha_response_handler_action_unittest.cc
@@ -81,6 +81,8 @@
  protected:
   void SetUp() override {
     FakeSystemState::CreateInstance();
+    // Enable MockPrefs;
+    FakeSystemState::Get()->set_prefs(nullptr);
     FakeBootControl* fake_boot_control =
         FakeSystemState::Get()->fake_boot_control();
     fake_boot_control->SetPartitionDevice(kPartitionNameKernel, 0, "/dev/sdz2");
diff --git a/cros/payload_state.cc b/cros/payload_state.cc
index 028e8fa..d417ef5 100644
--- a/cros/payload_state.cc
+++ b/cros/payload_state.cc
@@ -831,7 +831,6 @@
 }
 
 void PayloadState::ResetRollbackVersion() {
-  CHECK(powerwash_safe_prefs_);
   rollback_version_ = "";
   powerwash_safe_prefs_->Delete(kPrefsRollbackVersion);
 }
@@ -880,7 +879,6 @@
 }
 
 void PayloadState::LoadResponseSignature() {
-  CHECK(prefs_);
   string stored_value;
   if (prefs_->Exists(kPrefsCurrentResponseSignature) &&
       prefs_->GetString(kPrefsCurrentResponseSignature, &stored_value)) {
@@ -889,7 +887,6 @@
 }
 
 void PayloadState::SetResponseSignature(const string& response_signature) {
-  CHECK(prefs_);
   response_signature_ = response_signature;
   LOG(INFO) << "Current Response Signature = \n" << response_signature_;
   prefs_->SetString(kPrefsCurrentResponseSignature, response_signature_);
@@ -912,7 +909,6 @@
 
 void PayloadState::SetFullPayloadAttemptNumber(
     int full_payload_attempt_number) {
-  CHECK(prefs_);
   full_payload_attempt_number_ = full_payload_attempt_number;
   LOG(INFO) << "Full Payload Attempt Number = " << full_payload_attempt_number_;
   prefs_->SetInt64(kPrefsFullPayloadAttemptNumber,
@@ -920,7 +916,6 @@
 }
 
 void PayloadState::SetPayloadIndex(size_t payload_index) {
-  CHECK(prefs_);
   payload_index_ = payload_index;
   LOG(INFO) << "Payload Index = " << payload_index_;
   prefs_->SetInt64(kPrefsUpdateStatePayloadIndex, payload_index_);
@@ -941,7 +936,6 @@
 }
 
 void PayloadState::SetUrlIndex(uint32_t url_index) {
-  CHECK(prefs_);
   url_index_ = url_index;
   LOG(INFO) << "Current URL Index = " << url_index_;
   prefs_->SetInt64(kPrefsCurrentUrlIndex, url_index_);
@@ -957,7 +951,6 @@
 }
 
 void PayloadState::SetScatteringWaitPeriod(TimeDelta wait_period) {
-  CHECK(prefs_);
   scattering_wait_period_ = wait_period;
   LOG(INFO) << "Scattering Wait Period (seconds) = "
             << scattering_wait_period_.InSeconds();
@@ -975,7 +968,6 @@
 }
 
 void PayloadState::SetStagingWaitPeriod(TimeDelta wait_period) {
-  CHECK(prefs_);
   staging_wait_period_ = wait_period;
   LOG(INFO) << "Staging Wait Period (days) =" << staging_wait_period_.InDays();
   if (staging_wait_period_.InSeconds() > 0) {
@@ -991,7 +983,6 @@
 }
 
 void PayloadState::SetUrlSwitchCount(uint32_t url_switch_count) {
-  CHECK(prefs_);
   url_switch_count_ = url_switch_count;
   LOG(INFO) << "URL Switch Count = " << url_switch_count_;
   prefs_->SetInt64(kPrefsUrlSwitchCount, url_switch_count_);
@@ -1002,7 +993,6 @@
 }
 
 void PayloadState::SetUrlFailureCount(uint32_t url_failure_count) {
-  CHECK(prefs_);
   url_failure_count_ = url_failure_count;
   LOG(INFO) << "Current URL (Url" << GetUrlIndex()
             << ")'s Failure Count = " << url_failure_count_;
@@ -1010,7 +1000,6 @@
 }
 
 void PayloadState::LoadBackoffExpiryTime() {
-  CHECK(prefs_);
   int64_t stored_value;
   if (!prefs_->Exists(kPrefsBackoffExpiryTime))
     return;
@@ -1029,7 +1018,6 @@
 }
 
 void PayloadState::SetBackoffExpiryTime(const Time& new_time) {
-  CHECK(prefs_);
   backoff_expiry_time_ = new_time;
   LOG(INFO) << "Backoff Expiry Time = "
             << utils::ToString(backoff_expiry_time_);
@@ -1047,9 +1035,6 @@
 void PayloadState::LoadUpdateTimestampStart() {
   int64_t stored_value;
   Time stored_time;
-
-  CHECK(prefs_);
-
   Time now = SystemState::Get()->clock()->GetWallclockTime();
 
   if (!prefs_->Exists(kPrefsUpdateTimestampStart)) {
@@ -1098,8 +1083,6 @@
   int64_t stored_value;
   TimeDelta stored_delta;
 
-  CHECK(prefs_);
-
   if (!prefs_->Exists(kPrefsUpdateDurationUptime)) {
     // The preference missing is not unexpected - in that case, just
     // we'll use zero as the delta
@@ -1130,14 +1113,12 @@
 }
 
 void PayloadState::LoadRollbackHappened() {
-  CHECK(powerwash_safe_prefs_);
   bool rollback_happened = false;
   powerwash_safe_prefs_->GetBoolean(kPrefsRollbackHappened, &rollback_happened);
   SetRollbackHappened(rollback_happened);
 }
 
 void PayloadState::SetRollbackHappened(bool rollback_happened) {
-  CHECK(powerwash_safe_prefs_);
   LOG(INFO) << "Setting rollback-happened to " << rollback_happened << ".";
   rollback_happened_ = rollback_happened;
   if (rollback_happened) {
@@ -1149,7 +1130,6 @@
 }
 
 void PayloadState::LoadRollbackVersion() {
-  CHECK(powerwash_safe_prefs_);
   string rollback_version;
   if (powerwash_safe_prefs_->GetString(kPrefsRollbackVersion,
                                        &rollback_version)) {
@@ -1158,7 +1138,6 @@
 }
 
 void PayloadState::SetRollbackVersion(const string& rollback_version) {
-  CHECK(powerwash_safe_prefs_);
   LOG(INFO) << "Excluding version " << rollback_version;
   rollback_version_ = rollback_version;
   powerwash_safe_prefs_->SetString(kPrefsRollbackVersion, rollback_version);
@@ -1167,7 +1146,6 @@
 void PayloadState::SetUpdateDurationUptimeExtended(const TimeDelta& value,
                                                    const Time& timestamp,
                                                    bool use_logging) {
-  CHECK(prefs_);
   update_duration_uptime_ = value;
   update_duration_uptime_timestamp_ = timestamp;
   prefs_->SetInt64(kPrefsUpdateDurationUptime,
@@ -1206,8 +1184,6 @@
 void PayloadState::SetCurrentBytesDownloaded(DownloadSource source,
                                              uint64_t current_bytes_downloaded,
                                              bool log) {
-  CHECK(prefs_);
-
   if (source >= kNumDownloadSources)
     return;
 
@@ -1229,8 +1205,6 @@
 void PayloadState::SetTotalBytesDownloaded(DownloadSource source,
                                            uint64_t total_bytes_downloaded,
                                            bool log) {
-  CHECK(prefs_);
-
   if (source >= kNumDownloadSources)
     return;
 
@@ -1249,7 +1223,6 @@
 }
 
 void PayloadState::SetNumResponsesSeen(int num_responses_seen) {
-  CHECK(prefs_);
   num_responses_seen_ = num_responses_seen;
   LOG(INFO) << "Num Responses Seen = " << num_responses_seen_;
   prefs_->SetInt64(kPrefsNumResponsesSeen, num_responses_seen_);
@@ -1389,7 +1362,6 @@
 void PayloadState::SetP2PNumAttempts(int value) {
   p2p_num_attempts_ = value;
   LOG(INFO) << "p2p Num Attempts = " << p2p_num_attempts_;
-  CHECK(prefs_);
   prefs_->SetInt64(kPrefsP2PNumAttempts, value);
 }
 
@@ -1405,7 +1377,6 @@
   p2p_first_attempt_timestamp_ = time;
   LOG(INFO) << "p2p First Attempt Timestamp = "
             << utils::ToString(p2p_first_attempt_timestamp_);
-  CHECK(prefs_);
   int64_t stored_value = time.ToInternalValue();
   prefs_->SetInt64(kPrefsP2PFirstAttemptTimestamp, stored_value);
 }
@@ -1418,7 +1389,6 @@
 }
 
 void PayloadState::P2PNewAttempt() {
-  CHECK(prefs_);
   // Set timestamp, if it hasn't been set already
   if (p2p_first_attempt_timestamp_.is_null()) {
     SetP2PFirstAttemptTimestamp(
diff --git a/cros/payload_state.h b/cros/payload_state.h
index ad19074..db54865 100644
--- a/cros/payload_state.h
+++ b/cros/payload_state.h
@@ -483,10 +483,9 @@
   size_t payload_index_ = 0;
 
   // The index of the current URL.  This type is different from the one in the
-  // accessor methods because PrefsInterface supports only int64_t but we want
+  // accessor methods because |PrefsInterface| supports only int64_t but we want
   // to provide a stronger abstraction of uint32_t.  Each update to this value
-  // is persisted so we resume from the same value in case of a process
-  // restart.
+  // is persisted so we resume from the same value in case of a process restart.
   size_t url_index_;
 
   // The count of failures encountered in the current attempt to download using
diff --git a/cros/payload_state_unittest.cc b/cros/payload_state_unittest.cc
index 9370a02..5478fca 100644
--- a/cros/payload_state_unittest.cc
+++ b/cros/payload_state_unittest.cc
@@ -25,7 +25,6 @@
 #include "update_engine/common/constants.h"
 #include "update_engine/common/excluder_interface.h"
 #include "update_engine/common/fake_hardware.h"
-#include "update_engine/common/fake_prefs.h"
 #include "update_engine/common/metrics_reporter_interface.h"
 #include "update_engine/common/mock_excluder.h"
 #include "update_engine/common/mock_prefs.h"
@@ -108,11 +107,15 @@
 class PayloadStateTest : public ::testing::Test {
  public:
   void SetUp() { FakeSystemState::CreateInstance(); }
+
+  // TODO(b/171829801): Replace all the |MockPrefs| in this file with
+  // |FakePrefs| so we don't have to catch every single unimportant mock call.
 };
 
 TEST_F(PayloadStateTest, SetResponseWorksWithEmptyResponse) {
   OmahaResponse response;
-  NiceMock<MockPrefs>* prefs = FakeSystemState::Get()->mock_prefs();
+  FakeSystemState::Get()->set_prefs(nullptr);
+  auto* prefs = FakeSystemState::Get()->mock_prefs();
   EXPECT_CALL(*prefs, SetInt64(_, _)).Times(AnyNumber());
   EXPECT_CALL(*prefs, SetInt64(kPrefsPayloadAttemptNumber, 0))
       .Times(AtLeast(1));
@@ -154,7 +157,8 @@
                                .metadata_size = 58123,
                                .metadata_signature = "msign",
                                .hash = "hash"});
-  NiceMock<MockPrefs>* prefs = FakeSystemState::Get()->mock_prefs();
+  FakeSystemState::Get()->set_prefs(nullptr);
+  auto* prefs = FakeSystemState::Get()->mock_prefs();
   EXPECT_CALL(*prefs, SetInt64(_, _)).Times(AnyNumber());
   EXPECT_CALL(*prefs, SetInt64(kPrefsPayloadAttemptNumber, 0))
       .Times(AtLeast(1));
@@ -205,7 +209,8 @@
                                .metadata_size = 558123,
                                .metadata_signature = "metasign",
                                .hash = "rhash"});
-  NiceMock<MockPrefs>* prefs = FakeSystemState::Get()->mock_prefs();
+  FakeSystemState::Get()->set_prefs(nullptr);
+  auto* prefs = FakeSystemState::Get()->mock_prefs();
   EXPECT_CALL(*prefs, SetInt64(_, _)).Times(AnyNumber());
   EXPECT_CALL(*prefs, SetInt64(kPrefsPayloadAttemptNumber, 0))
       .Times(AtLeast(1));
@@ -248,7 +253,8 @@
 
 TEST_F(PayloadStateTest, CanAdvanceUrlIndexCorrectly) {
   OmahaResponse response;
-  NiceMock<MockPrefs>* prefs = FakeSystemState::Get()->mock_prefs();
+  FakeSystemState::Get()->set_prefs(nullptr);
+  auto* prefs = FakeSystemState::Get()->mock_prefs();
   PayloadState payload_state;
 
   EXPECT_CALL(*prefs, SetInt64(_, _)).Times(AnyNumber());
@@ -350,7 +356,8 @@
   OmahaResponse response;
   PayloadState payload_state;
   int progress_bytes = 100;
-  NiceMock<MockPrefs>* prefs = FakeSystemState::Get()->mock_prefs();
+  FakeSystemState::Get()->set_prefs(nullptr);
+  auto* prefs = FakeSystemState::Get()->mock_prefs();
 
   EXPECT_CALL(*prefs, SetInt64(_, _)).Times(AnyNumber());
   EXPECT_CALL(*prefs, SetInt64(kPrefsPayloadAttemptNumber, 0))
@@ -495,7 +502,8 @@
        PayloadAttemptNumberIncreasesOnSuccessfulFullDownload) {
   OmahaResponse response;
   PayloadState payload_state;
-  NiceMock<MockPrefs>* prefs = FakeSystemState::Get()->mock_prefs();
+  FakeSystemState::Get()->set_prefs(nullptr);
+  auto* prefs = FakeSystemState::Get()->mock_prefs();
 
   EXPECT_CALL(*prefs, SetInt64(_, _)).Times(AnyNumber());
   EXPECT_CALL(*prefs, SetInt64(kPrefsPayloadAttemptNumber, 0))
@@ -534,7 +542,8 @@
        PayloadAttemptNumberIncreasesOnSuccessfulDeltaDownload) {
   OmahaResponse response;
   PayloadState payload_state;
-  NiceMock<MockPrefs>* prefs = FakeSystemState::Get()->mock_prefs();
+  FakeSystemState::Get()->set_prefs(nullptr);
+  auto* prefs = FakeSystemState::Get()->mock_prefs();
 
   EXPECT_CALL(*prefs, SetInt64(_, _)).Times(AnyNumber());
   EXPECT_CALL(*prefs, SetInt64(kPrefsPayloadAttemptNumber, 0))
@@ -587,20 +596,20 @@
   EXPECT_EQ(1U, payload_state.GetUrlSwitchCount());
 
   // Now, simulate a corrupted url index on persisted store which gets
-  // loaded when update_engine restarts. Using a different prefs object
-  // so as to not bother accounting for the uninteresting calls above.
-  NiceMock<MockPrefs>* prefs2 = FakeSystemState::Get()->mock_prefs();
-  EXPECT_CALL(*prefs2, Exists(_)).WillRepeatedly(Return(true));
-  EXPECT_CALL(*prefs2, GetInt64(_, _)).Times(AtLeast(1));
-  EXPECT_CALL(*prefs2, GetInt64(kPrefsPayloadAttemptNumber, _))
+  // loaded when update_engine restarts.
+  FakeSystemState::Get()->set_prefs(nullptr);
+  auto* prefs = FakeSystemState::Get()->mock_prefs();
+  EXPECT_CALL(*prefs, Exists(_)).WillRepeatedly(Return(true));
+  EXPECT_CALL(*prefs, GetInt64(_, _)).Times(AtLeast(1));
+  EXPECT_CALL(*prefs, GetInt64(kPrefsPayloadAttemptNumber, _))
       .Times(AtLeast(1));
-  EXPECT_CALL(*prefs2, GetInt64(kPrefsFullPayloadAttemptNumber, _))
+  EXPECT_CALL(*prefs, GetInt64(kPrefsFullPayloadAttemptNumber, _))
       .Times(AtLeast(1));
-  EXPECT_CALL(*prefs2, GetInt64(kPrefsCurrentUrlIndex, _))
+  EXPECT_CALL(*prefs, GetInt64(kPrefsCurrentUrlIndex, _))
       .WillRepeatedly(DoAll(SetArgPointee<1>(2), Return(true)));
-  EXPECT_CALL(*prefs2, GetInt64(kPrefsCurrentUrlFailureCount, _))
+  EXPECT_CALL(*prefs, GetInt64(kPrefsCurrentUrlFailureCount, _))
       .Times(AtLeast(1));
-  EXPECT_CALL(*prefs2, GetInt64(kPrefsUrlSwitchCount, _)).Times(AtLeast(1));
+  EXPECT_CALL(*prefs, GetInt64(kPrefsUrlSwitchCount, _)).Times(AtLeast(1));
 
   // Note: This will be a different payload object, but the response should
   // have the same hash as before so as to not trivially reset because the
@@ -937,12 +946,12 @@
 }
 
 TEST_F(PayloadStateTest, NumRebootsIncrementsCorrectly) {
-  PayloadState payload_state;
-
-  NiceMock<MockPrefs>* prefs = FakeSystemState::Get()->mock_prefs();
+  FakeSystemState::Get()->set_prefs(nullptr);
+  auto* prefs = FakeSystemState::Get()->mock_prefs();
   EXPECT_CALL(*prefs, SetInt64(_, _)).Times(AtLeast(0));
   EXPECT_CALL(*prefs, SetInt64(kPrefsNumReboots, 1)).Times(AtLeast(1));
 
+  PayloadState payload_state;
   EXPECT_TRUE(payload_state.Initialize());
 
   payload_state.UpdateRestarted();
@@ -964,10 +973,10 @@
 }
 
 TEST_F(PayloadStateTest, RollbackHappened) {
-  PayloadState payload_state;
-
-  NiceMock<MockPrefs>* mock_powerwash_safe_prefs =
+  FakeSystemState::Get()->set_powerwash_safe_prefs(nullptr);
+  auto* mock_powerwash_safe_prefs =
       FakeSystemState::Get()->mock_powerwash_safe_prefs();
+  PayloadState payload_state;
   EXPECT_TRUE(payload_state.Initialize());
 
   // Verify pre-conditions are good.
@@ -994,9 +1003,8 @@
 }
 
 TEST_F(PayloadStateTest, RollbackVersion) {
-  PayloadState payload_state;
-
-  NiceMock<MockPrefs>* mock_powerwash_safe_prefs =
+  FakeSystemState::Get()->set_powerwash_safe_prefs(nullptr);
+  auto* mock_powerwash_safe_prefs =
       FakeSystemState::Get()->mock_powerwash_safe_prefs();
 
   // Mock out the os version and make sure it's excluded correctly.
@@ -1005,6 +1013,7 @@
   params.Init(rollback_version, "", {});
   FakeSystemState::Get()->set_request_params(&params);
 
+  PayloadState payload_state;
   EXPECT_TRUE(payload_state.Initialize());
 
   // Verify pre-conditions are good.
@@ -1038,8 +1047,6 @@
 TEST_F(PayloadStateTest, DurationsAreCorrect) {
   OmahaResponse response;
   response.packages.resize(1);
-  PayloadState payload_state;
-  FakePrefs fake_prefs;
 
   // Set the clock to a well-known time - 1 second on the wall-clock
   // and 2 seconds on the monotonic clock
@@ -1047,7 +1054,7 @@
   fake_clock->SetWallclockTime(Time::FromInternalValue(1000000));
   fake_clock->SetMonotonicTime(Time::FromInternalValue(2000000));
 
-  FakeSystemState::Get()->set_prefs(&fake_prefs);
+  PayloadState payload_state;
   EXPECT_TRUE(payload_state.Initialize());
 
   // Check that durations are correct for a successful update where
@@ -1098,15 +1105,13 @@
 
 TEST_F(PayloadStateTest, RebootAfterSuccessfulUpdateTest) {
   OmahaResponse response;
-  PayloadState payload_state;
-  FakePrefs fake_prefs;
 
   // Set the clock to a well-known time (t = 30 seconds).
   auto* fake_clock = FakeSystemState::Get()->fake_clock();
   fake_clock->SetMonotonicTime(
       Time::FromInternalValue(30 * Time::kMicrosecondsPerSecond));
 
-  FakeSystemState::Get()->set_prefs(&fake_prefs);
+  PayloadState payload_state;
   EXPECT_TRUE(payload_state.Initialize());
 
   // Make the update succeed.
@@ -1114,8 +1119,9 @@
       "Hash8593", true, false, &payload_state, &response);
   payload_state.UpdateSucceeded();
 
+  auto* fake_prefs = FakeSystemState::Get()->fake_prefs();
   // Check that the marker was written.
-  EXPECT_TRUE(fake_prefs.Exists(kPrefsSystemUpdatedMarker));
+  EXPECT_TRUE(fake_prefs->Exists(kPrefsSystemUpdatedMarker));
 
   // Now simulate a reboot and set the wallclock time to a later point
   // (t = 500 seconds). We do this by using a new PayloadState object
@@ -1134,14 +1140,15 @@
   payload_state2.UpdateEngineStarted();
 
   // Check that the marker was nuked.
-  EXPECT_FALSE(fake_prefs.Exists(kPrefsSystemUpdatedMarker));
+  EXPECT_FALSE(fake_prefs->Exists(kPrefsSystemUpdatedMarker));
 }
 
 TEST_F(PayloadStateTest, RestartAfterCrash) {
   PayloadState payload_state;
   testing::StrictMock<MockMetricsReporter> mock_metrics_reporter;
   FakeSystemState::Get()->set_metrics_reporter(&mock_metrics_reporter);
-  NiceMock<MockPrefs>* prefs = FakeSystemState::Get()->mock_prefs();
+  FakeSystemState::Get()->set_prefs(nullptr);
+  auto* prefs = FakeSystemState::Get()->mock_prefs();
 
   EXPECT_TRUE(payload_state.Initialize());
 
@@ -1173,14 +1180,12 @@
 }
 
 TEST_F(PayloadStateTest, AbnormalTerminationAttemptMetricsReported) {
-  PayloadState payload_state;
-  FakePrefs fake_prefs;
-
   // If we have a marker at startup, ensure it's reported and the
   // marker is then cleared.
-  FakeSystemState::Get()->set_prefs(&fake_prefs);
-  fake_prefs.SetBoolean(kPrefsAttemptInProgress, true);
+  auto* fake_prefs = FakeSystemState::Get()->fake_prefs();
+  fake_prefs->SetBoolean(kPrefsAttemptInProgress, true);
 
+  PayloadState payload_state;
   EXPECT_TRUE(payload_state.Initialize());
 
   EXPECT_CALL(*FakeSystemState::Get()->mock_metrics_reporter(),
@@ -1188,17 +1193,14 @@
       .Times(1);
   payload_state.UpdateEngineStarted();
 
-  EXPECT_FALSE(fake_prefs.Exists(kPrefsAttemptInProgress));
+  EXPECT_FALSE(fake_prefs->Exists(kPrefsAttemptInProgress));
 }
 
 TEST_F(PayloadStateTest, AbnormalTerminationAttemptMetricsClearedOnSucceess) {
-  PayloadState payload_state;
-  FakePrefs fake_prefs;
-
   // Make sure the marker is written and cleared during an attempt and
   // also that we DO NOT emit the metric (since the attempt didn't end
   // abnormally).
-  FakeSystemState::Get()->set_prefs(&fake_prefs);
+  PayloadState payload_state;
   EXPECT_TRUE(payload_state.Initialize());
   OmahaResponse response;
   response.packages.resize(1);
@@ -1208,18 +1210,19 @@
               ReportAbnormallyTerminatedUpdateAttemptMetrics())
       .Times(0);
 
+  auto* fake_prefs = FakeSystemState::Get()->fake_prefs();
   // Attempt not in progress, should be clear.
-  EXPECT_FALSE(fake_prefs.Exists(kPrefsAttemptInProgress));
+  EXPECT_FALSE(fake_prefs->Exists(kPrefsAttemptInProgress));
 
   payload_state.UpdateRestarted();
 
   // Attempt not in progress, should be set.
-  EXPECT_TRUE(fake_prefs.Exists(kPrefsAttemptInProgress));
+  EXPECT_TRUE(fake_prefs->Exists(kPrefsAttemptInProgress));
 
   payload_state.UpdateSucceeded();
 
   // Attempt not in progress, should be clear.
-  EXPECT_FALSE(fake_prefs.Exists(kPrefsAttemptInProgress));
+  EXPECT_FALSE(fake_prefs->Exists(kPrefsAttemptInProgress));
 }
 
 TEST_F(PayloadStateTest, CandidateUrlsComputedCorrectly) {
@@ -1373,9 +1376,6 @@
 TEST_F(PayloadStateTest, RebootAfterUpdateFailedMetric) {
   OmahaResponse response;
   PayloadState payload_state;
-  FakePrefs fake_prefs;
-  FakeSystemState::Get()->set_prefs(&fake_prefs);
-
   EXPECT_TRUE(payload_state.Initialize());
   SetupPayloadStateWith2Urls(
       "Hash3141", true, false, &payload_state, &response);
@@ -1415,9 +1415,6 @@
 TEST_F(PayloadStateTest, RebootAfterUpdateSucceed) {
   OmahaResponse response;
   PayloadState payload_state;
-  FakePrefs fake_prefs;
-  FakeSystemState::Get()->set_prefs(&fake_prefs);
-
   FakeBootControl* fake_boot_control =
       FakeSystemState::Get()->fake_boot_control();
   fake_boot_control->SetCurrentSlot(0);
@@ -1448,9 +1445,6 @@
 TEST_F(PayloadStateTest, RebootAfterCanceledUpdate) {
   OmahaResponse response;
   PayloadState payload_state;
-  FakePrefs fake_prefs;
-
-  FakeSystemState::Get()->set_prefs(&fake_prefs);
   EXPECT_TRUE(payload_state.Initialize());
   SetupPayloadStateWith2Urls(
       "Hash3141", true, false, &payload_state, &response);
@@ -1473,9 +1467,6 @@
 
 TEST_F(PayloadStateTest, UpdateSuccessWithWipedPrefs) {
   PayloadState payload_state;
-  FakePrefs fake_prefs;
-
-  FakeSystemState::Get()->set_prefs(&fake_prefs);
   EXPECT_TRUE(payload_state.Initialize());
 
   EXPECT_CALL(*FakeSystemState::Get()->mock_metrics_reporter(),
@@ -1489,9 +1480,6 @@
 TEST_F(PayloadStateTest, DisallowP2PAfterTooManyAttempts) {
   OmahaResponse response;
   PayloadState payload_state;
-  FakePrefs fake_prefs;
-  FakeSystemState::Get()->set_prefs(&fake_prefs);
-
   EXPECT_TRUE(payload_state.Initialize());
   SetupPayloadStateWith2Urls(
       "Hash8593", true, false, &payload_state, &response);
@@ -1509,9 +1497,6 @@
 TEST_F(PayloadStateTest, DisallowP2PAfterDeadline) {
   OmahaResponse response;
   PayloadState payload_state;
-  FakePrefs fake_prefs;
-
-  FakeSystemState::Get()->set_prefs(&fake_prefs);
   EXPECT_TRUE(payload_state.Initialize());
   SetupPayloadStateWith2Urls(
       "Hash8593", true, false, &payload_state, &response);
@@ -1553,9 +1538,6 @@
 TEST_F(PayloadStateTest, P2PStateVarsInitialValue) {
   OmahaResponse response;
   PayloadState payload_state;
-  FakePrefs fake_prefs;
-
-  FakeSystemState::Get()->set_prefs(&fake_prefs);
   EXPECT_TRUE(payload_state.Initialize());
   SetupPayloadStateWith2Urls(
       "Hash8593", true, false, &payload_state, &response);
@@ -1568,8 +1550,6 @@
 TEST_F(PayloadStateTest, P2PStateVarsArePersisted) {
   OmahaResponse response;
   PayloadState payload_state;
-  FakePrefs fake_prefs;
-  FakeSystemState::Get()->set_prefs(&fake_prefs);
   EXPECT_TRUE(payload_state.Initialize());
   SetupPayloadStateWith2Urls(
       "Hash8593", true, false, &payload_state, &response);
@@ -1594,9 +1574,6 @@
 TEST_F(PayloadStateTest, P2PStateVarsAreClearedOnNewResponse) {
   OmahaResponse response;
   PayloadState payload_state;
-  FakePrefs fake_prefs;
-  FakeSystemState::Get()->set_prefs(&fake_prefs);
-
   EXPECT_TRUE(payload_state.Initialize());
   SetupPayloadStateWith2Urls(
       "Hash8593", true, false, &payload_state, &response);
diff --git a/cros/update_attempter.cc b/cros/update_attempter.cc
index b98b32c..cad7838 100644
--- a/cros/update_attempter.cc
+++ b/cros/update_attempter.cc
@@ -583,7 +583,7 @@
   if (device_policy && !interactive && oobe_complete) {
     staging_wait_time_ = omaha_request_params_->waiting_period();
     staging_case = CalculateStagingCase(
-        device_policy, prefs_, &staging_wait_time_, &staging_schedule_);
+        device_policy, &staging_wait_time_, &staging_schedule_);
   }
   switch (staging_case) {
     case StagingCase::kOff:
@@ -618,11 +618,10 @@
 
 bool UpdateAttempter::ResetDlcPrefs(const string& dlc_id) {
   vector<string> failures;
-  PrefsInterface* prefs = SystemState::Get()->prefs();
   for (auto& sub_key :
        {kPrefsPingActive, kPrefsPingLastActive, kPrefsPingLastRollcall}) {
-    auto key = prefs->CreateSubKey({kDlcPrefsSubDir, dlc_id, sub_key});
-    if (!prefs->Delete(key))
+    auto key = prefs_->CreateSubKey({kDlcPrefsSubDir, dlc_id, sub_key});
+    if (!prefs_->Delete(key))
       failures.emplace_back(sub_key);
   }
   if (failures.size() != 0)
@@ -653,11 +652,10 @@
   }
   LOG(INFO) << "Set DLC (" << dlc_id << ") to "
             << (is_active ? "Active" : "Inactive");
-  PrefsInterface* prefs = SystemState::Get()->prefs();
   if (is_active) {
     auto ping_active_key =
-        prefs->CreateSubKey({kDlcPrefsSubDir, dlc_id, kPrefsPingActive});
-    if (!prefs->SetInt64(ping_active_key, kPingActiveValue)) {
+        prefs_->CreateSubKey({kDlcPrefsSubDir, dlc_id, kPrefsPingActive});
+    if (!prefs_->SetInt64(ping_active_key, kPingActiveValue)) {
       LOG(ERROR) << "Failed to set the value of ping metadata '"
                  << kPrefsPingActive << "'.";
       return false;
@@ -692,7 +690,6 @@
     LOG(INFO) << "Failed to retrieve DLC module IDs from dlcservice. Check the "
                  "state of dlcservice, will not update DLC modules.";
   }
-  PrefsInterface* prefs = SystemState::Get()->prefs();
   map<string, OmahaRequestParams::AppParams> dlc_apps_params;
   for (const auto& dlc_id : dlc_ids_) {
     OmahaRequestParams::AppParams dlc_params{
@@ -712,16 +709,16 @@
       // install or might not really be active yet.
       dlc_params.ping_active = kPingActiveValue;
       auto ping_active_key =
-          prefs->CreateSubKey({kDlcPrefsSubDir, dlc_id, kPrefsPingActive});
-      if (!prefs->GetInt64(ping_active_key, &dlc_params.ping_active) ||
+          prefs_->CreateSubKey({kDlcPrefsSubDir, dlc_id, kPrefsPingActive});
+      if (!prefs_->GetInt64(ping_active_key, &dlc_params.ping_active) ||
           dlc_params.ping_active != kPingActiveValue) {
         dlc_params.ping_active = kPingInactiveValue;
       }
       auto ping_last_active_key =
-          prefs->CreateSubKey({kDlcPrefsSubDir, dlc_id, kPrefsPingLastActive});
+          prefs_->CreateSubKey({kDlcPrefsSubDir, dlc_id, kPrefsPingLastActive});
       dlc_params.ping_date_last_active = GetPingMetadata(ping_last_active_key);
 
-      auto ping_last_rollcall_key = prefs->CreateSubKey(
+      auto ping_last_rollcall_key = prefs_->CreateSubKey(
           {kDlcPrefsSubDir, dlc_id, kPrefsPingLastRollcall});
       dlc_params.ping_date_last_rollcall =
           GetPingMetadata(ping_last_rollcall_key);
@@ -1721,7 +1718,7 @@
   SystemState::Get()->payload_state()->UpdateEngineStarted();
   StartP2PAtStartup();
 
-  excluder_ = CreateExcluder(SystemState::Get()->prefs());
+  excluder_ = CreateExcluder();
 }
 
 bool UpdateAttempter::StartP2PAtStartup() {
diff --git a/cros/update_attempter_unittest.cc b/cros/update_attempter_unittest.cc
index 18705bd..b4fcdf2 100644
--- a/cros/update_attempter_unittest.cc
+++ b/cros/update_attempter_unittest.cc
@@ -37,11 +37,9 @@
 
 #include "update_engine/common/constants.h"
 #include "update_engine/common/dlcservice_interface.h"
-#include "update_engine/common/fake_prefs.h"
 #include "update_engine/common/mock_action.h"
 #include "update_engine/common/mock_action_processor.h"
 #include "update_engine/common/mock_http_fetcher.h"
-#include "update_engine/common/mock_prefs.h"
 #include "update_engine/common/mock_service_observer.h"
 #include "update_engine/common/platform_constants.h"
 #include "update_engine/common/prefs.h"
@@ -230,8 +228,9 @@
     FakeSystemState::Get()->set_update_manager(&mock_update_manager_);
     loop_.SetAsCurrent();
 
-    certificate_checker_.reset(new CertificateChecker(
-        FakeSystemState::Get()->mock_prefs(), &openssl_wrapper_));
+    prefs_ = FakeSystemState::Get()->fake_prefs();
+    certificate_checker_.reset(
+        new CertificateChecker(prefs_, &openssl_wrapper_));
     certificate_checker_->Init();
 
     attempter_.set_forced_update_pending_callback(
@@ -247,7 +246,6 @@
     EXPECT_EQ(0ULL, attempter_.new_payload_size_);
     processor_ = new NiceMock<MockActionProcessor>();
     attempter_.processor_.reset(processor_);  // Transfers ownership.
-    prefs_ = FakeSystemState::Get()->mock_prefs();
 
     // Setup store/load semantics of P2P properties via the mock |PayloadState|.
     actual_using_p2p_for_downloading_ = false;
@@ -291,7 +289,7 @@
                                   bool is_policy_available,
                                   bool expected_reset);
   // Staging related callbacks.
-  void SetUpStagingTest(const StagingSchedule& schedule, FakePrefs* prefs);
+  void SetUpStagingTest(const StagingSchedule& schedule);
   void CheckStagingOff();
   void StagingSetsPrefsAndTurnsOffScatteringStart();
   void StagingOffIfInteractiveStart();
@@ -321,9 +319,10 @@
   MockUpdateManager mock_update_manager_;
 
   NiceMock<MockActionProcessor>* processor_;
-  NiceMock<MockPrefs>* prefs_;
   NiceMock<MockConnectionManager> mock_connection_manager;
 
+  FakePrefs* prefs_;
+
   // |CheckForUpdate()| test params.
   CheckForUpdateTestParams cfu_params_;
 
@@ -502,8 +501,8 @@
                         nullptr,
                         fetcher.release(),
                         false /* interactive */);
-  EXPECT_CALL(*prefs_, GetInt64(kPrefsDeltaUpdateFailures, _)).Times(0);
   attempter_.ActionCompleted(nullptr, &action, ErrorCode::kSuccess);
+  EXPECT_FALSE(prefs_->Exists(kPrefsDeltaUpdateFailures));
   EXPECT_EQ(UpdateStatus::FINALIZING, attempter_.status());
   EXPECT_EQ(0.0, attempter_.download_progress_);
   ASSERT_EQ(nullptr, attempter_.error_event_.get());
@@ -513,8 +512,6 @@
   MockAction action;
   EXPECT_CALL(action, Type()).WillRepeatedly(Return("MockAction"));
   attempter_.status_ = UpdateStatus::DOWNLOADING;
-  EXPECT_CALL(*prefs_, GetInt64(kPrefsDeltaUpdateFailures, _))
-      .WillOnce(Return(false));
   attempter_.ActionCompleted(nullptr, &action, ErrorCode::kError);
   ASSERT_NE(nullptr, attempter_.error_event_.get());
 }
@@ -607,8 +604,8 @@
   OmahaResponse response;
   response.poll_interval = 234;
   action.SetOutputObject(response);
-  EXPECT_CALL(*prefs_, GetInt64(kPrefsDeltaUpdateFailures, _)).Times(0);
   attempter_.ActionCompleted(nullptr, &action, ErrorCode::kSuccess);
+  EXPECT_FALSE(prefs_->Exists(kPrefsDeltaUpdateFailures));
   EXPECT_EQ(500, attempter_.http_response_code());
   EXPECT_EQ(UpdateStatus::IDLE, attempter_.status());
   EXPECT_EQ(234U, attempter_.server_dictated_poll_interval_);
@@ -616,11 +613,10 @@
 }
 
 TEST_F(UpdateAttempterTest, ConstructWithUpdatedMarkerTest) {
-  FakePrefs fake_prefs;
   string boot_id;
   EXPECT_TRUE(utils::GetBootId(&boot_id));
-  fake_prefs.SetString(kPrefsUpdateCompletedOnBootId, boot_id);
-  FakeSystemState::Get()->set_prefs(&fake_prefs);
+  FakeSystemState::Get()->fake_prefs()->SetString(kPrefsUpdateCompletedOnBootId,
+                                                  boot_id);
   attempter_.Init();
   EXPECT_EQ(UpdateStatus::UPDATED_NEED_REBOOT, attempter_.status());
 }
@@ -655,44 +651,38 @@
 
 TEST_F(UpdateAttempterTest, DisableDeltaUpdateIfNeededTest) {
   attempter_.omaha_request_params_->set_delta_okay(true);
-  EXPECT_CALL(*prefs_, GetInt64(kPrefsDeltaUpdateFailures, _))
-      .WillOnce(Return(false));
   attempter_.DisableDeltaUpdateIfNeeded();
   EXPECT_TRUE(attempter_.omaha_request_params_->delta_okay());
-  EXPECT_CALL(*prefs_, GetInt64(kPrefsDeltaUpdateFailures, _))
-      .WillOnce(
-          DoAll(SetArgPointee<1>(UpdateAttempter::kMaxDeltaUpdateFailures - 1),
-                Return(true)));
+  prefs_->SetInt64(kPrefsDeltaUpdateFailures,
+                   UpdateAttempter::kMaxDeltaUpdateFailures - 1);
   attempter_.DisableDeltaUpdateIfNeeded();
   EXPECT_TRUE(attempter_.omaha_request_params_->delta_okay());
-  EXPECT_CALL(*prefs_, GetInt64(kPrefsDeltaUpdateFailures, _))
-      .WillOnce(
-          DoAll(SetArgPointee<1>(UpdateAttempter::kMaxDeltaUpdateFailures),
-                Return(true)));
+  prefs_->SetInt64(kPrefsDeltaUpdateFailures,
+                   UpdateAttempter::kMaxDeltaUpdateFailures);
   attempter_.DisableDeltaUpdateIfNeeded();
   EXPECT_FALSE(attempter_.omaha_request_params_->delta_okay());
-  EXPECT_CALL(*prefs_, GetInt64(_, _)).Times(0);
   attempter_.DisableDeltaUpdateIfNeeded();
   EXPECT_FALSE(attempter_.omaha_request_params_->delta_okay());
 }
 
 TEST_F(UpdateAttempterTest, MarkDeltaUpdateFailureTest) {
-  EXPECT_CALL(*prefs_, GetInt64(kPrefsDeltaUpdateFailures, _))
-      .WillOnce(Return(false))
-      .WillOnce(DoAll(SetArgPointee<1>(-1), Return(true)))
-      .WillOnce(DoAll(SetArgPointee<1>(1), Return(true)))
-      .WillOnce(
-          DoAll(SetArgPointee<1>(UpdateAttempter::kMaxDeltaUpdateFailures),
-                Return(true)));
-  EXPECT_CALL(*prefs_, SetInt64(Ne(kPrefsDeltaUpdateFailures), _))
-      .WillRepeatedly(Return(true));
-  EXPECT_CALL(*prefs_, SetInt64(kPrefsDeltaUpdateFailures, 1)).Times(2);
-  EXPECT_CALL(*prefs_, SetInt64(kPrefsDeltaUpdateFailures, 2));
-  EXPECT_CALL(*prefs_,
-              SetInt64(kPrefsDeltaUpdateFailures,
-                       UpdateAttempter::kMaxDeltaUpdateFailures + 1));
-  for (int i = 0; i < 4; i++)
-    attempter_.MarkDeltaUpdateFailure();
+  attempter_.MarkDeltaUpdateFailure();
+
+  EXPECT_TRUE(prefs_->SetInt64(kPrefsDeltaUpdateFailures, -1));
+  attempter_.MarkDeltaUpdateFailure();
+  int64_t value = 0;
+  EXPECT_TRUE(prefs_->GetInt64(kPrefsDeltaUpdateFailures, &value));
+  EXPECT_EQ(value, 1);
+
+  attempter_.MarkDeltaUpdateFailure();
+  EXPECT_TRUE(prefs_->GetInt64(kPrefsDeltaUpdateFailures, &value));
+  EXPECT_EQ(value, 2);
+
+  EXPECT_TRUE(prefs_->SetInt64(kPrefsDeltaUpdateFailures,
+                               UpdateAttempter::kMaxDeltaUpdateFailures));
+  attempter_.MarkDeltaUpdateFailure();
+  EXPECT_TRUE(prefs_->GetInt64(kPrefsDeltaUpdateFailures, &value));
+  EXPECT_EQ(value, UpdateAttempter::kMaxDeltaUpdateFailures + 1);
 }
 
 TEST_F(UpdateAttempterTest, ScheduleErrorEventActionNoEventTest) {
@@ -1109,12 +1099,10 @@
   // Tests that the scatter_factor_in_seconds value is properly fetched
   // from the device policy and is decremented if value > 0.
   int64_t initial_value = 5;
-  FakePrefs fake_prefs;
-  attempter_.prefs_ = &fake_prefs;
-
+  auto* fake_prefs = FakeSystemState::Get()->fake_prefs();
   FakeSystemState::Get()->fake_hardware()->SetIsOOBEComplete(Time::UnixEpoch());
 
-  EXPECT_TRUE(fake_prefs.SetInt64(kPrefsUpdateCheckCount, initial_value));
+  EXPECT_TRUE(fake_prefs->SetInt64(kPrefsUpdateCheckCount, initial_value));
 
   int64_t scatter_factor_in_seconds = 10;
 
@@ -1133,10 +1121,10 @@
   EXPECT_EQ(scatter_factor_in_seconds, attempter_.scatter_factor_.InSeconds());
 
   // Make sure the file still exists.
-  EXPECT_TRUE(fake_prefs.Exists(kPrefsUpdateCheckCount));
+  EXPECT_TRUE(fake_prefs->Exists(kPrefsUpdateCheckCount));
 
   int64_t new_value;
-  EXPECT_TRUE(fake_prefs.GetInt64(kPrefsUpdateCheckCount, &new_value));
+  EXPECT_TRUE(fake_prefs->GetInt64(kPrefsUpdateCheckCount, &new_value));
   EXPECT_EQ(initial_value - 1, new_value);
 
   EXPECT_TRUE(
@@ -1144,10 +1132,10 @@
 
   // However, if the count is already 0, it's not decremented. Test that.
   initial_value = 0;
-  EXPECT_TRUE(fake_prefs.SetInt64(kPrefsUpdateCheckCount, initial_value));
+  EXPECT_TRUE(fake_prefs->SetInt64(kPrefsUpdateCheckCount, initial_value));
   attempter_.Update({});
-  EXPECT_TRUE(fake_prefs.Exists(kPrefsUpdateCheckCount));
-  EXPECT_TRUE(fake_prefs.GetInt64(kPrefsUpdateCheckCount, &new_value));
+  EXPECT_TRUE(fake_prefs->Exists(kPrefsUpdateCheckCount));
+  EXPECT_TRUE(fake_prefs->GetInt64(kPrefsUpdateCheckCount, &new_value));
   EXPECT_EQ(initial_value, new_value);
 
   ScheduleQuitMainLoop();
@@ -1166,15 +1154,12 @@
   // Tests that no scattering logic is enabled if the update check
   // is manually done (as opposed to a scheduled update check)
   int64_t initial_value = 8;
-  FakePrefs fake_prefs;
-  attempter_.prefs_ = &fake_prefs;
-
+  auto* fake_prefs = FakeSystemState::Get()->fake_prefs();
   FakeSystemState::Get()->fake_hardware()->SetIsOOBEComplete(Time::UnixEpoch());
-  FakeSystemState::Get()->set_prefs(&fake_prefs);
 
   EXPECT_TRUE(
-      fake_prefs.SetInt64(kPrefsWallClockScatteringWaitPeriod, initial_value));
-  EXPECT_TRUE(fake_prefs.SetInt64(kPrefsUpdateCheckCount, initial_value));
+      fake_prefs->SetInt64(kPrefsWallClockScatteringWaitPeriod, initial_value));
+  EXPECT_TRUE(fake_prefs->SetInt64(kPrefsUpdateCheckCount, initial_value));
 
   // make sure scatter_factor is non-zero as scattering is disabled
   // otherwise.
@@ -1199,24 +1184,20 @@
   // checks and all artifacts are removed.
   EXPECT_FALSE(
       attempter_.omaha_request_params_->wall_clock_based_wait_enabled());
-  EXPECT_FALSE(fake_prefs.Exists(kPrefsWallClockScatteringWaitPeriod));
+  EXPECT_FALSE(fake_prefs->Exists(kPrefsWallClockScatteringWaitPeriod));
   EXPECT_EQ(0, attempter_.omaha_request_params_->waiting_period().InSeconds());
   EXPECT_FALSE(
       attempter_.omaha_request_params_->update_check_count_wait_enabled());
-  EXPECT_FALSE(fake_prefs.Exists(kPrefsUpdateCheckCount));
+  EXPECT_FALSE(fake_prefs->Exists(kPrefsUpdateCheckCount));
 
   ScheduleQuitMainLoop();
 }
 
-void UpdateAttempterTest::SetUpStagingTest(const StagingSchedule& schedule,
-                                           FakePrefs* prefs) {
-  attempter_.prefs_ = prefs;
-  FakeSystemState::Get()->set_prefs(prefs);
-
+void UpdateAttempterTest::SetUpStagingTest(const StagingSchedule& schedule) {
   int64_t initial_value = 8;
   EXPECT_TRUE(
-      prefs->SetInt64(kPrefsWallClockScatteringWaitPeriod, initial_value));
-  EXPECT_TRUE(prefs->SetInt64(kPrefsUpdateCheckCount, initial_value));
+      prefs_->SetInt64(kPrefsWallClockScatteringWaitPeriod, initial_value));
+  EXPECT_TRUE(prefs_->SetInt64(kPrefsUpdateCheckCount, initial_value));
   attempter_.scatter_factor_ = TimeDelta::FromSeconds(20);
 
   auto device_policy = std::make_unique<policy::MockDevicePolicy>();
@@ -1241,16 +1222,16 @@
 void UpdateAttempterTest::StagingSetsPrefsAndTurnsOffScatteringStart() {
   // Tests that staging sets its prefs properly and turns off scattering.
   FakeSystemState::Get()->fake_hardware()->SetIsOOBEComplete(Time::UnixEpoch());
-  FakePrefs fake_prefs;
-  SetUpStagingTest(kValidStagingSchedule, &fake_prefs);
+  SetUpStagingTest(kValidStagingSchedule);
 
   attempter_.Update({});
+  auto* fake_prefs = FakeSystemState::Get()->fake_prefs();
   // Check that prefs have the correct values.
   int64_t update_count;
-  EXPECT_TRUE(fake_prefs.GetInt64(kPrefsUpdateCheckCount, &update_count));
+  EXPECT_TRUE(fake_prefs->GetInt64(kPrefsUpdateCheckCount, &update_count));
   int64_t waiting_time_days;
-  EXPECT_TRUE(fake_prefs.GetInt64(kPrefsWallClockStagingWaitPeriod,
-                                  &waiting_time_days));
+  EXPECT_TRUE(fake_prefs->GetInt64(kPrefsWallClockStagingWaitPeriod,
+                                   &waiting_time_days));
   EXPECT_GT(waiting_time_days, 0);
   // Update count should have been decremented.
   EXPECT_EQ(7, update_count);
@@ -1266,16 +1247,16 @@
   EXPECT_EQ(kValidStagingSchedule, attempter_.staging_schedule_);
   // Check that scattering is turned off
   EXPECT_EQ(0, attempter_.scatter_factor_.InSeconds());
-  EXPECT_FALSE(fake_prefs.Exists(kPrefsWallClockScatteringWaitPeriod));
+  EXPECT_FALSE(fake_prefs->Exists(kPrefsWallClockScatteringWaitPeriod));
 
   ScheduleQuitMainLoop();
 }
 
 void UpdateAttempterTest::CheckStagingOff() {
   // Check that all prefs were removed.
-  EXPECT_FALSE(attempter_.prefs_->Exists(kPrefsUpdateCheckCount));
-  EXPECT_FALSE(attempter_.prefs_->Exists(kPrefsWallClockScatteringWaitPeriod));
-  EXPECT_FALSE(attempter_.prefs_->Exists(kPrefsWallClockStagingWaitPeriod));
+  EXPECT_FALSE(prefs_->Exists(kPrefsUpdateCheckCount));
+  EXPECT_FALSE(prefs_->Exists(kPrefsWallClockScatteringWaitPeriod));
+  EXPECT_FALSE(prefs_->Exists(kPrefsWallClockStagingWaitPeriod));
   // Check that the Omaha parameters have the correct value.
   EXPECT_EQ(0, attempter_.omaha_request_params_->waiting_period().InDays());
   EXPECT_EQ(attempter_.omaha_request_params_->waiting_period(),
@@ -1298,8 +1279,7 @@
 void UpdateAttempterTest::StagingOffIfInteractiveStart() {
   // Tests that staging is turned off when an interactive update is requested.
   FakeSystemState::Get()->fake_hardware()->SetIsOOBEComplete(Time::UnixEpoch());
-  FakePrefs fake_prefs;
-  SetUpStagingTest(kValidStagingSchedule, &fake_prefs);
+  SetUpStagingTest(kValidStagingSchedule);
 
   attempter_.Update({.interactive = true});
   CheckStagingOff();
@@ -1318,8 +1298,7 @@
   // Tests that staging is turned off if OOBE hasn't been completed.
   FakeSystemState::Get()->fake_hardware()->SetIsOOBEEnabled(true);
   FakeSystemState::Get()->fake_hardware()->UnsetIsOOBEComplete();
-  FakePrefs fake_prefs;
-  SetUpStagingTest(kValidStagingSchedule, &fake_prefs);
+  SetUpStagingTest(kValidStagingSchedule);
 
   attempter_.Update({.interactive = true});
   CheckStagingOff();
@@ -1329,10 +1308,7 @@
 
 // Checks that we only report daily metrics at most every 24 hours.
 TEST_F(UpdateAttempterTest, ReportDailyMetrics) {
-  FakePrefs fake_prefs;
-  FakeSystemState::Get()->set_prefs(&fake_prefs);
   auto* fake_clock = FakeSystemState::Get()->fake_clock();
-
   Time epoch = Time::FromInternalValue(0);
   fake_clock->SetWallclockTime(epoch);
 
@@ -1391,8 +1367,6 @@
 
 TEST_F(UpdateAttempterTest, BootTimeInUpdateMarkerFile) {
   FakeSystemState::Get()->fake_clock()->SetBootTime(Time::FromTimeT(42));
-  FakePrefs fake_prefs;
-  FakeSystemState::Get()->set_prefs(&fake_prefs);
   attempter_.Init();
 
   Time boot_time;
@@ -1955,17 +1929,14 @@
   EXPECT_CALL(*device_policy, GetDisallowedTimeIntervals(_))
       .WillOnce(Return(true));
 
-  FakePrefs fake_prefs;
   Time update_first_seen_at = Time::Now();
-  fake_prefs.SetInt64(kPrefsUpdateFirstSeenAt,
-                      update_first_seen_at.ToInternalValue());
+  FakeSystemState::Get()->fake_prefs()->SetInt64(
+      kPrefsUpdateFirstSeenAt, update_first_seen_at.ToInternalValue());
 
   Time update_finished_at =
       update_first_seen_at + TimeDelta::FromDays(kDaysToUpdate);
   FakeSystemState::Get()->fake_clock()->SetWallclockTime(update_finished_at);
 
-  FakeSystemState::Get()->set_prefs(&fake_prefs);
-
   EXPECT_CALL(*FakeSystemState::Get()->mock_metrics_reporter(),
               ReportEnterpriseUpdateSeenToDownloadDays(true, kDaysToUpdate))
       .Times(1);
@@ -1983,15 +1954,13 @@
   EXPECT_CALL(*device_policy, GetDisallowedTimeIntervals(_))
       .WillOnce(Return(false));
 
-  FakePrefs fake_prefs;
   Time update_first_seen_at = Time::Now();
-  fake_prefs.SetInt64(kPrefsUpdateFirstSeenAt,
-                      update_first_seen_at.ToInternalValue());
+  FakeSystemState::Get()->fake_prefs()->SetInt64(
+      kPrefsUpdateFirstSeenAt, update_first_seen_at.ToInternalValue());
 
   Time update_finished_at =
       update_first_seen_at + TimeDelta::FromDays(kDaysToUpdate);
   FakeSystemState::Get()->fake_clock()->SetWallclockTime(update_finished_at);
-  FakeSystemState::Get()->set_prefs(&fake_prefs);
 
   EXPECT_CALL(*FakeSystemState::Get()->mock_metrics_reporter(),
               ReportEnterpriseUpdateSeenToDownloadDays(false, kDaysToUpdate))
@@ -2287,11 +2256,7 @@
 
 TEST_F(UpdateAttempterTest, FutureEolTest) {
   EolDate eol_date = std::numeric_limits<int64_t>::max();
-  EXPECT_CALL(*prefs_, Exists(kPrefsOmahaEolDate)).WillOnce(Return(true));
-  EXPECT_CALL(*prefs_, GetString(kPrefsOmahaEolDate, _))
-      .WillOnce(
-          DoAll(SetArgPointee<1>(EolDateToString(eol_date)), Return(true)));
-
+  EXPECT_TRUE(prefs_->SetString(kPrefsOmahaEolDate, EolDateToString(eol_date)));
   UpdateEngineStatus status;
   attempter_.GetStatus(&status);
   EXPECT_EQ(eol_date, status.eol_date);
@@ -2299,29 +2264,13 @@
 
 TEST_F(UpdateAttempterTest, PastEolTest) {
   EolDate eol_date = 1;
-  EXPECT_CALL(*prefs_, Exists(kPrefsOmahaEolDate)).WillOnce(Return(true));
-  EXPECT_CALL(*prefs_, GetString(kPrefsOmahaEolDate, _))
-      .WillOnce(
-          DoAll(SetArgPointee<1>(EolDateToString(eol_date)), Return(true)));
-
+  EXPECT_TRUE(prefs_->SetString(kPrefsOmahaEolDate, EolDateToString(eol_date)));
   UpdateEngineStatus status;
   attempter_.GetStatus(&status);
   EXPECT_EQ(eol_date, status.eol_date);
 }
 
-TEST_F(UpdateAttempterTest, FailedEolTest) {
-  EXPECT_CALL(*prefs_, Exists(kPrefsOmahaEolDate)).WillOnce(Return(true));
-  EXPECT_CALL(*prefs_, GetString(kPrefsOmahaEolDate, _))
-      .WillOnce(Return(false));
-
-  UpdateEngineStatus status;
-  attempter_.GetStatus(&status);
-  EXPECT_EQ(kEolDateInvalid, status.eol_date);
-}
-
 TEST_F(UpdateAttempterTest, MissingEolTest) {
-  EXPECT_CALL(*prefs_, Exists(kPrefsOmahaEolDate)).WillOnce(Return(false));
-
   UpdateEngineStatus status;
   attempter_.GetStatus(&status);
   EXPECT_EQ(kEolDateInvalid, status.eol_date);
@@ -2329,8 +2278,6 @@
 
 TEST_F(UpdateAttempterTest, CalculateDlcParamsInstallTest) {
   string dlc_id = "dlc0";
-  FakePrefs fake_prefs;
-  FakeSystemState::Get()->set_prefs(&fake_prefs);
   attempter_.is_install_ = true;
   attempter_.dlc_ids_ = {dlc_id};
   attempter_.CalculateDlcParams();
@@ -2353,8 +2300,6 @@
 
 TEST_F(UpdateAttempterTest, CalculateDlcParamsNoPrefFilesTest) {
   string dlc_id = "dlc0";
-  FakePrefs fake_prefs;
-  FakeSystemState::Get()->set_prefs(&fake_prefs);
   EXPECT_CALL(mock_dlcservice_, GetDlcsToUpdate(_))
       .WillOnce(
           DoAll(SetArgPointee<0>(std::vector<string>({dlc_id})), Return(true)));
@@ -2409,8 +2354,6 @@
 
 TEST_F(UpdateAttempterTest, CalculateDlcParamsValidValuesTest) {
   string dlc_id = "dlc0";
-  MemoryPrefs fake_prefs;
-  FakeSystemState::Get()->set_prefs(&fake_prefs);
   EXPECT_CALL(mock_dlcservice_, GetDlcsToUpdate(_))
       .WillOnce(
           DoAll(SetArgPointee<0>(std::vector<string>({dlc_id})), Return(true)));
@@ -2443,8 +2386,6 @@
 
 TEST_F(UpdateAttempterTest, CalculateDlcParamsRemoveStaleMetadata) {
   string dlc_id = "dlc0";
-  FakePrefs fake_prefs;
-  FakeSystemState::Get()->set_prefs(&fake_prefs);
   auto active_key =
       PrefsInterface::CreateSubKey({kDlcPrefsSubDir, dlc_id, kPrefsPingActive});
   auto last_active_key = PrefsInterface::CreateSubKey(
@@ -2473,8 +2414,6 @@
 
 TEST_F(UpdateAttempterTest, SetDlcActiveValue) {
   string dlc_id = "dlc0";
-  FakePrefs fake_prefs;
-  FakeSystemState::Get()->set_prefs(&fake_prefs);
   attempter_.SetDlcActiveValue(true, dlc_id);
   int64_t temp_int;
   auto active_key =
@@ -2486,8 +2425,6 @@
 
 TEST_F(UpdateAttempterTest, SetDlcInactive) {
   string dlc_id = "dlc0";
-  MemoryPrefs fake_prefs;
-  FakeSystemState::Get()->set_prefs(&fake_prefs);
   auto sub_keys = {
       kPrefsPingActive, kPrefsPingLastActive, kPrefsPingLastRollcall};
   for (auto& sub_key : sub_keys) {
diff --git a/download_action_unittest.cc b/download_action_unittest.cc
index ac02b21..24b03cd 100644
--- a/download_action_unittest.cc
+++ b/download_action_unittest.cc
@@ -36,7 +36,6 @@
 #include "update_engine/common/hash_calculator.h"
 #include "update_engine/common/mock_download_action.h"
 #include "update_engine/common/mock_http_fetcher.h"
-#include "update_engine/common/mock_prefs.h"
 #include "update_engine/common/test_utils.h"
 #include "update_engine/common/utils.h"
 #include "update_engine/cros/fake_p2p_manager_configuration.h"
diff --git a/metrics_utils_unittest.cc b/metrics_utils_unittest.cc
index 41e4cae..93b48fb 100644
--- a/metrics_utils_unittest.cc
+++ b/metrics_utils_unittest.cc
@@ -18,8 +18,6 @@
 
 #include <gtest/gtest.h>
 
-#include "update_engine/common/fake_prefs.h"
-
 namespace chromeos_update_engine {
 namespace metrics_utils {
 
diff --git a/update_manager/real_updater_provider.cc b/update_manager/real_updater_provider.cc
index 4bc28a9..5b76332 100644
--- a/update_manager/real_updater_provider.cc
+++ b/update_manager/real_updater_provider.cc
@@ -299,24 +299,25 @@
       public chromeos_update_engine::PrefsInterface::ObserverInterface {
  public:
   BooleanPrefVariable(const string& name,
-                      chromeos_update_engine::PrefsInterface* prefs,
                       const char* key,
                       bool default_val)
       : AsyncCopyVariable<bool>(name),
-        prefs_(prefs),
         key_(key),
         default_val_(default_val) {
-    prefs->AddObserver(key, this);
+    SystemState::Get()->prefs()->AddObserver(key, this);
     OnPrefSet(key);
   }
-  ~BooleanPrefVariable() { prefs_->RemoveObserver(key_, this); }
+  ~BooleanPrefVariable() {
+    SystemState::Get()->prefs()->RemoveObserver(key_, this);
+  }
 
  private:
   // Reads the actual value from the Prefs instance and updates the Variable
   // value.
   void OnPrefSet(const string& key) override {
     bool result = default_val_;
-    if (prefs_ && prefs_->Exists(key_) && !prefs_->GetBoolean(key_, &result))
+    auto* prefs = SystemState::Get()->prefs();
+    if (prefs->Exists(key_) && !prefs->GetBoolean(key_, &result))
       result = default_val_;
     // AsyncCopyVariable will take care of values that didn't change.
     SetValue(result);
@@ -324,8 +325,6 @@
 
   void OnPrefDeleted(const string& key) override { SetValue(default_val_); }
 
-  chromeos_update_engine::PrefsInterface* prefs_;
-
   // The Boolean preference key and default value.
   const char* const key_;
   const bool default_val_;
@@ -435,11 +434,8 @@
 // A variable class for reading timeout interval prefs value.
 class TestUpdateCheckIntervalTimeoutVariable : public Variable<int64_t> {
  public:
-  TestUpdateCheckIntervalTimeoutVariable(
-      const string& name, chromeos_update_engine::PrefsInterface* prefs)
-      : Variable<int64_t>(name, kVariableModePoll),
-        prefs_(prefs),
-        read_count_(0) {
+  explicit TestUpdateCheckIntervalTimeoutVariable(const string& name)
+      : Variable<int64_t>(name, kVariableModePoll), read_count_(0) {
     SetMissingOk();
   }
   ~TestUpdateCheckIntervalTimeoutVariable() = default;
@@ -448,12 +444,13 @@
   const int64_t* GetValue(TimeDelta /* timeout */,
                           string* /* errmsg */) override {
     auto key = chromeos_update_engine::kPrefsTestUpdateCheckIntervalTimeout;
+    auto* prefs = SystemState::Get()->prefs();
     int64_t result;
-    if (prefs_ && prefs_->Exists(key) && prefs_->GetInt64(key, &result)) {
+    if (prefs->Exists(key) && prefs->GetInt64(key, &result)) {
       // This specific value is used for testing only. So it should not be kept
       // around and should be deleted after a few reads.
       if (++read_count_ > 5)
-        prefs_->Delete(key);
+        prefs->Delete(key);
 
       // Limit the timeout interval to 10 minutes so it is not abused if it is
       // seen on official images.
@@ -462,8 +459,6 @@
     return nullptr;
   }
 
-  chromeos_update_engine::PrefsInterface* prefs_;
-
   // Counts how many times this variable is read. This is used to delete the
   // underlying file defining the variable after a certain number of reads in
   // order to prevent any abuse of this variable.
@@ -487,14 +482,10 @@
       var_payload_size_(new PayloadSizeVariable("payload_size")),
       var_curr_channel_(new CurrChannelVariable("curr_channel")),
       var_new_channel_(new NewChannelVariable("new_channel")),
-      var_p2p_enabled_(
-          new BooleanPrefVariable("p2p_enabled",
-                                  SystemState::Get()->prefs(),
-                                  chromeos_update_engine::kPrefsP2PEnabled,
-                                  false)),
+      var_p2p_enabled_(new BooleanPrefVariable(
+          "p2p_enabled", chromeos_update_engine::kPrefsP2PEnabled, false)),
       var_cellular_enabled_(new BooleanPrefVariable(
           "cellular_enabled",
-          SystemState::Get()->prefs(),
           chromeos_update_engine::kPrefsUpdateOverCellularPermission,
           false)),
       var_consecutive_failed_update_checks_(
@@ -508,6 +499,5 @@
           new UpdateRestrictionsVariable("update_restrictions")),
       var_test_update_check_interval_timeout_(
           new TestUpdateCheckIntervalTimeoutVariable(
-              "test_update_check_interval_timeout",
-              SystemState::Get()->prefs())) {}
+              "test_update_check_interval_timeout")) {}
 }  // namespace chromeos_update_manager
diff --git a/update_manager/real_updater_provider_unittest.cc b/update_manager/real_updater_provider_unittest.cc
index a59a91d..4afe7fc 100644
--- a/update_manager/real_updater_provider_unittest.cc
+++ b/update_manager/real_updater_provider_unittest.cc
@@ -23,7 +23,6 @@
 #include <gtest/gtest.h>
 #include <update_engine/dbus-constants.h>
 
-#include "update_engine/common/fake_prefs.h"
 #include "update_engine/cros/fake_system_state.h"
 #include "update_engine/cros/mock_update_attempter.h"
 #include "update_engine/cros/omaha_request_params.h"
@@ -99,7 +98,6 @@
  protected:
   void SetUp() override {
     FakeSystemState::CreateInstance();
-    FakeSystemState::Get()->set_prefs(&fake_prefs_);
     provider_.reset(new RealUpdaterProvider());
     // Check that provider initializes correctly.
     ASSERT_TRUE(provider_->Init());
@@ -122,7 +120,6 @@
     return kCurrWallclockTime - kDurationSinceUpdate;
   }
 
-  FakePrefs fake_prefs_;
   unique_ptr<RealUpdaterProvider> provider_;
 };
 
@@ -363,22 +360,26 @@
 }
 
 TEST_F(UmRealUpdaterProviderTest, GetP2PEnabledOkayPrefReadsFalse) {
-  fake_prefs_.SetBoolean(chromeos_update_engine::kPrefsP2PEnabled, false);
+  FakeSystemState::Get()->fake_prefs()->SetBoolean(
+      chromeos_update_engine::kPrefsP2PEnabled, false);
   UmTestUtils::ExpectVariableHasValue(false, provider_->var_p2p_enabled());
 }
 
 TEST_F(UmRealUpdaterProviderTest, GetP2PEnabledReadWhenInitialized) {
-  fake_prefs_.SetBoolean(chromeos_update_engine::kPrefsP2PEnabled, true);
-  SetUp();
+  FakeSystemState::Get()->fake_prefs()->SetBoolean(
+      chromeos_update_engine::kPrefsP2PEnabled, true);
+  provider_.reset(new RealUpdaterProvider());
+  ASSERT_TRUE(provider_->Init());
   UmTestUtils::ExpectVariableHasValue(true, provider_->var_p2p_enabled());
 }
 
 TEST_F(UmRealUpdaterProviderTest, GetP2PEnabledUpdated) {
-  fake_prefs_.SetBoolean(chromeos_update_engine::kPrefsP2PEnabled, false);
+  auto* fake_prefs = FakeSystemState::Get()->fake_prefs();
+  fake_prefs->SetBoolean(chromeos_update_engine::kPrefsP2PEnabled, false);
   UmTestUtils::ExpectVariableHasValue(false, provider_->var_p2p_enabled());
-  fake_prefs_.SetBoolean(chromeos_update_engine::kPrefsP2PEnabled, true);
+  fake_prefs->SetBoolean(chromeos_update_engine::kPrefsP2PEnabled, true);
   UmTestUtils::ExpectVariableHasValue(true, provider_->var_p2p_enabled());
-  fake_prefs_.Delete(chromeos_update_engine::kPrefsP2PEnabled);
+  fake_prefs->Delete(chromeos_update_engine::kPrefsP2PEnabled);
   UmTestUtils::ExpectVariableHasValue(false, provider_->var_p2p_enabled());
 }
 
@@ -387,7 +388,7 @@
 }
 
 TEST_F(UmRealUpdaterProviderTest, GetCellularEnabledOkayPrefReadsTrue) {
-  fake_prefs_.SetBoolean(
+  FakeSystemState::Get()->fake_prefs()->SetBoolean(
       chromeos_update_engine::kPrefsUpdateOverCellularPermission, true);
   UmTestUtils::ExpectVariableHasValue(true, provider_->var_cellular_enabled());
 }
@@ -448,14 +449,15 @@
 TEST_F(UmRealUpdaterProviderTest, TestUpdateCheckIntervalTimeout) {
   UmTestUtils::ExpectVariableNotSet(
       provider_->var_test_update_check_interval_timeout());
-  fake_prefs_.SetInt64(
+  auto* fake_prefs = FakeSystemState::Get()->fake_prefs();
+  fake_prefs->SetInt64(
       chromeos_update_engine::kPrefsTestUpdateCheckIntervalTimeout, 1);
   UmTestUtils::ExpectVariableHasValue(
       static_cast<int64_t>(1),
       provider_->var_test_update_check_interval_timeout());
 
   // Make sure the value does not exceed a threshold of 10 minutes.
-  fake_prefs_.SetInt64(
+  fake_prefs->SetInt64(
       chromeos_update_engine::kPrefsTestUpdateCheckIntervalTimeout, 11 * 60);
   // The next 5 reads should return valid values.
   for (int i = 0; i < 5; ++i)
diff --git a/update_manager/staging_utils.cc b/update_manager/staging_utils.cc
index 186da73..a992975 100644
--- a/update_manager/staging_utils.cc
+++ b/update_manager/staging_utils.cc
@@ -26,11 +26,11 @@
 
 #include "update_engine/common/constants.h"
 #include "update_engine/common/hardware_interface.h"
-#include "update_engine/common/prefs_interface.h"
+#include "update_engine/common/system_state.h"
 
 using base::TimeDelta;
 using chromeos_update_engine::kPrefsWallClockStagingWaitPeriod;
-using chromeos_update_engine::PrefsInterface;
+using chromeos_update_engine::SystemState;
 using policy::DevicePolicy;
 
 namespace chromeos_update_manager {
@@ -97,7 +97,6 @@
 }
 
 StagingCase CalculateStagingCase(const DevicePolicy* device_policy,
-                                 PrefsInterface* prefs,
                                  TimeDelta* staging_wait_time,
                                  StagingSchedule* staging_schedule) {
   // Check that the schedule in the device policy is correct.
@@ -127,7 +126,8 @@
   int64_t wait_period_in_days;
   // There exists a persisted value that is valid. That is, it's smaller than
   // the maximum amount of days of staging set by the user.
-  if (prefs->GetInt64(kPrefsWallClockStagingWaitPeriod, &wait_period_in_days) &&
+  if (SystemState::Get()->prefs()->GetInt64(kPrefsWallClockStagingWaitPeriod,
+                                            &wait_period_in_days) &&
       wait_period_in_days > 0 && wait_period_in_days <= max_days) {
     *staging_wait_time = TimeDelta::FromDays(wait_period_in_days);
     return StagingCase::kSetStagingFromPref;
diff --git a/update_manager/staging_utils.h b/update_manager/staging_utils.h
index e91bfeb..0de1dfd 100644
--- a/update_manager/staging_utils.h
+++ b/update_manager/staging_utils.h
@@ -62,7 +62,6 @@
 // contain the previous staging schedule, if there is a new schedule found, its
 // value will be replaced with the new one.
 StagingCase CalculateStagingCase(const policy::DevicePolicy* device_policy,
-                                 chromeos_update_engine::PrefsInterface* prefs,
                                  base::TimeDelta* staging_wait_time,
                                  StagingSchedule* staging_schedule);
 
diff --git a/update_manager/staging_utils_unittest.cc b/update_manager/staging_utils_unittest.cc
index 8d75acd..126617f 100644
--- a/update_manager/staging_utils_unittest.cc
+++ b/update_manager/staging_utils_unittest.cc
@@ -24,10 +24,10 @@
 #include <policy/mock_device_policy.h>
 
 #include "update_engine/common/constants.h"
-#include "update_engine/common/fake_prefs.h"
+#include "update_engine/cros/fake_system_state.h"
 
 using base::TimeDelta;
-using chromeos_update_engine::FakePrefs;
+using chromeos_update_engine::FakeSystemState;
 using chromeos_update_engine::kPrefsWallClockStagingWaitPeriod;
 using testing::_;
 using testing::DoAll;
@@ -44,6 +44,7 @@
 class StagingUtilsScheduleTest : public testing::Test {
  protected:
   void SetUp() override {
+    FakeSystemState::CreateInstance();
     test_wait_time_ = TimeDelta();
     test_staging_schedule_ = StagingSchedule();
   }
@@ -55,14 +56,13 @@
   }
 
   void SetPersistedStagingVal(int64_t wait_time) {
-    EXPECT_TRUE(
-        fake_prefs_.SetInt64(kPrefsWallClockStagingWaitPeriod, wait_time));
+    EXPECT_TRUE(FakeSystemState::Get()->fake_prefs()->SetInt64(
+        kPrefsWallClockStagingWaitPeriod, wait_time));
   }
 
   void TestStagingCase(const StagingCase& expected) {
     EXPECT_EQ(expected,
               CalculateStagingCase(&device_policy_,
-                                   &fake_prefs_,
                                    &test_wait_time_,
                                    &test_staging_schedule_));
   }
@@ -75,7 +75,6 @@
   policy::MockDevicePolicy device_policy_;
   TimeDelta test_wait_time_;
   StagingSchedule test_staging_schedule_;
-  FakePrefs fake_prefs_;
 };
 
 // Last element should be 100, if not return false.