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

Side by Side 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: test migration from blank 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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/session_startup_pref.h" 5 #include "chrome/browser/prefs/session_startup_pref.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/values.h" 9 #include "base/values.h"
10 #include "chrome/browser/net/url_fixer_upper.h" 10 #include "chrome/browser/net/url_fixer_upper.h"
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 DCHECK(profile); 125 DCHECK(profile);
126 return GetStartupPref(profile->GetPrefs()); 126 return GetStartupPref(profile->GetPrefs());
127 } 127 }
128 128
129 // static 129 // static
130 SessionStartupPref SessionStartupPref::GetStartupPref(PrefService* prefs) { 130 SessionStartupPref SessionStartupPref::GetStartupPref(PrefService* prefs) {
131 DCHECK(prefs); 131 DCHECK(prefs);
132 SessionStartupPref pref( 132 SessionStartupPref pref(
133 PrefValueToType(prefs->GetInteger(prefs::kRestoreOnStartup))); 133 PrefValueToType(prefs->GetInteger(prefs::kRestoreOnStartup)));
134 134
135 // Migrate from "Open the home page" to "Open the following URLs". If the user 135 // Migrate from "Open the home page" to "Open the following URLs". If the
136 // had the "Open the homepage" option selected, then we need to switch them to 136 // user had the "Open the home page" option selected, switch them to "Open
137 // "Open the following URLs" and set the list of URLs to a list containing 137 // the following URLs" and set the list of URLs to a one-item list containing
138 // just the user's homepage. 138 // their homepage. If the kRestoreOnStartup pref is blank, it could be a user
139 if (pref.type == SessionStartupPref::HOMEPAGE) { 139 // coming from Chrome 18 or lower, who had "open the homepage" selected
140 // (since that was the default) or it could be a user who originally
141 // installed Chrome 19 or higher. We distinguish between these cases using
142 // the kHomePageIsNewTabPage pref: A Chrome 18 user wanting to open a
143 // homepage other than the NTP on startup would have set
144 // kHomePageIsNewTabPage to false. If kHomePageIsNewTabPage is true, there is
145 // no need to do the migration; the new default behavior is to open the NTP.
146 if (pref.type == SessionStartupPref::HOMEPAGE ||
147 (!prefs->HasPrefPath(prefs::kRestoreOnStartup) &&
148 !prefs->GetBoolean(prefs::kHomePageIsNewTabPage))) {
Mattias Nissler (ping if slow) 2012/04/16 09:21:46 This is likely to break in case there is policy pr
140 prefs->SetInteger(prefs::kRestoreOnStartup, kPrefValueURLs); 149 prefs->SetInteger(prefs::kRestoreOnStartup, kPrefValueURLs);
141 pref.type = SessionStartupPref::URLS; 150 pref.type = SessionStartupPref::URLS;
142 SetNewURLList(prefs); 151 SetNewURLList(prefs);
152 } else if (!prefs->HasPrefPath(prefs::kRestoreOnStartup)) {
Mattias Nissler (ping if slow) 2012/04/16 09:21:46 Setting a pref to the default is bad. This breaks
153 // If we didn't do the migration, but the kRestoreOnStartup pref is blank,
154 // then set it explicitly to the default value, so that we won't do the
155 // migration the next time this function is called.
156 prefs->SetInteger(prefs::kRestoreOnStartup,
157 TypeToPrefValue(GetDefaultStartupType()));
143 } 158 }
144 159
145 // Always load the urls, even if the pref type isn't URLS. This way the 160 // Always load the urls, even if the pref type isn't URLS. This way the
146 // preferences panels can show the user their last choice. 161 // preferences panels can show the user their last choice.
147 const ListValue* url_list = prefs->GetList(prefs::kURLsToRestoreOnStartup); 162 const ListValue* url_list = prefs->GetList(prefs::kURLsToRestoreOnStartup);
148 URLListToPref(url_list, &pref); 163 URLListToPref(url_list, &pref);
149 164
150 return pref; 165 return pref;
151 } 166 }
152 167
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 CHECK(prefs_watcher->GetBackupForPref( 224 CHECK(prefs_watcher->GetBackupForPref(
210 prefs::kURLsToRestoreOnStartup)->GetAsList(&url_list)); 225 prefs::kURLsToRestoreOnStartup)->GetAsList(&url_list));
211 URLListToPref(url_list, &backup_pref); 226 URLListToPref(url_list, &backup_pref);
212 227
213 return backup_pref; 228 return backup_pref;
214 } 229 }
215 230
216 SessionStartupPref::SessionStartupPref(Type type) : type(type) {} 231 SessionStartupPref::SessionStartupPref(Type type) : type(type) {}
217 232
218 SessionStartupPref::~SessionStartupPref() {} 233 SessionStartupPref::~SessionStartupPref() {}
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/prefs/session_startup_pref_unittest.cc » ('j') | chrome/test/functional/protector.py » ('J')

Powered by Google App Engine
This is Rietveld 408576698