blob: 21356fdac87ba7ae0722c553ff855999b85bc749 [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]054c8012011-11-16 00:12:4213#include "base/lazy_instance.h"
[email protected]3b63f8f42011-03-28 01:54:1514#include "base/memory/scoped_ptr.h"
[email protected]85ed9d42010-06-08 22:37:4415#include "base/perftimer.h"
[email protected]3853a4c2013-02-11 17:15:5716#include "base/prefs/pref_registry_simple.h"
17#include "base/prefs/pref_service.h"
[email protected]ed0fd002012-04-25 23:10:3418#include "base/profiler/alternate_timer.h"
initial.commit09911bf2008-07-26 23:55:2919#include "base/string_util.h"
[email protected]3ea1b182013-02-08 22:38:4120#include "base/strings/string_number_conversions.h"
[email protected]fadf97f2008-09-18 12:18:1421#include "base/sys_info.h"
[email protected]37f39e42010-01-06 17:35:1722#include "base/third_party/nspr/prtime.h"
[email protected]1eeb5e02010-07-20 23:02:1123#include "base/time.h"
[email protected]ed0fd002012-04-25 23:10:3424#include "base/tracked_objects.h"
[email protected]1eeb5e02010-07-20 23:02:1125#include "base/utf_string_conversions.h"
[email protected]9f8bc2f2012-07-03 16:26:5326#include "chrome/browser/autocomplete/autocomplete_input.h"
[email protected]9ac40092010-10-27 23:05:2627#include "chrome/browser/autocomplete/autocomplete_match.h"
[email protected]30f5bc92012-06-26 04:14:5528#include "chrome/browser/autocomplete/autocomplete_provider.h"
[email protected]73c2b1632012-07-02 22:51:3829#include "chrome/browser/autocomplete/autocomplete_result.h"
initial.commit09911bf2008-07-26 23:55:2930#include "chrome/browser/browser_process.h"
[email protected]24b9bb392013-01-29 20:29:2931#include "chrome/browser/google/google_util.h"
[email protected]0fafc8d2013-06-01 00:09:5032#include "chrome/browser/omnibox/omnibox_log.h"
[email protected]0f5e57f52012-09-20 20:53:1833#include "chrome/browser/plugins/plugin_prefs.h"
[email protected]10084982011-08-19 17:56:5634#include "chrome/browser/profiles/profile_manager.h"
[email protected]f3b357692013-03-22 05:16:1335#include "chrome/common/chrome_process_type.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]79078df2012-02-16 01:22:3244#include "content/public/browser/gpu_data_manager.h"
[email protected]1a838cc2012-04-24 22:06:4945#include "content/public/common/content_client.h"
[email protected]611ae29a2013-04-29 21:32:1946#include "device/bluetooth/bluetooth_adapter.h"
47#include "device/bluetooth/bluetooth_adapter_factory.h"
48#include "device/bluetooth/bluetooth_device.h"
[email protected]46072d42008-07-28 14:49:3549#include "googleurl/src/gurl.h"
[email protected]d7b5cc72013-05-23 20:05:0050#include "gpu/config/gpu_info.h"
[email protected]6b7d954ff2011-10-25 00:39:3551#include "ui/gfx/screen.h"
[email protected]91d9f3d2011-08-14 05:24:4452#include "webkit/plugins/webplugininfo.h"
initial.commit09911bf2008-07-26 23:55:2953
[email protected]5106b3a2012-10-03 20:10:4454#if defined(OS_ANDROID)
55#include "base/android/build_info.h"
56#endif
57
initial.commit09911bf2008-07-26 23:55:2958#define OPEN_ELEMENT_FOR_SCOPE(name) ScopedElement scoped_element(this, name)
59
[email protected]d1be67b2008-11-19 20:28:3860#if defined(OS_WIN)
[email protected]1bb25e02012-08-03 22:39:3961#include "base/win/metro.h"
[email protected]e245ace92013-05-07 00:37:4162#include "ui/base/win/dpi.h"
[email protected]1bb25e02012-08-03 22:39:3963
64// http://blogs.msdn.com/oldnewthing/archive/2004/10/25/247180.aspx
[email protected]d1be67b2008-11-19 20:28:3865extern "C" IMAGE_DOS_HEADER __ImageBase;
66#endif
67
[email protected]79078df2012-02-16 01:22:3268using content::GpuDataManager;
[email protected]fe58acc22012-02-29 01:29:5869using metrics::OmniboxEventProto;
[email protected]f65859e2013-02-04 20:00:2570using metrics::PerfDataProto;
[email protected]ed0fd002012-04-25 23:10:3471using metrics::ProfilerEventProto;
[email protected]fe58acc22012-02-29 01:29:5872using metrics::SystemProfileProto;
[email protected]ed0fd002012-04-25 23:10:3473using tracked_objects::ProcessDataSnapshot;
[email protected]0c8b7ad2012-11-06 07:08:1474typedef chrome_variations::ActiveGroupId ActiveGroupId;
[email protected]197c0772012-05-14 23:50:5175typedef SystemProfileProto::GoogleUpdate::ProductInfo ProductInfo;
[email protected]611ae29a2013-04-29 21:32:1976typedef SystemProfileProto::Hardware::Bluetooth::PairedDevice PairedDevice;
[email protected]79078df2012-02-16 01:22:3277
[email protected]1df44b72012-01-19 05:20:3478namespace {
79
80// Returns the date at which the current metrics client ID was created as
[email protected]ca5ac4b2012-12-14 07:46:4081// a string containing seconds since the epoch, or "0" if none was found.
[email protected]cc5d7f42012-10-30 00:30:0982std::string GetMetricsEnabledDate(PrefService* pref) {
[email protected]767c9d92012-03-02 16:04:3483 if (!pref) {
[email protected]1df44b72012-01-19 05:20:3484 NOTREACHED();
85 return "0";
86 }
[email protected]767c9d92012-03-02 16:04:3487
88 return pref->GetString(prefs::kMetricsClientIDTimestamp);
[email protected]1df44b72012-01-19 05:20:3489}
90
[email protected]fe58acc22012-02-29 01:29:5891OmniboxEventProto::InputType AsOmniboxEventInputType(
92 AutocompleteInput::Type type) {
93 switch (type) {
94 case AutocompleteInput::INVALID:
95 return OmniboxEventProto::INVALID;
96 case AutocompleteInput::UNKNOWN:
97 return OmniboxEventProto::UNKNOWN;
[email protected]fe58acc22012-02-29 01:29:5898 case AutocompleteInput::URL:
99 return OmniboxEventProto::URL;
100 case AutocompleteInput::QUERY:
101 return OmniboxEventProto::QUERY;
102 case AutocompleteInput::FORCED_QUERY:
103 return OmniboxEventProto::FORCED_QUERY;
104 default:
105 NOTREACHED();
106 return OmniboxEventProto::INVALID;
107 }
108}
109
[email protected]fe58acc22012-02-29 01:29:58110OmniboxEventProto::Suggestion::ResultType AsOmniboxEventResultType(
111 AutocompleteMatch::Type type) {
112 switch (type) {
[email protected]b7f64d742013-05-21 04:04:04113 case AutocompleteMatchType::URL_WHAT_YOU_TYPED:
[email protected]fe58acc22012-02-29 01:29:58114 return OmniboxEventProto::Suggestion::URL_WHAT_YOU_TYPED;
[email protected]b7f64d742013-05-21 04:04:04115 case AutocompleteMatchType::HISTORY_URL:
[email protected]fe58acc22012-02-29 01:29:58116 return OmniboxEventProto::Suggestion::HISTORY_URL;
[email protected]b7f64d742013-05-21 04:04:04117 case AutocompleteMatchType::HISTORY_TITLE:
[email protected]fe58acc22012-02-29 01:29:58118 return OmniboxEventProto::Suggestion::HISTORY_TITLE;
[email protected]b7f64d742013-05-21 04:04:04119 case AutocompleteMatchType::HISTORY_BODY:
[email protected]fe58acc22012-02-29 01:29:58120 return OmniboxEventProto::Suggestion::HISTORY_BODY;
[email protected]b7f64d742013-05-21 04:04:04121 case AutocompleteMatchType::HISTORY_KEYWORD:
[email protected]fe58acc22012-02-29 01:29:58122 return OmniboxEventProto::Suggestion::HISTORY_KEYWORD;
[email protected]b7f64d742013-05-21 04:04:04123 case AutocompleteMatchType::NAVSUGGEST:
[email protected]fe58acc22012-02-29 01:29:58124 return OmniboxEventProto::Suggestion::NAVSUGGEST;
[email protected]b7f64d742013-05-21 04:04:04125 case AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED:
[email protected]fe58acc22012-02-29 01:29:58126 return OmniboxEventProto::Suggestion::SEARCH_WHAT_YOU_TYPED;
[email protected]b7f64d742013-05-21 04:04:04127 case AutocompleteMatchType::SEARCH_HISTORY:
[email protected]fe58acc22012-02-29 01:29:58128 return OmniboxEventProto::Suggestion::SEARCH_HISTORY;
[email protected]b7f64d742013-05-21 04:04:04129 case AutocompleteMatchType::SEARCH_SUGGEST:
[email protected]fe58acc22012-02-29 01:29:58130 return OmniboxEventProto::Suggestion::SEARCH_SUGGEST;
[email protected]b7f64d742013-05-21 04:04:04131 case AutocompleteMatchType::SEARCH_OTHER_ENGINE:
[email protected]fe58acc22012-02-29 01:29:58132 return OmniboxEventProto::Suggestion::SEARCH_OTHER_ENGINE;
[email protected]b7f64d742013-05-21 04:04:04133 case AutocompleteMatchType::EXTENSION_APP:
[email protected]fe58acc22012-02-29 01:29:58134 return OmniboxEventProto::Suggestion::EXTENSION_APP;
[email protected]b7f64d742013-05-21 04:04:04135 case AutocompleteMatchType::CONTACT:
[email protected]dbacefb2012-09-12 03:32:06136 return OmniboxEventProto::Suggestion::CONTACT;
[email protected]b7f64d742013-05-21 04:04:04137 case AutocompleteMatchType::BOOKMARK_TITLE:
[email protected]25320602012-10-18 22:05:56138 return OmniboxEventProto::Suggestion::BOOKMARK_TITLE;
[email protected]fe58acc22012-02-29 01:29:58139 default:
140 NOTREACHED();
141 return OmniboxEventProto::Suggestion::UNKNOWN_RESULT_TYPE;
142 }
143}
144
[email protected]ed0fd002012-04-25 23:10:34145ProfilerEventProto::TrackedObject::ProcessType AsProtobufProcessType(
[email protected]f3b357692013-03-22 05:16:13146 int process_type) {
[email protected]ed0fd002012-04-25 23:10:34147 switch (process_type) {
148 case content::PROCESS_TYPE_BROWSER:
149 return ProfilerEventProto::TrackedObject::BROWSER;
150 case content::PROCESS_TYPE_RENDERER:
151 return ProfilerEventProto::TrackedObject::RENDERER;
152 case content::PROCESS_TYPE_PLUGIN:
153 return ProfilerEventProto::TrackedObject::PLUGIN;
154 case content::PROCESS_TYPE_WORKER:
155 return ProfilerEventProto::TrackedObject::WORKER;
[email protected]ed0fd002012-04-25 23:10:34156 case content::PROCESS_TYPE_UTILITY:
157 return ProfilerEventProto::TrackedObject::UTILITY;
[email protected]ed0fd002012-04-25 23:10:34158 case content::PROCESS_TYPE_ZYGOTE:
159 return ProfilerEventProto::TrackedObject::ZYGOTE;
160 case content::PROCESS_TYPE_SANDBOX_HELPER:
161 return ProfilerEventProto::TrackedObject::SANDBOX_HELPER;
[email protected]ed0fd002012-04-25 23:10:34162 case content::PROCESS_TYPE_GPU:
163 return ProfilerEventProto::TrackedObject::GPU;
164 case content::PROCESS_TYPE_PPAPI_PLUGIN:
165 return ProfilerEventProto::TrackedObject::PPAPI_PLUGIN;
166 case content::PROCESS_TYPE_PPAPI_BROKER:
167 return ProfilerEventProto::TrackedObject::PPAPI_BROKER;
[email protected]f3b357692013-03-22 05:16:13168 case PROCESS_TYPE_PROFILE_IMPORT:
169 return ProfilerEventProto::TrackedObject::PROFILE_IMPORT;
170 case PROCESS_TYPE_NACL_LOADER:
171 return ProfilerEventProto::TrackedObject::NACL_LOADER;
172 case PROCESS_TYPE_NACL_BROKER:
173 return ProfilerEventProto::TrackedObject::NACL_BROKER;
[email protected]ed0fd002012-04-25 23:10:34174 default:
175 NOTREACHED();
176 return ProfilerEventProto::TrackedObject::UNKNOWN;
177 }
178}
179
[email protected]1df44b72012-01-19 05:20:34180// Returns the plugin preferences corresponding for this user, if available.
181// If multiple user profiles are loaded, returns the preferences corresponding
182// to an arbitrary one of the profiles.
183PluginPrefs* GetPluginPrefs() {
184 ProfileManager* profile_manager = g_browser_process->profile_manager();
[email protected]fe58acc22012-02-29 01:29:58185
186 if (!profile_manager) {
187 // The profile manager can be NULL when testing.
188 return NULL;
189 }
190
[email protected]1df44b72012-01-19 05:20:34191 std::vector<Profile*> profiles = profile_manager->GetLoadedProfiles();
192 if (profiles.empty())
193 return NULL;
194
195 return PluginPrefs::GetForProfile(profiles.front());
196}
197
[email protected]fe58acc22012-02-29 01:29:58198// Fills |plugin| with the info contained in |plugin_info| and |plugin_prefs|.
199void SetPluginInfo(const webkit::WebPluginInfo& plugin_info,
200 const PluginPrefs* plugin_prefs,
201 SystemProfileProto::Plugin* plugin) {
202 plugin->set_name(UTF16ToUTF8(plugin_info.name));
203 plugin->set_filename(plugin_info.path.BaseName().AsUTF8Unsafe());
204 plugin->set_version(UTF16ToUTF8(plugin_info.version));
205 if (plugin_prefs)
206 plugin->set_is_disabled(!plugin_prefs->IsPluginEnabled(plugin_info));
207}
208
[email protected]0c8b7ad2012-11-06 07:08:14209void WriteFieldTrials(const std::vector<ActiveGroupId>& field_trial_ids,
[email protected]767c9d92012-03-02 16:04:34210 SystemProfileProto* system_profile) {
[email protected]0c8b7ad2012-11-06 07:08:14211 for (std::vector<ActiveGroupId>::const_iterator it =
[email protected]ad2461c2012-04-27 21:11:03212 field_trial_ids.begin(); it != field_trial_ids.end(); ++it) {
[email protected]767c9d92012-03-02 16:04:34213 SystemProfileProto::FieldTrial* field_trial =
214 system_profile->add_field_trial();
215 field_trial->set_name_id(it->name);
216 field_trial->set_group_id(it->group);
217 }
218}
219
[email protected]ed0fd002012-04-25 23:10:34220void WriteProfilerData(const ProcessDataSnapshot& profiler_data,
[email protected]f3b357692013-03-22 05:16:13221 int process_type,
[email protected]ed0fd002012-04-25 23:10:34222 ProfilerEventProto* performance_profile) {
223 for (std::vector<tracked_objects::TaskSnapshot>::const_iterator it =
224 profiler_data.tasks.begin();
225 it != profiler_data.tasks.end(); ++it) {
226 std::string ignored;
227 uint64 birth_thread_name_hash;
228 uint64 exec_thread_name_hash;
229 uint64 source_file_name_hash;
230 uint64 source_function_name_hash;
231 MetricsLogBase::CreateHashes(it->birth.thread_name,
232 &ignored, &birth_thread_name_hash);
233 MetricsLogBase::CreateHashes(it->death_thread_name,
234 &ignored, &exec_thread_name_hash);
[email protected]ed0fd002012-04-25 23:10:34235 MetricsLogBase::CreateHashes(it->birth.location.file_name,
[email protected]04162262012-10-23 01:17:25236 &ignored, &source_file_name_hash);
237 MetricsLogBase::CreateHashes(it->birth.location.function_name,
[email protected]ed0fd002012-04-25 23:10:34238 &ignored, &source_function_name_hash);
239
240 const tracked_objects::DeathDataSnapshot& death_data = it->death_data;
241 ProfilerEventProto::TrackedObject* tracked_object =
242 performance_profile->add_tracked_object();
243 tracked_object->set_birth_thread_name_hash(birth_thread_name_hash);
244 tracked_object->set_exec_thread_name_hash(exec_thread_name_hash);
245 tracked_object->set_source_file_name_hash(source_file_name_hash);
246 tracked_object->set_source_function_name_hash(source_function_name_hash);
247 tracked_object->set_source_line_number(it->birth.location.line_number);
248 tracked_object->set_exec_count(death_data.count);
249 tracked_object->set_exec_time_total(death_data.run_duration_sum);
250 tracked_object->set_exec_time_sampled(death_data.run_duration_sample);
251 tracked_object->set_queue_time_total(death_data.queue_duration_sum);
252 tracked_object->set_queue_time_sampled(death_data.queue_duration_sample);
253 tracked_object->set_process_type(AsProtobufProcessType(process_type));
254 tracked_object->set_process_id(profiler_data.process_id);
255 }
256}
257
[email protected]59a7ae4e2012-10-01 23:54:44258#if defined(GOOGLE_CHROME_BUILD) && defined(OS_WIN)
[email protected]197c0772012-05-14 23:50:51259void ProductDataToProto(const GoogleUpdateSettings::ProductData& product_data,
260 ProductInfo* product_info) {
261 product_info->set_version(product_data.version);
262 product_info->set_last_update_success_timestamp(
263 product_data.last_success.ToTimeT());
264 product_info->set_last_error(product_data.last_error_code);
265 product_info->set_last_extra_error(product_data.last_extra_code);
266 if (ProductInfo::InstallResult_IsValid(product_data.last_result)) {
267 product_info->set_last_result(
268 static_cast<ProductInfo::InstallResult>(product_data.last_result));
269 }
270}
[email protected]59a7ae4e2012-10-01 23:54:44271#endif
[email protected]197c0772012-05-14 23:50:51272
[email protected]76869ff2013-01-15 16:13:47273#if defined(OS_WIN)
[email protected]ffaf7322013-05-15 00:26:11274struct ScreenDPIInformation {
[email protected]76869ff2013-01-15 16:13:47275 double max_dpi_x;
276 double max_dpi_y;
277};
278
279// Called once for each connected monitor.
280BOOL CALLBACK GetMonitorDPICallback(HMONITOR, HDC hdc, LPRECT, LPARAM dwData) {
281 const double kMillimetersPerInch = 25.4;
282 ScreenDPIInformation* screen_info =
283 reinterpret_cast<ScreenDPIInformation*>(dwData);
284 // Size of screen, in mm.
285 DWORD size_x = GetDeviceCaps(hdc, HORZSIZE);
286 DWORD size_y = GetDeviceCaps(hdc, VERTSIZE);
287 double dpi_x = (size_x > 0) ?
288 GetDeviceCaps(hdc, HORZRES) / (size_x / kMillimetersPerInch) : 0;
289 double dpi_y = (size_y > 0) ?
290 GetDeviceCaps(hdc, VERTRES) / (size_y / kMillimetersPerInch) : 0;
[email protected]e245ace92013-05-07 00:37:41291 dpi_x *= ui::win::GetUndocumentedDPIScale();
292 dpi_y *= ui::win::GetUndocumentedDPIScale();
[email protected]76869ff2013-01-15 16:13:47293 screen_info->max_dpi_x = std::max(dpi_x, screen_info->max_dpi_x);
294 screen_info->max_dpi_y = std::max(dpi_y, screen_info->max_dpi_y);
295 return TRUE;
296}
297
298void WriteScreenDPIInformationProto(SystemProfileProto::Hardware* hardware) {
299 HDC desktop_dc = GetDC(NULL);
300 if (desktop_dc) {
[email protected]ffaf7322013-05-15 00:26:11301 ScreenDPIInformation si = {0, 0};
[email protected]76869ff2013-01-15 16:13:47302 if (EnumDisplayMonitors(desktop_dc, NULL, GetMonitorDPICallback,
303 reinterpret_cast<LPARAM>(&si))) {
304 hardware->set_max_dpi_x(si.max_dpi_x);
305 hardware->set_max_dpi_y(si.max_dpi_y);
306 }
307 ReleaseDC(GetDesktopWindow(), desktop_dc);
308 }
309}
310
311#endif // defined(OS_WIN)
312
[email protected]611ae29a2013-04-29 21:32:19313#if defined(OS_CHROMEOS)
314PairedDevice::Type AsBluetoothDeviceType(
315 enum device::BluetoothDevice::DeviceType device_type) {
316 switch (device_type) {
317 case device::BluetoothDevice::DEVICE_UNKNOWN:
318 return PairedDevice::DEVICE_UNKNOWN;
319 case device::BluetoothDevice::DEVICE_COMPUTER:
320 return PairedDevice::DEVICE_COMPUTER;
321 case device::BluetoothDevice::DEVICE_PHONE:
322 return PairedDevice::DEVICE_PHONE;
323 case device::BluetoothDevice::DEVICE_MODEM:
324 return PairedDevice::DEVICE_MODEM;
325 case device::BluetoothDevice::DEVICE_AUDIO:
326 return PairedDevice::DEVICE_AUDIO;
327 case device::BluetoothDevice::DEVICE_CAR_AUDIO:
328 return PairedDevice::DEVICE_CAR_AUDIO;
329 case device::BluetoothDevice::DEVICE_VIDEO:
330 return PairedDevice::DEVICE_VIDEO;
331 case device::BluetoothDevice::DEVICE_PERIPHERAL:
332 return PairedDevice::DEVICE_PERIPHERAL;
333 case device::BluetoothDevice::DEVICE_JOYSTICK:
334 return PairedDevice::DEVICE_JOYSTICK;
335 case device::BluetoothDevice::DEVICE_GAMEPAD:
336 return PairedDevice::DEVICE_GAMEPAD;
337 case device::BluetoothDevice::DEVICE_KEYBOARD:
338 return PairedDevice::DEVICE_KEYBOARD;
339 case device::BluetoothDevice::DEVICE_MOUSE:
340 return PairedDevice::DEVICE_MOUSE;
341 case device::BluetoothDevice::DEVICE_TABLET:
342 return PairedDevice::DEVICE_TABLET;
343 case device::BluetoothDevice::DEVICE_KEYBOARD_MOUSE_COMBO:
344 return PairedDevice::DEVICE_KEYBOARD_MOUSE_COMBO;
345 }
346
347 NOTREACHED();
348 return PairedDevice::DEVICE_UNKNOWN;
349}
350#endif // defined(OS_CHROMEOS)
351
[email protected]1df44b72012-01-19 05:20:34352} // namespace
353
[email protected]197c0772012-05-14 23:50:51354GoogleUpdateMetrics::GoogleUpdateMetrics() : is_system_install(false) {}
355
356GoogleUpdateMetrics::~GoogleUpdateMetrics() {}
357
[email protected]67f92bc32012-01-26 01:56:19358static base::LazyInstance<std::string>::Leaky
[email protected]054c8012011-11-16 00:12:42359 g_version_extension = LAZY_INSTANCE_INITIALIZER;
360
[email protected]1226abb2010-06-10 18:01:28361MetricsLog::MetricsLog(const std::string& client_id, int session_id)
[email protected]5eae204c2013-02-13 15:53:42362 : MetricsLogBase(client_id, session_id, MetricsLog::GetVersionString()) {}
[email protected]5ed7d4572009-12-23 17:42:41363
[email protected]1226abb2010-06-10 18:01:28364MetricsLog::~MetricsLog() {}
initial.commit09911bf2008-07-26 23:55:29365
366// static
[email protected]b1de2c72013-02-06 02:45:47367void MetricsLog::RegisterPrefs(PrefRegistrySimple* registry) {
368 registry->RegisterListPref(prefs::kStabilityPluginStats);
initial.commit09911bf2008-07-26 23:55:29369}
370
[email protected]1df44b72012-01-19 05:20:34371// static
[email protected]9165f742010-03-10 22:55:01372int64 MetricsLog::GetIncrementalUptime(PrefService* pref) {
373 base::TimeTicks now = base::TimeTicks::Now();
374 static base::TimeTicks last_updated_time(now);
375 int64 incremental_time = (now - last_updated_time).InSeconds();
376 last_updated_time = now;
377
378 if (incremental_time > 0) {
379 int64 metrics_uptime = pref->GetInt64(prefs::kUninstallMetricsUptimeSec);
380 metrics_uptime += incremental_time;
381 pref->SetInt64(prefs::kUninstallMetricsUptimeSec, metrics_uptime);
382 }
383
384 return incremental_time;
385}
386
[email protected]1226abb2010-06-10 18:01:28387// static
388std::string MetricsLog::GetVersionString() {
[email protected]0211f57e2010-08-27 20:28:42389 chrome::VersionInfo version_info;
[email protected]30c91802010-12-18 00:40:17390 if (!version_info.is_valid()) {
391 NOTREACHED() << "Unable to retrieve version info.";
392 return std::string();
393 }
394
[email protected]0211f57e2010-08-27 20:28:42395 std::string version = version_info.Version();
[email protected]054c8012011-11-16 00:12:42396 if (!version_extension().empty())
397 version += version_extension();
[email protected]0211f57e2010-08-27 20:28:42398 if (!version_info.IsOfficialBuild())
399 version.append("-devel");
400 return version;
[email protected]1226abb2010-06-10 18:01:28401}
402
[email protected]054c8012011-11-16 00:12:42403// static
404void MetricsLog::set_version_extension(const std::string& extension) {
405 g_version_extension.Get() = extension;
406}
407
408// static
409const std::string& MetricsLog::version_extension() {
410 return g_version_extension.Get();
411}
412
[email protected]fe58acc22012-02-29 01:29:58413void MetricsLog::RecordIncrementalStabilityElements(
414 const std::vector<webkit::WebPluginInfo>& plugin_list) {
[email protected]767c9d92012-03-02 16:04:34415 DCHECK(!locked());
[email protected]0b33f80b2008-12-17 21:34:36416
[email protected]767c9d92012-03-02 16:04:34417 PrefService* pref = GetPrefService();
[email protected]0b33f80b2008-12-17 21:34:36418 DCHECK(pref);
419
[email protected]147bbc0b2009-01-06 19:37:40420 OPEN_ELEMENT_FOR_SCOPE("profile");
421 WriteCommonEventAttributes();
422
[email protected]9958a322011-03-08 20:04:17423 WriteInstallElement();
[email protected]147bbc0b2009-01-06 19:37:40424
425 {
426 OPEN_ELEMENT_FOR_SCOPE("stability"); // Minimal set of stability elements.
427 WriteRequiredStabilityAttributes(pref);
428 WriteRealtimeStabilityAttributes(pref);
[email protected]fe58acc22012-02-29 01:29:58429 WritePluginStabilityElements(plugin_list, pref);
[email protected]147bbc0b2009-01-06 19:37:40430 }
[email protected]0b33f80b2008-12-17 21:34:36431}
432
[email protected]767c9d92012-03-02 16:04:34433PrefService* MetricsLog::GetPrefService() {
434 return g_browser_process->local_state();
435}
436
437gfx::Size MetricsLog::GetScreenSize() const {
[email protected]ffabb1e2012-10-12 19:51:17438 return gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().GetSizeInPixel();
[email protected]767c9d92012-03-02 16:04:34439}
440
[email protected]aa96417972012-08-22 03:16:44441float MetricsLog::GetScreenDeviceScaleFactor() const {
[email protected]ffabb1e2012-10-12 19:51:17442 return gfx::Screen::GetNativeScreen()->
443 GetPrimaryDisplay().device_scale_factor();
[email protected]aa96417972012-08-22 03:16:44444}
445
[email protected]767c9d92012-03-02 16:04:34446int MetricsLog::GetScreenCount() const {
[email protected]ffabb1e2012-10-12 19:51:17447 // TODO(scottmg): NativeScreen maybe wrong. http://crbug.com/133312
448 return gfx::Screen::GetNativeScreen()->GetNumDisplays();
[email protected]767c9d92012-03-02 16:04:34449}
450
[email protected]767c9d92012-03-02 16:04:34451void MetricsLog::GetFieldTrialIds(
[email protected]0c8b7ad2012-11-06 07:08:14452 std::vector<ActiveGroupId>* field_trial_ids) const {
453 chrome_variations::GetFieldTrialActiveGroupIds(field_trial_ids);
[email protected]767c9d92012-03-02 16:04:34454}
455
[email protected]fe58acc22012-02-29 01:29:58456void MetricsLog::WriteStabilityElement(
457 const std::vector<webkit::WebPluginInfo>& plugin_list,
458 PrefService* pref) {
[email protected]767c9d92012-03-02 16:04:34459 DCHECK(!locked());
initial.commit09911bf2008-07-26 23:55:29460
initial.commit09911bf2008-07-26 23:55:29461 // Get stability attributes out of Local State, zeroing out stored values.
462 // NOTE: This could lead to some data loss if this report isn't successfully
463 // sent, but that's true for all the metrics.
464
[email protected]ffaf78a2008-11-12 17:38:33465 OPEN_ELEMENT_FOR_SCOPE("stability");
[email protected]147bbc0b2009-01-06 19:37:40466 WriteRequiredStabilityAttributes(pref);
467 WriteRealtimeStabilityAttributes(pref);
initial.commit09911bf2008-07-26 23:55:29468
[email protected]fe58acc22012-02-29 01:29:58469 int incomplete_shutdown_count =
470 pref->GetInteger(prefs::kStabilityIncompleteSessionEndCount);
[email protected]e324f6b2012-02-28 05:43:37471 pref->SetInteger(prefs::kStabilityIncompleteSessionEndCount, 0);
[email protected]fe58acc22012-02-29 01:29:58472 int breakpad_registration_success_count =
473 pref->GetInteger(prefs::kStabilityBreakpadRegistrationSuccess);
[email protected]e324f6b2012-02-28 05:43:37474 pref->SetInteger(prefs::kStabilityBreakpadRegistrationSuccess, 0);
[email protected]fe58acc22012-02-29 01:29:58475 int breakpad_registration_failure_count =
476 pref->GetInteger(prefs::kStabilityBreakpadRegistrationFail);
[email protected]e324f6b2012-02-28 05:43:37477 pref->SetInteger(prefs::kStabilityBreakpadRegistrationFail, 0);
[email protected]fe58acc22012-02-29 01:29:58478 int debugger_present_count =
479 pref->GetInteger(prefs::kStabilityDebuggerPresent);
[email protected]e324f6b2012-02-28 05:43:37480 pref->SetInteger(prefs::kStabilityDebuggerPresent, 0);
[email protected]fe58acc22012-02-29 01:29:58481 int debugger_not_present_count =
482 pref->GetInteger(prefs::kStabilityDebuggerNotPresent);
[email protected]e324f6b2012-02-28 05:43:37483 pref->SetInteger(prefs::kStabilityDebuggerNotPresent, 0);
[email protected]b2a4812d2012-02-28 05:31:31484
[email protected]fe58acc22012-02-29 01:29:58485 // TODO(jar): The following are all optional, so we *could* optimize them for
486 // values of zero (and not include them).
487
488 // Write the XML version.
489 WriteIntAttribute("incompleteshutdowncount", incomplete_shutdown_count);
490 WriteIntAttribute("breakpadregistrationok",
491 breakpad_registration_success_count);
492 WriteIntAttribute("breakpadregistrationfail",
493 breakpad_registration_failure_count);
494 WriteIntAttribute("debuggerpresent", debugger_present_count);
495 WriteIntAttribute("debuggernotpresent", debugger_not_present_count);
496
497 // Write the protobuf version.
498 SystemProfileProto::Stability* stability =
[email protected]767c9d92012-03-02 16:04:34499 uma_proto()->mutable_system_profile()->mutable_stability();
[email protected]fe58acc22012-02-29 01:29:58500 stability->set_incomplete_shutdown_count(incomplete_shutdown_count);
501 stability->set_breakpad_registration_success_count(
502 breakpad_registration_success_count);
503 stability->set_breakpad_registration_failure_count(
504 breakpad_registration_failure_count);
505 stability->set_debugger_present_count(debugger_present_count);
506 stability->set_debugger_not_present_count(debugger_not_present_count);
507
508 WritePluginStabilityElements(plugin_list, pref);
[email protected]147bbc0b2009-01-06 19:37:40509}
510
[email protected]fe58acc22012-02-29 01:29:58511void MetricsLog::WritePluginStabilityElements(
512 const std::vector<webkit::WebPluginInfo>& plugin_list,
513 PrefService* pref) {
[email protected]147bbc0b2009-01-06 19:37:40514 // Now log plugin stability info.
initial.commit09911bf2008-07-26 23:55:29515 const ListValue* plugin_stats_list = pref->GetList(
516 prefs::kStabilityPluginStats);
[email protected]1df44b72012-01-19 05:20:34517 if (!plugin_stats_list)
518 return;
initial.commit09911bf2008-07-26 23:55:29519
[email protected]1df44b72012-01-19 05:20:34520 OPEN_ELEMENT_FOR_SCOPE("plugins");
[email protected]ebd71962012-12-20 02:56:55521
522#if defined(ENABLE_PLUGINS)
[email protected]fe58acc22012-02-29 01:29:58523 SystemProfileProto::Stability* stability =
[email protected]767c9d92012-03-02 16:04:34524 uma_proto()->mutable_system_profile()->mutable_stability();
[email protected]fe58acc22012-02-29 01:29:58525 PluginPrefs* plugin_prefs = GetPluginPrefs();
[email protected]1df44b72012-01-19 05:20:34526 for (ListValue::const_iterator iter = plugin_stats_list->begin();
527 iter != plugin_stats_list->end(); ++iter) {
528 if (!(*iter)->IsType(Value::TYPE_DICTIONARY)) {
529 NOTREACHED();
530 continue;
initial.commit09911bf2008-07-26 23:55:29531 }
[email protected]1df44b72012-01-19 05:20:34532 DictionaryValue* plugin_dict = static_cast<DictionaryValue*>(*iter);
initial.commit09911bf2008-07-26 23:55:29533
[email protected]1df44b72012-01-19 05:20:34534 std::string plugin_name;
535 plugin_dict->GetString(prefs::kStabilityPluginName, &plugin_name);
536
[email protected]fe58acc22012-02-29 01:29:58537 std::string base64_name_hash;
538 uint64 numeric_name_hash_ignored;
539 CreateHashes(plugin_name, &base64_name_hash, &numeric_name_hash_ignored);
540
541 // Write the XML verison.
[email protected]1df44b72012-01-19 05:20:34542 OPEN_ELEMENT_FOR_SCOPE("pluginstability");
543 // Use "filename" instead of "name", otherwise we need to update the
544 // UMA servers.
[email protected]fe58acc22012-02-29 01:29:58545 WriteAttribute("filename", base64_name_hash);
[email protected]1df44b72012-01-19 05:20:34546
547 int launches = 0;
548 plugin_dict->GetInteger(prefs::kStabilityPluginLaunches, &launches);
549 WriteIntAttribute("launchcount", launches);
550
551 int instances = 0;
552 plugin_dict->GetInteger(prefs::kStabilityPluginInstances, &instances);
553 WriteIntAttribute("instancecount", instances);
554
555 int crashes = 0;
556 plugin_dict->GetInteger(prefs::kStabilityPluginCrashes, &crashes);
557 WriteIntAttribute("crashcount", crashes);
[email protected]fe58acc22012-02-29 01:29:58558
559 // Write the protobuf version.
560 // Note that this search is potentially a quadratic operation, but given the
561 // low number of plugins installed on a "reasonable" setup, this should be
562 // fine.
563 // TODO(isherman): Verify that this does not show up as a hotspot in
564 // profiler runs.
565 const webkit::WebPluginInfo* plugin_info = NULL;
566 const string16 plugin_name_utf16 = UTF8ToUTF16(plugin_name);
567 for (std::vector<webkit::WebPluginInfo>::const_iterator iter =
568 plugin_list.begin();
569 iter != plugin_list.end(); ++iter) {
570 if (iter->name == plugin_name_utf16) {
571 plugin_info = &(*iter);
572 break;
573 }
574 }
575
576 if (!plugin_info) {
577 NOTREACHED();
578 continue;
579 }
[email protected]cd937072012-07-02 09:00:29580 int loading_errors = 0;
581 plugin_dict->GetInteger(prefs::kStabilityPluginLoadingErrors,
582 &loading_errors);
583 WriteIntAttribute("loadingerrorcount", loading_errors);
[email protected]fe58acc22012-02-29 01:29:58584
[email protected]cd937072012-07-02 09:00:29585 // Write the protobuf version.
[email protected]fe58acc22012-02-29 01:29:58586 SystemProfileProto::Stability::PluginStability* plugin_stability =
587 stability->add_plugin_stability();
588 SetPluginInfo(*plugin_info, plugin_prefs,
589 plugin_stability->mutable_plugin());
590 plugin_stability->set_launch_count(launches);
591 plugin_stability->set_instance_count(instances);
592 plugin_stability->set_crash_count(crashes);
[email protected]cd937072012-07-02 09:00:29593 plugin_stability->set_loading_error_count(loading_errors);
initial.commit09911bf2008-07-26 23:55:29594 }
[email protected]ebd71962012-12-20 02:56:55595#endif // defined(ENABLE_PLUGINS)
[email protected]1df44b72012-01-19 05:20:34596
597 pref->ClearPref(prefs::kStabilityPluginStats);
initial.commit09911bf2008-07-26 23:55:29598}
599
[email protected]fe58acc22012-02-29 01:29:58600// The server refuses data that doesn't have certain values. crashcount and
601// launchcount are currently "required" in the "stability" group.
602// TODO(isherman): Stop writing these attributes specially once the migration to
603// protobufs is complete.
[email protected]147bbc0b2009-01-06 19:37:40604void MetricsLog::WriteRequiredStabilityAttributes(PrefService* pref) {
[email protected]fe58acc22012-02-29 01:29:58605 int launch_count = pref->GetInteger(prefs::kStabilityLaunchCount);
[email protected]0b33f80b2008-12-17 21:34:36606 pref->SetInteger(prefs::kStabilityLaunchCount, 0);
[email protected]fe58acc22012-02-29 01:29:58607 int crash_count = pref->GetInteger(prefs::kStabilityCrashCount);
[email protected]0b33f80b2008-12-17 21:34:36608 pref->SetInteger(prefs::kStabilityCrashCount, 0);
[email protected]fe58acc22012-02-29 01:29:58609
610 // Write the XML version.
611 WriteIntAttribute("launchcount", launch_count);
612 WriteIntAttribute("crashcount", crash_count);
613
614 // Write the protobuf version.
615 SystemProfileProto::Stability* stability =
[email protected]767c9d92012-03-02 16:04:34616 uma_proto()->mutable_system_profile()->mutable_stability();
[email protected]fe58acc22012-02-29 01:29:58617 stability->set_launch_count(launch_count);
618 stability->set_crash_count(crash_count);
[email protected]0b33f80b2008-12-17 21:34:36619}
620
[email protected]147bbc0b2009-01-06 19:37:40621void MetricsLog::WriteRealtimeStabilityAttributes(PrefService* pref) {
[email protected]0b33f80b2008-12-17 21:34:36622 // Update the stats which are critical for real-time stability monitoring.
623 // Since these are "optional," only list ones that are non-zero, as the counts
624 // are aggergated (summed) server side.
625
[email protected]fe58acc22012-02-29 01:29:58626 SystemProfileProto::Stability* stability =
[email protected]767c9d92012-03-02 16:04:34627 uma_proto()->mutable_system_profile()->mutable_stability();
[email protected]0b33f80b2008-12-17 21:34:36628 int count = pref->GetInteger(prefs::kStabilityPageLoadCount);
629 if (count) {
630 WriteIntAttribute("pageloadcount", count);
[email protected]fe58acc22012-02-29 01:29:58631 stability->set_page_load_count(count);
[email protected]0b33f80b2008-12-17 21:34:36632 pref->SetInteger(prefs::kStabilityPageLoadCount, 0);
633 }
634
635 count = pref->GetInteger(prefs::kStabilityRendererCrashCount);
636 if (count) {
637 WriteIntAttribute("renderercrashcount", count);
[email protected]fe58acc22012-02-29 01:29:58638 stability->set_renderer_crash_count(count);
[email protected]0b33f80b2008-12-17 21:34:36639 pref->SetInteger(prefs::kStabilityRendererCrashCount, 0);
640 }
641
[email protected]1f085622009-12-04 05:33:45642 count = pref->GetInteger(prefs::kStabilityExtensionRendererCrashCount);
643 if (count) {
644 WriteIntAttribute("extensionrenderercrashcount", count);
[email protected]fe58acc22012-02-29 01:29:58645 stability->set_extension_renderer_crash_count(count);
[email protected]1f085622009-12-04 05:33:45646 pref->SetInteger(prefs::kStabilityExtensionRendererCrashCount, 0);
647 }
648
[email protected]0b33f80b2008-12-17 21:34:36649 count = pref->GetInteger(prefs::kStabilityRendererHangCount);
650 if (count) {
651 WriteIntAttribute("rendererhangcount", count);
[email protected]fe58acc22012-02-29 01:29:58652 stability->set_renderer_hang_count(count);
[email protected]0b33f80b2008-12-17 21:34:36653 pref->SetInteger(prefs::kStabilityRendererHangCount, 0);
654 }
[email protected]1f085622009-12-04 05:33:45655
656 count = pref->GetInteger(prefs::kStabilityChildProcessCrashCount);
657 if (count) {
658 WriteIntAttribute("childprocesscrashcount", count);
[email protected]fe58acc22012-02-29 01:29:58659 stability->set_child_process_crash_count(count);
[email protected]1f085622009-12-04 05:33:45660 pref->SetInteger(prefs::kStabilityChildProcessCrashCount, 0);
661 }
[email protected]9165f742010-03-10 22:55:01662
[email protected]c1834a92011-01-21 18:21:03663#if defined(OS_CHROMEOS)
664 count = pref->GetInteger(prefs::kStabilityOtherUserCrashCount);
665 if (count) {
[email protected]fe58acc22012-02-29 01:29:58666 stability->set_other_user_crash_count(count);
[email protected]c1834a92011-01-21 18:21:03667 pref->SetInteger(prefs::kStabilityOtherUserCrashCount, 0);
668 }
669
670 count = pref->GetInteger(prefs::kStabilityKernelCrashCount);
671 if (count) {
[email protected]fe58acc22012-02-29 01:29:58672 stability->set_kernel_crash_count(count);
[email protected]c1834a92011-01-21 18:21:03673 pref->SetInteger(prefs::kStabilityKernelCrashCount, 0);
674 }
675
676 count = pref->GetInteger(prefs::kStabilitySystemUncleanShutdownCount);
677 if (count) {
[email protected]fe58acc22012-02-29 01:29:58678 stability->set_unclean_system_shutdown_count(count);
[email protected]c1834a92011-01-21 18:21:03679 pref->SetInteger(prefs::kStabilitySystemUncleanShutdownCount, 0);
680 }
681#endif // OS_CHROMEOS
682
[email protected]9165f742010-03-10 22:55:01683 int64 recent_duration = GetIncrementalUptime(pref);
[email protected]fe58acc22012-02-29 01:29:58684 if (recent_duration) {
[email protected]9165f742010-03-10 22:55:01685 WriteInt64Attribute("uptimesec", recent_duration);
[email protected]fe58acc22012-02-29 01:29:58686 stability->set_uptime_sec(recent_duration);
687 }
[email protected]0b33f80b2008-12-17 21:34:36688}
689
initial.commit09911bf2008-07-26 23:55:29690void MetricsLog::WritePluginList(
[email protected]bc66d532012-03-23 01:57:05691 const std::vector<webkit::WebPluginInfo>& plugin_list,
692 bool write_as_xml) {
[email protected]767c9d92012-03-02 16:04:34693 DCHECK(!locked());
initial.commit09911bf2008-07-26 23:55:29694
[email protected]ffaf78a2008-11-12 17:38:33695 OPEN_ELEMENT_FOR_SCOPE("plugins");
[email protected]ebd71962012-12-20 02:56:55696
697#if defined(ENABLE_PLUGINS)
698 PluginPrefs* plugin_prefs = GetPluginPrefs();
[email protected]767c9d92012-03-02 16:04:34699 SystemProfileProto* system_profile = uma_proto()->mutable_system_profile();
[email protected]91d9f3d2011-08-14 05:24:44700 for (std::vector<webkit::WebPluginInfo>::const_iterator iter =
[email protected]191eb3f72010-12-21 06:27:50701 plugin_list.begin();
initial.commit09911bf2008-07-26 23:55:29702 iter != plugin_list.end(); ++iter) {
[email protected]bc66d532012-03-23 01:57:05703 if (write_as_xml) {
704 std::string base64_name_hash;
705 uint64 numeric_hash_ignored;
706 CreateHashes(UTF16ToUTF8(iter->name), &base64_name_hash,
707 &numeric_hash_ignored);
[email protected]fe58acc22012-02-29 01:29:58708
[email protected]bc66d532012-03-23 01:57:05709 std::string filename_bytes = iter->path.BaseName().AsUTF8Unsafe();
710 std::string base64_filename_hash;
711 CreateHashes(filename_bytes, &base64_filename_hash,
712 &numeric_hash_ignored);
[email protected]fe58acc22012-02-29 01:29:58713
[email protected]bc66d532012-03-23 01:57:05714 // Write the XML version.
715 OPEN_ELEMENT_FOR_SCOPE("plugin");
initial.commit09911bf2008-07-26 23:55:29716
[email protected]bc66d532012-03-23 01:57:05717 // Plugin name and filename are hashed for the privacy of those
718 // testing unreleased new extensions.
719 WriteAttribute("name", base64_name_hash);
720 WriteAttribute("filename", base64_filename_hash);
721 WriteAttribute("version", UTF16ToUTF8(iter->version));
722 if (plugin_prefs)
723 WriteIntAttribute("disabled", !plugin_prefs->IsPluginEnabled(*iter));
724 } else {
725 // Write the protobuf version.
726 SystemProfileProto::Plugin* plugin = system_profile->add_plugin();
727 SetPluginInfo(*iter, plugin_prefs, plugin);
728 }
initial.commit09911bf2008-07-26 23:55:29729 }
[email protected]ebd71962012-12-20 02:56:55730#endif // defined(ENABLE_PLUGINS)
initial.commit09911bf2008-07-26 23:55:29731}
732
[email protected]147bbc0b2009-01-06 19:37:40733void MetricsLog::WriteInstallElement() {
[email protected]fe58acc22012-02-29 01:29:58734 // Write the XML version.
[email protected]bc66d532012-03-23 01:57:05735 // We'll write the protobuf version in RecordEnvironmentProto().
[email protected]147bbc0b2009-01-06 19:37:40736 OPEN_ELEMENT_FOR_SCOPE("install");
[email protected]cc5d7f42012-10-30 00:30:09737 WriteAttribute("installdate", GetMetricsEnabledDate(GetPrefService()));
[email protected]147bbc0b2009-01-06 19:37:40738 WriteIntAttribute("buildid", 0); // We're using appversion instead.
[email protected]147bbc0b2009-01-06 19:37:40739}
740
initial.commit09911bf2008-07-26 23:55:29741void MetricsLog::RecordEnvironment(
[email protected]91d9f3d2011-08-14 05:24:44742 const std::vector<webkit::WebPluginInfo>& plugin_list,
[email protected]197c0772012-05-14 23:50:51743 const GoogleUpdateMetrics& google_update_metrics,
initial.commit09911bf2008-07-26 23:55:29744 const DictionaryValue* profile_metrics) {
[email protected]767c9d92012-03-02 16:04:34745 DCHECK(!locked());
initial.commit09911bf2008-07-26 23:55:29746
[email protected]767c9d92012-03-02 16:04:34747 PrefService* pref = GetPrefService();
initial.commit09911bf2008-07-26 23:55:29748
[email protected]ffaf78a2008-11-12 17:38:33749 OPEN_ELEMENT_FOR_SCOPE("profile");
initial.commit09911bf2008-07-26 23:55:29750 WriteCommonEventAttributes();
751
[email protected]147bbc0b2009-01-06 19:37:40752 WriteInstallElement();
initial.commit09911bf2008-07-26 23:55:29753
[email protected]bc66d532012-03-23 01:57:05754 // Write the XML version.
755 // We'll write the protobuf version in RecordEnvironmentProto().
756 bool write_as_xml = true;
757 WritePluginList(plugin_list, write_as_xml);
initial.commit09911bf2008-07-26 23:55:29758
[email protected]fe58acc22012-02-29 01:29:58759 WriteStabilityElement(plugin_list, pref);
initial.commit09911bf2008-07-26 23:55:29760
761 {
[email protected]fe58acc22012-02-29 01:29:58762 // Write the XML version.
[email protected]bc66d532012-03-23 01:57:05763 // We'll write the protobuf version in RecordEnvironmentProto().
initial.commit09911bf2008-07-26 23:55:29764 OPEN_ELEMENT_FOR_SCOPE("cpu");
[email protected]0b6a4fb2012-10-16 01:58:21765 WriteAttribute("arch", base::SysInfo::OperatingSystemArchitecture());
initial.commit09911bf2008-07-26 23:55:29766 }
767
768 {
[email protected]fe58acc22012-02-29 01:29:58769 // Write the XML version.
[email protected]bc66d532012-03-23 01:57:05770 // We'll write the protobuf version in RecordEnvironmentProto().
initial.commit09911bf2008-07-26 23:55:29771 OPEN_ELEMENT_FOR_SCOPE("memory");
[email protected]bc66d532012-03-23 01:57:05772 WriteIntAttribute("mb", base::SysInfo::AmountOfPhysicalMemoryMB());
[email protected]d1be67b2008-11-19 20:28:38773#if defined(OS_WIN)
774 WriteIntAttribute("dllbase", reinterpret_cast<int>(&__ImageBase));
775#endif
initial.commit09911bf2008-07-26 23:55:29776 }
777
778 {
[email protected]fe58acc22012-02-29 01:29:58779 // Write the XML version.
[email protected]bc66d532012-03-23 01:57:05780 // We'll write the protobuf version in RecordEnvironmentProto().
initial.commit09911bf2008-07-26 23:55:29781 OPEN_ELEMENT_FOR_SCOPE("os");
[email protected]bc66d532012-03-23 01:57:05782 WriteAttribute("name", base::SysInfo::OperatingSystemName());
783 WriteAttribute("version", base::SysInfo::OperatingSystemVersion());
initial.commit09911bf2008-07-26 23:55:29784 }
785
786 {
[email protected]e8c287c872010-07-20 00:49:42787 OPEN_ELEMENT_FOR_SCOPE("gpu");
[email protected]d7b5cc72013-05-23 20:05:00788 const gpu::GPUInfo& gpu_info =
[email protected]fe58acc22012-02-29 01:29:58789 GpuDataManager::GetInstance()->GetGPUInfo();
[email protected]fe58acc22012-02-29 01:29:58790
791 // Write the XML version.
[email protected]bc66d532012-03-23 01:57:05792 // We'll write the protobuf version in RecordEnvironmentProto().
[email protected]a094e2c2012-05-10 23:02:42793 WriteIntAttribute("vendorid", gpu_info.gpu.vendor_id);
794 WriteIntAttribute("deviceid", gpu_info.gpu.device_id);
[email protected]e8c287c872010-07-20 00:49:42795 }
796
797 {
[email protected]767c9d92012-03-02 16:04:34798 const gfx::Size display_size = GetScreenSize();
[email protected]fe58acc22012-02-29 01:29:58799
800 // Write the XML version.
[email protected]bc66d532012-03-23 01:57:05801 // We'll write the protobuf version in RecordEnvironmentProto().
[email protected]fe58acc22012-02-29 01:29:58802 OPEN_ELEMENT_FOR_SCOPE("display");
[email protected]bc66d532012-03-23 01:57:05803 WriteIntAttribute("xsize", display_size.width());
804 WriteIntAttribute("ysize", display_size.height());
805 WriteIntAttribute("screens", GetScreenCount());
initial.commit09911bf2008-07-26 23:55:29806 }
807
808 {
809 OPEN_ELEMENT_FOR_SCOPE("bookmarks");
initial.commit09911bf2008-07-26 23:55:29810 {
811 OPEN_ELEMENT_FOR_SCOPE("bookmarklocation");
812 WriteAttribute("name", "full-tree");
[email protected]8542bcc2013-01-30 00:15:36813 WriteIntAttribute("foldercount", 0);
814 WriteIntAttribute("itemcount", 0);
initial.commit09911bf2008-07-26 23:55:29815 }
816 {
817 OPEN_ELEMENT_FOR_SCOPE("bookmarklocation");
818 WriteAttribute("name", "toolbar");
[email protected]8542bcc2013-01-30 00:15:36819 WriteIntAttribute("foldercount", 0);
820 WriteIntAttribute("itemcount", 0);
initial.commit09911bf2008-07-26 23:55:29821 }
822 }
823
824 {
825 OPEN_ELEMENT_FOR_SCOPE("keywords");
826 WriteIntAttribute("count", pref->GetInteger(prefs::kNumKeywords));
827 }
828
829 if (profile_metrics)
830 WriteAllProfilesMetrics(*profile_metrics);
[email protected]767c9d92012-03-02 16:04:34831
[email protected]197c0772012-05-14 23:50:51832 RecordEnvironmentProto(plugin_list, google_update_metrics);
[email protected]bc66d532012-03-23 01:57:05833}
834
835void MetricsLog::RecordEnvironmentProto(
[email protected]197c0772012-05-14 23:50:51836 const std::vector<webkit::WebPluginInfo>& plugin_list,
837 const GoogleUpdateMetrics& google_update_metrics) {
[email protected]bc66d532012-03-23 01:57:05838 SystemProfileProto* system_profile = uma_proto()->mutable_system_profile();
[email protected]24b9bb392013-01-29 20:29:29839
840 std::string brand_code;
841 if (google_util::GetBrand(&brand_code))
842 system_profile->set_brand_code(brand_code);
843
[email protected]cc5d7f42012-10-30 00:30:09844 int enabled_date;
845 bool success = base::StringToInt(GetMetricsEnabledDate(GetPrefService()),
846 &enabled_date);
[email protected]bc66d532012-03-23 01:57:05847 DCHECK(success);
[email protected]cc5d7f42012-10-30 00:30:09848 system_profile->set_uma_enabled_date(enabled_date);
[email protected]bc66d532012-03-23 01:57:05849
850 system_profile->set_application_locale(
[email protected]eabbfb12013-04-05 23:28:35851 g_browser_process->GetApplicationLocale());
[email protected]bc66d532012-03-23 01:57:05852
853 SystemProfileProto::Hardware* hardware = system_profile->mutable_hardware();
[email protected]0b6a4fb2012-10-16 01:58:21854 hardware->set_cpu_architecture(base::SysInfo::OperatingSystemArchitecture());
[email protected]bc66d532012-03-23 01:57:05855 hardware->set_system_ram_mb(base::SysInfo::AmountOfPhysicalMemoryMB());
856#if defined(OS_WIN)
857 hardware->set_dll_base(reinterpret_cast<uint64>(&__ImageBase));
858#endif
859
[email protected]74b299e2013-01-29 01:24:42860 SystemProfileProto::Network* network = system_profile->mutable_network();
861 network->set_connection_type_is_ambiguous(
[email protected]5eae204c2013-02-13 15:53:42862 network_observer_.connection_type_is_ambiguous());
863 network->set_connection_type(network_observer_.connection_type());
864 network->set_wifi_phy_layer_protocol_is_ambiguous(
865 network_observer_.wifi_phy_layer_protocol_is_ambiguous());
866 network->set_wifi_phy_layer_protocol(
867 network_observer_.wifi_phy_layer_protocol());
868 network_observer_.Reset();
[email protected]74b299e2013-01-29 01:24:42869
[email protected]bc66d532012-03-23 01:57:05870 SystemProfileProto::OS* os = system_profile->mutable_os();
[email protected]1bb25e02012-08-03 22:39:39871 std::string os_name = base::SysInfo::OperatingSystemName();
872#if defined(OS_WIN)
873 // TODO(mad): This only checks whether the main process is a Metro process at
874 // upload time; not whether the collected metrics were all gathered from
875 // Metro. This is ok as an approximation for now, since users will rarely be
876 // switching from Metro to Desktop mode; but we should re-evaluate whether we
877 // can distinguish metrics more cleanly in the future: http://crbug.com/140568
878 if (base::win::IsMetroProcess())
879 os_name += " (Metro)";
880#endif
881 os->set_name(os_name);
[email protected]bc66d532012-03-23 01:57:05882 os->set_version(base::SysInfo::OperatingSystemVersion());
[email protected]5106b3a2012-10-03 20:10:44883#if defined(OS_ANDROID)
884 os->set_fingerprint(
885 base::android::BuildInfo::GetInstance()->android_build_fp());
886#endif
[email protected]bc66d532012-03-23 01:57:05887
[email protected]d7b5cc72013-05-23 20:05:00888 const gpu::GPUInfo& gpu_info =
[email protected]bc66d532012-03-23 01:57:05889 GpuDataManager::GetInstance()->GetGPUInfo();
890 SystemProfileProto::Hardware::Graphics* gpu = hardware->mutable_gpu();
[email protected]a094e2c2012-05-10 23:02:42891 gpu->set_vendor_id(gpu_info.gpu.vendor_id);
892 gpu->set_device_id(gpu_info.gpu.device_id);
[email protected]bc66d532012-03-23 01:57:05893 gpu->set_driver_version(gpu_info.driver_version);
894 gpu->set_driver_date(gpu_info.driver_date);
895 SystemProfileProto::Hardware::Graphics::PerformanceStatistics*
896 gpu_performance = gpu->mutable_performance_statistics();
897 gpu_performance->set_graphics_score(gpu_info.performance_stats.graphics);
898 gpu_performance->set_gaming_score(gpu_info.performance_stats.gaming);
899 gpu_performance->set_overall_score(gpu_info.performance_stats.overall);
[email protected]d6bdfae2013-01-18 20:23:01900 gpu->set_gl_vendor(gpu_info.gl_vendor);
901 gpu->set_gl_renderer(gpu_info.gl_renderer);
[email protected]bc66d532012-03-23 01:57:05902
903 const gfx::Size display_size = GetScreenSize();
904 hardware->set_primary_screen_width(display_size.width());
905 hardware->set_primary_screen_height(display_size.height());
[email protected]aa96417972012-08-22 03:16:44906 hardware->set_primary_screen_scale_factor(GetScreenDeviceScaleFactor());
[email protected]bc66d532012-03-23 01:57:05907 hardware->set_screen_count(GetScreenCount());
908
[email protected]76869ff2013-01-15 16:13:47909#if defined(OS_WIN)
910 WriteScreenDPIInformationProto(hardware);
911#endif
912
[email protected]197c0772012-05-14 23:50:51913 WriteGoogleUpdateProto(google_update_metrics);
914
[email protected]bc66d532012-03-23 01:57:05915 bool write_as_xml = false;
916 WritePluginList(plugin_list, write_as_xml);
917
[email protected]0c8b7ad2012-11-06 07:08:14918 std::vector<ActiveGroupId> field_trial_ids;
[email protected]767c9d92012-03-02 16:04:34919 GetFieldTrialIds(&field_trial_ids);
920 WriteFieldTrials(field_trial_ids, system_profile);
[email protected]f65859e2013-02-04 20:00:25921
922#if defined(OS_CHROMEOS)
923 PerfDataProto perf_data_proto;
924 if (perf_provider_.GetPerfData(&perf_data_proto))
925 uma_proto()->add_perf_data()->Swap(&perf_data_proto);
[email protected]611ae29a2013-04-29 21:32:19926
927 // BluetoothAdapterFactory::GetAdapter is synchronous on Chrome OS; if that
928 // changes this will fail at the DCHECK().
929 device::BluetoothAdapterFactory::GetAdapter(
930 base::Bind(&MetricsLog::SetBluetoothAdapter,
931 base::Unretained(this)));
932 DCHECK(adapter_.get());
933 WriteBluetoothProto(hardware);
[email protected]f65859e2013-02-04 20:00:25934#endif
initial.commit09911bf2008-07-26 23:55:29935}
936
[email protected]ed0fd002012-04-25 23:10:34937void MetricsLog::RecordProfilerData(
938 const tracked_objects::ProcessDataSnapshot& process_data,
[email protected]f3b357692013-03-22 05:16:13939 int process_type) {
[email protected]ed0fd002012-04-25 23:10:34940 DCHECK(!locked());
941
[email protected]8f829682012-04-27 00:36:49942 if (tracked_objects::GetTimeSourceType() !=
943 tracked_objects::TIME_SOURCE_TYPE_WALL_TIME) {
[email protected]ed0fd002012-04-25 23:10:34944 // We currently only support the default time source, wall clock time.
945 return;
946 }
947
948 ProfilerEventProto* profile;
949 if (!uma_proto()->profiler_event_size()) {
950 // For the first process's data, add a new field to the protocol buffer.
951 profile = uma_proto()->add_profiler_event();
952 profile->set_profile_type(ProfilerEventProto::STARTUP_PROFILE);
953 profile->set_time_source(ProfilerEventProto::WALL_CLOCK_TIME);
954 } else {
955 // For the remaining calls, re-use the existing field.
956 profile = uma_proto()->mutable_profiler_event(0);
957 }
958
959 WriteProfilerData(process_data, process_type, profile);
960}
961
initial.commit09911bf2008-07-26 23:55:29962void MetricsLog::WriteAllProfilesMetrics(
963 const DictionaryValue& all_profiles_metrics) {
[email protected]57ecc4b2010-08-11 03:02:51964 const std::string profile_prefix(prefs::kProfilePrefix);
[email protected]a703e71e2013-02-26 23:58:14965 for (DictionaryValue::Iterator i(all_profiles_metrics); !i.IsAtEnd();
966 i.Advance()) {
967 if (i.key().compare(0, profile_prefix.size(), profile_prefix) == 0) {
[email protected]a61890e2012-07-27 22:27:11968 const DictionaryValue* profile;
[email protected]a703e71e2013-02-26 23:58:14969 if (i.value().GetAsDictionary(&profile))
970 WriteProfileMetrics(i.key().substr(profile_prefix.size()), *profile);
initial.commit09911bf2008-07-26 23:55:29971 }
972 }
973}
974
[email protected]e7b418b2010-07-30 19:47:47975void MetricsLog::WriteProfileMetrics(const std::string& profileidhash,
initial.commit09911bf2008-07-26 23:55:29976 const DictionaryValue& profile_metrics) {
977 OPEN_ELEMENT_FOR_SCOPE("userprofile");
[email protected]e7b418b2010-07-30 19:47:47978 WriteAttribute("profileidhash", profileidhash);
[email protected]a703e71e2013-02-26 23:58:14979 for (DictionaryValue::Iterator i(profile_metrics); !i.IsAtEnd();
980 i.Advance()) {
981 DCHECK_NE(i.key(), "id");
982 switch (i.value().GetType()) {
983 case Value::TYPE_STRING: {
984 std::string string_value;
985 if (i.value().GetAsString(&string_value)) {
986 OPEN_ELEMENT_FOR_SCOPE("profileparam");
987 WriteAttribute("name", i.key());
988 WriteAttribute("value", string_value);
initial.commit09911bf2008-07-26 23:55:29989 }
[email protected]a703e71e2013-02-26 23:58:14990 break;
initial.commit09911bf2008-07-26 23:55:29991 }
[email protected]a703e71e2013-02-26 23:58:14992
993 case Value::TYPE_BOOLEAN: {
994 bool bool_value;
995 if (i.value().GetAsBoolean(&bool_value)) {
996 OPEN_ELEMENT_FOR_SCOPE("profileparam");
997 WriteAttribute("name", i.key());
998 WriteIntAttribute("value", bool_value ? 1 : 0);
999 }
1000 break;
1001 }
1002
1003 case Value::TYPE_INTEGER: {
1004 int int_value;
1005 if (i.value().GetAsInteger(&int_value)) {
1006 OPEN_ELEMENT_FOR_SCOPE("profileparam");
1007 WriteAttribute("name", i.key());
1008 WriteIntAttribute("value", int_value);
1009 }
1010 break;
1011 }
1012
1013 default:
1014 NOTREACHED();
1015 break;
initial.commit09911bf2008-07-26 23:55:291016 }
1017 }
1018}
1019
[email protected]0fafc8d2013-06-01 00:09:501020void MetricsLog::RecordOmniboxOpenedURL(const OmniboxLog& log) {
[email protected]767c9d92012-03-02 16:04:341021 DCHECK(!locked());
initial.commit09911bf2008-07-26 23:55:291022
[email protected]fe58acc22012-02-29 01:29:581023 // Write the XML version.
[email protected]ffaf78a2008-11-12 17:38:331024 OPEN_ELEMENT_FOR_SCOPE("uielement");
initial.commit09911bf2008-07-26 23:55:291025 WriteAttribute("action", "autocomplete");
[email protected]007b3f82013-04-09 08:46:451026 WriteAttribute("targetidhash", std::string());
initial.commit09911bf2008-07-26 23:55:291027 // TODO(kochi): Properly track windows.
1028 WriteIntAttribute("window", 0);
[email protected]6ebc3162011-12-19 13:44:001029 if (log.tab_id != -1) {
1030 // If we know what tab the autocomplete URL was opened in, log it.
1031 WriteIntAttribute("tab", static_cast<int>(log.tab_id));
1032 }
initial.commit09911bf2008-07-26 23:55:291033 WriteCommonEventAttributes();
1034
[email protected]65956312012-04-19 21:28:121035 std::vector<string16> terms;
1036 const int num_terms =
1037 static_cast<int>(Tokenize(log.text, kWhitespaceUTF16, &terms));
[email protected]ffaf78a2008-11-12 17:38:331038 {
1039 OPEN_ELEMENT_FOR_SCOPE("autocomplete");
initial.commit09911bf2008-07-26 23:55:291040
[email protected]ffaf78a2008-11-12 17:38:331041 WriteIntAttribute("typedlength", static_cast<int>(log.text.length()));
[email protected]65956312012-04-19 21:28:121042 WriteIntAttribute("numterms", num_terms);
[email protected]ffaf78a2008-11-12 17:38:331043 WriteIntAttribute("selectedindex", static_cast<int>(log.selected_index));
1044 WriteIntAttribute("completedlength",
[email protected]62b3ef52013-01-18 00:13:021045 log.completed_length != string16::npos ?
1046 static_cast<int>(log.completed_length) : 0);
[email protected]9e349762012-01-31 03:24:361047 if (log.elapsed_time_since_user_first_modified_omnibox !=
1048 base::TimeDelta::FromMilliseconds(-1)) {
1049 // Only upload the typing duration if it is set/valid.
1050 WriteInt64Attribute("typingduration",
1051 log.elapsed_time_since_user_first_modified_omnibox.InMilliseconds());
1052 }
[email protected]381e2992008-12-16 01:41:001053 const std::string input_type(
1054 AutocompleteInput::TypeToString(log.input_type));
1055 if (!input_type.empty())
1056 WriteAttribute("inputtype", input_type);
initial.commit09911bf2008-07-26 23:55:291057
[email protected]ffaf78a2008-11-12 17:38:331058 for (AutocompleteResult::const_iterator i(log.result.begin());
1059 i != log.result.end(); ++i) {
1060 OPEN_ELEMENT_FOR_SCOPE("autocompleteitem");
1061 if (i->provider)
[email protected]35f1f4f02012-09-11 13:17:001062 WriteAttribute("provider", i->provider->GetName());
[email protected]b7f64d742013-05-21 04:04:041063 const std::string result_type(AutocompleteMatchType::ToString(i->type));
[email protected]381e2992008-12-16 01:41:001064 if (!result_type.empty())
1065 WriteAttribute("resulttype", result_type);
[email protected]ffaf78a2008-11-12 17:38:331066 WriteIntAttribute("relevance", i->relevance);
1067 WriteIntAttribute("isstarred", i->starred ? 1 : 0);
1068 }
initial.commit09911bf2008-07-26 23:55:291069 }
initial.commit09911bf2008-07-26 23:55:291070
[email protected]fe58acc22012-02-29 01:29:581071 // Write the protobuf version.
[email protected]767c9d92012-03-02 16:04:341072 OmniboxEventProto* omnibox_event = uma_proto()->add_omnibox_event();
[email protected]fe58acc22012-02-29 01:29:581073 omnibox_event->set_time(MetricsLogBase::GetCurrentTime());
1074 if (log.tab_id != -1) {
1075 // If we know what tab the autocomplete URL was opened in, log it.
1076 omnibox_event->set_tab_id(log.tab_id);
1077 }
1078 omnibox_event->set_typed_length(log.text.length());
[email protected]660fe8f32012-05-03 20:01:081079 omnibox_event->set_just_deleted_text(log.just_deleted_text);
[email protected]65956312012-04-19 21:28:121080 omnibox_event->set_num_typed_terms(num_terms);
[email protected]fe58acc22012-02-29 01:29:581081 omnibox_event->set_selected_index(log.selected_index);
[email protected]62b3ef52013-01-18 00:13:021082 if (log.completed_length != string16::npos)
1083 omnibox_event->set_completed_length(log.completed_length);
[email protected]65956312012-04-19 21:28:121084 if (log.elapsed_time_since_user_first_modified_omnibox !=
1085 base::TimeDelta::FromMilliseconds(-1)) {
1086 // Only upload the typing duration if it is set/valid.
1087 omnibox_event->set_typing_duration_ms(
1088 log.elapsed_time_since_user_first_modified_omnibox.InMilliseconds());
1089 }
[email protected]35d55602012-11-20 23:49:031090 omnibox_event->set_duration_since_last_default_match_update_ms(
1091 log.elapsed_time_since_last_change_to_default_match.InMilliseconds());
[email protected]ee902532012-05-01 23:54:491092 omnibox_event->set_current_page_classification(
1093 log.current_page_classification);
[email protected]fe58acc22012-02-29 01:29:581094 omnibox_event->set_input_type(AsOmniboxEventInputType(log.input_type));
1095 for (AutocompleteResult::const_iterator i(log.result.begin());
1096 i != log.result.end(); ++i) {
1097 OmniboxEventProto::Suggestion* suggestion = omnibox_event->add_suggestion();
[email protected]0e9e8782012-05-15 23:01:511098 suggestion->set_provider(i->provider->AsOmniboxEventProviderType());
[email protected]fe58acc22012-02-29 01:29:581099 suggestion->set_result_type(AsOmniboxEventResultType(i->type));
1100 suggestion->set_relevance(i->relevance);
[email protected]cf6256f2012-06-12 23:36:011101 if (i->typed_count != -1)
1102 suggestion->set_typed_count(i->typed_count);
[email protected]fe58acc22012-02-29 01:29:581103 suggestion->set_is_starred(i->starred);
1104 }
[email protected]0e9e8782012-05-15 23:01:511105 for (ProvidersInfo::const_iterator i(log.providers_info.begin());
1106 i != log.providers_info.end(); ++i) {
1107 OmniboxEventProto::ProviderInfo* provider_info =
1108 omnibox_event->add_provider_info();
1109 provider_info->CopyFrom(*i);
1110 }
[email protected]fe58acc22012-02-29 01:29:581111
initial.commit09911bf2008-07-26 23:55:291112 ++num_events_;
1113}
[email protected]197c0772012-05-14 23:50:511114
1115void MetricsLog::WriteGoogleUpdateProto(
1116 const GoogleUpdateMetrics& google_update_metrics) {
1117#if defined(GOOGLE_CHROME_BUILD) && defined(OS_WIN)
1118 SystemProfileProto::GoogleUpdate* google_update =
1119 uma_proto()->mutable_system_profile()->mutable_google_update();
1120
1121 google_update->set_is_system_install(google_update_metrics.is_system_install);
1122
1123 if (!google_update_metrics.last_started_au.is_null()) {
1124 google_update->set_last_automatic_start_timestamp(
1125 google_update_metrics.last_started_au.ToTimeT());
1126 }
1127
1128 if (!google_update_metrics.last_checked.is_null()) {
1129 google_update->set_last_update_check_timestamp(
1130 google_update_metrics.last_checked.ToTimeT());
1131 }
1132
1133 if (!google_update_metrics.google_update_data.version.empty()) {
1134 ProductDataToProto(google_update_metrics.google_update_data,
1135 google_update->mutable_google_update_status());
1136 }
1137
1138 if (!google_update_metrics.product_data.version.empty()) {
1139 ProductDataToProto(google_update_metrics.product_data,
1140 google_update->mutable_client_status());
1141 }
1142#endif // defined(GOOGLE_CHROME_BUILD) && defined(OS_WIN)
1143}
[email protected]611ae29a2013-04-29 21:32:191144
1145void MetricsLog::SetBluetoothAdapter(
1146 scoped_refptr<device::BluetoothAdapter> adapter) {
1147 adapter_ = adapter;
1148}
1149
1150void MetricsLog::WriteBluetoothProto(
1151 SystemProfileProto::Hardware* hardware) {
[email protected]728f9b22013-05-02 06:08:181152#if defined(OS_CHROMEOS)
[email protected]611ae29a2013-04-29 21:32:191153 SystemProfileProto::Hardware::Bluetooth* bluetooth =
1154 hardware->mutable_bluetooth();
1155
1156 bluetooth->set_is_present(adapter_->IsPresent());
1157 bluetooth->set_is_enabled(adapter_->IsPowered());
1158
1159 device::BluetoothAdapter::DeviceList devices = adapter_->GetDevices();
1160 for (device::BluetoothAdapter::DeviceList::iterator iter =
1161 devices.begin(); iter != devices.end(); ++iter) {
1162 PairedDevice* paired_device = bluetooth->add_paired_device();
1163
1164 device::BluetoothDevice* device = *iter;
1165 paired_device->set_bluetooth_class(device->GetBluetoothClass());
1166 paired_device->set_type(AsBluetoothDeviceType(device->GetDeviceType()));
1167
1168 // address is xx:xx:xx:xx:xx:xx, extract the first three components and
1169 // pack into a uint32
1170 std::string address = device->GetAddress();
1171 if (address.size() > 9 &&
1172 address[2] == ':' && address[5] == ':' && address[8] == ':') {
1173 std::string vendor_prefix_str;
1174 uint64 vendor_prefix;
1175
1176 RemoveChars(address.substr(0, 9), ":", &vendor_prefix_str);
1177 DCHECK_EQ(6U, vendor_prefix_str.size());
1178 base::HexStringToUInt64(vendor_prefix_str, &vendor_prefix);
1179
1180 paired_device->set_vendor_prefix(vendor_prefix);
1181 }
1182
1183 paired_device->set_vendor_id(device->GetVendorID());
1184 paired_device->set_product_id(device->GetProductID());
1185 paired_device->set_device_id(device->GetDeviceID());
1186 }
1187#endif // defined(OS_CHROMEOS)
1188}