Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / metrics / chrome_browser_main_extra_parts_metrics.cc
bloba14e30f3a0a0eedf755b04d5189ada64b08fc228
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chrome/browser/metrics/chrome_browser_main_extra_parts_metrics.h"
7 #include <string>
9 #include "base/bind.h"
10 #include "base/command_line.h"
11 #include "base/cpu.h"
12 #include "base/metrics/histogram.h"
13 #include "base/metrics/sparse_histogram.h"
14 #include "base/sys_info.h"
15 #include "base/threading/sequenced_worker_pool.h"
16 #include "base/time/time.h"
17 #include "chrome/browser/about_flags.h"
18 #include "chrome/browser/browser_process.h"
19 #include "chrome/browser/chrome_browser_main.h"
20 #include "chrome/browser/pref_service_flags_storage.h"
21 #include "chrome/browser/shell_integration.h"
22 #include "content/public/browser/browser_thread.h"
23 #include "ui/base/touch/touch_device.h"
24 #include "ui/base/ui_base_switches.h"
25 #include "ui/events/event_switches.h"
27 #if defined(OS_LINUX) && !defined(OS_CHROMEOS)
28 #include <gnu/libc-version.h>
30 #include "base/version.h"
31 #endif
33 namespace {
35 enum UMALinuxGlibcVersion {
36 UMA_LINUX_GLIBC_NOT_PARSEABLE,
37 UMA_LINUX_GLIBC_UNKNOWN,
38 UMA_LINUX_GLIBC_2_11,
39 UMA_LINUX_GLIBC_2_19 = UMA_LINUX_GLIBC_2_11 + 8,
40 // NOTE: Add new version above this line and update the enum list in
41 // tools/histograms/histograms.xml accordingly.
42 UMA_LINUX_GLIBC_VERSION_COUNT
45 enum UMATouchEventsState {
46 UMA_TOUCH_EVENTS_ENABLED,
47 UMA_TOUCH_EVENTS_AUTO_ENABLED,
48 UMA_TOUCH_EVENTS_AUTO_DISABLED,
49 UMA_TOUCH_EVENTS_DISABLED,
50 // NOTE: Add states only immediately above this line. Make sure to
51 // update the enum list in tools/histograms/histograms.xml accordingly.
52 UMA_TOUCH_EVENTS_STATE_COUNT
55 void RecordMicroArchitectureStats() {
56 #if defined(ARCH_CPU_X86_FAMILY)
57 base::CPU cpu;
58 base::CPU::IntelMicroArchitecture arch = cpu.GetIntelMicroArchitecture();
59 UMA_HISTOGRAM_ENUMERATION("Platform.IntelMaxMicroArchitecture", arch,
60 base::CPU::MAX_INTEL_MICRO_ARCHITECTURE);
61 #endif // defined(ARCH_CPU_X86_FAMILY)
62 UMA_HISTOGRAM_SPARSE_SLOWLY("Platform.LogicalCpuCount",
63 base::SysInfo::NumberOfProcessors());
66 void RecordDefaultBrowserUMAStat() {
67 // Record whether Chrome is the default browser or not.
68 ShellIntegration::DefaultWebClientState default_state =
69 ShellIntegration::GetDefaultBrowser();
70 UMA_HISTOGRAM_ENUMERATION("DefaultBrowser.State", default_state,
71 ShellIntegration::NUM_DEFAULT_STATES);
74 void RecordLinuxGlibcVersion() {
75 #if defined(OS_LINUX) && !defined(OS_CHROMEOS)
76 Version version(gnu_get_libc_version());
78 UMALinuxGlibcVersion glibc_version_result = UMA_LINUX_GLIBC_NOT_PARSEABLE;
79 if (version.IsValid() && version.components().size() == 2) {
80 glibc_version_result = UMA_LINUX_GLIBC_UNKNOWN;
81 int glibc_major_version = version.components()[0];
82 int glibc_minor_version = version.components()[1];
83 if (glibc_major_version == 2) {
84 // A constant to translate glibc 2.x minor versions to their
85 // equivalent UMALinuxGlibcVersion values.
86 const int kGlibcMinorVersionTranslationOffset = 11 - UMA_LINUX_GLIBC_2_11;
87 int translated_glibc_minor_version =
88 glibc_minor_version - kGlibcMinorVersionTranslationOffset;
89 if (translated_glibc_minor_version >= UMA_LINUX_GLIBC_2_11 &&
90 translated_glibc_minor_version <= UMA_LINUX_GLIBC_2_19) {
91 glibc_version_result =
92 static_cast<UMALinuxGlibcVersion>(translated_glibc_minor_version);
96 UMA_HISTOGRAM_ENUMERATION("Linux.GlibcVersion", glibc_version_result,
97 UMA_LINUX_GLIBC_VERSION_COUNT);
98 #endif
101 void RecordTouchEventState() {
102 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
103 const std::string touch_enabled_switch =
104 command_line.HasSwitch(switches::kTouchEvents) ?
105 command_line.GetSwitchValueASCII(switches::kTouchEvents) :
106 switches::kTouchEventsAuto;
108 UMATouchEventsState state;
109 if (touch_enabled_switch.empty() ||
110 touch_enabled_switch == switches::kTouchEventsEnabled) {
111 state = UMA_TOUCH_EVENTS_ENABLED;
112 } else if (touch_enabled_switch == switches::kTouchEventsAuto) {
113 state = ui::IsTouchDevicePresent() ?
114 UMA_TOUCH_EVENTS_AUTO_ENABLED : UMA_TOUCH_EVENTS_AUTO_DISABLED;
115 } else if (touch_enabled_switch == switches::kTouchEventsDisabled) {
116 state = UMA_TOUCH_EVENTS_DISABLED;
117 } else {
118 NOTREACHED();
119 return;
122 UMA_HISTOGRAM_ENUMERATION("Touchscreen.TouchEventsEnabled", state,
123 UMA_TOUCH_EVENTS_STATE_COUNT);
126 } // namespace
128 ChromeBrowserMainExtraPartsMetrics::ChromeBrowserMainExtraPartsMetrics() {
131 ChromeBrowserMainExtraPartsMetrics::~ChromeBrowserMainExtraPartsMetrics() {
134 void ChromeBrowserMainExtraPartsMetrics::PreProfileInit() {
135 RecordMicroArchitectureStats();
138 void ChromeBrowserMainExtraPartsMetrics::PreBrowserStart() {
139 about_flags::PrefServiceFlagsStorage flags_storage_(
140 g_browser_process->local_state());
141 about_flags::RecordUMAStatistics(&flags_storage_);
143 // Querying the default browser state can be slow, do it in the background.
144 content::BrowserThread::GetBlockingPool()->PostDelayedTask(
145 FROM_HERE,
146 base::Bind(&RecordDefaultBrowserUMAStat),
147 base::TimeDelta::FromSeconds(45));
150 void ChromeBrowserMainExtraPartsMetrics::PostBrowserStart() {
151 RecordLinuxGlibcVersion();
152 RecordTouchEventState();
155 namespace chrome {
157 void AddMetricsExtraParts(ChromeBrowserMainParts* main_parts) {
158 main_parts->AddParts(new ChromeBrowserMainExtraPartsMetrics());
161 } // namespace chrome