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..e0c0f2083cfee232a73983f953d5ecb125dfc14f |
--- /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( |
gab
2017/03/13 16:52:02
Why the :: prefix? Explicit global namespace is un
Sam McNally
2017/03/14 02:01:35
Removed it.
|
+ scoped_refptr<base::SequencedTaskRunner> io_task_runner, |
+ const base::FilePath& unprotected_pref_filename, |
+ const base::FilePath& protected_pref_filename, |
+ const std::vector<PrefHashFilter::TrackedPreferenceMetadata>& |
+ tracking_configuration, |
+ uint64_t reporting_ids_count, |
+ const std::string& seed, |
+ const std::string& legacy_device_id, |
+ const base::string16& registry_path, |
+ 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 : tracking_configuration) { |
+ if (metadata.enforcement_level > |
+ mojom::TrackedPreferenceMetadata::EnforcementLevel::NO_ENFORCEMENT) { |
+ protected_configuration.push_back(metadata); |
+ protected_pref_names.insert(metadata.name); |
+ } else { |
+ unprotected_configuration.push_back(metadata); |
+ unprotected_pref_names.insert(metadata.name); |
+ } |
+ } |
+ |
+ std::unique_ptr<PrefHashFilter> unprotected_pref_hash_filter( |
+ new PrefHashFilter( |
+ CreatePrefHashStore(seed, legacy_device_id, false), |
+ GetExternalVerificationPrefHashStorePair( |
+ seed, legacy_device_id, registry_path, unprotected_pref_filename), |
+ unprotected_configuration, base::Closure(), validation_delegate, |
+ reporting_ids_count, false)); |
+ std::unique_ptr<PrefHashFilter> protected_pref_hash_filter(new PrefHashFilter( |
+ CreatePrefHashStore(seed, legacy_device_id, true), |
+ GetExternalVerificationPrefHashStorePair( |
+ seed, legacy_device_id, registry_path, unprotected_pref_filename), |
+ 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(unprotected_pref_filename, io_task_runner.get(), |
+ std::move(unprotected_pref_hash_filter))); |
+ scoped_refptr<JsonPrefStore> protected_pref_store( |
+ new JsonPrefStore(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(seed, legacy_device_id, false), |
+ CreatePrefHashStore(seed, 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 |