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