blob: 4526893fb51759fded13b2f891f346c8d1d9ab1f [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]10084982011-08-19 17:56:5622#include "chrome/browser/plugin_prefs.h"
[email protected]37858e52010-08-26 00:22:0223#include "chrome/browser/prefs/pref_service.h"
[email protected]10084982011-08-19 17:56:5624#include "chrome/browser/profiles/profile_manager.h"
[email protected]1eeb5e02010-07-20 23:02:1125#include "chrome/common/chrome_version_info.h"
initial.commit09911bf2008-07-26 23:55:2926#include "chrome/common/logging_chrome.h"
27#include "chrome/common/pref_names.h"
[email protected]d9f37932011-05-09 20:09:2428#include "content/browser/gpu/gpu_data_manager.h"
[email protected]46072d42008-07-28 14:49:3529#include "googleurl/src/gurl.h"
[email protected]6b7d954ff2011-10-25 00:39:3530#include "ui/gfx/screen.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();
[email protected]24c935e52011-09-01 12:06:26279 std::vector<Profile*> profiles = profile_manager->GetLoadedProfiles();
280 PluginPrefs* plugin_prefs = NULL;
281 if (!profiles.empty())
282 plugin_prefs = PluginPrefs::GetForProfile(profiles.front());
[email protected]10084982011-08-19 17:56:56283
[email protected]ffaf78a2008-11-12 17:38:33284 OPEN_ELEMENT_FOR_SCOPE("plugins");
initial.commit09911bf2008-07-26 23:55:29285
[email protected]91d9f3d2011-08-14 05:24:44286 for (std::vector<webkit::WebPluginInfo>::const_iterator iter =
[email protected]191eb3f72010-12-21 06:27:50287 plugin_list.begin();
initial.commit09911bf2008-07-26 23:55:29288 iter != plugin_list.end(); ++iter) {
[email protected]ffaf78a2008-11-12 17:38:33289 OPEN_ELEMENT_FOR_SCOPE("plugin");
initial.commit09911bf2008-07-26 23:55:29290
291 // Plugin name and filename are hashed for the privacy of those
292 // testing unreleased new extensions.
[email protected]c9d811372010-06-23 21:44:57293 WriteAttribute("name", CreateBase64Hash(UTF16ToUTF8(iter->name)));
[email protected]0abb1652011-02-07 23:37:55294 std::string filename_bytes =
295#if defined(OS_WIN)
296 UTF16ToUTF8(iter->path.BaseName().value());
297#else
298 iter->path.BaseName().value();
299#endif
300 WriteAttribute("filename", CreateBase64Hash(filename_bytes));
[email protected]c9d811372010-06-23 21:44:57301 WriteAttribute("version", UTF16ToUTF8(iter->version));
[email protected]24c935e52011-09-01 12:06:26302 if (plugin_prefs)
303 WriteIntAttribute("disabled", !plugin_prefs->IsPluginEnabled(*iter));
initial.commit09911bf2008-07-26 23:55:29304 }
initial.commit09911bf2008-07-26 23:55:29305}
306
[email protected]147bbc0b2009-01-06 19:37:40307void MetricsLog::WriteInstallElement() {
308 OPEN_ELEMENT_FOR_SCOPE("install");
309 WriteAttribute("installdate", GetInstallDate());
310 WriteIntAttribute("buildid", 0); // We're using appversion instead.
[email protected]147bbc0b2009-01-06 19:37:40311}
312
initial.commit09911bf2008-07-26 23:55:29313void MetricsLog::RecordEnvironment(
[email protected]91d9f3d2011-08-14 05:24:44314 const std::vector<webkit::WebPluginInfo>& plugin_list,
initial.commit09911bf2008-07-26 23:55:29315 const DictionaryValue* profile_metrics) {
316 DCHECK(!locked_);
317
318 PrefService* pref = g_browser_process->local_state();
319
[email protected]ffaf78a2008-11-12 17:38:33320 OPEN_ELEMENT_FOR_SCOPE("profile");
initial.commit09911bf2008-07-26 23:55:29321 WriteCommonEventAttributes();
322
[email protected]147bbc0b2009-01-06 19:37:40323 WriteInstallElement();
initial.commit09911bf2008-07-26 23:55:29324
325 WritePluginList(plugin_list);
326
[email protected]c1834a92011-01-21 18:21:03327 WriteStabilityElement(pref);
initial.commit09911bf2008-07-26 23:55:29328
329 {
330 OPEN_ELEMENT_FOR_SCOPE("cpu");
[email protected]05f9b682008-09-29 22:18:01331 WriteAttribute("arch", base::SysInfo::CPUArchitecture());
initial.commit09911bf2008-07-26 23:55:29332 }
333
334 {
initial.commit09911bf2008-07-26 23:55:29335 OPEN_ELEMENT_FOR_SCOPE("memory");
[email protected]ed6fc352008-09-18 12:44:40336 WriteIntAttribute("mb", base::SysInfo::AmountOfPhysicalMemoryMB());
[email protected]d1be67b2008-11-19 20:28:38337#if defined(OS_WIN)
338 WriteIntAttribute("dllbase", reinterpret_cast<int>(&__ImageBase));
339#endif
initial.commit09911bf2008-07-26 23:55:29340 }
341
342 {
343 OPEN_ELEMENT_FOR_SCOPE("os");
344 WriteAttribute("name",
[email protected]05f9b682008-09-29 22:18:01345 base::SysInfo::OperatingSystemName());
initial.commit09911bf2008-07-26 23:55:29346 WriteAttribute("version",
[email protected]05f9b682008-09-29 22:18:01347 base::SysInfo::OperatingSystemVersion());
initial.commit09911bf2008-07-26 23:55:29348 }
349
350 {
[email protected]e8c287c872010-07-20 00:49:42351 OPEN_ELEMENT_FOR_SCOPE("gpu");
[email protected]27d8778e2011-03-09 22:00:59352 GpuDataManager* gpu_data_manager = GpuDataManager::GetInstance();
353 if (gpu_data_manager) {
354 WriteIntAttribute("vendorid", gpu_data_manager->gpu_info().vendor_id);
355 WriteIntAttribute("deviceid", gpu_data_manager->gpu_info().device_id);
[email protected]06b2fc92011-02-22 22:00:40356 }
[email protected]e8c287c872010-07-20 00:49:42357 }
358
359 {
initial.commit09911bf2008-07-26 23:55:29360 OPEN_ELEMENT_FOR_SCOPE("display");
[email protected]6b7d954ff2011-10-25 00:39:35361 const gfx::Size display_size = gfx::Screen::GetPrimaryMonitorSize();
362 WriteIntAttribute("xsize", display_size.width());
363 WriteIntAttribute("ysize", display_size.height());
364 WriteIntAttribute("screens", gfx::Screen::GetNumMonitors());
initial.commit09911bf2008-07-26 23:55:29365 }
366
367 {
368 OPEN_ELEMENT_FOR_SCOPE("bookmarks");
369 int num_bookmarks_on_bookmark_bar =
370 pref->GetInteger(prefs::kNumBookmarksOnBookmarkBar);
371 int num_folders_on_bookmark_bar =
372 pref->GetInteger(prefs::kNumFoldersOnBookmarkBar);
373 int num_bookmarks_in_other_bookmarks_folder =
374 pref->GetInteger(prefs::kNumBookmarksInOtherBookmarkFolder);
375 int num_folders_in_other_bookmarks_folder =
376 pref->GetInteger(prefs::kNumFoldersInOtherBookmarkFolder);
377 {
378 OPEN_ELEMENT_FOR_SCOPE("bookmarklocation");
379 WriteAttribute("name", "full-tree");
380 WriteIntAttribute("foldercount",
381 num_folders_on_bookmark_bar + num_folders_in_other_bookmarks_folder);
382 WriteIntAttribute("itemcount",
383 num_bookmarks_on_bookmark_bar +
384 num_bookmarks_in_other_bookmarks_folder);
385 }
386 {
387 OPEN_ELEMENT_FOR_SCOPE("bookmarklocation");
388 WriteAttribute("name", "toolbar");
389 WriteIntAttribute("foldercount", num_folders_on_bookmark_bar);
390 WriteIntAttribute("itemcount", num_bookmarks_on_bookmark_bar);
391 }
392 }
393
394 {
395 OPEN_ELEMENT_FOR_SCOPE("keywords");
396 WriteIntAttribute("count", pref->GetInteger(prefs::kNumKeywords));
397 }
398
399 if (profile_metrics)
400 WriteAllProfilesMetrics(*profile_metrics);
initial.commit09911bf2008-07-26 23:55:29401}
402
403void MetricsLog::WriteAllProfilesMetrics(
404 const DictionaryValue& all_profiles_metrics) {
[email protected]57ecc4b2010-08-11 03:02:51405 const std::string profile_prefix(prefs::kProfilePrefix);
initial.commit09911bf2008-07-26 23:55:29406 for (DictionaryValue::key_iterator i = all_profiles_metrics.begin_keys();
407 i != all_profiles_metrics.end_keys(); ++i) {
[email protected]e7b418b2010-07-30 19:47:47408 const std::string& key_name = *i;
initial.commit09911bf2008-07-26 23:55:29409 if (key_name.compare(0, profile_prefix.size(), profile_prefix) == 0) {
410 DictionaryValue* profile;
[email protected]4dad9ad82009-11-25 20:47:52411 if (all_profiles_metrics.GetDictionaryWithoutPathExpansion(key_name,
412 &profile))
initial.commit09911bf2008-07-26 23:55:29413 WriteProfileMetrics(key_name.substr(profile_prefix.size()), *profile);
414 }
415 }
416}
417
[email protected]e7b418b2010-07-30 19:47:47418void MetricsLog::WriteProfileMetrics(const std::string& profileidhash,
initial.commit09911bf2008-07-26 23:55:29419 const DictionaryValue& profile_metrics) {
420 OPEN_ELEMENT_FOR_SCOPE("userprofile");
[email protected]e7b418b2010-07-30 19:47:47421 WriteAttribute("profileidhash", profileidhash);
initial.commit09911bf2008-07-26 23:55:29422 for (DictionaryValue::key_iterator i = profile_metrics.begin_keys();
423 i != profile_metrics.end_keys(); ++i) {
424 Value* value;
[email protected]4dad9ad82009-11-25 20:47:52425 if (profile_metrics.GetWithoutPathExpansion(*i, &value)) {
[email protected]e7b418b2010-07-30 19:47:47426 DCHECK(*i != "id");
initial.commit09911bf2008-07-26 23:55:29427 switch (value->GetType()) {
428 case Value::TYPE_STRING: {
[email protected]5e324b72008-12-18 00:07:59429 std::string string_value;
initial.commit09911bf2008-07-26 23:55:29430 if (value->GetAsString(&string_value)) {
431 OPEN_ELEMENT_FOR_SCOPE("profileparam");
[email protected]e7b418b2010-07-30 19:47:47432 WriteAttribute("name", *i);
[email protected]5e324b72008-12-18 00:07:59433 WriteAttribute("value", string_value);
initial.commit09911bf2008-07-26 23:55:29434 }
435 break;
436 }
437
438 case Value::TYPE_BOOLEAN: {
439 bool bool_value;
440 if (value->GetAsBoolean(&bool_value)) {
441 OPEN_ELEMENT_FOR_SCOPE("profileparam");
[email protected]e7b418b2010-07-30 19:47:47442 WriteAttribute("name", *i);
initial.commit09911bf2008-07-26 23:55:29443 WriteIntAttribute("value", bool_value ? 1 : 0);
444 }
445 break;
446 }
447
448 case Value::TYPE_INTEGER: {
449 int int_value;
450 if (value->GetAsInteger(&int_value)) {
451 OPEN_ELEMENT_FOR_SCOPE("profileparam");
[email protected]e7b418b2010-07-30 19:47:47452 WriteAttribute("name", *i);
initial.commit09911bf2008-07-26 23:55:29453 WriteIntAttribute("value", int_value);
454 }
455 break;
456 }
457
458 default:
459 NOTREACHED();
460 break;
461 }
462 }
463 }
464}
465
466void MetricsLog::RecordOmniboxOpenedURL(const AutocompleteLog& log) {
467 DCHECK(!locked_);
468
[email protected]ffaf78a2008-11-12 17:38:33469 OPEN_ELEMENT_FOR_SCOPE("uielement");
initial.commit09911bf2008-07-26 23:55:29470 WriteAttribute("action", "autocomplete");
471 WriteAttribute("targetidhash", "");
472 // TODO(kochi): Properly track windows.
473 WriteIntAttribute("window", 0);
474 WriteCommonEventAttributes();
475
[email protected]ffaf78a2008-11-12 17:38:33476 {
477 OPEN_ELEMENT_FOR_SCOPE("autocomplete");
initial.commit09911bf2008-07-26 23:55:29478
[email protected]ffaf78a2008-11-12 17:38:33479 WriteIntAttribute("typedlength", static_cast<int>(log.text.length()));
480 WriteIntAttribute("selectedindex", static_cast<int>(log.selected_index));
481 WriteIntAttribute("completedlength",
482 static_cast<int>(log.inline_autocompleted_length));
[email protected]381e2992008-12-16 01:41:00483 const std::string input_type(
484 AutocompleteInput::TypeToString(log.input_type));
485 if (!input_type.empty())
486 WriteAttribute("inputtype", input_type);
initial.commit09911bf2008-07-26 23:55:29487
[email protected]ffaf78a2008-11-12 17:38:33488 for (AutocompleteResult::const_iterator i(log.result.begin());
489 i != log.result.end(); ++i) {
490 OPEN_ELEMENT_FOR_SCOPE("autocompleteitem");
491 if (i->provider)
492 WriteAttribute("provider", i->provider->name());
[email protected]381e2992008-12-16 01:41:00493 const std::string result_type(AutocompleteMatch::TypeToString(i->type));
494 if (!result_type.empty())
495 WriteAttribute("resulttype", result_type);
[email protected]ffaf78a2008-11-12 17:38:33496 WriteIntAttribute("relevance", i->relevance);
497 WriteIntAttribute("isstarred", i->starred ? 1 : 0);
498 }
initial.commit09911bf2008-07-26 23:55:29499 }
initial.commit09911bf2008-07-26 23:55:29500
501 ++num_events_;
502}