| 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 29c6f474b35710d3ccda94805fe2946d870b374c..657d24dd4563c42ea8d0073ae29feeda02416a23 100644
|
| --- a/chrome/browser/prefs/session_startup_pref.cc
|
| +++ b/chrome/browser/prefs/session_startup_pref.cc
|
| @@ -35,10 +35,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)) {
|
| + base::ListValue new_url_pref_list;
|
| + base::StringValue* home_page =
|
| + new base::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) {
|
| @@ -61,6 +64,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
|
| @@ -120,19 +126,12 @@ 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);
|
| - }
|
| -
|
| // Always load the urls, even if the pref type isn't URLS. This way the
|
| // preferences panels can show the user their last choice.
|
| const ListValue* url_list = prefs->GetList(prefs::kURLsToRestoreOnStartup);
|
| @@ -142,6 +141,48 @@ SessionStartupPref SessionStartupPref::GetStartupPref(PrefService* prefs) {
|
| }
|
|
|
| // static
|
| +void SessionStartupPref::MigrateIfNecessary(PrefService* prefs) {
|
| + DCHECK(prefs);
|
| +
|
| + if (!prefs->GetBoolean(prefs::kRestoreOnStartupMigrated)) {
|
| + // Read existing values
|
| + const base::Value* homepage_is_new_tab_page_value =
|
| + prefs->GetUserPrefValue(prefs::kHomePageIsNewTabPage);
|
| + bool homepage_is_new_tab_page = true;
|
| + if (homepage_is_new_tab_page_value)
|
| + homepage_is_new_tab_page_value->GetAsBoolean(&homepage_is_new_tab_page);
|
| +
|
| + const base::Value* restore_on_startup_value =
|
| + prefs->GetUserPrefValue(prefs::kRestoreOnStartup);
|
| + int restore_on_startup = -1;
|
| + if (restore_on_startup_value)
|
| + restore_on_startup_value->GetAsInteger(&restore_on_startup);
|
| +
|
| + // If restore_on_startup has the deprecated value kPrefValueHomePage,
|
| + // migrate it to open the homepage on startup. If 'homepage is NTP' is set,
|
| + // that means just opening the NTP. If not, it means opening a one-item URL
|
| + // list containing the homepage.
|
| + if (restore_on_startup == kPrefValueHomePage) {
|
| + if (homepage_is_new_tab_page) {
|
| + prefs->SetInteger(prefs::kRestoreOnStartup, kPrefValueNewTab);
|
| + } else {
|
| + prefs->SetInteger(prefs::kRestoreOnStartup, kPrefValueURLs);
|
| + SetNewURLList(prefs);
|
| + }
|
| + } else if (!restore_on_startup_value && !homepage_is_new_tab_page) {
|
| + // kRestoreOnStartup was never set by the user, but the homepage was set.
|
| + // Migrate to the list of URLs. (If restore_on_startup was never set,
|
| + // and homepage_is_new_tab_page is true, no action is needed. The new
|
| + // default value is "open the new tab page" which is what we want.)
|
| + 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 =
|
|
|