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