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

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

Issue 944433002: Revamp the MigrateBrowserPrefs and MigrateUserPrefs code. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: readd kbrowserwindowplacement to ui_prefs.cc Created 5 years, 10 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 2012 The Chromium Authors. All rights reserved. 1 // Copyright 2012 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/browser_prefs.h" 5 #include "chrome/browser/prefs/browser_prefs.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/metrics/histogram_macros.h" 9 #include "base/metrics/histogram_macros.h"
10 #include "base/prefs/pref_registry_simple.h" 10 #include "base/prefs/pref_registry_simple.h"
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 #if defined(TOOLKIT_VIEWS) 217 #if defined(TOOLKIT_VIEWS)
218 #include "chrome/browser/ui/browser_view_prefs.h" 218 #include "chrome/browser/ui/browser_view_prefs.h"
219 #endif 219 #endif
220 220
221 #if defined(USE_ASH) 221 #if defined(USE_ASH)
222 #include "chrome/browser/ui/ash/chrome_launcher_prefs.h" 222 #include "chrome/browser/ui/ash/chrome_launcher_prefs.h"
223 #endif 223 #endif
224 224
225 namespace { 225 namespace {
226 226
227 enum MigratedPreferences {
228 NO_PREFS = 0,
229 DNS_PREFS = 1 << 0,
230 WINDOWS_PREFS = 1 << 1,
231 };
232
233 // A previous feature (see
234 // chrome/browser/protector/protected_prefs_watcher.cc in source
235 // control history) used this string as a prefix for various prefs it
236 // registered. We keep it here for now to clear out those old prefs in
237 // MigrateUserPrefs.
238 const char kBackupPref[] = "backup";
239
240 #if !defined(OS_ANDROID) 227 #if !defined(OS_ANDROID)
241 // The AutomaticProfileResetter service used this preference to save that the 228 // The AutomaticProfileResetter service used this preference to save that the
242 // profile reset prompt had already been shown, however, the preference has been 229 // profile reset prompt had already been shown, however, the preference has been
243 // renamed in Local State. We keep the name here for now so that we can clear 230 // renamed in Local State. We keep the name here for now so that we can clear
244 // out legacy values. 231 // out legacy values.
245 // TODO(engedy): Remove this and usages in M42 or later. See crbug.com/398813. 232 // TODO(engedy): Remove this and usages in M42 or later. See crbug.com/398813.
246 const char kLegacyProfileResetPromptMemento[] = "profile.reset_prompt_memento"; 233 const char kLegacyProfileResetPromptMemento[] = "profile.reset_prompt_memento";
247 #endif 234 #endif
248 235
249 } // namespace 236 } // namespace
250 237
251 namespace chrome { 238 namespace chrome {
252 239
253 void RegisterLocalState(PrefRegistrySimple* registry) { 240 void RegisterLocalState(PrefRegistrySimple* registry) {
254 // Prefs in Local State.
255 registry->RegisterIntegerPref(prefs::kMultipleProfilePrefMigration, 0);
256 241
257 // Please keep this list alphabetized. 242 // Please keep this list alphabetized.
258 AppListService::RegisterPrefs(registry); 243 AppListService::RegisterPrefs(registry);
259 browser_shutdown::RegisterPrefs(registry); 244 browser_shutdown::RegisterPrefs(registry);
260 BrowserProcessImpl::RegisterPrefs(registry); 245 BrowserProcessImpl::RegisterPrefs(registry);
261 ChromeMetricsServiceClient::RegisterPrefs(registry); 246 ChromeMetricsServiceClient::RegisterPrefs(registry);
262 chrome_prefs::RegisterPrefs(registry); 247 chrome_prefs::RegisterPrefs(registry);
263 chrome_variations::VariationsService::RegisterPrefs(registry); 248 chrome_variations::VariationsService::RegisterPrefs(registry);
264 component_updater::RegisterPrefsForRecoveryComponent(registry); 249 component_updater::RegisterPrefsForRecoveryComponent(registry);
265 component_updater::SupervisedUserWhitelistInstaller::RegisterPrefs(registry); 250 component_updater::SupervisedUserWhitelistInstaller::RegisterPrefs(registry);
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after
525 #if defined(TOOLKIT_VIEWS) 510 #if defined(TOOLKIT_VIEWS)
526 RegisterBrowserViewProfilePrefs(registry); 511 RegisterBrowserViewProfilePrefs(registry);
527 RegisterInvertBubbleUserPrefs(registry); 512 RegisterInvertBubbleUserPrefs(registry);
528 #endif 513 #endif
529 514
530 #if defined(USE_ASH) 515 #if defined(USE_ASH)
531 ash::RegisterChromeLauncherUserPrefs(registry); 516 ash::RegisterChromeLauncherUserPrefs(registry);
532 #endif 517 #endif
533 518
534 // Preferences registered only for migration (clearing or moving to a new key) 519 // Preferences registered only for migration (clearing or moving to a new key)
535 // go here. 520 // go here.
gab 2015/02/24 20:55:20 Remove this comment I guess now that it comments n
rkaplow 2015/02/24 22:41:11 make sense. We actually have this comment on line
536 registry->RegisterDictionaryPref(
537 kBackupPref,
538 new base::DictionaryValue(),
539 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
540 } 521 }
541 522
542 void RegisterUserProfilePrefs(user_prefs::PrefRegistrySyncable* registry) { 523 void RegisterUserProfilePrefs(user_prefs::PrefRegistrySyncable* registry) {
543 RegisterProfilePrefs(registry); 524 RegisterProfilePrefs(registry);
544 525
545 #if defined(OS_CHROMEOS) 526 #if defined(OS_CHROMEOS)
546 chromeos::PowerPrefs::RegisterUserProfilePrefs(registry); 527 chromeos::PowerPrefs::RegisterUserProfilePrefs(registry);
547 #endif 528 #endif
548 } 529 }
549 530
550 void RegisterScreenshotPrefs(PrefRegistrySimple* registry) { 531 void RegisterScreenshotPrefs(PrefRegistrySimple* registry) {
551 registry->RegisterBooleanPref(prefs::kDisableScreenshots, false); 532 registry->RegisterBooleanPref(prefs::kDisableScreenshots, false);
552 } 533 }
553 534
554 #if defined(OS_CHROMEOS) 535 #if defined(OS_CHROMEOS)
555 void RegisterLoginProfilePrefs(user_prefs::PrefRegistrySyncable* registry) { 536 void RegisterLoginProfilePrefs(user_prefs::PrefRegistrySyncable* registry) {
556 RegisterProfilePrefs(registry); 537 RegisterProfilePrefs(registry);
557 538
558 chromeos::PowerPrefs::RegisterLoginProfilePrefs(registry); 539 chromeos::PowerPrefs::RegisterLoginProfilePrefs(registry);
559 } 540 }
560 #endif 541 #endif
561 542
562 void MigrateUserPrefs(Profile* profile) { 543 void MigrateObsoleteBrowserPrefs(Profile* profile, PrefService* local_state) {
563 PrefService* prefs = profile->GetPrefs(); 544 // This method should be periodically pruned of year+ old migrations.
564 545
565 // Cleanup prefs from now-removed protector feature. 546 // Added 05/2014.
566 prefs->ClearPref(kBackupPref); 547 #if defined(TOOLKIT_VIEWS)
548 MigrateBrowserTabStripPrefs(local_state);
549 #endif
550
551 // Added 08/2014.
552 #if !defined(OS_ANDROID)
553 local_state->ClearPref(kLegacyProfileResetPromptMemento);
554 #endif
555 }
556
557 void MigrateObsoleteProfilePrefs(Profile* profile) {
558 // This method should be periodically pruned of year+ old migrations.
559 PrefService* profile_prefs = profile->GetPrefs();
560
561 #if defined(OS_MACOSX) && !defined(OS_IOS)
562 // Added 06/2014.
563 autofill::AutofillManager::MigrateUserPrefs(profile_prefs);
564 #endif // defined(OS_MACOSX) && !defined(OS_IOS)
565
566 // Added 07/2014.
567 translate::TranslatePrefs::MigrateUserPrefs(profile_prefs,
568 prefs::kAcceptLanguages);
567 569
568 #if !defined(OS_ANDROID) 570 #if !defined(OS_ANDROID)
571 // Added 08/2014.
569 // Migrate kNetworkPredictionEnabled to kNetworkPredictionOptions when not on 572 // Migrate kNetworkPredictionEnabled to kNetworkPredictionOptions when not on
570 // Android. On Android, platform-specific code performs preference migration. 573 // Android. On Android, platform-specific code performs preference migration.
571 // TODO(bnc): https://crbug.com/401970 Remove migration code one year after 574 // TODO(bnc): https://crbug.com/401970 Remove migration code one year after
572 // M38. 575 // M38.
573 chrome_browser_net::MigrateNetworkPredictionUserPrefs(prefs); 576 chrome_browser_net::MigrateNetworkPredictionUserPrefs(profile_prefs);
574 #endif 577 #endif
575 578
576 PromoResourceService::MigrateUserPrefs(prefs);
577 translate::TranslatePrefs::MigrateUserPrefs(prefs, prefs::kAcceptLanguages);
578
579 #if defined(OS_MACOSX) && !defined(OS_IOS)
580 autofill::AutofillManager::MigrateUserPrefs(prefs);
581 #endif // defined(OS_MACOSX) && !defined(OS_IOS)
582
583 #if defined(OS_CHROMEOS) && defined(ENABLE_APP_LIST) 579 #if defined(OS_CHROMEOS) && defined(ENABLE_APP_LIST)
580 // Added 02/2015.
584 MigrateGoogleNowPrefs(profile); 581 MigrateGoogleNowPrefs(profile);
585 #endif 582 #endif
586 } 583 }
587 584
588 void MigrateBrowserPrefs(Profile* profile, PrefService* local_state) {
589 // Copy pref values which have been migrated to user_prefs from local_state,
590 // or remove them from local_state outright, if copying is not required.
591 int current_version =
592 local_state->GetInteger(prefs::kMultipleProfilePrefMigration);
593 PrefRegistrySimple* registry = static_cast<PrefRegistrySimple*>(
594 local_state->DeprecatedGetPrefRegistry());
595
596 if (!(current_version & DNS_PREFS)) {
597 registry->RegisterListPref(prefs::kDnsStartupPrefetchList);
598 local_state->ClearPref(prefs::kDnsStartupPrefetchList);
599
600 registry->RegisterListPref(prefs::kDnsHostReferralList);
601 local_state->ClearPref(prefs::kDnsHostReferralList);
602
603 current_version |= DNS_PREFS;
604 local_state->SetInteger(prefs::kMultipleProfilePrefMigration,
605 current_version);
606 }
607
608 PrefService* user_prefs = profile->GetPrefs();
609 if (!(current_version & WINDOWS_PREFS)) {
610 registry->RegisterDictionaryPref(prefs::kBrowserWindowPlacement);
611 if (local_state->HasPrefPath(prefs::kBrowserWindowPlacement)) {
612 const PrefService::Preference* pref =
613 local_state->FindPreference(prefs::kBrowserWindowPlacement);
614 DCHECK(pref);
615 user_prefs->Set(prefs::kBrowserWindowPlacement,
616 *(pref->GetValue()));
617 }
618 local_state->ClearPref(prefs::kBrowserWindowPlacement);
619
620 current_version |= WINDOWS_PREFS;
621 local_state->SetInteger(prefs::kMultipleProfilePrefMigration,
622 current_version);
623 }
624
625 #if !defined(OS_ANDROID)
626 local_state->ClearPref(kLegacyProfileResetPromptMemento);
627 #endif
628
629 #if defined(OS_CHROMEOS)
630 chromeos::default_pinned_apps_field_trial::MigratePrefs(local_state);
631 #endif
632
633 #if defined(TOOLKIT_VIEWS)
634 MigrateBrowserTabStripPrefs(local_state);
635 #endif
636 }
637
638 // As part of the migration from per-profile to per-partition HostZoomMaps, 585 // As part of the migration from per-profile to per-partition HostZoomMaps,
639 // we need to detect if an existing per-profile set of preferences exist, and 586 // we need to detect if an existing per-profile set of preferences exist, and
640 // if so convert them to be per-partition. We migrate any per-profile zoom 587 // if so convert them to be per-partition. We migrate any per-profile zoom
641 // level prefs via zoom_level_prefs. 588 // level prefs via zoom_level_prefs.
642 // Code that updates zoom prefs in the profile prefs store has been removed, 589 // Code that updates zoom prefs in the profile prefs store has been removed,
643 // so once we clear these values here, they should never get set again. 590 // so once we clear these values here, they should never get set again.
644 // TODO(wjmaclean): Remove this migration machinery after histograms show 591 // TODO(wjmaclean): Remove this migration machinery after histograms show
645 // that an aceptable percentage of users have been migrated. 592 // that an aceptable percentage of users have been migrated.
646 // crbug.com/420643 593 // crbug.com/420643
647 void MigrateProfileZoomLevelPrefs(Profile* profile) { 594 void MigrateProfileZoomLevelPrefs(Profile* profile) {
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
682 host_zoom_dictionary, false /* sanitize_partition_host_zoom_levels */); 629 host_zoom_dictionary, false /* sanitize_partition_host_zoom_levels */);
683 630
684 // We're done migrating the profile per-host zoom level values, so we clear 631 // We're done migrating the profile per-host zoom level values, so we clear
685 // them all. 632 // them all.
686 DictionaryPrefUpdate host_zoom_dictionary_update( 633 DictionaryPrefUpdate host_zoom_dictionary_update(
687 prefs, prefs::kPerHostZoomLevelsDeprecated); 634 prefs, prefs::kPerHostZoomLevelsDeprecated);
688 host_zoom_dictionary_update->Clear(); 635 host_zoom_dictionary_update->Clear();
689 } 636 }
690 637
691 } // namespace chrome 638 } // namespace chrome
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698