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

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: Now with sync support. 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/metrics/histogram.h"
9 #include "base/prefs/pref_service.h" 10 #include "base/prefs/pref_service.h"
11 #include "base/time/time.h"
10 #include "base/values.h" 12 #include "base/values.h"
11 #include "base/version.h" 13 #include "base/version.h"
12 #include "chrome/browser/prefs/scoped_user_pref_update.h" 14 #include "chrome/browser/prefs/scoped_user_pref_update.h"
13 #include "chrome/browser/profiles/profile.h" 15 #include "chrome/browser/profiles/profile.h"
14 #include "chrome/common/net/url_fixer_upper.h" 16 #include "chrome/common/net/url_fixer_upper.h"
15 #include "chrome/common/pref_names.h" 17 #include "chrome/common/pref_names.h"
16 #include "components/user_prefs/pref_registry_syncable.h" 18 #include "components/user_prefs/pref_registry_syncable.h"
17 19
18 #if defined(OS_MACOSX) 20 #if defined(OS_MACOSX)
19 #include "chrome/browser/ui/cocoa/window_restore_utils.h" 21 #include "chrome/browser/ui/cocoa/window_restore_utils.h"
20 #endif 22 #endif
21 23
22 namespace { 24 namespace {
23 25
26 enum StartupURLsMigrationMetrics {
27 STARTUP_URLS_MIGRATION_METRICS_STARTED,
28 STARTUP_URLS_MIGRATION_METRICS_DELETED,
29 STARTUP_URLS_MIGRATION_METRICS_RESET,
30 STARTUP_URLS_MIGRATION_METRICS_MAX,
31 };
32
24 // Converts a SessionStartupPref::Type to an integer written to prefs. 33 // Converts a SessionStartupPref::Type to an integer written to prefs.
25 int TypeToPrefValue(SessionStartupPref::Type type) { 34 int TypeToPrefValue(SessionStartupPref::Type type) {
26 switch (type) { 35 switch (type) {
27 case SessionStartupPref::LAST: return SessionStartupPref::kPrefValueLast; 36 case SessionStartupPref::LAST: return SessionStartupPref::kPrefValueLast;
28 case SessionStartupPref::URLS: return SessionStartupPref::kPrefValueURLs; 37 case SessionStartupPref::URLS: return SessionStartupPref::kPrefValueURLs;
29 default: return SessionStartupPref::kPrefValueNewTab; 38 default: return SessionStartupPref::kPrefValueNewTab;
30 } 39 }
31 } 40 }
32 41
33 void SetNewURLList(PrefService* prefs) { 42 void SetNewURLList(PrefService* prefs) {
(...skipping 21 matching lines...) Expand all
55 64
56 // static 65 // static
57 void SessionStartupPref::RegisterProfilePrefs( 66 void SessionStartupPref::RegisterProfilePrefs(
58 user_prefs::PrefRegistrySyncable* registry) { 67 user_prefs::PrefRegistrySyncable* registry) {
59 registry->RegisterIntegerPref( 68 registry->RegisterIntegerPref(
60 prefs::kRestoreOnStartup, 69 prefs::kRestoreOnStartup,
61 TypeToPrefValue(GetDefaultStartupType()), 70 TypeToPrefValue(GetDefaultStartupType()),
62 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF); 71 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF);
63 registry->RegisterListPref(prefs::kURLsToRestoreOnStartup, 72 registry->RegisterListPref(prefs::kURLsToRestoreOnStartup,
64 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF); 73 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF);
74 registry->RegisterListPref(prefs::kURLsToRestoreOnStartupOld,
75 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
65 registry->RegisterBooleanPref( 76 registry->RegisterBooleanPref(
66 prefs::kRestoreOnStartupMigrated, 77 prefs::kRestoreOnStartupMigrated,
67 false, 78 false,
68 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); 79 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
80 registry->RegisterDoublePref(
81 prefs::kRestoreStartupURLsMigrated,
82 false,
83 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
69 } 84 }
70 85
71 // static 86 // static
72 SessionStartupPref::Type SessionStartupPref::GetDefaultStartupType() { 87 SessionStartupPref::Type SessionStartupPref::GetDefaultStartupType() {
73 #if defined(OS_CHROMEOS) 88 #if defined(OS_CHROMEOS)
74 return SessionStartupPref::LAST; 89 return SessionStartupPref::LAST;
75 #else 90 #else
76 return SessionStartupPref::DEFAULT; 91 return SessionStartupPref::DEFAULT;
77 #endif 92 #endif
78 } 93 }
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 const ListValue* url_list = prefs->GetList(prefs::kURLsToRestoreOnStartup); 144 const ListValue* url_list = prefs->GetList(prefs::kURLsToRestoreOnStartup);
130 URLListToPref(url_list, &pref); 145 URLListToPref(url_list, &pref);
131 146
132 return pref; 147 return pref;
133 } 148 }
134 149
135 // static 150 // static
136 void SessionStartupPref::MigrateIfNecessary(PrefService* prefs) { 151 void SessionStartupPref::MigrateIfNecessary(PrefService* prefs) {
137 DCHECK(prefs); 152 DCHECK(prefs);
138 153
154 // Check if we need to migrate the old version of the startup URLs preference
155 // to the new name, and also send metrics about the migration.
156 const base::ListValue* old_startup_urls =
157 prefs->GetList(prefs::kURLsToRestoreOnStartupOld);
158 if (!prefs->GetUserPrefValue(prefs::kRestoreStartupURLsMigrated)) {
159 // Seems like we never migrated, do it if necessary.
160 if (!prefs->GetUserPrefValue(prefs::kURLsToRestoreOnStartup)) {
161 if (old_startup_urls && old_startup_urls->GetSize() > 0) {
162 prefs->Set(prefs::kURLsToRestoreOnStartup, *old_startup_urls);
163 prefs->Set(prefs::kURLsToRestoreOnStartupOld, base::ListValue());
164 }
165 UMA_HISTOGRAM_ENUMERATION(
166 "Settings.StartupURLsMigration",
167 STARTUP_URLS_MIGRATION_METRICS_STARTED,
168 STARTUP_URLS_MIGRATION_METRICS_MAX);
169 } else {
170 // We migrated but the migration data got deleted somehow.
171 UMA_HISTOGRAM_ENUMERATION(
172 "Settings.StartupURLsMigration",
173 STARTUP_URLS_MIGRATION_METRICS_DELETED,
174 STARTUP_URLS_MIGRATION_METRICS_MAX);
175 }
176 prefs->SetDouble(prefs::kRestoreStartupURLsMigrated,
177 base::Time::Now().ToDoubleT());
178 } else if (old_startup_urls && old_startup_urls->GetSize() > 0) {
179 // Migration needs to be reset.
180 prefs->Set(prefs::kURLsToRestoreOnStartupOld, base::ListValue());
181 base::Time last_migration_time = base::Time::FromDoubleT(prefs->GetDouble(
182 prefs::kRestoreStartupURLsMigrated));
183 base::Time now = base::Time::Now();
184 prefs->SetDouble(prefs::kRestoreStartupURLsMigrated, now.ToDoubleT());
185 DCHECK(now > last_migration_time);
186 HISTOGRAM_CUSTOM_TIMES("Settings.StartupURLsResetTime",
187 now - last_migration_time,
robertshield 2013/10/04 15:16:15 in theory, this could be negative. What's the effe
MAD 2013/10/04 19:31:22 I just tried it and it would go in the 0 bucket (i
188 base::TimeDelta::FromDays(0),
189 base::TimeDelta::FromDays(7),
190 50);
191 UMA_HISTOGRAM_ENUMERATION(
192 "Settings.StartupURLsMigration",
193 STARTUP_URLS_MIGRATION_METRICS_RESET,
194 STARTUP_URLS_MIGRATION_METRICS_MAX);
195 }
196
139 if (!prefs->GetBoolean(prefs::kRestoreOnStartupMigrated)) { 197 if (!prefs->GetBoolean(prefs::kRestoreOnStartupMigrated)) {
140 // Read existing values 198 // Read existing values.
141 const base::Value* homepage_is_new_tab_page_value = 199 const base::Value* homepage_is_new_tab_page_value =
142 prefs->GetUserPrefValue(prefs::kHomePageIsNewTabPage); 200 prefs->GetUserPrefValue(prefs::kHomePageIsNewTabPage);
143 bool homepage_is_new_tab_page = true; 201 bool homepage_is_new_tab_page = true;
144 if (homepage_is_new_tab_page_value) { 202 if (homepage_is_new_tab_page_value) {
145 if (!homepage_is_new_tab_page_value->GetAsBoolean( 203 if (!homepage_is_new_tab_page_value->GetAsBoolean(
146 &homepage_is_new_tab_page)) 204 &homepage_is_new_tab_page))
147 NOTREACHED(); 205 NOTREACHED();
148 } 206 }
149 207
150 const base::Value* restore_on_startup_value = 208 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; 290 case kPrefValueLast: return SessionStartupPref::LAST;
233 case kPrefValueURLs: return SessionStartupPref::URLS; 291 case kPrefValueURLs: return SessionStartupPref::URLS;
234 case kPrefValueHomePage: return SessionStartupPref::HOMEPAGE; 292 case kPrefValueHomePage: return SessionStartupPref::HOMEPAGE;
235 default: return SessionStartupPref::DEFAULT; 293 default: return SessionStartupPref::DEFAULT;
236 } 294 }
237 } 295 }
238 296
239 SessionStartupPref::SessionStartupPref(Type type) : type(type) {} 297 SessionStartupPref::SessionStartupPref(Type type) : type(type) {}
240 298
241 SessionStartupPref::~SessionStartupPref() {} 299 SessionStartupPref::~SessionStartupPref() {}
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698