| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/prefs/profile_pref_store_manager.h" | 5 #include "chrome/browser/prefs/profile_pref_store_manager.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/callback.h" | 10 #include "base/callback.h" |
| 11 #include "base/files/file_util.h" | 11 #include "base/files/file_util.h" |
| 12 #include "base/json/json_file_value_serializer.h" | 12 #include "base/json/json_file_value_serializer.h" |
| 13 #include "base/logging.h" | 13 #include "base/logging.h" |
| 14 #include "base/memory/ptr_util.h" | 14 #include "base/memory/ptr_util.h" |
| 15 #include "base/metrics/histogram_macros.h" | 15 #include "base/metrics/histogram_macros.h" |
| 16 #include "base/sequenced_task_runner.h" | 16 #include "base/sequenced_task_runner.h" |
| 17 #include "build/build_config.h" | 17 #include "build/build_config.h" |
| 18 #include "chrome/common/chrome_constants.h" | 18 #include "chrome/common/chrome_constants.h" |
| 19 #include "chrome/common/chrome_features.h" |
| 19 #include "components/pref_registry/pref_registry_syncable.h" | 20 #include "components/pref_registry/pref_registry_syncable.h" |
| 20 #include "components/prefs/json_pref_store.h" | 21 #include "components/prefs/json_pref_store.h" |
| 21 #include "components/prefs/persistent_pref_store.h" | 22 #include "components/prefs/persistent_pref_store.h" |
| 22 #include "components/prefs/pref_registry_simple.h" | 23 #include "components/prefs/pref_registry_simple.h" |
| 23 #include "components/user_prefs/tracked/pref_hash_store_impl.h" | 24 #include "components/user_prefs/tracked/pref_hash_store_impl.h" |
| 24 #include "components/user_prefs/tracked/segregated_pref_store.h" | 25 #include "components/user_prefs/tracked/segregated_pref_store.h" |
| 25 #include "components/user_prefs/tracked/tracked_preferences_migration.h" | 26 #include "components/user_prefs/tracked/tracked_preferences_migration.h" |
| 27 #include "services/preferences/public/cpp/persistent_pref_store_client.h" |
| 28 #include "services/preferences/public/interfaces/preferences.mojom.h" |
| 29 #include "services/service_manager/public/cpp/connector.h" |
| 26 | 30 |
| 27 #if defined(OS_WIN) | 31 #if defined(OS_WIN) |
| 28 #include "chrome/install_static/install_util.h" | 32 #include "chrome/install_static/install_util.h" |
| 29 #include "components/user_prefs/tracked/registry_hash_store_contents_win.h" | 33 #include "components/user_prefs/tracked/registry_hash_store_contents_win.h" |
| 30 #endif | 34 #endif |
| 31 | 35 |
| 32 namespace { | 36 namespace { |
| 33 | 37 |
| 34 void RemoveValueSilently(const base::WeakPtr<JsonPrefStore> pref_store, | 38 void RemoveValueSilently(const base::WeakPtr<JsonPrefStore> pref_store, |
| 35 const std::string& key) { | 39 const std::string& key) { |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 void ProfilePrefStoreManager::SetPreferenceValidationRegistryPathForTesting( | 99 void ProfilePrefStoreManager::SetPreferenceValidationRegistryPathForTesting( |
| 96 const base::string16* path) { | 100 const base::string16* path) { |
| 97 DCHECK(!path->empty()); | 101 DCHECK(!path->empty()); |
| 98 g_preference_validation_registry_path_for_testing = path; | 102 g_preference_validation_registry_path_for_testing = path; |
| 99 } | 103 } |
| 100 #endif // OS_WIN | 104 #endif // OS_WIN |
| 101 | 105 |
| 102 PersistentPrefStore* ProfilePrefStoreManager::CreateProfilePrefStore( | 106 PersistentPrefStore* ProfilePrefStoreManager::CreateProfilePrefStore( |
| 103 const scoped_refptr<base::SequencedTaskRunner>& io_task_runner, | 107 const scoped_refptr<base::SequencedTaskRunner>& io_task_runner, |
| 104 const base::Closure& on_reset_on_load, | 108 const base::Closure& on_reset_on_load, |
| 105 prefs::mojom::TrackedPreferenceValidationDelegate* validation_delegate) { | 109 prefs::mojom::TrackedPreferenceValidationDelegate* validation_delegate, |
| 106 std::unique_ptr<PrefFilter> pref_filter; | 110 service_manager::Connector* connector) { |
| 111 if (base::FeatureList::IsEnabled(features::kPrefService)) { |
| 112 ConfigurePrefService(on_reset_on_load, connector); |
| 113 prefs::mojom::PersistentPrefStoreConnectorPtr pref_connector; |
| 114 connector->BindInterface(prefs::mojom::kPrefStoreServiceName, |
| 115 &pref_connector); |
| 116 return new prefs::PersistentPrefStoreClient(std::move(pref_connector)); |
| 117 } |
| 107 if (!kPlatformSupportsPreferenceTracking) { | 118 if (!kPlatformSupportsPreferenceTracking) { |
| 108 return new JsonPrefStore(profile_path_.Append(chrome::kPreferencesFilename), | 119 return new JsonPrefStore(profile_path_.Append(chrome::kPreferencesFilename), |
| 109 io_task_runner.get(), | 120 io_task_runner.get(), |
| 110 std::unique_ptr<PrefFilter>()); | 121 std::unique_ptr<PrefFilter>()); |
| 111 } | 122 } |
| 112 | 123 |
| 113 std::vector<PrefHashFilter::TrackedPreferenceMetadata> | 124 std::vector<PrefHashFilter::TrackedPreferenceMetadata> |
| 114 unprotected_configuration; | 125 unprotected_configuration; |
| 115 std::vector<PrefHashFilter::TrackedPreferenceMetadata> | 126 std::vector<PrefHashFilter::TrackedPreferenceMetadata> |
| 116 protected_configuration; | 127 protected_configuration; |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 218 ? base::MakeUnique<RegistryHashStoreContentsWin>( | 229 ? base::MakeUnique<RegistryHashStoreContentsWin>( |
| 219 *g_preference_validation_registry_path_for_testing, | 230 *g_preference_validation_registry_path_for_testing, |
| 220 profile_path_.BaseName().LossyDisplayName()) | 231 profile_path_.BaseName().LossyDisplayName()) |
| 221 : base::MakeUnique<RegistryHashStoreContentsWin>( | 232 : base::MakeUnique<RegistryHashStoreContentsWin>( |
| 222 install_static::GetRegistryPath(), | 233 install_static::GetRegistryPath(), |
| 223 profile_path_.BaseName().LossyDisplayName())); | 234 profile_path_.BaseName().LossyDisplayName())); |
| 224 #else | 235 #else |
| 225 return std::make_pair(nullptr, nullptr); | 236 return std::make_pair(nullptr, nullptr); |
| 226 #endif | 237 #endif |
| 227 } | 238 } |
| 239 |
| 240 void ProfilePrefStoreManager::ConfigurePrefService( |
| 241 const base::Closure& on_reset_on_load, |
| 242 service_manager::Connector* connector) { |
| 243 auto config = prefs::mojom::PersistentPrefStoreConfiguration::New(); |
| 244 config->set_simple_configuration( |
| 245 prefs::mojom::SimplePersistentPrefStoreConfiguration::New( |
| 246 profile_path_.Append(chrome::kPreferencesFilename))); |
| 247 prefs::mojom::PrefServiceControlPtr control; |
| 248 connector->BindInterface(prefs::mojom::kPrefStoreServiceName, &control); |
| 249 control->Init(std::move(config)); |
| 250 } |
| OLD | NEW |