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/file_util.h" | 8 #include "base/file_util.h" |
8 #include "base/json/json_file_value_serializer.h" | 9 #include "base/json/json_file_value_serializer.h" |
9 #include "base/logging.h" | 10 #include "base/logging.h" |
10 #include "base/metrics/histogram.h" | 11 #include "base/metrics/histogram.h" |
11 #include "base/prefs/json_pref_store.h" | 12 #include "base/prefs/json_pref_store.h" |
12 #include "base/prefs/persistent_pref_store.h" | 13 #include "base/prefs/persistent_pref_store.h" |
13 #include "base/prefs/pref_registry_simple.h" | 14 #include "base/prefs/pref_registry_simple.h" |
14 #include "chrome/browser/prefs/pref_hash_store_impl.h" | 15 #include "chrome/browser/prefs/pref_hash_store_impl.h" |
15 #include "chrome/browser/prefs/tracked/pref_service_hash_store_contents.h" | 16 #include "chrome/browser/prefs/tracked/pref_service_hash_store_contents.h" |
16 #include "chrome/browser/prefs/tracked/segregated_pref_store.h" | 17 #include "chrome/browser/prefs/tracked/segregated_pref_store.h" |
| 18 #include "chrome/browser/prefs/tracked/tracked_preferences_migration.h" |
17 #include "chrome/common/chrome_constants.h" | 19 #include "chrome/common/chrome_constants.h" |
18 #include "chrome/common/pref_names.h" | 20 #include "chrome/common/pref_names.h" |
19 #include "components/user_prefs/pref_registry_syncable.h" | 21 #include "components/user_prefs/pref_registry_syncable.h" |
20 | 22 |
21 namespace { | 23 namespace { |
22 | 24 |
23 // An adaptor that allows a PrefHashStoreImpl to access a preference store | 25 // An adaptor that allows a PrefHashStoreImpl to access a preference store |
24 // directly as a dictionary. Uses an equivalent layout to | 26 // directly as a dictionary. Uses an equivalent layout to |
25 // PrefStoreHashStoreContents. | 27 // PrefStoreHashStoreContents. |
26 class DictionaryHashStoreContents : public HashStoreContents { | 28 class DictionaryHashStoreContents : public HashStoreContents { |
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
276 return new JsonPrefStore(GetPrefFilePathFromProfilePath(profile_path_), | 278 return new JsonPrefStore(GetPrefFilePathFromProfilePath(profile_path_), |
277 io_task_runner, | 279 io_task_runner, |
278 scoped_ptr<PrefFilter>()); | 280 scoped_ptr<PrefFilter>()); |
279 } | 281 } |
280 | 282 |
281 std::vector<PrefHashFilter::TrackedPreferenceMetadata> | 283 std::vector<PrefHashFilter::TrackedPreferenceMetadata> |
282 unprotected_configuration; | 284 unprotected_configuration; |
283 std::vector<PrefHashFilter::TrackedPreferenceMetadata> | 285 std::vector<PrefHashFilter::TrackedPreferenceMetadata> |
284 protected_configuration; | 286 protected_configuration; |
285 std::set<std::string> protected_pref_names; | 287 std::set<std::string> protected_pref_names; |
| 288 std::set<std::string> unprotected_pref_names; |
286 for (std::vector<PrefHashFilter::TrackedPreferenceMetadata>::const_iterator | 289 for (std::vector<PrefHashFilter::TrackedPreferenceMetadata>::const_iterator |
287 it = tracking_configuration_.begin(); | 290 it = tracking_configuration_.begin(); |
288 it != tracking_configuration_.end(); | 291 it != tracking_configuration_.end(); |
289 ++it) { | 292 ++it) { |
290 if (it->enforcement_level > PrefHashFilter::NO_ENFORCEMENT) { | 293 if (it->enforcement_level > PrefHashFilter::NO_ENFORCEMENT) { |
291 protected_configuration.push_back(*it); | 294 protected_configuration.push_back(*it); |
292 protected_pref_names.insert(it->name); | 295 protected_pref_names.insert(it->name); |
293 } else { | 296 } else { |
294 unprotected_configuration.push_back(*it); | 297 unprotected_configuration.push_back(*it); |
| 298 unprotected_pref_names.insert(it->name); |
295 } | 299 } |
296 } | 300 } |
297 | 301 |
298 scoped_ptr<PrefFilter> unprotected_pref_hash_filter( | 302 scoped_ptr<PrefHashFilter> unprotected_pref_hash_filter( |
299 new PrefHashFilter(GetPrefHashStoreImpl().PassAs<PrefHashStore>(), | 303 new PrefHashFilter(GetPrefHashStoreImpl().PassAs<PrefHashStore>(), |
300 unprotected_configuration, | 304 unprotected_configuration, |
301 reporting_ids_count_)); | 305 reporting_ids_count_)); |
302 scoped_ptr<PrefFilter> protected_pref_hash_filter( | 306 scoped_ptr<PrefHashFilter> protected_pref_hash_filter( |
303 new PrefHashFilter(GetPrefHashStoreImpl().PassAs<PrefHashStore>(), | 307 new PrefHashFilter(GetPrefHashStoreImpl().PassAs<PrefHashStore>(), |
304 protected_configuration, | 308 protected_configuration, |
305 reporting_ids_count_)); | 309 reporting_ids_count_)); |
306 | 310 |
307 scoped_refptr<PersistentPrefStore> unprotected_pref_store( | 311 PrefHashFilter* raw_unprotected_pref_hash_filter = |
| 312 unprotected_pref_hash_filter.get(); |
| 313 PrefHashFilter* raw_protected_pref_hash_filter = |
| 314 protected_pref_hash_filter.get(); |
| 315 |
| 316 scoped_refptr<JsonPrefStore> unprotected_pref_store( |
308 new JsonPrefStore(GetPrefFilePathFromProfilePath(profile_path_), | 317 new JsonPrefStore(GetPrefFilePathFromProfilePath(profile_path_), |
309 io_task_runner, | 318 io_task_runner, |
310 unprotected_pref_hash_filter.Pass())); | 319 unprotected_pref_hash_filter.PassAs<PrefFilter>())); |
311 scoped_refptr<PersistentPrefStore> protected_pref_store(new JsonPrefStore( | 320 scoped_refptr<JsonPrefStore> protected_pref_store(new JsonPrefStore( |
312 profile_path_.Append(chrome::kProtectedPreferencesFilename), | 321 profile_path_.Append(chrome::kProtectedPreferencesFilename), |
313 io_task_runner, | 322 io_task_runner, |
314 protected_pref_hash_filter.Pass())); | 323 protected_pref_hash_filter.PassAs<PrefFilter>())); |
315 | 324 |
316 // The on_initialized callback is used to migrate newly protected values from | 325 SetupTrackedPreferencesMigration( |
317 // the main Preferences store to the Protected Preferences store. It is also | 326 unprotected_pref_names, |
318 // responsible for the initial migration to a two-store model. | |
319 return new SegregatedPrefStore( | |
320 unprotected_pref_store, | |
321 protected_pref_store, | |
322 protected_pref_names, | 327 protected_pref_names, |
323 base::Bind(&PrefHashFilter::MigrateValues, | 328 base::Bind(&JsonPrefStore::RemoveValueSilently, |
324 base::Owned(new PrefHashFilter( | 329 unprotected_pref_store->AsWeakPtr()), |
325 CopyPrefHashStore(), | 330 base::Bind(&JsonPrefStore::RemoveValueSilently, |
326 protected_configuration, | 331 protected_pref_store->AsWeakPtr()), |
327 reporting_ids_count_)), | 332 base::Bind(&JsonPrefStore::RegisterOnNextSuccessfulWriteCallback, |
328 unprotected_pref_store, | 333 unprotected_pref_store->AsWeakPtr()), |
329 protected_pref_store)); | 334 base::Bind(&JsonPrefStore::RegisterOnNextSuccessfulWriteCallback, |
| 335 protected_pref_store->AsWeakPtr()), |
| 336 raw_unprotected_pref_hash_filter, |
| 337 raw_protected_pref_hash_filter); |
| 338 |
| 339 return new SegregatedPrefStore(unprotected_pref_store, protected_pref_store, |
| 340 protected_pref_names); |
330 } | 341 } |
331 | 342 |
332 void ProfilePrefStoreManager::UpdateProfileHashStoreIfRequired( | 343 void ProfilePrefStoreManager::UpdateProfileHashStoreIfRequired( |
333 const scoped_refptr<base::SequencedTaskRunner>& io_task_runner) { | 344 const scoped_refptr<base::SequencedTaskRunner>& io_task_runner) { |
334 if (!kPlatformSupportsPreferenceTracking) | 345 if (!kPlatformSupportsPreferenceTracking) |
335 return; | 346 return; |
336 scoped_ptr<PrefHashStoreImpl> pref_hash_store_impl(GetPrefHashStoreImpl()); | 347 scoped_ptr<PrefHashStoreImpl> pref_hash_store_impl(GetPrefHashStoreImpl()); |
337 const PrefHashStoreImpl::StoreVersion current_version = | 348 const PrefHashStoreImpl::StoreVersion current_version = |
338 pref_hash_store_impl->GetCurrentVersion(); | 349 pref_hash_store_impl->GetCurrentVersion(); |
339 UMA_HISTOGRAM_ENUMERATION("Settings.TrackedPreferencesAlternateStoreVersion", | 350 UMA_HISTOGRAM_ENUMERATION("Settings.TrackedPreferencesAlternateStoreVersion", |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
403 | 414 |
404 scoped_ptr<PrefHashStoreImpl> ProfilePrefStoreManager::GetPrefHashStoreImpl() { | 415 scoped_ptr<PrefHashStoreImpl> ProfilePrefStoreManager::GetPrefHashStoreImpl() { |
405 DCHECK(kPlatformSupportsPreferenceTracking); | 416 DCHECK(kPlatformSupportsPreferenceTracking); |
406 | 417 |
407 return make_scoped_ptr(new PrefHashStoreImpl( | 418 return make_scoped_ptr(new PrefHashStoreImpl( |
408 seed_, | 419 seed_, |
409 device_id_, | 420 device_id_, |
410 scoped_ptr<HashStoreContents>(new PrefServiceHashStoreContents( | 421 scoped_ptr<HashStoreContents>(new PrefServiceHashStoreContents( |
411 profile_path_.AsUTF8Unsafe(), local_state_)))); | 422 profile_path_.AsUTF8Unsafe(), local_state_)))); |
412 } | 423 } |
413 | |
414 scoped_ptr<PrefHashStore> ProfilePrefStoreManager::CopyPrefHashStore() { | |
415 DCHECK(kPlatformSupportsPreferenceTracking); | |
416 | |
417 PrefServiceHashStoreContents real_contents(profile_path_.AsUTF8Unsafe(), | |
418 local_state_); | |
419 return scoped_ptr<PrefHashStore>(new PrefHashStoreImpl( | |
420 seed_, | |
421 device_id_, | |
422 scoped_ptr<HashStoreContents>( | |
423 new DictionaryHashStoreContents(real_contents)))); | |
424 } | |
OLD | NEW |