Commit b41fa5c4 authored by Michael Giuffrida's avatar Michael Giuffrida Committed by Commit Bot

Move TabStatsTracker prefs out of //component/metrics

Tab metrics prefs should be registered by Chrome. Currently they live
in the metrics component itself, which isn't Chrome-specific.

The other prefs in the metrics component are related to metrics
collecting/uploading. Prefs needed for tracking arbitrary features via
metrics should be colocated with the classes that track them.

This change also ensures we don't register these prefs on Android,
where they aren't used.

Bug: 720131
Change-Id: Ibaca7241b4dc2d62a8c631fe15a7774cd6fe474c
Reviewed-on: https://chromium-review.googlesource.com/760402
Commit-Queue: Michael Giuffrida <michaelpg@chromium.org>
Reviewed-by: default avatarSébastien Marchand <sebmarchand@chromium.org>
Reviewed-by: default avatarBernhard Bauer <bauerb@chromium.org>
Reviewed-by: default avatarAlexei Svitkine <asvitkine@chromium.org>
Cr-Commit-Position: refs/heads/master@{#516095}
parent 2292183b
......@@ -9,7 +9,7 @@
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_list.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "components/metrics/metrics_pref_names.h"
#include "chrome/common/pref_names.h"
#include "components/prefs/pref_service.h"
namespace metrics {
......
......@@ -4,7 +4,7 @@
#include "chrome/browser/metrics/tab_stats_data_store.h"
#include "components/metrics/metrics_service.h"
#include "chrome/browser/metrics/tab_stats_tracker.h"
#include "components/prefs/pref_registry_simple.h"
#include "components/prefs/testing_pref_service.h"
#include "testing/gtest/include/gtest/gtest.h"
......@@ -25,7 +25,7 @@ TEST_F(TabStatsDataStoreTest, TabStatsGetsReloadedFromLocalState) {
// As the TabStatsTracker constructor restores its state from the pref service
// the maximums should be restored.
TestingPrefServiceSimple pref_service;
MetricsService::RegisterPrefs(pref_service.registry());
TabStatsTracker::RegisterPrefs(pref_service.registry());
std::unique_ptr<TabStatsDataStore> data_store(
std::make_unique<TabStatsDataStore>(&pref_service));
size_t expected_tab_count = 12;
......
......@@ -13,7 +13,9 @@
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_list.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "components/metrics/metrics_pref_names.h"
#include "chrome/common/pref_names.h"
#include "components/metrics/daily_event.h"
#include "components/prefs/pref_registry_simple.h"
#include "components/prefs/pref_service.h"
namespace metrics {
......@@ -104,6 +106,13 @@ TabStatsTracker* TabStatsTracker::GetInstance() {
return g_instance;
}
void TabStatsTracker::RegisterPrefs(PrefRegistrySimple* registry) {
registry->RegisterIntegerPref(prefs::kTabStatsTotalTabCountMax, 0);
registry->RegisterIntegerPref(prefs::kTabStatsMaxTabsPerWindow, 0);
registry->RegisterIntegerPref(prefs::kTabStatsWindowCountMax, 0);
DailyEvent::RegisterPref(registry, prefs::kTabStatsDailySample);
}
void TabStatsTracker::TabStatsDailyObserver::OnDailyEvent() {
reporting_delegate_->ReportDailyMetrics(data_store_->tab_stats());
data_store_->ResetMaximumsToCurrentState();
......
......@@ -16,6 +16,7 @@
#include "chrome/browser/ui/tabs/tab_strip_model_observer.h"
#include "components/metrics/daily_event.h"
class PrefRegistrySimple;
class PrefService;
namespace metrics {
......@@ -40,6 +41,9 @@ class TabStatsTracker : public TabStripModelObserver,
// Returns the |TabStatsTracker| global instance.
static TabStatsTracker* GetInstance();
// Registers prefs used to track tab stats.
static void RegisterPrefs(PrefRegistrySimple* registry);
// Accessors.
const TabStatsDataStore::TabsStats& tab_stats() const;
......
......@@ -11,9 +11,8 @@
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/common/pref_names.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "components/metrics/metrics_pref_names.h"
#include "components/metrics/metrics_service.h"
#include "components/prefs/pref_registry_simple.h"
#include "components/prefs/testing_pref_service.h"
#include "testing/gtest/include/gtest/gtest.h"
......@@ -117,7 +116,8 @@ class TabStatsTrackerTest : public testing::Test {
power_monitor_.reset(new base::PowerMonitor(
std::unique_ptr<base::PowerMonitorSource>(power_monitor_source_)));
MetricsService::RegisterPrefs(pref_service_.registry());
TabStatsTracker::RegisterPrefs(pref_service_.registry());
// The tab stats tracker has to be created after the power monitor as it's
// using it.
tab_stats_tracker_.reset(new TestTabStatsTracker(&pref_service_));
......
......@@ -185,9 +185,12 @@
#include "components/omnibox/browser/omnibox_field_trial.h"
#else
#include "chrome/browser/gcm/gcm_product_util.h"
#include "chrome/browser/metrics/tab_stats_tracker.h"
#include "chrome/browser/signin/signin_promo.h"
#include "chrome/browser/ui/startup/startup_browser_creator.h"
#include "chrome/browser/ui/webui/foreign_session_handler.h"
#include "chrome/browser/ui/webui/md_history_ui.h"
#include "chrome/browser/ui/webui/settings/md_settings_ui.h"
#include "chrome/browser/upgrade_detector.h"
#endif
......@@ -236,6 +239,7 @@
#include "chrome/browser/extensions/extension_assets_manager_chromeos.h"
#include "chrome/browser/media/protected_media_identifier_permission_context.h"
#include "chrome/browser/metrics/chromeos_metrics_provider.h"
#include "chrome/browser/ui/ash/chrome_launcher_prefs.h"
#include "chrome/browser/ui/webui/chromeos/login/enable_debugging_screen_handler.h"
#include "chrome/browser/ui/webui/chromeos/login/hid_detection_screen_handler.h"
#include "chrome/browser/ui/webui/chromeos/login/signin_screen_handler.h"
......@@ -256,10 +260,6 @@
#include "chrome/browser/ui/app_list/arc/arc_app_list_prefs.h"
#endif
#if defined(OS_CHROMEOS)
#include "chrome/browser/ui/ash/chrome_launcher_prefs.h"
#endif
#if defined(OS_MACOSX)
#include "chrome/browser/ui/cocoa/apps/quit_with_apps_controller_mac.h"
#include "chrome/browser/ui/cocoa/confirm_quit.h"
......@@ -281,11 +281,6 @@
#include "chrome/browser/ui/browser_view_prefs.h"
#endif
#if !defined(OS_ANDROID)
#include "chrome/browser/ui/webui/md_history_ui.h"
#include "chrome/browser/ui/webui/settings/md_settings_ui.h"
#endif
namespace {
#if BUILDFLAG(ENABLE_EXTENSIONS)
......@@ -328,7 +323,6 @@ void RegisterLocalState(PrefRegistrySimple* registry) {
BrowserProcessImpl::RegisterPrefs(registry);
ChromeMetricsServiceClient::RegisterPrefs(registry);
ChromeTracingDelegate::RegisterPrefs(registry);
variations::VariationsService::RegisterPrefs(registry);
component_updater::RegisterPrefs(registry);
ExternalProtocolHandler::RegisterPrefs(registry);
flags_ui::PrefServiceFlagsStorage::RegisterPrefs(registry);
......@@ -345,14 +339,19 @@ void RegisterLocalState(PrefRegistrySimple* registry) {
RegisterScreenshotPrefs(registry);
SigninManagerFactory::RegisterPrefs(registry);
ssl_config::SSLConfigServiceManager::RegisterPrefs(registry);
subresource_filter::IndexedRulesetVersion::RegisterPrefs(registry);
startup_metric_utils::RegisterPrefs(registry);
subresource_filter::IndexedRulesetVersion::RegisterPrefs(registry);
update_client::RegisterPrefs(registry);
variations::VariationsService::RegisterPrefs(registry);
policy::BrowserPolicyConnector::RegisterPrefs(registry);
policy::PolicyStatisticsCollector::RegisterPrefs(registry);
policy::RegisterPrefs(registry);
#if BUILDFLAG(ENABLE_BACKGROUND)
BackgroundModeManager::RegisterPrefs(registry);
#endif
#if BUILDFLAG(ENABLE_EXTENSIONS)
EasyUnlockService::RegisterPrefs(registry);
#endif
......@@ -367,24 +366,16 @@ void RegisterLocalState(PrefRegistrySimple* registry) {
// Obsolete activity prefs. See MigrateObsoleteBrowserPrefs().
registry->RegisterIntegerPref(kStabilityForegroundActivityType, 0);
registry->RegisterIntegerPref(kStabilityLaunchedActivityFlags, 0);
registry->RegisterListPref(kStabilityLaunchedActivityCounts);
registry->RegisterListPref(kStabilityCrashedActivityCounts);
#endif
#if !defined(OS_ANDROID)
task_manager::TaskManagerInterface::RegisterPrefs(registry);
#endif // !defined(OS_ANDROID)
#if BUILDFLAG(ENABLE_BACKGROUND)
BackgroundModeManager::RegisterPrefs(registry);
#endif
#if !defined(OS_ANDROID)
RegisterBrowserPrefs(registry);
StartupBrowserCreator::RegisterLocalStatePrefs(registry);
registry->RegisterListPref(kStabilityLaunchedActivityCounts);
#else
// The native GCM is used on Android instead.
gcm::GCMChannelStatusSyncer::RegisterPrefs(registry);
gcm::RegisterPrefs(registry);
metrics::TabStatsTracker::RegisterPrefs(registry);
RegisterBrowserPrefs(registry);
StartupBrowserCreator::RegisterLocalStatePrefs(registry);
task_manager::TaskManagerInterface::RegisterPrefs(registry);
UpgradeDetector::RegisterPrefs(registry);
#if !defined(OS_CHROMEOS)
RegisterDefaultBrowserPromptPrefs(registry);
......
......@@ -2512,4 +2512,19 @@ const char kPrefetchUsageMixedCount[] = "offline_pages.prefetch_mixed_count";
// will be wiped.
const char kMediaEngagementSchemaVersion[] = "media.engagement.schema_version";
// Maximum number of tabs that has been opened since the last time it has been
// reported.
const char kTabStatsTotalTabCountMax[] = "tab_stats.total_tab_count_max";
// Maximum number of tabs that has been opened in a single window since the last
// time it has been reported.
const char kTabStatsMaxTabsPerWindow[] = "tab_stats.max_tabs_per_window";
// Maximum number of windows that has been opened since the last time it has
// been reported.
const char kTabStatsWindowCountMax[] = "tab_stats.window_count_max";
// Timestamp of the last time the tab stats daily metrics have been reported.
const char kTabStatsDailySample[] = "tab_stats.last_daily_sample";
} // namespace prefs
......@@ -894,6 +894,12 @@ extern const char kPrefetchUsageMixedCount[];
extern const char kMediaEngagementSchemaVersion[];
// Preferences for recording metrics about tab and window usage.
extern const char kTabStatsTotalTabCountMax[];
extern const char kTabStatsMaxTabsPerWindow[];
extern const char kTabStatsWindowCountMax[];
extern const char kTabStatsDailySample[];
} // namespace prefs
#endif // CHROME_COMMON_PREF_NAMES_H_
......@@ -202,20 +202,5 @@ const char kUmaCellDataUse[] = "user_experience_metrics.uma_cell_datause";
// per day.
const char kUserCellDataUse[] = "user_experience_metrics.user_call_datause";
// Maximum number of tabs that has been opened since the last time it has been
// reported.
const char kTabStatsTotalTabCountMax[] = "tab_stats.total_tab_count_max";
// Maximum number of tabs that has been opened in a single window since the last
// time it has been reported.
const char kTabStatsMaxTabsPerWindow[] = "tab_stats.max_tabs_per_window";
// Maximum number of windows that has been opened since the last time it has
// been reported.
const char kTabStatsWindowCountMax[] = "tab_stats.window_count_max";
// Timestamp of the last time the tab stats daily metrics have been reported.
const char kTabStatsDailySample[] = "tab_stats.last_daily_sample";
} // namespace prefs
} // namespace metrics
......@@ -69,12 +69,6 @@ extern const char kUkmCellDataUse[];
extern const char kUmaCellDataUse[];
extern const char kUserCellDataUse[];
// Preferences for recording information about the tabs and windows usage.
extern const char kTabStatsTotalTabCountMax[];
extern const char kTabStatsMaxTabsPerWindow[];
extern const char kTabStatsWindowCountMax[];
extern const char kTabStatsDailySample[];
} // namespace prefs
} // namespace metrics
......
......@@ -144,7 +144,6 @@
#include "base/threading/sequenced_task_runner_handle.h"
#include "base/time/time.h"
#include "build/build_config.h"
#include "components/metrics/daily_event.h"
#include "components/metrics/environment_recorder.h"
#include "components/metrics/field_trials_provider.h"
#include "components/metrics/metrics_log.h"
......@@ -206,12 +205,6 @@ void MetricsService::RegisterPrefs(PrefRegistrySimple* registry) {
registry->RegisterInt64Pref(prefs::kUninstallLaunchCount, 0);
registry->RegisterInt64Pref(prefs::kUninstallMetricsUptimeSec, 0);
// Register the tab stats metrics.
registry->RegisterIntegerPref(prefs::kTabStatsTotalTabCountMax, 0);
registry->RegisterIntegerPref(prefs::kTabStatsMaxTabsPerWindow, 0);
registry->RegisterIntegerPref(prefs::kTabStatsWindowCountMax, 0);
metrics::DailyEvent::RegisterPref(registry, prefs::kTabStatsDailySample);
}
MetricsService::MetricsService(MetricsStateManager* state_manager,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment