blob: ce8263460afc01b5c179b92dc2c510668ac7304c [file] [log] [blame]
[email protected]3b63f8f42011-03-28 01:54:151// Copyright (c) 2011 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]3b63f8f42011-03-28 01:54:1512#include "base/memory/scoped_ptr.h"
[email protected]85ed9d42010-06-08 22:37:4413#include "base/perftimer.h"
initial.commit09911bf2008-07-26 23:55:2914#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]e9c0ba72011-06-15 15:46:2622#include "chrome/browser/metrics/display_utils.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]d9f37932011-05-09 20:09:2427#include "content/browser/gpu/gpu_data_manager.h"
[email protected]46072d42008-07-28 14:49:3528#include "googleurl/src/gurl.h"
[email protected]91d9f3d2011-08-14 05:24:4429#include "webkit/plugins/webplugininfo.h"
initial.commit09911bf2008-07-26 23:55:2930
31#define OPEN_ELEMENT_FOR_SCOPE(name) ScopedElement scoped_element(this, name)
32
[email protected]d1be67b2008-11-19 20:28:3833// http://blogs.msdn.com/oldnewthing/archive/2004/10/25/247180.aspx
34#if defined(OS_WIN)
35extern "C" IMAGE_DOS_HEADER __ImageBase;
36#endif
37
[email protected]1226abb2010-06-10 18:01:2838MetricsLog::MetricsLog(const std::string& client_id, int session_id)
39 : MetricsLogBase(client_id, session_id, MetricsLog::GetVersionString()) {}
[email protected]5ed7d4572009-12-23 17:42:4140
[email protected]1226abb2010-06-10 18:01:2841MetricsLog::~MetricsLog() {}
initial.commit09911bf2008-07-26 23:55:2942
43// static
44void MetricsLog::RegisterPrefs(PrefService* local_state) {
45 local_state->RegisterListPref(prefs::kStabilityPluginStats);
initial.commit09911bf2008-07-26 23:55:2946}
47
[email protected]9165f742010-03-10 22:55:0148int64 MetricsLog::GetIncrementalUptime(PrefService* pref) {
49 base::TimeTicks now = base::TimeTicks::Now();
50 static base::TimeTicks last_updated_time(now);
51 int64 incremental_time = (now - last_updated_time).InSeconds();
52 last_updated_time = now;
53
54 if (incremental_time > 0) {
55 int64 metrics_uptime = pref->GetInt64(prefs::kUninstallMetricsUptimeSec);
56 metrics_uptime += incremental_time;
57 pref->SetInt64(prefs::kUninstallMetricsUptimeSec, metrics_uptime);
58 }
59
60 return incremental_time;
61}
62
initial.commit09911bf2008-07-26 23:55:2963std::string MetricsLog::GetInstallDate() const {
64 PrefService* pref = g_browser_process->local_state();
65 if (pref) {
[email protected]ddd231e2010-06-29 20:35:1966 return pref->GetString(prefs::kMetricsClientIDTimestamp);
initial.commit09911bf2008-07-26 23:55:2967 } else {
68 NOTREACHED();
69 return "0";
70 }
71}
72
[email protected]1226abb2010-06-10 18:01:2873// static
74std::string MetricsLog::GetVersionString() {
[email protected]0211f57e2010-08-27 20:28:4275 chrome::VersionInfo version_info;
[email protected]30c91802010-12-18 00:40:1776 if (!version_info.is_valid()) {
77 NOTREACHED() << "Unable to retrieve version info.";
78 return std::string();
79 }
80
[email protected]0211f57e2010-08-27 20:28:4281 std::string version = version_info.Version();
82 if (!version_extension_.empty())
83 version += version_extension_;
84 if (!version_info.IsOfficialBuild())
85 version.append("-devel");
86 return version;
[email protected]1226abb2010-06-10 18:01:2887}
88
[email protected]dec76e802010-09-23 22:43:5389MetricsLog* MetricsLog::AsMetricsLog() {
90 return this;
91}
92
[email protected]0b33f80b2008-12-17 21:34:3693void MetricsLog::RecordIncrementalStabilityElements() {
94 DCHECK(!locked_);
95
96 PrefService* pref = g_browser_process->local_state();
97 DCHECK(pref);
98
[email protected]147bbc0b2009-01-06 19:37:4099 OPEN_ELEMENT_FOR_SCOPE("profile");
100 WriteCommonEventAttributes();
101
[email protected]9958a322011-03-08 20:04:17102 WriteInstallElement();
[email protected]147bbc0b2009-01-06 19:37:40103
104 {
105 OPEN_ELEMENT_FOR_SCOPE("stability"); // Minimal set of stability elements.
106 WriteRequiredStabilityAttributes(pref);
107 WriteRealtimeStabilityAttributes(pref);
108
109 WritePluginStabilityElements(pref);
110 }
[email protected]0b33f80b2008-12-17 21:34:36111}
112
[email protected]c1834a92011-01-21 18:21:03113void MetricsLog::WriteStabilityElement(PrefService* pref) {
initial.commit09911bf2008-07-26 23:55:29114 DCHECK(!locked_);
115
initial.commit09911bf2008-07-26 23:55:29116 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
[email protected]c1834a92011-01-21 18:21:03235#if defined(OS_CHROMEOS)
236 count = pref->GetInteger(prefs::kStabilityOtherUserCrashCount);
237 if (count) {
238 // TODO(kmixter): Write attribute once log server supports it
239 // and remove warning log.
240 // WriteIntAttribute("otherusercrashcount", count);
241 LOG(WARNING) << "Not yet able to send otherusercrashcount="
242 << count;
243 pref->SetInteger(prefs::kStabilityOtherUserCrashCount, 0);
244 }
245
246 count = pref->GetInteger(prefs::kStabilityKernelCrashCount);
247 if (count) {
248 // TODO(kmixter): Write attribute once log server supports it
249 // and remove warning log.
250 // WriteIntAttribute("kernelcrashcount", count);
251 LOG(WARNING) << "Not yet able to send kernelcrashcount="
252 << count;
253 pref->SetInteger(prefs::kStabilityKernelCrashCount, 0);
254 }
255
256 count = pref->GetInteger(prefs::kStabilitySystemUncleanShutdownCount);
257 if (count) {
258 // TODO(kmixter): Write attribute once log server supports it
259 // and remove warning log.
260 // WriteIntAttribute("systemuncleanshutdowns", count);
261 LOG(WARNING) << "Not yet able to send systemuncleanshutdowns="
262 << count;
263 pref->SetInteger(prefs::kStabilitySystemUncleanShutdownCount, 0);
264 }
265#endif // OS_CHROMEOS
266
[email protected]9165f742010-03-10 22:55:01267 int64 recent_duration = GetIncrementalUptime(pref);
268 if (recent_duration)
269 WriteInt64Attribute("uptimesec", recent_duration);
[email protected]0b33f80b2008-12-17 21:34:36270}
271
initial.commit09911bf2008-07-26 23:55:29272void MetricsLog::WritePluginList(
[email protected]91d9f3d2011-08-14 05:24:44273 const std::vector<webkit::WebPluginInfo>& plugin_list) {
initial.commit09911bf2008-07-26 23:55:29274 DCHECK(!locked_);
275
[email protected]ffaf78a2008-11-12 17:38:33276 OPEN_ELEMENT_FOR_SCOPE("plugins");
initial.commit09911bf2008-07-26 23:55:29277
[email protected]91d9f3d2011-08-14 05:24:44278 for (std::vector<webkit::WebPluginInfo>::const_iterator iter =
[email protected]191eb3f72010-12-21 06:27:50279 plugin_list.begin();
initial.commit09911bf2008-07-26 23:55:29280 iter != plugin_list.end(); ++iter) {
[email protected]ffaf78a2008-11-12 17:38:33281 OPEN_ELEMENT_FOR_SCOPE("plugin");
initial.commit09911bf2008-07-26 23:55:29282
283 // Plugin name and filename are hashed for the privacy of those
284 // testing unreleased new extensions.
[email protected]c9d811372010-06-23 21:44:57285 WriteAttribute("name", CreateBase64Hash(UTF16ToUTF8(iter->name)));
[email protected]0abb1652011-02-07 23:37:55286 std::string filename_bytes =
287#if defined(OS_WIN)
288 UTF16ToUTF8(iter->path.BaseName().value());
289#else
290 iter->path.BaseName().value();
291#endif
292 WriteAttribute("filename", CreateBase64Hash(filename_bytes));
[email protected]c9d811372010-06-23 21:44:57293 WriteAttribute("version", UTF16ToUTF8(iter->version));
[email protected]91d9f3d2011-08-14 05:24:44294 WriteIntAttribute("disabled", !webkit::IsPluginEnabled(*iter));
initial.commit09911bf2008-07-26 23:55:29295 }
initial.commit09911bf2008-07-26 23:55:29296}
297
[email protected]147bbc0b2009-01-06 19:37:40298void MetricsLog::WriteInstallElement() {
299 OPEN_ELEMENT_FOR_SCOPE("install");
300 WriteAttribute("installdate", GetInstallDate());
301 WriteIntAttribute("buildid", 0); // We're using appversion instead.
[email protected]147bbc0b2009-01-06 19:37:40302}
303
initial.commit09911bf2008-07-26 23:55:29304void MetricsLog::RecordEnvironment(
[email protected]91d9f3d2011-08-14 05:24:44305 const std::vector<webkit::WebPluginInfo>& plugin_list,
initial.commit09911bf2008-07-26 23:55:29306 const DictionaryValue* profile_metrics) {
307 DCHECK(!locked_);
308
309 PrefService* pref = g_browser_process->local_state();
310
[email protected]ffaf78a2008-11-12 17:38:33311 OPEN_ELEMENT_FOR_SCOPE("profile");
initial.commit09911bf2008-07-26 23:55:29312 WriteCommonEventAttributes();
313
[email protected]147bbc0b2009-01-06 19:37:40314 WriteInstallElement();
initial.commit09911bf2008-07-26 23:55:29315
316 WritePluginList(plugin_list);
317
[email protected]c1834a92011-01-21 18:21:03318 WriteStabilityElement(pref);
initial.commit09911bf2008-07-26 23:55:29319
320 {
321 OPEN_ELEMENT_FOR_SCOPE("cpu");
[email protected]05f9b682008-09-29 22:18:01322 WriteAttribute("arch", base::SysInfo::CPUArchitecture());
initial.commit09911bf2008-07-26 23:55:29323 }
324
325 {
initial.commit09911bf2008-07-26 23:55:29326 OPEN_ELEMENT_FOR_SCOPE("memory");
[email protected]ed6fc352008-09-18 12:44:40327 WriteIntAttribute("mb", base::SysInfo::AmountOfPhysicalMemoryMB());
[email protected]d1be67b2008-11-19 20:28:38328#if defined(OS_WIN)
329 WriteIntAttribute("dllbase", reinterpret_cast<int>(&__ImageBase));
330#endif
initial.commit09911bf2008-07-26 23:55:29331 }
332
333 {
334 OPEN_ELEMENT_FOR_SCOPE("os");
335 WriteAttribute("name",
[email protected]05f9b682008-09-29 22:18:01336 base::SysInfo::OperatingSystemName());
initial.commit09911bf2008-07-26 23:55:29337 WriteAttribute("version",
[email protected]05f9b682008-09-29 22:18:01338 base::SysInfo::OperatingSystemVersion());
initial.commit09911bf2008-07-26 23:55:29339 }
340
341 {
[email protected]e8c287c872010-07-20 00:49:42342 OPEN_ELEMENT_FOR_SCOPE("gpu");
[email protected]27d8778e2011-03-09 22:00:59343 GpuDataManager* gpu_data_manager = GpuDataManager::GetInstance();
344 if (gpu_data_manager) {
345 WriteIntAttribute("vendorid", gpu_data_manager->gpu_info().vendor_id);
346 WriteIntAttribute("deviceid", gpu_data_manager->gpu_info().device_id);
[email protected]06b2fc92011-02-22 22:00:40347 }
[email protected]e8c287c872010-07-20 00:49:42348 }
349
350 {
initial.commit09911bf2008-07-26 23:55:29351 OPEN_ELEMENT_FOR_SCOPE("display");
352 int width = 0;
353 int height = 0;
[email protected]e9c0ba72011-06-15 15:46:26354 DisplayUtils::GetPrimaryDisplayDimensions(&width, &height);
initial.commit09911bf2008-07-26 23:55:29355 WriteIntAttribute("xsize", width);
356 WriteIntAttribute("ysize", height);
[email protected]e9c0ba72011-06-15 15:46:26357 WriteIntAttribute("screens", DisplayUtils::GetDisplayCount());
initial.commit09911bf2008-07-26 23:55:29358 }
359
360 {
361 OPEN_ELEMENT_FOR_SCOPE("bookmarks");
362 int num_bookmarks_on_bookmark_bar =
363 pref->GetInteger(prefs::kNumBookmarksOnBookmarkBar);
364 int num_folders_on_bookmark_bar =
365 pref->GetInteger(prefs::kNumFoldersOnBookmarkBar);
366 int num_bookmarks_in_other_bookmarks_folder =
367 pref->GetInteger(prefs::kNumBookmarksInOtherBookmarkFolder);
368 int num_folders_in_other_bookmarks_folder =
369 pref->GetInteger(prefs::kNumFoldersInOtherBookmarkFolder);
370 {
371 OPEN_ELEMENT_FOR_SCOPE("bookmarklocation");
372 WriteAttribute("name", "full-tree");
373 WriteIntAttribute("foldercount",
374 num_folders_on_bookmark_bar + num_folders_in_other_bookmarks_folder);
375 WriteIntAttribute("itemcount",
376 num_bookmarks_on_bookmark_bar +
377 num_bookmarks_in_other_bookmarks_folder);
378 }
379 {
380 OPEN_ELEMENT_FOR_SCOPE("bookmarklocation");
381 WriteAttribute("name", "toolbar");
382 WriteIntAttribute("foldercount", num_folders_on_bookmark_bar);
383 WriteIntAttribute("itemcount", num_bookmarks_on_bookmark_bar);
384 }
385 }
386
387 {
388 OPEN_ELEMENT_FOR_SCOPE("keywords");
389 WriteIntAttribute("count", pref->GetInteger(prefs::kNumKeywords));
390 }
391
392 if (profile_metrics)
393 WriteAllProfilesMetrics(*profile_metrics);
initial.commit09911bf2008-07-26 23:55:29394}
395
396void MetricsLog::WriteAllProfilesMetrics(
397 const DictionaryValue& all_profiles_metrics) {
[email protected]57ecc4b2010-08-11 03:02:51398 const std::string profile_prefix(prefs::kProfilePrefix);
initial.commit09911bf2008-07-26 23:55:29399 for (DictionaryValue::key_iterator i = all_profiles_metrics.begin_keys();
400 i != all_profiles_metrics.end_keys(); ++i) {
[email protected]e7b418b2010-07-30 19:47:47401 const std::string& key_name = *i;
initial.commit09911bf2008-07-26 23:55:29402 if (key_name.compare(0, profile_prefix.size(), profile_prefix) == 0) {
403 DictionaryValue* profile;
[email protected]4dad9ad82009-11-25 20:47:52404 if (all_profiles_metrics.GetDictionaryWithoutPathExpansion(key_name,
405 &profile))
initial.commit09911bf2008-07-26 23:55:29406 WriteProfileMetrics(key_name.substr(profile_prefix.size()), *profile);
407 }
408 }
409}
410
[email protected]e7b418b2010-07-30 19:47:47411void MetricsLog::WriteProfileMetrics(const std::string& profileidhash,
initial.commit09911bf2008-07-26 23:55:29412 const DictionaryValue& profile_metrics) {
413 OPEN_ELEMENT_FOR_SCOPE("userprofile");
[email protected]e7b418b2010-07-30 19:47:47414 WriteAttribute("profileidhash", profileidhash);
initial.commit09911bf2008-07-26 23:55:29415 for (DictionaryValue::key_iterator i = profile_metrics.begin_keys();
416 i != profile_metrics.end_keys(); ++i) {
417 Value* value;
[email protected]4dad9ad82009-11-25 20:47:52418 if (profile_metrics.GetWithoutPathExpansion(*i, &value)) {
[email protected]e7b418b2010-07-30 19:47:47419 DCHECK(*i != "id");
initial.commit09911bf2008-07-26 23:55:29420 switch (value->GetType()) {
421 case Value::TYPE_STRING: {
[email protected]5e324b72008-12-18 00:07:59422 std::string string_value;
initial.commit09911bf2008-07-26 23:55:29423 if (value->GetAsString(&string_value)) {
424 OPEN_ELEMENT_FOR_SCOPE("profileparam");
[email protected]e7b418b2010-07-30 19:47:47425 WriteAttribute("name", *i);
[email protected]5e324b72008-12-18 00:07:59426 WriteAttribute("value", string_value);
initial.commit09911bf2008-07-26 23:55:29427 }
428 break;
429 }
430
431 case Value::TYPE_BOOLEAN: {
432 bool bool_value;
433 if (value->GetAsBoolean(&bool_value)) {
434 OPEN_ELEMENT_FOR_SCOPE("profileparam");
[email protected]e7b418b2010-07-30 19:47:47435 WriteAttribute("name", *i);
initial.commit09911bf2008-07-26 23:55:29436 WriteIntAttribute("value", bool_value ? 1 : 0);
437 }
438 break;
439 }
440
441 case Value::TYPE_INTEGER: {
442 int int_value;
443 if (value->GetAsInteger(&int_value)) {
444 OPEN_ELEMENT_FOR_SCOPE("profileparam");
[email protected]e7b418b2010-07-30 19:47:47445 WriteAttribute("name", *i);
initial.commit09911bf2008-07-26 23:55:29446 WriteIntAttribute("value", int_value);
447 }
448 break;
449 }
450
451 default:
452 NOTREACHED();
453 break;
454 }
455 }
456 }
457}
458
459void MetricsLog::RecordOmniboxOpenedURL(const AutocompleteLog& log) {
460 DCHECK(!locked_);
461
[email protected]ffaf78a2008-11-12 17:38:33462 OPEN_ELEMENT_FOR_SCOPE("uielement");
initial.commit09911bf2008-07-26 23:55:29463 WriteAttribute("action", "autocomplete");
464 WriteAttribute("targetidhash", "");
465 // TODO(kochi): Properly track windows.
466 WriteIntAttribute("window", 0);
467 WriteCommonEventAttributes();
468
[email protected]ffaf78a2008-11-12 17:38:33469 {
470 OPEN_ELEMENT_FOR_SCOPE("autocomplete");
initial.commit09911bf2008-07-26 23:55:29471
[email protected]ffaf78a2008-11-12 17:38:33472 WriteIntAttribute("typedlength", static_cast<int>(log.text.length()));
473 WriteIntAttribute("selectedindex", static_cast<int>(log.selected_index));
474 WriteIntAttribute("completedlength",
475 static_cast<int>(log.inline_autocompleted_length));
[email protected]381e2992008-12-16 01:41:00476 const std::string input_type(
477 AutocompleteInput::TypeToString(log.input_type));
478 if (!input_type.empty())
479 WriteAttribute("inputtype", input_type);
initial.commit09911bf2008-07-26 23:55:29480
[email protected]ffaf78a2008-11-12 17:38:33481 for (AutocompleteResult::const_iterator i(log.result.begin());
482 i != log.result.end(); ++i) {
483 OPEN_ELEMENT_FOR_SCOPE("autocompleteitem");
484 if (i->provider)
485 WriteAttribute("provider", i->provider->name());
[email protected]381e2992008-12-16 01:41:00486 const std::string result_type(AutocompleteMatch::TypeToString(i->type));
487 if (!result_type.empty())
488 WriteAttribute("resulttype", result_type);
[email protected]ffaf78a2008-11-12 17:38:33489 WriteIntAttribute("relevance", i->relevance);
490 WriteIntAttribute("isstarred", i->starred ? 1 : 0);
491 }
initial.commit09911bf2008-07-26 23:55:29492 }
initial.commit09911bf2008-07-26 23:55:29493
494 ++num_events_;
495}