blob: db64070cb808c251f2ae1003a4dfb6af27cbeb16 [file] [log] [blame]
[email protected]1df44b72012-01-19 05:20:341// Copyright (c) 2012 The Chromium Authors. All rights reserved.
license.botbf09a502008-08-24 00:55:552// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
initial.commit09911bf2008-07-26 23:55:294
[email protected]cd1adc22009-01-16 01:29:225#include "chrome/browser/metrics/metrics_log.h"
initial.commit09911bf2008-07-26 23:55:296
[email protected]76869ff2013-01-15 16:13:477#include <algorithm>
[email protected]1eeb5e02010-07-20 23:02:118#include <string>
9#include <vector>
10
[email protected]d1be67b2008-11-19 20:28:3811#include "base/basictypes.h"
[email protected]611ae29a2013-04-29 21:32:1912#include "base/bind.h"
[email protected]5c8f89f692013-07-18 11:13:2813#include "base/cpu.h"
[email protected]054c8012011-11-16 00:12:4214#include "base/lazy_instance.h"
[email protected]3b63f8f42011-03-28 01:54:1515#include "base/memory/scoped_ptr.h"
[email protected]85ed9d42010-06-08 22:37:4416#include "base/perftimer.h"
[email protected]3853a4c2013-02-11 17:15:5717#include "base/prefs/pref_registry_simple.h"
18#include "base/prefs/pref_service.h"
[email protected]ed0fd002012-04-25 23:10:3419#include "base/profiler/alternate_timer.h"
[email protected]3ea1b182013-02-08 22:38:4120#include "base/strings/string_number_conversions.h"
[email protected]f9b294362013-06-10 20:22:3121#include "base/strings/string_util.h"
[email protected]112158af2013-06-07 23:46:1822#include "base/strings/utf_string_conversions.h"
[email protected]fadf97f2008-09-18 12:18:1423#include "base/sys_info.h"
[email protected]37f39e42010-01-06 17:35:1724#include "base/third_party/nspr/prtime.h"
[email protected]84813472013-06-28 00:25:1925#include "base/time/time.h"
[email protected]ed0fd002012-04-25 23:10:3426#include "base/tracked_objects.h"
[email protected]9f8bc2f2012-07-03 16:26:5327#include "chrome/browser/autocomplete/autocomplete_input.h"
[email protected]9ac40092010-10-27 23:05:2628#include "chrome/browser/autocomplete/autocomplete_match.h"
[email protected]30f5bc92012-06-26 04:14:5529#include "chrome/browser/autocomplete/autocomplete_provider.h"
[email protected]73c2b1632012-07-02 22:51:3830#include "chrome/browser/autocomplete/autocomplete_result.h"
initial.commit09911bf2008-07-26 23:55:2931#include "chrome/browser/browser_process.h"
[email protected]24b9bb392013-01-29 20:29:2932#include "chrome/browser/google/google_util.h"
[email protected]0fafc8d2013-06-01 00:09:5033#include "chrome/browser/omnibox/omnibox_log.h"
[email protected]0f5e57f52012-09-20 20:53:1834#include "chrome/browser/plugins/plugin_prefs.h"
[email protected]10084982011-08-19 17:56:5635#include "chrome/browser/profiles/profile_manager.h"
[email protected]1eeb5e02010-07-20 23:02:1136#include "chrome/common/chrome_version_info.h"
initial.commit09911bf2008-07-26 23:55:2937#include "chrome/common/logging_chrome.h"
[email protected]fe58acc22012-02-29 01:29:5838#include "chrome/common/metrics/proto/omnibox_event.pb.h"
[email protected]ed0fd002012-04-25 23:10:3439#include "chrome/common/metrics/proto/profiler_event.pb.h"
[email protected]fe58acc22012-02-29 01:29:5840#include "chrome/common/metrics/proto/system_profile.pb.h"
[email protected]cf265dc02012-08-15 01:01:1641#include "chrome/common/metrics/variations/variations_util.h"
initial.commit09911bf2008-07-26 23:55:2942#include "chrome/common/pref_names.h"
[email protected]197c0772012-05-14 23:50:5143#include "chrome/installer/util/google_update_settings.h"
[email protected]d5d383252013-07-04 14:44:3244#include "components/nacl/common/nacl_process_type.h"
[email protected]79078df2012-02-16 01:22:3245#include "content/public/browser/gpu_data_manager.h"
[email protected]1a838cc2012-04-24 22:06:4946#include "content/public/common/content_client.h"
[email protected]d7bd3e52013-07-21 04:29:2047#include "content/public/common/webplugininfo.h"
[email protected]611ae29a2013-04-29 21:32:1948#include "device/bluetooth/bluetooth_adapter.h"
49#include "device/bluetooth/bluetooth_adapter_factory.h"
50#include "device/bluetooth/bluetooth_device.h"
[email protected]d7b5cc72013-05-23 20:05:0051#include "gpu/config/gpu_info.h"
[email protected]6b7d954ff2011-10-25 00:39:3552#include "ui/gfx/screen.h"
[email protected]761fa4702013-07-02 15:25:1553#include "url/gurl.h"
initial.commit09911bf2008-07-26 23:55:2954
[email protected]5106b3a2012-10-03 20:10:4455#if defined(OS_ANDROID)
56#include "base/android/build_info.h"
57#endif
58
[email protected]d1be67b2008-11-19 20:28:3859#if defined(OS_WIN)
[email protected]1bb25e02012-08-03 22:39:3960#include "base/win/metro.h"
[email protected]e245ace92013-05-07 00:37:4161#include "ui/base/win/dpi.h"
[email protected]1bb25e02012-08-03 22:39:3962
63// http://blogs.msdn.com/oldnewthing/archive/2004/10/25/247180.aspx
[email protected]d1be67b2008-11-19 20:28:3864extern "C" IMAGE_DOS_HEADER __ImageBase;
65#endif
66
[email protected]79078df2012-02-16 01:22:3267using content::GpuDataManager;
[email protected]fe58acc22012-02-29 01:29:5868using metrics::OmniboxEventProto;
[email protected]f65859e2013-02-04 20:00:2569using metrics::PerfDataProto;
[email protected]ed0fd002012-04-25 23:10:3470using metrics::ProfilerEventProto;
[email protected]fe58acc22012-02-29 01:29:5871using metrics::SystemProfileProto;
[email protected]ed0fd002012-04-25 23:10:3472using tracked_objects::ProcessDataSnapshot;
[email protected]0c8b7ad2012-11-06 07:08:1473typedef chrome_variations::ActiveGroupId ActiveGroupId;
[email protected]197c0772012-05-14 23:50:5174typedef SystemProfileProto::GoogleUpdate::ProductInfo ProductInfo;
[email protected]611ae29a2013-04-29 21:32:1975typedef SystemProfileProto::Hardware::Bluetooth::PairedDevice PairedDevice;
[email protected]79078df2012-02-16 01:22:3276
[email protected]1df44b72012-01-19 05:20:3477namespace {
78
79// Returns the date at which the current metrics client ID was created as
[email protected]ca5ac4b2012-12-14 07:46:4080// a string containing seconds since the epoch, or "0" if none was found.
[email protected]cc5d7f42012-10-30 00:30:0981std::string GetMetricsEnabledDate(PrefService* pref) {
[email protected]767c9d92012-03-02 16:04:3482 if (!pref) {
[email protected]1df44b72012-01-19 05:20:3483 NOTREACHED();
84 return "0";
85 }
[email protected]767c9d92012-03-02 16:04:3486
87 return pref->GetString(prefs::kMetricsClientIDTimestamp);
[email protected]1df44b72012-01-19 05:20:3488}
89
[email protected]fe58acc22012-02-29 01:29:5890OmniboxEventProto::InputType AsOmniboxEventInputType(
91 AutocompleteInput::Type type) {
92 switch (type) {
93 case AutocompleteInput::INVALID:
94 return OmniboxEventProto::INVALID;
95 case AutocompleteInput::UNKNOWN:
96 return OmniboxEventProto::UNKNOWN;
[email protected]fe58acc22012-02-29 01:29:5897 case AutocompleteInput::URL:
98 return OmniboxEventProto::URL;
99 case AutocompleteInput::QUERY:
100 return OmniboxEventProto::QUERY;
101 case AutocompleteInput::FORCED_QUERY:
102 return OmniboxEventProto::FORCED_QUERY;
103 default:
104 NOTREACHED();
105 return OmniboxEventProto::INVALID;
106 }
107}
108
[email protected]fe58acc22012-02-29 01:29:58109OmniboxEventProto::Suggestion::ResultType AsOmniboxEventResultType(
110 AutocompleteMatch::Type type) {
111 switch (type) {
[email protected]b7f64d742013-05-21 04:04:04112 case AutocompleteMatchType::URL_WHAT_YOU_TYPED:
[email protected]fe58acc22012-02-29 01:29:58113 return OmniboxEventProto::Suggestion::URL_WHAT_YOU_TYPED;
[email protected]b7f64d742013-05-21 04:04:04114 case AutocompleteMatchType::HISTORY_URL:
[email protected]fe58acc22012-02-29 01:29:58115 return OmniboxEventProto::Suggestion::HISTORY_URL;
[email protected]b7f64d742013-05-21 04:04:04116 case AutocompleteMatchType::HISTORY_TITLE:
[email protected]fe58acc22012-02-29 01:29:58117 return OmniboxEventProto::Suggestion::HISTORY_TITLE;
[email protected]b7f64d742013-05-21 04:04:04118 case AutocompleteMatchType::HISTORY_BODY:
[email protected]fe58acc22012-02-29 01:29:58119 return OmniboxEventProto::Suggestion::HISTORY_BODY;
[email protected]b7f64d742013-05-21 04:04:04120 case AutocompleteMatchType::HISTORY_KEYWORD:
[email protected]fe58acc22012-02-29 01:29:58121 return OmniboxEventProto::Suggestion::HISTORY_KEYWORD;
[email protected]b7f64d742013-05-21 04:04:04122 case AutocompleteMatchType::NAVSUGGEST:
[email protected]fe58acc22012-02-29 01:29:58123 return OmniboxEventProto::Suggestion::NAVSUGGEST;
[email protected]b7f64d742013-05-21 04:04:04124 case AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED:
[email protected]fe58acc22012-02-29 01:29:58125 return OmniboxEventProto::Suggestion::SEARCH_WHAT_YOU_TYPED;
[email protected]b7f64d742013-05-21 04:04:04126 case AutocompleteMatchType::SEARCH_HISTORY:
[email protected]fe58acc22012-02-29 01:29:58127 return OmniboxEventProto::Suggestion::SEARCH_HISTORY;
[email protected]b7f64d742013-05-21 04:04:04128 case AutocompleteMatchType::SEARCH_SUGGEST:
[email protected]fe58acc22012-02-29 01:29:58129 return OmniboxEventProto::Suggestion::SEARCH_SUGGEST;
[email protected]b7f64d742013-05-21 04:04:04130 case AutocompleteMatchType::SEARCH_OTHER_ENGINE:
[email protected]fe58acc22012-02-29 01:29:58131 return OmniboxEventProto::Suggestion::SEARCH_OTHER_ENGINE;
[email protected]b7f64d742013-05-21 04:04:04132 case AutocompleteMatchType::EXTENSION_APP:
[email protected]fe58acc22012-02-29 01:29:58133 return OmniboxEventProto::Suggestion::EXTENSION_APP;
[email protected]b7f64d742013-05-21 04:04:04134 case AutocompleteMatchType::CONTACT:
[email protected]dbacefb2012-09-12 03:32:06135 return OmniboxEventProto::Suggestion::CONTACT;
[email protected]b7f64d742013-05-21 04:04:04136 case AutocompleteMatchType::BOOKMARK_TITLE:
[email protected]25320602012-10-18 22:05:56137 return OmniboxEventProto::Suggestion::BOOKMARK_TITLE;
[email protected]fe58acc22012-02-29 01:29:58138 default:
139 NOTREACHED();
140 return OmniboxEventProto::Suggestion::UNKNOWN_RESULT_TYPE;
141 }
142}
143
[email protected]3c919d6a2013-07-28 18:35:52144OmniboxEventProto::PageClassification AsOmniboxEventPageClassification(
145 AutocompleteInput::PageClassification page_classification) {
146 switch (page_classification) {
147 case AutocompleteInput::INVALID_SPEC:
148 return OmniboxEventProto::INVALID_SPEC;
149 case AutocompleteInput::NEW_TAB_PAGE:
150 return OmniboxEventProto::NEW_TAB_PAGE;
151 case AutocompleteInput::BLANK:
152 return OmniboxEventProto::BLANK;
153 case AutocompleteInput::HOMEPAGE:
154 return OmniboxEventProto::HOMEPAGE;
155 case AutocompleteInput::OTHER:
156 return OmniboxEventProto::OTHER;
157 case AutocompleteInput::INSTANT_NEW_TAB_PAGE:
158 return OmniboxEventProto::INSTANT_NEW_TAB_PAGE;
159 case AutocompleteInput::SEARCH_RESULT_PAGE_DOING_SEARCH_TERM_REPLACEMENT:
160 return OmniboxEventProto::
161 SEARCH_RESULT_PAGE_DOING_SEARCH_TERM_REPLACEMENT;
162 }
163 return OmniboxEventProto::INVALID_SPEC;
164}
165
[email protected]ed0fd002012-04-25 23:10:34166ProfilerEventProto::TrackedObject::ProcessType AsProtobufProcessType(
[email protected]f3b357692013-03-22 05:16:13167 int process_type) {
[email protected]ed0fd002012-04-25 23:10:34168 switch (process_type) {
169 case content::PROCESS_TYPE_BROWSER:
170 return ProfilerEventProto::TrackedObject::BROWSER;
171 case content::PROCESS_TYPE_RENDERER:
172 return ProfilerEventProto::TrackedObject::RENDERER;
173 case content::PROCESS_TYPE_PLUGIN:
174 return ProfilerEventProto::TrackedObject::PLUGIN;
175 case content::PROCESS_TYPE_WORKER:
176 return ProfilerEventProto::TrackedObject::WORKER;
[email protected]ed0fd002012-04-25 23:10:34177 case content::PROCESS_TYPE_UTILITY:
178 return ProfilerEventProto::TrackedObject::UTILITY;
[email protected]ed0fd002012-04-25 23:10:34179 case content::PROCESS_TYPE_ZYGOTE:
180 return ProfilerEventProto::TrackedObject::ZYGOTE;
181 case content::PROCESS_TYPE_SANDBOX_HELPER:
182 return ProfilerEventProto::TrackedObject::SANDBOX_HELPER;
[email protected]ed0fd002012-04-25 23:10:34183 case content::PROCESS_TYPE_GPU:
184 return ProfilerEventProto::TrackedObject::GPU;
185 case content::PROCESS_TYPE_PPAPI_PLUGIN:
186 return ProfilerEventProto::TrackedObject::PPAPI_PLUGIN;
187 case content::PROCESS_TYPE_PPAPI_BROKER:
188 return ProfilerEventProto::TrackedObject::PPAPI_BROKER;
[email protected]f3b357692013-03-22 05:16:13189 case PROCESS_TYPE_NACL_LOADER:
190 return ProfilerEventProto::TrackedObject::NACL_LOADER;
191 case PROCESS_TYPE_NACL_BROKER:
192 return ProfilerEventProto::TrackedObject::NACL_BROKER;
[email protected]ed0fd002012-04-25 23:10:34193 default:
194 NOTREACHED();
195 return ProfilerEventProto::TrackedObject::UNKNOWN;
196 }
197}
198
[email protected]1df44b72012-01-19 05:20:34199// Returns the plugin preferences corresponding for this user, if available.
200// If multiple user profiles are loaded, returns the preferences corresponding
201// to an arbitrary one of the profiles.
202PluginPrefs* GetPluginPrefs() {
203 ProfileManager* profile_manager = g_browser_process->profile_manager();
[email protected]fe58acc22012-02-29 01:29:58204
205 if (!profile_manager) {
206 // The profile manager can be NULL when testing.
207 return NULL;
208 }
209
[email protected]1df44b72012-01-19 05:20:34210 std::vector<Profile*> profiles = profile_manager->GetLoadedProfiles();
211 if (profiles.empty())
212 return NULL;
213
[email protected]cadac622013-06-11 16:46:36214 return PluginPrefs::GetForProfile(profiles.front()).get();
[email protected]1df44b72012-01-19 05:20:34215}
216
[email protected]fe58acc22012-02-29 01:29:58217// Fills |plugin| with the info contained in |plugin_info| and |plugin_prefs|.
[email protected]d7bd3e52013-07-21 04:29:20218void SetPluginInfo(const content::WebPluginInfo& plugin_info,
[email protected]fe58acc22012-02-29 01:29:58219 const PluginPrefs* plugin_prefs,
220 SystemProfileProto::Plugin* plugin) {
221 plugin->set_name(UTF16ToUTF8(plugin_info.name));
222 plugin->set_filename(plugin_info.path.BaseName().AsUTF8Unsafe());
223 plugin->set_version(UTF16ToUTF8(plugin_info.version));
224 if (plugin_prefs)
225 plugin->set_is_disabled(!plugin_prefs->IsPluginEnabled(plugin_info));
226}
227
[email protected]0c8b7ad2012-11-06 07:08:14228void WriteFieldTrials(const std::vector<ActiveGroupId>& field_trial_ids,
[email protected]767c9d92012-03-02 16:04:34229 SystemProfileProto* system_profile) {
[email protected]0c8b7ad2012-11-06 07:08:14230 for (std::vector<ActiveGroupId>::const_iterator it =
[email protected]ad2461c2012-04-27 21:11:03231 field_trial_ids.begin(); it != field_trial_ids.end(); ++it) {
[email protected]767c9d92012-03-02 16:04:34232 SystemProfileProto::FieldTrial* field_trial =
233 system_profile->add_field_trial();
234 field_trial->set_name_id(it->name);
235 field_trial->set_group_id(it->group);
236 }
237}
238
[email protected]ed0fd002012-04-25 23:10:34239void WriteProfilerData(const ProcessDataSnapshot& profiler_data,
[email protected]f3b357692013-03-22 05:16:13240 int process_type,
[email protected]ed0fd002012-04-25 23:10:34241 ProfilerEventProto* performance_profile) {
242 for (std::vector<tracked_objects::TaskSnapshot>::const_iterator it =
243 profiler_data.tasks.begin();
244 it != profiler_data.tasks.end(); ++it) {
[email protected]ed0fd002012-04-25 23:10:34245 const tracked_objects::DeathDataSnapshot& death_data = it->death_data;
246 ProfilerEventProto::TrackedObject* tracked_object =
247 performance_profile->add_tracked_object();
[email protected]db7fec832013-07-18 09:41:41248 tracked_object->set_birth_thread_name_hash(
249 MetricsLogBase::Hash(it->birth.thread_name));
250 tracked_object->set_exec_thread_name_hash(
251 MetricsLogBase::Hash(it->death_thread_name));
252 tracked_object->set_source_file_name_hash(
253 MetricsLogBase::Hash(it->birth.location.file_name));
254 tracked_object->set_source_function_name_hash(
255 MetricsLogBase::Hash(it->birth.location.function_name));
[email protected]ed0fd002012-04-25 23:10:34256 tracked_object->set_source_line_number(it->birth.location.line_number);
257 tracked_object->set_exec_count(death_data.count);
258 tracked_object->set_exec_time_total(death_data.run_duration_sum);
259 tracked_object->set_exec_time_sampled(death_data.run_duration_sample);
260 tracked_object->set_queue_time_total(death_data.queue_duration_sum);
261 tracked_object->set_queue_time_sampled(death_data.queue_duration_sample);
262 tracked_object->set_process_type(AsProtobufProcessType(process_type));
263 tracked_object->set_process_id(profiler_data.process_id);
264 }
265}
266
[email protected]59a7ae4e2012-10-01 23:54:44267#if defined(GOOGLE_CHROME_BUILD) && defined(OS_WIN)
[email protected]197c0772012-05-14 23:50:51268void ProductDataToProto(const GoogleUpdateSettings::ProductData& product_data,
269 ProductInfo* product_info) {
270 product_info->set_version(product_data.version);
271 product_info->set_last_update_success_timestamp(
272 product_data.last_success.ToTimeT());
273 product_info->set_last_error(product_data.last_error_code);
274 product_info->set_last_extra_error(product_data.last_extra_code);
275 if (ProductInfo::InstallResult_IsValid(product_data.last_result)) {
276 product_info->set_last_result(
277 static_cast<ProductInfo::InstallResult>(product_data.last_result));
278 }
279}
[email protected]59a7ae4e2012-10-01 23:54:44280#endif
[email protected]197c0772012-05-14 23:50:51281
[email protected]76869ff2013-01-15 16:13:47282#if defined(OS_WIN)
[email protected]ffaf7322013-05-15 00:26:11283struct ScreenDPIInformation {
[email protected]76869ff2013-01-15 16:13:47284 double max_dpi_x;
285 double max_dpi_y;
286};
287
288// Called once for each connected monitor.
289BOOL CALLBACK GetMonitorDPICallback(HMONITOR, HDC hdc, LPRECT, LPARAM dwData) {
290 const double kMillimetersPerInch = 25.4;
291 ScreenDPIInformation* screen_info =
292 reinterpret_cast<ScreenDPIInformation*>(dwData);
293 // Size of screen, in mm.
294 DWORD size_x = GetDeviceCaps(hdc, HORZSIZE);
295 DWORD size_y = GetDeviceCaps(hdc, VERTSIZE);
296 double dpi_x = (size_x > 0) ?
297 GetDeviceCaps(hdc, HORZRES) / (size_x / kMillimetersPerInch) : 0;
298 double dpi_y = (size_y > 0) ?
299 GetDeviceCaps(hdc, VERTRES) / (size_y / kMillimetersPerInch) : 0;
[email protected]e245ace92013-05-07 00:37:41300 dpi_x *= ui::win::GetUndocumentedDPIScale();
301 dpi_y *= ui::win::GetUndocumentedDPIScale();
[email protected]76869ff2013-01-15 16:13:47302 screen_info->max_dpi_x = std::max(dpi_x, screen_info->max_dpi_x);
303 screen_info->max_dpi_y = std::max(dpi_y, screen_info->max_dpi_y);
304 return TRUE;
305}
306
307void WriteScreenDPIInformationProto(SystemProfileProto::Hardware* hardware) {
308 HDC desktop_dc = GetDC(NULL);
309 if (desktop_dc) {
[email protected]ffaf7322013-05-15 00:26:11310 ScreenDPIInformation si = {0, 0};
[email protected]76869ff2013-01-15 16:13:47311 if (EnumDisplayMonitors(desktop_dc, NULL, GetMonitorDPICallback,
312 reinterpret_cast<LPARAM>(&si))) {
313 hardware->set_max_dpi_x(si.max_dpi_x);
314 hardware->set_max_dpi_y(si.max_dpi_y);
315 }
316 ReleaseDC(GetDesktopWindow(), desktop_dc);
317 }
318}
319
320#endif // defined(OS_WIN)
321
[email protected]611ae29a2013-04-29 21:32:19322#if defined(OS_CHROMEOS)
323PairedDevice::Type AsBluetoothDeviceType(
324 enum device::BluetoothDevice::DeviceType device_type) {
325 switch (device_type) {
326 case device::BluetoothDevice::DEVICE_UNKNOWN:
327 return PairedDevice::DEVICE_UNKNOWN;
328 case device::BluetoothDevice::DEVICE_COMPUTER:
329 return PairedDevice::DEVICE_COMPUTER;
330 case device::BluetoothDevice::DEVICE_PHONE:
331 return PairedDevice::DEVICE_PHONE;
332 case device::BluetoothDevice::DEVICE_MODEM:
333 return PairedDevice::DEVICE_MODEM;
334 case device::BluetoothDevice::DEVICE_AUDIO:
335 return PairedDevice::DEVICE_AUDIO;
336 case device::BluetoothDevice::DEVICE_CAR_AUDIO:
337 return PairedDevice::DEVICE_CAR_AUDIO;
338 case device::BluetoothDevice::DEVICE_VIDEO:
339 return PairedDevice::DEVICE_VIDEO;
340 case device::BluetoothDevice::DEVICE_PERIPHERAL:
341 return PairedDevice::DEVICE_PERIPHERAL;
342 case device::BluetoothDevice::DEVICE_JOYSTICK:
343 return PairedDevice::DEVICE_JOYSTICK;
344 case device::BluetoothDevice::DEVICE_GAMEPAD:
345 return PairedDevice::DEVICE_GAMEPAD;
346 case device::BluetoothDevice::DEVICE_KEYBOARD:
347 return PairedDevice::DEVICE_KEYBOARD;
348 case device::BluetoothDevice::DEVICE_MOUSE:
349 return PairedDevice::DEVICE_MOUSE;
350 case device::BluetoothDevice::DEVICE_TABLET:
351 return PairedDevice::DEVICE_TABLET;
352 case device::BluetoothDevice::DEVICE_KEYBOARD_MOUSE_COMBO:
353 return PairedDevice::DEVICE_KEYBOARD_MOUSE_COMBO;
354 }
355
356 NOTREACHED();
357 return PairedDevice::DEVICE_UNKNOWN;
358}
359#endif // defined(OS_CHROMEOS)
360
[email protected]86573d12013-07-11 19:48:32361// Round a timestamp measured in seconds since epoch to one with a granularity
362// of an hour. This can be used before uploaded potentially sensitive
363// timestamps.
364int64 RoundSecondsToHour(int64 time_in_seconds) {
365 return 3600 * (time_in_seconds / 3600);
366}
367
[email protected]1df44b72012-01-19 05:20:34368} // namespace
369
[email protected]197c0772012-05-14 23:50:51370GoogleUpdateMetrics::GoogleUpdateMetrics() : is_system_install(false) {}
371
372GoogleUpdateMetrics::~GoogleUpdateMetrics() {}
373
[email protected]67f92bc32012-01-26 01:56:19374static base::LazyInstance<std::string>::Leaky
[email protected]054c8012011-11-16 00:12:42375 g_version_extension = LAZY_INSTANCE_INITIALIZER;
376
[email protected]1226abb2010-06-10 18:01:28377MetricsLog::MetricsLog(const std::string& client_id, int session_id)
[email protected]5eae204c2013-02-13 15:53:42378 : MetricsLogBase(client_id, session_id, MetricsLog::GetVersionString()) {}
[email protected]5ed7d4572009-12-23 17:42:41379
[email protected]1226abb2010-06-10 18:01:28380MetricsLog::~MetricsLog() {}
initial.commit09911bf2008-07-26 23:55:29381
382// static
[email protected]b1de2c72013-02-06 02:45:47383void MetricsLog::RegisterPrefs(PrefRegistrySimple* registry) {
384 registry->RegisterListPref(prefs::kStabilityPluginStats);
initial.commit09911bf2008-07-26 23:55:29385}
386
[email protected]1df44b72012-01-19 05:20:34387// static
[email protected]9165f742010-03-10 22:55:01388int64 MetricsLog::GetIncrementalUptime(PrefService* pref) {
389 base::TimeTicks now = base::TimeTicks::Now();
390 static base::TimeTicks last_updated_time(now);
391 int64 incremental_time = (now - last_updated_time).InSeconds();
392 last_updated_time = now;
393
394 if (incremental_time > 0) {
395 int64 metrics_uptime = pref->GetInt64(prefs::kUninstallMetricsUptimeSec);
396 metrics_uptime += incremental_time;
397 pref->SetInt64(prefs::kUninstallMetricsUptimeSec, metrics_uptime);
398 }
399
400 return incremental_time;
401}
402
[email protected]1226abb2010-06-10 18:01:28403// static
404std::string MetricsLog::GetVersionString() {
[email protected]0211f57e2010-08-27 20:28:42405 chrome::VersionInfo version_info;
[email protected]30c91802010-12-18 00:40:17406 if (!version_info.is_valid()) {
407 NOTREACHED() << "Unable to retrieve version info.";
408 return std::string();
409 }
410
[email protected]0211f57e2010-08-27 20:28:42411 std::string version = version_info.Version();
[email protected]054c8012011-11-16 00:12:42412 if (!version_extension().empty())
413 version += version_extension();
[email protected]0211f57e2010-08-27 20:28:42414 if (!version_info.IsOfficialBuild())
415 version.append("-devel");
416 return version;
[email protected]1226abb2010-06-10 18:01:28417}
418
[email protected]054c8012011-11-16 00:12:42419// static
420void MetricsLog::set_version_extension(const std::string& extension) {
421 g_version_extension.Get() = extension;
422}
423
424// static
425const std::string& MetricsLog::version_extension() {
426 return g_version_extension.Get();
427}
428
[email protected]fe58acc22012-02-29 01:29:58429void MetricsLog::RecordIncrementalStabilityElements(
[email protected]d7bd3e52013-07-21 04:29:20430 const std::vector<content::WebPluginInfo>& plugin_list) {
[email protected]767c9d92012-03-02 16:04:34431 DCHECK(!locked());
[email protected]0b33f80b2008-12-17 21:34:36432
[email protected]767c9d92012-03-02 16:04:34433 PrefService* pref = GetPrefService();
[email protected]0b33f80b2008-12-17 21:34:36434 DCHECK(pref);
435
[email protected]f31a01a2013-07-13 02:51:11436 WriteRequiredStabilityAttributes(pref);
437 WriteRealtimeStabilityAttributes(pref);
438 WritePluginStabilityElements(plugin_list, pref);
[email protected]0b33f80b2008-12-17 21:34:36439}
440
[email protected]767c9d92012-03-02 16:04:34441PrefService* MetricsLog::GetPrefService() {
442 return g_browser_process->local_state();
443}
444
445gfx::Size MetricsLog::GetScreenSize() const {
[email protected]ffabb1e2012-10-12 19:51:17446 return gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().GetSizeInPixel();
[email protected]767c9d92012-03-02 16:04:34447}
448
[email protected]aa96417972012-08-22 03:16:44449float MetricsLog::GetScreenDeviceScaleFactor() const {
[email protected]ffabb1e2012-10-12 19:51:17450 return gfx::Screen::GetNativeScreen()->
451 GetPrimaryDisplay().device_scale_factor();
[email protected]aa96417972012-08-22 03:16:44452}
453
[email protected]767c9d92012-03-02 16:04:34454int MetricsLog::GetScreenCount() const {
[email protected]ffabb1e2012-10-12 19:51:17455 // TODO(scottmg): NativeScreen maybe wrong. http://crbug.com/133312
456 return gfx::Screen::GetNativeScreen()->GetNumDisplays();
[email protected]767c9d92012-03-02 16:04:34457}
458
[email protected]767c9d92012-03-02 16:04:34459void MetricsLog::GetFieldTrialIds(
[email protected]0c8b7ad2012-11-06 07:08:14460 std::vector<ActiveGroupId>* field_trial_ids) const {
461 chrome_variations::GetFieldTrialActiveGroupIds(field_trial_ids);
[email protected]767c9d92012-03-02 16:04:34462}
463
[email protected]fe58acc22012-02-29 01:29:58464void MetricsLog::WriteStabilityElement(
[email protected]d7bd3e52013-07-21 04:29:20465 const std::vector<content::WebPluginInfo>& plugin_list,
[email protected]fe58acc22012-02-29 01:29:58466 PrefService* pref) {
[email protected]767c9d92012-03-02 16:04:34467 DCHECK(!locked());
initial.commit09911bf2008-07-26 23:55:29468
initial.commit09911bf2008-07-26 23:55:29469 // Get stability attributes out of Local State, zeroing out stored values.
470 // NOTE: This could lead to some data loss if this report isn't successfully
471 // sent, but that's true for all the metrics.
472
[email protected]147bbc0b2009-01-06 19:37:40473 WriteRequiredStabilityAttributes(pref);
474 WriteRealtimeStabilityAttributes(pref);
initial.commit09911bf2008-07-26 23:55:29475
[email protected]fe58acc22012-02-29 01:29:58476 int incomplete_shutdown_count =
477 pref->GetInteger(prefs::kStabilityIncompleteSessionEndCount);
[email protected]e324f6b2012-02-28 05:43:37478 pref->SetInteger(prefs::kStabilityIncompleteSessionEndCount, 0);
[email protected]fe58acc22012-02-29 01:29:58479 int breakpad_registration_success_count =
480 pref->GetInteger(prefs::kStabilityBreakpadRegistrationSuccess);
[email protected]e324f6b2012-02-28 05:43:37481 pref->SetInteger(prefs::kStabilityBreakpadRegistrationSuccess, 0);
[email protected]fe58acc22012-02-29 01:29:58482 int breakpad_registration_failure_count =
483 pref->GetInteger(prefs::kStabilityBreakpadRegistrationFail);
[email protected]e324f6b2012-02-28 05:43:37484 pref->SetInteger(prefs::kStabilityBreakpadRegistrationFail, 0);
[email protected]fe58acc22012-02-29 01:29:58485 int debugger_present_count =
486 pref->GetInteger(prefs::kStabilityDebuggerPresent);
[email protected]e324f6b2012-02-28 05:43:37487 pref->SetInteger(prefs::kStabilityDebuggerPresent, 0);
[email protected]fe58acc22012-02-29 01:29:58488 int debugger_not_present_count =
489 pref->GetInteger(prefs::kStabilityDebuggerNotPresent);
[email protected]e324f6b2012-02-28 05:43:37490 pref->SetInteger(prefs::kStabilityDebuggerNotPresent, 0);
[email protected]b2a4812d2012-02-28 05:31:31491
[email protected]fe58acc22012-02-29 01:29:58492 // TODO(jar): The following are all optional, so we *could* optimize them for
493 // values of zero (and not include them).
[email protected]fe58acc22012-02-29 01:29:58494 SystemProfileProto::Stability* stability =
[email protected]767c9d92012-03-02 16:04:34495 uma_proto()->mutable_system_profile()->mutable_stability();
[email protected]fe58acc22012-02-29 01:29:58496 stability->set_incomplete_shutdown_count(incomplete_shutdown_count);
497 stability->set_breakpad_registration_success_count(
498 breakpad_registration_success_count);
499 stability->set_breakpad_registration_failure_count(
500 breakpad_registration_failure_count);
501 stability->set_debugger_present_count(debugger_present_count);
502 stability->set_debugger_not_present_count(debugger_not_present_count);
503
504 WritePluginStabilityElements(plugin_list, pref);
[email protected]147bbc0b2009-01-06 19:37:40505}
506
[email protected]fe58acc22012-02-29 01:29:58507void MetricsLog::WritePluginStabilityElements(
[email protected]d7bd3e52013-07-21 04:29:20508 const std::vector<content::WebPluginInfo>& plugin_list,
[email protected]fe58acc22012-02-29 01:29:58509 PrefService* pref) {
[email protected]147bbc0b2009-01-06 19:37:40510 // Now log plugin stability info.
initial.commit09911bf2008-07-26 23:55:29511 const ListValue* plugin_stats_list = pref->GetList(
512 prefs::kStabilityPluginStats);
[email protected]1df44b72012-01-19 05:20:34513 if (!plugin_stats_list)
514 return;
initial.commit09911bf2008-07-26 23:55:29515
[email protected]ebd71962012-12-20 02:56:55516#if defined(ENABLE_PLUGINS)
[email protected]fe58acc22012-02-29 01:29:58517 SystemProfileProto::Stability* stability =
[email protected]767c9d92012-03-02 16:04:34518 uma_proto()->mutable_system_profile()->mutable_stability();
[email protected]fe58acc22012-02-29 01:29:58519 PluginPrefs* plugin_prefs = GetPluginPrefs();
[email protected]1df44b72012-01-19 05:20:34520 for (ListValue::const_iterator iter = plugin_stats_list->begin();
521 iter != plugin_stats_list->end(); ++iter) {
522 if (!(*iter)->IsType(Value::TYPE_DICTIONARY)) {
523 NOTREACHED();
524 continue;
initial.commit09911bf2008-07-26 23:55:29525 }
[email protected]1df44b72012-01-19 05:20:34526 DictionaryValue* plugin_dict = static_cast<DictionaryValue*>(*iter);
initial.commit09911bf2008-07-26 23:55:29527
[email protected]fe58acc22012-02-29 01:29:58528 // Write the protobuf version.
529 // Note that this search is potentially a quadratic operation, but given the
530 // low number of plugins installed on a "reasonable" setup, this should be
531 // fine.
532 // TODO(isherman): Verify that this does not show up as a hotspot in
533 // profiler runs.
[email protected]d7bd3e52013-07-21 04:29:20534 const content::WebPluginInfo* plugin_info = NULL;
[email protected]f31a01a2013-07-13 02:51:11535 std::string plugin_name;
536 plugin_dict->GetString(prefs::kStabilityPluginName, &plugin_name);
[email protected]fe58acc22012-02-29 01:29:58537 const string16 plugin_name_utf16 = UTF8ToUTF16(plugin_name);
[email protected]d7bd3e52013-07-21 04:29:20538 for (std::vector<content::WebPluginInfo>::const_iterator iter =
[email protected]fe58acc22012-02-29 01:29:58539 plugin_list.begin();
540 iter != plugin_list.end(); ++iter) {
541 if (iter->name == plugin_name_utf16) {
542 plugin_info = &(*iter);
543 break;
544 }
545 }
546
547 if (!plugin_info) {
548 NOTREACHED();
549 continue;
550 }
[email protected]fe58acc22012-02-29 01:29:58551
[email protected]fe58acc22012-02-29 01:29:58552 SystemProfileProto::Stability::PluginStability* plugin_stability =
553 stability->add_plugin_stability();
554 SetPluginInfo(*plugin_info, plugin_prefs,
555 plugin_stability->mutable_plugin());
[email protected]f31a01a2013-07-13 02:51:11556
557 int launches = 0;
558 plugin_dict->GetInteger(prefs::kStabilityPluginLaunches, &launches);
559 if (launches > 0)
560 plugin_stability->set_launch_count(launches);
561
562 int instances = 0;
563 plugin_dict->GetInteger(prefs::kStabilityPluginInstances, &instances);
564 if (instances > 0)
565 plugin_stability->set_instance_count(instances);
566
567 int crashes = 0;
568 plugin_dict->GetInteger(prefs::kStabilityPluginCrashes, &crashes);
569 if (crashes > 0)
570 plugin_stability->set_crash_count(crashes);
571
572 int loading_errors = 0;
573 plugin_dict->GetInteger(prefs::kStabilityPluginLoadingErrors,
574 &loading_errors);
575 if (loading_errors > 0)
576 plugin_stability->set_loading_error_count(loading_errors);
initial.commit09911bf2008-07-26 23:55:29577 }
[email protected]ebd71962012-12-20 02:56:55578#endif // defined(ENABLE_PLUGINS)
[email protected]1df44b72012-01-19 05:20:34579
580 pref->ClearPref(prefs::kStabilityPluginStats);
initial.commit09911bf2008-07-26 23:55:29581}
582
[email protected]fe58acc22012-02-29 01:29:58583// The server refuses data that doesn't have certain values. crashcount and
584// launchcount are currently "required" in the "stability" group.
585// TODO(isherman): Stop writing these attributes specially once the migration to
586// protobufs is complete.
[email protected]147bbc0b2009-01-06 19:37:40587void MetricsLog::WriteRequiredStabilityAttributes(PrefService* pref) {
[email protected]fe58acc22012-02-29 01:29:58588 int launch_count = pref->GetInteger(prefs::kStabilityLaunchCount);
[email protected]0b33f80b2008-12-17 21:34:36589 pref->SetInteger(prefs::kStabilityLaunchCount, 0);
[email protected]fe58acc22012-02-29 01:29:58590 int crash_count = pref->GetInteger(prefs::kStabilityCrashCount);
[email protected]0b33f80b2008-12-17 21:34:36591 pref->SetInteger(prefs::kStabilityCrashCount, 0);
[email protected]fe58acc22012-02-29 01:29:58592
[email protected]fe58acc22012-02-29 01:29:58593 SystemProfileProto::Stability* stability =
[email protected]767c9d92012-03-02 16:04:34594 uma_proto()->mutable_system_profile()->mutable_stability();
[email protected]fe58acc22012-02-29 01:29:58595 stability->set_launch_count(launch_count);
596 stability->set_crash_count(crash_count);
[email protected]0b33f80b2008-12-17 21:34:36597}
598
[email protected]147bbc0b2009-01-06 19:37:40599void MetricsLog::WriteRealtimeStabilityAttributes(PrefService* pref) {
[email protected]0b33f80b2008-12-17 21:34:36600 // Update the stats which are critical for real-time stability monitoring.
601 // Since these are "optional," only list ones that are non-zero, as the counts
602 // are aggergated (summed) server side.
603
[email protected]fe58acc22012-02-29 01:29:58604 SystemProfileProto::Stability* stability =
[email protected]767c9d92012-03-02 16:04:34605 uma_proto()->mutable_system_profile()->mutable_stability();
[email protected]0b33f80b2008-12-17 21:34:36606 int count = pref->GetInteger(prefs::kStabilityPageLoadCount);
607 if (count) {
[email protected]fe58acc22012-02-29 01:29:58608 stability->set_page_load_count(count);
[email protected]0b33f80b2008-12-17 21:34:36609 pref->SetInteger(prefs::kStabilityPageLoadCount, 0);
610 }
611
612 count = pref->GetInteger(prefs::kStabilityRendererCrashCount);
613 if (count) {
[email protected]fe58acc22012-02-29 01:29:58614 stability->set_renderer_crash_count(count);
[email protected]0b33f80b2008-12-17 21:34:36615 pref->SetInteger(prefs::kStabilityRendererCrashCount, 0);
616 }
617
[email protected]1f085622009-12-04 05:33:45618 count = pref->GetInteger(prefs::kStabilityExtensionRendererCrashCount);
619 if (count) {
[email protected]fe58acc22012-02-29 01:29:58620 stability->set_extension_renderer_crash_count(count);
[email protected]1f085622009-12-04 05:33:45621 pref->SetInteger(prefs::kStabilityExtensionRendererCrashCount, 0);
622 }
623
[email protected]0b33f80b2008-12-17 21:34:36624 count = pref->GetInteger(prefs::kStabilityRendererHangCount);
625 if (count) {
[email protected]fe58acc22012-02-29 01:29:58626 stability->set_renderer_hang_count(count);
[email protected]0b33f80b2008-12-17 21:34:36627 pref->SetInteger(prefs::kStabilityRendererHangCount, 0);
628 }
[email protected]1f085622009-12-04 05:33:45629
630 count = pref->GetInteger(prefs::kStabilityChildProcessCrashCount);
631 if (count) {
[email protected]fe58acc22012-02-29 01:29:58632 stability->set_child_process_crash_count(count);
[email protected]1f085622009-12-04 05:33:45633 pref->SetInteger(prefs::kStabilityChildProcessCrashCount, 0);
634 }
[email protected]9165f742010-03-10 22:55:01635
[email protected]c1834a92011-01-21 18:21:03636#if defined(OS_CHROMEOS)
637 count = pref->GetInteger(prefs::kStabilityOtherUserCrashCount);
638 if (count) {
[email protected]fe58acc22012-02-29 01:29:58639 stability->set_other_user_crash_count(count);
[email protected]c1834a92011-01-21 18:21:03640 pref->SetInteger(prefs::kStabilityOtherUserCrashCount, 0);
641 }
642
643 count = pref->GetInteger(prefs::kStabilityKernelCrashCount);
644 if (count) {
[email protected]fe58acc22012-02-29 01:29:58645 stability->set_kernel_crash_count(count);
[email protected]c1834a92011-01-21 18:21:03646 pref->SetInteger(prefs::kStabilityKernelCrashCount, 0);
647 }
648
649 count = pref->GetInteger(prefs::kStabilitySystemUncleanShutdownCount);
650 if (count) {
[email protected]fe58acc22012-02-29 01:29:58651 stability->set_unclean_system_shutdown_count(count);
[email protected]c1834a92011-01-21 18:21:03652 pref->SetInteger(prefs::kStabilitySystemUncleanShutdownCount, 0);
653 }
654#endif // OS_CHROMEOS
655
[email protected]9165f742010-03-10 22:55:01656 int64 recent_duration = GetIncrementalUptime(pref);
[email protected]f31a01a2013-07-13 02:51:11657 if (recent_duration)
[email protected]fe58acc22012-02-29 01:29:58658 stability->set_uptime_sec(recent_duration);
[email protected]0b33f80b2008-12-17 21:34:36659}
660
initial.commit09911bf2008-07-26 23:55:29661void MetricsLog::WritePluginList(
[email protected]d7bd3e52013-07-21 04:29:20662 const std::vector<content::WebPluginInfo>& plugin_list) {
[email protected]767c9d92012-03-02 16:04:34663 DCHECK(!locked());
initial.commit09911bf2008-07-26 23:55:29664
[email protected]ebd71962012-12-20 02:56:55665#if defined(ENABLE_PLUGINS)
666 PluginPrefs* plugin_prefs = GetPluginPrefs();
[email protected]767c9d92012-03-02 16:04:34667 SystemProfileProto* system_profile = uma_proto()->mutable_system_profile();
[email protected]d7bd3e52013-07-21 04:29:20668 for (std::vector<content::WebPluginInfo>::const_iterator iter =
[email protected]191eb3f72010-12-21 06:27:50669 plugin_list.begin();
initial.commit09911bf2008-07-26 23:55:29670 iter != plugin_list.end(); ++iter) {
[email protected]0eecc2542013-06-23 04:22:02671 SystemProfileProto::Plugin* plugin = system_profile->add_plugin();
672 SetPluginInfo(*iter, plugin_prefs, plugin);
initial.commit09911bf2008-07-26 23:55:29673 }
[email protected]ebd71962012-12-20 02:56:55674#endif // defined(ENABLE_PLUGINS)
initial.commit09911bf2008-07-26 23:55:29675}
676
initial.commit09911bf2008-07-26 23:55:29677void MetricsLog::RecordEnvironment(
[email protected]d7bd3e52013-07-21 04:29:20678 const std::vector<content::WebPluginInfo>& plugin_list,
[email protected]f31a01a2013-07-13 02:51:11679 const GoogleUpdateMetrics& google_update_metrics) {
[email protected]767c9d92012-03-02 16:04:34680 DCHECK(!locked());
initial.commit09911bf2008-07-26 23:55:29681
[email protected]767c9d92012-03-02 16:04:34682 PrefService* pref = GetPrefService();
[email protected]fe58acc22012-02-29 01:29:58683 WriteStabilityElement(plugin_list, pref);
initial.commit09911bf2008-07-26 23:55:29684
[email protected]197c0772012-05-14 23:50:51685 RecordEnvironmentProto(plugin_list, google_update_metrics);
[email protected]bc66d532012-03-23 01:57:05686}
687
688void MetricsLog::RecordEnvironmentProto(
[email protected]d7bd3e52013-07-21 04:29:20689 const std::vector<content::WebPluginInfo>& plugin_list,
[email protected]197c0772012-05-14 23:50:51690 const GoogleUpdateMetrics& google_update_metrics) {
[email protected]bc66d532012-03-23 01:57:05691 SystemProfileProto* system_profile = uma_proto()->mutable_system_profile();
[email protected]24b9bb392013-01-29 20:29:29692
693 std::string brand_code;
694 if (google_util::GetBrand(&brand_code))
695 system_profile->set_brand_code(brand_code);
696
[email protected]cc5d7f42012-10-30 00:30:09697 int enabled_date;
698 bool success = base::StringToInt(GetMetricsEnabledDate(GetPrefService()),
699 &enabled_date);
[email protected]bc66d532012-03-23 01:57:05700 DCHECK(success);
[email protected]86573d12013-07-11 19:48:32701
702 // Reduce granularity of the enabled_date field to nearest hour.
703 system_profile->set_uma_enabled_date(RoundSecondsToHour(enabled_date));
704
705 int64 install_date = GetPrefService()->GetInt64(prefs::kInstallDate);
706
707 // Reduce granularity of the install_date field to nearest hour.
708 system_profile->set_install_date(RoundSecondsToHour(install_date));
[email protected]bc66d532012-03-23 01:57:05709
710 system_profile->set_application_locale(
[email protected]eabbfb12013-04-05 23:28:35711 g_browser_process->GetApplicationLocale());
[email protected]bc66d532012-03-23 01:57:05712
713 SystemProfileProto::Hardware* hardware = system_profile->mutable_hardware();
[email protected]0b6a4fb2012-10-16 01:58:21714 hardware->set_cpu_architecture(base::SysInfo::OperatingSystemArchitecture());
[email protected]bc66d532012-03-23 01:57:05715 hardware->set_system_ram_mb(base::SysInfo::AmountOfPhysicalMemoryMB());
716#if defined(OS_WIN)
717 hardware->set_dll_base(reinterpret_cast<uint64>(&__ImageBase));
718#endif
719
[email protected]74b299e2013-01-29 01:24:42720 SystemProfileProto::Network* network = system_profile->mutable_network();
721 network->set_connection_type_is_ambiguous(
[email protected]5eae204c2013-02-13 15:53:42722 network_observer_.connection_type_is_ambiguous());
723 network->set_connection_type(network_observer_.connection_type());
724 network->set_wifi_phy_layer_protocol_is_ambiguous(
725 network_observer_.wifi_phy_layer_protocol_is_ambiguous());
726 network->set_wifi_phy_layer_protocol(
727 network_observer_.wifi_phy_layer_protocol());
728 network_observer_.Reset();
[email protected]74b299e2013-01-29 01:24:42729
[email protected]bc66d532012-03-23 01:57:05730 SystemProfileProto::OS* os = system_profile->mutable_os();
[email protected]1bb25e02012-08-03 22:39:39731 std::string os_name = base::SysInfo::OperatingSystemName();
732#if defined(OS_WIN)
733 // TODO(mad): This only checks whether the main process is a Metro process at
734 // upload time; not whether the collected metrics were all gathered from
735 // Metro. This is ok as an approximation for now, since users will rarely be
736 // switching from Metro to Desktop mode; but we should re-evaluate whether we
737 // can distinguish metrics more cleanly in the future: http://crbug.com/140568
738 if (base::win::IsMetroProcess())
739 os_name += " (Metro)";
740#endif
741 os->set_name(os_name);
[email protected]bc66d532012-03-23 01:57:05742 os->set_version(base::SysInfo::OperatingSystemVersion());
[email protected]5106b3a2012-10-03 20:10:44743#if defined(OS_ANDROID)
744 os->set_fingerprint(
745 base::android::BuildInfo::GetInstance()->android_build_fp());
746#endif
[email protected]bc66d532012-03-23 01:57:05747
[email protected]5c8f89f692013-07-18 11:13:28748 base::CPU cpu_info;
749 SystemProfileProto::Hardware::CPU* cpu = hardware->mutable_cpu();
750 cpu->set_vendor_name(cpu_info.vendor_name());
751 cpu->set_signature(cpu_info.signature());
752
[email protected]d7b5cc72013-05-23 20:05:00753 const gpu::GPUInfo& gpu_info =
[email protected]bc66d532012-03-23 01:57:05754 GpuDataManager::GetInstance()->GetGPUInfo();
755 SystemProfileProto::Hardware::Graphics* gpu = hardware->mutable_gpu();
[email protected]a094e2c2012-05-10 23:02:42756 gpu->set_vendor_id(gpu_info.gpu.vendor_id);
757 gpu->set_device_id(gpu_info.gpu.device_id);
[email protected]bc66d532012-03-23 01:57:05758 gpu->set_driver_version(gpu_info.driver_version);
759 gpu->set_driver_date(gpu_info.driver_date);
760 SystemProfileProto::Hardware::Graphics::PerformanceStatistics*
761 gpu_performance = gpu->mutable_performance_statistics();
762 gpu_performance->set_graphics_score(gpu_info.performance_stats.graphics);
763 gpu_performance->set_gaming_score(gpu_info.performance_stats.gaming);
764 gpu_performance->set_overall_score(gpu_info.performance_stats.overall);
[email protected]d6bdfae2013-01-18 20:23:01765 gpu->set_gl_vendor(gpu_info.gl_vendor);
766 gpu->set_gl_renderer(gpu_info.gl_renderer);
[email protected]bc66d532012-03-23 01:57:05767
768 const gfx::Size display_size = GetScreenSize();
769 hardware->set_primary_screen_width(display_size.width());
770 hardware->set_primary_screen_height(display_size.height());
[email protected]aa96417972012-08-22 03:16:44771 hardware->set_primary_screen_scale_factor(GetScreenDeviceScaleFactor());
[email protected]bc66d532012-03-23 01:57:05772 hardware->set_screen_count(GetScreenCount());
773
[email protected]76869ff2013-01-15 16:13:47774#if defined(OS_WIN)
775 WriteScreenDPIInformationProto(hardware);
776#endif
777
[email protected]197c0772012-05-14 23:50:51778 WriteGoogleUpdateProto(google_update_metrics);
779
[email protected]0eecc2542013-06-23 04:22:02780 WritePluginList(plugin_list);
[email protected]bc66d532012-03-23 01:57:05781
[email protected]0c8b7ad2012-11-06 07:08:14782 std::vector<ActiveGroupId> field_trial_ids;
[email protected]767c9d92012-03-02 16:04:34783 GetFieldTrialIds(&field_trial_ids);
784 WriteFieldTrials(field_trial_ids, system_profile);
[email protected]f65859e2013-02-04 20:00:25785
786#if defined(OS_CHROMEOS)
787 PerfDataProto perf_data_proto;
788 if (perf_provider_.GetPerfData(&perf_data_proto))
789 uma_proto()->add_perf_data()->Swap(&perf_data_proto);
[email protected]611ae29a2013-04-29 21:32:19790
791 // BluetoothAdapterFactory::GetAdapter is synchronous on Chrome OS; if that
792 // changes this will fail at the DCHECK().
793 device::BluetoothAdapterFactory::GetAdapter(
794 base::Bind(&MetricsLog::SetBluetoothAdapter,
795 base::Unretained(this)));
796 DCHECK(adapter_.get());
797 WriteBluetoothProto(hardware);
[email protected]f65859e2013-02-04 20:00:25798#endif
initial.commit09911bf2008-07-26 23:55:29799}
800
[email protected]ed0fd002012-04-25 23:10:34801void MetricsLog::RecordProfilerData(
802 const tracked_objects::ProcessDataSnapshot& process_data,
[email protected]f3b357692013-03-22 05:16:13803 int process_type) {
[email protected]ed0fd002012-04-25 23:10:34804 DCHECK(!locked());
805
[email protected]8f829682012-04-27 00:36:49806 if (tracked_objects::GetTimeSourceType() !=
807 tracked_objects::TIME_SOURCE_TYPE_WALL_TIME) {
[email protected]ed0fd002012-04-25 23:10:34808 // We currently only support the default time source, wall clock time.
809 return;
810 }
811
812 ProfilerEventProto* profile;
813 if (!uma_proto()->profiler_event_size()) {
814 // For the first process's data, add a new field to the protocol buffer.
815 profile = uma_proto()->add_profiler_event();
816 profile->set_profile_type(ProfilerEventProto::STARTUP_PROFILE);
817 profile->set_time_source(ProfilerEventProto::WALL_CLOCK_TIME);
818 } else {
819 // For the remaining calls, re-use the existing field.
820 profile = uma_proto()->mutable_profiler_event(0);
821 }
822
823 WriteProfilerData(process_data, process_type, profile);
824}
825
[email protected]0fafc8d2013-06-01 00:09:50826void MetricsLog::RecordOmniboxOpenedURL(const OmniboxLog& log) {
[email protected]767c9d92012-03-02 16:04:34827 DCHECK(!locked());
initial.commit09911bf2008-07-26 23:55:29828
[email protected]65956312012-04-19 21:28:12829 std::vector<string16> terms;
830 const int num_terms =
831 static_cast<int>(Tokenize(log.text, kWhitespaceUTF16, &terms));
initial.commit09911bf2008-07-26 23:55:29832
[email protected]767c9d92012-03-02 16:04:34833 OmniboxEventProto* omnibox_event = uma_proto()->add_omnibox_event();
[email protected]fe58acc22012-02-29 01:29:58834 omnibox_event->set_time(MetricsLogBase::GetCurrentTime());
835 if (log.tab_id != -1) {
836 // If we know what tab the autocomplete URL was opened in, log it.
837 omnibox_event->set_tab_id(log.tab_id);
838 }
839 omnibox_event->set_typed_length(log.text.length());
[email protected]660fe8f32012-05-03 20:01:08840 omnibox_event->set_just_deleted_text(log.just_deleted_text);
[email protected]65956312012-04-19 21:28:12841 omnibox_event->set_num_typed_terms(num_terms);
[email protected]fe58acc22012-02-29 01:29:58842 omnibox_event->set_selected_index(log.selected_index);
[email protected]62b3ef52013-01-18 00:13:02843 if (log.completed_length != string16::npos)
844 omnibox_event->set_completed_length(log.completed_length);
[email protected]65956312012-04-19 21:28:12845 if (log.elapsed_time_since_user_first_modified_omnibox !=
846 base::TimeDelta::FromMilliseconds(-1)) {
847 // Only upload the typing duration if it is set/valid.
848 omnibox_event->set_typing_duration_ms(
849 log.elapsed_time_since_user_first_modified_omnibox.InMilliseconds());
850 }
[email protected]35d55602012-11-20 23:49:03851 omnibox_event->set_duration_since_last_default_match_update_ms(
852 log.elapsed_time_since_last_change_to_default_match.InMilliseconds());
[email protected]ee902532012-05-01 23:54:49853 omnibox_event->set_current_page_classification(
[email protected]3c919d6a2013-07-28 18:35:52854 AsOmniboxEventPageClassification(log.current_page_classification));
[email protected]fe58acc22012-02-29 01:29:58855 omnibox_event->set_input_type(AsOmniboxEventInputType(log.input_type));
856 for (AutocompleteResult::const_iterator i(log.result.begin());
857 i != log.result.end(); ++i) {
858 OmniboxEventProto::Suggestion* suggestion = omnibox_event->add_suggestion();
[email protected]0e9e8782012-05-15 23:01:51859 suggestion->set_provider(i->provider->AsOmniboxEventProviderType());
[email protected]fe58acc22012-02-29 01:29:58860 suggestion->set_result_type(AsOmniboxEventResultType(i->type));
861 suggestion->set_relevance(i->relevance);
[email protected]cf6256f2012-06-12 23:36:01862 if (i->typed_count != -1)
863 suggestion->set_typed_count(i->typed_count);
[email protected]fe58acc22012-02-29 01:29:58864 suggestion->set_is_starred(i->starred);
865 }
[email protected]0e9e8782012-05-15 23:01:51866 for (ProvidersInfo::const_iterator i(log.providers_info.begin());
867 i != log.providers_info.end(); ++i) {
868 OmniboxEventProto::ProviderInfo* provider_info =
869 omnibox_event->add_provider_info();
870 provider_info->CopyFrom(*i);
871 }
[email protected]fe58acc22012-02-29 01:29:58872
initial.commit09911bf2008-07-26 23:55:29873 ++num_events_;
874}
[email protected]197c0772012-05-14 23:50:51875
876void MetricsLog::WriteGoogleUpdateProto(
877 const GoogleUpdateMetrics& google_update_metrics) {
878#if defined(GOOGLE_CHROME_BUILD) && defined(OS_WIN)
879 SystemProfileProto::GoogleUpdate* google_update =
880 uma_proto()->mutable_system_profile()->mutable_google_update();
881
882 google_update->set_is_system_install(google_update_metrics.is_system_install);
883
884 if (!google_update_metrics.last_started_au.is_null()) {
885 google_update->set_last_automatic_start_timestamp(
886 google_update_metrics.last_started_au.ToTimeT());
887 }
888
889 if (!google_update_metrics.last_checked.is_null()) {
890 google_update->set_last_update_check_timestamp(
891 google_update_metrics.last_checked.ToTimeT());
892 }
893
894 if (!google_update_metrics.google_update_data.version.empty()) {
895 ProductDataToProto(google_update_metrics.google_update_data,
896 google_update->mutable_google_update_status());
897 }
898
899 if (!google_update_metrics.product_data.version.empty()) {
900 ProductDataToProto(google_update_metrics.product_data,
901 google_update->mutable_client_status());
902 }
903#endif // defined(GOOGLE_CHROME_BUILD) && defined(OS_WIN)
904}
[email protected]611ae29a2013-04-29 21:32:19905
906void MetricsLog::SetBluetoothAdapter(
907 scoped_refptr<device::BluetoothAdapter> adapter) {
908 adapter_ = adapter;
909}
910
911void MetricsLog::WriteBluetoothProto(
912 SystemProfileProto::Hardware* hardware) {
[email protected]728f9b22013-05-02 06:08:18913#if defined(OS_CHROMEOS)
[email protected]611ae29a2013-04-29 21:32:19914 SystemProfileProto::Hardware::Bluetooth* bluetooth =
915 hardware->mutable_bluetooth();
916
917 bluetooth->set_is_present(adapter_->IsPresent());
918 bluetooth->set_is_enabled(adapter_->IsPowered());
919
920 device::BluetoothAdapter::DeviceList devices = adapter_->GetDevices();
921 for (device::BluetoothAdapter::DeviceList::iterator iter =
922 devices.begin(); iter != devices.end(); ++iter) {
923 PairedDevice* paired_device = bluetooth->add_paired_device();
924
925 device::BluetoothDevice* device = *iter;
926 paired_device->set_bluetooth_class(device->GetBluetoothClass());
927 paired_device->set_type(AsBluetoothDeviceType(device->GetDeviceType()));
928
929 // address is xx:xx:xx:xx:xx:xx, extract the first three components and
930 // pack into a uint32
931 std::string address = device->GetAddress();
932 if (address.size() > 9 &&
933 address[2] == ':' && address[5] == ':' && address[8] == ':') {
934 std::string vendor_prefix_str;
935 uint64 vendor_prefix;
936
937 RemoveChars(address.substr(0, 9), ":", &vendor_prefix_str);
938 DCHECK_EQ(6U, vendor_prefix_str.size());
939 base::HexStringToUInt64(vendor_prefix_str, &vendor_prefix);
940
941 paired_device->set_vendor_prefix(vendor_prefix);
942 }
943
944 paired_device->set_vendor_id(device->GetVendorID());
945 paired_device->set_product_id(device->GetProductID());
946 paired_device->set_device_id(device->GetDeviceID());
947 }
948#endif // defined(OS_CHROMEOS)
949}