OLD | NEW |
---|---|
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 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
63 | 63 |
64 } // namespace | 64 } // namespace |
65 | 65 |
66 // static | 66 // static |
67 void SessionStartupPref::RegisterUserPrefs(PrefService* prefs) { | 67 void SessionStartupPref::RegisterUserPrefs(PrefService* prefs) { |
68 prefs->RegisterIntegerPref(prefs::kRestoreOnStartup, | 68 prefs->RegisterIntegerPref(prefs::kRestoreOnStartup, |
69 TypeToPrefValue(GetDefaultStartupType()), | 69 TypeToPrefValue(GetDefaultStartupType()), |
70 PrefService::SYNCABLE_PREF); | 70 PrefService::SYNCABLE_PREF); |
71 prefs->RegisterListPref(prefs::kURLsToRestoreOnStartup, | 71 prefs->RegisterListPref(prefs::kURLsToRestoreOnStartup, |
72 PrefService::SYNCABLE_PREF); | 72 PrefService::SYNCABLE_PREF); |
73 prefs->RegisterBooleanPref(prefs::kRestoreOnStartupMigrated, | |
74 false, | |
75 PrefService::UNSYNCABLE_PREF); | |
73 } | 76 } |
74 | 77 |
75 // static | 78 // static |
76 SessionStartupPref::Type SessionStartupPref::GetDefaultStartupType() { | 79 SessionStartupPref::Type SessionStartupPref::GetDefaultStartupType() { |
77 #if defined(OS_CHROMEOS) | 80 #if defined(OS_CHROMEOS) |
78 SessionStartupPref::Type type = SessionStartupPref::LAST; | 81 SessionStartupPref::Type type = SessionStartupPref::LAST; |
79 #else | 82 #else |
80 SessionStartupPref::Type type = SessionStartupPref::DEFAULT; | 83 SessionStartupPref::Type type = SessionStartupPref::DEFAULT; |
81 #endif | 84 #endif |
82 | 85 |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
125 DCHECK(profile); | 128 DCHECK(profile); |
126 return GetStartupPref(profile->GetPrefs()); | 129 return GetStartupPref(profile->GetPrefs()); |
127 } | 130 } |
128 | 131 |
129 // static | 132 // static |
130 SessionStartupPref SessionStartupPref::GetStartupPref(PrefService* prefs) { | 133 SessionStartupPref SessionStartupPref::GetStartupPref(PrefService* prefs) { |
131 DCHECK(prefs); | 134 DCHECK(prefs); |
132 SessionStartupPref pref( | 135 SessionStartupPref pref( |
133 PrefValueToType(prefs->GetInteger(prefs::kRestoreOnStartup))); | 136 PrefValueToType(prefs->GetInteger(prefs::kRestoreOnStartup))); |
134 | 137 |
135 // Migrate from "Open the home page" to "Open the following URLs". If the user | 138 if (!prefs->GetBoolean(prefs::kRestoreOnStartupMigrated)) { |
Ivan Korotkov
2012/04/17 09:27:51
Could you move the migration to a separate functio
Tyler Breisacher (Chromium)
2012/04/17 19:54:33
Done.
| |
136 // had the "Open the homepage" option selected, then we need to switch them to | 139 // Migrate from "Open the home page" to "Open the following URLs". If the |
137 // "Open the following URLs" and set the list of URLs to a list containing | 140 // user had the "Open the home page" option selected, switch them to "Open |
138 // just the user's homepage. | 141 // the following URLs" and set the list of URLs to a one-item list |
139 if (pref.type == SessionStartupPref::HOMEPAGE) { | 142 // containing their homepage. |
140 prefs->SetInteger(prefs::kRestoreOnStartup, kPrefValueURLs); | 143 if (pref.type == SessionStartupPref::HOMEPAGE || |
141 pref.type = SessionStartupPref::URLS; | 144 (!prefs->HasPrefPath(prefs::kRestoreOnStartup) && |
142 SetNewURLList(prefs); | 145 !prefs->GetBoolean(prefs::kHomePageIsNewTabPage))) { |
146 | |
147 if (prefs->GetBoolean(prefs::kHomePageIsNewTabPage)) { | |
Mattias Nissler (ping if slow)
2012/04/17 09:54:48
These values may still come from policy, in which
Tyler Breisacher (Chromium)
2012/04/17 19:54:33
Done.
| |
148 prefs->SetInteger(prefs::kRestoreOnStartup, kPrefValueNewTab); | |
149 pref.type = SessionStartupPref::DEFAULT; | |
150 } else { | |
151 prefs->SetInteger(prefs::kRestoreOnStartup, kPrefValueURLs); | |
152 pref.type = SessionStartupPref::URLS; | |
153 SetNewURLList(prefs); | |
154 } | |
155 } | |
156 | |
157 prefs->SetBoolean(prefs::kRestoreOnStartupMigrated, true); | |
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 Loading... | |
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() {} |
OLD | NEW |