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

Unified Diff: chrome/browser/prefs/profile_pref_store_manager.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: 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 4310f9f16f366f67ec5af9f056b45d24c9b46735..ba8325ed6821c81806e6ad9ca37a796ebc0880e5 100644
--- a/chrome/browser/prefs/profile_pref_store_manager.cc
+++ b/chrome/browser/prefs/profile_pref_store_manager.cc
@@ -23,6 +23,7 @@
#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/cpp/tracked_persistent_pref_store_factory.h"
#if defined(OS_WIN)
#include "chrome/install_static/install_util.h"
@@ -31,14 +32,6 @@
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);
- }
-}
-
#if defined(OS_WIN)
// Forces a different registry key to be used for storing preference validation
// MACs. See |SetPreferenceValidationRegistryPathForTesting|.
@@ -46,6 +39,18 @@ const base::string16* g_preference_validation_registry_path_for_testing =
nullptr;
#endif // OS_WIN
+std::vector<prefs::mojom::TrackedPreferenceMetadataPtr>
+WrapTrackedPreferenceMetadata(
+ const std::vector<PrefHashFilter::TrackedPreferenceMetadata>& input) {
+ std::vector<prefs::mojom::TrackedPreferenceMetadataPtr> output;
+ for (const auto& metadata : input) {
+ output.emplace_back(base::in_place, metadata.reporting_id, metadata.name,
+ metadata.enforcement_level, metadata.strategy,
+ metadata.value_type);
+ }
+ return output;
+}
+
} // namespace
// Preference tracking and protection is not required on platforms where other
@@ -63,14 +68,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_(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() {}
@@ -100,71 +103,16 @@ void ProfilePrefStoreManager::SetPreferenceValidationRegistryPathForTesting(
#endif // OS_WIN
PersistentPrefStore* ProfilePrefStoreManager::CreateProfilePrefStore(
- const scoped_refptr<base::SequencedTaskRunner>& io_task_runner,
+ scoped_refptr<base::SequencedTaskRunner> io_task_runner,
const base::Closure& on_reset_on_load,
prefs::mojom::TrackedPreferenceValidationDelegate* validation_delegate) {
- std::unique_ptr<PrefFilter> pref_filter;
if (!kPlatformSupportsPreferenceTracking) {
return new JsonPrefStore(profile_path_.Append(chrome::kPreferencesFilename),
- io_task_runner.get(),
- std::unique_ptr<PrefFilter>());
+ std::move(io_task_runner), nullptr);
}
-
- 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 (std::vector<PrefHashFilter::TrackedPreferenceMetadata>::const_iterator
- it = tracking_configuration_.begin();
- it != tracking_configuration_.end();
- ++it) {
- if (it->enforcement_level >
- PrefHashFilter::EnforcementLevel::NO_ENFORCEMENT) {
- protected_configuration.push_back(*it);
- protected_pref_names.insert(it->name);
- } else {
- unprotected_configuration.push_back(*it);
- unprotected_pref_names.insert(it->name);
- }
- }
-
- 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 prefs::CreateTrackedPersistentPrefStore(
+ std::move(io_task_runner), CreateTrackedPrefsConfiguration(),
+ validation_delegate, on_reset_on_load);
}
bool ProfilePrefStoreManager::InitializePrefsFromMasterPrefs(
@@ -175,10 +123,10 @@ bool ProfilePrefStoreManager::InitializePrefsFromMasterPrefs(
return false;
if (kPlatformSupportsPreferenceTracking) {
- PrefHashFilter(GetPrefHashStore(false),
- GetExternalVerificationPrefHashStorePair(),
- tracking_configuration_, base::Closure(), NULL,
- reporting_ids_count_, false)
+ PrefHashFilter(
gab 2017/03/21 21:19:22 After this CL this is the only instantiation of Pr
+ base::MakeUnique<PrefHashStoreImpl>(seed_, legacy_device_id_, false),
+ GetExternalVerificationPrefHashStorePair(), tracking_configuration_,
+ base::Closure(), NULL, reporting_ids_count_, false)
.Initialize(master_prefs.get());
}
@@ -198,14 +146,6 @@ 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);
@@ -225,3 +165,22 @@ ProfilePrefStoreManager::GetExternalVerificationPrefHashStorePair() {
return std::make_pair(nullptr, nullptr);
#endif
}
+
+prefs::mojom::TrackedPersistentPrefStoreConfigurationPtr
+ProfilePrefStoreManager::CreateTrackedPrefsConfiguration() {
+ DCHECK(kPlatformSupportsPreferenceTracking);
+ prefs::mojom::TrackedPreferenceValidationDelegatePtr validation_delegate_ptr;
gab 2017/03/28 16:42:08 Unused?
Sam McNally 2017/03/30 09:06:05 Done.
+ return prefs::mojom::TrackedPersistentPrefStoreConfiguration::New(
gab 2017/03/28 16:42:08 Where are things like ::New() documented? I dug ar
Sam McNally 2017/03/30 09:06:05 It does appear that mojo structs and unions are no
+ profile_path_.Append(chrome::kPreferencesFilename),
+ profile_path_.Append(chrome::kSecurePreferencesFilename),
+ WrapTrackedPreferenceMetadata(tracking_configuration_),
+ reporting_ids_count_, seed_, legacy_device_id_,
+#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
+ nullptr, nullptr);
+}

Powered by Google App Engine
This is Rietveld 408576698