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

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: additional cleanup Created 5 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 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 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 #endif 156 #endif
157 157
158 #if defined(OS_CHROMEOS) 158 #if defined(OS_CHROMEOS)
159 #include "chrome/browser/chromeos/app_mode/kiosk_app_manager.h" 159 #include "chrome/browser/chromeos/app_mode/kiosk_app_manager.h"
160 #include "chrome/browser/chromeos/attestation/platform_verification_flow.h" 160 #include "chrome/browser/chromeos/attestation/platform_verification_flow.h"
161 #include "chrome/browser/chromeos/customization/customization_document.h" 161 #include "chrome/browser/chromeos/customization/customization_document.h"
162 #include "chrome/browser/chromeos/display/display_preferences.h" 162 #include "chrome/browser/chromeos/display/display_preferences.h"
163 #include "chrome/browser/chromeos/extensions/echo_private_api.h" 163 #include "chrome/browser/chromeos/extensions/echo_private_api.h"
164 #include "chrome/browser/chromeos/file_system_provider/registry.h" 164 #include "chrome/browser/chromeos/file_system_provider/registry.h"
165 #include "chrome/browser/chromeos/first_run/first_run.h" 165 #include "chrome/browser/chromeos/first_run/first_run.h"
166 #include "chrome/browser/chromeos/login/default_pinned_apps_field_trial.h"
167 #include "chrome/browser/chromeos/login/saml/saml_offline_signin_limiter.h" 166 #include "chrome/browser/chromeos/login/saml/saml_offline_signin_limiter.h"
168 #include "chrome/browser/chromeos/login/session/user_session_manager.h" 167 #include "chrome/browser/chromeos/login/session/user_session_manager.h"
169 #include "chrome/browser/chromeos/login/startup_utils.h" 168 #include "chrome/browser/chromeos/login/startup_utils.h"
170 #include "chrome/browser/chromeos/login/users/avatar/user_image_manager.h" 169 #include "chrome/browser/chromeos/login/users/avatar/user_image_manager.h"
171 #include "chrome/browser/chromeos/login/users/avatar/user_image_sync_observer.h" 170 #include "chrome/browser/chromeos/login/users/avatar/user_image_sync_observer.h"
172 #include "chrome/browser/chromeos/login/users/chrome_user_manager_impl.h" 171 #include "chrome/browser/chromeos/login/users/chrome_user_manager_impl.h"
173 #include "chrome/browser/chromeos/login/users/multi_profile_user_controller.h" 172 #include "chrome/browser/chromeos/login/users/multi_profile_user_controller.h"
174 #include "chrome/browser/chromeos/login/users/wallpaper/wallpaper_manager.h" 173 #include "chrome/browser/chromeos/login/users/wallpaper/wallpaper_manager.h"
175 #include "chrome/browser/chromeos/net/proxy_config_handler.h" 174 #include "chrome/browser/chromeos/net/proxy_config_handler.h"
176 #include "chrome/browser/chromeos/policy/auto_enrollment_client.h" 175 #include "chrome/browser/chromeos/policy/auto_enrollment_client.h"
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 #if defined(TOOLKIT_VIEWS) 216 #if defined(TOOLKIT_VIEWS)
218 #include "chrome/browser/ui/browser_view_prefs.h" 217 #include "chrome/browser/ui/browser_view_prefs.h"
219 #endif 218 #endif
220 219
221 #if defined(USE_ASH) 220 #if defined(USE_ASH)
222 #include "chrome/browser/ui/ash/chrome_launcher_prefs.h" 221 #include "chrome/browser/ui/ash/chrome_launcher_prefs.h"
223 #endif 222 #endif
224 223
225 namespace { 224 namespace {
226 225
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) 226 #if !defined(OS_ANDROID)
241 // The AutomaticProfileResetter service used this preference to save that the 227 // The AutomaticProfileResetter service used this preference to save that the
242 // profile reset prompt had already been shown, however, the preference has been 228 // 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 229 // renamed in Local State. We keep the name here for now so that we can clear
244 // out legacy values. 230 // out legacy values.
245 // TODO(engedy): Remove this and usages in M42 or later. See crbug.com/398813. 231 // TODO(engedy): Remove this and usages in M42 or later. See crbug.com/398813.
246 const char kLegacyProfileResetPromptMemento[] = "profile.reset_prompt_memento"; 232 const char kLegacyProfileResetPromptMemento[] = "profile.reset_prompt_memento";
247 #endif 233 #endif
248 234
249 } // namespace 235 } // namespace
250 236
251 namespace chrome { 237 namespace chrome {
252 238
253 void RegisterLocalState(PrefRegistrySimple* registry) { 239 void RegisterLocalState(PrefRegistrySimple* registry) {
254 // Prefs in Local State.
255 registry->RegisterIntegerPref(prefs::kMultipleProfilePrefMigration, 0);
256 240
257 // Please keep this list alphabetized. 241 // Please keep this list alphabetized.
258 AppListService::RegisterPrefs(registry); 242 AppListService::RegisterPrefs(registry);
259 browser_shutdown::RegisterPrefs(registry); 243 browser_shutdown::RegisterPrefs(registry);
260 BrowserProcessImpl::RegisterPrefs(registry); 244 BrowserProcessImpl::RegisterPrefs(registry);
261 ChromeMetricsServiceClient::RegisterPrefs(registry); 245 ChromeMetricsServiceClient::RegisterPrefs(registry);
262 chrome_prefs::RegisterPrefs(registry); 246 chrome_prefs::RegisterPrefs(registry);
263 chrome_variations::VariationsService::RegisterPrefs(registry); 247 chrome_variations::VariationsService::RegisterPrefs(registry);
264 component_updater::RegisterPrefsForRecoveryComponent(registry); 248 component_updater::RegisterPrefsForRecoveryComponent(registry);
265 component_updater::SupervisedUserWhitelistInstaller::RegisterPrefs(registry); 249 component_updater::SupervisedUserWhitelistInstaller::RegisterPrefs(registry);
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
322 #endif // !defined(OS_CHROMEOS) 306 #endif // !defined(OS_CHROMEOS)
323 #endif // !defined(OS_ANDROID) 307 #endif // !defined(OS_ANDROID)
324 308
325 #if defined(OS_CHROMEOS) 309 #if defined(OS_CHROMEOS)
326 ChromeOSMetricsProvider::RegisterPrefs(registry); 310 ChromeOSMetricsProvider::RegisterPrefs(registry);
327 chromeos::AudioDevicesPrefHandlerImpl::RegisterPrefs(registry); 311 chromeos::AudioDevicesPrefHandlerImpl::RegisterPrefs(registry);
328 chromeos::ChromeUserManagerImpl::RegisterPrefs(registry); 312 chromeos::ChromeUserManagerImpl::RegisterPrefs(registry);
329 chromeos::DataPromoNotification::RegisterPrefs(registry); 313 chromeos::DataPromoNotification::RegisterPrefs(registry);
330 chromeos::DeviceOAuth2TokenService::RegisterPrefs(registry); 314 chromeos::DeviceOAuth2TokenService::RegisterPrefs(registry);
331 chromeos::device_settings_cache::RegisterPrefs(registry); 315 chromeos::device_settings_cache::RegisterPrefs(registry);
332 chromeos::default_pinned_apps_field_trial::RegisterPrefs(registry);
333 chromeos::EnableDebuggingScreenHandler::RegisterPrefs(registry); 316 chromeos::EnableDebuggingScreenHandler::RegisterPrefs(registry);
334 chromeos::language_prefs::RegisterPrefs(registry); 317 chromeos::language_prefs::RegisterPrefs(registry);
335 chromeos::KioskAppManager::RegisterPrefs(registry); 318 chromeos::KioskAppManager::RegisterPrefs(registry);
336 chromeos::MultiProfileUserController::RegisterPrefs(registry); 319 chromeos::MultiProfileUserController::RegisterPrefs(registry);
337 chromeos::HIDDetectionScreenHandler::RegisterPrefs(registry); 320 chromeos::HIDDetectionScreenHandler::RegisterPrefs(registry);
338 chromeos::DemoModeDetector::RegisterPrefs(registry); 321 chromeos::DemoModeDetector::RegisterPrefs(registry);
339 chromeos::Preferences::RegisterPrefs(registry); 322 chromeos::Preferences::RegisterPrefs(registry);
340 chromeos::proxy_config::RegisterPrefs(registry); 323 chromeos::proxy_config::RegisterPrefs(registry);
341 chromeos::RegisterDisplayLocalStatePrefs(registry); 324 chromeos::RegisterDisplayLocalStatePrefs(registry);
342 chromeos::ResetScreenHandler::RegisterPrefs(registry); 325 chromeos::ResetScreenHandler::RegisterPrefs(registry);
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
523 #endif 506 #endif
524 507
525 #if defined(TOOLKIT_VIEWS) 508 #if defined(TOOLKIT_VIEWS)
526 RegisterBrowserViewProfilePrefs(registry); 509 RegisterBrowserViewProfilePrefs(registry);
527 RegisterInvertBubbleUserPrefs(registry); 510 RegisterInvertBubbleUserPrefs(registry);
528 #endif 511 #endif
529 512
530 #if defined(USE_ASH) 513 #if defined(USE_ASH)
531 ash::RegisterChromeLauncherUserPrefs(registry); 514 ash::RegisterChromeLauncherUserPrefs(registry);
532 #endif 515 #endif
533
534 // Preferences registered only for migration (clearing or moving to a new key)
535 // go here.
536 registry->RegisterDictionaryPref(
537 kBackupPref,
538 new base::DictionaryValue(),
539 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
540 } 516 }
541 517
542 void RegisterUserProfilePrefs(user_prefs::PrefRegistrySyncable* registry) { 518 void RegisterUserProfilePrefs(user_prefs::PrefRegistrySyncable* registry) {
543 RegisterProfilePrefs(registry); 519 RegisterProfilePrefs(registry);
544 520
545 #if defined(OS_CHROMEOS) 521 #if defined(OS_CHROMEOS)
546 chromeos::PowerPrefs::RegisterUserProfilePrefs(registry); 522 chromeos::PowerPrefs::RegisterUserProfilePrefs(registry);
547 #endif 523 #endif
548 } 524 }
549 525
550 void RegisterScreenshotPrefs(PrefRegistrySimple* registry) { 526 void RegisterScreenshotPrefs(PrefRegistrySimple* registry) {
551 registry->RegisterBooleanPref(prefs::kDisableScreenshots, false); 527 registry->RegisterBooleanPref(prefs::kDisableScreenshots, false);
552 } 528 }
553 529
554 #if defined(OS_CHROMEOS) 530 #if defined(OS_CHROMEOS)
555 void RegisterLoginProfilePrefs(user_prefs::PrefRegistrySyncable* registry) { 531 void RegisterLoginProfilePrefs(user_prefs::PrefRegistrySyncable* registry) {
556 RegisterProfilePrefs(registry); 532 RegisterProfilePrefs(registry);
557 533
558 chromeos::PowerPrefs::RegisterLoginProfilePrefs(registry); 534 chromeos::PowerPrefs::RegisterLoginProfilePrefs(registry);
559 } 535 }
560 #endif 536 #endif
561 537
562 void MigrateUserPrefs(Profile* profile) { 538 void MigrateObsoleteBrowserPrefs(Profile* profile, PrefService* local_state) {
563 PrefService* prefs = profile->GetPrefs(); 539 // This method should be periodically pruned of year+ old migrations.
gab 2015/03/02 19:28:09 Indent.
rkaplow 2015/03/02 19:36:35 I agree, but what happened here was git cl format
gab 2015/03/02 20:05:08 Actually I think this highlights that the comment
rkaplow 2015/03/02 20:21:35 Done.
564 540
565 // Cleanup prefs from now-removed protector feature. 541 // Added 05/2014.
gab 2015/03/02 19:28:09 Comment inside ifdef (and thus indented).
rkaplow 2015/03/02 19:36:35 Done.
566 prefs->ClearPref(kBackupPref); 542 #if defined(TOOLKIT_VIEWS)
543 MigrateBrowserTabStripPrefs(local_state);
544 #endif
545
546 // Added 08/2014.
gab 2015/03/02 19:28:09 Comment inside ifdef (and thus indented).
rkaplow 2015/03/02 19:36:35 Done.
547 #if !defined(OS_ANDROID)
548 local_state->ClearPref(kLegacyProfileResetPromptMemento);
549 #endif
550 }
551
552 void MigrateObsoleteProfilePrefs(Profile* profile) {
553 // This method should be periodically pruned of year+ old migrations.
554 PrefService* profile_prefs = profile->GetPrefs();
gab 2015/03/02 20:05:08 Actually these two lines particularly highlight wh
rkaplow 2015/03/02 20:21:35 Done.
555
556 #if defined(OS_MACOSX) && !defined(OS_IOS)
557 // Added 06/2014.
558 autofill::AutofillManager::MigrateUserPrefs(profile_prefs);
559 #endif // defined(OS_MACOSX) && !defined(OS_IOS)
560
561 // Added 07/2014.
562 translate::TranslatePrefs::MigrateUserPrefs(profile_prefs,
563 prefs::kAcceptLanguages);
567 564
568 #if !defined(OS_ANDROID) 565 #if !defined(OS_ANDROID)
566 // Added 08/2014.
569 // Migrate kNetworkPredictionEnabled to kNetworkPredictionOptions when not on 567 // Migrate kNetworkPredictionEnabled to kNetworkPredictionOptions when not on
570 // Android. On Android, platform-specific code performs preference migration. 568 // Android. On Android, platform-specific code performs preference migration.
571 // TODO(bnc): https://crbug.com/401970 Remove migration code one year after 569 // TODO(bnc): https://crbug.com/401970 Remove migration code one year after
572 // M38. 570 // M38.
573 chrome_browser_net::MigrateNetworkPredictionUserPrefs(prefs); 571 chrome_browser_net::MigrateNetworkPredictionUserPrefs(profile_prefs);
574 #endif 572 #endif
575 573
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) 574 #if defined(OS_CHROMEOS) && defined(ENABLE_APP_LIST)
575 // Added 02/2015.
584 MigrateGoogleNowPrefs(profile); 576 MigrateGoogleNowPrefs(profile);
585 #endif 577 #endif
586 } 578 }
587 579
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, 580 // 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 581 // 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 582 // if so convert them to be per-partition. We migrate any per-profile zoom
641 // level prefs via zoom_level_prefs. 583 // level prefs via zoom_level_prefs.
642 // Code that updates zoom prefs in the profile prefs store has been removed, 584 // 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. 585 // so once we clear these values here, they should never get set again.
644 // TODO(wjmaclean): Remove this migration machinery after histograms show 586 // TODO(wjmaclean): Remove this migration machinery after histograms show
645 // that an aceptable percentage of users have been migrated. 587 // that an aceptable percentage of users have been migrated.
646 // crbug.com/420643 588 // crbug.com/420643
647 void MigrateProfileZoomLevelPrefs(Profile* profile) { 589 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 */); 624 host_zoom_dictionary, false /* sanitize_partition_host_zoom_levels */);
683 625
684 // We're done migrating the profile per-host zoom level values, so we clear 626 // We're done migrating the profile per-host zoom level values, so we clear
685 // them all. 627 // them all.
686 DictionaryPrefUpdate host_zoom_dictionary_update( 628 DictionaryPrefUpdate host_zoom_dictionary_update(
687 prefs, prefs::kPerHostZoomLevelsDeprecated); 629 prefs, prefs::kPerHostZoomLevelsDeprecated);
688 host_zoom_dictionary_update->Clear(); 630 host_zoom_dictionary_update->Clear();
689 } 631 }
690 632
691 } // namespace chrome 633 } // namespace chrome
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698