Chromium Code Reviews| 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 b1408398ecc9d271f0ec47b43c669083d79b0c81..f539ce7bb20f42a0aaf0e1368fa8f90270f50019 100644 |
| --- a/chrome/browser/prefs/profile_pref_store_manager.cc |
| +++ b/chrome/browser/prefs/profile_pref_store_manager.cc |
| @@ -6,8 +6,6 @@ |
| #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" |
| @@ -24,29 +22,15 @@ |
| #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/pref_hash_store_impl.h" |
| -#include "services/preferences/tracked/segregated_pref_store.h" |
| -#include "services/preferences/tracked/tracked_preferences_migration.h" |
| +#include "services/preferences/tracked/tracked_persistent_pref_store_factory.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 |
| // MACs. See |SetPreferenceValidationRegistryPathForTesting|. |
| @@ -71,14 +55,12 @@ ProfilePrefStoreManager::ProfilePrefStoreManager( |
| tracking_configuration, |
| size_t reporting_ids_count, |
| const std::string& seed, |
| - const std::string& legacy_device_id, |
| - PrefService* local_state) |
| + const std::string& legacy_device_id) |
| : profile_path_(profile_path), |
| tracking_configuration_(std::move(tracking_configuration)), |
| reporting_ids_count_(reporting_ids_count), |
| seed_(seed), |
| - legacy_device_id_(legacy_device_id), |
| - local_state_(local_state) {} |
| + legacy_device_id_(legacy_device_id) {} |
| ProfilePrefStoreManager::~ProfilePrefStoreManager() {} |
| @@ -108,76 +90,29 @@ void ProfilePrefStoreManager::SetPreferenceValidationRegistryPathForTesting( |
| #endif // OS_WIN |
| PersistentPrefStore* ProfilePrefStoreManager::CreateProfilePrefStore( |
| - const scoped_refptr<base::SequencedTaskRunner>& io_task_runner, |
| - const base::Closure& on_reset_on_load, |
| - prefs::mojom::TrackedPreferenceValidationDelegate* validation_delegate, |
| + base::SequencedWorkerPool* worker_pool, |
| + prefs::mojom::ResetOnLoadObserverPtr reset_on_load_observer, |
| + prefs::mojom::TrackedPreferenceValidationDelegatePtr validation_delegate, |
| service_manager::Connector* connector, |
| scoped_refptr<PrefRegistry> pref_registry) { |
| if (features::PrefServiceEnabled()) { |
| - ConfigurePrefService(on_reset_on_load, connector); |
| + ConfigurePrefService(std::move(reset_on_load_observer), |
| + std::move(validation_delegate), 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), |
| - io_task_runner.get(), |
| - std::unique_ptr<PrefFilter>()); |
| + return new JsonPrefStore( |
| + profile_path_.Append(chrome::kPreferencesFilename), |
| + JsonPrefStore::GetTaskRunnerForFile(profile_path_, worker_pool), |
| + nullptr); |
| } |
| - |
| - 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); |
| + return CreateTrackedPersistentPrefStore( |
| + CreateTrackedPrefStoreConfiguration(std::move(reset_on_load_observer), |
| + std::move(validation_delegate)), |
| + worker_pool); |
| } |
| bool ProfilePrefStoreManager::InitializePrefsFromMasterPrefs( |
| @@ -188,11 +123,8 @@ bool ProfilePrefStoreManager::InitializePrefsFromMasterPrefs( |
| return false; |
| if (kPlatformSupportsPreferenceTracking) { |
| - PrefHashFilter(GetPrefHashStore(false), |
| - GetExternalVerificationPrefHashStorePair(), |
| - tracking_configuration_, base::Closure(), NULL, |
| - reporting_ids_count_, false) |
| - .Initialize(master_prefs.get()); |
| + InitializeMasterPrefsTracking( |
| + CreateTrackedPrefStoreConfiguration({}, nullptr), master_prefs.get()); |
| } |
| // This will write out to a single combined file which will be immediately |
| @@ -211,42 +143,39 @@ bool ProfilePrefStoreManager::InitializePrefsFromMasterPrefs( |
| 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( |
| - const base::Closure& on_reset_on_load, |
| + prefs::mojom::ResetOnLoadObserverPtr reset_on_load_observer, |
| + prefs::mojom::TrackedPreferenceValidationDelegatePtr validation_delegate, |
| service_manager::Connector* connector) { |
| auto config = prefs::mojom::PersistentPrefStoreConfiguration::New(); |
| - config->set_simple_configuration( |
| - prefs::mojom::SimplePersistentPrefStoreConfiguration::New( |
| - profile_path_.Append(chrome::kPreferencesFilename))); |
| + if (!kPlatformSupportsPreferenceTracking) { |
| + config->set_simple_configuration( |
| + prefs::mojom::SimplePersistentPrefStoreConfiguration::New( |
| + profile_path_.Append(chrome::kPreferencesFilename))); |
| + } else { |
| + config->set_tracked_configuration(CreateTrackedPrefStoreConfiguration( |
| + std::move(reset_on_load_observer), std::move(validation_delegate))); |
| + } |
| prefs::mojom::PrefServiceControlPtr control; |
| connector->BindInterface(prefs::mojom::kServiceName, &control); |
| control->Init(std::move(config)); |
| } |
| + |
| +prefs::mojom::TrackedPersistentPrefStoreConfigurationPtr |
| +ProfilePrefStoreManager::CreateTrackedPrefStoreConfiguration( |
| + 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_, |
|
gab
2017/04/03 16:11:17
This move means this ProfilePrefStoreManager can o
Sam McNally
2017/04/04 03:24:49
Done.
|
| + 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)); |
| +} |