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

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: Rename remaining old pref value. 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_PERFORMED,
28 STARTUP_URLS_MIGRATION_METRICS_NOT_PRESENT,
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->RegisterInt64Pref(
81 prefs::kRestoreStartupURLsMigrationTime,
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 StartupURLsMigrationMetrics metrics_result =
157 STARTUP_URLS_MIGRATION_METRICS_MAX;
158 const base::ListValue* old_startup_urls =
159 prefs->GetList(prefs::kURLsToRestoreOnStartupOld);
160 if (!prefs->GetUserPrefValue(prefs::kRestoreStartupURLsMigrationTime)) {
161 // Record the absence of the migration timestamp, this will get overwritten
162 // below if migration occurs now.
163 metrics_result = STARTUP_URLS_MIGRATION_METRICS_NOT_PRESENT;
164
165 // Seems like we never migrated, do it if necessary.
166 if (!prefs->GetUserPrefValue(prefs::kURLsToRestoreOnStartup)) {
167 if (old_startup_urls && !old_startup_urls->empty()) {
168 prefs->Set(prefs::kURLsToRestoreOnStartup, *old_startup_urls);
169 prefs->ClearPref(prefs::kURLsToRestoreOnStartupOld);
170 }
171 metrics_result = STARTUP_URLS_MIGRATION_METRICS_PERFORMED;
172 }
173
174 prefs->SetInt64(prefs::kRestoreStartupURLsMigrationTime,
175 base::Time::Now().ToInternalValue());
176 } else if (old_startup_urls && !old_startup_urls->empty()) {
177 // Migration needs to be reset.
178 prefs->ClearPref(prefs::kURLsToRestoreOnStartupOld);
179 base::Time last_migration_time = base::Time::FromInternalValue(
180 prefs->GetInt64(prefs::kRestoreStartupURLsMigrationTime));
181 base::Time now = base::Time::Now();
182 prefs->SetInt64(prefs::kRestoreStartupURLsMigrationTime,
183 now.ToInternalValue());
184 if (now < last_migration_time)
185 last_migration_time = now;
186 HISTOGRAM_CUSTOM_TIMES("Settings.StartupURLsResetTime",
187 now - last_migration_time,
188 base::TimeDelta::FromDays(0),
189 base::TimeDelta::FromDays(7),
190 50);
191 metrics_result = STARTUP_URLS_MIGRATION_METRICS_RESET;
192 }
193
194 // Record a metric migration event if something interesting happened.
195 if (metrics_result != STARTUP_URLS_MIGRATION_METRICS_MAX) {
196 UMA_HISTOGRAM_ENUMERATION(
197 "Settings.StartupURLsMigration",
198 metrics_result,
199 STARTUP_URLS_MIGRATION_METRICS_MAX);
200 }
201
139 if (!prefs->GetBoolean(prefs::kRestoreOnStartupMigrated)) { 202 if (!prefs->GetBoolean(prefs::kRestoreOnStartupMigrated)) {
140 // Read existing values 203 // Read existing values.
141 const base::Value* homepage_is_new_tab_page_value = 204 const base::Value* homepage_is_new_tab_page_value =
142 prefs->GetUserPrefValue(prefs::kHomePageIsNewTabPage); 205 prefs->GetUserPrefValue(prefs::kHomePageIsNewTabPage);
143 bool homepage_is_new_tab_page = true; 206 bool homepage_is_new_tab_page = true;
144 if (homepage_is_new_tab_page_value) { 207 if (homepage_is_new_tab_page_value) {
145 if (!homepage_is_new_tab_page_value->GetAsBoolean( 208 if (!homepage_is_new_tab_page_value->GetAsBoolean(
146 &homepage_is_new_tab_page)) 209 &homepage_is_new_tab_page))
147 NOTREACHED(); 210 NOTREACHED();
148 } 211 }
149 212
150 const base::Value* restore_on_startup_value = 213 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; 295 case kPrefValueLast: return SessionStartupPref::LAST;
233 case kPrefValueURLs: return SessionStartupPref::URLS; 296 case kPrefValueURLs: return SessionStartupPref::URLS;
234 case kPrefValueHomePage: return SessionStartupPref::HOMEPAGE; 297 case kPrefValueHomePage: return SessionStartupPref::HOMEPAGE;
235 default: return SessionStartupPref::DEFAULT; 298 default: return SessionStartupPref::DEFAULT;
236 } 299 }
237 } 300 }
238 301
239 SessionStartupPref::SessionStartupPref(Type type) : type(type) {} 302 SessionStartupPref::SessionStartupPref(Type type) : type(type) {}
240 303
241 SessionStartupPref::~SessionStartupPref() {} 304 SessionStartupPref::~SessionStartupPref() {}
OLDNEW
« no previous file with comments | « chrome/browser/prefs/pref_model_associator.cc ('k') | chrome/browser/profile_resetter/profile_resetter_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698