blob: a9a1fc5c6226e8d90039734474f514c154fd171c [file] [log] [blame]
isherman@chromium.org1df44b72012-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
ben@chromium.orgcd1adc22009-01-16 01:29:225#include "chrome/browser/metrics/metrics_log.h"
initial.commit09911bf2008-07-26 23:55:296
girard@chromium.org76869ff2013-01-15 16:13:477#include <algorithm>
thestig@chromium.org1eeb5e02010-07-20 23:02:118#include <string>
9#include <vector>
10
deanm@chromium.orgd1be67b2008-11-19 20:28:3811#include "base/basictypes.h"
keybuk@chromium.org611ae29a2013-04-29 21:32:1912#include "base/bind.h"
simonjam@chromium.org5c8f89f692013-07-18 11:13:2813#include "base/cpu.h"
thakis@chromium.org054c8012011-11-16 00:12:4214#include "base/lazy_instance.h"
levin@chromium.org3b63f8f42011-03-28 01:54:1515#include "base/memory/scoped_ptr.h"
joi@chromium.org3853a4c2013-02-11 17:15:5716#include "base/prefs/pref_registry_simple.h"
17#include "base/prefs/pref_service.h"
isherman@chromium.orged0fd002012-04-25 23:10:3418#include "base/profiler/alternate_timer.h"
brettw@chromium.org3ea1b182013-02-08 22:38:4119#include "base/strings/string_number_conversions.h"
avi@chromium.orgf9b294362013-06-10 20:22:3120#include "base/strings/string_util.h"
avi@chromium.org112158af2013-06-07 23:46:1821#include "base/strings/utf_string_conversions.h"
deanm@chromium.orgfadf97f2008-09-18 12:18:1422#include "base/sys_info.h"
tfarina@chromium.orgbb5c95c2013-08-24 15:09:4523#include "base/test/perftimer.h"
jar@chromium.org37f39e42010-01-06 17:35:1724#include "base/third_party/nspr/prtime.h"
avi@chromium.org84813472013-06-28 00:25:1925#include "base/time/time.h"
isherman@chromium.orged0fd002012-04-25 23:10:3426#include "base/tracked_objects.h"
tfarina@chromium.org9f8bc2f2012-07-03 16:26:5327#include "chrome/browser/autocomplete/autocomplete_input.h"
scr@chromium.org9ac40092010-10-27 23:05:2628#include "chrome/browser/autocomplete/autocomplete_match.h"
tfarina@chromium.org30f5bc92012-06-26 04:14:5529#include "chrome/browser/autocomplete/autocomplete_provider.h"
tfarina@chromium.org73c2b1632012-07-02 22:51:3830#include "chrome/browser/autocomplete/autocomplete_result.h"
initial.commit09911bf2008-07-26 23:55:2931#include "chrome/browser/browser_process.h"
mpearson@chromium.org24b9bb392013-01-29 20:29:2932#include "chrome/browser/google/google_util.h"
tfarina@chromium.org0fafc8d2013-06-01 00:09:5033#include "chrome/browser/omnibox/omnibox_log.h"
ibraaaa@google.com0f5e57f52012-09-20 20:53:1834#include "chrome/browser/plugins/plugin_prefs.h"
bauerb@chromium.org10084982011-08-19 17:56:5635#include "chrome/browser/profiles/profile_manager.h"
thestig@chromium.org1eeb5e02010-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"
isherman@chromium.orgfe58acc22012-02-29 01:29:5838#include "chrome/common/metrics/proto/omnibox_event.pb.h"
isherman@chromium.orged0fd002012-04-25 23:10:3439#include "chrome/common/metrics/proto/profiler_event.pb.h"
isherman@chromium.orgfe58acc22012-02-29 01:29:5840#include "chrome/common/metrics/proto/system_profile.pb.h"
stevet@chromium.orgcf265dc02012-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"
ryanmyers@chromium.org197c0772012-05-14 23:50:5143#include "chrome/installer/util/google_update_settings.h"
yael.aharon@intel.comd5d383252013-07-04 14:44:3244#include "components/nacl/common/nacl_process_type.h"
jam@chromium.org79078df2012-02-16 01:22:3245#include "content/public/browser/gpu_data_manager.h"
isherman@chromium.org1a838cc2012-04-24 22:06:4946#include "content/public/common/content_client.h"
jam@chromium.orgd7bd3e52013-07-21 04:29:2047#include "content/public/common/webplugininfo.h"
keybuk@chromium.org611ae29a2013-04-29 21:32:1948#include "device/bluetooth/bluetooth_adapter.h"
49#include "device/bluetooth/bluetooth_adapter_factory.h"
50#include "device/bluetooth/bluetooth_device.h"
zmo@chromium.orgd7b5cc72013-05-23 20:05:0051#include "gpu/config/gpu_info.h"
derat@chromium.org6b7d954ff2011-10-25 00:39:3552#include "ui/gfx/screen.h"
tfarina@chromium.org761fa4702013-07-02 15:25:1553#include "url/gurl.h"
initial.commit09911bf2008-07-26 23:55:2954
dfalcantara@chromium.org5106b3a2012-10-03 20:10:4455#if defined(OS_ANDROID)
56#include "base/android/build_info.h"
57#endif
58
deanm@chromium.orgd1be67b2008-11-19 20:28:3859#if defined(OS_WIN)
isherman@chromium.org1bb25e02012-08-03 22:39:3960#include "base/win/metro.h"
girard@chromium.orge245ace92013-05-07 00:37:4161#include "ui/base/win/dpi.h"
isherman@chromium.org1bb25e02012-08-03 22:39:3962
63// http://blogs.msdn.com/oldnewthing/archive/2004/10/25/247180.aspx
deanm@chromium.orgd1be67b2008-11-19 20:28:3864extern "C" IMAGE_DOS_HEADER __ImageBase;
65#endif
66
jam@chromium.org79078df2012-02-16 01:22:3267using content::GpuDataManager;
isherman@chromium.orgfe58acc22012-02-29 01:29:5868using metrics::OmniboxEventProto;
asharif@chromium.orgf65859e2013-02-04 20:00:2569using metrics::PerfDataProto;
isherman@chromium.orged0fd002012-04-25 23:10:3470using metrics::ProfilerEventProto;
isherman@chromium.orgfe58acc22012-02-29 01:29:5871using metrics::SystemProfileProto;
isherman@chromium.orged0fd002012-04-25 23:10:3472using tracked_objects::ProcessDataSnapshot;
asvitkine@chromium.org0c8b7ad2012-11-06 07:08:1473typedef chrome_variations::ActiveGroupId ActiveGroupId;
ryanmyers@chromium.org197c0772012-05-14 23:50:5174typedef SystemProfileProto::GoogleUpdate::ProductInfo ProductInfo;
keybuk@chromium.org611ae29a2013-04-29 21:32:1975typedef SystemProfileProto::Hardware::Bluetooth::PairedDevice PairedDevice;
jam@chromium.org79078df2012-02-16 01:22:3276
isherman@chromium.org1df44b72012-01-19 05:20:3477namespace {
78
79// Returns the date at which the current metrics client ID was created as
isherman@chromium.orgca5ac4b2012-12-14 07:46:4080// a string containing seconds since the epoch, or "0" if none was found.
isherman@chromium.orgcc5d7f42012-10-30 00:30:0981std::string GetMetricsEnabledDate(PrefService* pref) {
isherman@chromium.org767c9d92012-03-02 16:04:3482 if (!pref) {
isherman@chromium.org1df44b72012-01-19 05:20:3483 NOTREACHED();
84 return "0";
85 }
isherman@chromium.org767c9d92012-03-02 16:04:3486
87 return pref->GetString(prefs::kMetricsClientIDTimestamp);
isherman@chromium.org1df44b72012-01-19 05:20:3488}
89
isherman@chromium.orgfe58acc22012-02-29 01:29:5890OmniboxEventProto::InputType AsOmniboxEventInputType(
91 AutocompleteInput::Type type) {
92 switch (type) {
93 case AutocompleteInput::INVALID:
94 return OmniboxEventProto::INVALID;
95 case AutocompleteInput::UNKNOWN:
96 return OmniboxEventProto::UNKNOWN;
isherman@chromium.orgfe58acc22012-02-29 01:29:5897 case AutocompleteInput::URL:
98 return OmniboxEventProto::URL;
99 case AutocompleteInput::QUERY:
100 return OmniboxEventProto::QUERY;
101 case AutocompleteInput::FORCED_QUERY:
102 return OmniboxEventProto::FORCED_QUERY;
103 default:
104 NOTREACHED();
105 return OmniboxEventProto::INVALID;
106 }
107}
108
isherman@chromium.orgfe58acc22012-02-29 01:29:58109OmniboxEventProto::Suggestion::ResultType AsOmniboxEventResultType(
110 AutocompleteMatch::Type type) {
111 switch (type) {
kmadhusu@chromium.orgb7f64d742013-05-21 04:04:04112 case AutocompleteMatchType::URL_WHAT_YOU_TYPED:
isherman@chromium.orgfe58acc22012-02-29 01:29:58113 return OmniboxEventProto::Suggestion::URL_WHAT_YOU_TYPED;
kmadhusu@chromium.orgb7f64d742013-05-21 04:04:04114 case AutocompleteMatchType::HISTORY_URL:
isherman@chromium.orgfe58acc22012-02-29 01:29:58115 return OmniboxEventProto::Suggestion::HISTORY_URL;
kmadhusu@chromium.orgb7f64d742013-05-21 04:04:04116 case AutocompleteMatchType::HISTORY_TITLE:
isherman@chromium.orgfe58acc22012-02-29 01:29:58117 return OmniboxEventProto::Suggestion::HISTORY_TITLE;
kmadhusu@chromium.orgb7f64d742013-05-21 04:04:04118 case AutocompleteMatchType::HISTORY_BODY:
isherman@chromium.orgfe58acc22012-02-29 01:29:58119 return OmniboxEventProto::Suggestion::HISTORY_BODY;
kmadhusu@chromium.orgb7f64d742013-05-21 04:04:04120 case AutocompleteMatchType::HISTORY_KEYWORD:
isherman@chromium.orgfe58acc22012-02-29 01:29:58121 return OmniboxEventProto::Suggestion::HISTORY_KEYWORD;
kmadhusu@chromium.orgb7f64d742013-05-21 04:04:04122 case AutocompleteMatchType::NAVSUGGEST:
isherman@chromium.orgfe58acc22012-02-29 01:29:58123 return OmniboxEventProto::Suggestion::NAVSUGGEST;
kmadhusu@chromium.orgb7f64d742013-05-21 04:04:04124 case AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED:
isherman@chromium.orgfe58acc22012-02-29 01:29:58125 return OmniboxEventProto::Suggestion::SEARCH_WHAT_YOU_TYPED;
kmadhusu@chromium.orgb7f64d742013-05-21 04:04:04126 case AutocompleteMatchType::SEARCH_HISTORY:
isherman@chromium.orgfe58acc22012-02-29 01:29:58127 return OmniboxEventProto::Suggestion::SEARCH_HISTORY;
kmadhusu@chromium.orgb7f64d742013-05-21 04:04:04128 case AutocompleteMatchType::SEARCH_SUGGEST:
isherman@chromium.orgfe58acc22012-02-29 01:29:58129 return OmniboxEventProto::Suggestion::SEARCH_SUGGEST;
kmadhusu@chromium.orgb7f64d742013-05-21 04:04:04130 case AutocompleteMatchType::SEARCH_OTHER_ENGINE:
isherman@chromium.orgfe58acc22012-02-29 01:29:58131 return OmniboxEventProto::Suggestion::SEARCH_OTHER_ENGINE;
kmadhusu@chromium.orgb7f64d742013-05-21 04:04:04132 case AutocompleteMatchType::EXTENSION_APP:
isherman@chromium.orgfe58acc22012-02-29 01:29:58133 return OmniboxEventProto::Suggestion::EXTENSION_APP;
kmadhusu@chromium.orgb7f64d742013-05-21 04:04:04134 case AutocompleteMatchType::CONTACT:
derat@chromium.orgdbacefb2012-09-12 03:32:06135 return OmniboxEventProto::Suggestion::CONTACT;
kmadhusu@chromium.orgb7f64d742013-05-21 04:04:04136 case AutocompleteMatchType::BOOKMARK_TITLE:
mrossetti@chromium.org25320602012-10-18 22:05:56137 return OmniboxEventProto::Suggestion::BOOKMARK_TITLE;
isherman@chromium.orgfe58acc22012-02-29 01:29:58138 default:
139 NOTREACHED();
140 return OmniboxEventProto::Suggestion::UNKNOWN_RESULT_TYPE;
141 }
142}
143
mpearson@chromium.org3c919d6a2013-07-28 18:35:52144OmniboxEventProto::PageClassification AsOmniboxEventPageClassification(
145 AutocompleteInput::PageClassification page_classification) {
146 switch (page_classification) {
147 case AutocompleteInput::INVALID_SPEC:
148 return OmniboxEventProto::INVALID_SPEC;
149 case AutocompleteInput::NEW_TAB_PAGE:
150 return OmniboxEventProto::NEW_TAB_PAGE;
151 case AutocompleteInput::BLANK:
152 return OmniboxEventProto::BLANK;
mpearson@chromium.org0b1a1112013-08-28 05:23:31153 case AutocompleteInput::HOME_PAGE:
154 return OmniboxEventProto::HOME_PAGE;
mpearson@chromium.org3c919d6a2013-07-28 18:35:52155 case AutocompleteInput::OTHER:
156 return OmniboxEventProto::OTHER;
mpearson@chromium.org3c919d6a2013-07-28 18:35:52157 case AutocompleteInput::SEARCH_RESULT_PAGE_DOING_SEARCH_TERM_REPLACEMENT:
158 return OmniboxEventProto::
159 SEARCH_RESULT_PAGE_DOING_SEARCH_TERM_REPLACEMENT;
samarth@chromium.orga93406d2013-08-07 03:22:32160 case AutocompleteInput::INSTANT_NEW_TAB_PAGE_WITH_OMNIBOX_AS_STARTING_FOCUS:
161 return OmniboxEventProto::
162 INSTANT_NEW_TAB_PAGE_WITH_OMNIBOX_AS_STARTING_FOCUS;
163 case AutocompleteInput::INSTANT_NEW_TAB_PAGE_WITH_FAKEBOX_AS_STARTING_FOCUS:
164 return OmniboxEventProto::
165 INSTANT_NEW_TAB_PAGE_WITH_FAKEBOX_AS_STARTING_FOCUS;
rlp@chromium.org2328ee22013-08-08 23:00:19166 case AutocompleteInput::SEARCH_RESULT_PAGE_NO_SEARCH_TERM_REPLACEMENT:
167 return OmniboxEventProto::
168 SEARCH_RESULT_PAGE_NO_SEARCH_TERM_REPLACEMENT;
mpearson@chromium.org3c919d6a2013-07-28 18:35:52169 }
170 return OmniboxEventProto::INVALID_SPEC;
171}
172
isherman@chromium.orged0fd002012-04-25 23:10:34173ProfilerEventProto::TrackedObject::ProcessType AsProtobufProcessType(
jam@chromium.orgf3b357692013-03-22 05:16:13174 int process_type) {
isherman@chromium.orged0fd002012-04-25 23:10:34175 switch (process_type) {
176 case content::PROCESS_TYPE_BROWSER:
177 return ProfilerEventProto::TrackedObject::BROWSER;
178 case content::PROCESS_TYPE_RENDERER:
179 return ProfilerEventProto::TrackedObject::RENDERER;
180 case content::PROCESS_TYPE_PLUGIN:
181 return ProfilerEventProto::TrackedObject::PLUGIN;
182 case content::PROCESS_TYPE_WORKER:
183 return ProfilerEventProto::TrackedObject::WORKER;
isherman@chromium.orged0fd002012-04-25 23:10:34184 case content::PROCESS_TYPE_UTILITY:
185 return ProfilerEventProto::TrackedObject::UTILITY;
isherman@chromium.orged0fd002012-04-25 23:10:34186 case content::PROCESS_TYPE_ZYGOTE:
187 return ProfilerEventProto::TrackedObject::ZYGOTE;
188 case content::PROCESS_TYPE_SANDBOX_HELPER:
189 return ProfilerEventProto::TrackedObject::SANDBOX_HELPER;
isherman@chromium.orged0fd002012-04-25 23:10:34190 case content::PROCESS_TYPE_GPU:
191 return ProfilerEventProto::TrackedObject::GPU;
192 case content::PROCESS_TYPE_PPAPI_PLUGIN:
193 return ProfilerEventProto::TrackedObject::PPAPI_PLUGIN;
194 case content::PROCESS_TYPE_PPAPI_BROKER:
195 return ProfilerEventProto::TrackedObject::PPAPI_BROKER;
jam@chromium.orgf3b357692013-03-22 05:16:13196 case PROCESS_TYPE_NACL_LOADER:
197 return ProfilerEventProto::TrackedObject::NACL_LOADER;
198 case PROCESS_TYPE_NACL_BROKER:
199 return ProfilerEventProto::TrackedObject::NACL_BROKER;
isherman@chromium.orged0fd002012-04-25 23:10:34200 default:
201 NOTREACHED();
202 return ProfilerEventProto::TrackedObject::UNKNOWN;
203 }
204}
205
isherman@chromium.org1df44b72012-01-19 05:20:34206// Returns the plugin preferences corresponding for this user, if available.
207// If multiple user profiles are loaded, returns the preferences corresponding
208// to an arbitrary one of the profiles.
209PluginPrefs* GetPluginPrefs() {
210 ProfileManager* profile_manager = g_browser_process->profile_manager();
isherman@chromium.orgfe58acc22012-02-29 01:29:58211
212 if (!profile_manager) {
213 // The profile manager can be NULL when testing.
214 return NULL;
215 }
216
isherman@chromium.org1df44b72012-01-19 05:20:34217 std::vector<Profile*> profiles = profile_manager->GetLoadedProfiles();
218 if (profiles.empty())
219 return NULL;
220
rsleevi@chromium.orgcadac622013-06-11 16:46:36221 return PluginPrefs::GetForProfile(profiles.front()).get();
isherman@chromium.org1df44b72012-01-19 05:20:34222}
223
isherman@chromium.orgfe58acc22012-02-29 01:29:58224// Fills |plugin| with the info contained in |plugin_info| and |plugin_prefs|.
jam@chromium.orgd7bd3e52013-07-21 04:29:20225void SetPluginInfo(const content::WebPluginInfo& plugin_info,
isherman@chromium.orgfe58acc22012-02-29 01:29:58226 const PluginPrefs* plugin_prefs,
227 SystemProfileProto::Plugin* plugin) {
228 plugin->set_name(UTF16ToUTF8(plugin_info.name));
229 plugin->set_filename(plugin_info.path.BaseName().AsUTF8Unsafe());
230 plugin->set_version(UTF16ToUTF8(plugin_info.version));
meacer@chromium.org4e3ca1c292013-09-10 01:59:19231 plugin->set_is_pepper(plugin_info.is_pepper_plugin());
isherman@chromium.orgfe58acc22012-02-29 01:29:58232 if (plugin_prefs)
233 plugin->set_is_disabled(!plugin_prefs->IsPluginEnabled(plugin_info));
234}
235
asvitkine@chromium.org0c8b7ad2012-11-06 07:08:14236void WriteFieldTrials(const std::vector<ActiveGroupId>& field_trial_ids,
isherman@chromium.org767c9d92012-03-02 16:04:34237 SystemProfileProto* system_profile) {
asvitkine@chromium.org0c8b7ad2012-11-06 07:08:14238 for (std::vector<ActiveGroupId>::const_iterator it =
stevet@chromium.orgad2461c2012-04-27 21:11:03239 field_trial_ids.begin(); it != field_trial_ids.end(); ++it) {
isherman@chromium.org767c9d92012-03-02 16:04:34240 SystemProfileProto::FieldTrial* field_trial =
241 system_profile->add_field_trial();
242 field_trial->set_name_id(it->name);
243 field_trial->set_group_id(it->group);
244 }
245}
246
isherman@chromium.orged0fd002012-04-25 23:10:34247void WriteProfilerData(const ProcessDataSnapshot& profiler_data,
jam@chromium.orgf3b357692013-03-22 05:16:13248 int process_type,
isherman@chromium.orged0fd002012-04-25 23:10:34249 ProfilerEventProto* performance_profile) {
250 for (std::vector<tracked_objects::TaskSnapshot>::const_iterator it =
251 profiler_data.tasks.begin();
252 it != profiler_data.tasks.end(); ++it) {
isherman@chromium.orged0fd002012-04-25 23:10:34253 const tracked_objects::DeathDataSnapshot& death_data = it->death_data;
254 ProfilerEventProto::TrackedObject* tracked_object =
255 performance_profile->add_tracked_object();
isherman@chromium.orgdb7fec832013-07-18 09:41:41256 tracked_object->set_birth_thread_name_hash(
257 MetricsLogBase::Hash(it->birth.thread_name));
258 tracked_object->set_exec_thread_name_hash(
259 MetricsLogBase::Hash(it->death_thread_name));
260 tracked_object->set_source_file_name_hash(
261 MetricsLogBase::Hash(it->birth.location.file_name));
262 tracked_object->set_source_function_name_hash(
263 MetricsLogBase::Hash(it->birth.location.function_name));
isherman@chromium.orged0fd002012-04-25 23:10:34264 tracked_object->set_source_line_number(it->birth.location.line_number);
265 tracked_object->set_exec_count(death_data.count);
266 tracked_object->set_exec_time_total(death_data.run_duration_sum);
267 tracked_object->set_exec_time_sampled(death_data.run_duration_sample);
268 tracked_object->set_queue_time_total(death_data.queue_duration_sum);
269 tracked_object->set_queue_time_sampled(death_data.queue_duration_sample);
270 tracked_object->set_process_type(AsProtobufProcessType(process_type));
271 tracked_object->set_process_id(profiler_data.process_id);
272 }
273}
274
thakis@chromium.org59a7ae4e2012-10-01 23:54:44275#if defined(GOOGLE_CHROME_BUILD) && defined(OS_WIN)
ryanmyers@chromium.org197c0772012-05-14 23:50:51276void ProductDataToProto(const GoogleUpdateSettings::ProductData& product_data,
277 ProductInfo* product_info) {
278 product_info->set_version(product_data.version);
279 product_info->set_last_update_success_timestamp(
280 product_data.last_success.ToTimeT());
281 product_info->set_last_error(product_data.last_error_code);
282 product_info->set_last_extra_error(product_data.last_extra_code);
283 if (ProductInfo::InstallResult_IsValid(product_data.last_result)) {
284 product_info->set_last_result(
285 static_cast<ProductInfo::InstallResult>(product_data.last_result));
286 }
287}
thakis@chromium.org59a7ae4e2012-10-01 23:54:44288#endif
ryanmyers@chromium.org197c0772012-05-14 23:50:51289
girard@chromium.org76869ff2013-01-15 16:13:47290#if defined(OS_WIN)
thestig@chromium.orgffaf7322013-05-15 00:26:11291struct ScreenDPIInformation {
girard@chromium.org76869ff2013-01-15 16:13:47292 double max_dpi_x;
293 double max_dpi_y;
294};
295
296// Called once for each connected monitor.
297BOOL CALLBACK GetMonitorDPICallback(HMONITOR, HDC hdc, LPRECT, LPARAM dwData) {
298 const double kMillimetersPerInch = 25.4;
299 ScreenDPIInformation* screen_info =
300 reinterpret_cast<ScreenDPIInformation*>(dwData);
301 // Size of screen, in mm.
302 DWORD size_x = GetDeviceCaps(hdc, HORZSIZE);
303 DWORD size_y = GetDeviceCaps(hdc, VERTSIZE);
304 double dpi_x = (size_x > 0) ?
305 GetDeviceCaps(hdc, HORZRES) / (size_x / kMillimetersPerInch) : 0;
306 double dpi_y = (size_y > 0) ?
307 GetDeviceCaps(hdc, VERTRES) / (size_y / kMillimetersPerInch) : 0;
girard@chromium.orge245ace92013-05-07 00:37:41308 dpi_x *= ui::win::GetUndocumentedDPIScale();
309 dpi_y *= ui::win::GetUndocumentedDPIScale();
girard@chromium.org76869ff2013-01-15 16:13:47310 screen_info->max_dpi_x = std::max(dpi_x, screen_info->max_dpi_x);
311 screen_info->max_dpi_y = std::max(dpi_y, screen_info->max_dpi_y);
312 return TRUE;
313}
314
315void WriteScreenDPIInformationProto(SystemProfileProto::Hardware* hardware) {
316 HDC desktop_dc = GetDC(NULL);
317 if (desktop_dc) {
thestig@chromium.orgffaf7322013-05-15 00:26:11318 ScreenDPIInformation si = {0, 0};
girard@chromium.org76869ff2013-01-15 16:13:47319 if (EnumDisplayMonitors(desktop_dc, NULL, GetMonitorDPICallback,
320 reinterpret_cast<LPARAM>(&si))) {
321 hardware->set_max_dpi_x(si.max_dpi_x);
322 hardware->set_max_dpi_y(si.max_dpi_y);
323 }
324 ReleaseDC(GetDesktopWindow(), desktop_dc);
325 }
326}
327
328#endif // defined(OS_WIN)
329
keybuk@chromium.org611ae29a2013-04-29 21:32:19330#if defined(OS_CHROMEOS)
331PairedDevice::Type AsBluetoothDeviceType(
332 enum device::BluetoothDevice::DeviceType device_type) {
333 switch (device_type) {
334 case device::BluetoothDevice::DEVICE_UNKNOWN:
335 return PairedDevice::DEVICE_UNKNOWN;
336 case device::BluetoothDevice::DEVICE_COMPUTER:
337 return PairedDevice::DEVICE_COMPUTER;
338 case device::BluetoothDevice::DEVICE_PHONE:
339 return PairedDevice::DEVICE_PHONE;
340 case device::BluetoothDevice::DEVICE_MODEM:
341 return PairedDevice::DEVICE_MODEM;
342 case device::BluetoothDevice::DEVICE_AUDIO:
343 return PairedDevice::DEVICE_AUDIO;
344 case device::BluetoothDevice::DEVICE_CAR_AUDIO:
345 return PairedDevice::DEVICE_CAR_AUDIO;
346 case device::BluetoothDevice::DEVICE_VIDEO:
347 return PairedDevice::DEVICE_VIDEO;
348 case device::BluetoothDevice::DEVICE_PERIPHERAL:
349 return PairedDevice::DEVICE_PERIPHERAL;
350 case device::BluetoothDevice::DEVICE_JOYSTICK:
351 return PairedDevice::DEVICE_JOYSTICK;
352 case device::BluetoothDevice::DEVICE_GAMEPAD:
353 return PairedDevice::DEVICE_GAMEPAD;
354 case device::BluetoothDevice::DEVICE_KEYBOARD:
355 return PairedDevice::DEVICE_KEYBOARD;
356 case device::BluetoothDevice::DEVICE_MOUSE:
357 return PairedDevice::DEVICE_MOUSE;
358 case device::BluetoothDevice::DEVICE_TABLET:
359 return PairedDevice::DEVICE_TABLET;
360 case device::BluetoothDevice::DEVICE_KEYBOARD_MOUSE_COMBO:
361 return PairedDevice::DEVICE_KEYBOARD_MOUSE_COMBO;
362 }
363
364 NOTREACHED();
365 return PairedDevice::DEVICE_UNKNOWN;
366}
367#endif // defined(OS_CHROMEOS)
368
rkaplow@chromium.org86573d12013-07-11 19:48:32369// Round a timestamp measured in seconds since epoch to one with a granularity
370// of an hour. This can be used before uploaded potentially sensitive
371// timestamps.
372int64 RoundSecondsToHour(int64 time_in_seconds) {
373 return 3600 * (time_in_seconds / 3600);
374}
375
isherman@chromium.org1df44b72012-01-19 05:20:34376} // namespace
377
ryanmyers@chromium.org197c0772012-05-14 23:50:51378GoogleUpdateMetrics::GoogleUpdateMetrics() : is_system_install(false) {}
379
380GoogleUpdateMetrics::~GoogleUpdateMetrics() {}
381
fischman@chromium.org67f92bc32012-01-26 01:56:19382static base::LazyInstance<std::string>::Leaky
thakis@chromium.org054c8012011-11-16 00:12:42383 g_version_extension = LAZY_INSTANCE_INITIALIZER;
384
ananta@chromium.org1226abb2010-06-10 18:01:28385MetricsLog::MetricsLog(const std::string& client_id, int session_id)
szym@chromium.org5eae204c2013-02-13 15:53:42386 : MetricsLogBase(client_id, session_id, MetricsLog::GetVersionString()) {}
jar@chromium.org5ed7d4572009-12-23 17:42:41387
ananta@chromium.org1226abb2010-06-10 18:01:28388MetricsLog::~MetricsLog() {}
initial.commit09911bf2008-07-26 23:55:29389
390// static
joi@chromium.orgb1de2c72013-02-06 02:45:47391void MetricsLog::RegisterPrefs(PrefRegistrySimple* registry) {
392 registry->RegisterListPref(prefs::kStabilityPluginStats);
initial.commit09911bf2008-07-26 23:55:29393}
394
isherman@chromium.org1df44b72012-01-19 05:20:34395// static
jar@chromium.org9165f742010-03-10 22:55:01396int64 MetricsLog::GetIncrementalUptime(PrefService* pref) {
397 base::TimeTicks now = base::TimeTicks::Now();
398 static base::TimeTicks last_updated_time(now);
399 int64 incremental_time = (now - last_updated_time).InSeconds();
400 last_updated_time = now;
401
402 if (incremental_time > 0) {
403 int64 metrics_uptime = pref->GetInt64(prefs::kUninstallMetricsUptimeSec);
404 metrics_uptime += incremental_time;
405 pref->SetInt64(prefs::kUninstallMetricsUptimeSec, metrics_uptime);
406 }
407
408 return incremental_time;
409}
410
ananta@chromium.org1226abb2010-06-10 18:01:28411// static
412std::string MetricsLog::GetVersionString() {
evan@chromium.org0211f57e2010-08-27 20:28:42413 chrome::VersionInfo version_info;
dmaclach@chromium.org30c91802010-12-18 00:40:17414 if (!version_info.is_valid()) {
415 NOTREACHED() << "Unable to retrieve version info.";
416 return std::string();
417 }
418
evan@chromium.org0211f57e2010-08-27 20:28:42419 std::string version = version_info.Version();
thakis@chromium.org054c8012011-11-16 00:12:42420 if (!version_extension().empty())
421 version += version_extension();
evan@chromium.org0211f57e2010-08-27 20:28:42422 if (!version_info.IsOfficialBuild())
423 version.append("-devel");
424 return version;
ananta@chromium.org1226abb2010-06-10 18:01:28425}
426
thakis@chromium.org054c8012011-11-16 00:12:42427// static
428void MetricsLog::set_version_extension(const std::string& extension) {
429 g_version_extension.Get() = extension;
430}
431
432// static
433const std::string& MetricsLog::version_extension() {
434 return g_version_extension.Get();
435}
436
isherman@chromium.orgfe58acc22012-02-29 01:29:58437void MetricsLog::RecordIncrementalStabilityElements(
jam@chromium.orgd7bd3e52013-07-21 04:29:20438 const std::vector<content::WebPluginInfo>& plugin_list) {
isherman@chromium.org767c9d92012-03-02 16:04:34439 DCHECK(!locked());
jar@google.com0b33f80b2008-12-17 21:34:36440
isherman@chromium.org767c9d92012-03-02 16:04:34441 PrefService* pref = GetPrefService();
jar@google.com0b33f80b2008-12-17 21:34:36442 DCHECK(pref);
443
isherman@chromium.orgf31a01a2013-07-13 02:51:11444 WriteRequiredStabilityAttributes(pref);
445 WriteRealtimeStabilityAttributes(pref);
446 WritePluginStabilityElements(plugin_list, pref);
jar@google.com0b33f80b2008-12-17 21:34:36447}
448
isherman@chromium.org767c9d92012-03-02 16:04:34449PrefService* MetricsLog::GetPrefService() {
450 return g_browser_process->local_state();
451}
452
453gfx::Size MetricsLog::GetScreenSize() const {
scottmg@chromium.orgffabb1e2012-10-12 19:51:17454 return gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().GetSizeInPixel();
isherman@chromium.org767c9d92012-03-02 16:04:34455}
456
thakis@chromium.orgaa96417972012-08-22 03:16:44457float MetricsLog::GetScreenDeviceScaleFactor() const {
scottmg@chromium.orgffabb1e2012-10-12 19:51:17458 return gfx::Screen::GetNativeScreen()->
459 GetPrimaryDisplay().device_scale_factor();
thakis@chromium.orgaa96417972012-08-22 03:16:44460}
461
isherman@chromium.org767c9d92012-03-02 16:04:34462int MetricsLog::GetScreenCount() const {
scottmg@chromium.orgffabb1e2012-10-12 19:51:17463 // TODO(scottmg): NativeScreen maybe wrong. http://crbug.com/133312
464 return gfx::Screen::GetNativeScreen()->GetNumDisplays();
isherman@chromium.org767c9d92012-03-02 16:04:34465}
466
isherman@chromium.org767c9d92012-03-02 16:04:34467void MetricsLog::GetFieldTrialIds(
asvitkine@chromium.org0c8b7ad2012-11-06 07:08:14468 std::vector<ActiveGroupId>* field_trial_ids) const {
469 chrome_variations::GetFieldTrialActiveGroupIds(field_trial_ids);
isherman@chromium.org767c9d92012-03-02 16:04:34470}
471
isherman@chromium.orgfe58acc22012-02-29 01:29:58472void MetricsLog::WriteStabilityElement(
jam@chromium.orgd7bd3e52013-07-21 04:29:20473 const std::vector<content::WebPluginInfo>& plugin_list,
isherman@chromium.orgfe58acc22012-02-29 01:29:58474 PrefService* pref) {
isherman@chromium.org767c9d92012-03-02 16:04:34475 DCHECK(!locked());
initial.commit09911bf2008-07-26 23:55:29476
initial.commit09911bf2008-07-26 23:55:29477 // Get stability attributes out of Local State, zeroing out stored values.
478 // NOTE: This could lead to some data loss if this report isn't successfully
479 // sent, but that's true for all the metrics.
480
jar@google.com147bbc0b2009-01-06 19:37:40481 WriteRequiredStabilityAttributes(pref);
482 WriteRealtimeStabilityAttributes(pref);
initial.commit09911bf2008-07-26 23:55:29483
isherman@chromium.orgfe58acc22012-02-29 01:29:58484 int incomplete_shutdown_count =
485 pref->GetInteger(prefs::kStabilityIncompleteSessionEndCount);
cpu@chromium.orge324f6b2012-02-28 05:43:37486 pref->SetInteger(prefs::kStabilityIncompleteSessionEndCount, 0);
isherman@chromium.orgfe58acc22012-02-29 01:29:58487 int breakpad_registration_success_count =
488 pref->GetInteger(prefs::kStabilityBreakpadRegistrationSuccess);
cpu@chromium.orge324f6b2012-02-28 05:43:37489 pref->SetInteger(prefs::kStabilityBreakpadRegistrationSuccess, 0);
isherman@chromium.orgfe58acc22012-02-29 01:29:58490 int breakpad_registration_failure_count =
491 pref->GetInteger(prefs::kStabilityBreakpadRegistrationFail);
cpu@chromium.orge324f6b2012-02-28 05:43:37492 pref->SetInteger(prefs::kStabilityBreakpadRegistrationFail, 0);
isherman@chromium.orgfe58acc22012-02-29 01:29:58493 int debugger_present_count =
494 pref->GetInteger(prefs::kStabilityDebuggerPresent);
cpu@chromium.orge324f6b2012-02-28 05:43:37495 pref->SetInteger(prefs::kStabilityDebuggerPresent, 0);
isherman@chromium.orgfe58acc22012-02-29 01:29:58496 int debugger_not_present_count =
497 pref->GetInteger(prefs::kStabilityDebuggerNotPresent);
cpu@chromium.orge324f6b2012-02-28 05:43:37498 pref->SetInteger(prefs::kStabilityDebuggerNotPresent, 0);
isherman@chromium.orgb2a4812d2012-02-28 05:31:31499
isherman@chromium.orgfe58acc22012-02-29 01:29:58500 // TODO(jar): The following are all optional, so we *could* optimize them for
501 // values of zero (and not include them).
isherman@chromium.orgfe58acc22012-02-29 01:29:58502 SystemProfileProto::Stability* stability =
isherman@chromium.org767c9d92012-03-02 16:04:34503 uma_proto()->mutable_system_profile()->mutable_stability();
isherman@chromium.orgfe58acc22012-02-29 01:29:58504 stability->set_incomplete_shutdown_count(incomplete_shutdown_count);
505 stability->set_breakpad_registration_success_count(
506 breakpad_registration_success_count);
507 stability->set_breakpad_registration_failure_count(
508 breakpad_registration_failure_count);
509 stability->set_debugger_present_count(debugger_present_count);
510 stability->set_debugger_not_present_count(debugger_not_present_count);
511
512 WritePluginStabilityElements(plugin_list, pref);
jar@google.com147bbc0b2009-01-06 19:37:40513}
514
isherman@chromium.orgfe58acc22012-02-29 01:29:58515void MetricsLog::WritePluginStabilityElements(
jam@chromium.orgd7bd3e52013-07-21 04:29:20516 const std::vector<content::WebPluginInfo>& plugin_list,
isherman@chromium.orgfe58acc22012-02-29 01:29:58517 PrefService* pref) {
jar@google.com147bbc0b2009-01-06 19:37:40518 // Now log plugin stability info.
initial.commit09911bf2008-07-26 23:55:29519 const ListValue* plugin_stats_list = pref->GetList(
520 prefs::kStabilityPluginStats);
isherman@chromium.org1df44b72012-01-19 05:20:34521 if (!plugin_stats_list)
522 return;
initial.commit09911bf2008-07-26 23:55:29523
nileshagrawal@chromium.orgebd71962012-12-20 02:56:55524#if defined(ENABLE_PLUGINS)
isherman@chromium.orgfe58acc22012-02-29 01:29:58525 SystemProfileProto::Stability* stability =
isherman@chromium.org767c9d92012-03-02 16:04:34526 uma_proto()->mutable_system_profile()->mutable_stability();
isherman@chromium.orgfe58acc22012-02-29 01:29:58527 PluginPrefs* plugin_prefs = GetPluginPrefs();
isherman@chromium.org1df44b72012-01-19 05:20:34528 for (ListValue::const_iterator iter = plugin_stats_list->begin();
529 iter != plugin_stats_list->end(); ++iter) {
530 if (!(*iter)->IsType(Value::TYPE_DICTIONARY)) {
531 NOTREACHED();
532 continue;
initial.commit09911bf2008-07-26 23:55:29533 }
isherman@chromium.org1df44b72012-01-19 05:20:34534 DictionaryValue* plugin_dict = static_cast<DictionaryValue*>(*iter);
initial.commit09911bf2008-07-26 23:55:29535
isherman@chromium.orgfe58acc22012-02-29 01:29:58536 // Write the protobuf version.
537 // Note that this search is potentially a quadratic operation, but given the
538 // low number of plugins installed on a "reasonable" setup, this should be
539 // fine.
540 // TODO(isherman): Verify that this does not show up as a hotspot in
541 // profiler runs.
jam@chromium.orgd7bd3e52013-07-21 04:29:20542 const content::WebPluginInfo* plugin_info = NULL;
isherman@chromium.orgf31a01a2013-07-13 02:51:11543 std::string plugin_name;
544 plugin_dict->GetString(prefs::kStabilityPluginName, &plugin_name);
isherman@chromium.orgfe58acc22012-02-29 01:29:58545 const string16 plugin_name_utf16 = UTF8ToUTF16(plugin_name);
jam@chromium.orgd7bd3e52013-07-21 04:29:20546 for (std::vector<content::WebPluginInfo>::const_iterator iter =
isherman@chromium.orgfe58acc22012-02-29 01:29:58547 plugin_list.begin();
548 iter != plugin_list.end(); ++iter) {
549 if (iter->name == plugin_name_utf16) {
550 plugin_info = &(*iter);
551 break;
552 }
553 }
554
555 if (!plugin_info) {
556 NOTREACHED();
557 continue;
558 }
isherman@chromium.orgfe58acc22012-02-29 01:29:58559
isherman@chromium.orgfe58acc22012-02-29 01:29:58560 SystemProfileProto::Stability::PluginStability* plugin_stability =
561 stability->add_plugin_stability();
562 SetPluginInfo(*plugin_info, plugin_prefs,
563 plugin_stability->mutable_plugin());
isherman@chromium.orgf31a01a2013-07-13 02:51:11564
565 int launches = 0;
566 plugin_dict->GetInteger(prefs::kStabilityPluginLaunches, &launches);
567 if (launches > 0)
568 plugin_stability->set_launch_count(launches);
569
570 int instances = 0;
571 plugin_dict->GetInteger(prefs::kStabilityPluginInstances, &instances);
572 if (instances > 0)
573 plugin_stability->set_instance_count(instances);
574
575 int crashes = 0;
576 plugin_dict->GetInteger(prefs::kStabilityPluginCrashes, &crashes);
577 if (crashes > 0)
578 plugin_stability->set_crash_count(crashes);
579
580 int loading_errors = 0;
581 plugin_dict->GetInteger(prefs::kStabilityPluginLoadingErrors,
582 &loading_errors);
583 if (loading_errors > 0)
584 plugin_stability->set_loading_error_count(loading_errors);
initial.commit09911bf2008-07-26 23:55:29585 }
nileshagrawal@chromium.orgebd71962012-12-20 02:56:55586#endif // defined(ENABLE_PLUGINS)
isherman@chromium.org1df44b72012-01-19 05:20:34587
588 pref->ClearPref(prefs::kStabilityPluginStats);
initial.commit09911bf2008-07-26 23:55:29589}
590
isherman@chromium.orgfe58acc22012-02-29 01:29:58591// The server refuses data that doesn't have certain values. crashcount and
592// launchcount are currently "required" in the "stability" group.
593// TODO(isherman): Stop writing these attributes specially once the migration to
594// protobufs is complete.
jar@google.com147bbc0b2009-01-06 19:37:40595void MetricsLog::WriteRequiredStabilityAttributes(PrefService* pref) {
isherman@chromium.orgfe58acc22012-02-29 01:29:58596 int launch_count = pref->GetInteger(prefs::kStabilityLaunchCount);
jar@google.com0b33f80b2008-12-17 21:34:36597 pref->SetInteger(prefs::kStabilityLaunchCount, 0);
isherman@chromium.orgfe58acc22012-02-29 01:29:58598 int crash_count = pref->GetInteger(prefs::kStabilityCrashCount);
jar@google.com0b33f80b2008-12-17 21:34:36599 pref->SetInteger(prefs::kStabilityCrashCount, 0);
isherman@chromium.orgfe58acc22012-02-29 01:29:58600
isherman@chromium.orgfe58acc22012-02-29 01:29:58601 SystemProfileProto::Stability* stability =
isherman@chromium.org767c9d92012-03-02 16:04:34602 uma_proto()->mutable_system_profile()->mutable_stability();
isherman@chromium.orgfe58acc22012-02-29 01:29:58603 stability->set_launch_count(launch_count);
604 stability->set_crash_count(crash_count);
jar@google.com0b33f80b2008-12-17 21:34:36605}
606
jar@google.com147bbc0b2009-01-06 19:37:40607void MetricsLog::WriteRealtimeStabilityAttributes(PrefService* pref) {
jar@google.com0b33f80b2008-12-17 21:34:36608 // Update the stats which are critical for real-time stability monitoring.
609 // Since these are "optional," only list ones that are non-zero, as the counts
610 // are aggergated (summed) server side.
611
isherman@chromium.orgfe58acc22012-02-29 01:29:58612 SystemProfileProto::Stability* stability =
isherman@chromium.org767c9d92012-03-02 16:04:34613 uma_proto()->mutable_system_profile()->mutable_stability();
jar@google.com0b33f80b2008-12-17 21:34:36614 int count = pref->GetInteger(prefs::kStabilityPageLoadCount);
615 if (count) {
isherman@chromium.orgfe58acc22012-02-29 01:29:58616 stability->set_page_load_count(count);
jar@google.com0b33f80b2008-12-17 21:34:36617 pref->SetInteger(prefs::kStabilityPageLoadCount, 0);
618 }
619
620 count = pref->GetInteger(prefs::kStabilityRendererCrashCount);
621 if (count) {
isherman@chromium.orgfe58acc22012-02-29 01:29:58622 stability->set_renderer_crash_count(count);
jar@google.com0b33f80b2008-12-17 21:34:36623 pref->SetInteger(prefs::kStabilityRendererCrashCount, 0);
624 }
625
asargent@chromium.org1f085622009-12-04 05:33:45626 count = pref->GetInteger(prefs::kStabilityExtensionRendererCrashCount);
627 if (count) {
isherman@chromium.orgfe58acc22012-02-29 01:29:58628 stability->set_extension_renderer_crash_count(count);
asargent@chromium.org1f085622009-12-04 05:33:45629 pref->SetInteger(prefs::kStabilityExtensionRendererCrashCount, 0);
630 }
631
jar@google.com0b33f80b2008-12-17 21:34:36632 count = pref->GetInteger(prefs::kStabilityRendererHangCount);
633 if (count) {
isherman@chromium.orgfe58acc22012-02-29 01:29:58634 stability->set_renderer_hang_count(count);
jar@google.com0b33f80b2008-12-17 21:34:36635 pref->SetInteger(prefs::kStabilityRendererHangCount, 0);
636 }
asargent@chromium.org1f085622009-12-04 05:33:45637
638 count = pref->GetInteger(prefs::kStabilityChildProcessCrashCount);
639 if (count) {
isherman@chromium.orgfe58acc22012-02-29 01:29:58640 stability->set_child_process_crash_count(count);
asargent@chromium.org1f085622009-12-04 05:33:45641 pref->SetInteger(prefs::kStabilityChildProcessCrashCount, 0);
642 }
jar@chromium.org9165f742010-03-10 22:55:01643
petkov@chromium.orgc1834a92011-01-21 18:21:03644#if defined(OS_CHROMEOS)
645 count = pref->GetInteger(prefs::kStabilityOtherUserCrashCount);
646 if (count) {
isherman@chromium.orgfe58acc22012-02-29 01:29:58647 stability->set_other_user_crash_count(count);
petkov@chromium.orgc1834a92011-01-21 18:21:03648 pref->SetInteger(prefs::kStabilityOtherUserCrashCount, 0);
649 }
650
651 count = pref->GetInteger(prefs::kStabilityKernelCrashCount);
652 if (count) {
isherman@chromium.orgfe58acc22012-02-29 01:29:58653 stability->set_kernel_crash_count(count);
petkov@chromium.orgc1834a92011-01-21 18:21:03654 pref->SetInteger(prefs::kStabilityKernelCrashCount, 0);
655 }
656
657 count = pref->GetInteger(prefs::kStabilitySystemUncleanShutdownCount);
658 if (count) {
isherman@chromium.orgfe58acc22012-02-29 01:29:58659 stability->set_unclean_system_shutdown_count(count);
petkov@chromium.orgc1834a92011-01-21 18:21:03660 pref->SetInteger(prefs::kStabilitySystemUncleanShutdownCount, 0);
661 }
662#endif // OS_CHROMEOS
663
jar@chromium.org9165f742010-03-10 22:55:01664 int64 recent_duration = GetIncrementalUptime(pref);
isherman@chromium.orgf31a01a2013-07-13 02:51:11665 if (recent_duration)
isherman@chromium.orgfe58acc22012-02-29 01:29:58666 stability->set_uptime_sec(recent_duration);
jar@google.com0b33f80b2008-12-17 21:34:36667}
668
initial.commit09911bf2008-07-26 23:55:29669void MetricsLog::WritePluginList(
jam@chromium.orgd7bd3e52013-07-21 04:29:20670 const std::vector<content::WebPluginInfo>& plugin_list) {
isherman@chromium.org767c9d92012-03-02 16:04:34671 DCHECK(!locked());
initial.commit09911bf2008-07-26 23:55:29672
nileshagrawal@chromium.orgebd71962012-12-20 02:56:55673#if defined(ENABLE_PLUGINS)
674 PluginPrefs* plugin_prefs = GetPluginPrefs();
isherman@chromium.org767c9d92012-03-02 16:04:34675 SystemProfileProto* system_profile = uma_proto()->mutable_system_profile();
jam@chromium.orgd7bd3e52013-07-21 04:29:20676 for (std::vector<content::WebPluginInfo>::const_iterator iter =
brettw@chromium.org191eb3f72010-12-21 06:27:50677 plugin_list.begin();
initial.commit09911bf2008-07-26 23:55:29678 iter != plugin_list.end(); ++iter) {
isherman@chromium.org0eecc2542013-06-23 04:22:02679 SystemProfileProto::Plugin* plugin = system_profile->add_plugin();
680 SetPluginInfo(*iter, plugin_prefs, plugin);
initial.commit09911bf2008-07-26 23:55:29681 }
nileshagrawal@chromium.orgebd71962012-12-20 02:56:55682#endif // defined(ENABLE_PLUGINS)
initial.commit09911bf2008-07-26 23:55:29683}
684
initial.commit09911bf2008-07-26 23:55:29685void MetricsLog::RecordEnvironment(
jam@chromium.orgd7bd3e52013-07-21 04:29:20686 const std::vector<content::WebPluginInfo>& plugin_list,
isherman@chromium.orgf31a01a2013-07-13 02:51:11687 const GoogleUpdateMetrics& google_update_metrics) {
isherman@chromium.org767c9d92012-03-02 16:04:34688 DCHECK(!locked());
initial.commit09911bf2008-07-26 23:55:29689
isherman@chromium.org767c9d92012-03-02 16:04:34690 PrefService* pref = GetPrefService();
isherman@chromium.orgfe58acc22012-02-29 01:29:58691 WriteStabilityElement(plugin_list, pref);
initial.commit09911bf2008-07-26 23:55:29692
ryanmyers@chromium.org197c0772012-05-14 23:50:51693 RecordEnvironmentProto(plugin_list, google_update_metrics);
isherman@chromium.orgbc66d532012-03-23 01:57:05694}
695
696void MetricsLog::RecordEnvironmentProto(
jam@chromium.orgd7bd3e52013-07-21 04:29:20697 const std::vector<content::WebPluginInfo>& plugin_list,
ryanmyers@chromium.org197c0772012-05-14 23:50:51698 const GoogleUpdateMetrics& google_update_metrics) {
isherman@chromium.orgbc66d532012-03-23 01:57:05699 SystemProfileProto* system_profile = uma_proto()->mutable_system_profile();
mpearson@chromium.org24b9bb392013-01-29 20:29:29700
701 std::string brand_code;
702 if (google_util::GetBrand(&brand_code))
703 system_profile->set_brand_code(brand_code);
704
isherman@chromium.orgcc5d7f42012-10-30 00:30:09705 int enabled_date;
706 bool success = base::StringToInt(GetMetricsEnabledDate(GetPrefService()),
707 &enabled_date);
isherman@chromium.orgbc66d532012-03-23 01:57:05708 DCHECK(success);
rkaplow@chromium.org86573d12013-07-11 19:48:32709
710 // Reduce granularity of the enabled_date field to nearest hour.
711 system_profile->set_uma_enabled_date(RoundSecondsToHour(enabled_date));
712
713 int64 install_date = GetPrefService()->GetInt64(prefs::kInstallDate);
714
715 // Reduce granularity of the install_date field to nearest hour.
716 system_profile->set_install_date(RoundSecondsToHour(install_date));
isherman@chromium.orgbc66d532012-03-23 01:57:05717
718 system_profile->set_application_locale(
jam@chromium.orgeabbfb12013-04-05 23:28:35719 g_browser_process->GetApplicationLocale());
isherman@chromium.orgbc66d532012-03-23 01:57:05720
721 SystemProfileProto::Hardware* hardware = system_profile->mutable_hardware();
thestig@chromium.org0b6a4fb2012-10-16 01:58:21722 hardware->set_cpu_architecture(base::SysInfo::OperatingSystemArchitecture());
isherman@chromium.orgbc66d532012-03-23 01:57:05723 hardware->set_system_ram_mb(base::SysInfo::AmountOfPhysicalMemoryMB());
724#if defined(OS_WIN)
725 hardware->set_dll_base(reinterpret_cast<uint64>(&__ImageBase));
726#endif
727
szym@chromium.org74b299e2013-01-29 01:24:42728 SystemProfileProto::Network* network = system_profile->mutable_network();
729 network->set_connection_type_is_ambiguous(
szym@chromium.org5eae204c2013-02-13 15:53:42730 network_observer_.connection_type_is_ambiguous());
731 network->set_connection_type(network_observer_.connection_type());
732 network->set_wifi_phy_layer_protocol_is_ambiguous(
733 network_observer_.wifi_phy_layer_protocol_is_ambiguous());
734 network->set_wifi_phy_layer_protocol(
735 network_observer_.wifi_phy_layer_protocol());
736 network_observer_.Reset();
szym@chromium.org74b299e2013-01-29 01:24:42737
isherman@chromium.orgbc66d532012-03-23 01:57:05738 SystemProfileProto::OS* os = system_profile->mutable_os();
isherman@chromium.org1bb25e02012-08-03 22:39:39739 std::string os_name = base::SysInfo::OperatingSystemName();
740#if defined(OS_WIN)
741 // TODO(mad): This only checks whether the main process is a Metro process at
742 // upload time; not whether the collected metrics were all gathered from
743 // Metro. This is ok as an approximation for now, since users will rarely be
744 // switching from Metro to Desktop mode; but we should re-evaluate whether we
745 // can distinguish metrics more cleanly in the future: http://crbug.com/140568
746 if (base::win::IsMetroProcess())
747 os_name += " (Metro)";
748#endif
749 os->set_name(os_name);
isherman@chromium.orgbc66d532012-03-23 01:57:05750 os->set_version(base::SysInfo::OperatingSystemVersion());
dfalcantara@chromium.org5106b3a2012-10-03 20:10:44751#if defined(OS_ANDROID)
752 os->set_fingerprint(
753 base::android::BuildInfo::GetInstance()->android_build_fp());
754#endif
isherman@chromium.orgbc66d532012-03-23 01:57:05755
simonjam@chromium.org5c8f89f692013-07-18 11:13:28756 base::CPU cpu_info;
757 SystemProfileProto::Hardware::CPU* cpu = hardware->mutable_cpu();
758 cpu->set_vendor_name(cpu_info.vendor_name());
759 cpu->set_signature(cpu_info.signature());
760
zmo@chromium.orgd7b5cc72013-05-23 20:05:00761 const gpu::GPUInfo& gpu_info =
isherman@chromium.orgbc66d532012-03-23 01:57:05762 GpuDataManager::GetInstance()->GetGPUInfo();
763 SystemProfileProto::Hardware::Graphics* gpu = hardware->mutable_gpu();
zmo@chromium.orga094e2c2012-05-10 23:02:42764 gpu->set_vendor_id(gpu_info.gpu.vendor_id);
765 gpu->set_device_id(gpu_info.gpu.device_id);
isherman@chromium.orgbc66d532012-03-23 01:57:05766 gpu->set_driver_version(gpu_info.driver_version);
767 gpu->set_driver_date(gpu_info.driver_date);
768 SystemProfileProto::Hardware::Graphics::PerformanceStatistics*
769 gpu_performance = gpu->mutable_performance_statistics();
770 gpu_performance->set_graphics_score(gpu_info.performance_stats.graphics);
771 gpu_performance->set_gaming_score(gpu_info.performance_stats.gaming);
772 gpu_performance->set_overall_score(gpu_info.performance_stats.overall);
cramya@chromium.orgd6bdfae2013-01-18 20:23:01773 gpu->set_gl_vendor(gpu_info.gl_vendor);
774 gpu->set_gl_renderer(gpu_info.gl_renderer);
isherman@chromium.orgbc66d532012-03-23 01:57:05775
776 const gfx::Size display_size = GetScreenSize();
777 hardware->set_primary_screen_width(display_size.width());
778 hardware->set_primary_screen_height(display_size.height());
thakis@chromium.orgaa96417972012-08-22 03:16:44779 hardware->set_primary_screen_scale_factor(GetScreenDeviceScaleFactor());
isherman@chromium.orgbc66d532012-03-23 01:57:05780 hardware->set_screen_count(GetScreenCount());
781
girard@chromium.org76869ff2013-01-15 16:13:47782#if defined(OS_WIN)
783 WriteScreenDPIInformationProto(hardware);
784#endif
785
ryanmyers@chromium.org197c0772012-05-14 23:50:51786 WriteGoogleUpdateProto(google_update_metrics);
787
isherman@chromium.org0eecc2542013-06-23 04:22:02788 WritePluginList(plugin_list);
isherman@chromium.orgbc66d532012-03-23 01:57:05789
asvitkine@chromium.org0c8b7ad2012-11-06 07:08:14790 std::vector<ActiveGroupId> field_trial_ids;
isherman@chromium.org767c9d92012-03-02 16:04:34791 GetFieldTrialIds(&field_trial_ids);
792 WriteFieldTrials(field_trial_ids, system_profile);
asharif@chromium.orgf65859e2013-02-04 20:00:25793
794#if defined(OS_CHROMEOS)
795 PerfDataProto perf_data_proto;
796 if (perf_provider_.GetPerfData(&perf_data_proto))
797 uma_proto()->add_perf_data()->Swap(&perf_data_proto);
keybuk@chromium.org611ae29a2013-04-29 21:32:19798
799 // BluetoothAdapterFactory::GetAdapter is synchronous on Chrome OS; if that
800 // changes this will fail at the DCHECK().
801 device::BluetoothAdapterFactory::GetAdapter(
802 base::Bind(&MetricsLog::SetBluetoothAdapter,
803 base::Unretained(this)));
804 DCHECK(adapter_.get());
805 WriteBluetoothProto(hardware);
asharif@chromium.orgf65859e2013-02-04 20:00:25806#endif
initial.commit09911bf2008-07-26 23:55:29807}
808
isherman@chromium.orged0fd002012-04-25 23:10:34809void MetricsLog::RecordProfilerData(
810 const tracked_objects::ProcessDataSnapshot& process_data,
jam@chromium.orgf3b357692013-03-22 05:16:13811 int process_type) {
isherman@chromium.orged0fd002012-04-25 23:10:34812 DCHECK(!locked());
813
isherman@chromium.org8f829682012-04-27 00:36:49814 if (tracked_objects::GetTimeSourceType() !=
815 tracked_objects::TIME_SOURCE_TYPE_WALL_TIME) {
isherman@chromium.orged0fd002012-04-25 23:10:34816 // We currently only support the default time source, wall clock time.
817 return;
818 }
819
820 ProfilerEventProto* profile;
821 if (!uma_proto()->profiler_event_size()) {
822 // For the first process's data, add a new field to the protocol buffer.
823 profile = uma_proto()->add_profiler_event();
824 profile->set_profile_type(ProfilerEventProto::STARTUP_PROFILE);
825 profile->set_time_source(ProfilerEventProto::WALL_CLOCK_TIME);
826 } else {
827 // For the remaining calls, re-use the existing field.
828 profile = uma_proto()->mutable_profiler_event(0);
829 }
830
831 WriteProfilerData(process_data, process_type, profile);
832}
833
tfarina@chromium.org0fafc8d2013-06-01 00:09:50834void MetricsLog::RecordOmniboxOpenedURL(const OmniboxLog& log) {
isherman@chromium.org767c9d92012-03-02 16:04:34835 DCHECK(!locked());
initial.commit09911bf2008-07-26 23:55:29836
isherman@chromium.org65956312012-04-19 21:28:12837 std::vector<string16> terms;
838 const int num_terms =
839 static_cast<int>(Tokenize(log.text, kWhitespaceUTF16, &terms));
initial.commit09911bf2008-07-26 23:55:29840
isherman@chromium.org767c9d92012-03-02 16:04:34841 OmniboxEventProto* omnibox_event = uma_proto()->add_omnibox_event();
isherman@chromium.orgfe58acc22012-02-29 01:29:58842 omnibox_event->set_time(MetricsLogBase::GetCurrentTime());
843 if (log.tab_id != -1) {
844 // If we know what tab the autocomplete URL was opened in, log it.
845 omnibox_event->set_tab_id(log.tab_id);
846 }
847 omnibox_event->set_typed_length(log.text.length());
mpearson@chromium.org660fe8f32012-05-03 20:01:08848 omnibox_event->set_just_deleted_text(log.just_deleted_text);
isherman@chromium.org65956312012-04-19 21:28:12849 omnibox_event->set_num_typed_terms(num_terms);
isherman@chromium.orgfe58acc22012-02-29 01:29:58850 omnibox_event->set_selected_index(log.selected_index);
bartn@chromium.org62b3ef52013-01-18 00:13:02851 if (log.completed_length != string16::npos)
852 omnibox_event->set_completed_length(log.completed_length);
isherman@chromium.org65956312012-04-19 21:28:12853 if (log.elapsed_time_since_user_first_modified_omnibox !=
854 base::TimeDelta::FromMilliseconds(-1)) {
855 // Only upload the typing duration if it is set/valid.
856 omnibox_event->set_typing_duration_ms(
857 log.elapsed_time_since_user_first_modified_omnibox.InMilliseconds());
858 }
mpearson@chromium.org35d55602012-11-20 23:49:03859 omnibox_event->set_duration_since_last_default_match_update_ms(
860 log.elapsed_time_since_last_change_to_default_match.InMilliseconds());
mpearson@chromium.orgee902532012-05-01 23:54:49861 omnibox_event->set_current_page_classification(
mpearson@chromium.org3c919d6a2013-07-28 18:35:52862 AsOmniboxEventPageClassification(log.current_page_classification));
isherman@chromium.orgfe58acc22012-02-29 01:29:58863 omnibox_event->set_input_type(AsOmniboxEventInputType(log.input_type));
dcblack@chromium.org1fce7dd42013-08-06 02:29:17864
865 // The view code to hide the top result is currently only implemented on the
jered@chromium.orgedd95dd2013-08-08 12:17:25866 // Mac and for views.
867#if defined(OS_MACOSX) || defined(TOOLKIT_VIEWS)
dcblack@chromium.org1fce7dd42013-08-06 02:29:17868 omnibox_event->set_is_top_result_hidden_in_dropdown(
869 log.result.ShouldHideTopMatch());
jered@chromium.orgedd95dd2013-08-08 12:17:25870#endif // defined(OS_MACOSX) || defined(TOOLKIT_VIEWS)
dcblack@chromium.org1fce7dd42013-08-06 02:29:17871
isherman@chromium.orgfe58acc22012-02-29 01:29:58872 for (AutocompleteResult::const_iterator i(log.result.begin());
873 i != log.result.end(); ++i) {
874 OmniboxEventProto::Suggestion* suggestion = omnibox_event->add_suggestion();
mpearson@chromium.org0e9e8782012-05-15 23:01:51875 suggestion->set_provider(i->provider->AsOmniboxEventProviderType());
isherman@chromium.orgfe58acc22012-02-29 01:29:58876 suggestion->set_result_type(AsOmniboxEventResultType(i->type));
877 suggestion->set_relevance(i->relevance);
mpearson@chromium.orgcf6256f2012-06-12 23:36:01878 if (i->typed_count != -1)
879 suggestion->set_typed_count(i->typed_count);
isherman@chromium.orgfe58acc22012-02-29 01:29:58880 suggestion->set_is_starred(i->starred);
881 }
mpearson@chromium.org0e9e8782012-05-15 23:01:51882 for (ProvidersInfo::const_iterator i(log.providers_info.begin());
883 i != log.providers_info.end(); ++i) {
884 OmniboxEventProto::ProviderInfo* provider_info =
885 omnibox_event->add_provider_info();
886 provider_info->CopyFrom(*i);
887 }
isherman@chromium.orgfe58acc22012-02-29 01:29:58888
initial.commit09911bf2008-07-26 23:55:29889 ++num_events_;
890}
ryanmyers@chromium.org197c0772012-05-14 23:50:51891
892void MetricsLog::WriteGoogleUpdateProto(
893 const GoogleUpdateMetrics& google_update_metrics) {
894#if defined(GOOGLE_CHROME_BUILD) && defined(OS_WIN)
895 SystemProfileProto::GoogleUpdate* google_update =
896 uma_proto()->mutable_system_profile()->mutable_google_update();
897
898 google_update->set_is_system_install(google_update_metrics.is_system_install);
899
900 if (!google_update_metrics.last_started_au.is_null()) {
901 google_update->set_last_automatic_start_timestamp(
902 google_update_metrics.last_started_au.ToTimeT());
903 }
904
905 if (!google_update_metrics.last_checked.is_null()) {
906 google_update->set_last_update_check_timestamp(
907 google_update_metrics.last_checked.ToTimeT());
908 }
909
910 if (!google_update_metrics.google_update_data.version.empty()) {
911 ProductDataToProto(google_update_metrics.google_update_data,
912 google_update->mutable_google_update_status());
913 }
914
915 if (!google_update_metrics.product_data.version.empty()) {
916 ProductDataToProto(google_update_metrics.product_data,
917 google_update->mutable_client_status());
918 }
919#endif // defined(GOOGLE_CHROME_BUILD) && defined(OS_WIN)
920}
keybuk@chromium.org611ae29a2013-04-29 21:32:19921
922void MetricsLog::SetBluetoothAdapter(
923 scoped_refptr<device::BluetoothAdapter> adapter) {
924 adapter_ = adapter;
925}
926
927void MetricsLog::WriteBluetoothProto(
928 SystemProfileProto::Hardware* hardware) {
keybuk@chromium.org728f9b22013-05-02 06:08:18929#if defined(OS_CHROMEOS)
keybuk@chromium.org611ae29a2013-04-29 21:32:19930 SystemProfileProto::Hardware::Bluetooth* bluetooth =
931 hardware->mutable_bluetooth();
932
933 bluetooth->set_is_present(adapter_->IsPresent());
934 bluetooth->set_is_enabled(adapter_->IsPowered());
935
936 device::BluetoothAdapter::DeviceList devices = adapter_->GetDevices();
937 for (device::BluetoothAdapter::DeviceList::iterator iter =
938 devices.begin(); iter != devices.end(); ++iter) {
939 PairedDevice* paired_device = bluetooth->add_paired_device();
940
941 device::BluetoothDevice* device = *iter;
942 paired_device->set_bluetooth_class(device->GetBluetoothClass());
943 paired_device->set_type(AsBluetoothDeviceType(device->GetDeviceType()));
944
945 // address is xx:xx:xx:xx:xx:xx, extract the first three components and
946 // pack into a uint32
947 std::string address = device->GetAddress();
948 if (address.size() > 9 &&
949 address[2] == ':' && address[5] == ':' && address[8] == ':') {
950 std::string vendor_prefix_str;
951 uint64 vendor_prefix;
952
953 RemoveChars(address.substr(0, 9), ":", &vendor_prefix_str);
954 DCHECK_EQ(6U, vendor_prefix_str.size());
955 base::HexStringToUInt64(vendor_prefix_str, &vendor_prefix);
956
957 paired_device->set_vendor_prefix(vendor_prefix);
958 }
959
960 paired_device->set_vendor_id(device->GetVendorID());
961 paired_device->set_product_id(device->GetProductID());
962 paired_device->set_device_id(device->GetDeviceID());
963 }
964#endif // defined(OS_CHROMEOS)
965}