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

Side by Side 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 unified diff | Download patch
OLDNEW
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 "mojo/public/cpp/bindings/strong_binding.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) {
36 if (pref_store) { 40 if (pref_store) {
37 pref_store->RemoveValueSilently( 41 pref_store->RemoveValueSilently(
38 key, WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS); 42 key, WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS);
39 } 43 }
40 } 44 }
41 45
42 #if defined(OS_WIN) 46 #if defined(OS_WIN)
43 // Forces a different registry key to be used for storing preference validation 47 // Forces a different registry key to be used for storing preference validation
44 // MACs. See |SetPreferenceValidationRegistryPathForTesting|. 48 // MACs. See |SetPreferenceValidationRegistryPathForTesting|.
45 const base::string16* g_preference_validation_registry_path_for_testing = 49 const base::string16* g_preference_validation_registry_path_for_testing =
46 nullptr; 50 nullptr;
47 #endif // OS_WIN 51 #endif // OS_WIN
48 52
53 class ResetOnLoadObserverImpl : public prefs::mojom::ResetOnLoadObserver {
54 public:
55 explicit ResetOnLoadObserverImpl(const base::Closure& on_reset_on_load)
56 : on_reset_on_load_(on_reset_on_load) {
57 DCHECK(on_reset_on_load_);
58 }
59
60 void OnResetOnLoad() override { on_reset_on_load_.Run(); }
61
62 private:
63 base::Closure on_reset_on_load_;
64 };
65
66 std::vector<prefs::mojom::TrackedPreferenceMetadataPtr>
67 WrapTrackedPreferenceMetadata(
68 const std::vector<PrefHashFilter::TrackedPreferenceMetadata>& input) {
69 std::vector<prefs::mojom::TrackedPreferenceMetadataPtr> output;
70 for (const auto& metadata : input) {
71 output.emplace_back(base::in_place, metadata.reporting_id, metadata.name,
72 metadata.enforcement_level, metadata.strategy,
73 metadata.value_type);
74 }
75 return output;
76 }
77
49 } // namespace 78 } // namespace
50 79
51 // Preference tracking and protection is not required on platforms where other 80 // Preference tracking and protection is not required on platforms where other
52 // apps do not have access to chrome's persistent storage. 81 // apps do not have access to chrome's persistent storage.
53 const bool ProfilePrefStoreManager::kPlatformSupportsPreferenceTracking = 82 const bool ProfilePrefStoreManager::kPlatformSupportsPreferenceTracking =
54 #if defined(OS_ANDROID) || defined(OS_CHROMEOS) 83 #if defined(OS_ANDROID) || defined(OS_CHROMEOS)
55 false; 84 false;
56 #else 85 #else
57 true; 86 true;
58 #endif 87 #endif
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 #if defined(OS_WIN) 122 #if defined(OS_WIN)
94 // static 123 // static
95 void ProfilePrefStoreManager::SetPreferenceValidationRegistryPathForTesting( 124 void ProfilePrefStoreManager::SetPreferenceValidationRegistryPathForTesting(
96 const base::string16* path) { 125 const base::string16* path) {
97 DCHECK(!path->empty()); 126 DCHECK(!path->empty());
98 g_preference_validation_registry_path_for_testing = path; 127 g_preference_validation_registry_path_for_testing = path;
99 } 128 }
100 #endif // OS_WIN 129 #endif // OS_WIN
101 130
102 PersistentPrefStore* ProfilePrefStoreManager::CreateProfilePrefStore( 131 PersistentPrefStore* ProfilePrefStoreManager::CreateProfilePrefStore(
132 const scoped_refptr<base::SingleThreadTaskRunner>& pref_task_runner,
103 const scoped_refptr<base::SequencedTaskRunner>& io_task_runner, 133 const scoped_refptr<base::SequencedTaskRunner>& io_task_runner,
104 const base::Closure& on_reset_on_load, 134 const base::Closure& on_reset_on_load,
105 prefs::mojom::TrackedPreferenceValidationDelegate* validation_delegate) { 135 std::unique_ptr<prefs::mojom::TrackedPreferenceValidationDelegate>*
106 std::unique_ptr<PrefFilter> pref_filter; 136 validation_delegate,
137 service_manager::Connector* connector) {
138 DCHECK(validation_delegate);
139 if (base::FeatureList::IsEnabled(features::kPrefService)) {
140 ConfigurePrefServiceUserPrefs(on_reset_on_load,
141 std::move(*validation_delegate), connector);
142 return nullptr;
143 }
107 if (!kPlatformSupportsPreferenceTracking) { 144 if (!kPlatformSupportsPreferenceTracking) {
108 return new JsonPrefStore(profile_path_.Append(chrome::kPreferencesFilename), 145 return new JsonPrefStore(profile_path_.Append(chrome::kPreferencesFilename),
109 io_task_runner.get(), 146 io_task_runner.get(),
110 std::unique_ptr<PrefFilter>()); 147 std::unique_ptr<PrefFilter>());
111 } 148 }
112 149
113 std::vector<PrefHashFilter::TrackedPreferenceMetadata> 150 std::vector<PrefHashFilter::TrackedPreferenceMetadata>
114 unprotected_configuration; 151 unprotected_configuration;
115 std::vector<PrefHashFilter::TrackedPreferenceMetadata> 152 std::vector<PrefHashFilter::TrackedPreferenceMetadata>
116 protected_configuration; 153 protected_configuration;
117 std::set<std::string> protected_pref_names; 154 std::set<std::string> protected_pref_names;
118 std::set<std::string> unprotected_pref_names; 155 std::set<std::string> unprotected_pref_names;
119 for (std::vector<PrefHashFilter::TrackedPreferenceMetadata>::const_iterator 156 for (std::vector<PrefHashFilter::TrackedPreferenceMetadata>::const_iterator
120 it = tracking_configuration_.begin(); 157 it = tracking_configuration_.begin();
121 it != tracking_configuration_.end(); 158 it != tracking_configuration_.end();
122 ++it) { 159 ++it) {
123 if (it->enforcement_level > PrefHashFilter::NO_ENFORCEMENT) { 160 if (it->enforcement_level >
161 PrefHashFilter::EnforcementLevel::NO_ENFORCEMENT) {
124 protected_configuration.push_back(*it); 162 protected_configuration.push_back(*it);
125 protected_pref_names.insert(it->name); 163 protected_pref_names.insert(it->name);
126 } else { 164 } else {
127 unprotected_configuration.push_back(*it); 165 unprotected_configuration.push_back(*it);
128 unprotected_pref_names.insert(it->name); 166 unprotected_pref_names.insert(it->name);
129 } 167 }
130 } 168 }
131 169
132 std::unique_ptr<PrefHashFilter> unprotected_pref_hash_filter( 170 std::unique_ptr<PrefHashFilter> unprotected_pref_hash_filter(
133 new PrefHashFilter(GetPrefHashStore(false), 171 new PrefHashFilter(
134 GetExternalVerificationPrefHashStorePair(), 172 GetPrefHashStore(false), GetExternalVerificationPrefHashStorePair(),
135 unprotected_configuration, base::Closure(), 173 unprotected_configuration, base::Closure(),
136 validation_delegate, reporting_ids_count_, false)); 174 validation_delegate->get(), reporting_ids_count_, false));
137 std::unique_ptr<PrefHashFilter> protected_pref_hash_filter(new PrefHashFilter( 175 std::unique_ptr<PrefHashFilter> protected_pref_hash_filter(new PrefHashFilter(
138 GetPrefHashStore(true), GetExternalVerificationPrefHashStorePair(), 176 GetPrefHashStore(true), GetExternalVerificationPrefHashStorePair(),
139 protected_configuration, on_reset_on_load, validation_delegate, 177 protected_configuration, on_reset_on_load, validation_delegate->get(),
140 reporting_ids_count_, true)); 178 reporting_ids_count_, true));
141 179
142 PrefHashFilter* raw_unprotected_pref_hash_filter = 180 PrefHashFilter* raw_unprotected_pref_hash_filter =
143 unprotected_pref_hash_filter.get(); 181 unprotected_pref_hash_filter.get();
144 PrefHashFilter* raw_protected_pref_hash_filter = 182 PrefHashFilter* raw_protected_pref_hash_filter =
145 protected_pref_hash_filter.get(); 183 protected_pref_hash_filter.get();
146 184
147 scoped_refptr<JsonPrefStore> unprotected_pref_store(new JsonPrefStore( 185 scoped_refptr<JsonPrefStore> unprotected_pref_store(new JsonPrefStore(
148 profile_path_.Append(chrome::kPreferencesFilename), io_task_runner.get(), 186 profile_path_.Append(chrome::kPreferencesFilename), io_task_runner.get(),
149 std::move(unprotected_pref_hash_filter))); 187 std::move(unprotected_pref_hash_filter)));
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
220 ? base::MakeUnique<RegistryHashStoreContentsWin>( 258 ? base::MakeUnique<RegistryHashStoreContentsWin>(
221 *g_preference_validation_registry_path_for_testing, 259 *g_preference_validation_registry_path_for_testing,
222 profile_path_.BaseName().LossyDisplayName()) 260 profile_path_.BaseName().LossyDisplayName())
223 : base::MakeUnique<RegistryHashStoreContentsWin>( 261 : base::MakeUnique<RegistryHashStoreContentsWin>(
224 install_static::GetRegistryPath(), 262 install_static::GetRegistryPath(),
225 profile_path_.BaseName().LossyDisplayName())); 263 profile_path_.BaseName().LossyDisplayName()));
226 #else 264 #else
227 return std::make_pair(nullptr, nullptr); 265 return std::make_pair(nullptr, nullptr);
228 #endif 266 #endif
229 } 267 }
268
269 void ProfilePrefStoreManager::ConfigurePrefServiceUserPrefs(
270 const base::Closure& on_reset_on_load,
271 std::unique_ptr<prefs::mojom::TrackedPreferenceValidationDelegate>
272 validation_delegate,
273 service_manager::Connector* connector) {
274 auto config = prefs::mojom::UserPrefsConfiguration::New();
275 if (!kPlatformSupportsPreferenceTracking) {
276 config->set_simple_configuration(
277 prefs::mojom::SimpleUserPrefsConfiguration::New(
278 profile_path_.Append(chrome::kPreferencesFilename)));
279 } else {
280 prefs::mojom::TrackedPreferenceValidationDelegatePtr
281 validation_delegate_ptr;
282 if (validation_delegate) {
283 mojo::MakeStrongBinding(std::move(validation_delegate),
284 mojo::MakeRequest(&validation_delegate_ptr));
285 }
286 prefs::mojom::ResetOnLoadObserverPtr reset_on_load_observer;
287 if (on_reset_on_load) {
288 mojo::MakeStrongBinding(
289 base::MakeUnique<ResetOnLoadObserverImpl>(on_reset_on_load),
290 mojo::MakeRequest(&reset_on_load_observer));
291 }
292 config->set_segregated_configuration(
293 prefs::mojom::SegregatedUserPrefsConfiguration::New(
294 profile_path_.Append(chrome::kPreferencesFilename),
295 profile_path_.Append(chrome::kSecurePreferencesFilename),
296 WrapTrackedPreferenceMetadata(tracking_configuration_),
297 reporting_ids_count_, seed_, legacy_device_id_,
298 #if defined(OS_WIN)
299 g_preference_validation_registry_path_for_testing
300 ? *g_preference_validation_registry_path_for_testing
301 : BrowserDistribution::GetDistribution()->GetRegistryPath(),
302 #else
303 base::string16(),
304 #endif
305 std::move(validation_delegate_ptr),
306 std::move(reset_on_load_observer)));
307 }
308 prefs::mojom::PersistentPrefStoreInitPtr init;
309 connector->BindInterface(prefs::mojom::kPrefStoreServiceName, &init);
310 init->Init(std::move(config));
311 }
OLDNEW
« 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