[Eraser strings] Remove unused Supervised User infobar and corresponding strings
[chromium-blink-merge.git] / chrome / browser / metrics / chrome_browser_main_extra_parts_metrics.cc
blob27cf2e4046b374140e92b67f07e8b0e5a89d55c8
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/mac/bluetooth_utility.h"
21 #include "chrome/browser/pref_service_flags_storage.h"
22 #include "chrome/browser/shell_integration.h"
23 #include "content/public/browser/browser_thread.h"
24 #include "ui/base/touch/touch_device.h"
25 #include "ui/base/ui_base_switches.h"
26 #include "ui/events/event_switches.h"
27 #include "ui/gfx/screen.h"
29 #if defined(OS_ANDROID) && defined(__arm__)
30 #include <cpu-features.h>
31 #endif // defined(OS_ANDROID) && defined(__arm__)
33 #if defined(OS_LINUX) && !defined(OS_CHROMEOS)
34 #include <gnu/libc-version.h>
36 #include "base/version.h"
37 #if defined(USE_X11)
38 #include "ui/base/x/x11_util.h"
39 #endif
40 #endif // defined(OS_LINUX) && !defined(OS_CHROMEOS)
42 #if defined(USE_OZONE) || defined(USE_X11)
43 #include "ui/events/devices/device_data_manager.h"
44 #include "ui/events/devices/input_device_event_observer.h"
45 #endif // defined(USE_OZONE) || defined(USE_X11)
47 #if defined(OS_WIN)
48 #include "chrome/installer/util/google_update_settings.h"
49 #endif // defined(OS_WIN)
51 namespace {
53 enum UMALinuxGlibcVersion {
54 UMA_LINUX_GLIBC_NOT_PARSEABLE,
55 UMA_LINUX_GLIBC_UNKNOWN,
56 UMA_LINUX_GLIBC_2_11,
57 // To log newer versions, just update tools/metrics/histograms/histograms.xml.
60 enum UMALinuxWindowManager {
61 UMA_LINUX_WINDOW_MANAGER_OTHER,
62 UMA_LINUX_WINDOW_MANAGER_BLACKBOX,
63 UMA_LINUX_WINDOW_MANAGER_CHROME_OS, // Deprecated.
64 UMA_LINUX_WINDOW_MANAGER_COMPIZ,
65 UMA_LINUX_WINDOW_MANAGER_ENLIGHTENMENT,
66 UMA_LINUX_WINDOW_MANAGER_ICE_WM,
67 UMA_LINUX_WINDOW_MANAGER_KWIN,
68 UMA_LINUX_WINDOW_MANAGER_METACITY,
69 UMA_LINUX_WINDOW_MANAGER_MUFFIN,
70 UMA_LINUX_WINDOW_MANAGER_MUTTER,
71 UMA_LINUX_WINDOW_MANAGER_OPENBOX,
72 UMA_LINUX_WINDOW_MANAGER_XFWM4,
73 UMA_LINUX_WINDOW_MANAGER_AWESOME,
74 UMA_LINUX_WINDOW_MANAGER_I3,
75 UMA_LINUX_WINDOW_MANAGER_ION3,
76 UMA_LINUX_WINDOW_MANAGER_MATCHBOX,
77 UMA_LINUX_WINDOW_MANAGER_NOTION,
78 UMA_LINUX_WINDOW_MANAGER_QTILE,
79 UMA_LINUX_WINDOW_MANAGER_RATPOISON,
80 UMA_LINUX_WINDOW_MANAGER_STUMPWM,
81 UMA_LINUX_WINDOW_MANAGER_WMII,
82 UMA_LINUX_WINDOW_MANAGER_FLUXBOX,
83 // NOTE: Append new window managers to the list above this line (i.e. don't
84 // renumber) and update LinuxWindowManagerName in
85 // tools/metrics/histograms/histograms.xml accordingly.
86 UMA_LINUX_WINDOW_MANAGER_COUNT
89 enum UMATouchEventsState {
90 UMA_TOUCH_EVENTS_ENABLED,
91 UMA_TOUCH_EVENTS_AUTO_ENABLED,
92 UMA_TOUCH_EVENTS_AUTO_DISABLED,
93 UMA_TOUCH_EVENTS_DISABLED,
94 // NOTE: Add states only immediately above this line. Make sure to
95 // update the enum list in tools/metrics/histograms/histograms.xml
96 // accordingly.
97 UMA_TOUCH_EVENTS_STATE_COUNT
100 #if defined(OS_ANDROID) && defined(__arm__)
101 enum UMAAndroidArmFpu {
102 UMA_ANDROID_ARM_FPU_VFPV3_D16, // The ARM CPU only supports vfpv3-d16.
103 UMA_ANDROID_ARM_FPU_NEON, // The Arm CPU supports NEON.
104 UMA_ANDROID_ARM_FPU_COUNT
106 #endif // defined(OS_ANDROID) && defined(__arm__)
108 void RecordMicroArchitectureStats() {
109 #if defined(ARCH_CPU_X86_FAMILY)
110 base::CPU cpu;
111 base::CPU::IntelMicroArchitecture arch = cpu.GetIntelMicroArchitecture();
112 UMA_HISTOGRAM_ENUMERATION("Platform.IntelMaxMicroArchitecture", arch,
113 base::CPU::MAX_INTEL_MICRO_ARCHITECTURE);
114 #endif // defined(ARCH_CPU_X86_FAMILY)
115 #if defined(OS_ANDROID) && defined(__arm__)
116 // Detect NEON support.
117 // TODO(fdegans): Remove once non-NEON support has been removed.
118 if (android_getCpuFeatures() & ANDROID_CPU_ARM_FEATURE_NEON) {
119 UMA_HISTOGRAM_ENUMERATION("Android.ArmFpu",
120 UMA_ANDROID_ARM_FPU_NEON,
121 UMA_ANDROID_ARM_FPU_COUNT);
122 } else {
123 UMA_HISTOGRAM_ENUMERATION("Android.ArmFpu",
124 UMA_ANDROID_ARM_FPU_VFPV3_D16,
125 UMA_ANDROID_ARM_FPU_COUNT);
127 #endif // defined(OS_ANDROID) && defined(__arm__)
128 UMA_HISTOGRAM_SPARSE_SLOWLY("Platform.LogicalCpuCount",
129 base::SysInfo::NumberOfProcessors());
132 // Called on the blocking pool some time after startup to avoid slowing down
133 // startup with metrics that aren't trivial to compute.
134 void RecordStartupMetricsOnBlockingPool() {
135 #if defined(OS_WIN)
136 GoogleUpdateSettings::RecordChromeUpdatePolicyHistograms();
137 #endif // defined(OS_WIN)
139 #if defined(OS_MACOSX) && !defined(OS_IOS)
140 bluetooth_utility::BluetoothAvailability availability =
141 bluetooth_utility::GetBluetoothAvailability();
142 UMA_HISTOGRAM_ENUMERATION("OSX.BluetoothAvailability",
143 availability,
144 bluetooth_utility::BLUETOOTH_AVAILABILITY_COUNT);
145 #endif // defined(OS_MACOSX) && !defined(OS_IOS)
147 // Record whether Chrome is the default browser or not.
148 ShellIntegration::DefaultWebClientState default_state =
149 ShellIntegration::GetDefaultBrowser();
150 UMA_HISTOGRAM_ENUMERATION("DefaultBrowser.State", default_state,
151 ShellIntegration::NUM_DEFAULT_STATES);
154 void RecordLinuxGlibcVersion() {
155 #if defined(OS_LINUX) && !defined(OS_CHROMEOS)
156 Version version(gnu_get_libc_version());
158 UMALinuxGlibcVersion glibc_version_result = UMA_LINUX_GLIBC_NOT_PARSEABLE;
159 if (version.IsValid() && version.components().size() == 2) {
160 glibc_version_result = UMA_LINUX_GLIBC_UNKNOWN;
161 uint32_t glibc_major_version = version.components()[0];
162 uint32_t glibc_minor_version = version.components()[1];
163 if (glibc_major_version == 2) {
164 // A constant to translate glibc 2.x minor versions to their
165 // equivalent UMALinuxGlibcVersion values.
166 const int kGlibcMinorVersionTranslationOffset = 11 - UMA_LINUX_GLIBC_2_11;
167 uint32_t translated_glibc_minor_version =
168 glibc_minor_version - kGlibcMinorVersionTranslationOffset;
169 if (translated_glibc_minor_version >= UMA_LINUX_GLIBC_2_11) {
170 glibc_version_result =
171 static_cast<UMALinuxGlibcVersion>(translated_glibc_minor_version);
175 UMA_HISTOGRAM_SPARSE_SLOWLY("Linux.GlibcVersion", glibc_version_result);
176 #endif
179 #if defined(USE_X11) && !defined(OS_CHROMEOS)
180 UMALinuxWindowManager GetLinuxWindowManager() {
181 switch (ui::GuessWindowManager()) {
182 case ui::WM_UNKNOWN:
183 return UMA_LINUX_WINDOW_MANAGER_OTHER;
184 case ui::WM_AWESOME:
185 return UMA_LINUX_WINDOW_MANAGER_AWESOME;
186 case ui::WM_BLACKBOX:
187 return UMA_LINUX_WINDOW_MANAGER_BLACKBOX;
188 case ui::WM_COMPIZ:
189 return UMA_LINUX_WINDOW_MANAGER_COMPIZ;
190 case ui::WM_ENLIGHTENMENT:
191 return UMA_LINUX_WINDOW_MANAGER_ENLIGHTENMENT;
192 case ui::WM_FLUXBOX:
193 return UMA_LINUX_WINDOW_MANAGER_FLUXBOX;
194 case ui::WM_I3:
195 return UMA_LINUX_WINDOW_MANAGER_I3;
196 case ui::WM_ICE_WM:
197 return UMA_LINUX_WINDOW_MANAGER_ICE_WM;
198 case ui::WM_ION3:
199 return UMA_LINUX_WINDOW_MANAGER_ION3;
200 case ui::WM_KWIN:
201 return UMA_LINUX_WINDOW_MANAGER_KWIN;
202 case ui::WM_MATCHBOX:
203 return UMA_LINUX_WINDOW_MANAGER_MATCHBOX;
204 case ui::WM_METACITY:
205 return UMA_LINUX_WINDOW_MANAGER_METACITY;
206 case ui::WM_MUFFIN:
207 return UMA_LINUX_WINDOW_MANAGER_MUFFIN;
208 case ui::WM_MUTTER:
209 return UMA_LINUX_WINDOW_MANAGER_MUTTER;
210 case ui::WM_NOTION:
211 return UMA_LINUX_WINDOW_MANAGER_NOTION;
212 case ui::WM_OPENBOX:
213 return UMA_LINUX_WINDOW_MANAGER_OPENBOX;
214 case ui::WM_QTILE:
215 return UMA_LINUX_WINDOW_MANAGER_QTILE;
216 case ui::WM_RATPOISON:
217 return UMA_LINUX_WINDOW_MANAGER_RATPOISON;
218 case ui::WM_STUMPWM:
219 return UMA_LINUX_WINDOW_MANAGER_STUMPWM;
220 case ui::WM_WMII:
221 return UMA_LINUX_WINDOW_MANAGER_WMII;
222 case ui::WM_XFWM4:
223 return UMA_LINUX_WINDOW_MANAGER_XFWM4;
225 return UMA_LINUX_WINDOW_MANAGER_OTHER;
227 #endif
229 void RecordTouchEventState() {
230 const base::CommandLine& command_line =
231 *base::CommandLine::ForCurrentProcess();
232 const std::string touch_enabled_switch =
233 command_line.HasSwitch(switches::kTouchEvents) ?
234 command_line.GetSwitchValueASCII(switches::kTouchEvents) :
235 switches::kTouchEventsAuto;
237 UMATouchEventsState state;
238 if (touch_enabled_switch.empty() ||
239 touch_enabled_switch == switches::kTouchEventsEnabled) {
240 state = UMA_TOUCH_EVENTS_ENABLED;
241 } else if (touch_enabled_switch == switches::kTouchEventsAuto) {
242 state = ui::IsTouchDevicePresent() ?
243 UMA_TOUCH_EVENTS_AUTO_ENABLED : UMA_TOUCH_EVENTS_AUTO_DISABLED;
244 } else if (touch_enabled_switch == switches::kTouchEventsDisabled) {
245 state = UMA_TOUCH_EVENTS_DISABLED;
246 } else {
247 NOTREACHED();
248 return;
251 UMA_HISTOGRAM_ENUMERATION("Touchscreen.TouchEventsEnabled", state,
252 UMA_TOUCH_EVENTS_STATE_COUNT);
255 #if defined(USE_OZONE) || defined(USE_X11)
257 // Asynchronously records the touch event state when the ui::DeviceDataManager
258 // completes a device scan.
259 class AsynchronousTouchEventStateRecorder
260 : public ui::InputDeviceEventObserver {
261 public:
262 AsynchronousTouchEventStateRecorder();
263 ~AsynchronousTouchEventStateRecorder() override;
265 // ui::InputDeviceEventObserver overrides.
266 void OnDeviceListsComplete() override;
268 private:
269 DISALLOW_COPY_AND_ASSIGN(AsynchronousTouchEventStateRecorder);
272 AsynchronousTouchEventStateRecorder::AsynchronousTouchEventStateRecorder() {
273 ui::DeviceDataManager::GetInstance()->AddObserver(this);
276 AsynchronousTouchEventStateRecorder::~AsynchronousTouchEventStateRecorder() {
277 ui::DeviceDataManager::GetInstance()->RemoveObserver(this);
280 void AsynchronousTouchEventStateRecorder::OnDeviceListsComplete() {
281 ui::DeviceDataManager::GetInstance()->RemoveObserver(this);
282 RecordTouchEventState();
285 #endif // defined(USE_OZONE) || defined(USE_X11)
287 } // namespace
289 ChromeBrowserMainExtraPartsMetrics::ChromeBrowserMainExtraPartsMetrics()
290 : display_count_(0), is_screen_observer_(false) {
293 ChromeBrowserMainExtraPartsMetrics::~ChromeBrowserMainExtraPartsMetrics() {
294 if (is_screen_observer_)
295 gfx::Screen::GetNativeScreen()->RemoveObserver(this);
298 void ChromeBrowserMainExtraPartsMetrics::PreProfileInit() {
299 RecordMicroArchitectureStats();
302 void ChromeBrowserMainExtraPartsMetrics::PreBrowserStart() {
303 about_flags::PrefServiceFlagsStorage flags_storage_(
304 g_browser_process->local_state());
305 about_flags::RecordUMAStatistics(&flags_storage_);
308 void ChromeBrowserMainExtraPartsMetrics::PostBrowserStart() {
309 RecordLinuxGlibcVersion();
310 #if defined(USE_X11) && !defined(OS_CHROMEOS)
311 UMA_HISTOGRAM_ENUMERATION("Linux.WindowManager",
312 GetLinuxWindowManager(),
313 UMA_LINUX_WINDOW_MANAGER_COUNT);
314 #endif
316 #if defined(USE_OZONE) || defined(USE_X11)
317 // The touch event state for X11 and Ozone based event sub-systems are based
318 // on device scans that happen asynchronously. So we may need to attach an
319 // observer to wait until these scans complete.
320 if (ui::DeviceDataManager::GetInstance()->device_lists_complete()) {
321 RecordTouchEventState();
322 } else {
323 input_device_event_observer_.reset(
324 new AsynchronousTouchEventStateRecorder());
326 #else
327 RecordTouchEventState();
328 #endif // defined(USE_OZONE) || defined(USE_X11)
330 #if defined(OS_MACOSX) && !defined(OS_IOS)
331 RecordMacMetrics();
332 #endif // defined(OS_MACOSX) && !defined(OS_IOS)
334 const int kStartupMetricsGatheringDelaySeconds = 45;
335 content::BrowserThread::GetBlockingPool()->PostDelayedTask(
336 FROM_HERE,
337 base::Bind(&RecordStartupMetricsOnBlockingPool),
338 base::TimeDelta::FromSeconds(kStartupMetricsGatheringDelaySeconds));
340 display_count_ = gfx::Screen::GetNativeScreen()->GetNumDisplays();
341 UMA_HISTOGRAM_COUNTS_100("Hardware.Display.Count.OnStartup", display_count_);
342 gfx::Screen::GetNativeScreen()->AddObserver(this);
343 is_screen_observer_ = true;
345 #if !defined(OS_ANDROID)
346 first_web_contents_profiler_ =
347 FirstWebContentsProfiler::CreateProfilerForFirstWebContents(this).Pass();
348 #endif // !defined(OS_ANDROID)
351 void ChromeBrowserMainExtraPartsMetrics::OnDisplayAdded(
352 const gfx::Display& new_display) {
353 EmitDisplaysChangedMetric();
356 void ChromeBrowserMainExtraPartsMetrics::OnDisplayRemoved(
357 const gfx::Display& old_display) {
358 EmitDisplaysChangedMetric();
361 void ChromeBrowserMainExtraPartsMetrics::OnDisplayMetricsChanged(
362 const gfx::Display& display,
363 uint32_t changed_metrics) {
366 void ChromeBrowserMainExtraPartsMetrics::ProfilerFinishedCollectingMetrics() {
367 first_web_contents_profiler_.reset();
370 void ChromeBrowserMainExtraPartsMetrics::EmitDisplaysChangedMetric() {
371 int display_count = gfx::Screen::GetNativeScreen()->GetNumDisplays();
372 if (display_count != display_count_) {
373 display_count_ = display_count;
374 UMA_HISTOGRAM_COUNTS_100("Hardware.Display.Count.OnChange", display_count_);
378 namespace chrome {
380 void AddMetricsExtraParts(ChromeBrowserMainParts* main_parts) {
381 main_parts->AddParts(new ChromeBrowserMainExtraPartsMetrics());
384 } // namespace chrome