| 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 2b7fd460bbc4f6d455a89e9b1862fba8f723b5eb..dac7ee226bfa3ed8b2a7f2a85826fc247253d675 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"
|
| @@ -25,29 +23,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|.
|
| @@ -68,18 +52,11 @@ const bool ProfilePrefStoreManager::kPlatformSupportsPreferenceTracking =
|
|
|
| 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,
|
| - 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() {}
|
|
|
| @@ -109,13 +86,18 @@ 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,
|
| + 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,
|
| service_manager::Connector* connector,
|
| scoped_refptr<PrefRegistry> pref_registry) {
|
| if (features::PrefServiceEnabled()) {
|
| - ConfigurePrefService(on_reset_on_load, connector);
|
| + ConfigurePrefService(std::move(tracking_configuration), reporting_ids_count,
|
| + std::move(reset_on_load_observer),
|
| + std::move(validation_delegate), connector);
|
| prefs::mojom::PrefStoreConnectorPtr pref_connector;
|
| connector->BindInterface(prefs::mojom::kServiceName, &pref_connector);
|
| auto in_process_types_set = chrome::InProcessPrefStores();
|
| @@ -126,66 +108,22 @@ PersistentPrefStore* ProfilePrefStoreManager::CreateProfilePrefStore(
|
| std::move(in_process_types));
|
| }
|
| if (!kPlatformSupportsPreferenceTracking) {
|
| - 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));
|
| - }
|
| + return new JsonPrefStore(
|
| + profile_path_.Append(chrome::kPreferencesFilename),
|
| + JsonPrefStore::GetTaskRunnerForFile(profile_path_, worker_pool),
|
| + nullptr);
|
| }
|
| - 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(tracking_configuration), reporting_ids_count,
|
| + std::move(reset_on_load_observer), std::move(validation_delegate)),
|
| + worker_pool);
|
| }
|
|
|
| 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).
|
| @@ -193,11 +131,10 @@ 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(std::move(tracking_configuration),
|
| + reporting_ids_count, {}, nullptr),
|
| + master_prefs.get());
|
| }
|
|
|
| // This will write out to a single combined file which will be immediately
|
| @@ -216,42 +153,46 @@ 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,
|
| + std::vector<prefs::mojom::TrackedPreferenceMetadataPtr>
|
| + tracking_configuration,
|
| + size_t reporting_ids_count,
|
| + 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(tracking_configuration), reporting_ids_count,
|
| + 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(
|
| + 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));
|
| +}
|
|
|