blob: 58cdfa1c312eaeb8f63e7538c4ae04dbfbff9814 [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]1eeb5e02010-07-20 23:02:117#include <string>
8#include <vector>
9
[email protected]d1be67b2008-11-19 20:28:3810#include "base/basictypes.h"
initial.commit09911bf2008-07-26 23:55:2911#include "base/file_util.h"
[email protected]054c8012011-11-16 00:12:4212#include "base/lazy_instance.h"
[email protected]3b63f8f42011-03-28 01:54:1513#include "base/memory/scoped_ptr.h"
[email protected]85ed9d42010-06-08 22:37:4414#include "base/perftimer.h"
[email protected]fe58acc22012-02-29 01:29:5815#include "base/string_number_conversions.h"
initial.commit09911bf2008-07-26 23:55:2916#include "base/string_util.h"
[email protected]fadf97f2008-09-18 12:18:1417#include "base/sys_info.h"
[email protected]37f39e42010-01-06 17:35:1718#include "base/third_party/nspr/prtime.h"
[email protected]1eeb5e02010-07-20 23:02:1119#include "base/time.h"
20#include "base/utf_string_conversions.h"
initial.commit09911bf2008-07-26 23:55:2921#include "chrome/browser/autocomplete/autocomplete.h"
[email protected]9ac40092010-10-27 23:05:2622#include "chrome/browser/autocomplete/autocomplete_match.h"
initial.commit09911bf2008-07-26 23:55:2923#include "chrome/browser/browser_process.h"
[email protected]10084982011-08-19 17:56:5624#include "chrome/browser/plugin_prefs.h"
[email protected]37858e52010-08-26 00:22:0225#include "chrome/browser/prefs/pref_service.h"
[email protected]10084982011-08-19 17:56:5626#include "chrome/browser/profiles/profile_manager.h"
[email protected]1eeb5e02010-07-20 23:02:1127#include "chrome/common/chrome_version_info.h"
initial.commit09911bf2008-07-26 23:55:2928#include "chrome/common/logging_chrome.h"
[email protected]fe58acc22012-02-29 01:29:5829#include "chrome/common/metrics/proto/omnibox_event.pb.h"
30#include "chrome/common/metrics/proto/system_profile.pb.h"
initial.commit09911bf2008-07-26 23:55:2931#include "chrome/common/pref_names.h"
[email protected]fe58acc22012-02-29 01:29:5832#include "content/public/browser/content_browser_client.h"
[email protected]79078df2012-02-16 01:22:3233#include "content/public/browser/gpu_data_manager.h"
34#include "content/public/common/gpu_info.h"
[email protected]fe58acc22012-02-29 01:29:5835#include "content/public/common/content_client.h"
[email protected]46072d42008-07-28 14:49:3536#include "googleurl/src/gurl.h"
[email protected]6b7d954ff2011-10-25 00:39:3537#include "ui/gfx/screen.h"
[email protected]91d9f3d2011-08-14 05:24:4438#include "webkit/plugins/webplugininfo.h"
initial.commit09911bf2008-07-26 23:55:2939
40#define OPEN_ELEMENT_FOR_SCOPE(name) ScopedElement scoped_element(this, name)
41
[email protected]d1be67b2008-11-19 20:28:3842// http://blogs.msdn.com/oldnewthing/archive/2004/10/25/247180.aspx
43#if defined(OS_WIN)
44extern "C" IMAGE_DOS_HEADER __ImageBase;
45#endif
46
[email protected]79078df2012-02-16 01:22:3247using content::GpuDataManager;
[email protected]fe58acc22012-02-29 01:29:5848using metrics::OmniboxEventProto;
49using metrics::SystemProfileProto;
[email protected]767c9d92012-03-02 16:04:3450typedef base::FieldTrial::NameGroupId NameGroupId;
[email protected]79078df2012-02-16 01:22:3251
[email protected]1df44b72012-01-19 05:20:3452namespace {
53
54// Returns the date at which the current metrics client ID was created as
55// a string containing milliseconds since the epoch, or "0" if none was found.
[email protected]767c9d92012-03-02 16:04:3456std::string GetInstallDate(PrefService* pref) {
57 if (!pref) {
[email protected]1df44b72012-01-19 05:20:3458 NOTREACHED();
59 return "0";
60 }
[email protected]767c9d92012-03-02 16:04:3461
62 return pref->GetString(prefs::kMetricsClientIDTimestamp);
[email protected]1df44b72012-01-19 05:20:3463}
64
[email protected]fe58acc22012-02-29 01:29:5865OmniboxEventProto::InputType AsOmniboxEventInputType(
66 AutocompleteInput::Type type) {
67 switch (type) {
68 case AutocompleteInput::INVALID:
69 return OmniboxEventProto::INVALID;
70 case AutocompleteInput::UNKNOWN:
71 return OmniboxEventProto::UNKNOWN;
72 case AutocompleteInput::REQUESTED_URL:
73 return OmniboxEventProto::REQUESTED_URL;
74 case AutocompleteInput::URL:
75 return OmniboxEventProto::URL;
76 case AutocompleteInput::QUERY:
77 return OmniboxEventProto::QUERY;
78 case AutocompleteInput::FORCED_QUERY:
79 return OmniboxEventProto::FORCED_QUERY;
80 default:
81 NOTREACHED();
82 return OmniboxEventProto::INVALID;
83 }
84}
85
86OmniboxEventProto::Suggestion::ProviderType AsOmniboxEventProviderType(
87 const AutocompleteProvider* provider) {
88 if (!provider)
89 return OmniboxEventProto::Suggestion::UNKNOWN_PROVIDER;
90
91 const std::string& name = provider->name();
92 if (name == "HistoryURL")
93 return OmniboxEventProto::Suggestion::URL;
94 if (name == "HistoryContents")
95 return OmniboxEventProto::Suggestion::HISTORY_CONTENTS;
96 if (name == "HistoryQuickProvider")
97 return OmniboxEventProto::Suggestion::HISTORY_QUICK;
98 if (name == "Search")
99 return OmniboxEventProto::Suggestion::SEARCH;
100 if (name == "Keyword")
101 return OmniboxEventProto::Suggestion::KEYWORD;
102 if (name == "Builtin")
103 return OmniboxEventProto::Suggestion::BUILTIN;
104 if (name == "ShortcutsProvider")
105 return OmniboxEventProto::Suggestion::SHORTCUTS;
106 if (name == "ExtensionApps")
107 return OmniboxEventProto::Suggestion::EXTENSION_APPS;
108
109 NOTREACHED();
110 return OmniboxEventProto::Suggestion::UNKNOWN_PROVIDER;
111}
112
113OmniboxEventProto::Suggestion::ResultType AsOmniboxEventResultType(
114 AutocompleteMatch::Type type) {
115 switch (type) {
116 case AutocompleteMatch::URL_WHAT_YOU_TYPED:
117 return OmniboxEventProto::Suggestion::URL_WHAT_YOU_TYPED;
118 case AutocompleteMatch::HISTORY_URL:
119 return OmniboxEventProto::Suggestion::HISTORY_URL;
120 case AutocompleteMatch::HISTORY_TITLE:
121 return OmniboxEventProto::Suggestion::HISTORY_TITLE;
122 case AutocompleteMatch::HISTORY_BODY:
123 return OmniboxEventProto::Suggestion::HISTORY_BODY;
124 case AutocompleteMatch::HISTORY_KEYWORD:
125 return OmniboxEventProto::Suggestion::HISTORY_KEYWORD;
126 case AutocompleteMatch::NAVSUGGEST:
127 return OmniboxEventProto::Suggestion::NAVSUGGEST;
128 case AutocompleteMatch::SEARCH_WHAT_YOU_TYPED:
129 return OmniboxEventProto::Suggestion::SEARCH_WHAT_YOU_TYPED;
130 case AutocompleteMatch::SEARCH_HISTORY:
131 return OmniboxEventProto::Suggestion::SEARCH_HISTORY;
132 case AutocompleteMatch::SEARCH_SUGGEST:
133 return OmniboxEventProto::Suggestion::SEARCH_SUGGEST;
134 case AutocompleteMatch::SEARCH_OTHER_ENGINE:
135 return OmniboxEventProto::Suggestion::SEARCH_OTHER_ENGINE;
136 case AutocompleteMatch::EXTENSION_APP:
137 return OmniboxEventProto::Suggestion::EXTENSION_APP;
138 default:
139 NOTREACHED();
140 return OmniboxEventProto::Suggestion::UNKNOWN_RESULT_TYPE;
141 }
142}
143
[email protected]1df44b72012-01-19 05:20:34144// Returns the plugin preferences corresponding for this user, if available.
145// If multiple user profiles are loaded, returns the preferences corresponding
146// to an arbitrary one of the profiles.
147PluginPrefs* GetPluginPrefs() {
148 ProfileManager* profile_manager = g_browser_process->profile_manager();
[email protected]fe58acc22012-02-29 01:29:58149
150 if (!profile_manager) {
151 // The profile manager can be NULL when testing.
152 return NULL;
153 }
154
[email protected]1df44b72012-01-19 05:20:34155 std::vector<Profile*> profiles = profile_manager->GetLoadedProfiles();
156 if (profiles.empty())
157 return NULL;
158
159 return PluginPrefs::GetForProfile(profiles.front());
160}
161
[email protected]fe58acc22012-02-29 01:29:58162// Fills |plugin| with the info contained in |plugin_info| and |plugin_prefs|.
163void SetPluginInfo(const webkit::WebPluginInfo& plugin_info,
164 const PluginPrefs* plugin_prefs,
165 SystemProfileProto::Plugin* plugin) {
166 plugin->set_name(UTF16ToUTF8(plugin_info.name));
167 plugin->set_filename(plugin_info.path.BaseName().AsUTF8Unsafe());
168 plugin->set_version(UTF16ToUTF8(plugin_info.version));
169 if (plugin_prefs)
170 plugin->set_is_disabled(!plugin_prefs->IsPluginEnabled(plugin_info));
171}
172
[email protected]767c9d92012-03-02 16:04:34173void WriteFieldTrials(const std::vector<NameGroupId>& field_trial_ids,
174 SystemProfileProto* system_profile) {
175 for (std::vector<NameGroupId>::const_iterator it = field_trial_ids.begin();
176 it != field_trial_ids.end(); ++it) {
177 SystemProfileProto::FieldTrial* field_trial =
178 system_profile->add_field_trial();
179 field_trial->set_name_id(it->name);
180 field_trial->set_group_id(it->group);
181 }
182}
183
[email protected]1df44b72012-01-19 05:20:34184} // namespace
185
[email protected]67f92bc32012-01-26 01:56:19186static base::LazyInstance<std::string>::Leaky
[email protected]054c8012011-11-16 00:12:42187 g_version_extension = LAZY_INSTANCE_INITIALIZER;
188
[email protected]1226abb2010-06-10 18:01:28189MetricsLog::MetricsLog(const std::string& client_id, int session_id)
190 : MetricsLogBase(client_id, session_id, MetricsLog::GetVersionString()) {}
[email protected]5ed7d4572009-12-23 17:42:41191
[email protected]1226abb2010-06-10 18:01:28192MetricsLog::~MetricsLog() {}
initial.commit09911bf2008-07-26 23:55:29193
194// static
195void MetricsLog::RegisterPrefs(PrefService* local_state) {
196 local_state->RegisterListPref(prefs::kStabilityPluginStats);
initial.commit09911bf2008-07-26 23:55:29197}
198
[email protected]1df44b72012-01-19 05:20:34199// static
[email protected]9165f742010-03-10 22:55:01200int64 MetricsLog::GetIncrementalUptime(PrefService* pref) {
201 base::TimeTicks now = base::TimeTicks::Now();
202 static base::TimeTicks last_updated_time(now);
203 int64 incremental_time = (now - last_updated_time).InSeconds();
204 last_updated_time = now;
205
206 if (incremental_time > 0) {
207 int64 metrics_uptime = pref->GetInt64(prefs::kUninstallMetricsUptimeSec);
208 metrics_uptime += incremental_time;
209 pref->SetInt64(prefs::kUninstallMetricsUptimeSec, metrics_uptime);
210 }
211
212 return incremental_time;
213}
214
[email protected]1226abb2010-06-10 18:01:28215// static
216std::string MetricsLog::GetVersionString() {
[email protected]0211f57e2010-08-27 20:28:42217 chrome::VersionInfo version_info;
[email protected]30c91802010-12-18 00:40:17218 if (!version_info.is_valid()) {
219 NOTREACHED() << "Unable to retrieve version info.";
220 return std::string();
221 }
222
[email protected]0211f57e2010-08-27 20:28:42223 std::string version = version_info.Version();
[email protected]054c8012011-11-16 00:12:42224 if (!version_extension().empty())
225 version += version_extension();
[email protected]0211f57e2010-08-27 20:28:42226 if (!version_info.IsOfficialBuild())
227 version.append("-devel");
228 return version;
[email protected]1226abb2010-06-10 18:01:28229}
230
[email protected]054c8012011-11-16 00:12:42231// static
232void MetricsLog::set_version_extension(const std::string& extension) {
233 g_version_extension.Get() = extension;
234}
235
236// static
237const std::string& MetricsLog::version_extension() {
238 return g_version_extension.Get();
239}
240
[email protected]fe58acc22012-02-29 01:29:58241void MetricsLog::RecordIncrementalStabilityElements(
242 const std::vector<webkit::WebPluginInfo>& plugin_list) {
[email protected]767c9d92012-03-02 16:04:34243 DCHECK(!locked());
[email protected]0b33f80b2008-12-17 21:34:36244
[email protected]767c9d92012-03-02 16:04:34245 PrefService* pref = GetPrefService();
[email protected]0b33f80b2008-12-17 21:34:36246 DCHECK(pref);
247
[email protected]147bbc0b2009-01-06 19:37:40248 OPEN_ELEMENT_FOR_SCOPE("profile");
249 WriteCommonEventAttributes();
250
[email protected]9958a322011-03-08 20:04:17251 WriteInstallElement();
[email protected]147bbc0b2009-01-06 19:37:40252
253 {
254 OPEN_ELEMENT_FOR_SCOPE("stability"); // Minimal set of stability elements.
255 WriteRequiredStabilityAttributes(pref);
256 WriteRealtimeStabilityAttributes(pref);
257
[email protected]fe58acc22012-02-29 01:29:58258 WritePluginStabilityElements(plugin_list, pref);
[email protected]147bbc0b2009-01-06 19:37:40259 }
[email protected]0b33f80b2008-12-17 21:34:36260}
261
[email protected]767c9d92012-03-02 16:04:34262PrefService* MetricsLog::GetPrefService() {
263 return g_browser_process->local_state();
264}
265
266gfx::Size MetricsLog::GetScreenSize() const {
267 return gfx::Screen::GetPrimaryMonitorSize();
268}
269
270int MetricsLog::GetScreenCount() const {
271 return gfx::Screen::GetNumMonitors();
272}
273
274
275void MetricsLog::GetFieldTrialIds(
276 std::vector<NameGroupId>* field_trial_ids) const {
277 base::FieldTrialList::GetFieldTrialNameGroupIds(field_trial_ids);
278}
279
[email protected]fe58acc22012-02-29 01:29:58280void MetricsLog::WriteStabilityElement(
281 const std::vector<webkit::WebPluginInfo>& plugin_list,
282 PrefService* pref) {
[email protected]767c9d92012-03-02 16:04:34283 DCHECK(!locked());
initial.commit09911bf2008-07-26 23:55:29284
initial.commit09911bf2008-07-26 23:55:29285 // Get stability attributes out of Local State, zeroing out stored values.
286 // NOTE: This could lead to some data loss if this report isn't successfully
287 // sent, but that's true for all the metrics.
288
[email protected]ffaf78a2008-11-12 17:38:33289 OPEN_ELEMENT_FOR_SCOPE("stability");
[email protected]147bbc0b2009-01-06 19:37:40290 WriteRequiredStabilityAttributes(pref);
291 WriteRealtimeStabilityAttributes(pref);
initial.commit09911bf2008-07-26 23:55:29292
[email protected]fe58acc22012-02-29 01:29:58293 int incomplete_shutdown_count =
294 pref->GetInteger(prefs::kStabilityIncompleteSessionEndCount);
[email protected]e324f6b2012-02-28 05:43:37295 pref->SetInteger(prefs::kStabilityIncompleteSessionEndCount, 0);
[email protected]fe58acc22012-02-29 01:29:58296 int breakpad_registration_success_count =
297 pref->GetInteger(prefs::kStabilityBreakpadRegistrationSuccess);
[email protected]e324f6b2012-02-28 05:43:37298 pref->SetInteger(prefs::kStabilityBreakpadRegistrationSuccess, 0);
[email protected]fe58acc22012-02-29 01:29:58299 int breakpad_registration_failure_count =
300 pref->GetInteger(prefs::kStabilityBreakpadRegistrationFail);
[email protected]e324f6b2012-02-28 05:43:37301 pref->SetInteger(prefs::kStabilityBreakpadRegistrationFail, 0);
[email protected]fe58acc22012-02-29 01:29:58302 int debugger_present_count =
303 pref->GetInteger(prefs::kStabilityDebuggerPresent);
[email protected]e324f6b2012-02-28 05:43:37304 pref->SetInteger(prefs::kStabilityDebuggerPresent, 0);
[email protected]fe58acc22012-02-29 01:29:58305 int debugger_not_present_count =
306 pref->GetInteger(prefs::kStabilityDebuggerNotPresent);
[email protected]e324f6b2012-02-28 05:43:37307 pref->SetInteger(prefs::kStabilityDebuggerNotPresent, 0);
[email protected]b2a4812d2012-02-28 05:31:31308
[email protected]fe58acc22012-02-29 01:29:58309 // TODO(jar): The following are all optional, so we *could* optimize them for
310 // values of zero (and not include them).
311
312 // Write the XML version.
313 WriteIntAttribute("incompleteshutdowncount", incomplete_shutdown_count);
314 WriteIntAttribute("breakpadregistrationok",
315 breakpad_registration_success_count);
316 WriteIntAttribute("breakpadregistrationfail",
317 breakpad_registration_failure_count);
318 WriteIntAttribute("debuggerpresent", debugger_present_count);
319 WriteIntAttribute("debuggernotpresent", debugger_not_present_count);
320
321 // Write the protobuf version.
322 SystemProfileProto::Stability* stability =
[email protected]767c9d92012-03-02 16:04:34323 uma_proto()->mutable_system_profile()->mutable_stability();
[email protected]fe58acc22012-02-29 01:29:58324 stability->set_incomplete_shutdown_count(incomplete_shutdown_count);
325 stability->set_breakpad_registration_success_count(
326 breakpad_registration_success_count);
327 stability->set_breakpad_registration_failure_count(
328 breakpad_registration_failure_count);
329 stability->set_debugger_present_count(debugger_present_count);
330 stability->set_debugger_not_present_count(debugger_not_present_count);
331
332 WritePluginStabilityElements(plugin_list, pref);
[email protected]147bbc0b2009-01-06 19:37:40333}
334
[email protected]fe58acc22012-02-29 01:29:58335void MetricsLog::WritePluginStabilityElements(
336 const std::vector<webkit::WebPluginInfo>& plugin_list,
337 PrefService* pref) {
[email protected]147bbc0b2009-01-06 19:37:40338 // Now log plugin stability info.
initial.commit09911bf2008-07-26 23:55:29339 const ListValue* plugin_stats_list = pref->GetList(
340 prefs::kStabilityPluginStats);
[email protected]1df44b72012-01-19 05:20:34341 if (!plugin_stats_list)
342 return;
initial.commit09911bf2008-07-26 23:55:29343
[email protected]1df44b72012-01-19 05:20:34344 OPEN_ELEMENT_FOR_SCOPE("plugins");
[email protected]fe58acc22012-02-29 01:29:58345 SystemProfileProto::Stability* stability =
[email protected]767c9d92012-03-02 16:04:34346 uma_proto()->mutable_system_profile()->mutable_stability();
[email protected]fe58acc22012-02-29 01:29:58347 PluginPrefs* plugin_prefs = GetPluginPrefs();
[email protected]1df44b72012-01-19 05:20:34348 for (ListValue::const_iterator iter = plugin_stats_list->begin();
349 iter != plugin_stats_list->end(); ++iter) {
350 if (!(*iter)->IsType(Value::TYPE_DICTIONARY)) {
351 NOTREACHED();
352 continue;
initial.commit09911bf2008-07-26 23:55:29353 }
[email protected]1df44b72012-01-19 05:20:34354 DictionaryValue* plugin_dict = static_cast<DictionaryValue*>(*iter);
initial.commit09911bf2008-07-26 23:55:29355
[email protected]1df44b72012-01-19 05:20:34356 std::string plugin_name;
357 plugin_dict->GetString(prefs::kStabilityPluginName, &plugin_name);
358
[email protected]fe58acc22012-02-29 01:29:58359 std::string base64_name_hash;
360 uint64 numeric_name_hash_ignored;
361 CreateHashes(plugin_name, &base64_name_hash, &numeric_name_hash_ignored);
362
363 // Write the XML verison.
[email protected]1df44b72012-01-19 05:20:34364 OPEN_ELEMENT_FOR_SCOPE("pluginstability");
365 // Use "filename" instead of "name", otherwise we need to update the
366 // UMA servers.
[email protected]fe58acc22012-02-29 01:29:58367 WriteAttribute("filename", base64_name_hash);
[email protected]1df44b72012-01-19 05:20:34368
369 int launches = 0;
370 plugin_dict->GetInteger(prefs::kStabilityPluginLaunches, &launches);
371 WriteIntAttribute("launchcount", launches);
372
373 int instances = 0;
374 plugin_dict->GetInteger(prefs::kStabilityPluginInstances, &instances);
375 WriteIntAttribute("instancecount", instances);
376
377 int crashes = 0;
378 plugin_dict->GetInteger(prefs::kStabilityPluginCrashes, &crashes);
379 WriteIntAttribute("crashcount", crashes);
[email protected]fe58acc22012-02-29 01:29:58380
381 // Write the protobuf version.
382 // Note that this search is potentially a quadratic operation, but given the
383 // low number of plugins installed on a "reasonable" setup, this should be
384 // fine.
385 // TODO(isherman): Verify that this does not show up as a hotspot in
386 // profiler runs.
387 const webkit::WebPluginInfo* plugin_info = NULL;
388 const string16 plugin_name_utf16 = UTF8ToUTF16(plugin_name);
389 for (std::vector<webkit::WebPluginInfo>::const_iterator iter =
390 plugin_list.begin();
391 iter != plugin_list.end(); ++iter) {
392 if (iter->name == plugin_name_utf16) {
393 plugin_info = &(*iter);
394 break;
395 }
396 }
397
398 if (!plugin_info) {
399 NOTREACHED();
400 continue;
401 }
402
403 SystemProfileProto::Stability::PluginStability* plugin_stability =
404 stability->add_plugin_stability();
405 SetPluginInfo(*plugin_info, plugin_prefs,
406 plugin_stability->mutable_plugin());
407 plugin_stability->set_launch_count(launches);
408 plugin_stability->set_instance_count(instances);
409 plugin_stability->set_crash_count(crashes);
initial.commit09911bf2008-07-26 23:55:29410 }
[email protected]1df44b72012-01-19 05:20:34411
412 pref->ClearPref(prefs::kStabilityPluginStats);
initial.commit09911bf2008-07-26 23:55:29413}
414
[email protected]fe58acc22012-02-29 01:29:58415// The server refuses data that doesn't have certain values. crashcount and
416// launchcount are currently "required" in the "stability" group.
417// TODO(isherman): Stop writing these attributes specially once the migration to
418// protobufs is complete.
[email protected]147bbc0b2009-01-06 19:37:40419void MetricsLog::WriteRequiredStabilityAttributes(PrefService* pref) {
[email protected]fe58acc22012-02-29 01:29:58420 int launch_count = pref->GetInteger(prefs::kStabilityLaunchCount);
[email protected]0b33f80b2008-12-17 21:34:36421 pref->SetInteger(prefs::kStabilityLaunchCount, 0);
[email protected]fe58acc22012-02-29 01:29:58422 int crash_count = pref->GetInteger(prefs::kStabilityCrashCount);
[email protected]0b33f80b2008-12-17 21:34:36423 pref->SetInteger(prefs::kStabilityCrashCount, 0);
[email protected]fe58acc22012-02-29 01:29:58424
425 // Write the XML version.
426 WriteIntAttribute("launchcount", launch_count);
427 WriteIntAttribute("crashcount", crash_count);
428
429 // Write the protobuf version.
430 SystemProfileProto::Stability* stability =
[email protected]767c9d92012-03-02 16:04:34431 uma_proto()->mutable_system_profile()->mutable_stability();
[email protected]fe58acc22012-02-29 01:29:58432 stability->set_launch_count(launch_count);
433 stability->set_crash_count(crash_count);
[email protected]0b33f80b2008-12-17 21:34:36434}
435
[email protected]147bbc0b2009-01-06 19:37:40436void MetricsLog::WriteRealtimeStabilityAttributes(PrefService* pref) {
[email protected]0b33f80b2008-12-17 21:34:36437 // Update the stats which are critical for real-time stability monitoring.
438 // Since these are "optional," only list ones that are non-zero, as the counts
439 // are aggergated (summed) server side.
440
[email protected]fe58acc22012-02-29 01:29:58441 SystemProfileProto::Stability* stability =
[email protected]767c9d92012-03-02 16:04:34442 uma_proto()->mutable_system_profile()->mutable_stability();
[email protected]0b33f80b2008-12-17 21:34:36443 int count = pref->GetInteger(prefs::kStabilityPageLoadCount);
444 if (count) {
445 WriteIntAttribute("pageloadcount", count);
[email protected]fe58acc22012-02-29 01:29:58446 stability->set_page_load_count(count);
[email protected]0b33f80b2008-12-17 21:34:36447 pref->SetInteger(prefs::kStabilityPageLoadCount, 0);
448 }
449
450 count = pref->GetInteger(prefs::kStabilityRendererCrashCount);
451 if (count) {
452 WriteIntAttribute("renderercrashcount", count);
[email protected]fe58acc22012-02-29 01:29:58453 stability->set_renderer_crash_count(count);
[email protected]0b33f80b2008-12-17 21:34:36454 pref->SetInteger(prefs::kStabilityRendererCrashCount, 0);
455 }
456
[email protected]1f085622009-12-04 05:33:45457 count = pref->GetInteger(prefs::kStabilityExtensionRendererCrashCount);
458 if (count) {
459 WriteIntAttribute("extensionrenderercrashcount", count);
[email protected]fe58acc22012-02-29 01:29:58460 stability->set_extension_renderer_crash_count(count);
[email protected]1f085622009-12-04 05:33:45461 pref->SetInteger(prefs::kStabilityExtensionRendererCrashCount, 0);
462 }
463
[email protected]0b33f80b2008-12-17 21:34:36464 count = pref->GetInteger(prefs::kStabilityRendererHangCount);
465 if (count) {
466 WriteIntAttribute("rendererhangcount", count);
[email protected]fe58acc22012-02-29 01:29:58467 stability->set_renderer_hang_count(count);
[email protected]0b33f80b2008-12-17 21:34:36468 pref->SetInteger(prefs::kStabilityRendererHangCount, 0);
469 }
[email protected]1f085622009-12-04 05:33:45470
471 count = pref->GetInteger(prefs::kStabilityChildProcessCrashCount);
472 if (count) {
473 WriteIntAttribute("childprocesscrashcount", count);
[email protected]fe58acc22012-02-29 01:29:58474 stability->set_child_process_crash_count(count);
[email protected]1f085622009-12-04 05:33:45475 pref->SetInteger(prefs::kStabilityChildProcessCrashCount, 0);
476 }
[email protected]9165f742010-03-10 22:55:01477
[email protected]c1834a92011-01-21 18:21:03478#if defined(OS_CHROMEOS)
479 count = pref->GetInteger(prefs::kStabilityOtherUserCrashCount);
480 if (count) {
[email protected]fe58acc22012-02-29 01:29:58481 stability->set_other_user_crash_count(count);
[email protected]c1834a92011-01-21 18:21:03482 pref->SetInteger(prefs::kStabilityOtherUserCrashCount, 0);
483 }
484
485 count = pref->GetInteger(prefs::kStabilityKernelCrashCount);
486 if (count) {
[email protected]fe58acc22012-02-29 01:29:58487 stability->set_kernel_crash_count(count);
[email protected]c1834a92011-01-21 18:21:03488 pref->SetInteger(prefs::kStabilityKernelCrashCount, 0);
489 }
490
491 count = pref->GetInteger(prefs::kStabilitySystemUncleanShutdownCount);
492 if (count) {
[email protected]fe58acc22012-02-29 01:29:58493 stability->set_unclean_system_shutdown_count(count);
[email protected]c1834a92011-01-21 18:21:03494 pref->SetInteger(prefs::kStabilitySystemUncleanShutdownCount, 0);
495 }
496#endif // OS_CHROMEOS
497
[email protected]9165f742010-03-10 22:55:01498 int64 recent_duration = GetIncrementalUptime(pref);
[email protected]fe58acc22012-02-29 01:29:58499 if (recent_duration) {
[email protected]9165f742010-03-10 22:55:01500 WriteInt64Attribute("uptimesec", recent_duration);
[email protected]fe58acc22012-02-29 01:29:58501 stability->set_uptime_sec(recent_duration);
502 }
[email protected]0b33f80b2008-12-17 21:34:36503}
504
initial.commit09911bf2008-07-26 23:55:29505void MetricsLog::WritePluginList(
[email protected]bc66d532012-03-23 01:57:05506 const std::vector<webkit::WebPluginInfo>& plugin_list,
507 bool write_as_xml) {
[email protected]767c9d92012-03-02 16:04:34508 DCHECK(!locked());
initial.commit09911bf2008-07-26 23:55:29509
[email protected]1df44b72012-01-19 05:20:34510 PluginPrefs* plugin_prefs = GetPluginPrefs();
[email protected]10084982011-08-19 17:56:56511
[email protected]ffaf78a2008-11-12 17:38:33512 OPEN_ELEMENT_FOR_SCOPE("plugins");
[email protected]767c9d92012-03-02 16:04:34513 SystemProfileProto* system_profile = uma_proto()->mutable_system_profile();
[email protected]91d9f3d2011-08-14 05:24:44514 for (std::vector<webkit::WebPluginInfo>::const_iterator iter =
[email protected]191eb3f72010-12-21 06:27:50515 plugin_list.begin();
initial.commit09911bf2008-07-26 23:55:29516 iter != plugin_list.end(); ++iter) {
[email protected]bc66d532012-03-23 01:57:05517 if (write_as_xml) {
518 std::string base64_name_hash;
519 uint64 numeric_hash_ignored;
520 CreateHashes(UTF16ToUTF8(iter->name), &base64_name_hash,
521 &numeric_hash_ignored);
[email protected]fe58acc22012-02-29 01:29:58522
[email protected]bc66d532012-03-23 01:57:05523 std::string filename_bytes = iter->path.BaseName().AsUTF8Unsafe();
524 std::string base64_filename_hash;
525 CreateHashes(filename_bytes, &base64_filename_hash,
526 &numeric_hash_ignored);
[email protected]fe58acc22012-02-29 01:29:58527
[email protected]bc66d532012-03-23 01:57:05528 // Write the XML version.
529 OPEN_ELEMENT_FOR_SCOPE("plugin");
initial.commit09911bf2008-07-26 23:55:29530
[email protected]bc66d532012-03-23 01:57:05531 // Plugin name and filename are hashed for the privacy of those
532 // testing unreleased new extensions.
533 WriteAttribute("name", base64_name_hash);
534 WriteAttribute("filename", base64_filename_hash);
535 WriteAttribute("version", UTF16ToUTF8(iter->version));
536 if (plugin_prefs)
537 WriteIntAttribute("disabled", !plugin_prefs->IsPluginEnabled(*iter));
538 } else {
539 // Write the protobuf version.
540 SystemProfileProto::Plugin* plugin = system_profile->add_plugin();
541 SetPluginInfo(*iter, plugin_prefs, plugin);
542 }
initial.commit09911bf2008-07-26 23:55:29543 }
initial.commit09911bf2008-07-26 23:55:29544}
545
[email protected]147bbc0b2009-01-06 19:37:40546void MetricsLog::WriteInstallElement() {
[email protected]fe58acc22012-02-29 01:29:58547 // Write the XML version.
[email protected]bc66d532012-03-23 01:57:05548 // We'll write the protobuf version in RecordEnvironmentProto().
[email protected]147bbc0b2009-01-06 19:37:40549 OPEN_ELEMENT_FOR_SCOPE("install");
[email protected]bc66d532012-03-23 01:57:05550 WriteAttribute("installdate", GetInstallDate(GetPrefService()));
[email protected]147bbc0b2009-01-06 19:37:40551 WriteIntAttribute("buildid", 0); // We're using appversion instead.
[email protected]147bbc0b2009-01-06 19:37:40552}
553
initial.commit09911bf2008-07-26 23:55:29554void MetricsLog::RecordEnvironment(
[email protected]91d9f3d2011-08-14 05:24:44555 const std::vector<webkit::WebPluginInfo>& plugin_list,
initial.commit09911bf2008-07-26 23:55:29556 const DictionaryValue* profile_metrics) {
[email protected]767c9d92012-03-02 16:04:34557 DCHECK(!locked());
initial.commit09911bf2008-07-26 23:55:29558
[email protected]767c9d92012-03-02 16:04:34559 PrefService* pref = GetPrefService();
initial.commit09911bf2008-07-26 23:55:29560
[email protected]ffaf78a2008-11-12 17:38:33561 OPEN_ELEMENT_FOR_SCOPE("profile");
initial.commit09911bf2008-07-26 23:55:29562 WriteCommonEventAttributes();
563
[email protected]147bbc0b2009-01-06 19:37:40564 WriteInstallElement();
initial.commit09911bf2008-07-26 23:55:29565
[email protected]bc66d532012-03-23 01:57:05566 // Write the XML version.
567 // We'll write the protobuf version in RecordEnvironmentProto().
568 bool write_as_xml = true;
569 WritePluginList(plugin_list, write_as_xml);
initial.commit09911bf2008-07-26 23:55:29570
[email protected]fe58acc22012-02-29 01:29:58571 WriteStabilityElement(plugin_list, pref);
initial.commit09911bf2008-07-26 23:55:29572
initial.commit09911bf2008-07-26 23:55:29573 {
[email protected]fe58acc22012-02-29 01:29:58574 // Write the XML version.
[email protected]bc66d532012-03-23 01:57:05575 // We'll write the protobuf version in RecordEnvironmentProto().
initial.commit09911bf2008-07-26 23:55:29576 OPEN_ELEMENT_FOR_SCOPE("cpu");
[email protected]bc66d532012-03-23 01:57:05577 WriteAttribute("arch", base::SysInfo::CPUArchitecture());
initial.commit09911bf2008-07-26 23:55:29578 }
579
580 {
[email protected]fe58acc22012-02-29 01:29:58581 // Write the XML version.
[email protected]bc66d532012-03-23 01:57:05582 // We'll write the protobuf version in RecordEnvironmentProto().
initial.commit09911bf2008-07-26 23:55:29583 OPEN_ELEMENT_FOR_SCOPE("memory");
[email protected]bc66d532012-03-23 01:57:05584 WriteIntAttribute("mb", base::SysInfo::AmountOfPhysicalMemoryMB());
[email protected]d1be67b2008-11-19 20:28:38585#if defined(OS_WIN)
586 WriteIntAttribute("dllbase", reinterpret_cast<int>(&__ImageBase));
587#endif
initial.commit09911bf2008-07-26 23:55:29588 }
589
590 {
[email protected]fe58acc22012-02-29 01:29:58591 // Write the XML version.
[email protected]bc66d532012-03-23 01:57:05592 // We'll write the protobuf version in RecordEnvironmentProto().
initial.commit09911bf2008-07-26 23:55:29593 OPEN_ELEMENT_FOR_SCOPE("os");
[email protected]bc66d532012-03-23 01:57:05594 WriteAttribute("name", base::SysInfo::OperatingSystemName());
595 WriteAttribute("version", base::SysInfo::OperatingSystemVersion());
initial.commit09911bf2008-07-26 23:55:29596 }
597
598 {
[email protected]e8c287c872010-07-20 00:49:42599 OPEN_ELEMENT_FOR_SCOPE("gpu");
[email protected]fe58acc22012-02-29 01:29:58600 const content::GPUInfo& gpu_info =
601 GpuDataManager::GetInstance()->GetGPUInfo();
[email protected]fe58acc22012-02-29 01:29:58602
603 // Write the XML version.
[email protected]bc66d532012-03-23 01:57:05604 // We'll write the protobuf version in RecordEnvironmentProto().
[email protected]79078df2012-02-16 01:22:32605 WriteIntAttribute("vendorid", gpu_info.vendor_id);
606 WriteIntAttribute("deviceid", gpu_info.device_id);
[email protected]e8c287c872010-07-20 00:49:42607 }
608
609 {
[email protected]767c9d92012-03-02 16:04:34610 const gfx::Size display_size = GetScreenSize();
[email protected]fe58acc22012-02-29 01:29:58611
612 // Write the XML version.
[email protected]bc66d532012-03-23 01:57:05613 // We'll write the protobuf version in RecordEnvironmentProto().
[email protected]fe58acc22012-02-29 01:29:58614 OPEN_ELEMENT_FOR_SCOPE("display");
[email protected]bc66d532012-03-23 01:57:05615 WriteIntAttribute("xsize", display_size.width());
616 WriteIntAttribute("ysize", display_size.height());
617 WriteIntAttribute("screens", GetScreenCount());
initial.commit09911bf2008-07-26 23:55:29618 }
619
620 {
621 OPEN_ELEMENT_FOR_SCOPE("bookmarks");
622 int num_bookmarks_on_bookmark_bar =
623 pref->GetInteger(prefs::kNumBookmarksOnBookmarkBar);
624 int num_folders_on_bookmark_bar =
625 pref->GetInteger(prefs::kNumFoldersOnBookmarkBar);
626 int num_bookmarks_in_other_bookmarks_folder =
627 pref->GetInteger(prefs::kNumBookmarksInOtherBookmarkFolder);
628 int num_folders_in_other_bookmarks_folder =
629 pref->GetInteger(prefs::kNumFoldersInOtherBookmarkFolder);
630 {
631 OPEN_ELEMENT_FOR_SCOPE("bookmarklocation");
632 WriteAttribute("name", "full-tree");
633 WriteIntAttribute("foldercount",
634 num_folders_on_bookmark_bar + num_folders_in_other_bookmarks_folder);
635 WriteIntAttribute("itemcount",
636 num_bookmarks_on_bookmark_bar +
637 num_bookmarks_in_other_bookmarks_folder);
638 }
639 {
640 OPEN_ELEMENT_FOR_SCOPE("bookmarklocation");
641 WriteAttribute("name", "toolbar");
642 WriteIntAttribute("foldercount", num_folders_on_bookmark_bar);
643 WriteIntAttribute("itemcount", num_bookmarks_on_bookmark_bar);
644 }
645 }
646
647 {
648 OPEN_ELEMENT_FOR_SCOPE("keywords");
649 WriteIntAttribute("count", pref->GetInteger(prefs::kNumKeywords));
650 }
651
652 if (profile_metrics)
653 WriteAllProfilesMetrics(*profile_metrics);
[email protected]767c9d92012-03-02 16:04:34654
[email protected]bc66d532012-03-23 01:57:05655 RecordEnvironmentProto(plugin_list);
656}
657
658void MetricsLog::RecordEnvironmentProto(
659 const std::vector<webkit::WebPluginInfo>& plugin_list) {
660 SystemProfileProto* system_profile = uma_proto()->mutable_system_profile();
661 int install_date;
662 bool success = base::StringToInt(GetInstallDate(GetPrefService()),
663 &install_date);
664 DCHECK(success);
665 system_profile->set_install_date(install_date);
666
667 system_profile->set_application_locale(
668 content::GetContentClient()->browser()->GetApplicationLocale());
669
670 SystemProfileProto::Hardware* hardware = system_profile->mutable_hardware();
671 hardware->set_cpu_architecture(base::SysInfo::CPUArchitecture());
672 hardware->set_system_ram_mb(base::SysInfo::AmountOfPhysicalMemoryMB());
673#if defined(OS_WIN)
674 hardware->set_dll_base(reinterpret_cast<uint64>(&__ImageBase));
675#endif
676
677 SystemProfileProto::OS* os = system_profile->mutable_os();
678 os->set_name(base::SysInfo::OperatingSystemName());
679 os->set_version(base::SysInfo::OperatingSystemVersion());
680
681 const content::GPUInfo& gpu_info =
682 GpuDataManager::GetInstance()->GetGPUInfo();
683 SystemProfileProto::Hardware::Graphics* gpu = hardware->mutable_gpu();
684 gpu->set_vendor_id(gpu_info.vendor_id);
685 gpu->set_device_id(gpu_info.device_id);
686 gpu->set_driver_version(gpu_info.driver_version);
687 gpu->set_driver_date(gpu_info.driver_date);
688 SystemProfileProto::Hardware::Graphics::PerformanceStatistics*
689 gpu_performance = gpu->mutable_performance_statistics();
690 gpu_performance->set_graphics_score(gpu_info.performance_stats.graphics);
691 gpu_performance->set_gaming_score(gpu_info.performance_stats.gaming);
692 gpu_performance->set_overall_score(gpu_info.performance_stats.overall);
693
694 const gfx::Size display_size = GetScreenSize();
695 hardware->set_primary_screen_width(display_size.width());
696 hardware->set_primary_screen_height(display_size.height());
697 hardware->set_screen_count(GetScreenCount());
698
699 bool write_as_xml = false;
700 WritePluginList(plugin_list, write_as_xml);
701
[email protected]767c9d92012-03-02 16:04:34702 std::vector<NameGroupId> field_trial_ids;
703 GetFieldTrialIds(&field_trial_ids);
704 WriteFieldTrials(field_trial_ids, system_profile);
initial.commit09911bf2008-07-26 23:55:29705}
706
707void MetricsLog::WriteAllProfilesMetrics(
708 const DictionaryValue& all_profiles_metrics) {
[email protected]57ecc4b2010-08-11 03:02:51709 const std::string profile_prefix(prefs::kProfilePrefix);
initial.commit09911bf2008-07-26 23:55:29710 for (DictionaryValue::key_iterator i = all_profiles_metrics.begin_keys();
711 i != all_profiles_metrics.end_keys(); ++i) {
[email protected]e7b418b2010-07-30 19:47:47712 const std::string& key_name = *i;
initial.commit09911bf2008-07-26 23:55:29713 if (key_name.compare(0, profile_prefix.size(), profile_prefix) == 0) {
714 DictionaryValue* profile;
[email protected]4dad9ad82009-11-25 20:47:52715 if (all_profiles_metrics.GetDictionaryWithoutPathExpansion(key_name,
716 &profile))
initial.commit09911bf2008-07-26 23:55:29717 WriteProfileMetrics(key_name.substr(profile_prefix.size()), *profile);
718 }
719 }
720}
721
[email protected]e7b418b2010-07-30 19:47:47722void MetricsLog::WriteProfileMetrics(const std::string& profileidhash,
initial.commit09911bf2008-07-26 23:55:29723 const DictionaryValue& profile_metrics) {
724 OPEN_ELEMENT_FOR_SCOPE("userprofile");
[email protected]e7b418b2010-07-30 19:47:47725 WriteAttribute("profileidhash", profileidhash);
initial.commit09911bf2008-07-26 23:55:29726 for (DictionaryValue::key_iterator i = profile_metrics.begin_keys();
727 i != profile_metrics.end_keys(); ++i) {
728 Value* value;
[email protected]4dad9ad82009-11-25 20:47:52729 if (profile_metrics.GetWithoutPathExpansion(*i, &value)) {
[email protected]e7b418b2010-07-30 19:47:47730 DCHECK(*i != "id");
initial.commit09911bf2008-07-26 23:55:29731 switch (value->GetType()) {
732 case Value::TYPE_STRING: {
[email protected]5e324b72008-12-18 00:07:59733 std::string string_value;
initial.commit09911bf2008-07-26 23:55:29734 if (value->GetAsString(&string_value)) {
735 OPEN_ELEMENT_FOR_SCOPE("profileparam");
[email protected]e7b418b2010-07-30 19:47:47736 WriteAttribute("name", *i);
[email protected]5e324b72008-12-18 00:07:59737 WriteAttribute("value", string_value);
initial.commit09911bf2008-07-26 23:55:29738 }
739 break;
740 }
741
742 case Value::TYPE_BOOLEAN: {
743 bool bool_value;
744 if (value->GetAsBoolean(&bool_value)) {
745 OPEN_ELEMENT_FOR_SCOPE("profileparam");
[email protected]e7b418b2010-07-30 19:47:47746 WriteAttribute("name", *i);
initial.commit09911bf2008-07-26 23:55:29747 WriteIntAttribute("value", bool_value ? 1 : 0);
748 }
749 break;
750 }
751
752 case Value::TYPE_INTEGER: {
753 int int_value;
754 if (value->GetAsInteger(&int_value)) {
755 OPEN_ELEMENT_FOR_SCOPE("profileparam");
[email protected]e7b418b2010-07-30 19:47:47756 WriteAttribute("name", *i);
initial.commit09911bf2008-07-26 23:55:29757 WriteIntAttribute("value", int_value);
758 }
759 break;
760 }
761
762 default:
763 NOTREACHED();
764 break;
765 }
766 }
767 }
768}
769
770void MetricsLog::RecordOmniboxOpenedURL(const AutocompleteLog& log) {
[email protected]767c9d92012-03-02 16:04:34771 DCHECK(!locked());
initial.commit09911bf2008-07-26 23:55:29772
[email protected]fe58acc22012-02-29 01:29:58773 // Write the XML version.
[email protected]ffaf78a2008-11-12 17:38:33774 OPEN_ELEMENT_FOR_SCOPE("uielement");
initial.commit09911bf2008-07-26 23:55:29775 WriteAttribute("action", "autocomplete");
776 WriteAttribute("targetidhash", "");
777 // TODO(kochi): Properly track windows.
778 WriteIntAttribute("window", 0);
[email protected]6ebc3162011-12-19 13:44:00779 if (log.tab_id != -1) {
780 // If we know what tab the autocomplete URL was opened in, log it.
781 WriteIntAttribute("tab", static_cast<int>(log.tab_id));
782 }
initial.commit09911bf2008-07-26 23:55:29783 WriteCommonEventAttributes();
784
[email protected]65956312012-04-19 21:28:12785 std::vector<string16> terms;
786 const int num_terms =
787 static_cast<int>(Tokenize(log.text, kWhitespaceUTF16, &terms));
[email protected]ffaf78a2008-11-12 17:38:33788 {
789 OPEN_ELEMENT_FOR_SCOPE("autocomplete");
initial.commit09911bf2008-07-26 23:55:29790
[email protected]ffaf78a2008-11-12 17:38:33791 WriteIntAttribute("typedlength", static_cast<int>(log.text.length()));
[email protected]65956312012-04-19 21:28:12792 WriteIntAttribute("numterms", num_terms);
[email protected]ffaf78a2008-11-12 17:38:33793 WriteIntAttribute("selectedindex", static_cast<int>(log.selected_index));
794 WriteIntAttribute("completedlength",
795 static_cast<int>(log.inline_autocompleted_length));
[email protected]9e349762012-01-31 03:24:36796 if (log.elapsed_time_since_user_first_modified_omnibox !=
797 base::TimeDelta::FromMilliseconds(-1)) {
798 // Only upload the typing duration if it is set/valid.
799 WriteInt64Attribute("typingduration",
800 log.elapsed_time_since_user_first_modified_omnibox.InMilliseconds());
801 }
[email protected]381e2992008-12-16 01:41:00802 const std::string input_type(
803 AutocompleteInput::TypeToString(log.input_type));
804 if (!input_type.empty())
805 WriteAttribute("inputtype", input_type);
initial.commit09911bf2008-07-26 23:55:29806
[email protected]ffaf78a2008-11-12 17:38:33807 for (AutocompleteResult::const_iterator i(log.result.begin());
808 i != log.result.end(); ++i) {
809 OPEN_ELEMENT_FOR_SCOPE("autocompleteitem");
810 if (i->provider)
811 WriteAttribute("provider", i->provider->name());
[email protected]381e2992008-12-16 01:41:00812 const std::string result_type(AutocompleteMatch::TypeToString(i->type));
813 if (!result_type.empty())
814 WriteAttribute("resulttype", result_type);
[email protected]ffaf78a2008-11-12 17:38:33815 WriteIntAttribute("relevance", i->relevance);
816 WriteIntAttribute("isstarred", i->starred ? 1 : 0);
817 }
initial.commit09911bf2008-07-26 23:55:29818 }
initial.commit09911bf2008-07-26 23:55:29819
[email protected]fe58acc22012-02-29 01:29:58820 // Write the protobuf version.
[email protected]767c9d92012-03-02 16:04:34821 OmniboxEventProto* omnibox_event = uma_proto()->add_omnibox_event();
[email protected]fe58acc22012-02-29 01:29:58822 omnibox_event->set_time(MetricsLogBase::GetCurrentTime());
823 if (log.tab_id != -1) {
824 // If we know what tab the autocomplete URL was opened in, log it.
825 omnibox_event->set_tab_id(log.tab_id);
826 }
827 omnibox_event->set_typed_length(log.text.length());
[email protected]65956312012-04-19 21:28:12828 omnibox_event->set_num_typed_terms(num_terms);
[email protected]fe58acc22012-02-29 01:29:58829 omnibox_event->set_selected_index(log.selected_index);
830 omnibox_event->set_completed_length(log.inline_autocompleted_length);
[email protected]65956312012-04-19 21:28:12831 if (log.elapsed_time_since_user_first_modified_omnibox !=
832 base::TimeDelta::FromMilliseconds(-1)) {
833 // Only upload the typing duration if it is set/valid.
834 omnibox_event->set_typing_duration_ms(
835 log.elapsed_time_since_user_first_modified_omnibox.InMilliseconds());
836 }
[email protected]fe58acc22012-02-29 01:29:58837 omnibox_event->set_input_type(AsOmniboxEventInputType(log.input_type));
838 for (AutocompleteResult::const_iterator i(log.result.begin());
839 i != log.result.end(); ++i) {
840 OmniboxEventProto::Suggestion* suggestion = omnibox_event->add_suggestion();
841 suggestion->set_provider(AsOmniboxEventProviderType(i->provider));
842 suggestion->set_result_type(AsOmniboxEventResultType(i->type));
843 suggestion->set_relevance(i->relevance);
844 suggestion->set_is_starred(i->starred);
845 }
846
initial.commit09911bf2008-07-26 23:55:29847 ++num_events_;
848}