blob: d7244447786992d3053b9216ff489bccd30cc41d [file] [log] [blame]
isherman@chromium.org1df44b72012-01-19 05:20:341// Copyright (c) 2012 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
ben@chromium.orgcd1adc22009-01-16 01:29:225#include "chrome/browser/metrics/metrics_log.h"
initial.commit09911bf2008-07-26 23:55:296
thestig@chromium.org1eeb5e02010-07-20 23:02:117#include <string>
8#include <vector>
9
deanm@chromium.orgd1be67b2008-11-19 20:28:3810#include "base/basictypes.h"
initial.commit09911bf2008-07-26 23:55:2911#include "base/file_util.h"
thakis@chromium.org054c8012011-11-16 00:12:4212#include "base/lazy_instance.h"
levin@chromium.org3b63f8f42011-03-28 01:54:1513#include "base/memory/scoped_ptr.h"
zelidrag@chromium.org85ed9d42010-06-08 22:37:4414#include "base/perftimer.h"
initial.commit09911bf2008-07-26 23:55:2915#include "base/string_util.h"
deanm@chromium.orgfadf97f2008-09-18 12:18:1416#include "base/sys_info.h"
jar@chromium.org37f39e42010-01-06 17:35:1717#include "base/third_party/nspr/prtime.h"
thestig@chromium.org1eeb5e02010-07-20 23:02:1118#include "base/time.h"
19#include "base/utf_string_conversions.h"
initial.commit09911bf2008-07-26 23:55:2920#include "chrome/browser/autocomplete/autocomplete.h"
scr@chromium.org9ac40092010-10-27 23:05:2621#include "chrome/browser/autocomplete/autocomplete_match.h"
initial.commit09911bf2008-07-26 23:55:2922#include "chrome/browser/browser_process.h"
bauerb@chromium.org10084982011-08-19 17:56:5623#include "chrome/browser/plugin_prefs.h"
evan@chromium.org37858e52010-08-26 00:22:0224#include "chrome/browser/prefs/pref_service.h"
bauerb@chromium.org10084982011-08-19 17:56:5625#include "chrome/browser/profiles/profile_manager.h"
thestig@chromium.org1eeb5e02010-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"
apatrick@chromium.orgd9f37932011-05-09 20:09:2429#include "content/browser/gpu/gpu_data_manager.h"
deanm@google.com46072d42008-07-28 14:49:3530#include "googleurl/src/gurl.h"
derat@chromium.org6b7d954ff2011-10-25 00:39:3531#include "ui/gfx/screen.h"
cpu@chromium.org91d9f3d2011-08-14 05:24:4432#include "webkit/plugins/webplugininfo.h"
initial.commit09911bf2008-07-26 23:55:2933
34#define OPEN_ELEMENT_FOR_SCOPE(name) ScopedElement scoped_element(this, name)
35
deanm@chromium.orgd1be67b2008-11-19 20:28:3836// http://blogs.msdn.com/oldnewthing/archive/2004/10/25/247180.aspx
37#if defined(OS_WIN)
38extern "C" IMAGE_DOS_HEADER __ImageBase;
39#endif
40
isherman@chromium.org1df44b72012-01-19 05:20:3441namespace {
42
43// Returns the date at which the current metrics client ID was created as
44// a string containing milliseconds since the epoch, or "0" if none was found.
45std::string GetInstallDate() {
46 PrefService* pref = g_browser_process->local_state();
47 if (pref) {
48 return pref->GetString(prefs::kMetricsClientIDTimestamp);
49 } else {
50 NOTREACHED();
51 return "0";
52 }
53}
54
55// Returns the plugin preferences corresponding for this user, if available.
56// If multiple user profiles are loaded, returns the preferences corresponding
57// to an arbitrary one of the profiles.
58PluginPrefs* GetPluginPrefs() {
59 ProfileManager* profile_manager = g_browser_process->profile_manager();
60 std::vector<Profile*> profiles = profile_manager->GetLoadedProfiles();
61 if (profiles.empty())
62 return NULL;
63
64 return PluginPrefs::GetForProfile(profiles.front());
65}
66
67} // namespace
68
thakis@chromium.org054c8012011-11-16 00:12:4269static base::LazyInstance<std::string,
70 base::LeakyLazyInstanceTraits<std::string > >
71 g_version_extension = LAZY_INSTANCE_INITIALIZER;
72
ananta@chromium.org1226abb2010-06-10 18:01:2873MetricsLog::MetricsLog(const std::string& client_id, int session_id)
74 : MetricsLogBase(client_id, session_id, MetricsLog::GetVersionString()) {}
jar@chromium.org5ed7d4572009-12-23 17:42:4175
ananta@chromium.org1226abb2010-06-10 18:01:2876MetricsLog::~MetricsLog() {}
initial.commit09911bf2008-07-26 23:55:2977
78// static
79void MetricsLog::RegisterPrefs(PrefService* local_state) {
80 local_state->RegisterListPref(prefs::kStabilityPluginStats);
initial.commit09911bf2008-07-26 23:55:2981}
82
isherman@chromium.org1df44b72012-01-19 05:20:3483// static
jar@chromium.org9165f742010-03-10 22:55:0184int64 MetricsLog::GetIncrementalUptime(PrefService* pref) {
85 base::TimeTicks now = base::TimeTicks::Now();
86 static base::TimeTicks last_updated_time(now);
87 int64 incremental_time = (now - last_updated_time).InSeconds();
88 last_updated_time = now;
89
90 if (incremental_time > 0) {
91 int64 metrics_uptime = pref->GetInt64(prefs::kUninstallMetricsUptimeSec);
92 metrics_uptime += incremental_time;
93 pref->SetInt64(prefs::kUninstallMetricsUptimeSec, metrics_uptime);
94 }
95
96 return incremental_time;
97}
98
ananta@chromium.org1226abb2010-06-10 18:01:2899// static
100std::string MetricsLog::GetVersionString() {
evan@chromium.org0211f57e2010-08-27 20:28:42101 chrome::VersionInfo version_info;
dmaclach@chromium.org30c91802010-12-18 00:40:17102 if (!version_info.is_valid()) {
103 NOTREACHED() << "Unable to retrieve version info.";
104 return std::string();
105 }
106
evan@chromium.org0211f57e2010-08-27 20:28:42107 std::string version = version_info.Version();
thakis@chromium.org054c8012011-11-16 00:12:42108 if (!version_extension().empty())
109 version += version_extension();
evan@chromium.org0211f57e2010-08-27 20:28:42110 if (!version_info.IsOfficialBuild())
111 version.append("-devel");
112 return version;
ananta@chromium.org1226abb2010-06-10 18:01:28113}
114
thakis@chromium.org054c8012011-11-16 00:12:42115// static
116void MetricsLog::set_version_extension(const std::string& extension) {
117 g_version_extension.Get() = extension;
118}
119
120// static
121const std::string& MetricsLog::version_extension() {
122 return g_version_extension.Get();
123}
124
isherman@chromium.org1df44b72012-01-19 05:20:34125MetricsLog* MetricsLog::AsMetricsLog() {
126 return this;
127}
128
jar@google.com0b33f80b2008-12-17 21:34:36129void MetricsLog::RecordIncrementalStabilityElements() {
130 DCHECK(!locked_);
131
132 PrefService* pref = g_browser_process->local_state();
133 DCHECK(pref);
134
jar@google.com147bbc0b2009-01-06 19:37:40135 OPEN_ELEMENT_FOR_SCOPE("profile");
136 WriteCommonEventAttributes();
137
jar@chromium.org9958a322011-03-08 20:04:17138 WriteInstallElement();
jar@google.com147bbc0b2009-01-06 19:37:40139
140 {
141 OPEN_ELEMENT_FOR_SCOPE("stability"); // Minimal set of stability elements.
142 WriteRequiredStabilityAttributes(pref);
143 WriteRealtimeStabilityAttributes(pref);
144
145 WritePluginStabilityElements(pref);
146 }
jar@google.com0b33f80b2008-12-17 21:34:36147}
148
petkov@chromium.orgc1834a92011-01-21 18:21:03149void MetricsLog::WriteStabilityElement(PrefService* pref) {
initial.commit09911bf2008-07-26 23:55:29150 DCHECK(!locked_);
151
initial.commit09911bf2008-07-26 23:55:29152 DCHECK(pref);
153
154 // Get stability attributes out of Local State, zeroing out stored values.
155 // NOTE: This could lead to some data loss if this report isn't successfully
156 // sent, but that's true for all the metrics.
157
pkasting@chromium.orgffaf78a2008-11-12 17:38:33158 OPEN_ELEMENT_FOR_SCOPE("stability");
jar@google.com147bbc0b2009-01-06 19:37:40159 WriteRequiredStabilityAttributes(pref);
160 WriteRealtimeStabilityAttributes(pref);
initial.commit09911bf2008-07-26 23:55:29161
jar@google.com0b33f80b2008-12-17 21:34:36162 // TODO(jar): The following are all optional, so we *could* optimize them for
163 // values of zero (and not include them).
evanm@google.com8e674e42008-07-30 16:05:48164 WriteIntAttribute("incompleteshutdowncount",
165 pref->GetInteger(
166 prefs::kStabilityIncompleteSessionEndCount));
167 pref->SetInteger(prefs::kStabilityIncompleteSessionEndCount, 0);
jar@google.com0b33f80b2008-12-17 21:34:36168
169
cpu@google.come73c01972008-08-13 00:18:24170 WriteIntAttribute("breakpadregistrationok",
171 pref->GetInteger(prefs::kStabilityBreakpadRegistrationSuccess));
172 pref->SetInteger(prefs::kStabilityBreakpadRegistrationSuccess, 0);
173 WriteIntAttribute("breakpadregistrationfail",
174 pref->GetInteger(prefs::kStabilityBreakpadRegistrationFail));
175 pref->SetInteger(prefs::kStabilityBreakpadRegistrationFail, 0);
176 WriteIntAttribute("debuggerpresent",
177 pref->GetInteger(prefs::kStabilityDebuggerPresent));
178 pref->SetInteger(prefs::kStabilityDebuggerPresent, 0);
179 WriteIntAttribute("debuggernotpresent",
180 pref->GetInteger(prefs::kStabilityDebuggerNotPresent));
181 pref->SetInteger(prefs::kStabilityDebuggerNotPresent, 0);
initial.commit09911bf2008-07-26 23:55:29182
jar@google.com147bbc0b2009-01-06 19:37:40183 WritePluginStabilityElements(pref);
184}
185
186void MetricsLog::WritePluginStabilityElements(PrefService* pref) {
187 // Now log plugin stability info.
initial.commit09911bf2008-07-26 23:55:29188 const ListValue* plugin_stats_list = pref->GetList(
189 prefs::kStabilityPluginStats);
isherman@chromium.org1df44b72012-01-19 05:20:34190 if (!plugin_stats_list)
191 return;
initial.commit09911bf2008-07-26 23:55:29192
isherman@chromium.org1df44b72012-01-19 05:20:34193 OPEN_ELEMENT_FOR_SCOPE("plugins");
194 for (ListValue::const_iterator iter = plugin_stats_list->begin();
195 iter != plugin_stats_list->end(); ++iter) {
196 if (!(*iter)->IsType(Value::TYPE_DICTIONARY)) {
197 NOTREACHED();
198 continue;
initial.commit09911bf2008-07-26 23:55:29199 }
isherman@chromium.org1df44b72012-01-19 05:20:34200 DictionaryValue* plugin_dict = static_cast<DictionaryValue*>(*iter);
initial.commit09911bf2008-07-26 23:55:29201
isherman@chromium.org1df44b72012-01-19 05:20:34202 std::string plugin_name;
203 plugin_dict->GetString(prefs::kStabilityPluginName, &plugin_name);
204
205 OPEN_ELEMENT_FOR_SCOPE("pluginstability");
206 // Use "filename" instead of "name", otherwise we need to update the
207 // UMA servers.
208 WriteAttribute("filename", CreateBase64Hash(plugin_name));
209
210 int launches = 0;
211 plugin_dict->GetInteger(prefs::kStabilityPluginLaunches, &launches);
212 WriteIntAttribute("launchcount", launches);
213
214 int instances = 0;
215 plugin_dict->GetInteger(prefs::kStabilityPluginInstances, &instances);
216 WriteIntAttribute("instancecount", instances);
217
218 int crashes = 0;
219 plugin_dict->GetInteger(prefs::kStabilityPluginCrashes, &crashes);
220 WriteIntAttribute("crashcount", crashes);
initial.commit09911bf2008-07-26 23:55:29221 }
isherman@chromium.org1df44b72012-01-19 05:20:34222
223 pref->ClearPref(prefs::kStabilityPluginStats);
initial.commit09911bf2008-07-26 23:55:29224}
225
jar@google.com147bbc0b2009-01-06 19:37:40226void MetricsLog::WriteRequiredStabilityAttributes(PrefService* pref) {
jar@google.com0b33f80b2008-12-17 21:34:36227 // The server refuses data that doesn't have certain values. crashcount and
228 // launchcount are currently "required" in the "stability" group.
229 WriteIntAttribute("launchcount",
230 pref->GetInteger(prefs::kStabilityLaunchCount));
231 pref->SetInteger(prefs::kStabilityLaunchCount, 0);
232 WriteIntAttribute("crashcount",
233 pref->GetInteger(prefs::kStabilityCrashCount));
234 pref->SetInteger(prefs::kStabilityCrashCount, 0);
235}
236
jar@google.com147bbc0b2009-01-06 19:37:40237void MetricsLog::WriteRealtimeStabilityAttributes(PrefService* pref) {
jar@google.com0b33f80b2008-12-17 21:34:36238 // Update the stats which are critical for real-time stability monitoring.
239 // Since these are "optional," only list ones that are non-zero, as the counts
240 // are aggergated (summed) server side.
241
242 int count = pref->GetInteger(prefs::kStabilityPageLoadCount);
243 if (count) {
244 WriteIntAttribute("pageloadcount", count);
245 pref->SetInteger(prefs::kStabilityPageLoadCount, 0);
246 }
247
248 count = pref->GetInteger(prefs::kStabilityRendererCrashCount);
249 if (count) {
250 WriteIntAttribute("renderercrashcount", count);
251 pref->SetInteger(prefs::kStabilityRendererCrashCount, 0);
252 }
253
asargent@chromium.org1f085622009-12-04 05:33:45254 count = pref->GetInteger(prefs::kStabilityExtensionRendererCrashCount);
255 if (count) {
256 WriteIntAttribute("extensionrenderercrashcount", count);
257 pref->SetInteger(prefs::kStabilityExtensionRendererCrashCount, 0);
258 }
259
jar@google.com0b33f80b2008-12-17 21:34:36260 count = pref->GetInteger(prefs::kStabilityRendererHangCount);
261 if (count) {
262 WriteIntAttribute("rendererhangcount", count);
263 pref->SetInteger(prefs::kStabilityRendererHangCount, 0);
264 }
asargent@chromium.org1f085622009-12-04 05:33:45265
266 count = pref->GetInteger(prefs::kStabilityChildProcessCrashCount);
267 if (count) {
268 WriteIntAttribute("childprocesscrashcount", count);
269 pref->SetInteger(prefs::kStabilityChildProcessCrashCount, 0);
270 }
jar@chromium.org9165f742010-03-10 22:55:01271
petkov@chromium.orgc1834a92011-01-21 18:21:03272#if defined(OS_CHROMEOS)
273 count = pref->GetInteger(prefs::kStabilityOtherUserCrashCount);
274 if (count) {
275 // TODO(kmixter): Write attribute once log server supports it
276 // and remove warning log.
277 // WriteIntAttribute("otherusercrashcount", count);
278 LOG(WARNING) << "Not yet able to send otherusercrashcount="
279 << count;
280 pref->SetInteger(prefs::kStabilityOtherUserCrashCount, 0);
281 }
282
283 count = pref->GetInteger(prefs::kStabilityKernelCrashCount);
284 if (count) {
285 // TODO(kmixter): Write attribute once log server supports it
286 // and remove warning log.
287 // WriteIntAttribute("kernelcrashcount", count);
288 LOG(WARNING) << "Not yet able to send kernelcrashcount="
289 << count;
290 pref->SetInteger(prefs::kStabilityKernelCrashCount, 0);
291 }
292
293 count = pref->GetInteger(prefs::kStabilitySystemUncleanShutdownCount);
294 if (count) {
295 // TODO(kmixter): Write attribute once log server supports it
296 // and remove warning log.
297 // WriteIntAttribute("systemuncleanshutdowns", count);
298 LOG(WARNING) << "Not yet able to send systemuncleanshutdowns="
299 << count;
300 pref->SetInteger(prefs::kStabilitySystemUncleanShutdownCount, 0);
301 }
302#endif // OS_CHROMEOS
303
jar@chromium.org9165f742010-03-10 22:55:01304 int64 recent_duration = GetIncrementalUptime(pref);
305 if (recent_duration)
306 WriteInt64Attribute("uptimesec", recent_duration);
jar@google.com0b33f80b2008-12-17 21:34:36307}
308
initial.commit09911bf2008-07-26 23:55:29309void MetricsLog::WritePluginList(
cpu@chromium.org91d9f3d2011-08-14 05:24:44310 const std::vector<webkit::WebPluginInfo>& plugin_list) {
initial.commit09911bf2008-07-26 23:55:29311 DCHECK(!locked_);
312
isherman@chromium.org1df44b72012-01-19 05:20:34313 PluginPrefs* plugin_prefs = GetPluginPrefs();
bauerb@chromium.org10084982011-08-19 17:56:56314
pkasting@chromium.orgffaf78a2008-11-12 17:38:33315 OPEN_ELEMENT_FOR_SCOPE("plugins");
initial.commit09911bf2008-07-26 23:55:29316
cpu@chromium.org91d9f3d2011-08-14 05:24:44317 for (std::vector<webkit::WebPluginInfo>::const_iterator iter =
brettw@chromium.org191eb3f72010-12-21 06:27:50318 plugin_list.begin();
initial.commit09911bf2008-07-26 23:55:29319 iter != plugin_list.end(); ++iter) {
pkasting@chromium.orgffaf78a2008-11-12 17:38:33320 OPEN_ELEMENT_FOR_SCOPE("plugin");
initial.commit09911bf2008-07-26 23:55:29321
322 // Plugin name and filename are hashed for the privacy of those
323 // testing unreleased new extensions.
stuartmorgan@chromium.orgc9d811372010-06-23 21:44:57324 WriteAttribute("name", CreateBase64Hash(UTF16ToUTF8(iter->name)));
evan@chromium.org0abb1652011-02-07 23:37:55325 std::string filename_bytes =
326#if defined(OS_WIN)
327 UTF16ToUTF8(iter->path.BaseName().value());
328#else
329 iter->path.BaseName().value();
330#endif
331 WriteAttribute("filename", CreateBase64Hash(filename_bytes));
stuartmorgan@chromium.orgc9d811372010-06-23 21:44:57332 WriteAttribute("version", UTF16ToUTF8(iter->version));
bauerb@chromium.org24c935e52011-09-01 12:06:26333 if (plugin_prefs)
334 WriteIntAttribute("disabled", !plugin_prefs->IsPluginEnabled(*iter));
initial.commit09911bf2008-07-26 23:55:29335 }
initial.commit09911bf2008-07-26 23:55:29336}
337
jar@google.com147bbc0b2009-01-06 19:37:40338void MetricsLog::WriteInstallElement() {
339 OPEN_ELEMENT_FOR_SCOPE("install");
340 WriteAttribute("installdate", GetInstallDate());
341 WriteIntAttribute("buildid", 0); // We're using appversion instead.
jar@google.com147bbc0b2009-01-06 19:37:40342}
343
initial.commit09911bf2008-07-26 23:55:29344void MetricsLog::RecordEnvironment(
cpu@chromium.org91d9f3d2011-08-14 05:24:44345 const std::vector<webkit::WebPluginInfo>& plugin_list,
initial.commit09911bf2008-07-26 23:55:29346 const DictionaryValue* profile_metrics) {
347 DCHECK(!locked_);
348
349 PrefService* pref = g_browser_process->local_state();
350
pkasting@chromium.orgffaf78a2008-11-12 17:38:33351 OPEN_ELEMENT_FOR_SCOPE("profile");
initial.commit09911bf2008-07-26 23:55:29352 WriteCommonEventAttributes();
353
jar@google.com147bbc0b2009-01-06 19:37:40354 WriteInstallElement();
initial.commit09911bf2008-07-26 23:55:29355
356 WritePluginList(plugin_list);
357
petkov@chromium.orgc1834a92011-01-21 18:21:03358 WriteStabilityElement(pref);
initial.commit09911bf2008-07-26 23:55:29359
360 {
361 OPEN_ELEMENT_FOR_SCOPE("cpu");
mark@chromium.org05f9b682008-09-29 22:18:01362 WriteAttribute("arch", base::SysInfo::CPUArchitecture());
initial.commit09911bf2008-07-26 23:55:29363 }
364
365 {
initial.commit09911bf2008-07-26 23:55:29366 OPEN_ELEMENT_FOR_SCOPE("memory");
deanm@chromium.orged6fc352008-09-18 12:44:40367 WriteIntAttribute("mb", base::SysInfo::AmountOfPhysicalMemoryMB());
deanm@chromium.orgd1be67b2008-11-19 20:28:38368#if defined(OS_WIN)
369 WriteIntAttribute("dllbase", reinterpret_cast<int>(&__ImageBase));
370#endif
initial.commit09911bf2008-07-26 23:55:29371 }
372
373 {
374 OPEN_ELEMENT_FOR_SCOPE("os");
375 WriteAttribute("name",
mark@chromium.org05f9b682008-09-29 22:18:01376 base::SysInfo::OperatingSystemName());
initial.commit09911bf2008-07-26 23:55:29377 WriteAttribute("version",
mark@chromium.org05f9b682008-09-29 22:18:01378 base::SysInfo::OperatingSystemVersion());
initial.commit09911bf2008-07-26 23:55:29379 }
380
381 {
rlp@chromium.orge8c287c872010-07-20 00:49:42382 OPEN_ELEMENT_FOR_SCOPE("gpu");
zmo@google.com27d8778e2011-03-09 22:00:59383 GpuDataManager* gpu_data_manager = GpuDataManager::GetInstance();
384 if (gpu_data_manager) {
385 WriteIntAttribute("vendorid", gpu_data_manager->gpu_info().vendor_id);
386 WriteIntAttribute("deviceid", gpu_data_manager->gpu_info().device_id);
apatrick@chromium.org06b2fc92011-02-22 22:00:40387 }
rlp@chromium.orge8c287c872010-07-20 00:49:42388 }
389
390 {
initial.commit09911bf2008-07-26 23:55:29391 OPEN_ELEMENT_FOR_SCOPE("display");
derat@chromium.org6b7d954ff2011-10-25 00:39:35392 const gfx::Size display_size = gfx::Screen::GetPrimaryMonitorSize();
393 WriteIntAttribute("xsize", display_size.width());
394 WriteIntAttribute("ysize", display_size.height());
395 WriteIntAttribute("screens", gfx::Screen::GetNumMonitors());
initial.commit09911bf2008-07-26 23:55:29396 }
397
398 {
399 OPEN_ELEMENT_FOR_SCOPE("bookmarks");
400 int num_bookmarks_on_bookmark_bar =
401 pref->GetInteger(prefs::kNumBookmarksOnBookmarkBar);
402 int num_folders_on_bookmark_bar =
403 pref->GetInteger(prefs::kNumFoldersOnBookmarkBar);
404 int num_bookmarks_in_other_bookmarks_folder =
405 pref->GetInteger(prefs::kNumBookmarksInOtherBookmarkFolder);
406 int num_folders_in_other_bookmarks_folder =
407 pref->GetInteger(prefs::kNumFoldersInOtherBookmarkFolder);
408 {
409 OPEN_ELEMENT_FOR_SCOPE("bookmarklocation");
410 WriteAttribute("name", "full-tree");
411 WriteIntAttribute("foldercount",
412 num_folders_on_bookmark_bar + num_folders_in_other_bookmarks_folder);
413 WriteIntAttribute("itemcount",
414 num_bookmarks_on_bookmark_bar +
415 num_bookmarks_in_other_bookmarks_folder);
416 }
417 {
418 OPEN_ELEMENT_FOR_SCOPE("bookmarklocation");
419 WriteAttribute("name", "toolbar");
420 WriteIntAttribute("foldercount", num_folders_on_bookmark_bar);
421 WriteIntAttribute("itemcount", num_bookmarks_on_bookmark_bar);
422 }
423 }
424
425 {
426 OPEN_ELEMENT_FOR_SCOPE("keywords");
427 WriteIntAttribute("count", pref->GetInteger(prefs::kNumKeywords));
428 }
429
430 if (profile_metrics)
431 WriteAllProfilesMetrics(*profile_metrics);
initial.commit09911bf2008-07-26 23:55:29432}
433
434void MetricsLog::WriteAllProfilesMetrics(
435 const DictionaryValue& all_profiles_metrics) {
viettrungluu@chromium.org57ecc4b2010-08-11 03:02:51436 const std::string profile_prefix(prefs::kProfilePrefix);
initial.commit09911bf2008-07-26 23:55:29437 for (DictionaryValue::key_iterator i = all_profiles_metrics.begin_keys();
438 i != all_profiles_metrics.end_keys(); ++i) {
viettrungluu@chromium.orge7b418b2010-07-30 19:47:47439 const std::string& key_name = *i;
initial.commit09911bf2008-07-26 23:55:29440 if (key_name.compare(0, profile_prefix.size(), profile_prefix) == 0) {
441 DictionaryValue* profile;
pkasting@chromium.org4dad9ad82009-11-25 20:47:52442 if (all_profiles_metrics.GetDictionaryWithoutPathExpansion(key_name,
443 &profile))
initial.commit09911bf2008-07-26 23:55:29444 WriteProfileMetrics(key_name.substr(profile_prefix.size()), *profile);
445 }
446 }
447}
448
viettrungluu@chromium.orge7b418b2010-07-30 19:47:47449void MetricsLog::WriteProfileMetrics(const std::string& profileidhash,
initial.commit09911bf2008-07-26 23:55:29450 const DictionaryValue& profile_metrics) {
451 OPEN_ELEMENT_FOR_SCOPE("userprofile");
viettrungluu@chromium.orge7b418b2010-07-30 19:47:47452 WriteAttribute("profileidhash", profileidhash);
initial.commit09911bf2008-07-26 23:55:29453 for (DictionaryValue::key_iterator i = profile_metrics.begin_keys();
454 i != profile_metrics.end_keys(); ++i) {
455 Value* value;
pkasting@chromium.org4dad9ad82009-11-25 20:47:52456 if (profile_metrics.GetWithoutPathExpansion(*i, &value)) {
viettrungluu@chromium.orge7b418b2010-07-30 19:47:47457 DCHECK(*i != "id");
initial.commit09911bf2008-07-26 23:55:29458 switch (value->GetType()) {
459 case Value::TYPE_STRING: {
scherkus@chromium.org5e324b72008-12-18 00:07:59460 std::string string_value;
initial.commit09911bf2008-07-26 23:55:29461 if (value->GetAsString(&string_value)) {
462 OPEN_ELEMENT_FOR_SCOPE("profileparam");
viettrungluu@chromium.orge7b418b2010-07-30 19:47:47463 WriteAttribute("name", *i);
scherkus@chromium.org5e324b72008-12-18 00:07:59464 WriteAttribute("value", string_value);
initial.commit09911bf2008-07-26 23:55:29465 }
466 break;
467 }
468
469 case Value::TYPE_BOOLEAN: {
470 bool bool_value;
471 if (value->GetAsBoolean(&bool_value)) {
472 OPEN_ELEMENT_FOR_SCOPE("profileparam");
viettrungluu@chromium.orge7b418b2010-07-30 19:47:47473 WriteAttribute("name", *i);
initial.commit09911bf2008-07-26 23:55:29474 WriteIntAttribute("value", bool_value ? 1 : 0);
475 }
476 break;
477 }
478
479 case Value::TYPE_INTEGER: {
480 int int_value;
481 if (value->GetAsInteger(&int_value)) {
482 OPEN_ELEMENT_FOR_SCOPE("profileparam");
viettrungluu@chromium.orge7b418b2010-07-30 19:47:47483 WriteAttribute("name", *i);
initial.commit09911bf2008-07-26 23:55:29484 WriteIntAttribute("value", int_value);
485 }
486 break;
487 }
488
489 default:
490 NOTREACHED();
491 break;
492 }
493 }
494 }
495}
496
497void MetricsLog::RecordOmniboxOpenedURL(const AutocompleteLog& log) {
498 DCHECK(!locked_);
499
pkasting@chromium.orgffaf78a2008-11-12 17:38:33500 OPEN_ELEMENT_FOR_SCOPE("uielement");
initial.commit09911bf2008-07-26 23:55:29501 WriteAttribute("action", "autocomplete");
502 WriteAttribute("targetidhash", "");
503 // TODO(kochi): Properly track windows.
504 WriteIntAttribute("window", 0);
mpearson@chromium.org6ebc3162011-12-19 13:44:00505 if (log.tab_id != -1) {
506 // If we know what tab the autocomplete URL was opened in, log it.
507 WriteIntAttribute("tab", static_cast<int>(log.tab_id));
508 }
initial.commit09911bf2008-07-26 23:55:29509 WriteCommonEventAttributes();
510
pkasting@chromium.orgffaf78a2008-11-12 17:38:33511 {
512 OPEN_ELEMENT_FOR_SCOPE("autocomplete");
initial.commit09911bf2008-07-26 23:55:29513
pkasting@chromium.orgffaf78a2008-11-12 17:38:33514 WriteIntAttribute("typedlength", static_cast<int>(log.text.length()));
515 WriteIntAttribute("selectedindex", static_cast<int>(log.selected_index));
516 WriteIntAttribute("completedlength",
517 static_cast<int>(log.inline_autocompleted_length));
pkasting@chromium.org381e2992008-12-16 01:41:00518 const std::string input_type(
519 AutocompleteInput::TypeToString(log.input_type));
520 if (!input_type.empty())
521 WriteAttribute("inputtype", input_type);
initial.commit09911bf2008-07-26 23:55:29522
pkasting@chromium.orgffaf78a2008-11-12 17:38:33523 for (AutocompleteResult::const_iterator i(log.result.begin());
524 i != log.result.end(); ++i) {
525 OPEN_ELEMENT_FOR_SCOPE("autocompleteitem");
526 if (i->provider)
527 WriteAttribute("provider", i->provider->name());
pkasting@chromium.org381e2992008-12-16 01:41:00528 const std::string result_type(AutocompleteMatch::TypeToString(i->type));
529 if (!result_type.empty())
530 WriteAttribute("resulttype", result_type);
pkasting@chromium.orgffaf78a2008-11-12 17:38:33531 WriteIntAttribute("relevance", i->relevance);
532 WriteIntAttribute("isstarred", i->starred ? 1 : 0);
533 }
initial.commit09911bf2008-07-26 23:55:29534 }
initial.commit09911bf2008-07-26 23:55:29535
536 ++num_events_;
537}