blob: 978ac56e07d961d4b095dc3b6a32768eeb403f63 [file] [log] [blame]
[email protected]1df44b72012-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
[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]1df44b72012-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
[email protected]67f92bc32012-01-26 01:56:1969static base::LazyInstance<std::string>::Leaky
[email protected]054c8012011-11-16 00:12:4270 g_version_extension = LAZY_INSTANCE_INITIALIZER;
71
[email protected]1226abb2010-06-10 18:01:2872MetricsLog::MetricsLog(const std::string& client_id, int session_id)
73 : MetricsLogBase(client_id, session_id, MetricsLog::GetVersionString()) {}
[email protected]5ed7d4572009-12-23 17:42:4174
[email protected]1226abb2010-06-10 18:01:2875MetricsLog::~MetricsLog() {}
initial.commit09911bf2008-07-26 23:55:2976
77// static
78void MetricsLog::RegisterPrefs(PrefService* local_state) {
79 local_state->RegisterListPref(prefs::kStabilityPluginStats);
initial.commit09911bf2008-07-26 23:55:2980}
81
[email protected]1df44b72012-01-19 05:20:3482// static
[email protected]9165f742010-03-10 22:55:0183int64 MetricsLog::GetIncrementalUptime(PrefService* pref) {
84 base::TimeTicks now = base::TimeTicks::Now();
85 static base::TimeTicks last_updated_time(now);
86 int64 incremental_time = (now - last_updated_time).InSeconds();
87 last_updated_time = now;
88
89 if (incremental_time > 0) {
90 int64 metrics_uptime = pref->GetInt64(prefs::kUninstallMetricsUptimeSec);
91 metrics_uptime += incremental_time;
92 pref->SetInt64(prefs::kUninstallMetricsUptimeSec, metrics_uptime);
93 }
94
95 return incremental_time;
96}
97
[email protected]1226abb2010-06-10 18:01:2898// static
99std::string MetricsLog::GetVersionString() {
[email protected]0211f57e2010-08-27 20:28:42100 chrome::VersionInfo version_info;
[email protected]30c91802010-12-18 00:40:17101 if (!version_info.is_valid()) {
102 NOTREACHED() << "Unable to retrieve version info.";
103 return std::string();
104 }
105
[email protected]0211f57e2010-08-27 20:28:42106 std::string version = version_info.Version();
[email protected]054c8012011-11-16 00:12:42107 if (!version_extension().empty())
108 version += version_extension();
[email protected]0211f57e2010-08-27 20:28:42109 if (!version_info.IsOfficialBuild())
110 version.append("-devel");
111 return version;
[email protected]1226abb2010-06-10 18:01:28112}
113
[email protected]054c8012011-11-16 00:12:42114// static
115void MetricsLog::set_version_extension(const std::string& extension) {
116 g_version_extension.Get() = extension;
117}
118
119// static
120const std::string& MetricsLog::version_extension() {
121 return g_version_extension.Get();
122}
123
[email protected]0b33f80b2008-12-17 21:34:36124void MetricsLog::RecordIncrementalStabilityElements() {
125 DCHECK(!locked_);
126
127 PrefService* pref = g_browser_process->local_state();
128 DCHECK(pref);
129
[email protected]147bbc0b2009-01-06 19:37:40130 OPEN_ELEMENT_FOR_SCOPE("profile");
131 WriteCommonEventAttributes();
132
[email protected]9958a322011-03-08 20:04:17133 WriteInstallElement();
[email protected]147bbc0b2009-01-06 19:37:40134
135 {
136 OPEN_ELEMENT_FOR_SCOPE("stability"); // Minimal set of stability elements.
137 WriteRequiredStabilityAttributes(pref);
138 WriteRealtimeStabilityAttributes(pref);
139
140 WritePluginStabilityElements(pref);
141 }
[email protected]0b33f80b2008-12-17 21:34:36142}
143
[email protected]c1834a92011-01-21 18:21:03144void MetricsLog::WriteStabilityElement(PrefService* pref) {
initial.commit09911bf2008-07-26 23:55:29145 DCHECK(!locked_);
146
initial.commit09911bf2008-07-26 23:55:29147 DCHECK(pref);
148
149 // Get stability attributes out of Local State, zeroing out stored values.
150 // NOTE: This could lead to some data loss if this report isn't successfully
151 // sent, but that's true for all the metrics.
152
[email protected]ffaf78a2008-11-12 17:38:33153 OPEN_ELEMENT_FOR_SCOPE("stability");
[email protected]147bbc0b2009-01-06 19:37:40154 WriteRequiredStabilityAttributes(pref);
155 WriteRealtimeStabilityAttributes(pref);
initial.commit09911bf2008-07-26 23:55:29156
[email protected]0b33f80b2008-12-17 21:34:36157 // TODO(jar): The following are all optional, so we *could* optimize them for
158 // values of zero (and not include them).
[email protected]8e674e42008-07-30 16:05:48159 WriteIntAttribute("incompleteshutdowncount",
160 pref->GetInteger(
161 prefs::kStabilityIncompleteSessionEndCount));
162 pref->SetInteger(prefs::kStabilityIncompleteSessionEndCount, 0);
[email protected]0b33f80b2008-12-17 21:34:36163
164
[email protected]e73c01972008-08-13 00:18:24165 WriteIntAttribute("breakpadregistrationok",
166 pref->GetInteger(prefs::kStabilityBreakpadRegistrationSuccess));
167 pref->SetInteger(prefs::kStabilityBreakpadRegistrationSuccess, 0);
168 WriteIntAttribute("breakpadregistrationfail",
169 pref->GetInteger(prefs::kStabilityBreakpadRegistrationFail));
170 pref->SetInteger(prefs::kStabilityBreakpadRegistrationFail, 0);
171 WriteIntAttribute("debuggerpresent",
172 pref->GetInteger(prefs::kStabilityDebuggerPresent));
173 pref->SetInteger(prefs::kStabilityDebuggerPresent, 0);
174 WriteIntAttribute("debuggernotpresent",
175 pref->GetInteger(prefs::kStabilityDebuggerNotPresent));
176 pref->SetInteger(prefs::kStabilityDebuggerNotPresent, 0);
initial.commit09911bf2008-07-26 23:55:29177
[email protected]147bbc0b2009-01-06 19:37:40178 WritePluginStabilityElements(pref);
179}
180
181void MetricsLog::WritePluginStabilityElements(PrefService* pref) {
182 // Now log plugin stability info.
initial.commit09911bf2008-07-26 23:55:29183 const ListValue* plugin_stats_list = pref->GetList(
184 prefs::kStabilityPluginStats);
[email protected]1df44b72012-01-19 05:20:34185 if (!plugin_stats_list)
186 return;
initial.commit09911bf2008-07-26 23:55:29187
[email protected]1df44b72012-01-19 05:20:34188 OPEN_ELEMENT_FOR_SCOPE("plugins");
189 for (ListValue::const_iterator iter = plugin_stats_list->begin();
190 iter != plugin_stats_list->end(); ++iter) {
191 if (!(*iter)->IsType(Value::TYPE_DICTIONARY)) {
192 NOTREACHED();
193 continue;
initial.commit09911bf2008-07-26 23:55:29194 }
[email protected]1df44b72012-01-19 05:20:34195 DictionaryValue* plugin_dict = static_cast<DictionaryValue*>(*iter);
initial.commit09911bf2008-07-26 23:55:29196
[email protected]1df44b72012-01-19 05:20:34197 std::string plugin_name;
198 plugin_dict->GetString(prefs::kStabilityPluginName, &plugin_name);
199
200 OPEN_ELEMENT_FOR_SCOPE("pluginstability");
201 // Use "filename" instead of "name", otherwise we need to update the
202 // UMA servers.
203 WriteAttribute("filename", CreateBase64Hash(plugin_name));
204
205 int launches = 0;
206 plugin_dict->GetInteger(prefs::kStabilityPluginLaunches, &launches);
207 WriteIntAttribute("launchcount", launches);
208
209 int instances = 0;
210 plugin_dict->GetInteger(prefs::kStabilityPluginInstances, &instances);
211 WriteIntAttribute("instancecount", instances);
212
213 int crashes = 0;
214 plugin_dict->GetInteger(prefs::kStabilityPluginCrashes, &crashes);
215 WriteIntAttribute("crashcount", crashes);
initial.commit09911bf2008-07-26 23:55:29216 }
[email protected]1df44b72012-01-19 05:20:34217
218 pref->ClearPref(prefs::kStabilityPluginStats);
initial.commit09911bf2008-07-26 23:55:29219}
220
[email protected]147bbc0b2009-01-06 19:37:40221void MetricsLog::WriteRequiredStabilityAttributes(PrefService* pref) {
[email protected]0b33f80b2008-12-17 21:34:36222 // The server refuses data that doesn't have certain values. crashcount and
223 // launchcount are currently "required" in the "stability" group.
224 WriteIntAttribute("launchcount",
225 pref->GetInteger(prefs::kStabilityLaunchCount));
226 pref->SetInteger(prefs::kStabilityLaunchCount, 0);
227 WriteIntAttribute("crashcount",
228 pref->GetInteger(prefs::kStabilityCrashCount));
229 pref->SetInteger(prefs::kStabilityCrashCount, 0);
230}
231
[email protected]147bbc0b2009-01-06 19:37:40232void MetricsLog::WriteRealtimeStabilityAttributes(PrefService* pref) {
[email protected]0b33f80b2008-12-17 21:34:36233 // Update the stats which are critical for real-time stability monitoring.
234 // Since these are "optional," only list ones that are non-zero, as the counts
235 // are aggergated (summed) server side.
236
237 int count = pref->GetInteger(prefs::kStabilityPageLoadCount);
238 if (count) {
239 WriteIntAttribute("pageloadcount", count);
240 pref->SetInteger(prefs::kStabilityPageLoadCount, 0);
241 }
242
243 count = pref->GetInteger(prefs::kStabilityRendererCrashCount);
244 if (count) {
245 WriteIntAttribute("renderercrashcount", count);
246 pref->SetInteger(prefs::kStabilityRendererCrashCount, 0);
247 }
248
[email protected]1f085622009-12-04 05:33:45249 count = pref->GetInteger(prefs::kStabilityExtensionRendererCrashCount);
250 if (count) {
251 WriteIntAttribute("extensionrenderercrashcount", count);
252 pref->SetInteger(prefs::kStabilityExtensionRendererCrashCount, 0);
253 }
254
[email protected]0b33f80b2008-12-17 21:34:36255 count = pref->GetInteger(prefs::kStabilityRendererHangCount);
256 if (count) {
257 WriteIntAttribute("rendererhangcount", count);
258 pref->SetInteger(prefs::kStabilityRendererHangCount, 0);
259 }
[email protected]1f085622009-12-04 05:33:45260
261 count = pref->GetInteger(prefs::kStabilityChildProcessCrashCount);
262 if (count) {
263 WriteIntAttribute("childprocesscrashcount", count);
264 pref->SetInteger(prefs::kStabilityChildProcessCrashCount, 0);
265 }
[email protected]9165f742010-03-10 22:55:01266
[email protected]c1834a92011-01-21 18:21:03267#if defined(OS_CHROMEOS)
268 count = pref->GetInteger(prefs::kStabilityOtherUserCrashCount);
269 if (count) {
270 // TODO(kmixter): Write attribute once log server supports it
271 // and remove warning log.
272 // WriteIntAttribute("otherusercrashcount", count);
273 LOG(WARNING) << "Not yet able to send otherusercrashcount="
274 << count;
275 pref->SetInteger(prefs::kStabilityOtherUserCrashCount, 0);
276 }
277
278 count = pref->GetInteger(prefs::kStabilityKernelCrashCount);
279 if (count) {
280 // TODO(kmixter): Write attribute once log server supports it
281 // and remove warning log.
282 // WriteIntAttribute("kernelcrashcount", count);
283 LOG(WARNING) << "Not yet able to send kernelcrashcount="
284 << count;
285 pref->SetInteger(prefs::kStabilityKernelCrashCount, 0);
286 }
287
288 count = pref->GetInteger(prefs::kStabilitySystemUncleanShutdownCount);
289 if (count) {
290 // TODO(kmixter): Write attribute once log server supports it
291 // and remove warning log.
292 // WriteIntAttribute("systemuncleanshutdowns", count);
293 LOG(WARNING) << "Not yet able to send systemuncleanshutdowns="
294 << count;
295 pref->SetInteger(prefs::kStabilitySystemUncleanShutdownCount, 0);
296 }
297#endif // OS_CHROMEOS
298
[email protected]9165f742010-03-10 22:55:01299 int64 recent_duration = GetIncrementalUptime(pref);
300 if (recent_duration)
301 WriteInt64Attribute("uptimesec", recent_duration);
[email protected]0b33f80b2008-12-17 21:34:36302}
303
initial.commit09911bf2008-07-26 23:55:29304void MetricsLog::WritePluginList(
[email protected]91d9f3d2011-08-14 05:24:44305 const std::vector<webkit::WebPluginInfo>& plugin_list) {
initial.commit09911bf2008-07-26 23:55:29306 DCHECK(!locked_);
307
[email protected]1df44b72012-01-19 05:20:34308 PluginPrefs* plugin_prefs = GetPluginPrefs();
[email protected]10084982011-08-19 17:56:56309
[email protected]ffaf78a2008-11-12 17:38:33310 OPEN_ELEMENT_FOR_SCOPE("plugins");
initial.commit09911bf2008-07-26 23:55:29311
[email protected]91d9f3d2011-08-14 05:24:44312 for (std::vector<webkit::WebPluginInfo>::const_iterator iter =
[email protected]191eb3f72010-12-21 06:27:50313 plugin_list.begin();
initial.commit09911bf2008-07-26 23:55:29314 iter != plugin_list.end(); ++iter) {
[email protected]ffaf78a2008-11-12 17:38:33315 OPEN_ELEMENT_FOR_SCOPE("plugin");
initial.commit09911bf2008-07-26 23:55:29316
317 // Plugin name and filename are hashed for the privacy of those
318 // testing unreleased new extensions.
[email protected]c9d811372010-06-23 21:44:57319 WriteAttribute("name", CreateBase64Hash(UTF16ToUTF8(iter->name)));
[email protected]0abb1652011-02-07 23:37:55320 std::string filename_bytes =
321#if defined(OS_WIN)
322 UTF16ToUTF8(iter->path.BaseName().value());
323#else
324 iter->path.BaseName().value();
325#endif
326 WriteAttribute("filename", CreateBase64Hash(filename_bytes));
[email protected]c9d811372010-06-23 21:44:57327 WriteAttribute("version", UTF16ToUTF8(iter->version));
[email protected]24c935e52011-09-01 12:06:26328 if (plugin_prefs)
329 WriteIntAttribute("disabled", !plugin_prefs->IsPluginEnabled(*iter));
initial.commit09911bf2008-07-26 23:55:29330 }
initial.commit09911bf2008-07-26 23:55:29331}
332
[email protected]147bbc0b2009-01-06 19:37:40333void MetricsLog::WriteInstallElement() {
334 OPEN_ELEMENT_FOR_SCOPE("install");
335 WriteAttribute("installdate", GetInstallDate());
336 WriteIntAttribute("buildid", 0); // We're using appversion instead.
[email protected]147bbc0b2009-01-06 19:37:40337}
338
initial.commit09911bf2008-07-26 23:55:29339void MetricsLog::RecordEnvironment(
[email protected]91d9f3d2011-08-14 05:24:44340 const std::vector<webkit::WebPluginInfo>& plugin_list,
initial.commit09911bf2008-07-26 23:55:29341 const DictionaryValue* profile_metrics) {
342 DCHECK(!locked_);
343
344 PrefService* pref = g_browser_process->local_state();
345
[email protected]ffaf78a2008-11-12 17:38:33346 OPEN_ELEMENT_FOR_SCOPE("profile");
initial.commit09911bf2008-07-26 23:55:29347 WriteCommonEventAttributes();
348
[email protected]147bbc0b2009-01-06 19:37:40349 WriteInstallElement();
initial.commit09911bf2008-07-26 23:55:29350
351 WritePluginList(plugin_list);
352
[email protected]c1834a92011-01-21 18:21:03353 WriteStabilityElement(pref);
initial.commit09911bf2008-07-26 23:55:29354
355 {
356 OPEN_ELEMENT_FOR_SCOPE("cpu");
[email protected]05f9b682008-09-29 22:18:01357 WriteAttribute("arch", base::SysInfo::CPUArchitecture());
initial.commit09911bf2008-07-26 23:55:29358 }
359
360 {
initial.commit09911bf2008-07-26 23:55:29361 OPEN_ELEMENT_FOR_SCOPE("memory");
[email protected]ed6fc352008-09-18 12:44:40362 WriteIntAttribute("mb", base::SysInfo::AmountOfPhysicalMemoryMB());
[email protected]d1be67b2008-11-19 20:28:38363#if defined(OS_WIN)
364 WriteIntAttribute("dllbase", reinterpret_cast<int>(&__ImageBase));
365#endif
initial.commit09911bf2008-07-26 23:55:29366 }
367
368 {
369 OPEN_ELEMENT_FOR_SCOPE("os");
370 WriteAttribute("name",
[email protected]05f9b682008-09-29 22:18:01371 base::SysInfo::OperatingSystemName());
initial.commit09911bf2008-07-26 23:55:29372 WriteAttribute("version",
[email protected]05f9b682008-09-29 22:18:01373 base::SysInfo::OperatingSystemVersion());
initial.commit09911bf2008-07-26 23:55:29374 }
375
376 {
[email protected]e8c287c872010-07-20 00:49:42377 OPEN_ELEMENT_FOR_SCOPE("gpu");
[email protected]27d8778e2011-03-09 22:00:59378 GpuDataManager* gpu_data_manager = GpuDataManager::GetInstance();
379 if (gpu_data_manager) {
380 WriteIntAttribute("vendorid", gpu_data_manager->gpu_info().vendor_id);
381 WriteIntAttribute("deviceid", gpu_data_manager->gpu_info().device_id);
[email protected]06b2fc92011-02-22 22:00:40382 }
[email protected]e8c287c872010-07-20 00:49:42383 }
384
385 {
initial.commit09911bf2008-07-26 23:55:29386 OPEN_ELEMENT_FOR_SCOPE("display");
[email protected]6b7d954ff2011-10-25 00:39:35387 const gfx::Size display_size = gfx::Screen::GetPrimaryMonitorSize();
388 WriteIntAttribute("xsize", display_size.width());
389 WriteIntAttribute("ysize", display_size.height());
390 WriteIntAttribute("screens", gfx::Screen::GetNumMonitors());
initial.commit09911bf2008-07-26 23:55:29391 }
392
393 {
394 OPEN_ELEMENT_FOR_SCOPE("bookmarks");
395 int num_bookmarks_on_bookmark_bar =
396 pref->GetInteger(prefs::kNumBookmarksOnBookmarkBar);
397 int num_folders_on_bookmark_bar =
398 pref->GetInteger(prefs::kNumFoldersOnBookmarkBar);
399 int num_bookmarks_in_other_bookmarks_folder =
400 pref->GetInteger(prefs::kNumBookmarksInOtherBookmarkFolder);
401 int num_folders_in_other_bookmarks_folder =
402 pref->GetInteger(prefs::kNumFoldersInOtherBookmarkFolder);
403 {
404 OPEN_ELEMENT_FOR_SCOPE("bookmarklocation");
405 WriteAttribute("name", "full-tree");
406 WriteIntAttribute("foldercount",
407 num_folders_on_bookmark_bar + num_folders_in_other_bookmarks_folder);
408 WriteIntAttribute("itemcount",
409 num_bookmarks_on_bookmark_bar +
410 num_bookmarks_in_other_bookmarks_folder);
411 }
412 {
413 OPEN_ELEMENT_FOR_SCOPE("bookmarklocation");
414 WriteAttribute("name", "toolbar");
415 WriteIntAttribute("foldercount", num_folders_on_bookmark_bar);
416 WriteIntAttribute("itemcount", num_bookmarks_on_bookmark_bar);
417 }
418 }
419
420 {
421 OPEN_ELEMENT_FOR_SCOPE("keywords");
422 WriteIntAttribute("count", pref->GetInteger(prefs::kNumKeywords));
423 }
424
425 if (profile_metrics)
426 WriteAllProfilesMetrics(*profile_metrics);
initial.commit09911bf2008-07-26 23:55:29427}
428
429void MetricsLog::WriteAllProfilesMetrics(
430 const DictionaryValue& all_profiles_metrics) {
[email protected]57ecc4b2010-08-11 03:02:51431 const std::string profile_prefix(prefs::kProfilePrefix);
initial.commit09911bf2008-07-26 23:55:29432 for (DictionaryValue::key_iterator i = all_profiles_metrics.begin_keys();
433 i != all_profiles_metrics.end_keys(); ++i) {
[email protected]e7b418b2010-07-30 19:47:47434 const std::string& key_name = *i;
initial.commit09911bf2008-07-26 23:55:29435 if (key_name.compare(0, profile_prefix.size(), profile_prefix) == 0) {
436 DictionaryValue* profile;
[email protected]4dad9ad82009-11-25 20:47:52437 if (all_profiles_metrics.GetDictionaryWithoutPathExpansion(key_name,
438 &profile))
initial.commit09911bf2008-07-26 23:55:29439 WriteProfileMetrics(key_name.substr(profile_prefix.size()), *profile);
440 }
441 }
442}
443
[email protected]e7b418b2010-07-30 19:47:47444void MetricsLog::WriteProfileMetrics(const std::string& profileidhash,
initial.commit09911bf2008-07-26 23:55:29445 const DictionaryValue& profile_metrics) {
446 OPEN_ELEMENT_FOR_SCOPE("userprofile");
[email protected]e7b418b2010-07-30 19:47:47447 WriteAttribute("profileidhash", profileidhash);
initial.commit09911bf2008-07-26 23:55:29448 for (DictionaryValue::key_iterator i = profile_metrics.begin_keys();
449 i != profile_metrics.end_keys(); ++i) {
450 Value* value;
[email protected]4dad9ad82009-11-25 20:47:52451 if (profile_metrics.GetWithoutPathExpansion(*i, &value)) {
[email protected]e7b418b2010-07-30 19:47:47452 DCHECK(*i != "id");
initial.commit09911bf2008-07-26 23:55:29453 switch (value->GetType()) {
454 case Value::TYPE_STRING: {
[email protected]5e324b72008-12-18 00:07:59455 std::string string_value;
initial.commit09911bf2008-07-26 23:55:29456 if (value->GetAsString(&string_value)) {
457 OPEN_ELEMENT_FOR_SCOPE("profileparam");
[email protected]e7b418b2010-07-30 19:47:47458 WriteAttribute("name", *i);
[email protected]5e324b72008-12-18 00:07:59459 WriteAttribute("value", string_value);
initial.commit09911bf2008-07-26 23:55:29460 }
461 break;
462 }
463
464 case Value::TYPE_BOOLEAN: {
465 bool bool_value;
466 if (value->GetAsBoolean(&bool_value)) {
467 OPEN_ELEMENT_FOR_SCOPE("profileparam");
[email protected]e7b418b2010-07-30 19:47:47468 WriteAttribute("name", *i);
initial.commit09911bf2008-07-26 23:55:29469 WriteIntAttribute("value", bool_value ? 1 : 0);
470 }
471 break;
472 }
473
474 case Value::TYPE_INTEGER: {
475 int int_value;
476 if (value->GetAsInteger(&int_value)) {
477 OPEN_ELEMENT_FOR_SCOPE("profileparam");
[email protected]e7b418b2010-07-30 19:47:47478 WriteAttribute("name", *i);
initial.commit09911bf2008-07-26 23:55:29479 WriteIntAttribute("value", int_value);
480 }
481 break;
482 }
483
484 default:
485 NOTREACHED();
486 break;
487 }
488 }
489 }
490}
491
492void MetricsLog::RecordOmniboxOpenedURL(const AutocompleteLog& log) {
493 DCHECK(!locked_);
494
[email protected]ffaf78a2008-11-12 17:38:33495 OPEN_ELEMENT_FOR_SCOPE("uielement");
initial.commit09911bf2008-07-26 23:55:29496 WriteAttribute("action", "autocomplete");
497 WriteAttribute("targetidhash", "");
498 // TODO(kochi): Properly track windows.
499 WriteIntAttribute("window", 0);
[email protected]6ebc3162011-12-19 13:44:00500 if (log.tab_id != -1) {
501 // If we know what tab the autocomplete URL was opened in, log it.
502 WriteIntAttribute("tab", static_cast<int>(log.tab_id));
503 }
initial.commit09911bf2008-07-26 23:55:29504 WriteCommonEventAttributes();
505
[email protected]ffaf78a2008-11-12 17:38:33506 {
507 OPEN_ELEMENT_FOR_SCOPE("autocomplete");
initial.commit09911bf2008-07-26 23:55:29508
[email protected]ffaf78a2008-11-12 17:38:33509 WriteIntAttribute("typedlength", static_cast<int>(log.text.length()));
[email protected]0fdc15d2012-01-24 22:32:08510 std::vector<string16> terms;
511 WriteIntAttribute("numterms",
512 static_cast<int>(Tokenize(log.text, kWhitespaceUTF16, &terms)));
[email protected]ffaf78a2008-11-12 17:38:33513 WriteIntAttribute("selectedindex", static_cast<int>(log.selected_index));
514 WriteIntAttribute("completedlength",
515 static_cast<int>(log.inline_autocompleted_length));
[email protected]9e349762012-01-31 03:24:36516 if (log.elapsed_time_since_user_first_modified_omnibox !=
517 base::TimeDelta::FromMilliseconds(-1)) {
518 // Only upload the typing duration if it is set/valid.
519 WriteInt64Attribute("typingduration",
520 log.elapsed_time_since_user_first_modified_omnibox.InMilliseconds());
521 }
[email protected]381e2992008-12-16 01:41:00522 const std::string input_type(
523 AutocompleteInput::TypeToString(log.input_type));
524 if (!input_type.empty())
525 WriteAttribute("inputtype", input_type);
initial.commit09911bf2008-07-26 23:55:29526
[email protected]ffaf78a2008-11-12 17:38:33527 for (AutocompleteResult::const_iterator i(log.result.begin());
528 i != log.result.end(); ++i) {
529 OPEN_ELEMENT_FOR_SCOPE("autocompleteitem");
530 if (i->provider)
531 WriteAttribute("provider", i->provider->name());
[email protected]381e2992008-12-16 01:41:00532 const std::string result_type(AutocompleteMatch::TypeToString(i->type));
533 if (!result_type.empty())
534 WriteAttribute("resulttype", result_type);
[email protected]ffaf78a2008-11-12 17:38:33535 WriteIntAttribute("relevance", i->relevance);
536 WriteIntAttribute("isstarred", i->starred ? 1 : 0);
537 }
initial.commit09911bf2008-07-26 23:55:29538 }
initial.commit09911bf2008-07-26 23:55:29539
540 ++num_events_;
541}