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

Unified Diff: services/preferences/persistent_pref_store_factory.cc

Issue 2745563005: Pref service: add support for tracked prefs. (Closed)
Patch Set: Created 3 years, 9 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: services/preferences/persistent_pref_store_factory.cc
diff --git a/services/preferences/persistent_pref_store_factory.cc b/services/preferences/persistent_pref_store_factory.cc
index c9909fbbe6942d6d2a07d05e7f0d1a192e63c21c..d353ab8c9a639c759285fd5856f815e39d98f2e1 100644
--- a/services/preferences/persistent_pref_store_factory.cc
+++ b/services/preferences/persistent_pref_store_factory.cc
@@ -5,15 +5,65 @@
#include "services/preferences/persistent_pref_store_factory.h"
#include <memory>
+#include <set>
+#include <string>
#include <utility>
+#include <vector>
#include "components/prefs/json_pref_store.h"
#include "components/prefs/pref_filter.h"
+#include "components/user_prefs/tracked/pref_hash_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 "mojo/public/cpp/bindings/strong_binding.h"
#include "services/preferences/persistent_pref_store_impl.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
+}
+
+void ForwardToResetOnLoadObserver(mojom::ResetOnLoadObserverPtr observer) {
+ if (observer)
+ observer->OnResetOnLoad();
+}
+
std::unique_ptr<PersistentPrefStoreImpl> CreateSimplePersistentPrefStore(
mojom::SimplePersistentPrefStoreConfigurationPtr config,
base::SequencedWorkerPool* worker_pool) {
@@ -25,6 +75,82 @@ std::unique_ptr<PersistentPrefStoreImpl> CreateSimplePersistentPrefStore(
nullptr);
}
+std::unique_ptr<PersistentPrefStoreImpl> CreateTrackedPersistentPrefStore(
tibell 2017/03/10 04:29:01 Does this method have to be kept in sync with some
Sam McNally 2017/03/10 05:04:44 Extracted out the common parts.
+ mojom::TrackedPersistentPrefStoreConfigurationPtr config,
+ base::SequencedWorkerPool* worker_pool) {
+ 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,
+ config->unprotected_pref_filename),
+ unprotected_configuration, base::Closure(),
+ config->validation_delegate.get(), 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,
+ base::Bind(&ForwardToResetOnLoadObserver,
+ base::Passed(&config->reset_on_load_observer)),
+ config->validation_delegate.get(), 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();
+
+ auto io_task_runner = JsonPrefStore::GetTaskRunnerForFile(
+ config->unprotected_pref_filename.DirName(), worker_pool);
+ 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 base::MakeUnique<PersistentPrefStoreImpl>(
+ new SegregatedPrefStore(unprotected_pref_store, protected_pref_store,
+ protected_pref_names),
+ std::move(config->validation_delegate));
+}
+
} // namespace
std::unique_ptr<PersistentPrefStoreImpl> CreatePersistentPrefStore(
@@ -34,6 +160,10 @@ std::unique_ptr<PersistentPrefStoreImpl> CreatePersistentPrefStore(
return CreateSimplePersistentPrefStore(
std::move(configuration->get_simple_configuration()), worker_pool);
}
+ if (configuration->is_tracked_configuration()) {
+ return CreateTrackedPersistentPrefStore(
+ std::move(configuration->get_tracked_configuration()), worker_pool);
+ }
NOTREACHED();
return nullptr;
}

Powered by Google App Engine
This is Rietveld 408576698