Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1681)

Unified Diff: chrome/browser/prefs/profile_pref_store_manager.cc

Issue 2799043003: Revert of Pref service: add support for tracked prefs. (Closed)
Patch Set: Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/prefs/profile_pref_store_manager.cc
diff --git a/chrome/browser/prefs/profile_pref_store_manager.cc b/chrome/browser/prefs/profile_pref_store_manager.cc
index ea22fbb65b28e91794bd2951f73fb459ed0cd514..b1408398ecc9d271f0ec47b43c669083d79b0c81 100644
--- a/chrome/browser/prefs/profile_pref_store_manager.cc
+++ b/chrome/browser/prefs/profile_pref_store_manager.cc
@@ -6,6 +6,8 @@
#include <utility>
+#include "base/bind.h"
+#include "base/callback.h"
#include "base/files/file_util.h"
#include "base/json/json_file_value_serializer.h"
#include "base/logging.h"
@@ -22,14 +24,28 @@
#include "services/preferences/public/cpp/persistent_pref_store_client.h"
#include "services/preferences/public/interfaces/preferences.mojom.h"
#include "services/preferences/tracked/pref_hash_filter.h"
-#include "services/preferences/tracked/tracked_persistent_pref_store_factory.h"
+#include "services/preferences/tracked/pref_hash_store_impl.h"
+#include "services/preferences/tracked/segregated_pref_store.h"
+#include "services/preferences/tracked/tracked_preferences_migration.h"
#include "services/service_manager/public/cpp/connector.h"
#if defined(OS_WIN)
#include "chrome/install_static/install_util.h"
+#include "services/preferences/tracked/registry_hash_store_contents_win.h"
#endif
namespace {
+
+using EnforcementLevel =
+ prefs::mojom::TrackedPreferenceMetadata::EnforcementLevel;
+
+void RemoveValueSilently(const base::WeakPtr<JsonPrefStore> pref_store,
+ const std::string& key) {
+ if (pref_store) {
+ pref_store->RemoveValueSilently(
+ key, WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS);
+ }
+}
#if defined(OS_WIN)
// Forces a different registry key to be used for storing preference validation
@@ -51,11 +67,18 @@
ProfilePrefStoreManager::ProfilePrefStoreManager(
const base::FilePath& profile_path,
+ std::vector<prefs::mojom::TrackedPreferenceMetadataPtr>
+ tracking_configuration,
+ size_t reporting_ids_count,
const std::string& seed,
- const std::string& legacy_device_id)
+ const std::string& legacy_device_id,
+ PrefService* local_state)
: profile_path_(profile_path),
+ tracking_configuration_(std::move(tracking_configuration)),
+ reporting_ids_count_(reporting_ids_count),
seed_(seed),
- legacy_device_id_(legacy_device_id) {}
+ legacy_device_id_(legacy_device_id),
+ local_state_(local_state) {}
ProfilePrefStoreManager::~ProfilePrefStoreManager() {}
@@ -85,40 +108,79 @@
#endif // OS_WIN
PersistentPrefStore* ProfilePrefStoreManager::CreateProfilePrefStore(
- std::vector<prefs::mojom::TrackedPreferenceMetadataPtr>
- tracking_configuration,
- size_t reporting_ids_count,
- base::SequencedWorkerPool* worker_pool,
- prefs::mojom::ResetOnLoadObserverPtr reset_on_load_observer,
- prefs::mojom::TrackedPreferenceValidationDelegatePtr validation_delegate,
+ const scoped_refptr<base::SequencedTaskRunner>& io_task_runner,
+ const base::Closure& on_reset_on_load,
+ prefs::mojom::TrackedPreferenceValidationDelegate* validation_delegate,
service_manager::Connector* connector,
scoped_refptr<PrefRegistry> pref_registry) {
if (features::PrefServiceEnabled()) {
- ConfigurePrefService(std::move(tracking_configuration), reporting_ids_count,
- std::move(reset_on_load_observer),
- std::move(validation_delegate), connector);
+ ConfigurePrefService(on_reset_on_load, connector);
prefs::mojom::PrefStoreConnectorPtr pref_connector;
connector->BindInterface(prefs::mojom::kServiceName, &pref_connector);
return new prefs::PersistentPrefStoreClient(std::move(pref_connector),
std::move(pref_registry));
}
if (!kPlatformSupportsPreferenceTracking) {
- return new JsonPrefStore(
- profile_path_.Append(chrome::kPreferencesFilename),
- JsonPrefStore::GetTaskRunnerForFile(profile_path_, worker_pool),
- nullptr);
- }
- return CreateTrackedPersistentPrefStore(
- CreateTrackedPrefStoreConfiguration(
- std::move(tracking_configuration), reporting_ids_count,
- std::move(reset_on_load_observer), std::move(validation_delegate)),
- worker_pool);
+ return new JsonPrefStore(profile_path_.Append(chrome::kPreferencesFilename),
+ io_task_runner.get(),
+ std::unique_ptr<PrefFilter>());
+ }
+
+ std::vector<prefs::mojom::TrackedPreferenceMetadataPtr>
+ unprotected_configuration;
+ std::vector<prefs::mojom::TrackedPreferenceMetadataPtr>
+ protected_configuration;
+ std::set<std::string> protected_pref_names;
+ std::set<std::string> unprotected_pref_names;
+ for (auto& metadata : tracking_configuration_) {
+ if (metadata->enforcement_level > EnforcementLevel::NO_ENFORCEMENT) {
+ protected_pref_names.insert(metadata->name);
+ protected_configuration.push_back(std::move(metadata));
+ } else {
+ unprotected_pref_names.insert(metadata->name);
+ unprotected_configuration.push_back(std::move(metadata));
+ }
+ }
+ tracking_configuration_.clear();
+
+ std::unique_ptr<PrefHashFilter> unprotected_pref_hash_filter(
+ new PrefHashFilter(GetPrefHashStore(false),
+ GetExternalVerificationPrefHashStorePair(),
+ unprotected_configuration, base::Closure(),
+ validation_delegate, reporting_ids_count_, false));
+ std::unique_ptr<PrefHashFilter> protected_pref_hash_filter(new PrefHashFilter(
+ GetPrefHashStore(true), GetExternalVerificationPrefHashStorePair(),
+ protected_configuration, on_reset_on_load, validation_delegate,
+ reporting_ids_count_, true));
+
+ PrefHashFilter* raw_unprotected_pref_hash_filter =
+ unprotected_pref_hash_filter.get();
+ PrefHashFilter* raw_protected_pref_hash_filter =
+ protected_pref_hash_filter.get();
+
+ scoped_refptr<JsonPrefStore> unprotected_pref_store(new JsonPrefStore(
+ profile_path_.Append(chrome::kPreferencesFilename), io_task_runner.get(),
+ std::move(unprotected_pref_hash_filter)));
+ scoped_refptr<JsonPrefStore> protected_pref_store(new JsonPrefStore(
+ profile_path_.Append(chrome::kSecurePreferencesFilename),
+ io_task_runner.get(), std::move(protected_pref_hash_filter)));
+
+ SetupTrackedPreferencesMigration(
+ unprotected_pref_names, protected_pref_names,
+ base::Bind(&RemoveValueSilently, unprotected_pref_store->AsWeakPtr()),
+ base::Bind(&RemoveValueSilently, protected_pref_store->AsWeakPtr()),
+ base::Bind(&JsonPrefStore::RegisterOnNextSuccessfulWriteReply,
+ unprotected_pref_store->AsWeakPtr()),
+ base::Bind(&JsonPrefStore::RegisterOnNextSuccessfulWriteReply,
+ protected_pref_store->AsWeakPtr()),
+ GetPrefHashStore(false), GetPrefHashStore(true),
+ raw_unprotected_pref_hash_filter, raw_protected_pref_hash_filter);
+
+ return new SegregatedPrefStore(unprotected_pref_store, protected_pref_store,
+ protected_pref_names);
}
bool ProfilePrefStoreManager::InitializePrefsFromMasterPrefs(
- std::vector<prefs::mojom::TrackedPreferenceMetadataPtr>
- tracking_configuration,
- size_t reporting_ids_count,
std::unique_ptr<base::DictionaryValue> master_prefs) {
// Create the profile directory if it doesn't exist yet (very possible on
// first run).
@@ -126,10 +188,11 @@
return false;
if (kPlatformSupportsPreferenceTracking) {
- InitializeMasterPrefsTracking(
- CreateTrackedPrefStoreConfiguration(std::move(tracking_configuration),
- reporting_ids_count, {}, nullptr),
- master_prefs.get());
+ PrefHashFilter(GetPrefHashStore(false),
+ GetExternalVerificationPrefHashStorePair(),
+ tracking_configuration_, base::Closure(), NULL,
+ reporting_ids_count_, false)
+ .Initialize(master_prefs.get());
}
// This will write out to a single combined file which will be immediately
@@ -148,46 +211,42 @@
return success;
}
+std::unique_ptr<PrefHashStore> ProfilePrefStoreManager::GetPrefHashStore(
+ bool use_super_mac) {
+ DCHECK(kPlatformSupportsPreferenceTracking);
+
+ return std::unique_ptr<PrefHashStore>(
+ new PrefHashStoreImpl(seed_, legacy_device_id_, use_super_mac));
+}
+
+std::pair<std::unique_ptr<PrefHashStore>, std::unique_ptr<HashStoreContents>>
+ProfilePrefStoreManager::GetExternalVerificationPrefHashStorePair() {
+ DCHECK(kPlatformSupportsPreferenceTracking);
+#if defined(OS_WIN)
+ return std::make_pair(
+ base::MakeUnique<PrefHashStoreImpl>(
+ "ChromeRegistryHashStoreValidationSeed", legacy_device_id_,
+ false /* use_super_mac */),
+ g_preference_validation_registry_path_for_testing
+ ? base::MakeUnique<RegistryHashStoreContentsWin>(
+ *g_preference_validation_registry_path_for_testing,
+ profile_path_.BaseName().LossyDisplayName())
+ : base::MakeUnique<RegistryHashStoreContentsWin>(
+ install_static::GetRegistryPath(),
+ profile_path_.BaseName().LossyDisplayName()));
+#else
+ return std::make_pair(nullptr, nullptr);
+#endif
+}
+
void ProfilePrefStoreManager::ConfigurePrefService(
- std::vector<prefs::mojom::TrackedPreferenceMetadataPtr>
- tracking_configuration,
- size_t reporting_ids_count,
- prefs::mojom::ResetOnLoadObserverPtr reset_on_load_observer,
- prefs::mojom::TrackedPreferenceValidationDelegatePtr validation_delegate,
+ const base::Closure& on_reset_on_load,
service_manager::Connector* connector) {
auto config = prefs::mojom::PersistentPrefStoreConfiguration::New();
- if (!kPlatformSupportsPreferenceTracking) {
- config->set_simple_configuration(
- prefs::mojom::SimplePersistentPrefStoreConfiguration::New(
- profile_path_.Append(chrome::kPreferencesFilename)));
- } else {
- config->set_tracked_configuration(CreateTrackedPrefStoreConfiguration(
- std::move(tracking_configuration), reporting_ids_count,
- std::move(reset_on_load_observer), std::move(validation_delegate)));
- }
+ config->set_simple_configuration(
+ prefs::mojom::SimplePersistentPrefStoreConfiguration::New(
+ profile_path_.Append(chrome::kPreferencesFilename)));
prefs::mojom::PrefServiceControlPtr control;
connector->BindInterface(prefs::mojom::kServiceName, &control);
control->Init(std::move(config));
}
-
-prefs::mojom::TrackedPersistentPrefStoreConfigurationPtr
-ProfilePrefStoreManager::CreateTrackedPrefStoreConfiguration(
- std::vector<prefs::mojom::TrackedPreferenceMetadataPtr>
- tracking_configuration,
- size_t reporting_ids_count,
- prefs::mojom::ResetOnLoadObserverPtr reset_on_load_observer,
- prefs::mojom::TrackedPreferenceValidationDelegatePtr validation_delegate) {
- return prefs::mojom::TrackedPersistentPrefStoreConfiguration::New(
- profile_path_.Append(chrome::kPreferencesFilename),
- profile_path_.Append(chrome::kSecurePreferencesFilename),
- std::move(tracking_configuration), reporting_ids_count, seed_,
- legacy_device_id_, "ChromeRegistryHashStoreValidationSeed",
-#if defined(OS_WIN)
- g_preference_validation_registry_path_for_testing
- ? *g_preference_validation_registry_path_for_testing
- : install_static::GetRegistryPath(),
-#else
- base::string16(),
-#endif
- std::move(validation_delegate), std::move(reset_on_load_observer));
-}
« no previous file with comments | « chrome/browser/prefs/profile_pref_store_manager.h ('k') | chrome/browser/prefs/profile_pref_store_manager_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698