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

Side by Side Diff: chrome/browser/prefs/profile_pref_store_manager.cc

Issue 257003007: Introduce a new framework for back-and-forth tracked/protected preferences migration. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: run cleanup directly if destination store wasn't altered (i.e. migration completed in previous run,… Created 6 years, 7 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 | Annotate | Revision Log
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 "base/file_util.h" 7 #include "base/file_util.h"
8 #include "base/json/json_file_value_serializer.h" 8 #include "base/json/json_file_value_serializer.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/metrics/histogram.h" 10 #include "base/metrics/histogram.h"
11 #include "base/prefs/json_pref_store.h" 11 #include "base/prefs/json_pref_store.h"
12 #include "base/prefs/persistent_pref_store.h" 12 #include "base/prefs/persistent_pref_store.h"
13 #include "base/prefs/pref_registry_simple.h" 13 #include "base/prefs/pref_registry_simple.h"
14 #include "chrome/browser/prefs/pref_hash_store_impl.h" 14 #include "chrome/browser/prefs/pref_hash_store_impl.h"
15 #include "chrome/browser/prefs/tracked/pref_service_hash_store_contents.h" 15 #include "chrome/browser/prefs/tracked/pref_service_hash_store_contents.h"
16 #include "chrome/browser/prefs/tracked/segregated_pref_store.h" 16 #include "chrome/browser/prefs/tracked/segregated_pref_store.h"
17 #include "chrome/browser/prefs/tracked/tracked_preferences_migration.h"
17 #include "chrome/common/chrome_constants.h" 18 #include "chrome/common/chrome_constants.h"
18 #include "chrome/common/pref_names.h" 19 #include "chrome/common/pref_names.h"
19 #include "components/user_prefs/pref_registry_syncable.h" 20 #include "components/user_prefs/pref_registry_syncable.h"
20 21
21 namespace { 22 namespace {
22 23
23 // An adaptor that allows a PrefHashStoreImpl to access a preference store 24 // An adaptor that allows a PrefHashStoreImpl to access a preference store
24 // directly as a dictionary. Uses an equivalent layout to 25 // directly as a dictionary. Uses an equivalent layout to
25 // PrefStoreHashStoreContents. 26 // PrefStoreHashStoreContents.
26 class DictionaryHashStoreContents : public HashStoreContents { 27 class DictionaryHashStoreContents : public HashStoreContents {
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after
276 return new JsonPrefStore(GetPrefFilePathFromProfilePath(profile_path_), 277 return new JsonPrefStore(GetPrefFilePathFromProfilePath(profile_path_),
277 io_task_runner, 278 io_task_runner,
278 scoped_ptr<PrefFilter>()); 279 scoped_ptr<PrefFilter>());
279 } 280 }
280 281
281 std::vector<PrefHashFilter::TrackedPreferenceMetadata> 282 std::vector<PrefHashFilter::TrackedPreferenceMetadata>
282 unprotected_configuration; 283 unprotected_configuration;
283 std::vector<PrefHashFilter::TrackedPreferenceMetadata> 284 std::vector<PrefHashFilter::TrackedPreferenceMetadata>
284 protected_configuration; 285 protected_configuration;
285 std::set<std::string> protected_pref_names; 286 std::set<std::string> protected_pref_names;
287 std::set<std::string> unprotected_pref_names;
286 for (std::vector<PrefHashFilter::TrackedPreferenceMetadata>::const_iterator 288 for (std::vector<PrefHashFilter::TrackedPreferenceMetadata>::const_iterator
287 it = tracking_configuration_.begin(); 289 it = tracking_configuration_.begin();
288 it != tracking_configuration_.end(); 290 it != tracking_configuration_.end();
289 ++it) { 291 ++it) {
290 if (it->enforcement_level > PrefHashFilter::NO_ENFORCEMENT) { 292 if (it->enforcement_level > PrefHashFilter::NO_ENFORCEMENT) {
291 protected_configuration.push_back(*it); 293 protected_configuration.push_back(*it);
292 protected_pref_names.insert(it->name); 294 protected_pref_names.insert(it->name);
293 } else { 295 } else {
294 unprotected_configuration.push_back(*it); 296 unprotected_configuration.push_back(*it);
297 unprotected_pref_names.insert(it->name);
295 } 298 }
296 } 299 }
297 300
298 scoped_ptr<PrefFilter> unprotected_pref_hash_filter( 301 scoped_ptr<PrefFilter> unprotected_pref_hash_filter(
299 new PrefHashFilter(GetPrefHashStoreImpl().PassAs<PrefHashStore>(), 302 new PrefHashFilter(GetPrefHashStoreImpl().PassAs<PrefHashStore>(),
300 unprotected_configuration, 303 unprotected_configuration,
301 reporting_ids_count_)); 304 reporting_ids_count_));
302 scoped_ptr<PrefFilter> protected_pref_hash_filter( 305 scoped_ptr<PrefFilter> protected_pref_hash_filter(
303 new PrefHashFilter(GetPrefHashStoreImpl().PassAs<PrefHashStore>(), 306 new PrefHashFilter(GetPrefHashStoreImpl().PassAs<PrefHashStore>(),
304 protected_configuration, 307 protected_configuration,
305 reporting_ids_count_)); 308 reporting_ids_count_));
306 309
307 scoped_refptr<PersistentPrefStore> unprotected_pref_store( 310 scoped_refptr<JsonPrefStore> unprotected_pref_store(
308 new JsonPrefStore(GetPrefFilePathFromProfilePath(profile_path_), 311 new JsonPrefStore(GetPrefFilePathFromProfilePath(profile_path_),
309 io_task_runner, 312 io_task_runner,
310 unprotected_pref_hash_filter.Pass())); 313 unprotected_pref_hash_filter.Pass()));
311 scoped_refptr<PersistentPrefStore> protected_pref_store(new JsonPrefStore( 314 scoped_refptr<JsonPrefStore> protected_pref_store(new JsonPrefStore(
312 profile_path_.Append(chrome::kProtectedPreferencesFilename), 315 profile_path_.Append(chrome::kProtectedPreferencesFilename),
313 io_task_runner, 316 io_task_runner,
314 protected_pref_hash_filter.Pass())); 317 protected_pref_hash_filter.Pass()));
315 318
316 // The on_initialized callback is used to migrate newly protected values from 319 SetupTrackedPreferencesMigration(unprotected_pref_names,
317 // the main Preferences store to the Protected Preferences store. It is also 320 protected_pref_names,
318 // responsible for the initial migration to a two-store model. 321 unprotected_pref_store,
319 return new SegregatedPrefStore( 322 protected_pref_store);
320 unprotected_pref_store, 323
321 protected_pref_store, 324 return new SegregatedPrefStore(unprotected_pref_store, protected_pref_store,
322 protected_pref_names, 325 protected_pref_names);
323 base::Bind(&PrefHashFilter::MigrateValues,
324 base::Owned(new PrefHashFilter(
325 CopyPrefHashStore(),
326 protected_configuration,
327 reporting_ids_count_)),
328 unprotected_pref_store,
329 protected_pref_store));
330 } 326 }
331 327
332 void ProfilePrefStoreManager::UpdateProfileHashStoreIfRequired( 328 void ProfilePrefStoreManager::UpdateProfileHashStoreIfRequired(
333 const scoped_refptr<base::SequencedTaskRunner>& io_task_runner) { 329 const scoped_refptr<base::SequencedTaskRunner>& io_task_runner) {
334 if (!kPlatformSupportsPreferenceTracking) 330 if (!kPlatformSupportsPreferenceTracking)
335 return; 331 return;
336 scoped_ptr<PrefHashStoreImpl> pref_hash_store_impl(GetPrefHashStoreImpl()); 332 scoped_ptr<PrefHashStoreImpl> pref_hash_store_impl(GetPrefHashStoreImpl());
337 const PrefHashStoreImpl::StoreVersion current_version = 333 const PrefHashStoreImpl::StoreVersion current_version =
338 pref_hash_store_impl->GetCurrentVersion(); 334 pref_hash_store_impl->GetCurrentVersion();
339 UMA_HISTOGRAM_ENUMERATION("Settings.TrackedPreferencesAlternateStoreVersion", 335 UMA_HISTOGRAM_ENUMERATION("Settings.TrackedPreferencesAlternateStoreVersion",
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
403 399
404 scoped_ptr<PrefHashStoreImpl> ProfilePrefStoreManager::GetPrefHashStoreImpl() { 400 scoped_ptr<PrefHashStoreImpl> ProfilePrefStoreManager::GetPrefHashStoreImpl() {
405 DCHECK(kPlatformSupportsPreferenceTracking); 401 DCHECK(kPlatformSupportsPreferenceTracking);
406 402
407 return make_scoped_ptr(new PrefHashStoreImpl( 403 return make_scoped_ptr(new PrefHashStoreImpl(
408 seed_, 404 seed_,
409 device_id_, 405 device_id_,
410 scoped_ptr<HashStoreContents>(new PrefServiceHashStoreContents( 406 scoped_ptr<HashStoreContents>(new PrefServiceHashStoreContents(
411 profile_path_.AsUTF8Unsafe(), local_state_)))); 407 profile_path_.AsUTF8Unsafe(), local_state_))));
412 } 408 }
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 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698