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