blob: fabf047edc15abc265e38005cf3c267952cea200 [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]054c8012011-11-16 00:12:4212#include "base/lazy_instance.h"
[email protected]3b63f8f42011-03-28 01:54:1513#include "base/memory/scoped_ptr.h"
[email protected]85ed9d42010-06-08 22:37:4414#include "base/perftimer.h"
initial.commit09911bf2008-07-26 23:55:2915#include "base/string_util.h"
[email protected]fadf97f2008-09-18 12:18:1416#include "base/sys_info.h"
[email protected]37f39e42010-01-06 17:35:1717#include "base/third_party/nspr/prtime.h"
[email protected]1eeb5e02010-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"
[email protected]9ac40092010-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"
[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]6b7d954ff2011-10-25 00:39:3531#include "ui/gfx/screen.h"
[email protected]91d9f3d2011-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
[email protected]d1be67b2008-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
[email protected]054c8012011-11-16 00:12:4241static base::LazyInstance<std::string,
42 base::LeakyLazyInstanceTraits<std::string > >
43 g_version_extension = LAZY_INSTANCE_INITIALIZER;
44
[email protected]1226abb2010-06-10 18:01:2845MetricsLog::MetricsLog(const std::string& client_id, int session_id)
46 : MetricsLogBase(client_id, session_id, MetricsLog::GetVersionString()) {}
[email protected]5ed7d4572009-12-23 17:42:4147
[email protected]1226abb2010-06-10 18:01:2848MetricsLog::~MetricsLog() {}
initial.commit09911bf2008-07-26 23:55:2949
50// static
51void MetricsLog::RegisterPrefs(PrefService* local_state) {
52 local_state->RegisterListPref(prefs::kStabilityPluginStats);
initial.commit09911bf2008-07-26 23:55:2953}
54
[email protected]9165f742010-03-10 22:55:0155int64 MetricsLog::GetIncrementalUptime(PrefService* pref) {
56 base::TimeTicks now = base::TimeTicks::Now();
57 static base::TimeTicks last_updated_time(now);
58 int64 incremental_time = (now - last_updated_time).InSeconds();
59 last_updated_time = now;
60
61 if (incremental_time > 0) {
62 int64 metrics_uptime = pref->GetInt64(prefs::kUninstallMetricsUptimeSec);
63 metrics_uptime += incremental_time;
64 pref->SetInt64(prefs::kUninstallMetricsUptimeSec, metrics_uptime);
65 }
66
67 return incremental_time;
68}
69
initial.commit09911bf2008-07-26 23:55:2970std::string MetricsLog::GetInstallDate() const {
71 PrefService* pref = g_browser_process->local_state();
72 if (pref) {
[email protected]ddd231e2010-06-29 20:35:1973 return pref->GetString(prefs::kMetricsClientIDTimestamp);
initial.commit09911bf2008-07-26 23:55:2974 } else {
75 NOTREACHED();
76 return "0";
77 }
78}
79
[email protected]1226abb2010-06-10 18:01:2880// static
81std::string MetricsLog::GetVersionString() {
[email protected]0211f57e2010-08-27 20:28:4282 chrome::VersionInfo version_info;
[email protected]30c91802010-12-18 00:40:1783 if (!version_info.is_valid()) {
84 NOTREACHED() << "Unable to retrieve version info.";
85 return std::string();
86 }
87
[email protected]0211f57e2010-08-27 20:28:4288 std::string version = version_info.Version();
[email protected]054c8012011-11-16 00:12:4289 if (!version_extension().empty())
90 version += version_extension();
[email protected]0211f57e2010-08-27 20:28:4291 if (!version_info.IsOfficialBuild())
92 version.append("-devel");
93 return version;
[email protected]1226abb2010-06-10 18:01:2894}
95
[email protected]dec76e802010-09-23 22:43:5396MetricsLog* MetricsLog::AsMetricsLog() {
97 return this;
98}
99
[email protected]054c8012011-11-16 00:12:42100// static
101void MetricsLog::set_version_extension(const std::string& extension) {
102 g_version_extension.Get() = extension;
103}
104
105// static
106const std::string& MetricsLog::version_extension() {
107 return g_version_extension.Get();
108}
109
[email protected]0b33f80b2008-12-17 21:34:36110void MetricsLog::RecordIncrementalStabilityElements() {
111 DCHECK(!locked_);
112
113 PrefService* pref = g_browser_process->local_state();
114 DCHECK(pref);
115
[email protected]147bbc0b2009-01-06 19:37:40116 OPEN_ELEMENT_FOR_SCOPE("profile");
117 WriteCommonEventAttributes();
118
[email protected]9958a322011-03-08 20:04:17119 WriteInstallElement();
[email protected]147bbc0b2009-01-06 19:37:40120
121 {
122 OPEN_ELEMENT_FOR_SCOPE("stability"); // Minimal set of stability elements.
123 WriteRequiredStabilityAttributes(pref);
124 WriteRealtimeStabilityAttributes(pref);
125
126 WritePluginStabilityElements(pref);
127 }
[email protected]0b33f80b2008-12-17 21:34:36128}
129
[email protected]c1834a92011-01-21 18:21:03130void MetricsLog::WriteStabilityElement(PrefService* pref) {
initial.commit09911bf2008-07-26 23:55:29131 DCHECK(!locked_);
132
initial.commit09911bf2008-07-26 23:55:29133 DCHECK(pref);
134
135 // Get stability attributes out of Local State, zeroing out stored values.
136 // NOTE: This could lead to some data loss if this report isn't successfully
137 // sent, but that's true for all the metrics.
138
[email protected]ffaf78a2008-11-12 17:38:33139 OPEN_ELEMENT_FOR_SCOPE("stability");
[email protected]147bbc0b2009-01-06 19:37:40140 WriteRequiredStabilityAttributes(pref);
141 WriteRealtimeStabilityAttributes(pref);
initial.commit09911bf2008-07-26 23:55:29142
[email protected]0b33f80b2008-12-17 21:34:36143 // TODO(jar): The following are all optional, so we *could* optimize them for
144 // values of zero (and not include them).
[email protected]8e674e42008-07-30 16:05:48145 WriteIntAttribute("incompleteshutdowncount",
146 pref->GetInteger(
147 prefs::kStabilityIncompleteSessionEndCount));
148 pref->SetInteger(prefs::kStabilityIncompleteSessionEndCount, 0);
[email protected]0b33f80b2008-12-17 21:34:36149
150
[email protected]e73c01972008-08-13 00:18:24151 WriteIntAttribute("breakpadregistrationok",
152 pref->GetInteger(prefs::kStabilityBreakpadRegistrationSuccess));
153 pref->SetInteger(prefs::kStabilityBreakpadRegistrationSuccess, 0);
154 WriteIntAttribute("breakpadregistrationfail",
155 pref->GetInteger(prefs::kStabilityBreakpadRegistrationFail));
156 pref->SetInteger(prefs::kStabilityBreakpadRegistrationFail, 0);
157 WriteIntAttribute("debuggerpresent",
158 pref->GetInteger(prefs::kStabilityDebuggerPresent));
159 pref->SetInteger(prefs::kStabilityDebuggerPresent, 0);
160 WriteIntAttribute("debuggernotpresent",
161 pref->GetInteger(prefs::kStabilityDebuggerNotPresent));
162 pref->SetInteger(prefs::kStabilityDebuggerNotPresent, 0);
initial.commit09911bf2008-07-26 23:55:29163
[email protected]147bbc0b2009-01-06 19:37:40164 WritePluginStabilityElements(pref);
165}
166
167void MetricsLog::WritePluginStabilityElements(PrefService* pref) {
168 // Now log plugin stability info.
initial.commit09911bf2008-07-26 23:55:29169 const ListValue* plugin_stats_list = pref->GetList(
170 prefs::kStabilityPluginStats);
171 if (plugin_stats_list) {
[email protected]ffaf78a2008-11-12 17:38:33172 OPEN_ELEMENT_FOR_SCOPE("plugins");
initial.commit09911bf2008-07-26 23:55:29173 for (ListValue::const_iterator iter = plugin_stats_list->begin();
174 iter != plugin_stats_list->end(); ++iter) {
175 if (!(*iter)->IsType(Value::TYPE_DICTIONARY)) {
176 NOTREACHED();
177 continue;
178 }
179 DictionaryValue* plugin_dict = static_cast<DictionaryValue*>(*iter);
180
[email protected]57ecc4b2010-08-11 03:02:51181 std::string plugin_name;
[email protected]8e50b602009-03-03 22:59:43182 plugin_dict->GetString(prefs::kStabilityPluginName, &plugin_name);
initial.commit09911bf2008-07-26 23:55:29183
[email protected]ffaf78a2008-11-12 17:38:33184 OPEN_ELEMENT_FOR_SCOPE("pluginstability");
[email protected]a27a9382009-02-11 23:55:10185 // Use "filename" instead of "name", otherwise we need to update the
186 // UMA servers.
[email protected]57ecc4b2010-08-11 03:02:51187 WriteAttribute("filename", CreateBase64Hash(plugin_name));
initial.commit09911bf2008-07-26 23:55:29188
189 int launches = 0;
[email protected]8e50b602009-03-03 22:59:43190 plugin_dict->GetInteger(prefs::kStabilityPluginLaunches, &launches);
initial.commit09911bf2008-07-26 23:55:29191 WriteIntAttribute("launchcount", launches);
192
193 int instances = 0;
[email protected]8e50b602009-03-03 22:59:43194 plugin_dict->GetInteger(prefs::kStabilityPluginInstances, &instances);
initial.commit09911bf2008-07-26 23:55:29195 WriteIntAttribute("instancecount", instances);
196
197 int crashes = 0;
[email protected]8e50b602009-03-03 22:59:43198 plugin_dict->GetInteger(prefs::kStabilityPluginCrashes, &crashes);
initial.commit09911bf2008-07-26 23:55:29199 WriteIntAttribute("crashcount", crashes);
initial.commit09911bf2008-07-26 23:55:29200 }
201
202 pref->ClearPref(prefs::kStabilityPluginStats);
initial.commit09911bf2008-07-26 23:55:29203 }
initial.commit09911bf2008-07-26 23:55:29204}
205
[email protected]147bbc0b2009-01-06 19:37:40206void MetricsLog::WriteRequiredStabilityAttributes(PrefService* pref) {
[email protected]0b33f80b2008-12-17 21:34:36207 // The server refuses data that doesn't have certain values. crashcount and
208 // launchcount are currently "required" in the "stability" group.
209 WriteIntAttribute("launchcount",
210 pref->GetInteger(prefs::kStabilityLaunchCount));
211 pref->SetInteger(prefs::kStabilityLaunchCount, 0);
212 WriteIntAttribute("crashcount",
213 pref->GetInteger(prefs::kStabilityCrashCount));
214 pref->SetInteger(prefs::kStabilityCrashCount, 0);
215}
216
[email protected]147bbc0b2009-01-06 19:37:40217void MetricsLog::WriteRealtimeStabilityAttributes(PrefService* pref) {
[email protected]0b33f80b2008-12-17 21:34:36218 // Update the stats which are critical for real-time stability monitoring.
219 // Since these are "optional," only list ones that are non-zero, as the counts
220 // are aggergated (summed) server side.
221
222 int count = pref->GetInteger(prefs::kStabilityPageLoadCount);
223 if (count) {
224 WriteIntAttribute("pageloadcount", count);
225 pref->SetInteger(prefs::kStabilityPageLoadCount, 0);
226 }
227
228 count = pref->GetInteger(prefs::kStabilityRendererCrashCount);
229 if (count) {
230 WriteIntAttribute("renderercrashcount", count);
231 pref->SetInteger(prefs::kStabilityRendererCrashCount, 0);
232 }
233
[email protected]1f085622009-12-04 05:33:45234 count = pref->GetInteger(prefs::kStabilityExtensionRendererCrashCount);
235 if (count) {
236 WriteIntAttribute("extensionrenderercrashcount", count);
237 pref->SetInteger(prefs::kStabilityExtensionRendererCrashCount, 0);
238 }
239
[email protected]0b33f80b2008-12-17 21:34:36240 count = pref->GetInteger(prefs::kStabilityRendererHangCount);
241 if (count) {
242 WriteIntAttribute("rendererhangcount", count);
243 pref->SetInteger(prefs::kStabilityRendererHangCount, 0);
244 }
[email protected]1f085622009-12-04 05:33:45245
246 count = pref->GetInteger(prefs::kStabilityChildProcessCrashCount);
247 if (count) {
248 WriteIntAttribute("childprocesscrashcount", count);
249 pref->SetInteger(prefs::kStabilityChildProcessCrashCount, 0);
250 }
[email protected]9165f742010-03-10 22:55:01251
[email protected]c1834a92011-01-21 18:21:03252#if defined(OS_CHROMEOS)
253 count = pref->GetInteger(prefs::kStabilityOtherUserCrashCount);
254 if (count) {
255 // TODO(kmixter): Write attribute once log server supports it
256 // and remove warning log.
257 // WriteIntAttribute("otherusercrashcount", count);
258 LOG(WARNING) << "Not yet able to send otherusercrashcount="
259 << count;
260 pref->SetInteger(prefs::kStabilityOtherUserCrashCount, 0);
261 }
262
263 count = pref->GetInteger(prefs::kStabilityKernelCrashCount);
264 if (count) {
265 // TODO(kmixter): Write attribute once log server supports it
266 // and remove warning log.
267 // WriteIntAttribute("kernelcrashcount", count);
268 LOG(WARNING) << "Not yet able to send kernelcrashcount="
269 << count;
270 pref->SetInteger(prefs::kStabilityKernelCrashCount, 0);
271 }
272
273 count = pref->GetInteger(prefs::kStabilitySystemUncleanShutdownCount);
274 if (count) {
275 // TODO(kmixter): Write attribute once log server supports it
276 // and remove warning log.
277 // WriteIntAttribute("systemuncleanshutdowns", count);
278 LOG(WARNING) << "Not yet able to send systemuncleanshutdowns="
279 << count;
280 pref->SetInteger(prefs::kStabilitySystemUncleanShutdownCount, 0);
281 }
282#endif // OS_CHROMEOS
283
[email protected]9165f742010-03-10 22:55:01284 int64 recent_duration = GetIncrementalUptime(pref);
285 if (recent_duration)
286 WriteInt64Attribute("uptimesec", recent_duration);
[email protected]0b33f80b2008-12-17 21:34:36287}
288
initial.commit09911bf2008-07-26 23:55:29289void MetricsLog::WritePluginList(
[email protected]91d9f3d2011-08-14 05:24:44290 const std::vector<webkit::WebPluginInfo>& plugin_list) {
initial.commit09911bf2008-07-26 23:55:29291 DCHECK(!locked_);
292
[email protected]10084982011-08-19 17:56:56293 ProfileManager* profile_manager = g_browser_process->profile_manager();
[email protected]24c935e52011-09-01 12:06:26294 std::vector<Profile*> profiles = profile_manager->GetLoadedProfiles();
295 PluginPrefs* plugin_prefs = NULL;
296 if (!profiles.empty())
297 plugin_prefs = PluginPrefs::GetForProfile(profiles.front());
[email protected]10084982011-08-19 17:56:56298
[email protected]ffaf78a2008-11-12 17:38:33299 OPEN_ELEMENT_FOR_SCOPE("plugins");
initial.commit09911bf2008-07-26 23:55:29300
[email protected]91d9f3d2011-08-14 05:24:44301 for (std::vector<webkit::WebPluginInfo>::const_iterator iter =
[email protected]191eb3f72010-12-21 06:27:50302 plugin_list.begin();
initial.commit09911bf2008-07-26 23:55:29303 iter != plugin_list.end(); ++iter) {
[email protected]ffaf78a2008-11-12 17:38:33304 OPEN_ELEMENT_FOR_SCOPE("plugin");
initial.commit09911bf2008-07-26 23:55:29305
306 // Plugin name and filename are hashed for the privacy of those
307 // testing unreleased new extensions.
[email protected]c9d811372010-06-23 21:44:57308 WriteAttribute("name", CreateBase64Hash(UTF16ToUTF8(iter->name)));
[email protected]0abb1652011-02-07 23:37:55309 std::string filename_bytes =
310#if defined(OS_WIN)
311 UTF16ToUTF8(iter->path.BaseName().value());
312#else
313 iter->path.BaseName().value();
314#endif
315 WriteAttribute("filename", CreateBase64Hash(filename_bytes));
[email protected]c9d811372010-06-23 21:44:57316 WriteAttribute("version", UTF16ToUTF8(iter->version));
[email protected]24c935e52011-09-01 12:06:26317 if (plugin_prefs)
318 WriteIntAttribute("disabled", !plugin_prefs->IsPluginEnabled(*iter));
initial.commit09911bf2008-07-26 23:55:29319 }
initial.commit09911bf2008-07-26 23:55:29320}
321
[email protected]147bbc0b2009-01-06 19:37:40322void MetricsLog::WriteInstallElement() {
323 OPEN_ELEMENT_FOR_SCOPE("install");
324 WriteAttribute("installdate", GetInstallDate());
325 WriteIntAttribute("buildid", 0); // We're using appversion instead.
[email protected]147bbc0b2009-01-06 19:37:40326}
327
initial.commit09911bf2008-07-26 23:55:29328void MetricsLog::RecordEnvironment(
[email protected]91d9f3d2011-08-14 05:24:44329 const std::vector<webkit::WebPluginInfo>& plugin_list,
initial.commit09911bf2008-07-26 23:55:29330 const DictionaryValue* profile_metrics) {
331 DCHECK(!locked_);
332
333 PrefService* pref = g_browser_process->local_state();
334
[email protected]ffaf78a2008-11-12 17:38:33335 OPEN_ELEMENT_FOR_SCOPE("profile");
initial.commit09911bf2008-07-26 23:55:29336 WriteCommonEventAttributes();
337
[email protected]147bbc0b2009-01-06 19:37:40338 WriteInstallElement();
initial.commit09911bf2008-07-26 23:55:29339
340 WritePluginList(plugin_list);
341
[email protected]c1834a92011-01-21 18:21:03342 WriteStabilityElement(pref);
initial.commit09911bf2008-07-26 23:55:29343
344 {
345 OPEN_ELEMENT_FOR_SCOPE("cpu");
[email protected]05f9b682008-09-29 22:18:01346 WriteAttribute("arch", base::SysInfo::CPUArchitecture());
initial.commit09911bf2008-07-26 23:55:29347 }
348
349 {
initial.commit09911bf2008-07-26 23:55:29350 OPEN_ELEMENT_FOR_SCOPE("memory");
[email protected]ed6fc352008-09-18 12:44:40351 WriteIntAttribute("mb", base::SysInfo::AmountOfPhysicalMemoryMB());
[email protected]d1be67b2008-11-19 20:28:38352#if defined(OS_WIN)
353 WriteIntAttribute("dllbase", reinterpret_cast<int>(&__ImageBase));
354#endif
initial.commit09911bf2008-07-26 23:55:29355 }
356
357 {
358 OPEN_ELEMENT_FOR_SCOPE("os");
359 WriteAttribute("name",
[email protected]05f9b682008-09-29 22:18:01360 base::SysInfo::OperatingSystemName());
initial.commit09911bf2008-07-26 23:55:29361 WriteAttribute("version",
[email protected]05f9b682008-09-29 22:18:01362 base::SysInfo::OperatingSystemVersion());
initial.commit09911bf2008-07-26 23:55:29363 }
364
365 {
[email protected]e8c287c872010-07-20 00:49:42366 OPEN_ELEMENT_FOR_SCOPE("gpu");
[email protected]27d8778e2011-03-09 22:00:59367 GpuDataManager* gpu_data_manager = GpuDataManager::GetInstance();
368 if (gpu_data_manager) {
369 WriteIntAttribute("vendorid", gpu_data_manager->gpu_info().vendor_id);
370 WriteIntAttribute("deviceid", gpu_data_manager->gpu_info().device_id);
[email protected]06b2fc92011-02-22 22:00:40371 }
[email protected]e8c287c872010-07-20 00:49:42372 }
373
374 {
initial.commit09911bf2008-07-26 23:55:29375 OPEN_ELEMENT_FOR_SCOPE("display");
[email protected]6b7d954ff2011-10-25 00:39:35376 const gfx::Size display_size = gfx::Screen::GetPrimaryMonitorSize();
377 WriteIntAttribute("xsize", display_size.width());
378 WriteIntAttribute("ysize", display_size.height());
379 WriteIntAttribute("screens", gfx::Screen::GetNumMonitors());
initial.commit09911bf2008-07-26 23:55:29380 }
381
382 {
383 OPEN_ELEMENT_FOR_SCOPE("bookmarks");
384 int num_bookmarks_on_bookmark_bar =
385 pref->GetInteger(prefs::kNumBookmarksOnBookmarkBar);
386 int num_folders_on_bookmark_bar =
387 pref->GetInteger(prefs::kNumFoldersOnBookmarkBar);
388 int num_bookmarks_in_other_bookmarks_folder =
389 pref->GetInteger(prefs::kNumBookmarksInOtherBookmarkFolder);
390 int num_folders_in_other_bookmarks_folder =
391 pref->GetInteger(prefs::kNumFoldersInOtherBookmarkFolder);
392 {
393 OPEN_ELEMENT_FOR_SCOPE("bookmarklocation");
394 WriteAttribute("name", "full-tree");
395 WriteIntAttribute("foldercount",
396 num_folders_on_bookmark_bar + num_folders_in_other_bookmarks_folder);
397 WriteIntAttribute("itemcount",
398 num_bookmarks_on_bookmark_bar +
399 num_bookmarks_in_other_bookmarks_folder);
400 }
401 {
402 OPEN_ELEMENT_FOR_SCOPE("bookmarklocation");
403 WriteAttribute("name", "toolbar");
404 WriteIntAttribute("foldercount", num_folders_on_bookmark_bar);
405 WriteIntAttribute("itemcount", num_bookmarks_on_bookmark_bar);
406 }
407 }
408
409 {
410 OPEN_ELEMENT_FOR_SCOPE("keywords");
411 WriteIntAttribute("count", pref->GetInteger(prefs::kNumKeywords));
412 }
413
414 if (profile_metrics)
415 WriteAllProfilesMetrics(*profile_metrics);
initial.commit09911bf2008-07-26 23:55:29416}
417
418void MetricsLog::WriteAllProfilesMetrics(
419 const DictionaryValue& all_profiles_metrics) {
[email protected]57ecc4b2010-08-11 03:02:51420 const std::string profile_prefix(prefs::kProfilePrefix);
initial.commit09911bf2008-07-26 23:55:29421 for (DictionaryValue::key_iterator i = all_profiles_metrics.begin_keys();
422 i != all_profiles_metrics.end_keys(); ++i) {
[email protected]e7b418b2010-07-30 19:47:47423 const std::string& key_name = *i;
initial.commit09911bf2008-07-26 23:55:29424 if (key_name.compare(0, profile_prefix.size(), profile_prefix) == 0) {
425 DictionaryValue* profile;
[email protected]4dad9ad82009-11-25 20:47:52426 if (all_profiles_metrics.GetDictionaryWithoutPathExpansion(key_name,
427 &profile))
initial.commit09911bf2008-07-26 23:55:29428 WriteProfileMetrics(key_name.substr(profile_prefix.size()), *profile);
429 }
430 }
431}
432
[email protected]e7b418b2010-07-30 19:47:47433void MetricsLog::WriteProfileMetrics(const std::string& profileidhash,
initial.commit09911bf2008-07-26 23:55:29434 const DictionaryValue& profile_metrics) {
435 OPEN_ELEMENT_FOR_SCOPE("userprofile");
[email protected]e7b418b2010-07-30 19:47:47436 WriteAttribute("profileidhash", profileidhash);
initial.commit09911bf2008-07-26 23:55:29437 for (DictionaryValue::key_iterator i = profile_metrics.begin_keys();
438 i != profile_metrics.end_keys(); ++i) {
439 Value* value;
[email protected]4dad9ad82009-11-25 20:47:52440 if (profile_metrics.GetWithoutPathExpansion(*i, &value)) {
[email protected]e7b418b2010-07-30 19:47:47441 DCHECK(*i != "id");
initial.commit09911bf2008-07-26 23:55:29442 switch (value->GetType()) {
443 case Value::TYPE_STRING: {
[email protected]5e324b72008-12-18 00:07:59444 std::string string_value;
initial.commit09911bf2008-07-26 23:55:29445 if (value->GetAsString(&string_value)) {
446 OPEN_ELEMENT_FOR_SCOPE("profileparam");
[email protected]e7b418b2010-07-30 19:47:47447 WriteAttribute("name", *i);
[email protected]5e324b72008-12-18 00:07:59448 WriteAttribute("value", string_value);
initial.commit09911bf2008-07-26 23:55:29449 }
450 break;
451 }
452
453 case Value::TYPE_BOOLEAN: {
454 bool bool_value;
455 if (value->GetAsBoolean(&bool_value)) {
456 OPEN_ELEMENT_FOR_SCOPE("profileparam");
[email protected]e7b418b2010-07-30 19:47:47457 WriteAttribute("name", *i);
initial.commit09911bf2008-07-26 23:55:29458 WriteIntAttribute("value", bool_value ? 1 : 0);
459 }
460 break;
461 }
462
463 case Value::TYPE_INTEGER: {
464 int int_value;
465 if (value->GetAsInteger(&int_value)) {
466 OPEN_ELEMENT_FOR_SCOPE("profileparam");
[email protected]e7b418b2010-07-30 19:47:47467 WriteAttribute("name", *i);
initial.commit09911bf2008-07-26 23:55:29468 WriteIntAttribute("value", int_value);
469 }
470 break;
471 }
472
473 default:
474 NOTREACHED();
475 break;
476 }
477 }
478 }
479}
480
481void MetricsLog::RecordOmniboxOpenedURL(const AutocompleteLog& log) {
482 DCHECK(!locked_);
483
[email protected]ffaf78a2008-11-12 17:38:33484 OPEN_ELEMENT_FOR_SCOPE("uielement");
initial.commit09911bf2008-07-26 23:55:29485 WriteAttribute("action", "autocomplete");
486 WriteAttribute("targetidhash", "");
487 // TODO(kochi): Properly track windows.
488 WriteIntAttribute("window", 0);
[email protected]6ebc3162011-12-19 13:44:00489 if (log.tab_id != -1) {
490 // If we know what tab the autocomplete URL was opened in, log it.
491 WriteIntAttribute("tab", static_cast<int>(log.tab_id));
492 }
initial.commit09911bf2008-07-26 23:55:29493 WriteCommonEventAttributes();
494
[email protected]ffaf78a2008-11-12 17:38:33495 {
496 OPEN_ELEMENT_FOR_SCOPE("autocomplete");
initial.commit09911bf2008-07-26 23:55:29497
[email protected]ffaf78a2008-11-12 17:38:33498 WriteIntAttribute("typedlength", static_cast<int>(log.text.length()));
499 WriteIntAttribute("selectedindex", static_cast<int>(log.selected_index));
500 WriteIntAttribute("completedlength",
501 static_cast<int>(log.inline_autocompleted_length));
[email protected]381e2992008-12-16 01:41:00502 const std::string input_type(
503 AutocompleteInput::TypeToString(log.input_type));
504 if (!input_type.empty())
505 WriteAttribute("inputtype", input_type);
initial.commit09911bf2008-07-26 23:55:29506
[email protected]ffaf78a2008-11-12 17:38:33507 for (AutocompleteResult::const_iterator i(log.result.begin());
508 i != log.result.end(); ++i) {
509 OPEN_ELEMENT_FOR_SCOPE("autocompleteitem");
510 if (i->provider)
511 WriteAttribute("provider", i->provider->name());
[email protected]381e2992008-12-16 01:41:00512 const std::string result_type(AutocompleteMatch::TypeToString(i->type));
513 if (!result_type.empty())
514 WriteAttribute("resulttype", result_type);
[email protected]ffaf78a2008-11-12 17:38:33515 WriteIntAttribute("relevance", i->relevance);
516 WriteIntAttribute("isstarred", i->starred ? 1 : 0);
517 }
initial.commit09911bf2008-07-26 23:55:29518 }
initial.commit09911bf2008-07-26 23:55:29519
520 ++num_events_;
521}