[email protected] | 85ed9d4 | 2010-06-08 22:37:44 | [diff] [blame] | 1 | // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
license.bot | bf09a50 | 2008-08-24 00:55:55 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4 | |
[email protected] | cd1adc2 | 2009-01-16 01:29:22 | [diff] [blame] | 5 | #include "chrome/browser/metrics/metrics_log.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 6 | |
[email protected] | 1eeb5e0 | 2010-07-20 23:02:11 | [diff] [blame] | 7 | #include <string> |
| 8 | #include <vector> |
| 9 | |
[email protected] | 978df34 | 2009-11-24 06:21:53 | [diff] [blame] | 10 | #include "base/base64.h" |
[email protected] | d1be67b | 2008-11-19 20:28:38 | [diff] [blame] | 11 | #include "base/basictypes.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 12 | #include "base/file_util.h" |
| 13 | #include "base/file_version_info.h" |
| 14 | #include "base/md5.h" |
[email protected] | 85ed9d4 | 2010-06-08 22:37:44 | [diff] [blame] | 15 | #include "base/perftimer.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 16 | #include "base/scoped_ptr.h" |
| 17 | #include "base/string_util.h" |
[email protected] | fadf97f | 2008-09-18 12:18:14 | [diff] [blame] | 18 | #include "base/sys_info.h" |
[email protected] | 37f39e4 | 2010-01-06 17:35:17 | [diff] [blame] | 19 | #include "base/third_party/nspr/prtime.h" |
[email protected] | 1eeb5e0 | 2010-07-20 23:02:11 | [diff] [blame] | 20 | #include "base/time.h" |
| 21 | #include "base/utf_string_conversions.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 22 | #include "chrome/browser/autocomplete/autocomplete.h" |
| 23 | #include "chrome/browser/browser_process.h" |
[email protected] | e8c287c87 | 2010-07-20 00:49:42 | [diff] [blame] | 24 | #include "chrome/browser/gpu_process_host.h" |
[email protected] | 052313b | 2010-02-19 09:43:08 | [diff] [blame] | 25 | #include "chrome/browser/pref_service.h" |
[email protected] | 1eeb5e0 | 2010-07-20 23:02:11 | [diff] [blame] | 26 | #include "chrome/common/chrome_version_info.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 27 | #include "chrome/common/logging_chrome.h" |
| 28 | #include "chrome/common/pref_names.h" |
[email protected] | 46072d4 | 2008-07-28 14:49:35 | [diff] [blame] | 29 | #include "googleurl/src/gurl.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 30 | |
| 31 | #define OPEN_ELEMENT_FOR_SCOPE(name) ScopedElement scoped_element(this, name) |
| 32 | |
[email protected] | d1be67b | 2008-11-19 20:28:38 | [diff] [blame] | 33 | // http://blogs.msdn.com/oldnewthing/archive/2004/10/25/247180.aspx |
| 34 | #if defined(OS_WIN) |
| 35 | extern "C" IMAGE_DOS_HEADER __ImageBase; |
| 36 | #endif |
| 37 | |
[email protected] | 1226abb | 2010-06-10 18:01:28 | [diff] [blame] | 38 | MetricsLog::MetricsLog(const std::string& client_id, int session_id) |
| 39 | : MetricsLogBase(client_id, session_id, MetricsLog::GetVersionString()) {} |
[email protected] | 5ed7d457 | 2009-12-23 17:42:41 | [diff] [blame] | 40 | |
[email protected] | 1226abb | 2010-06-10 18:01:28 | [diff] [blame] | 41 | MetricsLog::~MetricsLog() {} |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 42 | |
| 43 | // static |
| 44 | void MetricsLog::RegisterPrefs(PrefService* local_state) { |
| 45 | local_state->RegisterListPref(prefs::kStabilityPluginStats); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 46 | } |
| 47 | |
[email protected] | 9165f74 | 2010-03-10 22:55:01 | [diff] [blame] | 48 | int64 MetricsLog::GetIncrementalUptime(PrefService* pref) { |
| 49 | base::TimeTicks now = base::TimeTicks::Now(); |
| 50 | static base::TimeTicks last_updated_time(now); |
| 51 | int64 incremental_time = (now - last_updated_time).InSeconds(); |
| 52 | last_updated_time = now; |
| 53 | |
| 54 | if (incremental_time > 0) { |
| 55 | int64 metrics_uptime = pref->GetInt64(prefs::kUninstallMetricsUptimeSec); |
| 56 | metrics_uptime += incremental_time; |
| 57 | pref->SetInt64(prefs::kUninstallMetricsUptimeSec, metrics_uptime); |
| 58 | } |
| 59 | |
| 60 | return incremental_time; |
| 61 | } |
| 62 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 63 | std::string MetricsLog::GetInstallDate() const { |
| 64 | PrefService* pref = g_browser_process->local_state(); |
| 65 | if (pref) { |
[email protected] | ddd231e | 2010-06-29 20:35:19 | [diff] [blame] | 66 | return pref->GetString(prefs::kMetricsClientIDTimestamp); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 67 | } else { |
| 68 | NOTREACHED(); |
| 69 | return "0"; |
| 70 | } |
| 71 | } |
| 72 | |
[email protected] | 1226abb | 2010-06-10 18:01:28 | [diff] [blame] | 73 | // static |
| 74 | std::string MetricsLog::GetVersionString() { |
| 75 | scoped_ptr<FileVersionInfo> version_info( |
[email protected] | 1eeb5e0 | 2010-07-20 23:02:11 | [diff] [blame] | 76 | chrome::GetChromeVersionInfo()); |
[email protected] | 1226abb | 2010-06-10 18:01:28 | [diff] [blame] | 77 | if (version_info.get()) { |
| 78 | std::string version = WideToUTF8(version_info->product_version()); |
| 79 | if (!version_extension_.empty()) |
| 80 | version += version_extension_; |
| 81 | if (!version_info->is_official_build()) |
| 82 | version.append("-devel"); |
| 83 | return version; |
| 84 | } else { |
| 85 | NOTREACHED() << "Unable to retrieve version string."; |
| 86 | } |
| 87 | |
| 88 | return std::string(); |
| 89 | } |
| 90 | |
[email protected] | 0b33f80b | 2008-12-17 21:34:36 | [diff] [blame] | 91 | void MetricsLog::RecordIncrementalStabilityElements() { |
| 92 | DCHECK(!locked_); |
| 93 | |
| 94 | PrefService* pref = g_browser_process->local_state(); |
| 95 | DCHECK(pref); |
| 96 | |
[email protected] | 147bbc0b | 2009-01-06 19:37:40 | [diff] [blame] | 97 | OPEN_ELEMENT_FOR_SCOPE("profile"); |
| 98 | WriteCommonEventAttributes(); |
| 99 | |
| 100 | WriteInstallElement(); // Supply appversion. |
| 101 | |
| 102 | { |
| 103 | OPEN_ELEMENT_FOR_SCOPE("stability"); // Minimal set of stability elements. |
| 104 | WriteRequiredStabilityAttributes(pref); |
| 105 | WriteRealtimeStabilityAttributes(pref); |
| 106 | |
| 107 | WritePluginStabilityElements(pref); |
| 108 | } |
[email protected] | 0b33f80b | 2008-12-17 21:34:36 | [diff] [blame] | 109 | } |
| 110 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 111 | void MetricsLog::WriteStabilityElement() { |
| 112 | DCHECK(!locked_); |
| 113 | |
| 114 | PrefService* pref = g_browser_process->local_state(); |
| 115 | DCHECK(pref); |
| 116 | |
| 117 | // Get stability attributes out of Local State, zeroing out stored values. |
| 118 | // NOTE: This could lead to some data loss if this report isn't successfully |
| 119 | // sent, but that's true for all the metrics. |
| 120 | |
[email protected] | ffaf78a | 2008-11-12 17:38:33 | [diff] [blame] | 121 | OPEN_ELEMENT_FOR_SCOPE("stability"); |
[email protected] | 147bbc0b | 2009-01-06 19:37:40 | [diff] [blame] | 122 | WriteRequiredStabilityAttributes(pref); |
| 123 | WriteRealtimeStabilityAttributes(pref); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 124 | |
[email protected] | 0b33f80b | 2008-12-17 21:34:36 | [diff] [blame] | 125 | // TODO(jar): The following are all optional, so we *could* optimize them for |
| 126 | // values of zero (and not include them). |
[email protected] | 8e674e4 | 2008-07-30 16:05:48 | [diff] [blame] | 127 | WriteIntAttribute("incompleteshutdowncount", |
| 128 | pref->GetInteger( |
| 129 | prefs::kStabilityIncompleteSessionEndCount)); |
| 130 | pref->SetInteger(prefs::kStabilityIncompleteSessionEndCount, 0); |
[email protected] | 0b33f80b | 2008-12-17 21:34:36 | [diff] [blame] | 131 | |
| 132 | |
[email protected] | e73c0197 | 2008-08-13 00:18:24 | [diff] [blame] | 133 | WriteIntAttribute("breakpadregistrationok", |
| 134 | pref->GetInteger(prefs::kStabilityBreakpadRegistrationSuccess)); |
| 135 | pref->SetInteger(prefs::kStabilityBreakpadRegistrationSuccess, 0); |
| 136 | WriteIntAttribute("breakpadregistrationfail", |
| 137 | pref->GetInteger(prefs::kStabilityBreakpadRegistrationFail)); |
| 138 | pref->SetInteger(prefs::kStabilityBreakpadRegistrationFail, 0); |
| 139 | WriteIntAttribute("debuggerpresent", |
| 140 | pref->GetInteger(prefs::kStabilityDebuggerPresent)); |
| 141 | pref->SetInteger(prefs::kStabilityDebuggerPresent, 0); |
| 142 | WriteIntAttribute("debuggernotpresent", |
| 143 | pref->GetInteger(prefs::kStabilityDebuggerNotPresent)); |
| 144 | pref->SetInteger(prefs::kStabilityDebuggerNotPresent, 0); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 145 | |
[email protected] | 147bbc0b | 2009-01-06 19:37:40 | [diff] [blame] | 146 | WritePluginStabilityElements(pref); |
| 147 | } |
| 148 | |
| 149 | void MetricsLog::WritePluginStabilityElements(PrefService* pref) { |
| 150 | // Now log plugin stability info. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 151 | const ListValue* plugin_stats_list = pref->GetList( |
| 152 | prefs::kStabilityPluginStats); |
| 153 | if (plugin_stats_list) { |
[email protected] | ffaf78a | 2008-11-12 17:38:33 | [diff] [blame] | 154 | OPEN_ELEMENT_FOR_SCOPE("plugins"); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 155 | for (ListValue::const_iterator iter = plugin_stats_list->begin(); |
| 156 | iter != plugin_stats_list->end(); ++iter) { |
| 157 | if (!(*iter)->IsType(Value::TYPE_DICTIONARY)) { |
| 158 | NOTREACHED(); |
| 159 | continue; |
| 160 | } |
| 161 | DictionaryValue* plugin_dict = static_cast<DictionaryValue*>(*iter); |
| 162 | |
[email protected] | 8e50b60 | 2009-03-03 22:59:43 | [diff] [blame] | 163 | std::wstring plugin_name; |
| 164 | plugin_dict->GetString(prefs::kStabilityPluginName, &plugin_name); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 165 | |
[email protected] | ffaf78a | 2008-11-12 17:38:33 | [diff] [blame] | 166 | OPEN_ELEMENT_FOR_SCOPE("pluginstability"); |
[email protected] | a27a938 | 2009-02-11 23:55:10 | [diff] [blame] | 167 | // Use "filename" instead of "name", otherwise we need to update the |
| 168 | // UMA servers. |
[email protected] | 8e50b60 | 2009-03-03 22:59:43 | [diff] [blame] | 169 | WriteAttribute("filename", CreateBase64Hash(WideToUTF8(plugin_name))); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 170 | |
| 171 | int launches = 0; |
[email protected] | 8e50b60 | 2009-03-03 22:59:43 | [diff] [blame] | 172 | plugin_dict->GetInteger(prefs::kStabilityPluginLaunches, &launches); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 173 | WriteIntAttribute("launchcount", launches); |
| 174 | |
| 175 | int instances = 0; |
[email protected] | 8e50b60 | 2009-03-03 22:59:43 | [diff] [blame] | 176 | plugin_dict->GetInteger(prefs::kStabilityPluginInstances, &instances); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 177 | WriteIntAttribute("instancecount", instances); |
| 178 | |
| 179 | int crashes = 0; |
[email protected] | 8e50b60 | 2009-03-03 22:59:43 | [diff] [blame] | 180 | plugin_dict->GetInteger(prefs::kStabilityPluginCrashes, &crashes); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 181 | WriteIntAttribute("crashcount", crashes); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 182 | } |
| 183 | |
| 184 | pref->ClearPref(prefs::kStabilityPluginStats); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 185 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 186 | } |
| 187 | |
[email protected] | 147bbc0b | 2009-01-06 19:37:40 | [diff] [blame] | 188 | void MetricsLog::WriteRequiredStabilityAttributes(PrefService* pref) { |
[email protected] | 0b33f80b | 2008-12-17 21:34:36 | [diff] [blame] | 189 | // The server refuses data that doesn't have certain values. crashcount and |
| 190 | // launchcount are currently "required" in the "stability" group. |
| 191 | WriteIntAttribute("launchcount", |
| 192 | pref->GetInteger(prefs::kStabilityLaunchCount)); |
| 193 | pref->SetInteger(prefs::kStabilityLaunchCount, 0); |
| 194 | WriteIntAttribute("crashcount", |
| 195 | pref->GetInteger(prefs::kStabilityCrashCount)); |
| 196 | pref->SetInteger(prefs::kStabilityCrashCount, 0); |
| 197 | } |
| 198 | |
[email protected] | 147bbc0b | 2009-01-06 19:37:40 | [diff] [blame] | 199 | void MetricsLog::WriteRealtimeStabilityAttributes(PrefService* pref) { |
[email protected] | 0b33f80b | 2008-12-17 21:34:36 | [diff] [blame] | 200 | // Update the stats which are critical for real-time stability monitoring. |
| 201 | // Since these are "optional," only list ones that are non-zero, as the counts |
| 202 | // are aggergated (summed) server side. |
| 203 | |
| 204 | int count = pref->GetInteger(prefs::kStabilityPageLoadCount); |
| 205 | if (count) { |
| 206 | WriteIntAttribute("pageloadcount", count); |
| 207 | pref->SetInteger(prefs::kStabilityPageLoadCount, 0); |
| 208 | } |
| 209 | |
| 210 | count = pref->GetInteger(prefs::kStabilityRendererCrashCount); |
| 211 | if (count) { |
| 212 | WriteIntAttribute("renderercrashcount", count); |
| 213 | pref->SetInteger(prefs::kStabilityRendererCrashCount, 0); |
| 214 | } |
| 215 | |
[email protected] | 1f08562 | 2009-12-04 05:33:45 | [diff] [blame] | 216 | count = pref->GetInteger(prefs::kStabilityExtensionRendererCrashCount); |
| 217 | if (count) { |
| 218 | WriteIntAttribute("extensionrenderercrashcount", count); |
| 219 | pref->SetInteger(prefs::kStabilityExtensionRendererCrashCount, 0); |
| 220 | } |
| 221 | |
[email protected] | 0b33f80b | 2008-12-17 21:34:36 | [diff] [blame] | 222 | count = pref->GetInteger(prefs::kStabilityRendererHangCount); |
| 223 | if (count) { |
| 224 | WriteIntAttribute("rendererhangcount", count); |
| 225 | pref->SetInteger(prefs::kStabilityRendererHangCount, 0); |
| 226 | } |
[email protected] | 1f08562 | 2009-12-04 05:33:45 | [diff] [blame] | 227 | |
| 228 | count = pref->GetInteger(prefs::kStabilityChildProcessCrashCount); |
| 229 | if (count) { |
| 230 | WriteIntAttribute("childprocesscrashcount", count); |
| 231 | pref->SetInteger(prefs::kStabilityChildProcessCrashCount, 0); |
| 232 | } |
[email protected] | 9165f74 | 2010-03-10 22:55:01 | [diff] [blame] | 233 | |
| 234 | int64 recent_duration = GetIncrementalUptime(pref); |
| 235 | if (recent_duration) |
| 236 | WriteInt64Attribute("uptimesec", recent_duration); |
[email protected] | 0b33f80b | 2008-12-17 21:34:36 | [diff] [blame] | 237 | } |
| 238 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 239 | void MetricsLog::WritePluginList( |
| 240 | const std::vector<WebPluginInfo>& plugin_list) { |
| 241 | DCHECK(!locked_); |
| 242 | |
[email protected] | ffaf78a | 2008-11-12 17:38:33 | [diff] [blame] | 243 | OPEN_ELEMENT_FOR_SCOPE("plugins"); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 244 | |
| 245 | for (std::vector<WebPluginInfo>::const_iterator iter = plugin_list.begin(); |
| 246 | iter != plugin_list.end(); ++iter) { |
[email protected] | ffaf78a | 2008-11-12 17:38:33 | [diff] [blame] | 247 | OPEN_ELEMENT_FOR_SCOPE("plugin"); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 248 | |
| 249 | // Plugin name and filename are hashed for the privacy of those |
| 250 | // testing unreleased new extensions. |
[email protected] | c9d81137 | 2010-06-23 21:44:57 | [diff] [blame] | 251 | WriteAttribute("name", CreateBase64Hash(UTF16ToUTF8(iter->name))); |
[email protected] | 046344c | 2009-01-13 00:54:21 | [diff] [blame] | 252 | WriteAttribute("filename", |
| 253 | CreateBase64Hash(WideToUTF8(iter->path.BaseName().ToWStringHack()))); |
[email protected] | c9d81137 | 2010-06-23 21:44:57 | [diff] [blame] | 254 | WriteAttribute("version", UTF16ToUTF8(iter->version)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 255 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 256 | } |
| 257 | |
[email protected] | 147bbc0b | 2009-01-06 19:37:40 | [diff] [blame] | 258 | void MetricsLog::WriteInstallElement() { |
| 259 | OPEN_ELEMENT_FOR_SCOPE("install"); |
| 260 | WriteAttribute("installdate", GetInstallDate()); |
| 261 | WriteIntAttribute("buildid", 0); // We're using appversion instead. |
[email protected] | 147bbc0b | 2009-01-06 19:37:40 | [diff] [blame] | 262 | } |
| 263 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 264 | void MetricsLog::RecordEnvironment( |
| 265 | const std::vector<WebPluginInfo>& plugin_list, |
| 266 | const DictionaryValue* profile_metrics) { |
| 267 | DCHECK(!locked_); |
| 268 | |
| 269 | PrefService* pref = g_browser_process->local_state(); |
| 270 | |
[email protected] | ffaf78a | 2008-11-12 17:38:33 | [diff] [blame] | 271 | OPEN_ELEMENT_FOR_SCOPE("profile"); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 272 | WriteCommonEventAttributes(); |
| 273 | |
[email protected] | 147bbc0b | 2009-01-06 19:37:40 | [diff] [blame] | 274 | WriteInstallElement(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 275 | |
| 276 | WritePluginList(plugin_list); |
| 277 | |
| 278 | WriteStabilityElement(); |
| 279 | |
| 280 | { |
| 281 | OPEN_ELEMENT_FOR_SCOPE("cpu"); |
[email protected] | 05f9b68 | 2008-09-29 22:18:01 | [diff] [blame] | 282 | WriteAttribute("arch", base::SysInfo::CPUArchitecture()); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 283 | } |
| 284 | |
| 285 | { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 286 | OPEN_ELEMENT_FOR_SCOPE("memory"); |
[email protected] | ed6fc35 | 2008-09-18 12:44:40 | [diff] [blame] | 287 | WriteIntAttribute("mb", base::SysInfo::AmountOfPhysicalMemoryMB()); |
[email protected] | d1be67b | 2008-11-19 20:28:38 | [diff] [blame] | 288 | #if defined(OS_WIN) |
| 289 | WriteIntAttribute("dllbase", reinterpret_cast<int>(&__ImageBase)); |
| 290 | #endif |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 291 | } |
| 292 | |
| 293 | { |
| 294 | OPEN_ELEMENT_FOR_SCOPE("os"); |
| 295 | WriteAttribute("name", |
[email protected] | 05f9b68 | 2008-09-29 22:18:01 | [diff] [blame] | 296 | base::SysInfo::OperatingSystemName()); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 297 | WriteAttribute("version", |
[email protected] | 05f9b68 | 2008-09-29 22:18:01 | [diff] [blame] | 298 | base::SysInfo::OperatingSystemVersion()); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 299 | } |
| 300 | |
| 301 | { |
[email protected] | e8c287c87 | 2010-07-20 00:49:42 | [diff] [blame] | 302 | OPEN_ELEMENT_FOR_SCOPE("gpu"); |
| 303 | WriteIntAttribute("vendorid", |
| 304 | GpuProcessHost::Get()->gpu_info().vendor_id()); |
| 305 | WriteIntAttribute("deviceid", |
| 306 | GpuProcessHost::Get()->gpu_info().device_id()); |
| 307 | } |
| 308 | |
| 309 | { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 310 | OPEN_ELEMENT_FOR_SCOPE("display"); |
| 311 | int width = 0; |
| 312 | int height = 0; |
[email protected] | 05f9b68 | 2008-09-29 22:18:01 | [diff] [blame] | 313 | base::SysInfo::GetPrimaryDisplayDimensions(&width, &height); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 314 | WriteIntAttribute("xsize", width); |
| 315 | WriteIntAttribute("ysize", height); |
[email protected] | 05f9b68 | 2008-09-29 22:18:01 | [diff] [blame] | 316 | WriteIntAttribute("screens", base::SysInfo::DisplayCount()); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 317 | } |
| 318 | |
| 319 | { |
| 320 | OPEN_ELEMENT_FOR_SCOPE("bookmarks"); |
| 321 | int num_bookmarks_on_bookmark_bar = |
| 322 | pref->GetInteger(prefs::kNumBookmarksOnBookmarkBar); |
| 323 | int num_folders_on_bookmark_bar = |
| 324 | pref->GetInteger(prefs::kNumFoldersOnBookmarkBar); |
| 325 | int num_bookmarks_in_other_bookmarks_folder = |
| 326 | pref->GetInteger(prefs::kNumBookmarksInOtherBookmarkFolder); |
| 327 | int num_folders_in_other_bookmarks_folder = |
| 328 | pref->GetInteger(prefs::kNumFoldersInOtherBookmarkFolder); |
| 329 | { |
| 330 | OPEN_ELEMENT_FOR_SCOPE("bookmarklocation"); |
| 331 | WriteAttribute("name", "full-tree"); |
| 332 | WriteIntAttribute("foldercount", |
| 333 | num_folders_on_bookmark_bar + num_folders_in_other_bookmarks_folder); |
| 334 | WriteIntAttribute("itemcount", |
| 335 | num_bookmarks_on_bookmark_bar + |
| 336 | num_bookmarks_in_other_bookmarks_folder); |
| 337 | } |
| 338 | { |
| 339 | OPEN_ELEMENT_FOR_SCOPE("bookmarklocation"); |
| 340 | WriteAttribute("name", "toolbar"); |
| 341 | WriteIntAttribute("foldercount", num_folders_on_bookmark_bar); |
| 342 | WriteIntAttribute("itemcount", num_bookmarks_on_bookmark_bar); |
| 343 | } |
| 344 | } |
| 345 | |
| 346 | { |
| 347 | OPEN_ELEMENT_FOR_SCOPE("keywords"); |
| 348 | WriteIntAttribute("count", pref->GetInteger(prefs::kNumKeywords)); |
| 349 | } |
| 350 | |
| 351 | if (profile_metrics) |
| 352 | WriteAllProfilesMetrics(*profile_metrics); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 353 | } |
| 354 | |
| 355 | void MetricsLog::WriteAllProfilesMetrics( |
| 356 | const DictionaryValue& all_profiles_metrics) { |
[email protected] | e7b418b | 2010-07-30 19:47:47 | [diff] [blame^] | 357 | const std::string profile_prefix(WideToUTF8(prefs::kProfilePrefix)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 358 | for (DictionaryValue::key_iterator i = all_profiles_metrics.begin_keys(); |
| 359 | i != all_profiles_metrics.end_keys(); ++i) { |
[email protected] | e7b418b | 2010-07-30 19:47:47 | [diff] [blame^] | 360 | const std::string& key_name = *i; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 361 | if (key_name.compare(0, profile_prefix.size(), profile_prefix) == 0) { |
| 362 | DictionaryValue* profile; |
[email protected] | 4dad9ad8 | 2009-11-25 20:47:52 | [diff] [blame] | 363 | if (all_profiles_metrics.GetDictionaryWithoutPathExpansion(key_name, |
| 364 | &profile)) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 365 | WriteProfileMetrics(key_name.substr(profile_prefix.size()), *profile); |
| 366 | } |
| 367 | } |
| 368 | } |
| 369 | |
[email protected] | e7b418b | 2010-07-30 19:47:47 | [diff] [blame^] | 370 | void MetricsLog::WriteProfileMetrics(const std::string& profileidhash, |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 371 | const DictionaryValue& profile_metrics) { |
| 372 | OPEN_ELEMENT_FOR_SCOPE("userprofile"); |
[email protected] | e7b418b | 2010-07-30 19:47:47 | [diff] [blame^] | 373 | WriteAttribute("profileidhash", profileidhash); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 374 | for (DictionaryValue::key_iterator i = profile_metrics.begin_keys(); |
| 375 | i != profile_metrics.end_keys(); ++i) { |
| 376 | Value* value; |
[email protected] | 4dad9ad8 | 2009-11-25 20:47:52 | [diff] [blame] | 377 | if (profile_metrics.GetWithoutPathExpansion(*i, &value)) { |
[email protected] | e7b418b | 2010-07-30 19:47:47 | [diff] [blame^] | 378 | DCHECK(*i != "id"); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 379 | switch (value->GetType()) { |
| 380 | case Value::TYPE_STRING: { |
[email protected] | 5e324b7 | 2008-12-18 00:07:59 | [diff] [blame] | 381 | std::string string_value; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 382 | if (value->GetAsString(&string_value)) { |
| 383 | OPEN_ELEMENT_FOR_SCOPE("profileparam"); |
[email protected] | e7b418b | 2010-07-30 19:47:47 | [diff] [blame^] | 384 | WriteAttribute("name", *i); |
[email protected] | 5e324b7 | 2008-12-18 00:07:59 | [diff] [blame] | 385 | WriteAttribute("value", string_value); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 386 | } |
| 387 | break; |
| 388 | } |
| 389 | |
| 390 | case Value::TYPE_BOOLEAN: { |
| 391 | bool bool_value; |
| 392 | if (value->GetAsBoolean(&bool_value)) { |
| 393 | OPEN_ELEMENT_FOR_SCOPE("profileparam"); |
[email protected] | e7b418b | 2010-07-30 19:47:47 | [diff] [blame^] | 394 | WriteAttribute("name", *i); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 395 | WriteIntAttribute("value", bool_value ? 1 : 0); |
| 396 | } |
| 397 | break; |
| 398 | } |
| 399 | |
| 400 | case Value::TYPE_INTEGER: { |
| 401 | int int_value; |
| 402 | if (value->GetAsInteger(&int_value)) { |
| 403 | OPEN_ELEMENT_FOR_SCOPE("profileparam"); |
[email protected] | e7b418b | 2010-07-30 19:47:47 | [diff] [blame^] | 404 | WriteAttribute("name", *i); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 405 | WriteIntAttribute("value", int_value); |
| 406 | } |
| 407 | break; |
| 408 | } |
| 409 | |
| 410 | default: |
| 411 | NOTREACHED(); |
| 412 | break; |
| 413 | } |
| 414 | } |
| 415 | } |
| 416 | } |
| 417 | |
| 418 | void MetricsLog::RecordOmniboxOpenedURL(const AutocompleteLog& log) { |
| 419 | DCHECK(!locked_); |
| 420 | |
[email protected] | ffaf78a | 2008-11-12 17:38:33 | [diff] [blame] | 421 | OPEN_ELEMENT_FOR_SCOPE("uielement"); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 422 | WriteAttribute("action", "autocomplete"); |
| 423 | WriteAttribute("targetidhash", ""); |
| 424 | // TODO(kochi): Properly track windows. |
| 425 | WriteIntAttribute("window", 0); |
| 426 | WriteCommonEventAttributes(); |
| 427 | |
[email protected] | ffaf78a | 2008-11-12 17:38:33 | [diff] [blame] | 428 | { |
| 429 | OPEN_ELEMENT_FOR_SCOPE("autocomplete"); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 430 | |
[email protected] | ffaf78a | 2008-11-12 17:38:33 | [diff] [blame] | 431 | WriteIntAttribute("typedlength", static_cast<int>(log.text.length())); |
| 432 | WriteIntAttribute("selectedindex", static_cast<int>(log.selected_index)); |
| 433 | WriteIntAttribute("completedlength", |
| 434 | static_cast<int>(log.inline_autocompleted_length)); |
[email protected] | 381e299 | 2008-12-16 01:41:00 | [diff] [blame] | 435 | const std::string input_type( |
| 436 | AutocompleteInput::TypeToString(log.input_type)); |
| 437 | if (!input_type.empty()) |
| 438 | WriteAttribute("inputtype", input_type); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 439 | |
[email protected] | ffaf78a | 2008-11-12 17:38:33 | [diff] [blame] | 440 | for (AutocompleteResult::const_iterator i(log.result.begin()); |
| 441 | i != log.result.end(); ++i) { |
| 442 | OPEN_ELEMENT_FOR_SCOPE("autocompleteitem"); |
| 443 | if (i->provider) |
| 444 | WriteAttribute("provider", i->provider->name()); |
[email protected] | 381e299 | 2008-12-16 01:41:00 | [diff] [blame] | 445 | const std::string result_type(AutocompleteMatch::TypeToString(i->type)); |
| 446 | if (!result_type.empty()) |
| 447 | WriteAttribute("resulttype", result_type); |
[email protected] | ffaf78a | 2008-11-12 17:38:33 | [diff] [blame] | 448 | WriteIntAttribute("relevance", i->relevance); |
| 449 | WriteIntAttribute("isstarred", i->starred ? 1 : 0); |
| 450 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 451 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 452 | |
| 453 | ++num_events_; |
| 454 | } |