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

Unified Diff: chrome/browser/prefs/session_startup_pref.cc

Issue 10049005: Fix homepage migration for users who never changed their settings. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fixes Created 8 years, 8 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/prefs/session_startup_pref.h ('k') | chrome/browser/prefs/session_startup_pref_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/prefs/session_startup_pref.cc
diff --git a/chrome/browser/prefs/session_startup_pref.cc b/chrome/browser/prefs/session_startup_pref.cc
index 447df6523efc57b16e18fcdbf7e666bb4dc04e77..1d4aad838ea420d625ee81ae94c8cf7d532c59ac 100644
--- a/chrome/browser/prefs/session_startup_pref.cc
+++ b/chrome/browser/prefs/session_startup_pref.cc
@@ -42,10 +42,13 @@ int TypeToPrefValue(SessionStartupPref::Type type) {
}
void SetNewURLList(PrefService* prefs) {
- ListValue new_url_pref_list;
- StringValue* home_page = new StringValue(prefs->GetString(prefs::kHomePage));
- new_url_pref_list.Append(home_page);
- prefs->Set(prefs::kURLsToRestoreOnStartup, new_url_pref_list);
+ if (prefs->IsUserModifiablePreference(prefs::kURLsToRestoreOnStartup)) {
+ ListValue new_url_pref_list;
+ StringValue* home_page =
+ new StringValue(prefs->GetString(prefs::kHomePage));
+ new_url_pref_list.Append(home_page);
+ prefs->Set(prefs::kURLsToRestoreOnStartup, new_url_pref_list);
+ }
}
void URLListToPref(const base::ListValue* url_list, SessionStartupPref* pref) {
@@ -70,6 +73,9 @@ void SessionStartupPref::RegisterUserPrefs(PrefService* prefs) {
PrefService::SYNCABLE_PREF);
prefs->RegisterListPref(prefs::kURLsToRestoreOnStartup,
PrefService::SYNCABLE_PREF);
+ prefs->RegisterBooleanPref(prefs::kRestoreOnStartupMigrated,
+ false,
+ PrefService::UNSYNCABLE_PREF);
}
// static
@@ -129,17 +135,17 @@ SessionStartupPref SessionStartupPref::GetStartupPref(Profile* profile) {
// static
SessionStartupPref SessionStartupPref::GetStartupPref(PrefService* prefs) {
DCHECK(prefs);
+
+ MigrateIfNecessary(prefs);
+
SessionStartupPref pref(
PrefValueToType(prefs->GetInteger(prefs::kRestoreOnStartup)));
- // Migrate from "Open the home page" to "Open the following URLs". If the user
- // had the "Open the homepage" option selected, then we need to switch them to
- // "Open the following URLs" and set the list of URLs to a list containing
- // just the user's homepage.
- if (pref.type == SessionStartupPref::HOMEPAGE) {
- prefs->SetInteger(prefs::kRestoreOnStartup, kPrefValueURLs);
- pref.type = SessionStartupPref::URLS;
- SetNewURLList(prefs);
+ if (pref.type == HOMEPAGE) {
+ // We've already migrated, so the only way this can happen is if
+ // kRestoreOnStartup is controlled by a policy. In that case, act as though
+ // URLS was selected.
Mattias Nissler (ping if slow) 2012/04/18 11:40:54 We should change RestoreOnStartupPolicyHandler in
Tyler Breisacher (Chromium) 2012/04/18 18:26:03 http://crbug.com/124027 The patch I just uploaded
Mattias Nissler (ping if slow) 2012/04/19 13:23:17 Thanks for fixing the policy!
+ pref.type = URLS;
}
// Always load the urls, even if the pref type isn't URLS. This way the
@@ -151,6 +157,30 @@ SessionStartupPref SessionStartupPref::GetStartupPref(PrefService* prefs) {
}
// static
+void SessionStartupPref::MigrateIfNecessary(PrefService* prefs) {
+ DCHECK(prefs);
+
+ if (!prefs->GetBoolean(prefs::kRestoreOnStartupMigrated)) {
+
+ if (prefs->GetInteger(prefs::kRestoreOnStartup) == kPrefValueHomePage ||
+ (!prefs->HasPrefPath(prefs::kRestoreOnStartup) &&
+ !prefs->GetBoolean(prefs::kHomePageIsNewTabPage))) {
+
+ if (prefs->GetBoolean(prefs::kHomePageIsNewTabPage)) {
Mattias Nissler (ping if slow) 2012/04/18 11:40:54 This still breaks if prefs::kHomePageIsNewTabPage
Tyler Breisacher (Chromium) 2012/04/18 18:26:03 I don't think we change the value of kHomePageIsNe
Mattias Nissler (ping if slow) 2012/04/19 13:23:17 What I meant was that the pref value you get in li
+ if (prefs->IsUserModifiablePreference(prefs::kRestoreOnStartup))
+ prefs->SetInteger(prefs::kRestoreOnStartup, kPrefValueNewTab);
+ } else {
+ if (prefs->IsUserModifiablePreference(prefs::kRestoreOnStartup))
+ prefs->SetInteger(prefs::kRestoreOnStartup, kPrefValueURLs);
+ SetNewURLList(prefs);
+ }
+ }
+
+ prefs->SetBoolean(prefs::kRestoreOnStartupMigrated, true);
+ }
+}
+
+// static
bool SessionStartupPref::TypeIsManaged(PrefService* prefs) {
DCHECK(prefs);
const PrefService::Preference* pref_restore =
« no previous file with comments | « chrome/browser/prefs/session_startup_pref.h ('k') | chrome/browser/prefs/session_startup_pref_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698