blob: 76563f59b0475e9f1a4d1480ef14a35a148e687d [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"
[email protected]3ea1b182013-02-08 22:38:4119#include "base/strings/string_number_conversions.h"
[email protected]f9b294362013-06-10 20:22:3120#include "base/strings/string_util.h"
[email protected]112158af2013-06-07 23:46:1821#include "base/strings/utf_string_conversions.h"
[email protected]fadf97f2008-09-18 12:18:1422#include "base/sys_info.h"
[email protected]37f39e42010-01-06 17:35:1723#include "base/third_party/nspr/prtime.h"
[email protected]84813472013-06-28 00:25:1924#include "base/time/time.h"
[email protected]ed0fd002012-04-25 23:10:3425#include "base/tracked_objects.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]1eeb5e02010-07-20 23:02:1135#include "chrome/common/chrome_version_info.h"
initial.commit09911bf2008-07-26 23:55:2936#include "chrome/common/logging_chrome.h"
[email protected]fe58acc22012-02-29 01:29:5837#include "chrome/common/metrics/proto/omnibox_event.pb.h"
[email protected]ed0fd002012-04-25 23:10:3438#include "chrome/common/metrics/proto/profiler_event.pb.h"
[email protected]fe58acc22012-02-29 01:29:5839#include "chrome/common/metrics/proto/system_profile.pb.h"
[email protected]cf265dc02012-08-15 01:01:1640#include "chrome/common/metrics/variations/variations_util.h"
initial.commit09911bf2008-07-26 23:55:2941#include "chrome/common/pref_names.h"
[email protected]197c0772012-05-14 23:50:5142#include "chrome/installer/util/google_update_settings.h"
[email protected]d5d383252013-07-04 14:44:3243#include "components/nacl/common/nacl_process_type.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]d7b5cc72013-05-23 20:05:0049#include "gpu/config/gpu_info.h"
[email protected]6b7d954ff2011-10-25 00:39:3550#include "ui/gfx/screen.h"
[email protected]761fa4702013-07-02 15:25:1551#include "url/gurl.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
[email protected]d1be67b2008-11-19 20:28:3858#if defined(OS_WIN)
[email protected]1bb25e02012-08-03 22:39:3959#include "base/win/metro.h"
[email protected]e245ace92013-05-07 00:37:4160#include "ui/base/win/dpi.h"
[email protected]1bb25e02012-08-03 22:39:3961
62// http://blogs.msdn.com/oldnewthing/archive/2004/10/25/247180.aspx
[email protected]d1be67b2008-11-19 20:28:3863extern "C" IMAGE_DOS_HEADER __ImageBase;
64#endif
65
[email protected]79078df2012-02-16 01:22:3266using content::GpuDataManager;
[email protected]fe58acc22012-02-29 01:29:5867using metrics::OmniboxEventProto;
[email protected]f65859e2013-02-04 20:00:2568using metrics::PerfDataProto;
[email protected]ed0fd002012-04-25 23:10:3469using metrics::ProfilerEventProto;
[email protected]fe58acc22012-02-29 01:29:5870using metrics::SystemProfileProto;
[email protected]ed0fd002012-04-25 23:10:3471using tracked_objects::ProcessDataSnapshot;
[email protected]0c8b7ad2012-11-06 07:08:1472typedef chrome_variations::ActiveGroupId ActiveGroupId;
[email protected]197c0772012-05-14 23:50:5173typedef SystemProfileProto::GoogleUpdate::ProductInfo ProductInfo;
[email protected]611ae29a2013-04-29 21:32:1974typedef SystemProfileProto::Hardware::Bluetooth::PairedDevice PairedDevice;
[email protected]79078df2012-02-16 01:22:3275
[email protected]1df44b72012-01-19 05:20:3476namespace {
77
78// Returns the date at which the current metrics client ID was created as
[email protected]ca5ac4b2012-12-14 07:46:4079// a string containing seconds since the epoch, or "0" if none was found.
[email protected]cc5d7f42012-10-30 00:30:0980std::string GetMetricsEnabledDate(PrefService* pref) {
[email protected]767c9d92012-03-02 16:04:3481 if (!pref) {
[email protected]1df44b72012-01-19 05:20:3482 NOTREACHED();
83 return "0";
84 }
[email protected]767c9d92012-03-02 16:04:3485
86 return pref->GetString(prefs::kMetricsClientIDTimestamp);
[email protected]1df44b72012-01-19 05:20:3487}
88
[email protected]fe58acc22012-02-29 01:29:5889OmniboxEventProto::InputType AsOmniboxEventInputType(
90 AutocompleteInput::Type type) {
91 switch (type) {
92 case AutocompleteInput::INVALID:
93 return OmniboxEventProto::INVALID;
94 case AutocompleteInput::UNKNOWN:
95 return OmniboxEventProto::UNKNOWN;
[email protected]fe58acc22012-02-29 01:29:5896 case AutocompleteInput::URL:
97 return OmniboxEventProto::URL;
98 case AutocompleteInput::QUERY:
99 return OmniboxEventProto::QUERY;
100 case AutocompleteInput::FORCED_QUERY:
101 return OmniboxEventProto::FORCED_QUERY;
102 default:
103 NOTREACHED();
104 return OmniboxEventProto::INVALID;
105 }
106}
107
[email protected]fe58acc22012-02-29 01:29:58108OmniboxEventProto::Suggestion::ResultType AsOmniboxEventResultType(
109 AutocompleteMatch::Type type) {
110 switch (type) {
[email protected]b7f64d742013-05-21 04:04:04111 case AutocompleteMatchType::URL_WHAT_YOU_TYPED:
[email protected]fe58acc22012-02-29 01:29:58112 return OmniboxEventProto::Suggestion::URL_WHAT_YOU_TYPED;
[email protected]b7f64d742013-05-21 04:04:04113 case AutocompleteMatchType::HISTORY_URL:
[email protected]fe58acc22012-02-29 01:29:58114 return OmniboxEventProto::Suggestion::HISTORY_URL;
[email protected]b7f64d742013-05-21 04:04:04115 case AutocompleteMatchType::HISTORY_TITLE:
[email protected]fe58acc22012-02-29 01:29:58116 return OmniboxEventProto::Suggestion::HISTORY_TITLE;
[email protected]b7f64d742013-05-21 04:04:04117 case AutocompleteMatchType::HISTORY_BODY:
[email protected]fe58acc22012-02-29 01:29:58118 return OmniboxEventProto::Suggestion::HISTORY_BODY;
[email protected]b7f64d742013-05-21 04:04:04119 case AutocompleteMatchType::HISTORY_KEYWORD:
[email protected]fe58acc22012-02-29 01:29:58120 return OmniboxEventProto::Suggestion::HISTORY_KEYWORD;
[email protected]b7f64d742013-05-21 04:04:04121 case AutocompleteMatchType::NAVSUGGEST:
[email protected]fe58acc22012-02-29 01:29:58122 return OmniboxEventProto::Suggestion::NAVSUGGEST;
[email protected]b7f64d742013-05-21 04:04:04123 case AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED:
[email protected]fe58acc22012-02-29 01:29:58124 return OmniboxEventProto::Suggestion::SEARCH_WHAT_YOU_TYPED;
[email protected]b7f64d742013-05-21 04:04:04125 case AutocompleteMatchType::SEARCH_HISTORY:
[email protected]fe58acc22012-02-29 01:29:58126 return OmniboxEventProto::Suggestion::SEARCH_HISTORY;
[email protected]b7f64d742013-05-21 04:04:04127 case AutocompleteMatchType::SEARCH_SUGGEST:
[email protected]fe58acc22012-02-29 01:29:58128 return OmniboxEventProto::Suggestion::SEARCH_SUGGEST;
[email protected]b7f64d742013-05-21 04:04:04129 case AutocompleteMatchType::SEARCH_OTHER_ENGINE:
[email protected]fe58acc22012-02-29 01:29:58130 return OmniboxEventProto::Suggestion::SEARCH_OTHER_ENGINE;
[email protected]b7f64d742013-05-21 04:04:04131 case AutocompleteMatchType::EXTENSION_APP:
[email protected]fe58acc22012-02-29 01:29:58132 return OmniboxEventProto::Suggestion::EXTENSION_APP;
[email protected]b7f64d742013-05-21 04:04:04133 case AutocompleteMatchType::CONTACT:
[email protected]dbacefb2012-09-12 03:32:06134 return OmniboxEventProto::Suggestion::CONTACT;
[email protected]b7f64d742013-05-21 04:04:04135 case AutocompleteMatchType::BOOKMARK_TITLE:
[email protected]25320602012-10-18 22:05:56136 return OmniboxEventProto::Suggestion::BOOKMARK_TITLE;
[email protected]fe58acc22012-02-29 01:29:58137 default:
138 NOTREACHED();
139 return OmniboxEventProto::Suggestion::UNKNOWN_RESULT_TYPE;
140 }
141}
142
[email protected]ed0fd002012-04-25 23:10:34143ProfilerEventProto::TrackedObject::ProcessType AsProtobufProcessType(
[email protected]f3b357692013-03-22 05:16:13144 int process_type) {
[email protected]ed0fd002012-04-25 23:10:34145 switch (process_type) {
146 case content::PROCESS_TYPE_BROWSER:
147 return ProfilerEventProto::TrackedObject::BROWSER;
148 case content::PROCESS_TYPE_RENDERER:
149 return ProfilerEventProto::TrackedObject::RENDERER;
150 case content::PROCESS_TYPE_PLUGIN:
151 return ProfilerEventProto::TrackedObject::PLUGIN;
152 case content::PROCESS_TYPE_WORKER:
153 return ProfilerEventProto::TrackedObject::WORKER;
[email protected]ed0fd002012-04-25 23:10:34154 case content::PROCESS_TYPE_UTILITY:
155 return ProfilerEventProto::TrackedObject::UTILITY;
[email protected]ed0fd002012-04-25 23:10:34156 case content::PROCESS_TYPE_ZYGOTE:
157 return ProfilerEventProto::TrackedObject::ZYGOTE;
158 case content::PROCESS_TYPE_SANDBOX_HELPER:
159 return ProfilerEventProto::TrackedObject::SANDBOX_HELPER;
[email protected]ed0fd002012-04-25 23:10:34160 case content::PROCESS_TYPE_GPU:
161 return ProfilerEventProto::TrackedObject::GPU;
162 case content::PROCESS_TYPE_PPAPI_PLUGIN:
163 return ProfilerEventProto::TrackedObject::PPAPI_PLUGIN;
164 case content::PROCESS_TYPE_PPAPI_BROKER:
165 return ProfilerEventProto::TrackedObject::PPAPI_BROKER;
[email protected]f3b357692013-03-22 05:16:13166 case PROCESS_TYPE_NACL_LOADER:
167 return ProfilerEventProto::TrackedObject::NACL_LOADER;
168 case PROCESS_TYPE_NACL_BROKER:
169 return ProfilerEventProto::TrackedObject::NACL_BROKER;
[email protected]ed0fd002012-04-25 23:10:34170 default:
171 NOTREACHED();
172 return ProfilerEventProto::TrackedObject::UNKNOWN;
173 }
174}
175
[email protected]1df44b72012-01-19 05:20:34176// Returns the plugin preferences corresponding for this user, if available.
177// If multiple user profiles are loaded, returns the preferences corresponding
178// to an arbitrary one of the profiles.
179PluginPrefs* GetPluginPrefs() {
180 ProfileManager* profile_manager = g_browser_process->profile_manager();
[email protected]fe58acc22012-02-29 01:29:58181
182 if (!profile_manager) {
183 // The profile manager can be NULL when testing.
184 return NULL;
185 }
186
[email protected]1df44b72012-01-19 05:20:34187 std::vector<Profile*> profiles = profile_manager->GetLoadedProfiles();
188 if (profiles.empty())
189 return NULL;
190
[email protected]cadac622013-06-11 16:46:36191 return PluginPrefs::GetForProfile(profiles.front()).get();
[email protected]1df44b72012-01-19 05:20:34192}
193
[email protected]fe58acc22012-02-29 01:29:58194// Fills |plugin| with the info contained in |plugin_info| and |plugin_prefs|.
195void SetPluginInfo(const webkit::WebPluginInfo& plugin_info,
196 const PluginPrefs* plugin_prefs,
197 SystemProfileProto::Plugin* plugin) {
198 plugin->set_name(UTF16ToUTF8(plugin_info.name));
199 plugin->set_filename(plugin_info.path.BaseName().AsUTF8Unsafe());
200 plugin->set_version(UTF16ToUTF8(plugin_info.version));
201 if (plugin_prefs)
202 plugin->set_is_disabled(!plugin_prefs->IsPluginEnabled(plugin_info));
203}
204
[email protected]0c8b7ad2012-11-06 07:08:14205void WriteFieldTrials(const std::vector<ActiveGroupId>& field_trial_ids,
[email protected]767c9d92012-03-02 16:04:34206 SystemProfileProto* system_profile) {
[email protected]0c8b7ad2012-11-06 07:08:14207 for (std::vector<ActiveGroupId>::const_iterator it =
[email protected]ad2461c2012-04-27 21:11:03208 field_trial_ids.begin(); it != field_trial_ids.end(); ++it) {
[email protected]767c9d92012-03-02 16:04:34209 SystemProfileProto::FieldTrial* field_trial =
210 system_profile->add_field_trial();
211 field_trial->set_name_id(it->name);
212 field_trial->set_group_id(it->group);
213 }
214}
215
[email protected]ed0fd002012-04-25 23:10:34216void WriteProfilerData(const ProcessDataSnapshot& profiler_data,
[email protected]f3b357692013-03-22 05:16:13217 int process_type,
[email protected]ed0fd002012-04-25 23:10:34218 ProfilerEventProto* performance_profile) {
219 for (std::vector<tracked_objects::TaskSnapshot>::const_iterator it =
220 profiler_data.tasks.begin();
221 it != profiler_data.tasks.end(); ++it) {
222 std::string ignored;
223 uint64 birth_thread_name_hash;
224 uint64 exec_thread_name_hash;
225 uint64 source_file_name_hash;
226 uint64 source_function_name_hash;
227 MetricsLogBase::CreateHashes(it->birth.thread_name,
228 &ignored, &birth_thread_name_hash);
229 MetricsLogBase::CreateHashes(it->death_thread_name,
230 &ignored, &exec_thread_name_hash);
[email protected]ed0fd002012-04-25 23:10:34231 MetricsLogBase::CreateHashes(it->birth.location.file_name,
[email protected]04162262012-10-23 01:17:25232 &ignored, &source_file_name_hash);
233 MetricsLogBase::CreateHashes(it->birth.location.function_name,
[email protected]ed0fd002012-04-25 23:10:34234 &ignored, &source_function_name_hash);
235
236 const tracked_objects::DeathDataSnapshot& death_data = it->death_data;
237 ProfilerEventProto::TrackedObject* tracked_object =
238 performance_profile->add_tracked_object();
239 tracked_object->set_birth_thread_name_hash(birth_thread_name_hash);
240 tracked_object->set_exec_thread_name_hash(exec_thread_name_hash);
241 tracked_object->set_source_file_name_hash(source_file_name_hash);
242 tracked_object->set_source_function_name_hash(source_function_name_hash);
243 tracked_object->set_source_line_number(it->birth.location.line_number);
244 tracked_object->set_exec_count(death_data.count);
245 tracked_object->set_exec_time_total(death_data.run_duration_sum);
246 tracked_object->set_exec_time_sampled(death_data.run_duration_sample);
247 tracked_object->set_queue_time_total(death_data.queue_duration_sum);
248 tracked_object->set_queue_time_sampled(death_data.queue_duration_sample);
249 tracked_object->set_process_type(AsProtobufProcessType(process_type));
250 tracked_object->set_process_id(profiler_data.process_id);
251 }
252}
253
[email protected]59a7ae4e2012-10-01 23:54:44254#if defined(GOOGLE_CHROME_BUILD) && defined(OS_WIN)
[email protected]197c0772012-05-14 23:50:51255void ProductDataToProto(const GoogleUpdateSettings::ProductData& product_data,
256 ProductInfo* product_info) {
257 product_info->set_version(product_data.version);
258 product_info->set_last_update_success_timestamp(
259 product_data.last_success.ToTimeT());
260 product_info->set_last_error(product_data.last_error_code);
261 product_info->set_last_extra_error(product_data.last_extra_code);
262 if (ProductInfo::InstallResult_IsValid(product_data.last_result)) {
263 product_info->set_last_result(
264 static_cast<ProductInfo::InstallResult>(product_data.last_result));
265 }
266}
[email protected]59a7ae4e2012-10-01 23:54:44267#endif
[email protected]197c0772012-05-14 23:50:51268
[email protected]76869ff2013-01-15 16:13:47269#if defined(OS_WIN)
[email protected]ffaf7322013-05-15 00:26:11270struct ScreenDPIInformation {
[email protected]76869ff2013-01-15 16:13:47271 double max_dpi_x;
272 double max_dpi_y;
273};
274
275// Called once for each connected monitor.
276BOOL CALLBACK GetMonitorDPICallback(HMONITOR, HDC hdc, LPRECT, LPARAM dwData) {
277 const double kMillimetersPerInch = 25.4;
278 ScreenDPIInformation* screen_info =
279 reinterpret_cast<ScreenDPIInformation*>(dwData);
280 // Size of screen, in mm.
281 DWORD size_x = GetDeviceCaps(hdc, HORZSIZE);
282 DWORD size_y = GetDeviceCaps(hdc, VERTSIZE);
283 double dpi_x = (size_x > 0) ?
284 GetDeviceCaps(hdc, HORZRES) / (size_x / kMillimetersPerInch) : 0;
285 double dpi_y = (size_y > 0) ?
286 GetDeviceCaps(hdc, VERTRES) / (size_y / kMillimetersPerInch) : 0;
[email protected]e245ace92013-05-07 00:37:41287 dpi_x *= ui::win::GetUndocumentedDPIScale();
288 dpi_y *= ui::win::GetUndocumentedDPIScale();
[email protected]76869ff2013-01-15 16:13:47289 screen_info->max_dpi_x = std::max(dpi_x, screen_info->max_dpi_x);
290 screen_info->max_dpi_y = std::max(dpi_y, screen_info->max_dpi_y);
291 return TRUE;
292}
293
294void WriteScreenDPIInformationProto(SystemProfileProto::Hardware* hardware) {
295 HDC desktop_dc = GetDC(NULL);
296 if (desktop_dc) {
[email protected]ffaf7322013-05-15 00:26:11297 ScreenDPIInformation si = {0, 0};
[email protected]76869ff2013-01-15 16:13:47298 if (EnumDisplayMonitors(desktop_dc, NULL, GetMonitorDPICallback,
299 reinterpret_cast<LPARAM>(&si))) {
300 hardware->set_max_dpi_x(si.max_dpi_x);
301 hardware->set_max_dpi_y(si.max_dpi_y);
302 }
303 ReleaseDC(GetDesktopWindow(), desktop_dc);
304 }
305}
306
307#endif // defined(OS_WIN)
308
[email protected]611ae29a2013-04-29 21:32:19309#if defined(OS_CHROMEOS)
310PairedDevice::Type AsBluetoothDeviceType(
311 enum device::BluetoothDevice::DeviceType device_type) {
312 switch (device_type) {
313 case device::BluetoothDevice::DEVICE_UNKNOWN:
314 return PairedDevice::DEVICE_UNKNOWN;
315 case device::BluetoothDevice::DEVICE_COMPUTER:
316 return PairedDevice::DEVICE_COMPUTER;
317 case device::BluetoothDevice::DEVICE_PHONE:
318 return PairedDevice::DEVICE_PHONE;
319 case device::BluetoothDevice::DEVICE_MODEM:
320 return PairedDevice::DEVICE_MODEM;
321 case device::BluetoothDevice::DEVICE_AUDIO:
322 return PairedDevice::DEVICE_AUDIO;
323 case device::BluetoothDevice::DEVICE_CAR_AUDIO:
324 return PairedDevice::DEVICE_CAR_AUDIO;
325 case device::BluetoothDevice::DEVICE_VIDEO:
326 return PairedDevice::DEVICE_VIDEO;
327 case device::BluetoothDevice::DEVICE_PERIPHERAL:
328 return PairedDevice::DEVICE_PERIPHERAL;
329 case device::BluetoothDevice::DEVICE_JOYSTICK:
330 return PairedDevice::DEVICE_JOYSTICK;
331 case device::BluetoothDevice::DEVICE_GAMEPAD:
332 return PairedDevice::DEVICE_GAMEPAD;
333 case device::BluetoothDevice::DEVICE_KEYBOARD:
334 return PairedDevice::DEVICE_KEYBOARD;
335 case device::BluetoothDevice::DEVICE_MOUSE:
336 return PairedDevice::DEVICE_MOUSE;
337 case device::BluetoothDevice::DEVICE_TABLET:
338 return PairedDevice::DEVICE_TABLET;
339 case device::BluetoothDevice::DEVICE_KEYBOARD_MOUSE_COMBO:
340 return PairedDevice::DEVICE_KEYBOARD_MOUSE_COMBO;
341 }
342
343 NOTREACHED();
344 return PairedDevice::DEVICE_UNKNOWN;
345}
346#endif // defined(OS_CHROMEOS)
347
[email protected]86573d12013-07-11 19:48:32348// Round a timestamp measured in seconds since epoch to one with a granularity
349// of an hour. This can be used before uploaded potentially sensitive
350// timestamps.
351int64 RoundSecondsToHour(int64 time_in_seconds) {
352 return 3600 * (time_in_seconds / 3600);
353}
354
[email protected]1df44b72012-01-19 05:20:34355} // namespace
356
[email protected]197c0772012-05-14 23:50:51357GoogleUpdateMetrics::GoogleUpdateMetrics() : is_system_install(false) {}
358
359GoogleUpdateMetrics::~GoogleUpdateMetrics() {}
360
[email protected]67f92bc32012-01-26 01:56:19361static base::LazyInstance<std::string>::Leaky
[email protected]054c8012011-11-16 00:12:42362 g_version_extension = LAZY_INSTANCE_INITIALIZER;
363
[email protected]1226abb2010-06-10 18:01:28364MetricsLog::MetricsLog(const std::string& client_id, int session_id)
[email protected]5eae204c2013-02-13 15:53:42365 : MetricsLogBase(client_id, session_id, MetricsLog::GetVersionString()) {}
[email protected]5ed7d4572009-12-23 17:42:41366
[email protected]1226abb2010-06-10 18:01:28367MetricsLog::~MetricsLog() {}
initial.commit09911bf2008-07-26 23:55:29368
369// static
[email protected]b1de2c72013-02-06 02:45:47370void MetricsLog::RegisterPrefs(PrefRegistrySimple* registry) {
371 registry->RegisterListPref(prefs::kStabilityPluginStats);
initial.commit09911bf2008-07-26 23:55:29372}
373
[email protected]1df44b72012-01-19 05:20:34374// static
[email protected]9165f742010-03-10 22:55:01375int64 MetricsLog::GetIncrementalUptime(PrefService* pref) {
376 base::TimeTicks now = base::TimeTicks::Now();
377 static base::TimeTicks last_updated_time(now);
378 int64 incremental_time = (now - last_updated_time).InSeconds();
379 last_updated_time = now;
380
381 if (incremental_time > 0) {
382 int64 metrics_uptime = pref->GetInt64(prefs::kUninstallMetricsUptimeSec);
383 metrics_uptime += incremental_time;
384 pref->SetInt64(prefs::kUninstallMetricsUptimeSec, metrics_uptime);
385 }
386
387 return incremental_time;
388}
389
[email protected]1226abb2010-06-10 18:01:28390// static
391std::string MetricsLog::GetVersionString() {
[email protected]0211f57e2010-08-27 20:28:42392 chrome::VersionInfo version_info;
[email protected]30c91802010-12-18 00:40:17393 if (!version_info.is_valid()) {
394 NOTREACHED() << "Unable to retrieve version info.";
395 return std::string();
396 }
397
[email protected]0211f57e2010-08-27 20:28:42398 std::string version = version_info.Version();
[email protected]054c8012011-11-16 00:12:42399 if (!version_extension().empty())
400 version += version_extension();
[email protected]0211f57e2010-08-27 20:28:42401 if (!version_info.IsOfficialBuild())
402 version.append("-devel");
403 return version;
[email protected]1226abb2010-06-10 18:01:28404}
405
[email protected]054c8012011-11-16 00:12:42406// static
407void MetricsLog::set_version_extension(const std::string& extension) {
408 g_version_extension.Get() = extension;
409}
410
411// static
412const std::string& MetricsLog::version_extension() {
413 return g_version_extension.Get();
414}
415
[email protected]fe58acc22012-02-29 01:29:58416void MetricsLog::RecordIncrementalStabilityElements(
417 const std::vector<webkit::WebPluginInfo>& plugin_list) {
[email protected]767c9d92012-03-02 16:04:34418 DCHECK(!locked());
[email protected]0b33f80b2008-12-17 21:34:36419
[email protected]767c9d92012-03-02 16:04:34420 PrefService* pref = GetPrefService();
[email protected]0b33f80b2008-12-17 21:34:36421 DCHECK(pref);
422
[email protected]f31a01a2013-07-13 02:51:11423 WriteRequiredStabilityAttributes(pref);
424 WriteRealtimeStabilityAttributes(pref);
425 WritePluginStabilityElements(plugin_list, pref);
[email protected]0b33f80b2008-12-17 21:34:36426}
427
[email protected]767c9d92012-03-02 16:04:34428PrefService* MetricsLog::GetPrefService() {
429 return g_browser_process->local_state();
430}
431
432gfx::Size MetricsLog::GetScreenSize() const {
[email protected]ffabb1e2012-10-12 19:51:17433 return gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().GetSizeInPixel();
[email protected]767c9d92012-03-02 16:04:34434}
435
[email protected]aa96417972012-08-22 03:16:44436float MetricsLog::GetScreenDeviceScaleFactor() const {
[email protected]ffabb1e2012-10-12 19:51:17437 return gfx::Screen::GetNativeScreen()->
438 GetPrimaryDisplay().device_scale_factor();
[email protected]aa96417972012-08-22 03:16:44439}
440
[email protected]767c9d92012-03-02 16:04:34441int MetricsLog::GetScreenCount() const {
[email protected]ffabb1e2012-10-12 19:51:17442 // TODO(scottmg): NativeScreen maybe wrong. http://crbug.com/133312
443 return gfx::Screen::GetNativeScreen()->GetNumDisplays();
[email protected]767c9d92012-03-02 16:04:34444}
445
[email protected]767c9d92012-03-02 16:04:34446void MetricsLog::GetFieldTrialIds(
[email protected]0c8b7ad2012-11-06 07:08:14447 std::vector<ActiveGroupId>* field_trial_ids) const {
448 chrome_variations::GetFieldTrialActiveGroupIds(field_trial_ids);
[email protected]767c9d92012-03-02 16:04:34449}
450
[email protected]fe58acc22012-02-29 01:29:58451void MetricsLog::WriteStabilityElement(
452 const std::vector<webkit::WebPluginInfo>& plugin_list,
453 PrefService* pref) {
[email protected]767c9d92012-03-02 16:04:34454 DCHECK(!locked());
initial.commit09911bf2008-07-26 23:55:29455
initial.commit09911bf2008-07-26 23:55:29456 // Get stability attributes out of Local State, zeroing out stored values.
457 // NOTE: This could lead to some data loss if this report isn't successfully
458 // sent, but that's true for all the metrics.
459
[email protected]147bbc0b2009-01-06 19:37:40460 WriteRequiredStabilityAttributes(pref);
461 WriteRealtimeStabilityAttributes(pref);
initial.commit09911bf2008-07-26 23:55:29462
[email protected]fe58acc22012-02-29 01:29:58463 int incomplete_shutdown_count =
464 pref->GetInteger(prefs::kStabilityIncompleteSessionEndCount);
[email protected]e324f6b2012-02-28 05:43:37465 pref->SetInteger(prefs::kStabilityIncompleteSessionEndCount, 0);
[email protected]fe58acc22012-02-29 01:29:58466 int breakpad_registration_success_count =
467 pref->GetInteger(prefs::kStabilityBreakpadRegistrationSuccess);
[email protected]e324f6b2012-02-28 05:43:37468 pref->SetInteger(prefs::kStabilityBreakpadRegistrationSuccess, 0);
[email protected]fe58acc22012-02-29 01:29:58469 int breakpad_registration_failure_count =
470 pref->GetInteger(prefs::kStabilityBreakpadRegistrationFail);
[email protected]e324f6b2012-02-28 05:43:37471 pref->SetInteger(prefs::kStabilityBreakpadRegistrationFail, 0);
[email protected]fe58acc22012-02-29 01:29:58472 int debugger_present_count =
473 pref->GetInteger(prefs::kStabilityDebuggerPresent);
[email protected]e324f6b2012-02-28 05:43:37474 pref->SetInteger(prefs::kStabilityDebuggerPresent, 0);
[email protected]fe58acc22012-02-29 01:29:58475 int debugger_not_present_count =
476 pref->GetInteger(prefs::kStabilityDebuggerNotPresent);
[email protected]e324f6b2012-02-28 05:43:37477 pref->SetInteger(prefs::kStabilityDebuggerNotPresent, 0);
[email protected]b2a4812d2012-02-28 05:31:31478
[email protected]fe58acc22012-02-29 01:29:58479 // TODO(jar): The following are all optional, so we *could* optimize them for
480 // values of zero (and not include them).
[email protected]fe58acc22012-02-29 01:29:58481 SystemProfileProto::Stability* stability =
[email protected]767c9d92012-03-02 16:04:34482 uma_proto()->mutable_system_profile()->mutable_stability();
[email protected]fe58acc22012-02-29 01:29:58483 stability->set_incomplete_shutdown_count(incomplete_shutdown_count);
484 stability->set_breakpad_registration_success_count(
485 breakpad_registration_success_count);
486 stability->set_breakpad_registration_failure_count(
487 breakpad_registration_failure_count);
488 stability->set_debugger_present_count(debugger_present_count);
489 stability->set_debugger_not_present_count(debugger_not_present_count);
490
491 WritePluginStabilityElements(plugin_list, pref);
[email protected]147bbc0b2009-01-06 19:37:40492}
493
[email protected]fe58acc22012-02-29 01:29:58494void MetricsLog::WritePluginStabilityElements(
495 const std::vector<webkit::WebPluginInfo>& plugin_list,
496 PrefService* pref) {
[email protected]147bbc0b2009-01-06 19:37:40497 // Now log plugin stability info.
initial.commit09911bf2008-07-26 23:55:29498 const ListValue* plugin_stats_list = pref->GetList(
499 prefs::kStabilityPluginStats);
[email protected]1df44b72012-01-19 05:20:34500 if (!plugin_stats_list)
501 return;
initial.commit09911bf2008-07-26 23:55:29502
[email protected]ebd71962012-12-20 02:56:55503#if defined(ENABLE_PLUGINS)
[email protected]fe58acc22012-02-29 01:29:58504 SystemProfileProto::Stability* stability =
[email protected]767c9d92012-03-02 16:04:34505 uma_proto()->mutable_system_profile()->mutable_stability();
[email protected]fe58acc22012-02-29 01:29:58506 PluginPrefs* plugin_prefs = GetPluginPrefs();
[email protected]1df44b72012-01-19 05:20:34507 for (ListValue::const_iterator iter = plugin_stats_list->begin();
508 iter != plugin_stats_list->end(); ++iter) {
509 if (!(*iter)->IsType(Value::TYPE_DICTIONARY)) {
510 NOTREACHED();
511 continue;
initial.commit09911bf2008-07-26 23:55:29512 }
[email protected]1df44b72012-01-19 05:20:34513 DictionaryValue* plugin_dict = static_cast<DictionaryValue*>(*iter);
initial.commit09911bf2008-07-26 23:55:29514
[email protected]fe58acc22012-02-29 01:29:58515 // Write the protobuf version.
516 // Note that this search is potentially a quadratic operation, but given the
517 // low number of plugins installed on a "reasonable" setup, this should be
518 // fine.
519 // TODO(isherman): Verify that this does not show up as a hotspot in
520 // profiler runs.
521 const webkit::WebPluginInfo* plugin_info = NULL;
[email protected]f31a01a2013-07-13 02:51:11522 std::string plugin_name;
523 plugin_dict->GetString(prefs::kStabilityPluginName, &plugin_name);
[email protected]fe58acc22012-02-29 01:29:58524 const string16 plugin_name_utf16 = UTF8ToUTF16(plugin_name);
525 for (std::vector<webkit::WebPluginInfo>::const_iterator iter =
526 plugin_list.begin();
527 iter != plugin_list.end(); ++iter) {
528 if (iter->name == plugin_name_utf16) {
529 plugin_info = &(*iter);
530 break;
531 }
532 }
533
534 if (!plugin_info) {
535 NOTREACHED();
536 continue;
537 }
[email protected]fe58acc22012-02-29 01:29:58538
[email protected]fe58acc22012-02-29 01:29:58539 SystemProfileProto::Stability::PluginStability* plugin_stability =
540 stability->add_plugin_stability();
541 SetPluginInfo(*plugin_info, plugin_prefs,
542 plugin_stability->mutable_plugin());
[email protected]f31a01a2013-07-13 02:51:11543
544 int launches = 0;
545 plugin_dict->GetInteger(prefs::kStabilityPluginLaunches, &launches);
546 if (launches > 0)
547 plugin_stability->set_launch_count(launches);
548
549 int instances = 0;
550 plugin_dict->GetInteger(prefs::kStabilityPluginInstances, &instances);
551 if (instances > 0)
552 plugin_stability->set_instance_count(instances);
553
554 int crashes = 0;
555 plugin_dict->GetInteger(prefs::kStabilityPluginCrashes, &crashes);
556 if (crashes > 0)
557 plugin_stability->set_crash_count(crashes);
558
559 int loading_errors = 0;
560 plugin_dict->GetInteger(prefs::kStabilityPluginLoadingErrors,
561 &loading_errors);
562 if (loading_errors > 0)
563 plugin_stability->set_loading_error_count(loading_errors);
initial.commit09911bf2008-07-26 23:55:29564 }
[email protected]ebd71962012-12-20 02:56:55565#endif // defined(ENABLE_PLUGINS)
[email protected]1df44b72012-01-19 05:20:34566
567 pref->ClearPref(prefs::kStabilityPluginStats);
initial.commit09911bf2008-07-26 23:55:29568}
569
[email protected]fe58acc22012-02-29 01:29:58570// The server refuses data that doesn't have certain values. crashcount and
571// launchcount are currently "required" in the "stability" group.
572// TODO(isherman): Stop writing these attributes specially once the migration to
573// protobufs is complete.
[email protected]147bbc0b2009-01-06 19:37:40574void MetricsLog::WriteRequiredStabilityAttributes(PrefService* pref) {
[email protected]fe58acc22012-02-29 01:29:58575 int launch_count = pref->GetInteger(prefs::kStabilityLaunchCount);
[email protected]0b33f80b2008-12-17 21:34:36576 pref->SetInteger(prefs::kStabilityLaunchCount, 0);
[email protected]fe58acc22012-02-29 01:29:58577 int crash_count = pref->GetInteger(prefs::kStabilityCrashCount);
[email protected]0b33f80b2008-12-17 21:34:36578 pref->SetInteger(prefs::kStabilityCrashCount, 0);
[email protected]fe58acc22012-02-29 01:29:58579
[email protected]fe58acc22012-02-29 01:29:58580 SystemProfileProto::Stability* stability =
[email protected]767c9d92012-03-02 16:04:34581 uma_proto()->mutable_system_profile()->mutable_stability();
[email protected]fe58acc22012-02-29 01:29:58582 stability->set_launch_count(launch_count);
583 stability->set_crash_count(crash_count);
[email protected]0b33f80b2008-12-17 21:34:36584}
585
[email protected]147bbc0b2009-01-06 19:37:40586void MetricsLog::WriteRealtimeStabilityAttributes(PrefService* pref) {
[email protected]0b33f80b2008-12-17 21:34:36587 // Update the stats which are critical for real-time stability monitoring.
588 // Since these are "optional," only list ones that are non-zero, as the counts
589 // are aggergated (summed) server side.
590
[email protected]fe58acc22012-02-29 01:29:58591 SystemProfileProto::Stability* stability =
[email protected]767c9d92012-03-02 16:04:34592 uma_proto()->mutable_system_profile()->mutable_stability();
[email protected]0b33f80b2008-12-17 21:34:36593 int count = pref->GetInteger(prefs::kStabilityPageLoadCount);
594 if (count) {
[email protected]fe58acc22012-02-29 01:29:58595 stability->set_page_load_count(count);
[email protected]0b33f80b2008-12-17 21:34:36596 pref->SetInteger(prefs::kStabilityPageLoadCount, 0);
597 }
598
599 count = pref->GetInteger(prefs::kStabilityRendererCrashCount);
600 if (count) {
[email protected]fe58acc22012-02-29 01:29:58601 stability->set_renderer_crash_count(count);
[email protected]0b33f80b2008-12-17 21:34:36602 pref->SetInteger(prefs::kStabilityRendererCrashCount, 0);
603 }
604
[email protected]1f085622009-12-04 05:33:45605 count = pref->GetInteger(prefs::kStabilityExtensionRendererCrashCount);
606 if (count) {
[email protected]fe58acc22012-02-29 01:29:58607 stability->set_extension_renderer_crash_count(count);
[email protected]1f085622009-12-04 05:33:45608 pref->SetInteger(prefs::kStabilityExtensionRendererCrashCount, 0);
609 }
610
[email protected]0b33f80b2008-12-17 21:34:36611 count = pref->GetInteger(prefs::kStabilityRendererHangCount);
612 if (count) {
[email protected]fe58acc22012-02-29 01:29:58613 stability->set_renderer_hang_count(count);
[email protected]0b33f80b2008-12-17 21:34:36614 pref->SetInteger(prefs::kStabilityRendererHangCount, 0);
615 }
[email protected]1f085622009-12-04 05:33:45616
617 count = pref->GetInteger(prefs::kStabilityChildProcessCrashCount);
618 if (count) {
[email protected]fe58acc22012-02-29 01:29:58619 stability->set_child_process_crash_count(count);
[email protected]1f085622009-12-04 05:33:45620 pref->SetInteger(prefs::kStabilityChildProcessCrashCount, 0);
621 }
[email protected]9165f742010-03-10 22:55:01622
[email protected]c1834a92011-01-21 18:21:03623#if defined(OS_CHROMEOS)
624 count = pref->GetInteger(prefs::kStabilityOtherUserCrashCount);
625 if (count) {
[email protected]fe58acc22012-02-29 01:29:58626 stability->set_other_user_crash_count(count);
[email protected]c1834a92011-01-21 18:21:03627 pref->SetInteger(prefs::kStabilityOtherUserCrashCount, 0);
628 }
629
630 count = pref->GetInteger(prefs::kStabilityKernelCrashCount);
631 if (count) {
[email protected]fe58acc22012-02-29 01:29:58632 stability->set_kernel_crash_count(count);
[email protected]c1834a92011-01-21 18:21:03633 pref->SetInteger(prefs::kStabilityKernelCrashCount, 0);
634 }
635
636 count = pref->GetInteger(prefs::kStabilitySystemUncleanShutdownCount);
637 if (count) {
[email protected]fe58acc22012-02-29 01:29:58638 stability->set_unclean_system_shutdown_count(count);
[email protected]c1834a92011-01-21 18:21:03639 pref->SetInteger(prefs::kStabilitySystemUncleanShutdownCount, 0);
640 }
641#endif // OS_CHROMEOS
642
[email protected]9165f742010-03-10 22:55:01643 int64 recent_duration = GetIncrementalUptime(pref);
[email protected]f31a01a2013-07-13 02:51:11644 if (recent_duration)
[email protected]fe58acc22012-02-29 01:29:58645 stability->set_uptime_sec(recent_duration);
[email protected]0b33f80b2008-12-17 21:34:36646}
647
initial.commit09911bf2008-07-26 23:55:29648void MetricsLog::WritePluginList(
[email protected]0eecc2542013-06-23 04:22:02649 const std::vector<webkit::WebPluginInfo>& plugin_list) {
[email protected]767c9d92012-03-02 16:04:34650 DCHECK(!locked());
initial.commit09911bf2008-07-26 23:55:29651
[email protected]ebd71962012-12-20 02:56:55652#if defined(ENABLE_PLUGINS)
653 PluginPrefs* plugin_prefs = GetPluginPrefs();
[email protected]767c9d92012-03-02 16:04:34654 SystemProfileProto* system_profile = uma_proto()->mutable_system_profile();
[email protected]91d9f3d2011-08-14 05:24:44655 for (std::vector<webkit::WebPluginInfo>::const_iterator iter =
[email protected]191eb3f72010-12-21 06:27:50656 plugin_list.begin();
initial.commit09911bf2008-07-26 23:55:29657 iter != plugin_list.end(); ++iter) {
[email protected]0eecc2542013-06-23 04:22:02658 SystemProfileProto::Plugin* plugin = system_profile->add_plugin();
659 SetPluginInfo(*iter, plugin_prefs, plugin);
initial.commit09911bf2008-07-26 23:55:29660 }
[email protected]ebd71962012-12-20 02:56:55661#endif // defined(ENABLE_PLUGINS)
initial.commit09911bf2008-07-26 23:55:29662}
663
initial.commit09911bf2008-07-26 23:55:29664void MetricsLog::RecordEnvironment(
[email protected]91d9f3d2011-08-14 05:24:44665 const std::vector<webkit::WebPluginInfo>& plugin_list,
[email protected]f31a01a2013-07-13 02:51:11666 const GoogleUpdateMetrics& google_update_metrics) {
[email protected]767c9d92012-03-02 16:04:34667 DCHECK(!locked());
initial.commit09911bf2008-07-26 23:55:29668
[email protected]767c9d92012-03-02 16:04:34669 PrefService* pref = GetPrefService();
[email protected]fe58acc22012-02-29 01:29:58670 WriteStabilityElement(plugin_list, pref);
initial.commit09911bf2008-07-26 23:55:29671
[email protected]197c0772012-05-14 23:50:51672 RecordEnvironmentProto(plugin_list, google_update_metrics);
[email protected]bc66d532012-03-23 01:57:05673}
674
675void MetricsLog::RecordEnvironmentProto(
[email protected]197c0772012-05-14 23:50:51676 const std::vector<webkit::WebPluginInfo>& plugin_list,
677 const GoogleUpdateMetrics& google_update_metrics) {
[email protected]bc66d532012-03-23 01:57:05678 SystemProfileProto* system_profile = uma_proto()->mutable_system_profile();
[email protected]24b9bb392013-01-29 20:29:29679
680 std::string brand_code;
681 if (google_util::GetBrand(&brand_code))
682 system_profile->set_brand_code(brand_code);
683
[email protected]cc5d7f42012-10-30 00:30:09684 int enabled_date;
685 bool success = base::StringToInt(GetMetricsEnabledDate(GetPrefService()),
686 &enabled_date);
[email protected]bc66d532012-03-23 01:57:05687 DCHECK(success);
[email protected]86573d12013-07-11 19:48:32688
689 // Reduce granularity of the enabled_date field to nearest hour.
690 system_profile->set_uma_enabled_date(RoundSecondsToHour(enabled_date));
691
692 int64 install_date = GetPrefService()->GetInt64(prefs::kInstallDate);
693
694 // Reduce granularity of the install_date field to nearest hour.
695 system_profile->set_install_date(RoundSecondsToHour(install_date));
[email protected]bc66d532012-03-23 01:57:05696
697 system_profile->set_application_locale(
[email protected]eabbfb12013-04-05 23:28:35698 g_browser_process->GetApplicationLocale());
[email protected]bc66d532012-03-23 01:57:05699
700 SystemProfileProto::Hardware* hardware = system_profile->mutable_hardware();
[email protected]0b6a4fb2012-10-16 01:58:21701 hardware->set_cpu_architecture(base::SysInfo::OperatingSystemArchitecture());
[email protected]bc66d532012-03-23 01:57:05702 hardware->set_system_ram_mb(base::SysInfo::AmountOfPhysicalMemoryMB());
703#if defined(OS_WIN)
704 hardware->set_dll_base(reinterpret_cast<uint64>(&__ImageBase));
705#endif
706
[email protected]74b299e2013-01-29 01:24:42707 SystemProfileProto::Network* network = system_profile->mutable_network();
708 network->set_connection_type_is_ambiguous(
[email protected]5eae204c2013-02-13 15:53:42709 network_observer_.connection_type_is_ambiguous());
710 network->set_connection_type(network_observer_.connection_type());
711 network->set_wifi_phy_layer_protocol_is_ambiguous(
712 network_observer_.wifi_phy_layer_protocol_is_ambiguous());
713 network->set_wifi_phy_layer_protocol(
714 network_observer_.wifi_phy_layer_protocol());
715 network_observer_.Reset();
[email protected]74b299e2013-01-29 01:24:42716
[email protected]bc66d532012-03-23 01:57:05717 SystemProfileProto::OS* os = system_profile->mutable_os();
[email protected]1bb25e02012-08-03 22:39:39718 std::string os_name = base::SysInfo::OperatingSystemName();
719#if defined(OS_WIN)
720 // TODO(mad): This only checks whether the main process is a Metro process at
721 // upload time; not whether the collected metrics were all gathered from
722 // Metro. This is ok as an approximation for now, since users will rarely be
723 // switching from Metro to Desktop mode; but we should re-evaluate whether we
724 // can distinguish metrics more cleanly in the future: http://crbug.com/140568
725 if (base::win::IsMetroProcess())
726 os_name += " (Metro)";
727#endif
728 os->set_name(os_name);
[email protected]bc66d532012-03-23 01:57:05729 os->set_version(base::SysInfo::OperatingSystemVersion());
[email protected]5106b3a2012-10-03 20:10:44730#if defined(OS_ANDROID)
731 os->set_fingerprint(
732 base::android::BuildInfo::GetInstance()->android_build_fp());
733#endif
[email protected]bc66d532012-03-23 01:57:05734
[email protected]d7b5cc72013-05-23 20:05:00735 const gpu::GPUInfo& gpu_info =
[email protected]bc66d532012-03-23 01:57:05736 GpuDataManager::GetInstance()->GetGPUInfo();
737 SystemProfileProto::Hardware::Graphics* gpu = hardware->mutable_gpu();
[email protected]a094e2c2012-05-10 23:02:42738 gpu->set_vendor_id(gpu_info.gpu.vendor_id);
739 gpu->set_device_id(gpu_info.gpu.device_id);
[email protected]bc66d532012-03-23 01:57:05740 gpu->set_driver_version(gpu_info.driver_version);
741 gpu->set_driver_date(gpu_info.driver_date);
742 SystemProfileProto::Hardware::Graphics::PerformanceStatistics*
743 gpu_performance = gpu->mutable_performance_statistics();
744 gpu_performance->set_graphics_score(gpu_info.performance_stats.graphics);
745 gpu_performance->set_gaming_score(gpu_info.performance_stats.gaming);
746 gpu_performance->set_overall_score(gpu_info.performance_stats.overall);
[email protected]d6bdfae2013-01-18 20:23:01747 gpu->set_gl_vendor(gpu_info.gl_vendor);
748 gpu->set_gl_renderer(gpu_info.gl_renderer);
[email protected]bc66d532012-03-23 01:57:05749
750 const gfx::Size display_size = GetScreenSize();
751 hardware->set_primary_screen_width(display_size.width());
752 hardware->set_primary_screen_height(display_size.height());
[email protected]aa96417972012-08-22 03:16:44753 hardware->set_primary_screen_scale_factor(GetScreenDeviceScaleFactor());
[email protected]bc66d532012-03-23 01:57:05754 hardware->set_screen_count(GetScreenCount());
755
[email protected]76869ff2013-01-15 16:13:47756#if defined(OS_WIN)
757 WriteScreenDPIInformationProto(hardware);
758#endif
759
[email protected]197c0772012-05-14 23:50:51760 WriteGoogleUpdateProto(google_update_metrics);
761
[email protected]0eecc2542013-06-23 04:22:02762 WritePluginList(plugin_list);
[email protected]bc66d532012-03-23 01:57:05763
[email protected]0c8b7ad2012-11-06 07:08:14764 std::vector<ActiveGroupId> field_trial_ids;
[email protected]767c9d92012-03-02 16:04:34765 GetFieldTrialIds(&field_trial_ids);
766 WriteFieldTrials(field_trial_ids, system_profile);
[email protected]f65859e2013-02-04 20:00:25767
768#if defined(OS_CHROMEOS)
769 PerfDataProto perf_data_proto;
770 if (perf_provider_.GetPerfData(&perf_data_proto))
771 uma_proto()->add_perf_data()->Swap(&perf_data_proto);
[email protected]611ae29a2013-04-29 21:32:19772
773 // BluetoothAdapterFactory::GetAdapter is synchronous on Chrome OS; if that
774 // changes this will fail at the DCHECK().
775 device::BluetoothAdapterFactory::GetAdapter(
776 base::Bind(&MetricsLog::SetBluetoothAdapter,
777 base::Unretained(this)));
778 DCHECK(adapter_.get());
779 WriteBluetoothProto(hardware);
[email protected]f65859e2013-02-04 20:00:25780#endif
initial.commit09911bf2008-07-26 23:55:29781}
782
[email protected]ed0fd002012-04-25 23:10:34783void MetricsLog::RecordProfilerData(
784 const tracked_objects::ProcessDataSnapshot& process_data,
[email protected]f3b357692013-03-22 05:16:13785 int process_type) {
[email protected]ed0fd002012-04-25 23:10:34786 DCHECK(!locked());
787
[email protected]8f829682012-04-27 00:36:49788 if (tracked_objects::GetTimeSourceType() !=
789 tracked_objects::TIME_SOURCE_TYPE_WALL_TIME) {
[email protected]ed0fd002012-04-25 23:10:34790 // We currently only support the default time source, wall clock time.
791 return;
792 }
793
794 ProfilerEventProto* profile;
795 if (!uma_proto()->profiler_event_size()) {
796 // For the first process's data, add a new field to the protocol buffer.
797 profile = uma_proto()->add_profiler_event();
798 profile->set_profile_type(ProfilerEventProto::STARTUP_PROFILE);
799 profile->set_time_source(ProfilerEventProto::WALL_CLOCK_TIME);
800 } else {
801 // For the remaining calls, re-use the existing field.
802 profile = uma_proto()->mutable_profiler_event(0);
803 }
804
805 WriteProfilerData(process_data, process_type, profile);
806}
807
[email protected]0fafc8d2013-06-01 00:09:50808void MetricsLog::RecordOmniboxOpenedURL(const OmniboxLog& log) {
[email protected]767c9d92012-03-02 16:04:34809 DCHECK(!locked());
initial.commit09911bf2008-07-26 23:55:29810
[email protected]65956312012-04-19 21:28:12811 std::vector<string16> terms;
812 const int num_terms =
813 static_cast<int>(Tokenize(log.text, kWhitespaceUTF16, &terms));
initial.commit09911bf2008-07-26 23:55:29814
[email protected]767c9d92012-03-02 16:04:34815 OmniboxEventProto* omnibox_event = uma_proto()->add_omnibox_event();
[email protected]fe58acc22012-02-29 01:29:58816 omnibox_event->set_time(MetricsLogBase::GetCurrentTime());
817 if (log.tab_id != -1) {
818 // If we know what tab the autocomplete URL was opened in, log it.
819 omnibox_event->set_tab_id(log.tab_id);
820 }
821 omnibox_event->set_typed_length(log.text.length());
[email protected]660fe8f32012-05-03 20:01:08822 omnibox_event->set_just_deleted_text(log.just_deleted_text);
[email protected]65956312012-04-19 21:28:12823 omnibox_event->set_num_typed_terms(num_terms);
[email protected]fe58acc22012-02-29 01:29:58824 omnibox_event->set_selected_index(log.selected_index);
[email protected]62b3ef52013-01-18 00:13:02825 if (log.completed_length != string16::npos)
826 omnibox_event->set_completed_length(log.completed_length);
[email protected]65956312012-04-19 21:28:12827 if (log.elapsed_time_since_user_first_modified_omnibox !=
828 base::TimeDelta::FromMilliseconds(-1)) {
829 // Only upload the typing duration if it is set/valid.
830 omnibox_event->set_typing_duration_ms(
831 log.elapsed_time_since_user_first_modified_omnibox.InMilliseconds());
832 }
[email protected]35d55602012-11-20 23:49:03833 omnibox_event->set_duration_since_last_default_match_update_ms(
834 log.elapsed_time_since_last_change_to_default_match.InMilliseconds());
[email protected]ee902532012-05-01 23:54:49835 omnibox_event->set_current_page_classification(
836 log.current_page_classification);
[email protected]fe58acc22012-02-29 01:29:58837 omnibox_event->set_input_type(AsOmniboxEventInputType(log.input_type));
838 for (AutocompleteResult::const_iterator i(log.result.begin());
839 i != log.result.end(); ++i) {
840 OmniboxEventProto::Suggestion* suggestion = omnibox_event->add_suggestion();
[email protected]0e9e8782012-05-15 23:01:51841 suggestion->set_provider(i->provider->AsOmniboxEventProviderType());
[email protected]fe58acc22012-02-29 01:29:58842 suggestion->set_result_type(AsOmniboxEventResultType(i->type));
843 suggestion->set_relevance(i->relevance);
[email protected]cf6256f2012-06-12 23:36:01844 if (i->typed_count != -1)
845 suggestion->set_typed_count(i->typed_count);
[email protected]fe58acc22012-02-29 01:29:58846 suggestion->set_is_starred(i->starred);
847 }
[email protected]0e9e8782012-05-15 23:01:51848 for (ProvidersInfo::const_iterator i(log.providers_info.begin());
849 i != log.providers_info.end(); ++i) {
850 OmniboxEventProto::ProviderInfo* provider_info =
851 omnibox_event->add_provider_info();
852 provider_info->CopyFrom(*i);
853 }
[email protected]fe58acc22012-02-29 01:29:58854
initial.commit09911bf2008-07-26 23:55:29855 ++num_events_;
856}
[email protected]197c0772012-05-14 23:50:51857
858void MetricsLog::WriteGoogleUpdateProto(
859 const GoogleUpdateMetrics& google_update_metrics) {
860#if defined(GOOGLE_CHROME_BUILD) && defined(OS_WIN)
861 SystemProfileProto::GoogleUpdate* google_update =
862 uma_proto()->mutable_system_profile()->mutable_google_update();
863
864 google_update->set_is_system_install(google_update_metrics.is_system_install);
865
866 if (!google_update_metrics.last_started_au.is_null()) {
867 google_update->set_last_automatic_start_timestamp(
868 google_update_metrics.last_started_au.ToTimeT());
869 }
870
871 if (!google_update_metrics.last_checked.is_null()) {
872 google_update->set_last_update_check_timestamp(
873 google_update_metrics.last_checked.ToTimeT());
874 }
875
876 if (!google_update_metrics.google_update_data.version.empty()) {
877 ProductDataToProto(google_update_metrics.google_update_data,
878 google_update->mutable_google_update_status());
879 }
880
881 if (!google_update_metrics.product_data.version.empty()) {
882 ProductDataToProto(google_update_metrics.product_data,
883 google_update->mutable_client_status());
884 }
885#endif // defined(GOOGLE_CHROME_BUILD) && defined(OS_WIN)
886}
[email protected]611ae29a2013-04-29 21:32:19887
888void MetricsLog::SetBluetoothAdapter(
889 scoped_refptr<device::BluetoothAdapter> adapter) {
890 adapter_ = adapter;
891}
892
893void MetricsLog::WriteBluetoothProto(
894 SystemProfileProto::Hardware* hardware) {
[email protected]728f9b22013-05-02 06:08:18895#if defined(OS_CHROMEOS)
[email protected]611ae29a2013-04-29 21:32:19896 SystemProfileProto::Hardware::Bluetooth* bluetooth =
897 hardware->mutable_bluetooth();
898
899 bluetooth->set_is_present(adapter_->IsPresent());
900 bluetooth->set_is_enabled(adapter_->IsPowered());
901
902 device::BluetoothAdapter::DeviceList devices = adapter_->GetDevices();
903 for (device::BluetoothAdapter::DeviceList::iterator iter =
904 devices.begin(); iter != devices.end(); ++iter) {
905 PairedDevice* paired_device = bluetooth->add_paired_device();
906
907 device::BluetoothDevice* device = *iter;
908 paired_device->set_bluetooth_class(device->GetBluetoothClass());
909 paired_device->set_type(AsBluetoothDeviceType(device->GetDeviceType()));
910
911 // address is xx:xx:xx:xx:xx:xx, extract the first three components and
912 // pack into a uint32
913 std::string address = device->GetAddress();
914 if (address.size() > 9 &&
915 address[2] == ':' && address[5] == ':' && address[8] == ':') {
916 std::string vendor_prefix_str;
917 uint64 vendor_prefix;
918
919 RemoveChars(address.substr(0, 9), ":", &vendor_prefix_str);
920 DCHECK_EQ(6U, vendor_prefix_str.size());
921 base::HexStringToUInt64(vendor_prefix_str, &vendor_prefix);
922
923 paired_device->set_vendor_prefix(vendor_prefix);
924 }
925
926 paired_device->set_vendor_id(device->GetVendorID());
927 paired_device->set_product_id(device->GetProductID());
928 paired_device->set_device_id(device->GetDeviceID());
929 }
930#endif // defined(OS_CHROMEOS)
931}