Chromium Code Reviews| Index: chrome/browser/prefs/session_startup_pref.cc |
| diff --git a/chrome/browser/prefs/session_startup_pref.cc b/chrome/browser/prefs/session_startup_pref.cc |
| index 478790a157d1c44ab61dc8fc84c2fae754dba090..53c0c868f0364b10b107856e77c689694e0c660c 100644 |
| --- a/chrome/browser/prefs/session_startup_pref.cc |
| +++ b/chrome/browser/prefs/session_startup_pref.cc |
| @@ -6,7 +6,9 @@ |
| #include <string> |
| +#include "base/metrics/histogram.h" |
| #include "base/prefs/pref_service.h" |
| +#include "base/time/time.h" |
| #include "base/values.h" |
| #include "base/version.h" |
| #include "chrome/browser/prefs/scoped_user_pref_update.h" |
| @@ -21,6 +23,13 @@ |
| namespace { |
| +enum StartupURLsMigrationMetrics { |
| + STARTUP_URLS_MIGRATION_METRICS_PERFORMED, |
| + STARTUP_URLS_MIGRATION_METRICS_NOT_PRESENT, |
| + STARTUP_URLS_MIGRATION_METRICS_RESET, |
| + STARTUP_URLS_MIGRATION_METRICS_MAX, |
| +}; |
| + |
| // Converts a SessionStartupPref::Type to an integer written to prefs. |
| int TypeToPrefValue(SessionStartupPref::Type type) { |
| switch (type) { |
| @@ -62,10 +71,16 @@ void SessionStartupPref::RegisterProfilePrefs( |
| user_prefs::PrefRegistrySyncable::SYNCABLE_PREF); |
| registry->RegisterListPref(prefs::kURLsToRestoreOnStartup, |
| user_prefs::PrefRegistrySyncable::SYNCABLE_PREF); |
| + registry->RegisterListPref(prefs::kURLsToRestoreOnStartupOld, |
| + user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); |
| registry->RegisterBooleanPref( |
| prefs::kRestoreOnStartupMigrated, |
| false, |
| user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); |
| + registry->RegisterInt64Pref( |
| + prefs::kRestoreStartupURLsMigrated, |
| + false, |
| + user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); |
| } |
| // static |
| @@ -136,8 +151,55 @@ SessionStartupPref SessionStartupPref::GetStartupPref(PrefService* prefs) { |
| void SessionStartupPref::MigrateIfNecessary(PrefService* prefs) { |
| DCHECK(prefs); |
| + // Check if we need to migrate the old version of the startup URLs preference |
| + // to the new name, and also send metrics about the migration. |
| + const base::ListValue* old_startup_urls = |
| + prefs->GetList(prefs::kURLsToRestoreOnStartupOld); |
| + if (!prefs->GetUserPrefValue(prefs::kRestoreStartupURLsMigrated)) { |
| + // Record the absence of the migration timestamp, this will get overwritten |
| + // below if migration occurs now. |
| + StartupURLsMigrationMetrics metrics_result = |
| + STARTUP_URLS_MIGRATION_METRICS_NOT_PRESENT; |
| + |
| + // Seems like we never migrated, do it if necessary. |
| + if (!prefs->GetUserPrefValue(prefs::kURLsToRestoreOnStartup)) { |
| + if (old_startup_urls && !old_startup_urls->empty()) { |
|
Bernhard Bauer
2013/10/15 22:03:52
|old_startup_urls| is guaranteed not to be NULL.
robertshield
2013/10/16 01:23:27
That does not line up with my reading of PrefServi
Bernhard Bauer
2013/10/16 15:13:33
Well, it's guaranteed not to be NULL in the absenc
robertshield
2013/10/16 15:50:08
On line 308 (https://code.google.com/p/chromium/co
|
| + prefs->Set(prefs::kURLsToRestoreOnStartup, *old_startup_urls); |
| + prefs->Set(prefs::kURLsToRestoreOnStartupOld, base::ListValue()); |
|
Bernhard Bauer
2013/10/15 22:03:52
You can use prefs->ClearPref().
robertshield
2013/10/16 01:23:27
Done.
|
| + } |
| + metrics_result = STARTUP_URLS_MIGRATION_METRICS_PERFORMED; |
| + } |
| + |
| + UMA_HISTOGRAM_ENUMERATION( |
| + "Settings.StartupURLsMigration", |
| + metrics_result, |
| + STARTUP_URLS_MIGRATION_METRICS_MAX); |
| + |
| + prefs->SetInt64(prefs::kRestoreStartupURLsMigrated, |
| + base::Time::Now().ToInternalValue()); |
| + } else if (old_startup_urls && !old_startup_urls->empty()) { |
| + // Migration needs to be reset. |
| + prefs->Set(prefs::kURLsToRestoreOnStartupOld, base::ListValue()); |
|
Bernhard Bauer
2013/10/15 22:03:52
It seems like you are doing a lot of similar thing
robertshield
2013/10/16 01:23:27
Played around with the logic a bit. I extracted th
|
| + base::Time last_migration_time = base::Time::FromInternalValue( |
| + prefs->GetInt64(prefs::kRestoreStartupURLsMigrated)); |
| + base::Time now = base::Time::Now(); |
| + prefs->SetInt64(prefs::kRestoreStartupURLsMigrated, now.ToInternalValue()); |
| + DCHECK(now > last_migration_time); |
|
Bernhard Bauer
2013/10/15 22:03:52
Nit: DCHECK_GT(now, last_migration_time) gives nic
robertshield
2013/10/16 01:23:27
Sadly, DCHECK_GT doesn't work with base::Time inst
|
| + if (now < last_migration_time) |
|
Bernhard Bauer
2013/10/15 22:03:52
This looks like you're handling a DCHECK failure?
robertshield
2013/10/16 01:23:27
Removing the DCHECK, there's no reason for it to b
|
| + last_migration_time = now; |
| + HISTOGRAM_CUSTOM_TIMES("Settings.StartupURLsResetTime", |
| + now - last_migration_time, |
| + base::TimeDelta::FromDays(0), |
| + base::TimeDelta::FromDays(7), |
| + 50); |
| + UMA_HISTOGRAM_ENUMERATION( |
| + "Settings.StartupURLsMigration", |
| + STARTUP_URLS_MIGRATION_METRICS_RESET, |
| + STARTUP_URLS_MIGRATION_METRICS_MAX); |
| + } |
| + |
| if (!prefs->GetBoolean(prefs::kRestoreOnStartupMigrated)) { |
| - // Read existing values |
| + // Read existing values. |
| const base::Value* homepage_is_new_tab_page_value = |
| prefs->GetUserPrefValue(prefs::kHomePageIsNewTabPage); |
| bool homepage_is_new_tab_page = true; |