blob: ba2117de3f41a4ba8e2644a0ebbf0527101f0ccc [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]0f2f7792013-11-28 16:09:1411#include "base/base64.h"
[email protected]d1be67b2008-11-19 20:28:3812#include "base/basictypes.h"
[email protected]611ae29a2013-04-29 21:32:1913#include "base/bind.h"
[email protected]5c8f89f692013-07-18 11:13:2814#include "base/cpu.h"
[email protected]054c8012011-11-16 00:12:4215#include "base/lazy_instance.h"
[email protected]3b63f8f42011-03-28 01:54:1516#include "base/memory/scoped_ptr.h"
[email protected]3853a4c2013-02-11 17:15:5717#include "base/prefs/pref_registry_simple.h"
18#include "base/prefs/pref_service.h"
[email protected]ed0fd002012-04-25 23:10:3419#include "base/profiler/alternate_timer.h"
[email protected]0f2f7792013-11-28 16:09:1420#include "base/sha1.h"
[email protected]3ea1b182013-02-08 22:38:4121#include "base/strings/string_number_conversions.h"
[email protected]f9b294362013-06-10 20:22:3122#include "base/strings/string_util.h"
[email protected]112158af2013-06-07 23:46:1823#include "base/strings/utf_string_conversions.h"
[email protected]fadf97f2008-09-18 12:18:1424#include "base/sys_info.h"
[email protected]37f39e42010-01-06 17:35:1725#include "base/third_party/nspr/prtime.h"
[email protected]84813472013-06-28 00:25:1926#include "base/time/time.h"
[email protected]ed0fd002012-04-25 23:10:3427#include "base/tracked_objects.h"
[email protected]9f8bc2f2012-07-03 16:26:5328#include "chrome/browser/autocomplete/autocomplete_input.h"
[email protected]9ac40092010-10-27 23:05:2629#include "chrome/browser/autocomplete/autocomplete_match.h"
[email protected]30f5bc92012-06-26 04:14:5530#include "chrome/browser/autocomplete/autocomplete_provider.h"
[email protected]73c2b1632012-07-02 22:51:3831#include "chrome/browser/autocomplete/autocomplete_result.h"
initial.commit09911bf2008-07-26 23:55:2932#include "chrome/browser/browser_process.h"
[email protected]24b9bb392013-01-29 20:29:2933#include "chrome/browser/google/google_util.h"
[email protected]0fafc8d2013-06-01 00:09:5034#include "chrome/browser/omnibox/omnibox_log.h"
[email protected]0f5e57f52012-09-20 20:53:1835#include "chrome/browser/plugins/plugin_prefs.h"
[email protected]10084982011-08-19 17:56:5636#include "chrome/browser/profiles/profile_manager.h"
[email protected]1eeb5e02010-07-20 23:02:1137#include "chrome/common/chrome_version_info.h"
initial.commit09911bf2008-07-26 23:55:2938#include "chrome/common/logging_chrome.h"
[email protected]fe58acc22012-02-29 01:29:5839#include "chrome/common/metrics/proto/omnibox_event.pb.h"
[email protected]ed0fd002012-04-25 23:10:3440#include "chrome/common/metrics/proto/profiler_event.pb.h"
[email protected]fe58acc22012-02-29 01:29:5841#include "chrome/common/metrics/proto/system_profile.pb.h"
[email protected]cf265dc02012-08-15 01:01:1642#include "chrome/common/metrics/variations/variations_util.h"
initial.commit09911bf2008-07-26 23:55:2943#include "chrome/common/pref_names.h"
[email protected]197c0772012-05-14 23:50:5144#include "chrome/installer/util/google_update_settings.h"
[email protected]d5d383252013-07-04 14:44:3245#include "components/nacl/common/nacl_process_type.h"
[email protected]79078df2012-02-16 01:22:3246#include "content/public/browser/gpu_data_manager.h"
[email protected]1a838cc2012-04-24 22:06:4947#include "content/public/common/content_client.h"
[email protected]d7bd3e52013-07-21 04:29:2048#include "content/public/common/webplugininfo.h"
[email protected]611ae29a2013-04-29 21:32:1949#include "device/bluetooth/bluetooth_adapter.h"
50#include "device/bluetooth/bluetooth_adapter_factory.h"
51#include "device/bluetooth/bluetooth_device.h"
[email protected]d7b5cc72013-05-23 20:05:0052#include "gpu/config/gpu_info.h"
[email protected]6b7d954ff2011-10-25 00:39:3553#include "ui/gfx/screen.h"
[email protected]761fa4702013-07-02 15:25:1554#include "url/gurl.h"
initial.commit09911bf2008-07-26 23:55:2955
[email protected]5106b3a2012-10-03 20:10:4456#if defined(OS_ANDROID)
57#include "base/android/build_info.h"
58#endif
59
[email protected]d1be67b2008-11-19 20:28:3860#if defined(OS_WIN)
[email protected]1bb25e02012-08-03 22:39:3961#include "base/win/metro.h"
62
63// http://blogs.msdn.com/oldnewthing/archive/2004/10/25/247180.aspx
[email protected]d1be67b2008-11-19 20:28:3864extern "C" IMAGE_DOS_HEADER __ImageBase;
65#endif
66
[email protected]afc03f02013-10-11 06:01:3567#if defined(OS_CHROMEOS)
68#include "chrome/browser/chromeos/login/user_manager.h"
69#endif
70
[email protected]79078df2012-02-16 01:22:3271using content::GpuDataManager;
[email protected]fe58acc22012-02-29 01:29:5872using metrics::OmniboxEventProto;
[email protected]f65859e2013-02-04 20:00:2573using metrics::PerfDataProto;
[email protected]ed0fd002012-04-25 23:10:3474using metrics::ProfilerEventProto;
[email protected]fe58acc22012-02-29 01:29:5875using metrics::SystemProfileProto;
[email protected]ed0fd002012-04-25 23:10:3476using tracked_objects::ProcessDataSnapshot;
[email protected]0c8b7ad2012-11-06 07:08:1477typedef chrome_variations::ActiveGroupId ActiveGroupId;
[email protected]197c0772012-05-14 23:50:5178typedef SystemProfileProto::GoogleUpdate::ProductInfo ProductInfo;
[email protected]611ae29a2013-04-29 21:32:1979typedef SystemProfileProto::Hardware::Bluetooth::PairedDevice PairedDevice;
[email protected]79078df2012-02-16 01:22:3280
[email protected]1df44b72012-01-19 05:20:3481namespace {
82
83// Returns the date at which the current metrics client ID was created as
[email protected]ca5ac4b2012-12-14 07:46:4084// a string containing seconds since the epoch, or "0" if none was found.
[email protected]cc5d7f42012-10-30 00:30:0985std::string GetMetricsEnabledDate(PrefService* pref) {
[email protected]767c9d92012-03-02 16:04:3486 if (!pref) {
[email protected]1df44b72012-01-19 05:20:3487 NOTREACHED();
88 return "0";
89 }
[email protected]767c9d92012-03-02 16:04:3490
91 return pref->GetString(prefs::kMetricsClientIDTimestamp);
[email protected]1df44b72012-01-19 05:20:3492}
93
[email protected]fe58acc22012-02-29 01:29:5894OmniboxEventProto::InputType AsOmniboxEventInputType(
95 AutocompleteInput::Type type) {
96 switch (type) {
97 case AutocompleteInput::INVALID:
98 return OmniboxEventProto::INVALID;
99 case AutocompleteInput::UNKNOWN:
100 return OmniboxEventProto::UNKNOWN;
[email protected]fe58acc22012-02-29 01:29:58101 case AutocompleteInput::URL:
102 return OmniboxEventProto::URL;
103 case AutocompleteInput::QUERY:
104 return OmniboxEventProto::QUERY;
105 case AutocompleteInput::FORCED_QUERY:
106 return OmniboxEventProto::FORCED_QUERY;
107 default:
108 NOTREACHED();
109 return OmniboxEventProto::INVALID;
110 }
111}
112
[email protected]fe58acc22012-02-29 01:29:58113OmniboxEventProto::Suggestion::ResultType AsOmniboxEventResultType(
114 AutocompleteMatch::Type type) {
115 switch (type) {
[email protected]b7f64d742013-05-21 04:04:04116 case AutocompleteMatchType::URL_WHAT_YOU_TYPED:
[email protected]fe58acc22012-02-29 01:29:58117 return OmniboxEventProto::Suggestion::URL_WHAT_YOU_TYPED;
[email protected]b7f64d742013-05-21 04:04:04118 case AutocompleteMatchType::HISTORY_URL:
[email protected]fe58acc22012-02-29 01:29:58119 return OmniboxEventProto::Suggestion::HISTORY_URL;
[email protected]b7f64d742013-05-21 04:04:04120 case AutocompleteMatchType::HISTORY_TITLE:
[email protected]fe58acc22012-02-29 01:29:58121 return OmniboxEventProto::Suggestion::HISTORY_TITLE;
[email protected]b7f64d742013-05-21 04:04:04122 case AutocompleteMatchType::HISTORY_BODY:
[email protected]fe58acc22012-02-29 01:29:58123 return OmniboxEventProto::Suggestion::HISTORY_BODY;
[email protected]b7f64d742013-05-21 04:04:04124 case AutocompleteMatchType::HISTORY_KEYWORD:
[email protected]fe58acc22012-02-29 01:29:58125 return OmniboxEventProto::Suggestion::HISTORY_KEYWORD;
[email protected]b7f64d742013-05-21 04:04:04126 case AutocompleteMatchType::NAVSUGGEST:
[email protected]fe58acc22012-02-29 01:29:58127 return OmniboxEventProto::Suggestion::NAVSUGGEST;
[email protected]b7f64d742013-05-21 04:04:04128 case AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED:
[email protected]fe58acc22012-02-29 01:29:58129 return OmniboxEventProto::Suggestion::SEARCH_WHAT_YOU_TYPED;
[email protected]b7f64d742013-05-21 04:04:04130 case AutocompleteMatchType::SEARCH_HISTORY:
[email protected]fe58acc22012-02-29 01:29:58131 return OmniboxEventProto::Suggestion::SEARCH_HISTORY;
[email protected]b7f64d742013-05-21 04:04:04132 case AutocompleteMatchType::SEARCH_SUGGEST:
[email protected]fe58acc22012-02-29 01:29:58133 return OmniboxEventProto::Suggestion::SEARCH_SUGGEST;
[email protected]2c03c06b2013-12-11 20:45:02134 case AutocompleteMatchType::SEARCH_SUGGEST_ENTITY:
135 return OmniboxEventProto::Suggestion::SEARCH_SUGGEST_ENTITY;
136 case AutocompleteMatchType::SEARCH_SUGGEST_INFINITE:
137 return OmniboxEventProto::Suggestion::SEARCH_SUGGEST_INFINITE;
138 case AutocompleteMatchType::SEARCH_SUGGEST_PERSONALIZED:
139 return OmniboxEventProto::Suggestion::SEARCH_SUGGEST_PERSONALIZED;
140 case AutocompleteMatchType::SEARCH_SUGGEST_PROFILE:
141 return OmniboxEventProto::Suggestion::SEARCH_SUGGEST_PROFILE;
[email protected]b7f64d742013-05-21 04:04:04142 case AutocompleteMatchType::SEARCH_OTHER_ENGINE:
[email protected]fe58acc22012-02-29 01:29:58143 return OmniboxEventProto::Suggestion::SEARCH_OTHER_ENGINE;
[email protected]b7f64d742013-05-21 04:04:04144 case AutocompleteMatchType::EXTENSION_APP:
[email protected]fe58acc22012-02-29 01:29:58145 return OmniboxEventProto::Suggestion::EXTENSION_APP;
[email protected]b7f64d742013-05-21 04:04:04146 case AutocompleteMatchType::CONTACT:
[email protected]dbacefb2012-09-12 03:32:06147 return OmniboxEventProto::Suggestion::CONTACT;
[email protected]b7f64d742013-05-21 04:04:04148 case AutocompleteMatchType::BOOKMARK_TITLE:
[email protected]25320602012-10-18 22:05:56149 return OmniboxEventProto::Suggestion::BOOKMARK_TITLE;
[email protected]fe58acc22012-02-29 01:29:58150 default:
151 NOTREACHED();
152 return OmniboxEventProto::Suggestion::UNKNOWN_RESULT_TYPE;
153 }
154}
155
[email protected]3c919d6a2013-07-28 18:35:52156OmniboxEventProto::PageClassification AsOmniboxEventPageClassification(
157 AutocompleteInput::PageClassification page_classification) {
158 switch (page_classification) {
159 case AutocompleteInput::INVALID_SPEC:
160 return OmniboxEventProto::INVALID_SPEC;
[email protected]12b5cd052013-11-08 20:59:37161 case AutocompleteInput::NTP:
162 return OmniboxEventProto::NTP;
[email protected]3c919d6a2013-07-28 18:35:52163 case AutocompleteInput::BLANK:
164 return OmniboxEventProto::BLANK;
[email protected]0b1a1112013-08-28 05:23:31165 case AutocompleteInput::HOME_PAGE:
166 return OmniboxEventProto::HOME_PAGE;
[email protected]3c919d6a2013-07-28 18:35:52167 case AutocompleteInput::OTHER:
168 return OmniboxEventProto::OTHER;
[email protected]3c919d6a2013-07-28 18:35:52169 case AutocompleteInput::SEARCH_RESULT_PAGE_DOING_SEARCH_TERM_REPLACEMENT:
170 return OmniboxEventProto::
171 SEARCH_RESULT_PAGE_DOING_SEARCH_TERM_REPLACEMENT;
[email protected]12b5cd052013-11-08 20:59:37172 case AutocompleteInput::INSTANT_NTP_WITH_OMNIBOX_AS_STARTING_FOCUS:
173 return OmniboxEventProto::INSTANT_NTP_WITH_OMNIBOX_AS_STARTING_FOCUS;
174 case AutocompleteInput::INSTANT_NTP_WITH_FAKEBOX_AS_STARTING_FOCUS:
175 return OmniboxEventProto::INSTANT_NTP_WITH_FAKEBOX_AS_STARTING_FOCUS;
[email protected]2328ee22013-08-08 23:00:19176 case AutocompleteInput::SEARCH_RESULT_PAGE_NO_SEARCH_TERM_REPLACEMENT:
177 return OmniboxEventProto::
178 SEARCH_RESULT_PAGE_NO_SEARCH_TERM_REPLACEMENT;
[email protected]3c919d6a2013-07-28 18:35:52179 }
180 return OmniboxEventProto::INVALID_SPEC;
181}
182
[email protected]ed0fd002012-04-25 23:10:34183ProfilerEventProto::TrackedObject::ProcessType AsProtobufProcessType(
[email protected]f3b357692013-03-22 05:16:13184 int process_type) {
[email protected]ed0fd002012-04-25 23:10:34185 switch (process_type) {
186 case content::PROCESS_TYPE_BROWSER:
187 return ProfilerEventProto::TrackedObject::BROWSER;
188 case content::PROCESS_TYPE_RENDERER:
189 return ProfilerEventProto::TrackedObject::RENDERER;
190 case content::PROCESS_TYPE_PLUGIN:
191 return ProfilerEventProto::TrackedObject::PLUGIN;
192 case content::PROCESS_TYPE_WORKER:
193 return ProfilerEventProto::TrackedObject::WORKER;
[email protected]ed0fd002012-04-25 23:10:34194 case content::PROCESS_TYPE_UTILITY:
195 return ProfilerEventProto::TrackedObject::UTILITY;
[email protected]ed0fd002012-04-25 23:10:34196 case content::PROCESS_TYPE_ZYGOTE:
197 return ProfilerEventProto::TrackedObject::ZYGOTE;
198 case content::PROCESS_TYPE_SANDBOX_HELPER:
199 return ProfilerEventProto::TrackedObject::SANDBOX_HELPER;
[email protected]ed0fd002012-04-25 23:10:34200 case content::PROCESS_TYPE_GPU:
201 return ProfilerEventProto::TrackedObject::GPU;
202 case content::PROCESS_TYPE_PPAPI_PLUGIN:
203 return ProfilerEventProto::TrackedObject::PPAPI_PLUGIN;
204 case content::PROCESS_TYPE_PPAPI_BROKER:
205 return ProfilerEventProto::TrackedObject::PPAPI_BROKER;
[email protected]f3b357692013-03-22 05:16:13206 case PROCESS_TYPE_NACL_LOADER:
207 return ProfilerEventProto::TrackedObject::NACL_LOADER;
208 case PROCESS_TYPE_NACL_BROKER:
209 return ProfilerEventProto::TrackedObject::NACL_BROKER;
[email protected]ed0fd002012-04-25 23:10:34210 default:
211 NOTREACHED();
212 return ProfilerEventProto::TrackedObject::UNKNOWN;
213 }
214}
215
[email protected]0f2f7792013-11-28 16:09:14216// Computes a SHA-1 hash of |data| and returns it as a hex string.
217std::string ComputeSHA1(const std::string& data) {
218 const std::string sha1 = base::SHA1HashString(data);
219 return base::HexEncode(sha1.data(), sha1.size());
220}
221
[email protected]1d51882f2013-11-12 01:59:02222#if defined(ENABLE_PLUGINS)
[email protected]1df44b72012-01-19 05:20:34223// Returns the plugin preferences corresponding for this user, if available.
224// If multiple user profiles are loaded, returns the preferences corresponding
225// to an arbitrary one of the profiles.
226PluginPrefs* GetPluginPrefs() {
227 ProfileManager* profile_manager = g_browser_process->profile_manager();
[email protected]fe58acc22012-02-29 01:29:58228
229 if (!profile_manager) {
230 // The profile manager can be NULL when testing.
231 return NULL;
232 }
233
[email protected]1df44b72012-01-19 05:20:34234 std::vector<Profile*> profiles = profile_manager->GetLoadedProfiles();
235 if (profiles.empty())
236 return NULL;
237
[email protected]cadac622013-06-11 16:46:36238 return PluginPrefs::GetForProfile(profiles.front()).get();
[email protected]1df44b72012-01-19 05:20:34239}
240
[email protected]fe58acc22012-02-29 01:29:58241// Fills |plugin| with the info contained in |plugin_info| and |plugin_prefs|.
[email protected]d7bd3e52013-07-21 04:29:20242void SetPluginInfo(const content::WebPluginInfo& plugin_info,
[email protected]fe58acc22012-02-29 01:29:58243 const PluginPrefs* plugin_prefs,
244 SystemProfileProto::Plugin* plugin) {
245 plugin->set_name(UTF16ToUTF8(plugin_info.name));
246 plugin->set_filename(plugin_info.path.BaseName().AsUTF8Unsafe());
247 plugin->set_version(UTF16ToUTF8(plugin_info.version));
[email protected]4e3ca1c292013-09-10 01:59:19248 plugin->set_is_pepper(plugin_info.is_pepper_plugin());
[email protected]fe58acc22012-02-29 01:29:58249 if (plugin_prefs)
250 plugin->set_is_disabled(!plugin_prefs->IsPluginEnabled(plugin_info));
251}
[email protected]1d51882f2013-11-12 01:59:02252#endif // defined(ENABLE_PLUGINS)
[email protected]fe58acc22012-02-29 01:29:58253
[email protected]0c8b7ad2012-11-06 07:08:14254void WriteFieldTrials(const std::vector<ActiveGroupId>& field_trial_ids,
[email protected]767c9d92012-03-02 16:04:34255 SystemProfileProto* system_profile) {
[email protected]0c8b7ad2012-11-06 07:08:14256 for (std::vector<ActiveGroupId>::const_iterator it =
[email protected]ad2461c2012-04-27 21:11:03257 field_trial_ids.begin(); it != field_trial_ids.end(); ++it) {
[email protected]767c9d92012-03-02 16:04:34258 SystemProfileProto::FieldTrial* field_trial =
259 system_profile->add_field_trial();
260 field_trial->set_name_id(it->name);
261 field_trial->set_group_id(it->group);
262 }
263}
264
[email protected]ed0fd002012-04-25 23:10:34265void WriteProfilerData(const ProcessDataSnapshot& profiler_data,
[email protected]f3b357692013-03-22 05:16:13266 int process_type,
[email protected]ed0fd002012-04-25 23:10:34267 ProfilerEventProto* performance_profile) {
268 for (std::vector<tracked_objects::TaskSnapshot>::const_iterator it =
269 profiler_data.tasks.begin();
270 it != profiler_data.tasks.end(); ++it) {
[email protected]ed0fd002012-04-25 23:10:34271 const tracked_objects::DeathDataSnapshot& death_data = it->death_data;
272 ProfilerEventProto::TrackedObject* tracked_object =
273 performance_profile->add_tracked_object();
[email protected]db7fec832013-07-18 09:41:41274 tracked_object->set_birth_thread_name_hash(
275 MetricsLogBase::Hash(it->birth.thread_name));
276 tracked_object->set_exec_thread_name_hash(
277 MetricsLogBase::Hash(it->death_thread_name));
278 tracked_object->set_source_file_name_hash(
279 MetricsLogBase::Hash(it->birth.location.file_name));
280 tracked_object->set_source_function_name_hash(
281 MetricsLogBase::Hash(it->birth.location.function_name));
[email protected]ed0fd002012-04-25 23:10:34282 tracked_object->set_source_line_number(it->birth.location.line_number);
283 tracked_object->set_exec_count(death_data.count);
284 tracked_object->set_exec_time_total(death_data.run_duration_sum);
285 tracked_object->set_exec_time_sampled(death_data.run_duration_sample);
286 tracked_object->set_queue_time_total(death_data.queue_duration_sum);
287 tracked_object->set_queue_time_sampled(death_data.queue_duration_sample);
288 tracked_object->set_process_type(AsProtobufProcessType(process_type));
289 tracked_object->set_process_id(profiler_data.process_id);
290 }
291}
292
[email protected]59a7ae4e2012-10-01 23:54:44293#if defined(GOOGLE_CHROME_BUILD) && defined(OS_WIN)
[email protected]197c0772012-05-14 23:50:51294void ProductDataToProto(const GoogleUpdateSettings::ProductData& product_data,
295 ProductInfo* product_info) {
296 product_info->set_version(product_data.version);
297 product_info->set_last_update_success_timestamp(
298 product_data.last_success.ToTimeT());
299 product_info->set_last_error(product_data.last_error_code);
300 product_info->set_last_extra_error(product_data.last_extra_code);
301 if (ProductInfo::InstallResult_IsValid(product_data.last_result)) {
302 product_info->set_last_result(
303 static_cast<ProductInfo::InstallResult>(product_data.last_result));
304 }
305}
[email protected]59a7ae4e2012-10-01 23:54:44306#endif
[email protected]197c0772012-05-14 23:50:51307
[email protected]76869ff2013-01-15 16:13:47308#if defined(OS_WIN)
[email protected]ffaf7322013-05-15 00:26:11309struct ScreenDPIInformation {
[email protected]76869ff2013-01-15 16:13:47310 double max_dpi_x;
311 double max_dpi_y;
312};
313
314// Called once for each connected monitor.
315BOOL CALLBACK GetMonitorDPICallback(HMONITOR, HDC hdc, LPRECT, LPARAM dwData) {
316 const double kMillimetersPerInch = 25.4;
317 ScreenDPIInformation* screen_info =
318 reinterpret_cast<ScreenDPIInformation*>(dwData);
319 // Size of screen, in mm.
320 DWORD size_x = GetDeviceCaps(hdc, HORZSIZE);
321 DWORD size_y = GetDeviceCaps(hdc, VERTSIZE);
322 double dpi_x = (size_x > 0) ?
323 GetDeviceCaps(hdc, HORZRES) / (size_x / kMillimetersPerInch) : 0;
324 double dpi_y = (size_y > 0) ?
325 GetDeviceCaps(hdc, VERTRES) / (size_y / kMillimetersPerInch) : 0;
326 screen_info->max_dpi_x = std::max(dpi_x, screen_info->max_dpi_x);
327 screen_info->max_dpi_y = std::max(dpi_y, screen_info->max_dpi_y);
328 return TRUE;
329}
330
331void WriteScreenDPIInformationProto(SystemProfileProto::Hardware* hardware) {
332 HDC desktop_dc = GetDC(NULL);
333 if (desktop_dc) {
[email protected]ffaf7322013-05-15 00:26:11334 ScreenDPIInformation si = {0, 0};
[email protected]76869ff2013-01-15 16:13:47335 if (EnumDisplayMonitors(desktop_dc, NULL, GetMonitorDPICallback,
336 reinterpret_cast<LPARAM>(&si))) {
337 hardware->set_max_dpi_x(si.max_dpi_x);
338 hardware->set_max_dpi_y(si.max_dpi_y);
339 }
340 ReleaseDC(GetDesktopWindow(), desktop_dc);
341 }
342}
343
344#endif // defined(OS_WIN)
345
[email protected]611ae29a2013-04-29 21:32:19346#if defined(OS_CHROMEOS)
347PairedDevice::Type AsBluetoothDeviceType(
348 enum device::BluetoothDevice::DeviceType device_type) {
349 switch (device_type) {
350 case device::BluetoothDevice::DEVICE_UNKNOWN:
351 return PairedDevice::DEVICE_UNKNOWN;
352 case device::BluetoothDevice::DEVICE_COMPUTER:
353 return PairedDevice::DEVICE_COMPUTER;
354 case device::BluetoothDevice::DEVICE_PHONE:
355 return PairedDevice::DEVICE_PHONE;
356 case device::BluetoothDevice::DEVICE_MODEM:
357 return PairedDevice::DEVICE_MODEM;
358 case device::BluetoothDevice::DEVICE_AUDIO:
359 return PairedDevice::DEVICE_AUDIO;
360 case device::BluetoothDevice::DEVICE_CAR_AUDIO:
361 return PairedDevice::DEVICE_CAR_AUDIO;
362 case device::BluetoothDevice::DEVICE_VIDEO:
363 return PairedDevice::DEVICE_VIDEO;
364 case device::BluetoothDevice::DEVICE_PERIPHERAL:
365 return PairedDevice::DEVICE_PERIPHERAL;
366 case device::BluetoothDevice::DEVICE_JOYSTICK:
367 return PairedDevice::DEVICE_JOYSTICK;
368 case device::BluetoothDevice::DEVICE_GAMEPAD:
369 return PairedDevice::DEVICE_GAMEPAD;
370 case device::BluetoothDevice::DEVICE_KEYBOARD:
371 return PairedDevice::DEVICE_KEYBOARD;
372 case device::BluetoothDevice::DEVICE_MOUSE:
373 return PairedDevice::DEVICE_MOUSE;
374 case device::BluetoothDevice::DEVICE_TABLET:
375 return PairedDevice::DEVICE_TABLET;
376 case device::BluetoothDevice::DEVICE_KEYBOARD_MOUSE_COMBO:
377 return PairedDevice::DEVICE_KEYBOARD_MOUSE_COMBO;
378 }
379
380 NOTREACHED();
381 return PairedDevice::DEVICE_UNKNOWN;
382}
383#endif // defined(OS_CHROMEOS)
384
[email protected]86573d12013-07-11 19:48:32385// Round a timestamp measured in seconds since epoch to one with a granularity
386// of an hour. This can be used before uploaded potentially sensitive
387// timestamps.
388int64 RoundSecondsToHour(int64 time_in_seconds) {
389 return 3600 * (time_in_seconds / 3600);
390}
391
[email protected]1df44b72012-01-19 05:20:34392} // namespace
393
[email protected]197c0772012-05-14 23:50:51394GoogleUpdateMetrics::GoogleUpdateMetrics() : is_system_install(false) {}
395
396GoogleUpdateMetrics::~GoogleUpdateMetrics() {}
397
[email protected]67f92bc32012-01-26 01:56:19398static base::LazyInstance<std::string>::Leaky
[email protected]0f2f7792013-11-28 16:09:14399 g_version_extension = LAZY_INSTANCE_INITIALIZER;
[email protected]054c8012011-11-16 00:12:42400
[email protected]1226abb2010-06-10 18:01:28401MetricsLog::MetricsLog(const std::string& client_id, int session_id)
[email protected]60677562013-11-17 15:52:55402 : MetricsLogBase(client_id, session_id, MetricsLog::GetVersionString()),
403 creation_time_(base::TimeTicks::Now()) {
[email protected]afc03f02013-10-11 06:01:35404#if defined(OS_CHROMEOS)
405 UpdateMultiProfileUserCount();
406#endif
407}
[email protected]5ed7d4572009-12-23 17:42:41408
[email protected]1226abb2010-06-10 18:01:28409MetricsLog::~MetricsLog() {}
initial.commit09911bf2008-07-26 23:55:29410
411// static
[email protected]b1de2c72013-02-06 02:45:47412void MetricsLog::RegisterPrefs(PrefRegistrySimple* registry) {
413 registry->RegisterListPref(prefs::kStabilityPluginStats);
initial.commit09911bf2008-07-26 23:55:29414}
415
[email protected]1df44b72012-01-19 05:20:34416// static
[email protected]1226abb2010-06-10 18:01:28417std::string MetricsLog::GetVersionString() {
[email protected]0211f57e2010-08-27 20:28:42418 chrome::VersionInfo version_info;
[email protected]30c91802010-12-18 00:40:17419 if (!version_info.is_valid()) {
420 NOTREACHED() << "Unable to retrieve version info.";
421 return std::string();
422 }
423
[email protected]0211f57e2010-08-27 20:28:42424 std::string version = version_info.Version();
[email protected]054c8012011-11-16 00:12:42425 if (!version_extension().empty())
426 version += version_extension();
[email protected]0211f57e2010-08-27 20:28:42427 if (!version_info.IsOfficialBuild())
428 version.append("-devel");
429 return version;
[email protected]1226abb2010-06-10 18:01:28430}
431
[email protected]054c8012011-11-16 00:12:42432// static
433void MetricsLog::set_version_extension(const std::string& extension) {
434 g_version_extension.Get() = extension;
435}
436
437// static
438const std::string& MetricsLog::version_extension() {
439 return g_version_extension.Get();
440}
441
[email protected]0edf8762013-11-21 18:33:30442void MetricsLog::RecordStabilityMetrics(
[email protected]0edf8762013-11-21 18:33:30443 base::TimeDelta incremental_uptime,
444 LogType log_type) {
445 DCHECK_NE(NO_LOG, log_type);
[email protected]767c9d92012-03-02 16:04:34446 DCHECK(!locked());
[email protected]0f2f7792013-11-28 16:09:14447 DCHECK(HasEnvironment());
448 DCHECK(!HasStabilityMetrics());
[email protected]0b33f80b2008-12-17 21:34:36449
[email protected]767c9d92012-03-02 16:04:34450 PrefService* pref = GetPrefService();
[email protected]0b33f80b2008-12-17 21:34:36451 DCHECK(pref);
452
initial.commit09911bf2008-07-26 23:55:29453 // Get stability attributes out of Local State, zeroing out stored values.
454 // NOTE: This could lead to some data loss if this report isn't successfully
455 // sent, but that's true for all the metrics.
456
[email protected]147bbc0b2009-01-06 19:37:40457 WriteRequiredStabilityAttributes(pref);
[email protected]250f7b662013-11-23 02:36:51458 WritePluginStabilityElements(pref);
[email protected]0edf8762013-11-21 18:33:30459
460 // Record recent delta for critical stability metrics. We can't wait for a
461 // restart to gather these, as that delay biases our observation away from
462 // users that run happily for a looooong time. We send increments with each
463 // uma log upload, just as we send histogram data.
[email protected]c68a2b9b2013-10-09 18:16:36464 WriteRealtimeStabilityAttributes(pref, incremental_uptime);
initial.commit09911bf2008-07-26 23:55:29465
[email protected]0edf8762013-11-21 18:33:30466 // Omit some stats unless this is the initial stability log.
467 if (log_type != INITIAL_LOG)
468 return;
469
[email protected]fe58acc22012-02-29 01:29:58470 int incomplete_shutdown_count =
471 pref->GetInteger(prefs::kStabilityIncompleteSessionEndCount);
[email protected]e324f6b2012-02-28 05:43:37472 pref->SetInteger(prefs::kStabilityIncompleteSessionEndCount, 0);
[email protected]fe58acc22012-02-29 01:29:58473 int breakpad_registration_success_count =
474 pref->GetInteger(prefs::kStabilityBreakpadRegistrationSuccess);
[email protected]e324f6b2012-02-28 05:43:37475 pref->SetInteger(prefs::kStabilityBreakpadRegistrationSuccess, 0);
[email protected]fe58acc22012-02-29 01:29:58476 int breakpad_registration_failure_count =
477 pref->GetInteger(prefs::kStabilityBreakpadRegistrationFail);
[email protected]e324f6b2012-02-28 05:43:37478 pref->SetInteger(prefs::kStabilityBreakpadRegistrationFail, 0);
[email protected]fe58acc22012-02-29 01:29:58479 int debugger_present_count =
480 pref->GetInteger(prefs::kStabilityDebuggerPresent);
[email protected]e324f6b2012-02-28 05:43:37481 pref->SetInteger(prefs::kStabilityDebuggerPresent, 0);
[email protected]fe58acc22012-02-29 01:29:58482 int debugger_not_present_count =
483 pref->GetInteger(prefs::kStabilityDebuggerNotPresent);
[email protected]e324f6b2012-02-28 05:43:37484 pref->SetInteger(prefs::kStabilityDebuggerNotPresent, 0);
[email protected]b2a4812d2012-02-28 05:31:31485
[email protected]fe58acc22012-02-29 01:29:58486 // TODO(jar): The following are all optional, so we *could* optimize them for
487 // values of zero (and not include them).
[email protected]fe58acc22012-02-29 01:29:58488 SystemProfileProto::Stability* stability =
[email protected]767c9d92012-03-02 16:04:34489 uma_proto()->mutable_system_profile()->mutable_stability();
[email protected]fe58acc22012-02-29 01:29:58490 stability->set_incomplete_shutdown_count(incomplete_shutdown_count);
491 stability->set_breakpad_registration_success_count(
492 breakpad_registration_success_count);
493 stability->set_breakpad_registration_failure_count(
494 breakpad_registration_failure_count);
495 stability->set_debugger_present_count(debugger_present_count);
496 stability->set_debugger_not_present_count(debugger_not_present_count);
[email protected]0edf8762013-11-21 18:33:30497}
[email protected]fe58acc22012-02-29 01:29:58498
[email protected]0edf8762013-11-21 18:33:30499PrefService* MetricsLog::GetPrefService() {
500 return g_browser_process->local_state();
501}
502
503gfx::Size MetricsLog::GetScreenSize() const {
504 return gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().GetSizeInPixel();
505}
506
507float MetricsLog::GetScreenDeviceScaleFactor() const {
508 return gfx::Screen::GetNativeScreen()->
509 GetPrimaryDisplay().device_scale_factor();
510}
511
512int MetricsLog::GetScreenCount() const {
513 // TODO(scottmg): NativeScreen maybe wrong. http://crbug.com/133312
514 return gfx::Screen::GetNativeScreen()->GetNumDisplays();
515}
516
517void MetricsLog::GetFieldTrialIds(
518 std::vector<ActiveGroupId>* field_trial_ids) const {
519 chrome_variations::GetFieldTrialActiveGroupIds(field_trial_ids);
[email protected]147bbc0b2009-01-06 19:37:40520}
521
[email protected]0f2f7792013-11-28 16:09:14522bool MetricsLog::HasEnvironment() const {
523 return uma_proto()->system_profile().has_uma_enabled_date();
524}
525
526bool MetricsLog::HasStabilityMetrics() const {
527 return uma_proto()->system_profile().stability().has_launch_count();
528}
529
[email protected]250f7b662013-11-23 02:36:51530void MetricsLog::WritePluginStabilityElements(PrefService* pref) {
[email protected]147bbc0b2009-01-06 19:37:40531 // Now log plugin stability info.
initial.commit09911bf2008-07-26 23:55:29532 const ListValue* plugin_stats_list = pref->GetList(
533 prefs::kStabilityPluginStats);
[email protected]1df44b72012-01-19 05:20:34534 if (!plugin_stats_list)
535 return;
initial.commit09911bf2008-07-26 23:55:29536
[email protected]ebd71962012-12-20 02:56:55537#if defined(ENABLE_PLUGINS)
[email protected]fe58acc22012-02-29 01:29:58538 SystemProfileProto::Stability* stability =
[email protected]767c9d92012-03-02 16:04:34539 uma_proto()->mutable_system_profile()->mutable_stability();
[email protected]1df44b72012-01-19 05:20:34540 for (ListValue::const_iterator iter = plugin_stats_list->begin();
541 iter != plugin_stats_list->end(); ++iter) {
542 if (!(*iter)->IsType(Value::TYPE_DICTIONARY)) {
543 NOTREACHED();
544 continue;
initial.commit09911bf2008-07-26 23:55:29545 }
[email protected]1df44b72012-01-19 05:20:34546 DictionaryValue* plugin_dict = static_cast<DictionaryValue*>(*iter);
initial.commit09911bf2008-07-26 23:55:29547
[email protected]fe58acc22012-02-29 01:29:58548 // Note that this search is potentially a quadratic operation, but given the
549 // low number of plugins installed on a "reasonable" setup, this should be
550 // fine.
551 // TODO(isherman): Verify that this does not show up as a hotspot in
552 // profiler runs.
[email protected]250f7b662013-11-23 02:36:51553 const SystemProfileProto::Plugin* system_profile_plugin = NULL;
[email protected]f31a01a2013-07-13 02:51:11554 std::string plugin_name;
555 plugin_dict->GetString(prefs::kStabilityPluginName, &plugin_name);
[email protected]250f7b662013-11-23 02:36:51556 const SystemProfileProto& system_profile = uma_proto()->system_profile();
557 for (int i = 0; i < system_profile.plugin_size(); ++i) {
558 if (system_profile.plugin(i).name() == plugin_name) {
559 system_profile_plugin = &system_profile.plugin(i);
[email protected]fe58acc22012-02-29 01:29:58560 break;
561 }
562 }
563
[email protected]250f7b662013-11-23 02:36:51564 if (!system_profile_plugin) {
[email protected]fe58acc22012-02-29 01:29:58565 NOTREACHED();
566 continue;
567 }
[email protected]fe58acc22012-02-29 01:29:58568
[email protected]fe58acc22012-02-29 01:29:58569 SystemProfileProto::Stability::PluginStability* plugin_stability =
570 stability->add_plugin_stability();
[email protected]250f7b662013-11-23 02:36:51571 *plugin_stability->mutable_plugin() = *system_profile_plugin;
[email protected]f31a01a2013-07-13 02:51:11572
573 int launches = 0;
574 plugin_dict->GetInteger(prefs::kStabilityPluginLaunches, &launches);
575 if (launches > 0)
576 plugin_stability->set_launch_count(launches);
577
578 int instances = 0;
579 plugin_dict->GetInteger(prefs::kStabilityPluginInstances, &instances);
580 if (instances > 0)
581 plugin_stability->set_instance_count(instances);
582
583 int crashes = 0;
584 plugin_dict->GetInteger(prefs::kStabilityPluginCrashes, &crashes);
585 if (crashes > 0)
586 plugin_stability->set_crash_count(crashes);
587
588 int loading_errors = 0;
589 plugin_dict->GetInteger(prefs::kStabilityPluginLoadingErrors,
590 &loading_errors);
591 if (loading_errors > 0)
592 plugin_stability->set_loading_error_count(loading_errors);
initial.commit09911bf2008-07-26 23:55:29593 }
[email protected]ebd71962012-12-20 02:56:55594#endif // defined(ENABLE_PLUGINS)
[email protected]1df44b72012-01-19 05:20:34595
596 pref->ClearPref(prefs::kStabilityPluginStats);
initial.commit09911bf2008-07-26 23:55:29597}
598
[email protected]fe58acc22012-02-29 01:29:58599// The server refuses data that doesn't have certain values. crashcount and
600// launchcount are currently "required" in the "stability" group.
601// TODO(isherman): Stop writing these attributes specially once the migration to
602// protobufs is complete.
[email protected]147bbc0b2009-01-06 19:37:40603void MetricsLog::WriteRequiredStabilityAttributes(PrefService* pref) {
[email protected]fe58acc22012-02-29 01:29:58604 int launch_count = pref->GetInteger(prefs::kStabilityLaunchCount);
[email protected]0b33f80b2008-12-17 21:34:36605 pref->SetInteger(prefs::kStabilityLaunchCount, 0);
[email protected]fe58acc22012-02-29 01:29:58606 int crash_count = pref->GetInteger(prefs::kStabilityCrashCount);
[email protected]0b33f80b2008-12-17 21:34:36607 pref->SetInteger(prefs::kStabilityCrashCount, 0);
[email protected]fe58acc22012-02-29 01:29:58608
[email protected]fe58acc22012-02-29 01:29:58609 SystemProfileProto::Stability* stability =
[email protected]767c9d92012-03-02 16:04:34610 uma_proto()->mutable_system_profile()->mutable_stability();
[email protected]fe58acc22012-02-29 01:29:58611 stability->set_launch_count(launch_count);
612 stability->set_crash_count(crash_count);
[email protected]0b33f80b2008-12-17 21:34:36613}
614
[email protected]c68a2b9b2013-10-09 18:16:36615void MetricsLog::WriteRealtimeStabilityAttributes(
616 PrefService* pref,
617 base::TimeDelta incremental_uptime) {
[email protected]0b33f80b2008-12-17 21:34:36618 // Update the stats which are critical for real-time stability monitoring.
619 // Since these are "optional," only list ones that are non-zero, as the counts
[email protected]250f7b662013-11-23 02:36:51620 // are aggregated (summed) server side.
[email protected]0b33f80b2008-12-17 21:34:36621
[email protected]fe58acc22012-02-29 01:29:58622 SystemProfileProto::Stability* stability =
[email protected]767c9d92012-03-02 16:04:34623 uma_proto()->mutable_system_profile()->mutable_stability();
[email protected]0b33f80b2008-12-17 21:34:36624 int count = pref->GetInteger(prefs::kStabilityPageLoadCount);
625 if (count) {
[email protected]fe58acc22012-02-29 01:29:58626 stability->set_page_load_count(count);
[email protected]0b33f80b2008-12-17 21:34:36627 pref->SetInteger(prefs::kStabilityPageLoadCount, 0);
628 }
629
630 count = pref->GetInteger(prefs::kStabilityRendererCrashCount);
631 if (count) {
[email protected]fe58acc22012-02-29 01:29:58632 stability->set_renderer_crash_count(count);
[email protected]0b33f80b2008-12-17 21:34:36633 pref->SetInteger(prefs::kStabilityRendererCrashCount, 0);
634 }
635
[email protected]1f085622009-12-04 05:33:45636 count = pref->GetInteger(prefs::kStabilityExtensionRendererCrashCount);
637 if (count) {
[email protected]fe58acc22012-02-29 01:29:58638 stability->set_extension_renderer_crash_count(count);
[email protected]1f085622009-12-04 05:33:45639 pref->SetInteger(prefs::kStabilityExtensionRendererCrashCount, 0);
640 }
641
[email protected]0b33f80b2008-12-17 21:34:36642 count = pref->GetInteger(prefs::kStabilityRendererHangCount);
643 if (count) {
[email protected]fe58acc22012-02-29 01:29:58644 stability->set_renderer_hang_count(count);
[email protected]0b33f80b2008-12-17 21:34:36645 pref->SetInteger(prefs::kStabilityRendererHangCount, 0);
646 }
[email protected]1f085622009-12-04 05:33:45647
648 count = pref->GetInteger(prefs::kStabilityChildProcessCrashCount);
649 if (count) {
[email protected]fe58acc22012-02-29 01:29:58650 stability->set_child_process_crash_count(count);
[email protected]1f085622009-12-04 05:33:45651 pref->SetInteger(prefs::kStabilityChildProcessCrashCount, 0);
652 }
[email protected]9165f742010-03-10 22:55:01653
[email protected]c1834a92011-01-21 18:21:03654#if defined(OS_CHROMEOS)
655 count = pref->GetInteger(prefs::kStabilityOtherUserCrashCount);
656 if (count) {
[email protected]fe58acc22012-02-29 01:29:58657 stability->set_other_user_crash_count(count);
[email protected]c1834a92011-01-21 18:21:03658 pref->SetInteger(prefs::kStabilityOtherUserCrashCount, 0);
659 }
660
661 count = pref->GetInteger(prefs::kStabilityKernelCrashCount);
662 if (count) {
[email protected]fe58acc22012-02-29 01:29:58663 stability->set_kernel_crash_count(count);
[email protected]c1834a92011-01-21 18:21:03664 pref->SetInteger(prefs::kStabilityKernelCrashCount, 0);
665 }
666
667 count = pref->GetInteger(prefs::kStabilitySystemUncleanShutdownCount);
668 if (count) {
[email protected]fe58acc22012-02-29 01:29:58669 stability->set_unclean_system_shutdown_count(count);
[email protected]c1834a92011-01-21 18:21:03670 pref->SetInteger(prefs::kStabilitySystemUncleanShutdownCount, 0);
671 }
672#endif // OS_CHROMEOS
673
[email protected]c68a2b9b2013-10-09 18:16:36674 const uint64 uptime_sec = incremental_uptime.InSeconds();
675 if (uptime_sec)
676 stability->set_uptime_sec(uptime_sec);
[email protected]0b33f80b2008-12-17 21:34:36677}
678
initial.commit09911bf2008-07-26 23:55:29679void MetricsLog::WritePluginList(
[email protected]d7bd3e52013-07-21 04:29:20680 const std::vector<content::WebPluginInfo>& plugin_list) {
[email protected]767c9d92012-03-02 16:04:34681 DCHECK(!locked());
initial.commit09911bf2008-07-26 23:55:29682
[email protected]ebd71962012-12-20 02:56:55683#if defined(ENABLE_PLUGINS)
684 PluginPrefs* plugin_prefs = GetPluginPrefs();
[email protected]767c9d92012-03-02 16:04:34685 SystemProfileProto* system_profile = uma_proto()->mutable_system_profile();
[email protected]d7bd3e52013-07-21 04:29:20686 for (std::vector<content::WebPluginInfo>::const_iterator iter =
[email protected]191eb3f72010-12-21 06:27:50687 plugin_list.begin();
initial.commit09911bf2008-07-26 23:55:29688 iter != plugin_list.end(); ++iter) {
[email protected]0eecc2542013-06-23 04:22:02689 SystemProfileProto::Plugin* plugin = system_profile->add_plugin();
690 SetPluginInfo(*iter, plugin_prefs, plugin);
initial.commit09911bf2008-07-26 23:55:29691 }
[email protected]ebd71962012-12-20 02:56:55692#endif // defined(ENABLE_PLUGINS)
initial.commit09911bf2008-07-26 23:55:29693}
694
initial.commit09911bf2008-07-26 23:55:29695void MetricsLog::RecordEnvironment(
[email protected]c68a2b9b2013-10-09 18:16:36696 const std::vector<content::WebPluginInfo>& plugin_list,
697 const GoogleUpdateMetrics& google_update_metrics,
[email protected]60677562013-11-17 15:52:55698 const std::vector<chrome_variations::ActiveGroupId>& synthetic_trials) {
[email protected]0f2f7792013-11-28 16:09:14699 DCHECK(!HasEnvironment());
700
[email protected]bc66d532012-03-23 01:57:05701 SystemProfileProto* system_profile = uma_proto()->mutable_system_profile();
[email protected]24b9bb392013-01-29 20:29:29702
703 std::string brand_code;
704 if (google_util::GetBrand(&brand_code))
705 system_profile->set_brand_code(brand_code);
706
[email protected]cc5d7f42012-10-30 00:30:09707 int enabled_date;
708 bool success = base::StringToInt(GetMetricsEnabledDate(GetPrefService()),
709 &enabled_date);
[email protected]bc66d532012-03-23 01:57:05710 DCHECK(success);
[email protected]86573d12013-07-11 19:48:32711
712 // Reduce granularity of the enabled_date field to nearest hour.
713 system_profile->set_uma_enabled_date(RoundSecondsToHour(enabled_date));
714
715 int64 install_date = GetPrefService()->GetInt64(prefs::kInstallDate);
716
717 // Reduce granularity of the install_date field to nearest hour.
718 system_profile->set_install_date(RoundSecondsToHour(install_date));
[email protected]bc66d532012-03-23 01:57:05719
720 system_profile->set_application_locale(
[email protected]eabbfb12013-04-05 23:28:35721 g_browser_process->GetApplicationLocale());
[email protected]bc66d532012-03-23 01:57:05722
723 SystemProfileProto::Hardware* hardware = system_profile->mutable_hardware();
[email protected]0b6a4fb2012-10-16 01:58:21724 hardware->set_cpu_architecture(base::SysInfo::OperatingSystemArchitecture());
[email protected]bc66d532012-03-23 01:57:05725 hardware->set_system_ram_mb(base::SysInfo::AmountOfPhysicalMemoryMB());
726#if defined(OS_WIN)
727 hardware->set_dll_base(reinterpret_cast<uint64>(&__ImageBase));
728#endif
729
[email protected]74b299e2013-01-29 01:24:42730 SystemProfileProto::Network* network = system_profile->mutable_network();
731 network->set_connection_type_is_ambiguous(
[email protected]5eae204c2013-02-13 15:53:42732 network_observer_.connection_type_is_ambiguous());
733 network->set_connection_type(network_observer_.connection_type());
734 network->set_wifi_phy_layer_protocol_is_ambiguous(
735 network_observer_.wifi_phy_layer_protocol_is_ambiguous());
736 network->set_wifi_phy_layer_protocol(
737 network_observer_.wifi_phy_layer_protocol());
738 network_observer_.Reset();
[email protected]74b299e2013-01-29 01:24:42739
[email protected]bc66d532012-03-23 01:57:05740 SystemProfileProto::OS* os = system_profile->mutable_os();
[email protected]1bb25e02012-08-03 22:39:39741 std::string os_name = base::SysInfo::OperatingSystemName();
742#if defined(OS_WIN)
743 // TODO(mad): This only checks whether the main process is a Metro process at
744 // upload time; not whether the collected metrics were all gathered from
745 // Metro. This is ok as an approximation for now, since users will rarely be
746 // switching from Metro to Desktop mode; but we should re-evaluate whether we
747 // can distinguish metrics more cleanly in the future: http://crbug.com/140568
748 if (base::win::IsMetroProcess())
749 os_name += " (Metro)";
750#endif
751 os->set_name(os_name);
[email protected]bc66d532012-03-23 01:57:05752 os->set_version(base::SysInfo::OperatingSystemVersion());
[email protected]5106b3a2012-10-03 20:10:44753#if defined(OS_ANDROID)
754 os->set_fingerprint(
755 base::android::BuildInfo::GetInstance()->android_build_fp());
756#endif
[email protected]bc66d532012-03-23 01:57:05757
[email protected]5c8f89f692013-07-18 11:13:28758 base::CPU cpu_info;
759 SystemProfileProto::Hardware::CPU* cpu = hardware->mutable_cpu();
760 cpu->set_vendor_name(cpu_info.vendor_name());
761 cpu->set_signature(cpu_info.signature());
762
[email protected]d7b5cc72013-05-23 20:05:00763 const gpu::GPUInfo& gpu_info =
[email protected]bc66d532012-03-23 01:57:05764 GpuDataManager::GetInstance()->GetGPUInfo();
765 SystemProfileProto::Hardware::Graphics* gpu = hardware->mutable_gpu();
[email protected]a094e2c2012-05-10 23:02:42766 gpu->set_vendor_id(gpu_info.gpu.vendor_id);
767 gpu->set_device_id(gpu_info.gpu.device_id);
[email protected]bc66d532012-03-23 01:57:05768 gpu->set_driver_version(gpu_info.driver_version);
769 gpu->set_driver_date(gpu_info.driver_date);
770 SystemProfileProto::Hardware::Graphics::PerformanceStatistics*
771 gpu_performance = gpu->mutable_performance_statistics();
772 gpu_performance->set_graphics_score(gpu_info.performance_stats.graphics);
773 gpu_performance->set_gaming_score(gpu_info.performance_stats.gaming);
774 gpu_performance->set_overall_score(gpu_info.performance_stats.overall);
[email protected]d6bdfae2013-01-18 20:23:01775 gpu->set_gl_vendor(gpu_info.gl_vendor);
776 gpu->set_gl_renderer(gpu_info.gl_renderer);
[email protected]bc66d532012-03-23 01:57:05777
778 const gfx::Size display_size = GetScreenSize();
779 hardware->set_primary_screen_width(display_size.width());
780 hardware->set_primary_screen_height(display_size.height());
[email protected]aa96417972012-08-22 03:16:44781 hardware->set_primary_screen_scale_factor(GetScreenDeviceScaleFactor());
[email protected]bc66d532012-03-23 01:57:05782 hardware->set_screen_count(GetScreenCount());
783
[email protected]76869ff2013-01-15 16:13:47784#if defined(OS_WIN)
785 WriteScreenDPIInformationProto(hardware);
786#endif
787
[email protected]197c0772012-05-14 23:50:51788 WriteGoogleUpdateProto(google_update_metrics);
789
[email protected]0eecc2542013-06-23 04:22:02790 WritePluginList(plugin_list);
[email protected]bc66d532012-03-23 01:57:05791
[email protected]0c8b7ad2012-11-06 07:08:14792 std::vector<ActiveGroupId> field_trial_ids;
[email protected]767c9d92012-03-02 16:04:34793 GetFieldTrialIds(&field_trial_ids);
794 WriteFieldTrials(field_trial_ids, system_profile);
[email protected]60677562013-11-17 15:52:55795 WriteFieldTrials(synthetic_trials, system_profile);
[email protected]f65859e2013-02-04 20:00:25796
797#if defined(OS_CHROMEOS)
798 PerfDataProto perf_data_proto;
799 if (perf_provider_.GetPerfData(&perf_data_proto))
800 uma_proto()->add_perf_data()->Swap(&perf_data_proto);
[email protected]611ae29a2013-04-29 21:32:19801
802 // BluetoothAdapterFactory::GetAdapter is synchronous on Chrome OS; if that
803 // changes this will fail at the DCHECK().
804 device::BluetoothAdapterFactory::GetAdapter(
805 base::Bind(&MetricsLog::SetBluetoothAdapter,
806 base::Unretained(this)));
807 DCHECK(adapter_.get());
808 WriteBluetoothProto(hardware);
[email protected]afc03f02013-10-11 06:01:35809 UpdateMultiProfileUserCount();
[email protected]f65859e2013-02-04 20:00:25810#endif
[email protected]0f2f7792013-11-28 16:09:14811
812 std::string serialied_system_profile;
813 std::string base64_system_profile;
[email protected]33fca122013-12-11 01:48:50814 if (system_profile->SerializeToString(&serialied_system_profile)) {
815 base::Base64Encode(serialied_system_profile, &base64_system_profile);
[email protected]0f2f7792013-11-28 16:09:14816 PrefService* local_state = GetPrefService();
817 local_state->SetString(prefs::kStabilitySavedSystemProfile,
818 base64_system_profile);
819 local_state->SetString(prefs::kStabilitySavedSystemProfileHash,
820 ComputeSHA1(serialied_system_profile));
821 }
822}
823
824bool MetricsLog::LoadSavedEnvironmentFromPrefs() {
825 PrefService* local_state = GetPrefService();
826 const std::string base64_system_profile =
827 local_state->GetString(prefs::kStabilitySavedSystemProfile);
828 if (base64_system_profile.empty())
829 return false;
830
831 const std::string system_profile_hash =
832 local_state->GetString(prefs::kStabilitySavedSystemProfileHash);
833 local_state->ClearPref(prefs::kStabilitySavedSystemProfile);
834 local_state->ClearPref(prefs::kStabilitySavedSystemProfileHash);
835
836 SystemProfileProto* system_profile = uma_proto()->mutable_system_profile();
837 std::string serialied_system_profile;
838 return base::Base64Decode(base64_system_profile, &serialied_system_profile) &&
839 ComputeSHA1(serialied_system_profile) == system_profile_hash &&
840 system_profile->ParseFromString(serialied_system_profile);
initial.commit09911bf2008-07-26 23:55:29841}
842
[email protected]ed0fd002012-04-25 23:10:34843void MetricsLog::RecordProfilerData(
844 const tracked_objects::ProcessDataSnapshot& process_data,
[email protected]f3b357692013-03-22 05:16:13845 int process_type) {
[email protected]ed0fd002012-04-25 23:10:34846 DCHECK(!locked());
847
[email protected]8f829682012-04-27 00:36:49848 if (tracked_objects::GetTimeSourceType() !=
849 tracked_objects::TIME_SOURCE_TYPE_WALL_TIME) {
[email protected]ed0fd002012-04-25 23:10:34850 // We currently only support the default time source, wall clock time.
851 return;
852 }
853
854 ProfilerEventProto* profile;
855 if (!uma_proto()->profiler_event_size()) {
856 // For the first process's data, add a new field to the protocol buffer.
857 profile = uma_proto()->add_profiler_event();
858 profile->set_profile_type(ProfilerEventProto::STARTUP_PROFILE);
859 profile->set_time_source(ProfilerEventProto::WALL_CLOCK_TIME);
860 } else {
861 // For the remaining calls, re-use the existing field.
862 profile = uma_proto()->mutable_profiler_event(0);
863 }
864
865 WriteProfilerData(process_data, process_type, profile);
866}
867
[email protected]0fafc8d2013-06-01 00:09:50868void MetricsLog::RecordOmniboxOpenedURL(const OmniboxLog& log) {
[email protected]767c9d92012-03-02 16:04:34869 DCHECK(!locked());
initial.commit09911bf2008-07-26 23:55:29870
[email protected]8790210c2013-12-02 05:29:53871 std::vector<base::string16> terms;
[email protected]65956312012-04-19 21:28:12872 const int num_terms =
[email protected]8790210c2013-12-02 05:29:53873 static_cast<int>(Tokenize(log.text, base::kWhitespaceUTF16, &terms));
initial.commit09911bf2008-07-26 23:55:29874
[email protected]767c9d92012-03-02 16:04:34875 OmniboxEventProto* omnibox_event = uma_proto()->add_omnibox_event();
[email protected]fe58acc22012-02-29 01:29:58876 omnibox_event->set_time(MetricsLogBase::GetCurrentTime());
877 if (log.tab_id != -1) {
878 // If we know what tab the autocomplete URL was opened in, log it.
879 omnibox_event->set_tab_id(log.tab_id);
880 }
881 omnibox_event->set_typed_length(log.text.length());
[email protected]660fe8f32012-05-03 20:01:08882 omnibox_event->set_just_deleted_text(log.just_deleted_text);
[email protected]65956312012-04-19 21:28:12883 omnibox_event->set_num_typed_terms(num_terms);
[email protected]fe58acc22012-02-29 01:29:58884 omnibox_event->set_selected_index(log.selected_index);
[email protected]439f1e32013-12-09 20:09:09885 if (log.completed_length != base::string16::npos)
[email protected]62b3ef52013-01-18 00:13:02886 omnibox_event->set_completed_length(log.completed_length);
[email protected]65956312012-04-19 21:28:12887 if (log.elapsed_time_since_user_first_modified_omnibox !=
888 base::TimeDelta::FromMilliseconds(-1)) {
889 // Only upload the typing duration if it is set/valid.
890 omnibox_event->set_typing_duration_ms(
891 log.elapsed_time_since_user_first_modified_omnibox.InMilliseconds());
892 }
[email protected]35d55602012-11-20 23:49:03893 omnibox_event->set_duration_since_last_default_match_update_ms(
894 log.elapsed_time_since_last_change_to_default_match.InMilliseconds());
[email protected]ee902532012-05-01 23:54:49895 omnibox_event->set_current_page_classification(
[email protected]3c919d6a2013-07-28 18:35:52896 AsOmniboxEventPageClassification(log.current_page_classification));
[email protected]fe58acc22012-02-29 01:29:58897 omnibox_event->set_input_type(AsOmniboxEventInputType(log.input_type));
[email protected]1fce7dd42013-08-06 02:29:17898 omnibox_event->set_is_top_result_hidden_in_dropdown(
899 log.result.ShouldHideTopMatch());
[email protected]1fce7dd42013-08-06 02:29:17900
[email protected]fe58acc22012-02-29 01:29:58901 for (AutocompleteResult::const_iterator i(log.result.begin());
902 i != log.result.end(); ++i) {
903 OmniboxEventProto::Suggestion* suggestion = omnibox_event->add_suggestion();
[email protected]0e9e8782012-05-15 23:01:51904 suggestion->set_provider(i->provider->AsOmniboxEventProviderType());
[email protected]fe58acc22012-02-29 01:29:58905 suggestion->set_result_type(AsOmniboxEventResultType(i->type));
906 suggestion->set_relevance(i->relevance);
[email protected]cf6256f2012-06-12 23:36:01907 if (i->typed_count != -1)
908 suggestion->set_typed_count(i->typed_count);
[email protected]fe58acc22012-02-29 01:29:58909 suggestion->set_is_starred(i->starred);
910 }
[email protected]0e9e8782012-05-15 23:01:51911 for (ProvidersInfo::const_iterator i(log.providers_info.begin());
912 i != log.providers_info.end(); ++i) {
913 OmniboxEventProto::ProviderInfo* provider_info =
914 omnibox_event->add_provider_info();
915 provider_info->CopyFrom(*i);
916 }
[email protected]fe58acc22012-02-29 01:29:58917
initial.commit09911bf2008-07-26 23:55:29918 ++num_events_;
919}
[email protected]197c0772012-05-14 23:50:51920
921void MetricsLog::WriteGoogleUpdateProto(
922 const GoogleUpdateMetrics& google_update_metrics) {
923#if defined(GOOGLE_CHROME_BUILD) && defined(OS_WIN)
924 SystemProfileProto::GoogleUpdate* google_update =
925 uma_proto()->mutable_system_profile()->mutable_google_update();
926
927 google_update->set_is_system_install(google_update_metrics.is_system_install);
928
929 if (!google_update_metrics.last_started_au.is_null()) {
930 google_update->set_last_automatic_start_timestamp(
931 google_update_metrics.last_started_au.ToTimeT());
932 }
933
934 if (!google_update_metrics.last_checked.is_null()) {
935 google_update->set_last_update_check_timestamp(
936 google_update_metrics.last_checked.ToTimeT());
937 }
938
939 if (!google_update_metrics.google_update_data.version.empty()) {
940 ProductDataToProto(google_update_metrics.google_update_data,
941 google_update->mutable_google_update_status());
942 }
943
944 if (!google_update_metrics.product_data.version.empty()) {
945 ProductDataToProto(google_update_metrics.product_data,
946 google_update->mutable_client_status());
947 }
948#endif // defined(GOOGLE_CHROME_BUILD) && defined(OS_WIN)
949}
[email protected]611ae29a2013-04-29 21:32:19950
951void MetricsLog::SetBluetoothAdapter(
952 scoped_refptr<device::BluetoothAdapter> adapter) {
953 adapter_ = adapter;
954}
955
956void MetricsLog::WriteBluetoothProto(
957 SystemProfileProto::Hardware* hardware) {
[email protected]728f9b22013-05-02 06:08:18958#if defined(OS_CHROMEOS)
[email protected]611ae29a2013-04-29 21:32:19959 SystemProfileProto::Hardware::Bluetooth* bluetooth =
960 hardware->mutable_bluetooth();
961
962 bluetooth->set_is_present(adapter_->IsPresent());
963 bluetooth->set_is_enabled(adapter_->IsPowered());
964
965 device::BluetoothAdapter::DeviceList devices = adapter_->GetDevices();
966 for (device::BluetoothAdapter::DeviceList::iterator iter =
967 devices.begin(); iter != devices.end(); ++iter) {
968 PairedDevice* paired_device = bluetooth->add_paired_device();
969
970 device::BluetoothDevice* device = *iter;
971 paired_device->set_bluetooth_class(device->GetBluetoothClass());
972 paired_device->set_type(AsBluetoothDeviceType(device->GetDeviceType()));
973
974 // address is xx:xx:xx:xx:xx:xx, extract the first three components and
975 // pack into a uint32
976 std::string address = device->GetAddress();
977 if (address.size() > 9 &&
978 address[2] == ':' && address[5] == ':' && address[8] == ':') {
979 std::string vendor_prefix_str;
980 uint64 vendor_prefix;
981
[email protected]466c9862013-12-03 22:05:28982 base::RemoveChars(address.substr(0, 9), ":", &vendor_prefix_str);
[email protected]611ae29a2013-04-29 21:32:19983 DCHECK_EQ(6U, vendor_prefix_str.size());
984 base::HexStringToUInt64(vendor_prefix_str, &vendor_prefix);
985
986 paired_device->set_vendor_prefix(vendor_prefix);
987 }
988
989 paired_device->set_vendor_id(device->GetVendorID());
990 paired_device->set_product_id(device->GetProductID());
991 paired_device->set_device_id(device->GetDeviceID());
992 }
993#endif // defined(OS_CHROMEOS)
994}
[email protected]afc03f02013-10-11 06:01:35995
996#if defined(OS_CHROMEOS)
997void MetricsLog::UpdateMultiProfileUserCount() {
998 if (chromeos::UserManager::IsInitialized() &&
999 chromeos::UserManager::Get()->IsMultipleProfilesAllowed()) {
1000 uint32 user_count = chromeos::UserManager::Get()
1001 ->GetLoggedInUsers().size();
1002 SystemProfileProto* system_profile = uma_proto()->mutable_system_profile();
1003
1004 // We invalidate the user count if it changed while the log was open.
1005 if (system_profile->has_multi_profile_user_count() &&
1006 user_count != system_profile->multi_profile_user_count())
1007 user_count = 0;
1008
1009 system_profile->set_multi_profile_user_count(user_count);
1010 }
1011}
1012#endif