blob: fc5fc769995ec450481602e92efe87b3997403bf [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]10084982011-08-19 17:56:5623#include "chrome/browser/plugin_prefs.h"
[email protected]37858e52010-08-26 00:22:0224#include "chrome/browser/prefs/pref_service.h"
[email protected]10084982011-08-19 17:56:5625#include "chrome/browser/profiles/profile_manager.h"
[email protected]1eeb5e02010-07-20 23:02:1126#include "chrome/common/chrome_version_info.h"
initial.commit09911bf2008-07-26 23:55:2927#include "chrome/common/logging_chrome.h"
28#include "chrome/common/pref_names.h"
[email protected]d9f37932011-05-09 20:09:2429#include "content/browser/gpu/gpu_data_manager.h"
[email protected]46072d42008-07-28 14:49:3530#include "googleurl/src/gurl.h"
[email protected]91d9f3d2011-08-14 05:24:4431#include "webkit/plugins/webplugininfo.h"
initial.commit09911bf2008-07-26 23:55:2932
33#define OPEN_ELEMENT_FOR_SCOPE(name) ScopedElement scoped_element(this, name)
34
[email protected]d1be67b2008-11-19 20:28:3835// http://blogs.msdn.com/oldnewthing/archive/2004/10/25/247180.aspx
36#if defined(OS_WIN)
37extern "C" IMAGE_DOS_HEADER __ImageBase;
38#endif
39
[email protected]1226abb2010-06-10 18:01:2840MetricsLog::MetricsLog(const std::string& client_id, int session_id)
41 : MetricsLogBase(client_id, session_id, MetricsLog::GetVersionString()) {}
[email protected]5ed7d4572009-12-23 17:42:4142
[email protected]1226abb2010-06-10 18:01:2843MetricsLog::~MetricsLog() {}
initial.commit09911bf2008-07-26 23:55:2944
45// static
46void MetricsLog::RegisterPrefs(PrefService* local_state) {
47 local_state->RegisterListPref(prefs::kStabilityPluginStats);
initial.commit09911bf2008-07-26 23:55:2948}
49
[email protected]9165f742010-03-10 22:55:0150int64 MetricsLog::GetIncrementalUptime(PrefService* pref) {
51 base::TimeTicks now = base::TimeTicks::Now();
52 static base::TimeTicks last_updated_time(now);
53 int64 incremental_time = (now - last_updated_time).InSeconds();
54 last_updated_time = now;
55
56 if (incremental_time > 0) {
57 int64 metrics_uptime = pref->GetInt64(prefs::kUninstallMetricsUptimeSec);
58 metrics_uptime += incremental_time;
59 pref->SetInt64(prefs::kUninstallMetricsUptimeSec, metrics_uptime);
60 }
61
62 return incremental_time;
63}
64
initial.commit09911bf2008-07-26 23:55:2965std::string MetricsLog::GetInstallDate() const {
66 PrefService* pref = g_browser_process->local_state();
67 if (pref) {
[email protected]ddd231e2010-06-29 20:35:1968 return pref->GetString(prefs::kMetricsClientIDTimestamp);
initial.commit09911bf2008-07-26 23:55:2969 } else {
70 NOTREACHED();
71 return "0";
72 }
73}
74
[email protected]1226abb2010-06-10 18:01:2875// static
76std::string MetricsLog::GetVersionString() {
[email protected]0211f57e2010-08-27 20:28:4277 chrome::VersionInfo version_info;
[email protected]30c91802010-12-18 00:40:1778 if (!version_info.is_valid()) {
79 NOTREACHED() << "Unable to retrieve version info.";
80 return std::string();
81 }
82
[email protected]0211f57e2010-08-27 20:28:4283 std::string version = version_info.Version();
84 if (!version_extension_.empty())
85 version += version_extension_;
86 if (!version_info.IsOfficialBuild())
87 version.append("-devel");
88 return version;
[email protected]1226abb2010-06-10 18:01:2889}
90
[email protected]dec76e802010-09-23 22:43:5391MetricsLog* MetricsLog::AsMetricsLog() {
92 return this;
93}
94
[email protected]0b33f80b2008-12-17 21:34:3695void MetricsLog::RecordIncrementalStabilityElements() {
96 DCHECK(!locked_);
97
98 PrefService* pref = g_browser_process->local_state();
99 DCHECK(pref);
100
[email protected]147bbc0b2009-01-06 19:37:40101 OPEN_ELEMENT_FOR_SCOPE("profile");
102 WriteCommonEventAttributes();
103
[email protected]9958a322011-03-08 20:04:17104 WriteInstallElement();
[email protected]147bbc0b2009-01-06 19:37:40105
106 {
107 OPEN_ELEMENT_FOR_SCOPE("stability"); // Minimal set of stability elements.
108 WriteRequiredStabilityAttributes(pref);
109 WriteRealtimeStabilityAttributes(pref);
110
111 WritePluginStabilityElements(pref);
112 }
[email protected]0b33f80b2008-12-17 21:34:36113}
114
[email protected]c1834a92011-01-21 18:21:03115void MetricsLog::WriteStabilityElement(PrefService* pref) {
initial.commit09911bf2008-07-26 23:55:29116 DCHECK(!locked_);
117
initial.commit09911bf2008-07-26 23:55:29118 DCHECK(pref);
119
120 // Get stability attributes out of Local State, zeroing out stored values.
121 // NOTE: This could lead to some data loss if this report isn't successfully
122 // sent, but that's true for all the metrics.
123
[email protected]ffaf78a2008-11-12 17:38:33124 OPEN_ELEMENT_FOR_SCOPE("stability");
[email protected]147bbc0b2009-01-06 19:37:40125 WriteRequiredStabilityAttributes(pref);
126 WriteRealtimeStabilityAttributes(pref);
initial.commit09911bf2008-07-26 23:55:29127
[email protected]0b33f80b2008-12-17 21:34:36128 // TODO(jar): The following are all optional, so we *could* optimize them for
129 // values of zero (and not include them).
[email protected]8e674e42008-07-30 16:05:48130 WriteIntAttribute("incompleteshutdowncount",
131 pref->GetInteger(
132 prefs::kStabilityIncompleteSessionEndCount));
133 pref->SetInteger(prefs::kStabilityIncompleteSessionEndCount, 0);
[email protected]0b33f80b2008-12-17 21:34:36134
135
[email protected]e73c01972008-08-13 00:18:24136 WriteIntAttribute("breakpadregistrationok",
137 pref->GetInteger(prefs::kStabilityBreakpadRegistrationSuccess));
138 pref->SetInteger(prefs::kStabilityBreakpadRegistrationSuccess, 0);
139 WriteIntAttribute("breakpadregistrationfail",
140 pref->GetInteger(prefs::kStabilityBreakpadRegistrationFail));
141 pref->SetInteger(prefs::kStabilityBreakpadRegistrationFail, 0);
142 WriteIntAttribute("debuggerpresent",
143 pref->GetInteger(prefs::kStabilityDebuggerPresent));
144 pref->SetInteger(prefs::kStabilityDebuggerPresent, 0);
145 WriteIntAttribute("debuggernotpresent",
146 pref->GetInteger(prefs::kStabilityDebuggerNotPresent));
147 pref->SetInteger(prefs::kStabilityDebuggerNotPresent, 0);
initial.commit09911bf2008-07-26 23:55:29148
[email protected]147bbc0b2009-01-06 19:37:40149 WritePluginStabilityElements(pref);
150}
151
152void MetricsLog::WritePluginStabilityElements(PrefService* pref) {
153 // Now log plugin stability info.
initial.commit09911bf2008-07-26 23:55:29154 const ListValue* plugin_stats_list = pref->GetList(
155 prefs::kStabilityPluginStats);
156 if (plugin_stats_list) {
[email protected]ffaf78a2008-11-12 17:38:33157 OPEN_ELEMENT_FOR_SCOPE("plugins");
initial.commit09911bf2008-07-26 23:55:29158 for (ListValue::const_iterator iter = plugin_stats_list->begin();
159 iter != plugin_stats_list->end(); ++iter) {
160 if (!(*iter)->IsType(Value::TYPE_DICTIONARY)) {
161 NOTREACHED();
162 continue;
163 }
164 DictionaryValue* plugin_dict = static_cast<DictionaryValue*>(*iter);
165
[email protected]57ecc4b2010-08-11 03:02:51166 std::string plugin_name;
[email protected]8e50b602009-03-03 22:59:43167 plugin_dict->GetString(prefs::kStabilityPluginName, &plugin_name);
initial.commit09911bf2008-07-26 23:55:29168
[email protected]ffaf78a2008-11-12 17:38:33169 OPEN_ELEMENT_FOR_SCOPE("pluginstability");
[email protected]a27a9382009-02-11 23:55:10170 // Use "filename" instead of "name", otherwise we need to update the
171 // UMA servers.
[email protected]57ecc4b2010-08-11 03:02:51172 WriteAttribute("filename", CreateBase64Hash(plugin_name));
initial.commit09911bf2008-07-26 23:55:29173
174 int launches = 0;
[email protected]8e50b602009-03-03 22:59:43175 plugin_dict->GetInteger(prefs::kStabilityPluginLaunches, &launches);
initial.commit09911bf2008-07-26 23:55:29176 WriteIntAttribute("launchcount", launches);
177
178 int instances = 0;
[email protected]8e50b602009-03-03 22:59:43179 plugin_dict->GetInteger(prefs::kStabilityPluginInstances, &instances);
initial.commit09911bf2008-07-26 23:55:29180 WriteIntAttribute("instancecount", instances);
181
182 int crashes = 0;
[email protected]8e50b602009-03-03 22:59:43183 plugin_dict->GetInteger(prefs::kStabilityPluginCrashes, &crashes);
initial.commit09911bf2008-07-26 23:55:29184 WriteIntAttribute("crashcount", crashes);
initial.commit09911bf2008-07-26 23:55:29185 }
186
187 pref->ClearPref(prefs::kStabilityPluginStats);
initial.commit09911bf2008-07-26 23:55:29188 }
initial.commit09911bf2008-07-26 23:55:29189}
190
[email protected]147bbc0b2009-01-06 19:37:40191void MetricsLog::WriteRequiredStabilityAttributes(PrefService* pref) {
[email protected]0b33f80b2008-12-17 21:34:36192 // The server refuses data that doesn't have certain values. crashcount and
193 // launchcount are currently "required" in the "stability" group.
194 WriteIntAttribute("launchcount",
195 pref->GetInteger(prefs::kStabilityLaunchCount));
196 pref->SetInteger(prefs::kStabilityLaunchCount, 0);
197 WriteIntAttribute("crashcount",
198 pref->GetInteger(prefs::kStabilityCrashCount));
199 pref->SetInteger(prefs::kStabilityCrashCount, 0);
200}
201
[email protected]147bbc0b2009-01-06 19:37:40202void MetricsLog::WriteRealtimeStabilityAttributes(PrefService* pref) {
[email protected]0b33f80b2008-12-17 21:34:36203 // Update the stats which are critical for real-time stability monitoring.
204 // Since these are "optional," only list ones that are non-zero, as the counts
205 // are aggergated (summed) server side.
206
207 int count = pref->GetInteger(prefs::kStabilityPageLoadCount);
208 if (count) {
209 WriteIntAttribute("pageloadcount", count);
210 pref->SetInteger(prefs::kStabilityPageLoadCount, 0);
211 }
212
213 count = pref->GetInteger(prefs::kStabilityRendererCrashCount);
214 if (count) {
215 WriteIntAttribute("renderercrashcount", count);
216 pref->SetInteger(prefs::kStabilityRendererCrashCount, 0);
217 }
218
[email protected]1f085622009-12-04 05:33:45219 count = pref->GetInteger(prefs::kStabilityExtensionRendererCrashCount);
220 if (count) {
221 WriteIntAttribute("extensionrenderercrashcount", count);
222 pref->SetInteger(prefs::kStabilityExtensionRendererCrashCount, 0);
223 }
224
[email protected]0b33f80b2008-12-17 21:34:36225 count = pref->GetInteger(prefs::kStabilityRendererHangCount);
226 if (count) {
227 WriteIntAttribute("rendererhangcount", count);
228 pref->SetInteger(prefs::kStabilityRendererHangCount, 0);
229 }
[email protected]1f085622009-12-04 05:33:45230
231 count = pref->GetInteger(prefs::kStabilityChildProcessCrashCount);
232 if (count) {
233 WriteIntAttribute("childprocesscrashcount", count);
234 pref->SetInteger(prefs::kStabilityChildProcessCrashCount, 0);
235 }
[email protected]9165f742010-03-10 22:55:01236
[email protected]c1834a92011-01-21 18:21:03237#if defined(OS_CHROMEOS)
238 count = pref->GetInteger(prefs::kStabilityOtherUserCrashCount);
239 if (count) {
240 // TODO(kmixter): Write attribute once log server supports it
241 // and remove warning log.
242 // WriteIntAttribute("otherusercrashcount", count);
243 LOG(WARNING) << "Not yet able to send otherusercrashcount="
244 << count;
245 pref->SetInteger(prefs::kStabilityOtherUserCrashCount, 0);
246 }
247
248 count = pref->GetInteger(prefs::kStabilityKernelCrashCount);
249 if (count) {
250 // TODO(kmixter): Write attribute once log server supports it
251 // and remove warning log.
252 // WriteIntAttribute("kernelcrashcount", count);
253 LOG(WARNING) << "Not yet able to send kernelcrashcount="
254 << count;
255 pref->SetInteger(prefs::kStabilityKernelCrashCount, 0);
256 }
257
258 count = pref->GetInteger(prefs::kStabilitySystemUncleanShutdownCount);
259 if (count) {
260 // TODO(kmixter): Write attribute once log server supports it
261 // and remove warning log.
262 // WriteIntAttribute("systemuncleanshutdowns", count);
263 LOG(WARNING) << "Not yet able to send systemuncleanshutdowns="
264 << count;
265 pref->SetInteger(prefs::kStabilitySystemUncleanShutdownCount, 0);
266 }
267#endif // OS_CHROMEOS
268
[email protected]9165f742010-03-10 22:55:01269 int64 recent_duration = GetIncrementalUptime(pref);
270 if (recent_duration)
271 WriteInt64Attribute("uptimesec", recent_duration);
[email protected]0b33f80b2008-12-17 21:34:36272}
273
initial.commit09911bf2008-07-26 23:55:29274void MetricsLog::WritePluginList(
[email protected]91d9f3d2011-08-14 05:24:44275 const std::vector<webkit::WebPluginInfo>& plugin_list) {
initial.commit09911bf2008-07-26 23:55:29276 DCHECK(!locked_);
277
[email protected]10084982011-08-19 17:56:56278 ProfileManager* profile_manager = g_browser_process->profile_manager();
279 PluginPrefs* plugin_prefs =
280 PluginPrefs::GetForProfile(profile_manager->GetLoadedProfiles().front());
281
[email protected]ffaf78a2008-11-12 17:38:33282 OPEN_ELEMENT_FOR_SCOPE("plugins");
initial.commit09911bf2008-07-26 23:55:29283
[email protected]91d9f3d2011-08-14 05:24:44284 for (std::vector<webkit::WebPluginInfo>::const_iterator iter =
[email protected]191eb3f72010-12-21 06:27:50285 plugin_list.begin();
initial.commit09911bf2008-07-26 23:55:29286 iter != plugin_list.end(); ++iter) {
[email protected]ffaf78a2008-11-12 17:38:33287 OPEN_ELEMENT_FOR_SCOPE("plugin");
initial.commit09911bf2008-07-26 23:55:29288
289 // Plugin name and filename are hashed for the privacy of those
290 // testing unreleased new extensions.
[email protected]c9d811372010-06-23 21:44:57291 WriteAttribute("name", CreateBase64Hash(UTF16ToUTF8(iter->name)));
[email protected]0abb1652011-02-07 23:37:55292 std::string filename_bytes =
293#if defined(OS_WIN)
294 UTF16ToUTF8(iter->path.BaseName().value());
295#else
296 iter->path.BaseName().value();
297#endif
298 WriteAttribute("filename", CreateBase64Hash(filename_bytes));
[email protected]c9d811372010-06-23 21:44:57299 WriteAttribute("version", UTF16ToUTF8(iter->version));
[email protected]10084982011-08-19 17:56:56300 WriteIntAttribute("disabled", !plugin_prefs->IsPluginEnabled(*iter));
initial.commit09911bf2008-07-26 23:55:29301 }
initial.commit09911bf2008-07-26 23:55:29302}
303
[email protected]147bbc0b2009-01-06 19:37:40304void MetricsLog::WriteInstallElement() {
305 OPEN_ELEMENT_FOR_SCOPE("install");
306 WriteAttribute("installdate", GetInstallDate());
307 WriteIntAttribute("buildid", 0); // We're using appversion instead.
[email protected]147bbc0b2009-01-06 19:37:40308}
309
initial.commit09911bf2008-07-26 23:55:29310void MetricsLog::RecordEnvironment(
[email protected]91d9f3d2011-08-14 05:24:44311 const std::vector<webkit::WebPluginInfo>& plugin_list,
initial.commit09911bf2008-07-26 23:55:29312 const DictionaryValue* profile_metrics) {
313 DCHECK(!locked_);
314
315 PrefService* pref = g_browser_process->local_state();
316
[email protected]ffaf78a2008-11-12 17:38:33317 OPEN_ELEMENT_FOR_SCOPE("profile");
initial.commit09911bf2008-07-26 23:55:29318 WriteCommonEventAttributes();
319
[email protected]147bbc0b2009-01-06 19:37:40320 WriteInstallElement();
initial.commit09911bf2008-07-26 23:55:29321
322 WritePluginList(plugin_list);
323
[email protected]c1834a92011-01-21 18:21:03324 WriteStabilityElement(pref);
initial.commit09911bf2008-07-26 23:55:29325
326 {
327 OPEN_ELEMENT_FOR_SCOPE("cpu");
[email protected]05f9b682008-09-29 22:18:01328 WriteAttribute("arch", base::SysInfo::CPUArchitecture());
initial.commit09911bf2008-07-26 23:55:29329 }
330
331 {
initial.commit09911bf2008-07-26 23:55:29332 OPEN_ELEMENT_FOR_SCOPE("memory");
[email protected]ed6fc352008-09-18 12:44:40333 WriteIntAttribute("mb", base::SysInfo::AmountOfPhysicalMemoryMB());
[email protected]d1be67b2008-11-19 20:28:38334#if defined(OS_WIN)
335 WriteIntAttribute("dllbase", reinterpret_cast<int>(&__ImageBase));
336#endif
initial.commit09911bf2008-07-26 23:55:29337 }
338
339 {
340 OPEN_ELEMENT_FOR_SCOPE("os");
341 WriteAttribute("name",
[email protected]05f9b682008-09-29 22:18:01342 base::SysInfo::OperatingSystemName());
initial.commit09911bf2008-07-26 23:55:29343 WriteAttribute("version",
[email protected]05f9b682008-09-29 22:18:01344 base::SysInfo::OperatingSystemVersion());
initial.commit09911bf2008-07-26 23:55:29345 }
346
347 {
[email protected]e8c287c872010-07-20 00:49:42348 OPEN_ELEMENT_FOR_SCOPE("gpu");
[email protected]27d8778e2011-03-09 22:00:59349 GpuDataManager* gpu_data_manager = GpuDataManager::GetInstance();
350 if (gpu_data_manager) {
351 WriteIntAttribute("vendorid", gpu_data_manager->gpu_info().vendor_id);
352 WriteIntAttribute("deviceid", gpu_data_manager->gpu_info().device_id);
[email protected]06b2fc92011-02-22 22:00:40353 }
[email protected]e8c287c872010-07-20 00:49:42354 }
355
356 {
initial.commit09911bf2008-07-26 23:55:29357 OPEN_ELEMENT_FOR_SCOPE("display");
358 int width = 0;
359 int height = 0;
[email protected]e9c0ba72011-06-15 15:46:26360 DisplayUtils::GetPrimaryDisplayDimensions(&width, &height);
initial.commit09911bf2008-07-26 23:55:29361 WriteIntAttribute("xsize", width);
362 WriteIntAttribute("ysize", height);
[email protected]e9c0ba72011-06-15 15:46:26363 WriteIntAttribute("screens", DisplayUtils::GetDisplayCount());
initial.commit09911bf2008-07-26 23:55:29364 }
365
366 {
367 OPEN_ELEMENT_FOR_SCOPE("bookmarks");
368 int num_bookmarks_on_bookmark_bar =
369 pref->GetInteger(prefs::kNumBookmarksOnBookmarkBar);
370 int num_folders_on_bookmark_bar =
371 pref->GetInteger(prefs::kNumFoldersOnBookmarkBar);
372 int num_bookmarks_in_other_bookmarks_folder =
373 pref->GetInteger(prefs::kNumBookmarksInOtherBookmarkFolder);
374 int num_folders_in_other_bookmarks_folder =
375 pref->GetInteger(prefs::kNumFoldersInOtherBookmarkFolder);
376 {
377 OPEN_ELEMENT_FOR_SCOPE("bookmarklocation");
378 WriteAttribute("name", "full-tree");
379 WriteIntAttribute("foldercount",
380 num_folders_on_bookmark_bar + num_folders_in_other_bookmarks_folder);
381 WriteIntAttribute("itemcount",
382 num_bookmarks_on_bookmark_bar +
383 num_bookmarks_in_other_bookmarks_folder);
384 }
385 {
386 OPEN_ELEMENT_FOR_SCOPE("bookmarklocation");
387 WriteAttribute("name", "toolbar");
388 WriteIntAttribute("foldercount", num_folders_on_bookmark_bar);
389 WriteIntAttribute("itemcount", num_bookmarks_on_bookmark_bar);
390 }
391 }
392
393 {
394 OPEN_ELEMENT_FOR_SCOPE("keywords");
395 WriteIntAttribute("count", pref->GetInteger(prefs::kNumKeywords));
396 }
397
398 if (profile_metrics)
399 WriteAllProfilesMetrics(*profile_metrics);
initial.commit09911bf2008-07-26 23:55:29400}
401
402void MetricsLog::WriteAllProfilesMetrics(
403 const DictionaryValue& all_profiles_metrics) {
[email protected]57ecc4b2010-08-11 03:02:51404 const std::string profile_prefix(prefs::kProfilePrefix);
initial.commit09911bf2008-07-26 23:55:29405 for (DictionaryValue::key_iterator i = all_profiles_metrics.begin_keys();
406 i != all_profiles_metrics.end_keys(); ++i) {
[email protected]e7b418b2010-07-30 19:47:47407 const std::string& key_name = *i;
initial.commit09911bf2008-07-26 23:55:29408 if (key_name.compare(0, profile_prefix.size(), profile_prefix) == 0) {
409 DictionaryValue* profile;
[email protected]4dad9ad82009-11-25 20:47:52410 if (all_profiles_metrics.GetDictionaryWithoutPathExpansion(key_name,
411 &profile))
initial.commit09911bf2008-07-26 23:55:29412 WriteProfileMetrics(key_name.substr(profile_prefix.size()), *profile);
413 }
414 }
415}
416
[email protected]e7b418b2010-07-30 19:47:47417void MetricsLog::WriteProfileMetrics(const std::string& profileidhash,
initial.commit09911bf2008-07-26 23:55:29418 const DictionaryValue& profile_metrics) {
419 OPEN_ELEMENT_FOR_SCOPE("userprofile");
[email protected]e7b418b2010-07-30 19:47:47420 WriteAttribute("profileidhash", profileidhash);
initial.commit09911bf2008-07-26 23:55:29421 for (DictionaryValue::key_iterator i = profile_metrics.begin_keys();
422 i != profile_metrics.end_keys(); ++i) {
423 Value* value;
[email protected]4dad9ad82009-11-25 20:47:52424 if (profile_metrics.GetWithoutPathExpansion(*i, &value)) {
[email protected]e7b418b2010-07-30 19:47:47425 DCHECK(*i != "id");
initial.commit09911bf2008-07-26 23:55:29426 switch (value->GetType()) {
427 case Value::TYPE_STRING: {
[email protected]5e324b72008-12-18 00:07:59428 std::string string_value;
initial.commit09911bf2008-07-26 23:55:29429 if (value->GetAsString(&string_value)) {
430 OPEN_ELEMENT_FOR_SCOPE("profileparam");
[email protected]e7b418b2010-07-30 19:47:47431 WriteAttribute("name", *i);
[email protected]5e324b72008-12-18 00:07:59432 WriteAttribute("value", string_value);
initial.commit09911bf2008-07-26 23:55:29433 }
434 break;
435 }
436
437 case Value::TYPE_BOOLEAN: {
438 bool bool_value;
439 if (value->GetAsBoolean(&bool_value)) {
440 OPEN_ELEMENT_FOR_SCOPE("profileparam");
[email protected]e7b418b2010-07-30 19:47:47441 WriteAttribute("name", *i);
initial.commit09911bf2008-07-26 23:55:29442 WriteIntAttribute("value", bool_value ? 1 : 0);
443 }
444 break;
445 }
446
447 case Value::TYPE_INTEGER: {
448 int int_value;
449 if (value->GetAsInteger(&int_value)) {
450 OPEN_ELEMENT_FOR_SCOPE("profileparam");
[email protected]e7b418b2010-07-30 19:47:47451 WriteAttribute("name", *i);
initial.commit09911bf2008-07-26 23:55:29452 WriteIntAttribute("value", int_value);
453 }
454 break;
455 }
456
457 default:
458 NOTREACHED();
459 break;
460 }
461 }
462 }
463}
464
465void MetricsLog::RecordOmniboxOpenedURL(const AutocompleteLog& log) {
466 DCHECK(!locked_);
467
[email protected]ffaf78a2008-11-12 17:38:33468 OPEN_ELEMENT_FOR_SCOPE("uielement");
initial.commit09911bf2008-07-26 23:55:29469 WriteAttribute("action", "autocomplete");
470 WriteAttribute("targetidhash", "");
471 // TODO(kochi): Properly track windows.
472 WriteIntAttribute("window", 0);
473 WriteCommonEventAttributes();
474
[email protected]ffaf78a2008-11-12 17:38:33475 {
476 OPEN_ELEMENT_FOR_SCOPE("autocomplete");
initial.commit09911bf2008-07-26 23:55:29477
[email protected]ffaf78a2008-11-12 17:38:33478 WriteIntAttribute("typedlength", static_cast<int>(log.text.length()));
479 WriteIntAttribute("selectedindex", static_cast<int>(log.selected_index));
480 WriteIntAttribute("completedlength",
481 static_cast<int>(log.inline_autocompleted_length));
[email protected]381e2992008-12-16 01:41:00482 const std::string input_type(
483 AutocompleteInput::TypeToString(log.input_type));
484 if (!input_type.empty())
485 WriteAttribute("inputtype", input_type);
initial.commit09911bf2008-07-26 23:55:29486
[email protected]ffaf78a2008-11-12 17:38:33487 for (AutocompleteResult::const_iterator i(log.result.begin());
488 i != log.result.end(); ++i) {
489 OPEN_ELEMENT_FOR_SCOPE("autocompleteitem");
490 if (i->provider)
491 WriteAttribute("provider", i->provider->name());
[email protected]381e2992008-12-16 01:41:00492 const std::string result_type(AutocompleteMatch::TypeToString(i->type));
493 if (!result_type.empty())
494 WriteAttribute("resulttype", result_type);
[email protected]ffaf78a2008-11-12 17:38:33495 WriteIntAttribute("relevance", i->relevance);
496 WriteIntAttribute("isstarred", i->starred ? 1 : 0);
497 }
initial.commit09911bf2008-07-26 23:55:29498 }
initial.commit09911bf2008-07-26 23:55:29499
500 ++num_events_;
501}