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

Unified Diff: chrome/browser/prefs/profile_pref_store_manager.cc

Issue 2743463002: WIP: Pref service user 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 891e7be0844b4ae6ca38065342c3fe0ad4b4333d..32cbba7f723d119fe6c89efa6554fe7be125a229 100644
--- a/chrome/browser/prefs/profile_pref_store_manager.cc
+++ b/chrome/browser/prefs/profile_pref_store_manager.cc
@@ -16,6 +16,7 @@
#include "base/sequenced_task_runner.h"
#include "build/build_config.h"
#include "chrome/common/chrome_constants.h"
+#include "chrome/common/chrome_features.h"
#include "components/pref_registry/pref_registry_syncable.h"
#include "components/prefs/json_pref_store.h"
#include "components/prefs/persistent_pref_store.h"
@@ -23,6 +24,9 @@
#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/public/interfaces/preferences.mojom.h"
+#include "services/service_manager/public/cpp/connector.h"
#if defined(OS_WIN)
#include "chrome/install_static/install_util.h"
@@ -46,6 +50,31 @@ const base::string16* g_preference_validation_registry_path_for_testing =
nullptr;
#endif // OS_WIN
+class ResetOnLoadObserverImpl : public prefs::mojom::ResetOnLoadObserver {
+ public:
+ explicit ResetOnLoadObserverImpl(const base::Closure& on_reset_on_load)
+ : on_reset_on_load_(on_reset_on_load) {
+ DCHECK(on_reset_on_load_);
+ }
+
+ void OnResetOnLoad() override { on_reset_on_load_.Run(); }
+
+ private:
+ base::Closure on_reset_on_load_;
+};
+
+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
@@ -100,10 +129,18 @@ void ProfilePrefStoreManager::SetPreferenceValidationRegistryPathForTesting(
#endif // OS_WIN
PersistentPrefStore* ProfilePrefStoreManager::CreateProfilePrefStore(
+ const scoped_refptr<base::SingleThreadTaskRunner>& pref_task_runner,
const 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;
+ std::unique_ptr<prefs::mojom::TrackedPreferenceValidationDelegate>*
+ validation_delegate,
+ service_manager::Connector* connector) {
+ DCHECK(validation_delegate);
+ if (base::FeatureList::IsEnabled(features::kPrefService)) {
+ ConfigurePrefServiceUserPrefs(on_reset_on_load,
+ std::move(*validation_delegate), connector);
+ return nullptr;
+ }
if (!kPlatformSupportsPreferenceTracking) {
return new JsonPrefStore(profile_path_.Append(chrome::kPreferencesFilename),
io_task_runner.get(),
@@ -120,7 +157,8 @@ PersistentPrefStore* ProfilePrefStoreManager::CreateProfilePrefStore(
it = tracking_configuration_.begin();
it != tracking_configuration_.end();
++it) {
- if (it->enforcement_level > PrefHashFilter::NO_ENFORCEMENT) {
+ if (it->enforcement_level >
+ PrefHashFilter::EnforcementLevel::NO_ENFORCEMENT) {
protected_configuration.push_back(*it);
protected_pref_names.insert(it->name);
} else {
@@ -130,13 +168,13 @@ PersistentPrefStore* ProfilePrefStoreManager::CreateProfilePrefStore(
}
std::unique_ptr<PrefHashFilter> unprotected_pref_hash_filter(
- new PrefHashFilter(GetPrefHashStore(false),
- GetExternalVerificationPrefHashStorePair(),
- unprotected_configuration, base::Closure(),
- validation_delegate, reporting_ids_count_, false));
+ new PrefHashFilter(
+ GetPrefHashStore(false), GetExternalVerificationPrefHashStorePair(),
+ unprotected_configuration, base::Closure(),
+ validation_delegate->get(), 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,
+ protected_configuration, on_reset_on_load, validation_delegate->get(),
reporting_ids_count_, true));
PrefHashFilter* raw_unprotected_pref_hash_filter =
@@ -227,3 +265,47 @@ ProfilePrefStoreManager::GetExternalVerificationPrefHashStorePair() {
return std::make_pair(nullptr, nullptr);
#endif
}
+
+void ProfilePrefStoreManager::ConfigurePrefServiceUserPrefs(
+ const base::Closure& on_reset_on_load,
+ std::unique_ptr<prefs::mojom::TrackedPreferenceValidationDelegate>
+ validation_delegate,
+ service_manager::Connector* connector) {
+ auto config = prefs::mojom::UserPrefsConfiguration::New();
+ if (!kPlatformSupportsPreferenceTracking) {
+ config->set_simple_configuration(
+ prefs::mojom::SimpleUserPrefsConfiguration::New(
+ profile_path_.Append(chrome::kPreferencesFilename)));
+ } else {
+ prefs::mojom::TrackedPreferenceValidationDelegatePtr
+ validation_delegate_ptr;
+ if (validation_delegate) {
+ mojo::MakeStrongBinding(std::move(validation_delegate),
+ mojo::MakeRequest(&validation_delegate_ptr));
+ }
+ prefs::mojom::ResetOnLoadObserverPtr reset_on_load_observer;
+ if (on_reset_on_load) {
+ mojo::MakeStrongBinding(
+ base::MakeUnique<ResetOnLoadObserverImpl>(on_reset_on_load),
+ mojo::MakeRequest(&reset_on_load_observer));
+ }
+ config->set_segregated_configuration(
+ prefs::mojom::SegregatedUserPrefsConfiguration::New(
+ 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
+ : BrowserDistribution::GetDistribution()->GetRegistryPath(),
+#else
+ base::string16(),
+#endif
+ std::move(validation_delegate_ptr),
+ std::move(reset_on_load_observer)));
+ }
+ prefs::mojom::PersistentPrefStoreInitPtr init;
+ connector->BindInterface(prefs::mojom::kPrefStoreServiceName, &init);
+ init->Init(std::move(config));
+}
« no previous file with comments | « chrome/browser/prefs/profile_pref_store_manager.h ('k') | chrome/browser/prefs/profile_pref_store_manager_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698