Chromium Code Reviews| Index: services/preferences/public/cpp/tracked_persistent_pref_store_factory.cc |
| diff --git a/services/preferences/public/cpp/tracked_persistent_pref_store_factory.cc b/services/preferences/public/cpp/tracked_persistent_pref_store_factory.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..90023a0a3086f885c95afb8c693a40b0b3aaaf0e |
| --- /dev/null |
| +++ b/services/preferences/public/cpp/tracked_persistent_pref_store_factory.cc |
| @@ -0,0 +1,129 @@ |
| +// Copyright 2017 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "services/preferences/public/cpp/tracked_persistent_pref_store_factory.h" |
| + |
| +#include <set> |
| +#include <utility> |
| + |
| +#include "components/prefs/json_pref_store.h" |
| +#include "components/prefs/pref_filter.h" |
| +#include "components/user_prefs/tracked/pref_hash_store_impl.h" |
| +#include "components/user_prefs/tracked/segregated_pref_store.h" |
| +#include "components/user_prefs/tracked/tracked_preferences_migration.h" |
| +#include "services/preferences/public/interfaces/tracked_preference_validation_delegate.mojom.h" |
| + |
| +#if defined(OS_WIN) |
| +#include "components/user_prefs/tracked/registry_hash_store_contents_win.h" |
| +#endif |
| + |
| +namespace prefs { |
| +namespace { |
| + |
| +void RemoveValueSilently(const base::WeakPtr<JsonPrefStore> pref_store, |
| + const std::string& key) { |
| + if (pref_store) { |
| + pref_store->RemoveValueSilently( |
| + key, WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS); |
| + } |
| +} |
| + |
| +std::unique_ptr<PrefHashStore> CreatePrefHashStore( |
| + const std::string& seed, |
| + const std::string& legacy_device_id, |
| + bool use_super_mac) { |
| + return base::MakeUnique<PrefHashStoreImpl>(seed, legacy_device_id, |
| + use_super_mac); |
| +} |
| + |
| +std::pair<std::unique_ptr<PrefHashStore>, std::unique_ptr<HashStoreContents>> |
| +GetExternalVerificationPrefHashStorePair(const std::string& seed, |
| + const std::string& legacy_device_id, |
| + const base::string16& registry_path, |
| + const base::FilePath& prefs_path) { |
| +#if defined(OS_WIN) |
| + return std::make_pair( |
| + base::MakeUnique<PrefHashStoreImpl>(seed, legacy_device_id, |
| + false /* use_super_mac */), |
| + base::MakeUnique<RegistryHashStoreContentsWin>( |
| + registry_path, prefs_path.DirName().BaseName().LossyDisplayName())); |
| +#else |
| + return std::make_pair(nullptr, nullptr); |
| +#endif |
| +} |
| + |
| +} // namespace |
| + |
| +PersistentPrefStore* CreateTrackedPersistentPrefStore( |
| + scoped_refptr<base::SequencedTaskRunner> io_task_runner, |
| + mojom::TrackedPersistentPrefStoreConfigurationPtr config, |
| + mojom::TrackedPreferenceValidationDelegate* validation_delegate, |
| + const base::Closure& on_reset_on_load) { |
| + std::vector<PrefHashFilter::TrackedPreferenceMetadata> |
| + unprotected_configuration; |
| + std::vector<PrefHashFilter::TrackedPreferenceMetadata> |
| + protected_configuration; |
| + std::set<std::string> protected_pref_names; |
| + std::set<std::string> unprotected_pref_names; |
| + for (const auto& metadata : config->tracking_configuration) { |
| + PrefHashFilter::TrackedPreferenceMetadata metadata_view = { |
| + metadata->reporting_id, metadata->name.c_str(), |
| + metadata->enforcement_level, metadata->strategy, |
| + metadata->value_type, |
| + }; |
| + if (metadata->enforcement_level > |
| + mojom::TrackedPreferenceMetadata::EnforcementLevel::NO_ENFORCEMENT) { |
| + protected_configuration.push_back(metadata_view); |
| + protected_pref_names.insert(metadata->name); |
| + } else { |
| + unprotected_configuration.push_back(metadata_view); |
| + unprotected_pref_names.insert(metadata->name); |
| + } |
| + } |
| + |
| + std::unique_ptr<PrefHashFilter> unprotected_pref_hash_filter( |
| + new PrefHashFilter( |
| + CreatePrefHashStore(config->seed, config->legacy_device_id, false), |
| + GetExternalVerificationPrefHashStorePair( |
| + config->seed, config->legacy_device_id, config->registry_path, |
|
gab
2017/03/28 16:42:08
This is the wrong seed, the external hash store us
Sam McNally
2017/03/30 09:06:05
Done.
|
| + config->unprotected_pref_filename), |
| + unprotected_configuration, base::Closure(), validation_delegate, |
| + config->reporting_ids_count, false)); |
| + std::unique_ptr<PrefHashFilter> protected_pref_hash_filter(new PrefHashFilter( |
| + CreatePrefHashStore(config->seed, config->legacy_device_id, true), |
| + GetExternalVerificationPrefHashStorePair( |
| + config->seed, config->legacy_device_id, config->registry_path, |
| + config->unprotected_pref_filename), |
| + protected_configuration, on_reset_on_load, validation_delegate, |
| + config->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(config->unprotected_pref_filename, io_task_runner.get(), |
| + std::move(unprotected_pref_hash_filter))); |
| + scoped_refptr<JsonPrefStore> protected_pref_store( |
| + new JsonPrefStore(config->protected_pref_filename, 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()), |
| + CreatePrefHashStore(config->seed, config->legacy_device_id, false), |
| + CreatePrefHashStore(config->seed, config->legacy_device_id, true), |
| + raw_unprotected_pref_hash_filter, raw_protected_pref_hash_filter); |
| + |
| + return new SegregatedPrefStore(unprotected_pref_store, protected_pref_store, |
| + protected_pref_names); |
| +} |
| + |
| +} // namespace prefs |