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