blob: bf541344ebc8c77f3aed2f22ce54fd26b023eeee [file] [log] [blame]
[email protected]85ed9d42010-06-08 22:37:441// Copyright (c) 2010 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]85ed9d42010-06-08 22:37:4412#include "base/perftimer.h"
initial.commit09911bf2008-07-26 23:55:2913#include "base/scoped_ptr.h"
14#include "base/string_util.h"
[email protected]fadf97f2008-09-18 12:18:1415#include "base/sys_info.h"
[email protected]37f39e42010-01-06 17:35:1716#include "base/third_party/nspr/prtime.h"
[email protected]1eeb5e02010-07-20 23:02:1117#include "base/time.h"
18#include "base/utf_string_conversions.h"
initial.commit09911bf2008-07-26 23:55:2919#include "chrome/browser/autocomplete/autocomplete.h"
[email protected]9ac40092010-10-27 23:05:2620#include "chrome/browser/autocomplete/autocomplete_match.h"
initial.commit09911bf2008-07-26 23:55:2921#include "chrome/browser/browser_process.h"
[email protected]19d7e562010-11-17 18:56:5522#include "chrome/browser/gpu_process_host_ui_shim.h"
[email protected]37858e52010-08-26 00:22:0223#include "chrome/browser/prefs/pref_service.h"
[email protected]1eeb5e02010-07-20 23:02:1124#include "chrome/common/chrome_version_info.h"
initial.commit09911bf2008-07-26 23:55:2925#include "chrome/common/logging_chrome.h"
26#include "chrome/common/pref_names.h"
[email protected]46072d42008-07-28 14:49:3527#include "googleurl/src/gurl.h"
[email protected]191eb3f72010-12-21 06:27:5028#include "webkit/plugins/npapi/webplugininfo.h"
initial.commit09911bf2008-07-26 23:55:2929
30#define OPEN_ELEMENT_FOR_SCOPE(name) ScopedElement scoped_element(this, name)
31
[email protected]d1be67b2008-11-19 20:28:3832// http://blogs.msdn.com/oldnewthing/archive/2004/10/25/247180.aspx
33#if defined(OS_WIN)
34extern "C" IMAGE_DOS_HEADER __ImageBase;
35#endif
36
[email protected]1226abb2010-06-10 18:01:2837MetricsLog::MetricsLog(const std::string& client_id, int session_id)
38 : MetricsLogBase(client_id, session_id, MetricsLog::GetVersionString()) {}
[email protected]5ed7d4572009-12-23 17:42:4139
[email protected]1226abb2010-06-10 18:01:2840MetricsLog::~MetricsLog() {}
initial.commit09911bf2008-07-26 23:55:2941
42// static
43void MetricsLog::RegisterPrefs(PrefService* local_state) {
44 local_state->RegisterListPref(prefs::kStabilityPluginStats);
initial.commit09911bf2008-07-26 23:55:2945}
46
[email protected]9165f742010-03-10 22:55:0147int64 MetricsLog::GetIncrementalUptime(PrefService* pref) {
48 base::TimeTicks now = base::TimeTicks::Now();
49 static base::TimeTicks last_updated_time(now);
50 int64 incremental_time = (now - last_updated_time).InSeconds();
51 last_updated_time = now;
52
53 if (incremental_time > 0) {
54 int64 metrics_uptime = pref->GetInt64(prefs::kUninstallMetricsUptimeSec);
55 metrics_uptime += incremental_time;
56 pref->SetInt64(prefs::kUninstallMetricsUptimeSec, metrics_uptime);
57 }
58
59 return incremental_time;
60}
61
initial.commit09911bf2008-07-26 23:55:2962std::string MetricsLog::GetInstallDate() const {
63 PrefService* pref = g_browser_process->local_state();
64 if (pref) {
[email protected]ddd231e2010-06-29 20:35:1965 return pref->GetString(prefs::kMetricsClientIDTimestamp);
initial.commit09911bf2008-07-26 23:55:2966 } else {
67 NOTREACHED();
68 return "0";
69 }
70}
71
[email protected]1226abb2010-06-10 18:01:2872// static
73std::string MetricsLog::GetVersionString() {
[email protected]0211f57e2010-08-27 20:28:4274 chrome::VersionInfo version_info;
[email protected]30c91802010-12-18 00:40:1775 if (!version_info.is_valid()) {
76 NOTREACHED() << "Unable to retrieve version info.";
77 return std::string();
78 }
79
[email protected]0211f57e2010-08-27 20:28:4280 std::string version = version_info.Version();
81 if (!version_extension_.empty())
82 version += version_extension_;
83 if (!version_info.IsOfficialBuild())
84 version.append("-devel");
85 return version;
[email protected]1226abb2010-06-10 18:01:2886}
87
[email protected]dec76e802010-09-23 22:43:5388MetricsLog* MetricsLog::AsMetricsLog() {
89 return this;
90}
91
[email protected]0b33f80b2008-12-17 21:34:3692void MetricsLog::RecordIncrementalStabilityElements() {
93 DCHECK(!locked_);
94
95 PrefService* pref = g_browser_process->local_state();
96 DCHECK(pref);
97
[email protected]147bbc0b2009-01-06 19:37:4098 OPEN_ELEMENT_FOR_SCOPE("profile");
99 WriteCommonEventAttributes();
100
101 WriteInstallElement(); // Supply appversion.
102
103 {
104 OPEN_ELEMENT_FOR_SCOPE("stability"); // Minimal set of stability elements.
105 WriteRequiredStabilityAttributes(pref);
106 WriteRealtimeStabilityAttributes(pref);
107
108 WritePluginStabilityElements(pref);
109 }
[email protected]0b33f80b2008-12-17 21:34:36110}
111
initial.commit09911bf2008-07-26 23:55:29112void MetricsLog::WriteStabilityElement() {
113 DCHECK(!locked_);
114
115 PrefService* pref = g_browser_process->local_state();
116 DCHECK(pref);
117
118 // Get stability attributes out of Local State, zeroing out stored values.
119 // NOTE: This could lead to some data loss if this report isn't successfully
120 // sent, but that's true for all the metrics.
121
[email protected]ffaf78a2008-11-12 17:38:33122 OPEN_ELEMENT_FOR_SCOPE("stability");
[email protected]147bbc0b2009-01-06 19:37:40123 WriteRequiredStabilityAttributes(pref);
124 WriteRealtimeStabilityAttributes(pref);
initial.commit09911bf2008-07-26 23:55:29125
[email protected]0b33f80b2008-12-17 21:34:36126 // TODO(jar): The following are all optional, so we *could* optimize them for
127 // values of zero (and not include them).
[email protected]8e674e42008-07-30 16:05:48128 WriteIntAttribute("incompleteshutdowncount",
129 pref->GetInteger(
130 prefs::kStabilityIncompleteSessionEndCount));
131 pref->SetInteger(prefs::kStabilityIncompleteSessionEndCount, 0);
[email protected]0b33f80b2008-12-17 21:34:36132
133
[email protected]e73c01972008-08-13 00:18:24134 WriteIntAttribute("breakpadregistrationok",
135 pref->GetInteger(prefs::kStabilityBreakpadRegistrationSuccess));
136 pref->SetInteger(prefs::kStabilityBreakpadRegistrationSuccess, 0);
137 WriteIntAttribute("breakpadregistrationfail",
138 pref->GetInteger(prefs::kStabilityBreakpadRegistrationFail));
139 pref->SetInteger(prefs::kStabilityBreakpadRegistrationFail, 0);
140 WriteIntAttribute("debuggerpresent",
141 pref->GetInteger(prefs::kStabilityDebuggerPresent));
142 pref->SetInteger(prefs::kStabilityDebuggerPresent, 0);
143 WriteIntAttribute("debuggernotpresent",
144 pref->GetInteger(prefs::kStabilityDebuggerNotPresent));
145 pref->SetInteger(prefs::kStabilityDebuggerNotPresent, 0);
initial.commit09911bf2008-07-26 23:55:29146
[email protected]147bbc0b2009-01-06 19:37:40147 WritePluginStabilityElements(pref);
148}
149
150void MetricsLog::WritePluginStabilityElements(PrefService* pref) {
151 // Now log plugin stability info.
initial.commit09911bf2008-07-26 23:55:29152 const ListValue* plugin_stats_list = pref->GetList(
153 prefs::kStabilityPluginStats);
154 if (plugin_stats_list) {
[email protected]ffaf78a2008-11-12 17:38:33155 OPEN_ELEMENT_FOR_SCOPE("plugins");
initial.commit09911bf2008-07-26 23:55:29156 for (ListValue::const_iterator iter = plugin_stats_list->begin();
157 iter != plugin_stats_list->end(); ++iter) {
158 if (!(*iter)->IsType(Value::TYPE_DICTIONARY)) {
159 NOTREACHED();
160 continue;
161 }
162 DictionaryValue* plugin_dict = static_cast<DictionaryValue*>(*iter);
163
[email protected]57ecc4b2010-08-11 03:02:51164 std::string plugin_name;
[email protected]8e50b602009-03-03 22:59:43165 plugin_dict->GetString(prefs::kStabilityPluginName, &plugin_name);
initial.commit09911bf2008-07-26 23:55:29166
[email protected]ffaf78a2008-11-12 17:38:33167 OPEN_ELEMENT_FOR_SCOPE("pluginstability");
[email protected]a27a9382009-02-11 23:55:10168 // Use "filename" instead of "name", otherwise we need to update the
169 // UMA servers.
[email protected]57ecc4b2010-08-11 03:02:51170 WriteAttribute("filename", CreateBase64Hash(plugin_name));
initial.commit09911bf2008-07-26 23:55:29171
172 int launches = 0;
[email protected]8e50b602009-03-03 22:59:43173 plugin_dict->GetInteger(prefs::kStabilityPluginLaunches, &launches);
initial.commit09911bf2008-07-26 23:55:29174 WriteIntAttribute("launchcount", launches);
175
176 int instances = 0;
[email protected]8e50b602009-03-03 22:59:43177 plugin_dict->GetInteger(prefs::kStabilityPluginInstances, &instances);
initial.commit09911bf2008-07-26 23:55:29178 WriteIntAttribute("instancecount", instances);
179
180 int crashes = 0;
[email protected]8e50b602009-03-03 22:59:43181 plugin_dict->GetInteger(prefs::kStabilityPluginCrashes, &crashes);
initial.commit09911bf2008-07-26 23:55:29182 WriteIntAttribute("crashcount", crashes);
initial.commit09911bf2008-07-26 23:55:29183 }
184
185 pref->ClearPref(prefs::kStabilityPluginStats);
initial.commit09911bf2008-07-26 23:55:29186 }
initial.commit09911bf2008-07-26 23:55:29187}
188
[email protected]147bbc0b2009-01-06 19:37:40189void MetricsLog::WriteRequiredStabilityAttributes(PrefService* pref) {
[email protected]0b33f80b2008-12-17 21:34:36190 // The server refuses data that doesn't have certain values. crashcount and
191 // launchcount are currently "required" in the "stability" group.
192 WriteIntAttribute("launchcount",
193 pref->GetInteger(prefs::kStabilityLaunchCount));
194 pref->SetInteger(prefs::kStabilityLaunchCount, 0);
195 WriteIntAttribute("crashcount",
196 pref->GetInteger(prefs::kStabilityCrashCount));
197 pref->SetInteger(prefs::kStabilityCrashCount, 0);
198}
199
[email protected]147bbc0b2009-01-06 19:37:40200void MetricsLog::WriteRealtimeStabilityAttributes(PrefService* pref) {
[email protected]0b33f80b2008-12-17 21:34:36201 // Update the stats which are critical for real-time stability monitoring.
202 // Since these are "optional," only list ones that are non-zero, as the counts
203 // are aggergated (summed) server side.
204
205 int count = pref->GetInteger(prefs::kStabilityPageLoadCount);
206 if (count) {
207 WriteIntAttribute("pageloadcount", count);
208 pref->SetInteger(prefs::kStabilityPageLoadCount, 0);
209 }
210
211 count = pref->GetInteger(prefs::kStabilityRendererCrashCount);
212 if (count) {
213 WriteIntAttribute("renderercrashcount", count);
214 pref->SetInteger(prefs::kStabilityRendererCrashCount, 0);
215 }
216
[email protected]1f085622009-12-04 05:33:45217 count = pref->GetInteger(prefs::kStabilityExtensionRendererCrashCount);
218 if (count) {
219 WriteIntAttribute("extensionrenderercrashcount", count);
220 pref->SetInteger(prefs::kStabilityExtensionRendererCrashCount, 0);
221 }
222
[email protected]0b33f80b2008-12-17 21:34:36223 count = pref->GetInteger(prefs::kStabilityRendererHangCount);
224 if (count) {
225 WriteIntAttribute("rendererhangcount", count);
226 pref->SetInteger(prefs::kStabilityRendererHangCount, 0);
227 }
[email protected]1f085622009-12-04 05:33:45228
229 count = pref->GetInteger(prefs::kStabilityChildProcessCrashCount);
230 if (count) {
231 WriteIntAttribute("childprocesscrashcount", count);
232 pref->SetInteger(prefs::kStabilityChildProcessCrashCount, 0);
233 }
[email protected]9165f742010-03-10 22:55:01234
235 int64 recent_duration = GetIncrementalUptime(pref);
236 if (recent_duration)
237 WriteInt64Attribute("uptimesec", recent_duration);
[email protected]0b33f80b2008-12-17 21:34:36238}
239
initial.commit09911bf2008-07-26 23:55:29240void MetricsLog::WritePluginList(
[email protected]191eb3f72010-12-21 06:27:50241 const std::vector<webkit::npapi::WebPluginInfo>& plugin_list) {
initial.commit09911bf2008-07-26 23:55:29242 DCHECK(!locked_);
243
[email protected]ffaf78a2008-11-12 17:38:33244 OPEN_ELEMENT_FOR_SCOPE("plugins");
initial.commit09911bf2008-07-26 23:55:29245
[email protected]191eb3f72010-12-21 06:27:50246 for (std::vector<webkit::npapi::WebPluginInfo>::const_iterator iter =
247 plugin_list.begin();
initial.commit09911bf2008-07-26 23:55:29248 iter != plugin_list.end(); ++iter) {
[email protected]ffaf78a2008-11-12 17:38:33249 OPEN_ELEMENT_FOR_SCOPE("plugin");
initial.commit09911bf2008-07-26 23:55:29250
251 // Plugin name and filename are hashed for the privacy of those
252 // testing unreleased new extensions.
[email protected]c9d811372010-06-23 21:44:57253 WriteAttribute("name", CreateBase64Hash(UTF16ToUTF8(iter->name)));
[email protected]046344c2009-01-13 00:54:21254 WriteAttribute("filename",
255 CreateBase64Hash(WideToUTF8(iter->path.BaseName().ToWStringHack())));
[email protected]c9d811372010-06-23 21:44:57256 WriteAttribute("version", UTF16ToUTF8(iter->version));
initial.commit09911bf2008-07-26 23:55:29257 }
initial.commit09911bf2008-07-26 23:55:29258}
259
[email protected]147bbc0b2009-01-06 19:37:40260void MetricsLog::WriteInstallElement() {
261 OPEN_ELEMENT_FOR_SCOPE("install");
262 WriteAttribute("installdate", GetInstallDate());
263 WriteIntAttribute("buildid", 0); // We're using appversion instead.
[email protected]147bbc0b2009-01-06 19:37:40264}
265
initial.commit09911bf2008-07-26 23:55:29266void MetricsLog::RecordEnvironment(
[email protected]191eb3f72010-12-21 06:27:50267 const std::vector<webkit::npapi::WebPluginInfo>& plugin_list,
initial.commit09911bf2008-07-26 23:55:29268 const DictionaryValue* profile_metrics) {
269 DCHECK(!locked_);
270
271 PrefService* pref = g_browser_process->local_state();
272
[email protected]ffaf78a2008-11-12 17:38:33273 OPEN_ELEMENT_FOR_SCOPE("profile");
initial.commit09911bf2008-07-26 23:55:29274 WriteCommonEventAttributes();
275
[email protected]147bbc0b2009-01-06 19:37:40276 WriteInstallElement();
initial.commit09911bf2008-07-26 23:55:29277
278 WritePluginList(plugin_list);
279
280 WriteStabilityElement();
281
282 {
283 OPEN_ELEMENT_FOR_SCOPE("cpu");
[email protected]05f9b682008-09-29 22:18:01284 WriteAttribute("arch", base::SysInfo::CPUArchitecture());
initial.commit09911bf2008-07-26 23:55:29285 }
286
287 {
initial.commit09911bf2008-07-26 23:55:29288 OPEN_ELEMENT_FOR_SCOPE("memory");
[email protected]ed6fc352008-09-18 12:44:40289 WriteIntAttribute("mb", base::SysInfo::AmountOfPhysicalMemoryMB());
[email protected]d1be67b2008-11-19 20:28:38290#if defined(OS_WIN)
291 WriteIntAttribute("dllbase", reinterpret_cast<int>(&__ImageBase));
292#endif
initial.commit09911bf2008-07-26 23:55:29293 }
294
295 {
296 OPEN_ELEMENT_FOR_SCOPE("os");
297 WriteAttribute("name",
[email protected]05f9b682008-09-29 22:18:01298 base::SysInfo::OperatingSystemName());
initial.commit09911bf2008-07-26 23:55:29299 WriteAttribute("version",
[email protected]05f9b682008-09-29 22:18:01300 base::SysInfo::OperatingSystemVersion());
initial.commit09911bf2008-07-26 23:55:29301 }
302
303 {
[email protected]e8c287c872010-07-20 00:49:42304 OPEN_ELEMENT_FOR_SCOPE("gpu");
[email protected]8e8bb6d2010-12-13 08:18:55305 WriteIntAttribute(
306 "vendorid",
307 GpuProcessHostUIShim::GetInstance()->gpu_info().vendor_id());
308 WriteIntAttribute(
309 "deviceid",
310 GpuProcessHostUIShim::GetInstance()->gpu_info().device_id());
[email protected]e8c287c872010-07-20 00:49:42311 }
312
313 {
initial.commit09911bf2008-07-26 23:55:29314 OPEN_ELEMENT_FOR_SCOPE("display");
315 int width = 0;
316 int height = 0;
[email protected]05f9b682008-09-29 22:18:01317 base::SysInfo::GetPrimaryDisplayDimensions(&width, &height);
initial.commit09911bf2008-07-26 23:55:29318 WriteIntAttribute("xsize", width);
319 WriteIntAttribute("ysize", height);
[email protected]05f9b682008-09-29 22:18:01320 WriteIntAttribute("screens", base::SysInfo::DisplayCount());
initial.commit09911bf2008-07-26 23:55:29321 }
322
323 {
324 OPEN_ELEMENT_FOR_SCOPE("bookmarks");
325 int num_bookmarks_on_bookmark_bar =
326 pref->GetInteger(prefs::kNumBookmarksOnBookmarkBar);
327 int num_folders_on_bookmark_bar =
328 pref->GetInteger(prefs::kNumFoldersOnBookmarkBar);
329 int num_bookmarks_in_other_bookmarks_folder =
330 pref->GetInteger(prefs::kNumBookmarksInOtherBookmarkFolder);
331 int num_folders_in_other_bookmarks_folder =
332 pref->GetInteger(prefs::kNumFoldersInOtherBookmarkFolder);
333 {
334 OPEN_ELEMENT_FOR_SCOPE("bookmarklocation");
335 WriteAttribute("name", "full-tree");
336 WriteIntAttribute("foldercount",
337 num_folders_on_bookmark_bar + num_folders_in_other_bookmarks_folder);
338 WriteIntAttribute("itemcount",
339 num_bookmarks_on_bookmark_bar +
340 num_bookmarks_in_other_bookmarks_folder);
341 }
342 {
343 OPEN_ELEMENT_FOR_SCOPE("bookmarklocation");
344 WriteAttribute("name", "toolbar");
345 WriteIntAttribute("foldercount", num_folders_on_bookmark_bar);
346 WriteIntAttribute("itemcount", num_bookmarks_on_bookmark_bar);
347 }
348 }
349
350 {
351 OPEN_ELEMENT_FOR_SCOPE("keywords");
352 WriteIntAttribute("count", pref->GetInteger(prefs::kNumKeywords));
353 }
354
355 if (profile_metrics)
356 WriteAllProfilesMetrics(*profile_metrics);
initial.commit09911bf2008-07-26 23:55:29357}
358
359void MetricsLog::WriteAllProfilesMetrics(
360 const DictionaryValue& all_profiles_metrics) {
[email protected]57ecc4b2010-08-11 03:02:51361 const std::string profile_prefix(prefs::kProfilePrefix);
initial.commit09911bf2008-07-26 23:55:29362 for (DictionaryValue::key_iterator i = all_profiles_metrics.begin_keys();
363 i != all_profiles_metrics.end_keys(); ++i) {
[email protected]e7b418b2010-07-30 19:47:47364 const std::string& key_name = *i;
initial.commit09911bf2008-07-26 23:55:29365 if (key_name.compare(0, profile_prefix.size(), profile_prefix) == 0) {
366 DictionaryValue* profile;
[email protected]4dad9ad82009-11-25 20:47:52367 if (all_profiles_metrics.GetDictionaryWithoutPathExpansion(key_name,
368 &profile))
initial.commit09911bf2008-07-26 23:55:29369 WriteProfileMetrics(key_name.substr(profile_prefix.size()), *profile);
370 }
371 }
372}
373
[email protected]e7b418b2010-07-30 19:47:47374void MetricsLog::WriteProfileMetrics(const std::string& profileidhash,
initial.commit09911bf2008-07-26 23:55:29375 const DictionaryValue& profile_metrics) {
376 OPEN_ELEMENT_FOR_SCOPE("userprofile");
[email protected]e7b418b2010-07-30 19:47:47377 WriteAttribute("profileidhash", profileidhash);
initial.commit09911bf2008-07-26 23:55:29378 for (DictionaryValue::key_iterator i = profile_metrics.begin_keys();
379 i != profile_metrics.end_keys(); ++i) {
380 Value* value;
[email protected]4dad9ad82009-11-25 20:47:52381 if (profile_metrics.GetWithoutPathExpansion(*i, &value)) {
[email protected]e7b418b2010-07-30 19:47:47382 DCHECK(*i != "id");
initial.commit09911bf2008-07-26 23:55:29383 switch (value->GetType()) {
384 case Value::TYPE_STRING: {
[email protected]5e324b72008-12-18 00:07:59385 std::string string_value;
initial.commit09911bf2008-07-26 23:55:29386 if (value->GetAsString(&string_value)) {
387 OPEN_ELEMENT_FOR_SCOPE("profileparam");
[email protected]e7b418b2010-07-30 19:47:47388 WriteAttribute("name", *i);
[email protected]5e324b72008-12-18 00:07:59389 WriteAttribute("value", string_value);
initial.commit09911bf2008-07-26 23:55:29390 }
391 break;
392 }
393
394 case Value::TYPE_BOOLEAN: {
395 bool bool_value;
396 if (value->GetAsBoolean(&bool_value)) {
397 OPEN_ELEMENT_FOR_SCOPE("profileparam");
[email protected]e7b418b2010-07-30 19:47:47398 WriteAttribute("name", *i);
initial.commit09911bf2008-07-26 23:55:29399 WriteIntAttribute("value", bool_value ? 1 : 0);
400 }
401 break;
402 }
403
404 case Value::TYPE_INTEGER: {
405 int int_value;
406 if (value->GetAsInteger(&int_value)) {
407 OPEN_ELEMENT_FOR_SCOPE("profileparam");
[email protected]e7b418b2010-07-30 19:47:47408 WriteAttribute("name", *i);
initial.commit09911bf2008-07-26 23:55:29409 WriteIntAttribute("value", int_value);
410 }
411 break;
412 }
413
414 default:
415 NOTREACHED();
416 break;
417 }
418 }
419 }
420}
421
422void MetricsLog::RecordOmniboxOpenedURL(const AutocompleteLog& log) {
423 DCHECK(!locked_);
424
[email protected]ffaf78a2008-11-12 17:38:33425 OPEN_ELEMENT_FOR_SCOPE("uielement");
initial.commit09911bf2008-07-26 23:55:29426 WriteAttribute("action", "autocomplete");
427 WriteAttribute("targetidhash", "");
428 // TODO(kochi): Properly track windows.
429 WriteIntAttribute("window", 0);
430 WriteCommonEventAttributes();
431
[email protected]ffaf78a2008-11-12 17:38:33432 {
433 OPEN_ELEMENT_FOR_SCOPE("autocomplete");
initial.commit09911bf2008-07-26 23:55:29434
[email protected]ffaf78a2008-11-12 17:38:33435 WriteIntAttribute("typedlength", static_cast<int>(log.text.length()));
436 WriteIntAttribute("selectedindex", static_cast<int>(log.selected_index));
437 WriteIntAttribute("completedlength",
438 static_cast<int>(log.inline_autocompleted_length));
[email protected]381e2992008-12-16 01:41:00439 const std::string input_type(
440 AutocompleteInput::TypeToString(log.input_type));
441 if (!input_type.empty())
442 WriteAttribute("inputtype", input_type);
initial.commit09911bf2008-07-26 23:55:29443
[email protected]ffaf78a2008-11-12 17:38:33444 for (AutocompleteResult::const_iterator i(log.result.begin());
445 i != log.result.end(); ++i) {
446 OPEN_ELEMENT_FOR_SCOPE("autocompleteitem");
447 if (i->provider)
448 WriteAttribute("provider", i->provider->name());
[email protected]381e2992008-12-16 01:41:00449 const std::string result_type(AutocompleteMatch::TypeToString(i->type));
450 if (!result_type.empty())
451 WriteAttribute("resulttype", result_type);
[email protected]ffaf78a2008-11-12 17:38:33452 WriteIntAttribute("relevance", i->relevance);
453 WriteIntAttribute("isstarred", i->starred ? 1 : 0);
454 }
initial.commit09911bf2008-07-26 23:55:29455 }
initial.commit09911bf2008-07-26 23:55:29456
457 ++num_events_;
458}