blob: cc5615da18b7aa95ec768cf97583145196c7ecbf [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]27d8778e2011-03-09 22:00:5922#include "chrome/browser/gpu_data_manager.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
[email protected]9958a322011-03-08 20:04:17101 WriteInstallElement();
[email protected]147bbc0b2009-01-06 19:37:40102
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
[email protected]c1834a92011-01-21 18:21:03112void MetricsLog::WriteStabilityElement(PrefService* pref) {
initial.commit09911bf2008-07-26 23:55:29113 DCHECK(!locked_);
114
initial.commit09911bf2008-07-26 23:55:29115 DCHECK(pref);
116
117 // Get stability attributes out of Local State, zeroing out stored values.
118 // NOTE: This could lead to some data loss if this report isn't successfully
119 // sent, but that's true for all the metrics.
120
[email protected]ffaf78a2008-11-12 17:38:33121 OPEN_ELEMENT_FOR_SCOPE("stability");
[email protected]147bbc0b2009-01-06 19:37:40122 WriteRequiredStabilityAttributes(pref);
123 WriteRealtimeStabilityAttributes(pref);
initial.commit09911bf2008-07-26 23:55:29124
[email protected]0b33f80b2008-12-17 21:34:36125 // TODO(jar): The following are all optional, so we *could* optimize them for
126 // values of zero (and not include them).
[email protected]8e674e42008-07-30 16:05:48127 WriteIntAttribute("incompleteshutdowncount",
128 pref->GetInteger(
129 prefs::kStabilityIncompleteSessionEndCount));
130 pref->SetInteger(prefs::kStabilityIncompleteSessionEndCount, 0);
[email protected]0b33f80b2008-12-17 21:34:36131
132
[email protected]e73c01972008-08-13 00:18:24133 WriteIntAttribute("breakpadregistrationok",
134 pref->GetInteger(prefs::kStabilityBreakpadRegistrationSuccess));
135 pref->SetInteger(prefs::kStabilityBreakpadRegistrationSuccess, 0);
136 WriteIntAttribute("breakpadregistrationfail",
137 pref->GetInteger(prefs::kStabilityBreakpadRegistrationFail));
138 pref->SetInteger(prefs::kStabilityBreakpadRegistrationFail, 0);
139 WriteIntAttribute("debuggerpresent",
140 pref->GetInteger(prefs::kStabilityDebuggerPresent));
141 pref->SetInteger(prefs::kStabilityDebuggerPresent, 0);
142 WriteIntAttribute("debuggernotpresent",
143 pref->GetInteger(prefs::kStabilityDebuggerNotPresent));
144 pref->SetInteger(prefs::kStabilityDebuggerNotPresent, 0);
initial.commit09911bf2008-07-26 23:55:29145
[email protected]147bbc0b2009-01-06 19:37:40146 WritePluginStabilityElements(pref);
147}
148
149void MetricsLog::WritePluginStabilityElements(PrefService* pref) {
150 // Now log plugin stability info.
initial.commit09911bf2008-07-26 23:55:29151 const ListValue* plugin_stats_list = pref->GetList(
152 prefs::kStabilityPluginStats);
153 if (plugin_stats_list) {
[email protected]ffaf78a2008-11-12 17:38:33154 OPEN_ELEMENT_FOR_SCOPE("plugins");
initial.commit09911bf2008-07-26 23:55:29155 for (ListValue::const_iterator iter = plugin_stats_list->begin();
156 iter != plugin_stats_list->end(); ++iter) {
157 if (!(*iter)->IsType(Value::TYPE_DICTIONARY)) {
158 NOTREACHED();
159 continue;
160 }
161 DictionaryValue* plugin_dict = static_cast<DictionaryValue*>(*iter);
162
[email protected]57ecc4b2010-08-11 03:02:51163 std::string plugin_name;
[email protected]8e50b602009-03-03 22:59:43164 plugin_dict->GetString(prefs::kStabilityPluginName, &plugin_name);
initial.commit09911bf2008-07-26 23:55:29165
[email protected]ffaf78a2008-11-12 17:38:33166 OPEN_ELEMENT_FOR_SCOPE("pluginstability");
[email protected]a27a9382009-02-11 23:55:10167 // Use "filename" instead of "name", otherwise we need to update the
168 // UMA servers.
[email protected]57ecc4b2010-08-11 03:02:51169 WriteAttribute("filename", CreateBase64Hash(plugin_name));
initial.commit09911bf2008-07-26 23:55:29170
171 int launches = 0;
[email protected]8e50b602009-03-03 22:59:43172 plugin_dict->GetInteger(prefs::kStabilityPluginLaunches, &launches);
initial.commit09911bf2008-07-26 23:55:29173 WriteIntAttribute("launchcount", launches);
174
175 int instances = 0;
[email protected]8e50b602009-03-03 22:59:43176 plugin_dict->GetInteger(prefs::kStabilityPluginInstances, &instances);
initial.commit09911bf2008-07-26 23:55:29177 WriteIntAttribute("instancecount", instances);
178
179 int crashes = 0;
[email protected]8e50b602009-03-03 22:59:43180 plugin_dict->GetInteger(prefs::kStabilityPluginCrashes, &crashes);
initial.commit09911bf2008-07-26 23:55:29181 WriteIntAttribute("crashcount", crashes);
initial.commit09911bf2008-07-26 23:55:29182 }
183
184 pref->ClearPref(prefs::kStabilityPluginStats);
initial.commit09911bf2008-07-26 23:55:29185 }
initial.commit09911bf2008-07-26 23:55:29186}
187
[email protected]147bbc0b2009-01-06 19:37:40188void MetricsLog::WriteRequiredStabilityAttributes(PrefService* pref) {
[email protected]0b33f80b2008-12-17 21:34:36189 // The server refuses data that doesn't have certain values. crashcount and
190 // launchcount are currently "required" in the "stability" group.
191 WriteIntAttribute("launchcount",
192 pref->GetInteger(prefs::kStabilityLaunchCount));
193 pref->SetInteger(prefs::kStabilityLaunchCount, 0);
194 WriteIntAttribute("crashcount",
195 pref->GetInteger(prefs::kStabilityCrashCount));
196 pref->SetInteger(prefs::kStabilityCrashCount, 0);
197}
198
[email protected]147bbc0b2009-01-06 19:37:40199void MetricsLog::WriteRealtimeStabilityAttributes(PrefService* pref) {
[email protected]0b33f80b2008-12-17 21:34:36200 // Update the stats which are critical for real-time stability monitoring.
201 // Since these are "optional," only list ones that are non-zero, as the counts
202 // are aggergated (summed) server side.
203
204 int count = pref->GetInteger(prefs::kStabilityPageLoadCount);
205 if (count) {
206 WriteIntAttribute("pageloadcount", count);
207 pref->SetInteger(prefs::kStabilityPageLoadCount, 0);
208 }
209
210 count = pref->GetInteger(prefs::kStabilityRendererCrashCount);
211 if (count) {
212 WriteIntAttribute("renderercrashcount", count);
213 pref->SetInteger(prefs::kStabilityRendererCrashCount, 0);
214 }
215
[email protected]1f085622009-12-04 05:33:45216 count = pref->GetInteger(prefs::kStabilityExtensionRendererCrashCount);
217 if (count) {
218 WriteIntAttribute("extensionrenderercrashcount", count);
219 pref->SetInteger(prefs::kStabilityExtensionRendererCrashCount, 0);
220 }
221
[email protected]0b33f80b2008-12-17 21:34:36222 count = pref->GetInteger(prefs::kStabilityRendererHangCount);
223 if (count) {
224 WriteIntAttribute("rendererhangcount", count);
225 pref->SetInteger(prefs::kStabilityRendererHangCount, 0);
226 }
[email protected]1f085622009-12-04 05:33:45227
228 count = pref->GetInteger(prefs::kStabilityChildProcessCrashCount);
229 if (count) {
230 WriteIntAttribute("childprocesscrashcount", count);
231 pref->SetInteger(prefs::kStabilityChildProcessCrashCount, 0);
232 }
[email protected]9165f742010-03-10 22:55:01233
[email protected]c1834a92011-01-21 18:21:03234#if defined(OS_CHROMEOS)
235 count = pref->GetInteger(prefs::kStabilityOtherUserCrashCount);
236 if (count) {
237 // TODO(kmixter): Write attribute once log server supports it
238 // and remove warning log.
239 // WriteIntAttribute("otherusercrashcount", count);
240 LOG(WARNING) << "Not yet able to send otherusercrashcount="
241 << count;
242 pref->SetInteger(prefs::kStabilityOtherUserCrashCount, 0);
243 }
244
245 count = pref->GetInteger(prefs::kStabilityKernelCrashCount);
246 if (count) {
247 // TODO(kmixter): Write attribute once log server supports it
248 // and remove warning log.
249 // WriteIntAttribute("kernelcrashcount", count);
250 LOG(WARNING) << "Not yet able to send kernelcrashcount="
251 << count;
252 pref->SetInteger(prefs::kStabilityKernelCrashCount, 0);
253 }
254
255 count = pref->GetInteger(prefs::kStabilitySystemUncleanShutdownCount);
256 if (count) {
257 // TODO(kmixter): Write attribute once log server supports it
258 // and remove warning log.
259 // WriteIntAttribute("systemuncleanshutdowns", count);
260 LOG(WARNING) << "Not yet able to send systemuncleanshutdowns="
261 << count;
262 pref->SetInteger(prefs::kStabilitySystemUncleanShutdownCount, 0);
263 }
264#endif // OS_CHROMEOS
265
[email protected]9165f742010-03-10 22:55:01266 int64 recent_duration = GetIncrementalUptime(pref);
267 if (recent_duration)
268 WriteInt64Attribute("uptimesec", recent_duration);
[email protected]0b33f80b2008-12-17 21:34:36269}
270
initial.commit09911bf2008-07-26 23:55:29271void MetricsLog::WritePluginList(
[email protected]191eb3f72010-12-21 06:27:50272 const std::vector<webkit::npapi::WebPluginInfo>& plugin_list) {
initial.commit09911bf2008-07-26 23:55:29273 DCHECK(!locked_);
274
[email protected]ffaf78a2008-11-12 17:38:33275 OPEN_ELEMENT_FOR_SCOPE("plugins");
initial.commit09911bf2008-07-26 23:55:29276
[email protected]191eb3f72010-12-21 06:27:50277 for (std::vector<webkit::npapi::WebPluginInfo>::const_iterator iter =
278 plugin_list.begin();
initial.commit09911bf2008-07-26 23:55:29279 iter != plugin_list.end(); ++iter) {
[email protected]ffaf78a2008-11-12 17:38:33280 OPEN_ELEMENT_FOR_SCOPE("plugin");
initial.commit09911bf2008-07-26 23:55:29281
282 // Plugin name and filename are hashed for the privacy of those
283 // testing unreleased new extensions.
[email protected]c9d811372010-06-23 21:44:57284 WriteAttribute("name", CreateBase64Hash(UTF16ToUTF8(iter->name)));
[email protected]0abb1652011-02-07 23:37:55285 std::string filename_bytes =
286#if defined(OS_WIN)
287 UTF16ToUTF8(iter->path.BaseName().value());
288#else
289 iter->path.BaseName().value();
290#endif
291 WriteAttribute("filename", CreateBase64Hash(filename_bytes));
[email protected]c9d811372010-06-23 21:44:57292 WriteAttribute("version", UTF16ToUTF8(iter->version));
initial.commit09911bf2008-07-26 23:55:29293 }
initial.commit09911bf2008-07-26 23:55:29294}
295
[email protected]147bbc0b2009-01-06 19:37:40296void MetricsLog::WriteInstallElement() {
297 OPEN_ELEMENT_FOR_SCOPE("install");
298 WriteAttribute("installdate", GetInstallDate());
299 WriteIntAttribute("buildid", 0); // We're using appversion instead.
[email protected]147bbc0b2009-01-06 19:37:40300}
301
initial.commit09911bf2008-07-26 23:55:29302void MetricsLog::RecordEnvironment(
[email protected]191eb3f72010-12-21 06:27:50303 const std::vector<webkit::npapi::WebPluginInfo>& plugin_list,
initial.commit09911bf2008-07-26 23:55:29304 const DictionaryValue* profile_metrics) {
305 DCHECK(!locked_);
306
307 PrefService* pref = g_browser_process->local_state();
308
[email protected]ffaf78a2008-11-12 17:38:33309 OPEN_ELEMENT_FOR_SCOPE("profile");
initial.commit09911bf2008-07-26 23:55:29310 WriteCommonEventAttributes();
311
[email protected]147bbc0b2009-01-06 19:37:40312 WriteInstallElement();
initial.commit09911bf2008-07-26 23:55:29313
314 WritePluginList(plugin_list);
315
[email protected]c1834a92011-01-21 18:21:03316 WriteStabilityElement(pref);
initial.commit09911bf2008-07-26 23:55:29317
318 {
319 OPEN_ELEMENT_FOR_SCOPE("cpu");
[email protected]05f9b682008-09-29 22:18:01320 WriteAttribute("arch", base::SysInfo::CPUArchitecture());
initial.commit09911bf2008-07-26 23:55:29321 }
322
323 {
initial.commit09911bf2008-07-26 23:55:29324 OPEN_ELEMENT_FOR_SCOPE("memory");
[email protected]ed6fc352008-09-18 12:44:40325 WriteIntAttribute("mb", base::SysInfo::AmountOfPhysicalMemoryMB());
[email protected]d1be67b2008-11-19 20:28:38326#if defined(OS_WIN)
327 WriteIntAttribute("dllbase", reinterpret_cast<int>(&__ImageBase));
328#endif
initial.commit09911bf2008-07-26 23:55:29329 }
330
331 {
332 OPEN_ELEMENT_FOR_SCOPE("os");
333 WriteAttribute("name",
[email protected]05f9b682008-09-29 22:18:01334 base::SysInfo::OperatingSystemName());
initial.commit09911bf2008-07-26 23:55:29335 WriteAttribute("version",
[email protected]05f9b682008-09-29 22:18:01336 base::SysInfo::OperatingSystemVersion());
initial.commit09911bf2008-07-26 23:55:29337 }
338
339 {
[email protected]e8c287c872010-07-20 00:49:42340 OPEN_ELEMENT_FOR_SCOPE("gpu");
[email protected]27d8778e2011-03-09 22:00:59341 GpuDataManager* gpu_data_manager = GpuDataManager::GetInstance();
342 if (gpu_data_manager) {
343 WriteIntAttribute("vendorid", gpu_data_manager->gpu_info().vendor_id);
344 WriteIntAttribute("deviceid", gpu_data_manager->gpu_info().device_id);
[email protected]06b2fc92011-02-22 22:00:40345 }
[email protected]e8c287c872010-07-20 00:49:42346 }
347
348 {
initial.commit09911bf2008-07-26 23:55:29349 OPEN_ELEMENT_FOR_SCOPE("display");
350 int width = 0;
351 int height = 0;
[email protected]05f9b682008-09-29 22:18:01352 base::SysInfo::GetPrimaryDisplayDimensions(&width, &height);
initial.commit09911bf2008-07-26 23:55:29353 WriteIntAttribute("xsize", width);
354 WriteIntAttribute("ysize", height);
[email protected]05f9b682008-09-29 22:18:01355 WriteIntAttribute("screens", base::SysInfo::DisplayCount());
initial.commit09911bf2008-07-26 23:55:29356 }
357
358 {
359 OPEN_ELEMENT_FOR_SCOPE("bookmarks");
360 int num_bookmarks_on_bookmark_bar =
361 pref->GetInteger(prefs::kNumBookmarksOnBookmarkBar);
362 int num_folders_on_bookmark_bar =
363 pref->GetInteger(prefs::kNumFoldersOnBookmarkBar);
364 int num_bookmarks_in_other_bookmarks_folder =
365 pref->GetInteger(prefs::kNumBookmarksInOtherBookmarkFolder);
366 int num_folders_in_other_bookmarks_folder =
367 pref->GetInteger(prefs::kNumFoldersInOtherBookmarkFolder);
368 {
369 OPEN_ELEMENT_FOR_SCOPE("bookmarklocation");
370 WriteAttribute("name", "full-tree");
371 WriteIntAttribute("foldercount",
372 num_folders_on_bookmark_bar + num_folders_in_other_bookmarks_folder);
373 WriteIntAttribute("itemcount",
374 num_bookmarks_on_bookmark_bar +
375 num_bookmarks_in_other_bookmarks_folder);
376 }
377 {
378 OPEN_ELEMENT_FOR_SCOPE("bookmarklocation");
379 WriteAttribute("name", "toolbar");
380 WriteIntAttribute("foldercount", num_folders_on_bookmark_bar);
381 WriteIntAttribute("itemcount", num_bookmarks_on_bookmark_bar);
382 }
383 }
384
385 {
386 OPEN_ELEMENT_FOR_SCOPE("keywords");
387 WriteIntAttribute("count", pref->GetInteger(prefs::kNumKeywords));
388 }
389
390 if (profile_metrics)
391 WriteAllProfilesMetrics(*profile_metrics);
initial.commit09911bf2008-07-26 23:55:29392}
393
394void MetricsLog::WriteAllProfilesMetrics(
395 const DictionaryValue& all_profiles_metrics) {
[email protected]57ecc4b2010-08-11 03:02:51396 const std::string profile_prefix(prefs::kProfilePrefix);
initial.commit09911bf2008-07-26 23:55:29397 for (DictionaryValue::key_iterator i = all_profiles_metrics.begin_keys();
398 i != all_profiles_metrics.end_keys(); ++i) {
[email protected]e7b418b2010-07-30 19:47:47399 const std::string& key_name = *i;
initial.commit09911bf2008-07-26 23:55:29400 if (key_name.compare(0, profile_prefix.size(), profile_prefix) == 0) {
401 DictionaryValue* profile;
[email protected]4dad9ad82009-11-25 20:47:52402 if (all_profiles_metrics.GetDictionaryWithoutPathExpansion(key_name,
403 &profile))
initial.commit09911bf2008-07-26 23:55:29404 WriteProfileMetrics(key_name.substr(profile_prefix.size()), *profile);
405 }
406 }
407}
408
[email protected]e7b418b2010-07-30 19:47:47409void MetricsLog::WriteProfileMetrics(const std::string& profileidhash,
initial.commit09911bf2008-07-26 23:55:29410 const DictionaryValue& profile_metrics) {
411 OPEN_ELEMENT_FOR_SCOPE("userprofile");
[email protected]e7b418b2010-07-30 19:47:47412 WriteAttribute("profileidhash", profileidhash);
initial.commit09911bf2008-07-26 23:55:29413 for (DictionaryValue::key_iterator i = profile_metrics.begin_keys();
414 i != profile_metrics.end_keys(); ++i) {
415 Value* value;
[email protected]4dad9ad82009-11-25 20:47:52416 if (profile_metrics.GetWithoutPathExpansion(*i, &value)) {
[email protected]e7b418b2010-07-30 19:47:47417 DCHECK(*i != "id");
initial.commit09911bf2008-07-26 23:55:29418 switch (value->GetType()) {
419 case Value::TYPE_STRING: {
[email protected]5e324b72008-12-18 00:07:59420 std::string string_value;
initial.commit09911bf2008-07-26 23:55:29421 if (value->GetAsString(&string_value)) {
422 OPEN_ELEMENT_FOR_SCOPE("profileparam");
[email protected]e7b418b2010-07-30 19:47:47423 WriteAttribute("name", *i);
[email protected]5e324b72008-12-18 00:07:59424 WriteAttribute("value", string_value);
initial.commit09911bf2008-07-26 23:55:29425 }
426 break;
427 }
428
429 case Value::TYPE_BOOLEAN: {
430 bool bool_value;
431 if (value->GetAsBoolean(&bool_value)) {
432 OPEN_ELEMENT_FOR_SCOPE("profileparam");
[email protected]e7b418b2010-07-30 19:47:47433 WriteAttribute("name", *i);
initial.commit09911bf2008-07-26 23:55:29434 WriteIntAttribute("value", bool_value ? 1 : 0);
435 }
436 break;
437 }
438
439 case Value::TYPE_INTEGER: {
440 int int_value;
441 if (value->GetAsInteger(&int_value)) {
442 OPEN_ELEMENT_FOR_SCOPE("profileparam");
[email protected]e7b418b2010-07-30 19:47:47443 WriteAttribute("name", *i);
initial.commit09911bf2008-07-26 23:55:29444 WriteIntAttribute("value", int_value);
445 }
446 break;
447 }
448
449 default:
450 NOTREACHED();
451 break;
452 }
453 }
454 }
455}
456
457void MetricsLog::RecordOmniboxOpenedURL(const AutocompleteLog& log) {
458 DCHECK(!locked_);
459
[email protected]ffaf78a2008-11-12 17:38:33460 OPEN_ELEMENT_FOR_SCOPE("uielement");
initial.commit09911bf2008-07-26 23:55:29461 WriteAttribute("action", "autocomplete");
462 WriteAttribute("targetidhash", "");
463 // TODO(kochi): Properly track windows.
464 WriteIntAttribute("window", 0);
465 WriteCommonEventAttributes();
466
[email protected]ffaf78a2008-11-12 17:38:33467 {
468 OPEN_ELEMENT_FOR_SCOPE("autocomplete");
initial.commit09911bf2008-07-26 23:55:29469
[email protected]ffaf78a2008-11-12 17:38:33470 WriteIntAttribute("typedlength", static_cast<int>(log.text.length()));
471 WriteIntAttribute("selectedindex", static_cast<int>(log.selected_index));
472 WriteIntAttribute("completedlength",
473 static_cast<int>(log.inline_autocompleted_length));
[email protected]381e2992008-12-16 01:41:00474 const std::string input_type(
475 AutocompleteInput::TypeToString(log.input_type));
476 if (!input_type.empty())
477 WriteAttribute("inputtype", input_type);
initial.commit09911bf2008-07-26 23:55:29478
[email protected]ffaf78a2008-11-12 17:38:33479 for (AutocompleteResult::const_iterator i(log.result.begin());
480 i != log.result.end(); ++i) {
481 OPEN_ELEMENT_FOR_SCOPE("autocompleteitem");
482 if (i->provider)
483 WriteAttribute("provider", i->provider->name());
[email protected]381e2992008-12-16 01:41:00484 const std::string result_type(AutocompleteMatch::TypeToString(i->type));
485 if (!result_type.empty())
486 WriteAttribute("resulttype", result_type);
[email protected]ffaf78a2008-11-12 17:38:33487 WriteIntAttribute("relevance", i->relevance);
488 WriteIntAttribute("isstarred", i->starred ? 1 : 0);
489 }
initial.commit09911bf2008-07-26 23:55:29490 }
initial.commit09911bf2008-07-26 23:55:29491
492 ++num_events_;
493}