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 "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
9 #include "base/json/json_file_value_serializer.h" | 9 #include "base/json/json_file_value_serializer.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
175 void InitializeHashStoreObserver::OnPrefValueChanged(const std::string& key) {} | 175 void InitializeHashStoreObserver::OnPrefValueChanged(const std::string& key) {} |
176 | 176 |
177 void InitializeHashStoreObserver::OnInitializationCompleted(bool succeeded) { | 177 void InitializeHashStoreObserver::OnInitializationCompleted(bool succeeded) { |
178 // If we successfully loaded the preferences _and_ the PrefHashStoreImpl | 178 // If we successfully loaded the preferences _and_ the PrefHashStoreImpl |
179 // hasn't been initialized by someone else in the meantime, initialize it now. | 179 // hasn't been initialized by someone else in the meantime, initialize it now. |
180 const PrefHashStoreImpl::StoreVersion pre_update_version = | 180 const PrefHashStoreImpl::StoreVersion pre_update_version = |
181 pref_hash_store_impl_->GetCurrentVersion(); | 181 pref_hash_store_impl_->GetCurrentVersion(); |
182 if (succeeded && pre_update_version < PrefHashStoreImpl::VERSION_LATEST) { | 182 if (succeeded && pre_update_version < PrefHashStoreImpl::VERSION_LATEST) { |
183 PrefHashFilter(pref_hash_store_impl_.PassAs<PrefHashStore>(), | 183 PrefHashFilter(pref_hash_store_impl_.PassAs<PrefHashStore>(), |
184 tracking_configuration_, | 184 tracking_configuration_, |
| 185 NULL, |
185 reporting_ids_count_).Initialize(*pref_store_); | 186 reporting_ids_count_).Initialize(*pref_store_); |
186 UMA_HISTOGRAM_ENUMERATION( | 187 UMA_HISTOGRAM_ENUMERATION( |
187 "Settings.TrackedPreferencesAlternateStoreVersionUpdatedFrom", | 188 "Settings.TrackedPreferencesAlternateStoreVersionUpdatedFrom", |
188 pre_update_version, | 189 pre_update_version, |
189 PrefHashStoreImpl::VERSION_LATEST + 1); | 190 PrefHashStoreImpl::VERSION_LATEST + 1); |
190 } | 191 } |
191 pref_store_->RemoveObserver(this); | 192 pref_store_->RemoveObserver(this); |
192 delete this; | 193 delete this; |
193 } | 194 } |
194 | 195 |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
252 void ProfilePrefStoreManager::ClearResetTime(PrefService* pref_service) { | 253 void ProfilePrefStoreManager::ClearResetTime(PrefService* pref_service) { |
253 PrefHashFilter::ClearResetTime(pref_service); | 254 PrefHashFilter::ClearResetTime(pref_service); |
254 } | 255 } |
255 | 256 |
256 void ProfilePrefStoreManager::ResetPrefHashStore() { | 257 void ProfilePrefStoreManager::ResetPrefHashStore() { |
257 if (kPlatformSupportsPreferenceTracking) | 258 if (kPlatformSupportsPreferenceTracking) |
258 GetPrefHashStoreImpl()->Reset(); | 259 GetPrefHashStoreImpl()->Reset(); |
259 } | 260 } |
260 | 261 |
261 PersistentPrefStore* ProfilePrefStoreManager::CreateProfilePrefStore( | 262 PersistentPrefStore* ProfilePrefStoreManager::CreateProfilePrefStore( |
262 const scoped_refptr<base::SequencedTaskRunner>& io_task_runner) { | 263 const scoped_refptr<base::SequencedTaskRunner>& io_task_runner, |
| 264 TrackedPreferenceValidationDelegate* validation_delegate) { |
263 scoped_ptr<PrefFilter> pref_filter; | 265 scoped_ptr<PrefFilter> pref_filter; |
264 if (!kPlatformSupportsPreferenceTracking) { | 266 if (!kPlatformSupportsPreferenceTracking) { |
265 return new JsonPrefStore(GetPrefFilePathFromProfilePath(profile_path_), | 267 return new JsonPrefStore(GetPrefFilePathFromProfilePath(profile_path_), |
266 io_task_runner, | 268 io_task_runner, |
267 scoped_ptr<PrefFilter>()); | 269 scoped_ptr<PrefFilter>()); |
268 } | 270 } |
269 | 271 |
270 std::vector<PrefHashFilter::TrackedPreferenceMetadata> | 272 std::vector<PrefHashFilter::TrackedPreferenceMetadata> |
271 unprotected_configuration; | 273 unprotected_configuration; |
272 std::vector<PrefHashFilter::TrackedPreferenceMetadata> | 274 std::vector<PrefHashFilter::TrackedPreferenceMetadata> |
273 protected_configuration; | 275 protected_configuration; |
274 std::set<std::string> protected_pref_names; | 276 std::set<std::string> protected_pref_names; |
275 std::set<std::string> unprotected_pref_names; | 277 std::set<std::string> unprotected_pref_names; |
276 for (std::vector<PrefHashFilter::TrackedPreferenceMetadata>::const_iterator | 278 for (std::vector<PrefHashFilter::TrackedPreferenceMetadata>::const_iterator |
277 it = tracking_configuration_.begin(); | 279 it = tracking_configuration_.begin(); |
278 it != tracking_configuration_.end(); | 280 it != tracking_configuration_.end(); |
279 ++it) { | 281 ++it) { |
280 if (it->enforcement_level > PrefHashFilter::NO_ENFORCEMENT) { | 282 if (it->enforcement_level > PrefHashFilter::NO_ENFORCEMENT) { |
281 protected_configuration.push_back(*it); | 283 protected_configuration.push_back(*it); |
282 protected_pref_names.insert(it->name); | 284 protected_pref_names.insert(it->name); |
283 } else { | 285 } else { |
284 unprotected_configuration.push_back(*it); | 286 unprotected_configuration.push_back(*it); |
285 unprotected_pref_names.insert(it->name); | 287 unprotected_pref_names.insert(it->name); |
286 } | 288 } |
287 } | 289 } |
288 | 290 |
289 scoped_ptr<PrefHashFilter> unprotected_pref_hash_filter( | 291 scoped_ptr<PrefHashFilter> unprotected_pref_hash_filter( |
290 new PrefHashFilter(GetPrefHashStoreImpl().PassAs<PrefHashStore>(), | 292 new PrefHashFilter(GetPrefHashStoreImpl().PassAs<PrefHashStore>(), |
291 unprotected_configuration, | 293 unprotected_configuration, |
| 294 validation_delegate, |
292 reporting_ids_count_)); | 295 reporting_ids_count_)); |
293 scoped_ptr<PrefHashFilter> protected_pref_hash_filter( | 296 scoped_ptr<PrefHashFilter> protected_pref_hash_filter( |
294 new PrefHashFilter(GetPrefHashStoreImpl().PassAs<PrefHashStore>(), | 297 new PrefHashFilter(GetPrefHashStoreImpl().PassAs<PrefHashStore>(), |
295 protected_configuration, | 298 protected_configuration, |
| 299 validation_delegate, |
296 reporting_ids_count_)); | 300 reporting_ids_count_)); |
297 | 301 |
298 PrefHashFilter* raw_unprotected_pref_hash_filter = | 302 PrefHashFilter* raw_unprotected_pref_hash_filter = |
299 unprotected_pref_hash_filter.get(); | 303 unprotected_pref_hash_filter.get(); |
300 PrefHashFilter* raw_protected_pref_hash_filter = | 304 PrefHashFilter* raw_protected_pref_hash_filter = |
301 protected_pref_hash_filter.get(); | 305 protected_pref_hash_filter.get(); |
302 | 306 |
303 scoped_refptr<JsonPrefStore> unprotected_pref_store( | 307 scoped_refptr<JsonPrefStore> unprotected_pref_store( |
304 new JsonPrefStore(GetPrefFilePathFromProfilePath(profile_path_), | 308 new JsonPrefStore(GetPrefFilePathFromProfilePath(profile_path_), |
305 io_task_runner, | 309 io_task_runner, |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
370 // complete before Chrome can start (as master preferences seed the Local | 374 // complete before Chrome can start (as master preferences seed the Local |
371 // State and Preferences files). This won't trip ThreadIORestrictions as they | 375 // State and Preferences files). This won't trip ThreadIORestrictions as they |
372 // won't have kicked in yet on the main thread. | 376 // won't have kicked in yet on the main thread. |
373 bool success = serializer.Serialize(master_prefs); | 377 bool success = serializer.Serialize(master_prefs); |
374 | 378 |
375 if (success && kPlatformSupportsPreferenceTracking) { | 379 if (success && kPlatformSupportsPreferenceTracking) { |
376 scoped_refptr<const PrefStore> pref_store( | 380 scoped_refptr<const PrefStore> pref_store( |
377 new DictionaryPrefStore(&master_prefs)); | 381 new DictionaryPrefStore(&master_prefs)); |
378 PrefHashFilter(GetPrefHashStoreImpl().PassAs<PrefHashStore>(), | 382 PrefHashFilter(GetPrefHashStoreImpl().PassAs<PrefHashStore>(), |
379 tracking_configuration_, | 383 tracking_configuration_, |
| 384 NULL, |
380 reporting_ids_count_).Initialize(*pref_store); | 385 reporting_ids_count_).Initialize(*pref_store); |
381 } | 386 } |
382 | 387 |
383 UMA_HISTOGRAM_BOOLEAN("Settings.InitializedFromMasterPrefs", success); | 388 UMA_HISTOGRAM_BOOLEAN("Settings.InitializedFromMasterPrefs", success); |
384 return success; | 389 return success; |
385 } | 390 } |
386 | 391 |
387 PersistentPrefStore* | 392 PersistentPrefStore* |
388 ProfilePrefStoreManager::CreateDeprecatedCombinedProfilePrefStore( | 393 ProfilePrefStoreManager::CreateDeprecatedCombinedProfilePrefStore( |
389 const scoped_refptr<base::SequencedTaskRunner>& io_task_runner) { | 394 const scoped_refptr<base::SequencedTaskRunner>& io_task_runner) { |
390 scoped_ptr<PrefFilter> pref_filter; | 395 scoped_ptr<PrefFilter> pref_filter; |
391 if (kPlatformSupportsPreferenceTracking) { | 396 if (kPlatformSupportsPreferenceTracking) { |
392 pref_filter.reset( | 397 pref_filter.reset( |
393 new PrefHashFilter(GetPrefHashStoreImpl().PassAs<PrefHashStore>(), | 398 new PrefHashFilter(GetPrefHashStoreImpl().PassAs<PrefHashStore>(), |
394 tracking_configuration_, | 399 tracking_configuration_, |
| 400 NULL, |
395 reporting_ids_count_)); | 401 reporting_ids_count_)); |
396 } | 402 } |
397 return new JsonPrefStore(GetPrefFilePathFromProfilePath(profile_path_), | 403 return new JsonPrefStore(GetPrefFilePathFromProfilePath(profile_path_), |
398 io_task_runner, | 404 io_task_runner, |
399 pref_filter.Pass()); | 405 pref_filter.Pass()); |
400 } | 406 } |
401 | 407 |
402 scoped_ptr<PrefHashStoreImpl> ProfilePrefStoreManager::GetPrefHashStoreImpl() { | 408 scoped_ptr<PrefHashStoreImpl> ProfilePrefStoreManager::GetPrefHashStoreImpl() { |
403 DCHECK(kPlatformSupportsPreferenceTracking); | 409 DCHECK(kPlatformSupportsPreferenceTracking); |
404 | 410 |
405 return make_scoped_ptr(new PrefHashStoreImpl( | 411 return make_scoped_ptr(new PrefHashStoreImpl( |
406 seed_, | 412 seed_, |
407 device_id_, | 413 device_id_, |
408 scoped_ptr<HashStoreContents>(new PrefServiceHashStoreContents( | 414 scoped_ptr<HashStoreContents>(new PrefServiceHashStoreContents( |
409 profile_path_.AsUTF8Unsafe(), local_state_)))); | 415 profile_path_.AsUTF8Unsafe(), local_state_)))); |
410 } | 416 } |
OLD | NEW |