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

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

Issue 1302303002: Remove year+ old migration support of "session.urls_to_restore_on_startup". (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@pref_service_syncable_unittest
Patch Set: Created 5 years, 4 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
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/metrics/histogram.h"
10 #include "base/prefs/pref_service.h" 10 #include "base/prefs/pref_service.h"
11 #include "base/prefs/scoped_user_pref_update.h" 11 #include "base/prefs/scoped_user_pref_update.h"
12 #include "base/time/time.h" 12 #include "base/time/time.h"
13 #include "base/values.h" 13 #include "base/values.h"
14 #include "chrome/browser/profiles/profile.h" 14 #include "chrome/browser/profiles/profile.h"
15 #include "chrome/common/pref_names.h" 15 #include "chrome/common/pref_names.h"
16 #include "components/pref_registry/pref_registry_syncable.h" 16 #include "components/pref_registry/pref_registry_syncable.h"
17 #include "components/url_formatter/url_fixer.h" 17 #include "components/url_formatter/url_fixer.h"
18 18
19 namespace { 19 namespace {
20 20
21 enum StartupURLsMigrationMetrics { 21 enum StartupURLsMigrationMetrics {
gab 2015/08/24 21:48:45 rm this enum
sdefresne 2015/08/25 08:36:10 Done.
22 STARTUP_URLS_MIGRATION_METRICS_PERFORMED, 22 STARTUP_URLS_MIGRATION_METRICS_PERFORMED,
23 STARTUP_URLS_MIGRATION_METRICS_NOT_PRESENT, 23 STARTUP_URLS_MIGRATION_METRICS_NOT_PRESENT,
24 STARTUP_URLS_MIGRATION_METRICS_RESET, 24 STARTUP_URLS_MIGRATION_METRICS_RESET,
25 STARTUP_URLS_MIGRATION_METRICS_MAX, 25 STARTUP_URLS_MIGRATION_METRICS_MAX,
26 }; 26 };
27 27
28 // Converts a SessionStartupPref::Type to an integer written to prefs. 28 // Converts a SessionStartupPref::Type to an integer written to prefs.
29 int TypeToPrefValue(SessionStartupPref::Type type) { 29 int TypeToPrefValue(SessionStartupPref::Type type) {
30 switch (type) { 30 switch (type) {
31 case SessionStartupPref::LAST: return SessionStartupPref::kPrefValueLast; 31 case SessionStartupPref::LAST: return SessionStartupPref::kPrefValueLast;
(...skipping 27 matching lines...) Expand all
59 59
60 // static 60 // static
61 void SessionStartupPref::RegisterProfilePrefs( 61 void SessionStartupPref::RegisterProfilePrefs(
62 user_prefs::PrefRegistrySyncable* registry) { 62 user_prefs::PrefRegistrySyncable* registry) {
63 registry->RegisterIntegerPref( 63 registry->RegisterIntegerPref(
64 prefs::kRestoreOnStartup, 64 prefs::kRestoreOnStartup,
65 TypeToPrefValue(GetDefaultStartupType()), 65 TypeToPrefValue(GetDefaultStartupType()),
66 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF); 66 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF);
67 registry->RegisterListPref(prefs::kURLsToRestoreOnStartup, 67 registry->RegisterListPref(prefs::kURLsToRestoreOnStartup,
68 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF); 68 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF);
69 registry->RegisterListPref(prefs::kURLsToRestoreOnStartupOld);
70 registry->RegisterBooleanPref(prefs::kRestoreOnStartupMigrated, false); 69 registry->RegisterBooleanPref(prefs::kRestoreOnStartupMigrated, false);
71 registry->RegisterInt64Pref(prefs::kRestoreStartupURLsMigrationTime, false);
72 } 70 }
73 71
74 // static 72 // static
75 SessionStartupPref::Type SessionStartupPref::GetDefaultStartupType() { 73 SessionStartupPref::Type SessionStartupPref::GetDefaultStartupType() {
76 #if defined(OS_CHROMEOS) 74 #if defined(OS_CHROMEOS)
77 return SessionStartupPref::LAST; 75 return SessionStartupPref::LAST;
78 #else 76 #else
79 return SessionStartupPref::DEFAULT; 77 return SessionStartupPref::DEFAULT;
80 #endif 78 #endif
81 } 79 }
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 const base::ListValue* url_list = 129 const base::ListValue* url_list =
132 prefs->GetList(prefs::kURLsToRestoreOnStartup); 130 prefs->GetList(prefs::kURLsToRestoreOnStartup);
133 URLListToPref(url_list, &pref); 131 URLListToPref(url_list, &pref);
134 132
135 return pref; 133 return pref;
136 } 134 }
137 135
138 // static 136 // static
139 void SessionStartupPref::MigrateIfNecessary(PrefService* prefs) { 137 void SessionStartupPref::MigrateIfNecessary(PrefService* prefs) {
140 DCHECK(prefs); 138 DCHECK(prefs);
141
142 // Check if we need to migrate the old version of the startup URLs preference
143 // to the new name, and also send metrics about the migration.
144 StartupURLsMigrationMetrics metrics_result =
145 STARTUP_URLS_MIGRATION_METRICS_MAX;
146 const base::ListValue* old_startup_urls =
147 prefs->GetList(prefs::kURLsToRestoreOnStartupOld);
148 if (!prefs->GetUserPrefValue(prefs::kRestoreStartupURLsMigrationTime)) {
149 // Record the absence of the migration timestamp, this will get overwritten
150 // below if migration occurs now.
151 metrics_result = STARTUP_URLS_MIGRATION_METRICS_NOT_PRESENT;
152
153 // Seems like we never migrated, do it if necessary.
154 if (!prefs->GetUserPrefValue(prefs::kURLsToRestoreOnStartup)) {
155 if (old_startup_urls && !old_startup_urls->empty()) {
156 prefs->Set(prefs::kURLsToRestoreOnStartup, *old_startup_urls);
157 prefs->ClearPref(prefs::kURLsToRestoreOnStartupOld);
158 }
159 metrics_result = STARTUP_URLS_MIGRATION_METRICS_PERFORMED;
160 }
161
162 prefs->SetInt64(prefs::kRestoreStartupURLsMigrationTime,
163 base::Time::Now().ToInternalValue());
164 } else if (old_startup_urls && !old_startup_urls->empty()) {
165 // Migration needs to be reset.
166 prefs->ClearPref(prefs::kURLsToRestoreOnStartupOld);
167 base::Time last_migration_time = base::Time::FromInternalValue(
168 prefs->GetInt64(prefs::kRestoreStartupURLsMigrationTime));
169 base::Time now = base::Time::Now();
gab 2015/08/24 21:48:45 Cross-referencing with https://codereview.chromium
sdefresne 2015/08/25 08:36:10 Done.
170 prefs->SetInt64(prefs::kRestoreStartupURLsMigrationTime,
171 now.ToInternalValue());
172 if (now < last_migration_time)
173 last_migration_time = now;
174 UMA_HISTOGRAM_CUSTOM_TIMES("Settings.StartupURLsResetTime",
175 now - last_migration_time,
176 base::TimeDelta::FromDays(0),
177 base::TimeDelta::FromDays(7),
178 50);
179 metrics_result = STARTUP_URLS_MIGRATION_METRICS_RESET;
180 }
181
182 // Record a metric migration event if something interesting happened.
183 if (metrics_result != STARTUP_URLS_MIGRATION_METRICS_MAX) {
184 UMA_HISTOGRAM_ENUMERATION(
185 "Settings.StartupURLsMigration",
186 metrics_result,
187 STARTUP_URLS_MIGRATION_METRICS_MAX);
188 }
189
190 if (!prefs->GetBoolean(prefs::kRestoreOnStartupMigrated)) { 139 if (!prefs->GetBoolean(prefs::kRestoreOnStartupMigrated)) {
191 // Read existing values. 140 // Read existing values.
192 const base::Value* homepage_is_new_tab_page_value = 141 const base::Value* homepage_is_new_tab_page_value =
193 prefs->GetUserPrefValue(prefs::kHomePageIsNewTabPage); 142 prefs->GetUserPrefValue(prefs::kHomePageIsNewTabPage);
194 bool homepage_is_new_tab_page = true; 143 bool homepage_is_new_tab_page = true;
195 if (homepage_is_new_tab_page_value) { 144 if (homepage_is_new_tab_page_value) {
196 if (!homepage_is_new_tab_page_value->GetAsBoolean( 145 if (!homepage_is_new_tab_page_value->GetAsBoolean(
197 &homepage_is_new_tab_page)) 146 &homepage_is_new_tab_page))
198 NOTREACHED(); 147 NOTREACHED();
199 } 148 }
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
264 case kPrefValueLast: return SessionStartupPref::LAST; 213 case kPrefValueLast: return SessionStartupPref::LAST;
265 case kPrefValueURLs: return SessionStartupPref::URLS; 214 case kPrefValueURLs: return SessionStartupPref::URLS;
266 case kPrefValueHomePage: return SessionStartupPref::HOMEPAGE; 215 case kPrefValueHomePage: return SessionStartupPref::HOMEPAGE;
267 default: return SessionStartupPref::DEFAULT; 216 default: return SessionStartupPref::DEFAULT;
268 } 217 }
269 } 218 }
270 219
271 SessionStartupPref::SessionStartupPref(Type type) : type(type) {} 220 SessionStartupPref::SessionStartupPref(Type type) : type(type) {}
272 221
273 SessionStartupPref::~SessionStartupPref() {} 222 SessionStartupPref::~SessionStartupPref() {}
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698