+void RecordAppListDiscoverability(PrefService* local_state,
+ bool is_startup_check) {
+ // Since this task may be delayed, ensure it does not interfere with shutdown
+ // when they unluckily coincide.
+ if (browser_shutdown::IsTryingToQuit())
+ return;
+
+ int64 enable_time_value = local_state->GetInt64(prefs::kAppListEnableTime);
+ if (enable_time_value == 0)
+ return; // Already recorded or never enabled.
+
+ base::Time app_list_enable_time =
+ base::Time::FromInternalValue(enable_time_value);
+ if (is_startup_check) {
+ // When checking at startup, only clear and record the "timeout" case,
+ // otherwise wait for a timeout.
+ base::TimeDelta time_remaining =
+ app_list_enable_time +
+ base::TimeDelta::FromMinutes(kDiscoverabilityTimeoutMinutes) -
+ base::Time::Now();
+ if (time_remaining > base::TimeDelta()) {
+ base::MessageLoop::current()->PostDelayedTask(
+ FROM_HERE,
+ base::Bind(&RecordAppListDiscoverability,
+ base::Unretained(local_state),
+ false),
+ time_remaining);
+ return;
+ }
+ }
+
+ local_state->SetInt64(prefs::kAppListEnableTime, 0);
+
+ AppListService::AppListEnableSource enable_source =
+ static_cast<AppListService::AppListEnableSource>(
+ local_state->GetInteger(prefs::kAppListEnableMethod));
+ if (enable_source == AppListService::ENABLE_FOR_APP_INSTALL) {
+ base::TimeDelta time_taken = base::Time::Now() - app_list_enable_time;
+ // This means the user "discovered" the app launcher naturally, after it was
+ // enabled on the first app install. Record how long it took to discover.
+ // Note that the last bucket is essentially "not discovered": subtract 1
+ // minute to account for clock inaccuracy.
+ UMA_HISTOGRAM_CUSTOM_TIMES(
+ "Apps.AppListTimeToDiscover",
+ time_taken,
+ base::TimeDelta::FromSeconds(1),
+ base::TimeDelta::FromMinutes(kDiscoverabilityTimeoutMinutes - 1),
+ 10 /* bucket_count */);
+ }
+ UMA_HISTOGRAM_ENUMERATION("Apps.AppListHowEnabled",
+ enable_source,
+ AppListService::ENABLE_NUM_ENABLE_SOURCES);
+}
+