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

Side by Side Diff: chrome/browser/prefs/session_startup_pref.cc

Issue 24930003: Migrate startup URLs pref. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 2 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/prefs/pref_service.h" 9 #include "base/prefs/pref_service.h"
10 #include "base/time/time.h"
10 #include "base/values.h" 11 #include "base/values.h"
11 #include "base/version.h" 12 #include "base/version.h"
12 #include "chrome/browser/prefs/scoped_user_pref_update.h" 13 #include "chrome/browser/prefs/scoped_user_pref_update.h"
13 #include "chrome/browser/profiles/profile.h" 14 #include "chrome/browser/profiles/profile.h"
14 #include "chrome/common/net/url_fixer_upper.h" 15 #include "chrome/common/net/url_fixer_upper.h"
15 #include "chrome/common/pref_names.h" 16 #include "chrome/common/pref_names.h"
16 #include "components/user_prefs/pref_registry_syncable.h" 17 #include "components/user_prefs/pref_registry_syncable.h"
17 18
18 #if defined(OS_MACOSX) 19 #if defined(OS_MACOSX)
19 #include "chrome/browser/ui/cocoa/window_restore_utils.h" 20 #include "chrome/browser/ui/cocoa/window_restore_utils.h"
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 56
56 // static 57 // static
57 void SessionStartupPref::RegisterProfilePrefs( 58 void SessionStartupPref::RegisterProfilePrefs(
58 user_prefs::PrefRegistrySyncable* registry) { 59 user_prefs::PrefRegistrySyncable* registry) {
59 registry->RegisterIntegerPref( 60 registry->RegisterIntegerPref(
60 prefs::kRestoreOnStartup, 61 prefs::kRestoreOnStartup,
61 TypeToPrefValue(GetDefaultStartupType()), 62 TypeToPrefValue(GetDefaultStartupType()),
62 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF); 63 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF);
63 registry->RegisterListPref(prefs::kURLsToRestoreOnStartup, 64 registry->RegisterListPref(prefs::kURLsToRestoreOnStartup,
64 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF); 65 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF);
66 registry->RegisterListPref(prefs::kURLsToRestoreOnStartupOld,
67 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
65 registry->RegisterBooleanPref( 68 registry->RegisterBooleanPref(
66 prefs::kRestoreOnStartupMigrated, 69 prefs::kRestoreOnStartupMigrated,
67 false, 70 false,
68 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); 71 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
72 registry->RegisterDoublePref(
73 prefs::kRestoreStartupURLsMigrated,
74 false,
75 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
69 } 76 }
70 77
71 // static 78 // static
72 SessionStartupPref::Type SessionStartupPref::GetDefaultStartupType() { 79 SessionStartupPref::Type SessionStartupPref::GetDefaultStartupType() {
73 #if defined(OS_CHROMEOS) 80 #if defined(OS_CHROMEOS)
74 return SessionStartupPref::LAST; 81 return SessionStartupPref::LAST;
75 #else 82 #else
76 return SessionStartupPref::DEFAULT; 83 return SessionStartupPref::DEFAULT;
77 #endif 84 #endif
78 } 85 }
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 const ListValue* url_list = prefs->GetList(prefs::kURLsToRestoreOnStartup); 136 const ListValue* url_list = prefs->GetList(prefs::kURLsToRestoreOnStartup);
130 URLListToPref(url_list, &pref); 137 URLListToPref(url_list, &pref);
131 138
132 return pref; 139 return pref;
133 } 140 }
134 141
135 // static 142 // static
136 void SessionStartupPref::MigrateIfNecessary(PrefService* prefs) { 143 void SessionStartupPref::MigrateIfNecessary(PrefService* prefs) {
137 DCHECK(prefs); 144 DCHECK(prefs);
138 145
146 if (!prefs->GetUserPrefValue(prefs::kRestoreStartupURLsMigrated)) {
147 // Read existing values.
148 const base::Value* startup_urls =
149 prefs->GetUserPrefValue(prefs::kURLsToRestoreOnStartupOld);
150 if (startup_urls)
151 prefs->Set(prefs::kURLsToRestoreOnStartup, *startup_urls);
152 }
153
139 if (!prefs->GetBoolean(prefs::kRestoreOnStartupMigrated)) { 154 if (!prefs->GetBoolean(prefs::kRestoreOnStartupMigrated)) {
140 // Read existing values 155 // Read existing values.
141 const base::Value* homepage_is_new_tab_page_value = 156 const base::Value* homepage_is_new_tab_page_value =
142 prefs->GetUserPrefValue(prefs::kHomePageIsNewTabPage); 157 prefs->GetUserPrefValue(prefs::kHomePageIsNewTabPage);
143 bool homepage_is_new_tab_page = true; 158 bool homepage_is_new_tab_page = true;
144 if (homepage_is_new_tab_page_value) { 159 if (homepage_is_new_tab_page_value) {
145 if (!homepage_is_new_tab_page_value->GetAsBoolean( 160 if (!homepage_is_new_tab_page_value->GetAsBoolean(
146 &homepage_is_new_tab_page)) 161 &homepage_is_new_tab_page))
147 NOTREACHED(); 162 NOTREACHED();
148 } 163 }
149 164
150 const base::Value* restore_on_startup_value = 165 const base::Value* restore_on_startup_value =
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
232 case kPrefValueLast: return SessionStartupPref::LAST; 247 case kPrefValueLast: return SessionStartupPref::LAST;
233 case kPrefValueURLs: return SessionStartupPref::URLS; 248 case kPrefValueURLs: return SessionStartupPref::URLS;
234 case kPrefValueHomePage: return SessionStartupPref::HOMEPAGE; 249 case kPrefValueHomePage: return SessionStartupPref::HOMEPAGE;
235 default: return SessionStartupPref::DEFAULT; 250 default: return SessionStartupPref::DEFAULT;
236 } 251 }
237 } 252 }
238 253
239 SessionStartupPref::SessionStartupPref(Type type) : type(type) {} 254 SessionStartupPref::SessionStartupPref(Type type) : type(type) {}
240 255
241 SessionStartupPref::~SessionStartupPref() {} 256 SessionStartupPref::~SessionStartupPref() {}
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698