summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorthestig@chromium.org <thestig@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-04-12 02:19:04 +0000
committerthestig@chromium.org <thestig@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-04-12 02:19:04 +0000
commit95132f5c2d501b13c7004e38bce727a81af907dd (patch)
tree59d8598dcee2f9d3bc8c765f3b8cd92e21e6d804
parent9a3d9a0ccbca950e62762a3bd9635fb87e4c08ec (diff)
downloadchromium_src-95132f5c2d501b13c7004e38bce727a81af907dd.zip
chromium_src-95132f5c2d501b13c7004e38bce727a81af907dd.tar.gz
chromium_src-95132f5c2d501b13c7004e38bce727a81af907dd.tar.bz2
Move various bits of UMA code from ChromeBrowserMain to a new ChromeBrowserMainExtraPartsMetrics class.
Review URL: https://chromiumcodereview.appspot.com/13868004 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@193829 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/chrome_browser_main.cc102
-rw-r--r--chrome/browser/chrome_content_browser_client.cc3
-rw-r--r--chrome/browser/metrics/chrome_browser_main_extra_parts_metrics.cc109
-rw-r--r--chrome/browser/metrics/chrome_browser_main_extra_parts_metrics.h32
-rw-r--r--chrome/chrome_browser.gypi2
5 files changed, 163 insertions, 85 deletions
diff --git a/chrome/browser/chrome_browser_main.cc b/chrome/browser/chrome_browser_main.cc
index 1918b32..5b9beb1 100644
--- a/chrome/browser/chrome_browser_main.cc
+++ b/chrome/browser/chrome_browser_main.cc
@@ -14,7 +14,6 @@
#include "base/at_exit.h"
#include "base/bind.h"
#include "base/command_line.h"
-#include "base/cpu.h"
#include "base/debug/trace_event.h"
#include "base/file_util.h"
#include "base/files/file_path.h"
@@ -34,7 +33,6 @@
#include "base/strings/sys_string_conversions.h"
#include "base/sys_info.h"
#include "base/threading/platform_thread.h"
-#include "base/threading/sequenced_worker_pool.h"
#include "base/time.h"
#include "base/utf_string_conversions.h"
#include "base/values.h"
@@ -139,9 +137,6 @@
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/layout.h"
#include "ui/base/resource/resource_bundle.h"
-#include "ui/base/resource/resource_handle.h"
-#include "ui/base/touch/touch_device.h"
-#include "ui/base/ui_base_switches.h"
#if defined(OS_ANDROID)
#include "base/android/build_info.h"
@@ -216,23 +211,6 @@ using content::BrowserThread;
namespace {
-enum UMATouchEventsState {
- UMA_TOUCH_EVENTS_ENABLED,
- UMA_TOUCH_EVENTS_AUTO_ENABLED,
- UMA_TOUCH_EVENTS_AUTO_DISABLED,
- UMA_TOUCH_EVENTS_DISABLED,
- // NOTE: Add states only immediately above this line. Make sure to
- // update the enum list in tools/histogram/histograms.xml accordingly.
- UMA_TOUCH_EVENTS_STATE_COUNT
-};
-
-void LogIntelMicroArchitecture() {
- base::CPU cpu;
- base::CPU::IntelMicroArchitecture arch = cpu.GetIntelMicroArchitecture();
- UMA_HISTOGRAM_ENUMERATION("Platform.IntelMaxMicroArchitecture", arch,
- base::CPU::MAX_INTEL_MICRO_ARCHITECTURE);
-}
-
// This function provides some ways to test crash and assertion handling
// behavior of the program.
void HandleTestParameters(const CommandLine& command_line) {
@@ -413,39 +391,6 @@ void AddPreReadHistogramTime(const char* name, base::TimeDelta time) {
counter->AddTime(time);
}
-void RecordDefaultBrowserUMAStat() {
- // Record whether Chrome is the default browser or not.
- ShellIntegration::DefaultWebClientState default_state =
- ShellIntegration::GetDefaultBrowser();
- UMA_HISTOGRAM_ENUMERATION("DefaultBrowser.State", default_state,
- ShellIntegration::NUM_DEFAULT_STATES);
-}
-
-void RecordTouchEventState(const CommandLine& command_line) {
- const std::string touch_enabled_switch =
- command_line.HasSwitch(switches::kTouchEvents) ?
- command_line.GetSwitchValueASCII(switches::kTouchEvents) :
- switches::kTouchEventsAuto;
-
- if (touch_enabled_switch.empty() ||
- touch_enabled_switch == switches::kTouchEventsEnabled) {
- UMA_HISTOGRAM_ENUMERATION("Touchscreen.TouchEventsEnabled",
- UMA_TOUCH_EVENTS_ENABLED,
- UMA_TOUCH_EVENTS_STATE_COUNT);
- } else if (touch_enabled_switch == switches::kTouchEventsAuto) {
- bool touch_device_present = ui::IsTouchDevicePresent();
- UMA_HISTOGRAM_ENUMERATION("Touchscreen.TouchEventsEnabled",
- touch_device_present ?
- UMA_TOUCH_EVENTS_AUTO_ENABLED :
- UMA_TOUCH_EVENTS_AUTO_DISABLED,
- UMA_TOUCH_EVENTS_STATE_COUNT);
- } else if (touch_enabled_switch == switches::kTouchEventsDisabled) {
- UMA_HISTOGRAM_ENUMERATION("Touchscreen.TouchEventsEnabled",
- UMA_TOUCH_EVENTS_DISABLED,
- UMA_TOUCH_EVENTS_STATE_COUNT);
- }
-}
-
void RegisterComponentsForUpdate(const CommandLine& command_line) {
ComponentUpdateService* cus = g_browser_process->component_updater();
@@ -537,21 +482,21 @@ void LaunchDevToolsHandlerIfNeeded(Profile* profile,
// recording and then deletes itself.
class LoadCompleteListener : public content::NotificationObserver {
public:
- LoadCompleteListener() {
- registrar_.Add(this,
- content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
- content::NotificationService::AllSources());
- }
- virtual ~LoadCompleteListener() {}
-
- // content::NotificationObserver implementation.
- virtual void Observe(int type,
- const content::NotificationSource& source,
- const content::NotificationDetails& details) OVERRIDE {
- DCHECK(type == content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME);
- startup_metric_utils::OnInitialPageLoadComplete();
- delete this;
- }
+ LoadCompleteListener() {
+ registrar_.Add(this,
+ content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
+ content::NotificationService::AllSources());
+ }
+ virtual ~LoadCompleteListener() {}
+
+ // content::NotificationObserver implementation.
+ virtual void Observe(int type,
+ const content::NotificationSource& source,
+ const content::NotificationDetails& details) OVERRIDE {
+ DCHECK_EQ(content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME, type);
+ startup_metric_utils::OnInitialPageLoadComplete();
+ delete this;
+ }
private:
content::NotificationRegistrar registrar_;
@@ -1096,10 +1041,6 @@ int ChromeBrowserMainParts::PreMainMessageLoopRunImpl() {
StartMetricsRecording();
#endif
-#if defined(ARCH_CPU_X86_FAMILY)
- LogIntelMicroArchitecture();
-#endif // defined(ARCH_CPU_X86_FAMILY)
-
// Create watchdog thread after creating all other threads because it will
// watch the other threads and they must be running.
browser_process_->watchdog_thread();
@@ -1439,7 +1380,6 @@ int ChromeBrowserMainParts::PreMainMessageLoopRunImpl() {
HandleTestParameters(parsed_command_line());
RecordBreakpadStatusUMA(browser_process_->metrics_service());
- about_flags::RecordUMAStatistics(local_state_);
#if defined(ENABLE_LANGUAGE_DETECTION)
LanguageUsageMetrics::RecordAcceptLanguages(
profile_->GetPrefs()->GetString(prefs::kAcceptLanguages));
@@ -1447,12 +1387,6 @@ int ChromeBrowserMainParts::PreMainMessageLoopRunImpl() {
browser_process_->GetApplicationLocale());
#endif
- // Querying the default browser state can be slow, do it in the background.
- BrowserThread::GetBlockingPool()->PostDelayedTask(
- FROM_HERE,
- base::Bind(&RecordDefaultBrowserUMAStat),
- base::TimeDelta::FromSeconds(5));
-
// The extension service may be available at this point. If the command line
// specifies --uninstall-extension, attempt the uninstall extension startup
// action.
@@ -1596,8 +1530,6 @@ int ChromeBrowserMainParts::PreMainMessageLoopRunImpl() {
browser_creator_.reset();
#endif // !defined(OS_ANDROID)
- RecordTouchEventState(parsed_command_line());
-
PostBrowserStart();
if (parameters().ui_task) {
@@ -1753,13 +1685,13 @@ void RecordBrowserStartupTime() {
// CurrentProcessInfo::CreationTime() is currently only implemented on Mac and
// Windows.
#if defined(OS_MACOSX) || defined(OS_WIN)
- const base::Time *process_creation_time =
+ const base::Time* process_creation_time =
base::CurrentProcessInfo::CreationTime();
if (process_creation_time)
RecordPreReadExperimentTime("Startup.BrowserMessageLoopStartTime",
base::Time::Now() - *process_creation_time);
-#endif // OS_MACOSX || OS_WIN
+#endif // defined(OS_MACOSX) || defined(OS_WIN)
// Record collected startup metrics.
startup_metric_utils::OnBrowserStartupComplete();
diff --git a/chrome/browser/chrome_content_browser_client.cc b/chrome/browser/chrome_content_browser_client.cc
index 3c518fb..b03bdec 100644
--- a/chrome/browser/chrome_content_browser_client.cc
+++ b/chrome/browser/chrome_content_browser_client.cc
@@ -44,6 +44,7 @@
#include "chrome/browser/geolocation/chrome_access_token_store.h"
#include "chrome/browser/google/google_util.h"
#include "chrome/browser/media/media_capture_devices_dispatcher.h"
+#include "chrome/browser/metrics/chrome_browser_main_extra_parts_metrics.h"
#include "chrome/browser/nacl_host/nacl_process_host.h"
#include "chrome/browser/net/chrome_net_log.h"
#include "chrome/browser/notifications/desktop_notification_service.h"
@@ -560,6 +561,8 @@ content::BrowserMainParts* ChromeContentBrowserClient::CreateBrowserMainParts(
chrome::AddAuraToolkitExtraParts(main_parts);
#endif
+ chrome::AddMetricsExtraParts(main_parts);
+
return main_parts;
}
diff --git a/chrome/browser/metrics/chrome_browser_main_extra_parts_metrics.cc b/chrome/browser/metrics/chrome_browser_main_extra_parts_metrics.cc
new file mode 100644
index 0000000..4e37412
--- /dev/null
+++ b/chrome/browser/metrics/chrome_browser_main_extra_parts_metrics.cc
@@ -0,0 +1,109 @@
+// Copyright (c) 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/metrics/chrome_browser_main_extra_parts_metrics.h"
+
+#include <string>
+
+#include "base/bind.h"
+#include "base/command_line.h"
+#include "base/cpu.h"
+#include "base/metrics/histogram.h"
+#include "base/threading/sequenced_worker_pool.h"
+#include "base/time.h"
+#include "chrome/browser/about_flags.h"
+#include "chrome/browser/browser_process.h"
+#include "chrome/browser/chrome_browser_main.h"
+#include "chrome/browser/shell_integration.h"
+#include "content/public/browser/browser_thread.h"
+#include "ui/base/touch/touch_device.h"
+#include "ui/base/ui_base_switches.h"
+
+namespace {
+
+enum UMATouchEventsState {
+ UMA_TOUCH_EVENTS_ENABLED,
+ UMA_TOUCH_EVENTS_AUTO_ENABLED,
+ UMA_TOUCH_EVENTS_AUTO_DISABLED,
+ UMA_TOUCH_EVENTS_DISABLED,
+ // NOTE: Add states only immediately above this line. Make sure to
+ // update the enum list in tools/histograms/histograms.xml accordingly.
+ UMA_TOUCH_EVENTS_STATE_COUNT
+};
+
+void LogIntelMicroArchitecture() {
+#if defined(ARCH_CPU_X86_FAMILY)
+ base::CPU cpu;
+ base::CPU::IntelMicroArchitecture arch = cpu.GetIntelMicroArchitecture();
+ UMA_HISTOGRAM_ENUMERATION("Platform.IntelMaxMicroArchitecture", arch,
+ base::CPU::MAX_INTEL_MICRO_ARCHITECTURE);
+#endif // defined(ARCH_CPU_X86_FAMILY)
+}
+
+void RecordDefaultBrowserUMAStat() {
+ // Record whether Chrome is the default browser or not.
+ ShellIntegration::DefaultWebClientState default_state =
+ ShellIntegration::GetDefaultBrowser();
+ UMA_HISTOGRAM_ENUMERATION("DefaultBrowser.State", default_state,
+ ShellIntegration::NUM_DEFAULT_STATES);
+}
+
+void RecordTouchEventState() {
+ const CommandLine& command_line = *CommandLine::ForCurrentProcess();
+ const std::string touch_enabled_switch =
+ command_line.HasSwitch(switches::kTouchEvents) ?
+ command_line.GetSwitchValueASCII(switches::kTouchEvents) :
+ switches::kTouchEventsAuto;
+
+ UMATouchEventsState state;
+ if (touch_enabled_switch.empty() ||
+ touch_enabled_switch == switches::kTouchEventsEnabled) {
+ state = UMA_TOUCH_EVENTS_ENABLED;
+ } else if (touch_enabled_switch == switches::kTouchEventsAuto) {
+ state = ui::IsTouchDevicePresent() ?
+ UMA_TOUCH_EVENTS_AUTO_ENABLED : UMA_TOUCH_EVENTS_AUTO_DISABLED;
+ } else if (touch_enabled_switch == switches::kTouchEventsDisabled) {
+ state = UMA_TOUCH_EVENTS_DISABLED;
+ } else {
+ NOTREACHED();
+ return;
+ }
+
+ UMA_HISTOGRAM_ENUMERATION("Touchscreen.TouchEventsEnabled", state,
+ UMA_TOUCH_EVENTS_STATE_COUNT);
+}
+
+} // namespace
+
+ChromeBrowserMainExtraPartsMetrics::ChromeBrowserMainExtraPartsMetrics() {
+}
+
+ChromeBrowserMainExtraPartsMetrics::~ChromeBrowserMainExtraPartsMetrics() {
+}
+
+void ChromeBrowserMainExtraPartsMetrics::PreProfileInit() {
+ LogIntelMicroArchitecture();
+}
+
+void ChromeBrowserMainExtraPartsMetrics::PreBrowserStart() {
+ about_flags::RecordUMAStatistics(g_browser_process->local_state());
+
+ // Querying the default browser state can be slow, do it in the background.
+ content::BrowserThread::GetBlockingPool()->PostDelayedTask(
+ FROM_HERE,
+ base::Bind(&RecordDefaultBrowserUMAStat),
+ base::TimeDelta::FromSeconds(45));
+}
+
+void ChromeBrowserMainExtraPartsMetrics::PostBrowserStart() {
+ RecordTouchEventState();
+}
+
+namespace chrome {
+
+void AddMetricsExtraParts(ChromeBrowserMainParts* main_parts) {
+ main_parts->AddParts(new ChromeBrowserMainExtraPartsMetrics());
+}
+
+} // namespace chrome
diff --git a/chrome/browser/metrics/chrome_browser_main_extra_parts_metrics.h b/chrome/browser/metrics/chrome_browser_main_extra_parts_metrics.h
new file mode 100644
index 0000000..d9ace38
--- /dev/null
+++ b/chrome/browser/metrics/chrome_browser_main_extra_parts_metrics.h
@@ -0,0 +1,32 @@
+// Copyright (c) 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_BROWSER_METRICS_CHROME_BROWSER_MAIN_EXTRA_PARTS_METRICS_H_
+#define CHROME_BROWSER_METRICS_CHROME_BROWSER_MAIN_EXTRA_PARTS_METRICS_H_
+
+#include "base/basictypes.h"
+#include "base/compiler_specific.h"
+#include "chrome/browser/chrome_browser_main_extra_parts.h"
+
+class ChromeBrowserMainParts;
+
+namespace chrome {
+void AddMetricsExtraParts(ChromeBrowserMainParts* main_parts);
+}
+
+class ChromeBrowserMainExtraPartsMetrics : public ChromeBrowserMainExtraParts {
+ public:
+ ChromeBrowserMainExtraPartsMetrics();
+ virtual ~ChromeBrowserMainExtraPartsMetrics();
+
+ // Overridden from ChromeBrowserMainExtraParts:
+ virtual void PreProfileInit() OVERRIDE;
+ virtual void PreBrowserStart() OVERRIDE;
+ virtual void PostBrowserStart() OVERRIDE;
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(ChromeBrowserMainExtraPartsMetrics);
+};
+
+#endif // CHROME_BROWSER_METRICS_CHROME_BROWSER_MAIN_EXTRA_PARTS_METRICS_H_
diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi
index 61c41cd..ff515d6 100644
--- a/chrome/chrome_browser.gypi
+++ b/chrome/chrome_browser.gypi
@@ -962,6 +962,8 @@
'browser/memory_details_win.cc',
'browser/memory_purger.cc',
'browser/memory_purger.h',
+ 'browser/metrics/chrome_browser_main_extra_parts_metrics.cc',
+ 'browser/metrics/chrome_browser_main_extra_parts_metrics.h',
'browser/metrics/field_trial_synchronizer.cc',
'browser/metrics/field_trial_synchronizer.h',
'browser/metrics/metric_event_duration_details.h',