[email protected] | 2e4cd1a | 2012-01-12 08:51:03 | [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 | |
| 5 | // This file defines a set of user experience metrics data recorded by |
| 6 | // the MetricsService. This is the unit of data that is sent to the server. |
| 7 | |
[email protected] | 11f485728 | 2009-11-13 19:56:17 | [diff] [blame] | 8 | #ifndef CHROME_BROWSER_METRICS_METRICS_LOG_H_ |
| 9 | #define CHROME_BROWSER_METRICS_METRICS_LOG_H_ |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 10 | |
[email protected] | 6ffdb900 | 2011-11-15 00:09:24 | [diff] [blame] | 11 | #include <string> |
| 12 | #include <vector> |
| 13 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 14 | #include "base/basictypes.h" |
[email protected] | 5eae204c | 2013-02-13 15:53:42 | [diff] [blame] | 15 | #include "chrome/browser/metrics/metrics_network_observer.h" |
[email protected] | e182be0 | 2012-01-27 02:35:44 | [diff] [blame] | 16 | #include "chrome/common/metrics/metrics_log_base.h" |
[email protected] | 197c077 | 2012-05-14 23:50:51 | [diff] [blame] | 17 | #include "chrome/installer/util/google_update_settings.h" |
[email protected] | 767c9d9 | 2012-03-02 16:04:34 | [diff] [blame] | 18 | #include "ui/gfx/size.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 19 | |
[email protected] | f65859e | 2013-02-04 20:00:25 | [diff] [blame] | 20 | #if defined(OS_CHROMEOS) |
| 21 | #include "chrome/browser/metrics/perf_provider_chromeos.h" |
| 22 | #endif |
| 23 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 24 | struct AutocompleteLog; |
[email protected] | 5eae204c | 2013-02-13 15:53:42 | [diff] [blame] | 25 | class MetricsNetworkObserver; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 26 | class PrefService; |
[email protected] | b1de2c7 | 2013-02-06 02:45:47 | [diff] [blame] | 27 | class PrefRegistrySimple; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 28 | |
[email protected] | f3a1c64 | 2011-07-12 19:15:03 | [diff] [blame] | 29 | namespace base { |
| 30 | class DictionaryValue; |
| 31 | } |
| 32 | |
[email protected] | 611ae29a | 2013-04-29 21:32:19 | [diff] [blame] | 33 | namespace device { |
| 34 | class BluetoothAdapter; |
| 35 | } |
| 36 | |
[email protected] | ed0fd00 | 2012-04-25 23:10:34 | [diff] [blame] | 37 | namespace tracked_objects { |
| 38 | struct ProcessDataSnapshot; |
| 39 | } |
| 40 | |
[email protected] | 2ac73f6 | 2012-08-13 21:49:07 | [diff] [blame] | 41 | namespace chrome_variations { |
[email protected] | 0c8b7ad | 2012-11-06 07:08:14 | [diff] [blame] | 42 | struct ActiveGroupId; |
[email protected] | ad2461c | 2012-04-27 21:11:03 | [diff] [blame] | 43 | } |
| 44 | |
[email protected] | 191eb3f7 | 2010-12-21 06:27:50 | [diff] [blame] | 45 | namespace webkit { |
[email protected] | 191eb3f7 | 2010-12-21 06:27:50 | [diff] [blame] | 46 | struct WebPluginInfo; |
| 47 | } |
[email protected] | 191eb3f7 | 2010-12-21 06:27:50 | [diff] [blame] | 48 | |
[email protected] | 197c077 | 2012-05-14 23:50:51 | [diff] [blame] | 49 | // This is a small helper struct to pass Google Update metrics in a single |
| 50 | // reference argument to MetricsLog::RecordEnvironment(). |
| 51 | struct GoogleUpdateMetrics { |
| 52 | GoogleUpdateMetrics(); |
| 53 | ~GoogleUpdateMetrics(); |
| 54 | |
| 55 | // Defines whether this is a user-level or system-level install. |
| 56 | bool is_system_install; |
| 57 | // The time at which Google Update last started an automatic update check. |
| 58 | base::Time last_started_au; |
| 59 | // The time at which Google Update last successfully recieved update |
| 60 | // information from Google servers. |
| 61 | base::Time last_checked; |
| 62 | // Details about Google Update's attempts to update itself. |
| 63 | GoogleUpdateSettings::ProductData google_update_data; |
| 64 | // Details about Google Update's attempts to update this product. |
| 65 | GoogleUpdateSettings::ProductData product_data; |
| 66 | }; |
| 67 | |
[email protected] | 1226abb | 2010-06-10 18:01:28 | [diff] [blame] | 68 | class MetricsLog : public MetricsLogBase { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 69 | public: |
| 70 | // Creates a new metrics log |
| 71 | // client_id is the identifier for this profile on this installation |
| 72 | // session_id is an integer that's incremented on each application launch |
| 73 | MetricsLog(const std::string& client_id, int session_id); |
| 74 | virtual ~MetricsLog(); |
| 75 | |
[email protected] | b1de2c7 | 2013-02-06 02:45:47 | [diff] [blame] | 76 | static void RegisterPrefs(PrefRegistrySimple* registry); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 77 | |
[email protected] | 1df44b7 | 2012-01-19 05:20:34 | [diff] [blame] | 78 | // Get the amount of uptime in seconds since this function was last called. |
| 79 | // This updates the cumulative uptime metric for uninstall as a side effect. |
| 80 | static int64 GetIncrementalUptime(PrefService* pref); |
| 81 | |
| 82 | // Get the current version of the application as a string. |
| 83 | static std::string GetVersionString(); |
| 84 | |
| 85 | // Use |extension| in all uploaded appversions in addition to the standard |
| 86 | // version string. |
| 87 | static void set_version_extension(const std::string& extension); |
| 88 | static const std::string& version_extension(); |
| 89 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 90 | // Records the current operating environment. Takes the list of installed |
[email protected] | 197c077 | 2012-05-14 23:50:51 | [diff] [blame] | 91 | // plugins and Google Update statistics as parameters because those can't be |
| 92 | // obtained synchronously from the UI thread. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 93 | // profile_metrics, if non-null, gives a dictionary of all profile metrics |
| 94 | // that are to be recorded. Each value in profile_metrics should be a |
| 95 | // dictionary giving the metrics for the profile. |
[email protected] | 191eb3f7 | 2010-12-21 06:27:50 | [diff] [blame] | 96 | void RecordEnvironment( |
[email protected] | 91d9f3d | 2011-08-14 05:24:44 | [diff] [blame] | 97 | const std::vector<webkit::WebPluginInfo>& plugin_list, |
[email protected] | 197c077 | 2012-05-14 23:50:51 | [diff] [blame] | 98 | const GoogleUpdateMetrics& google_update_metrics, |
[email protected] | f3a1c64 | 2011-07-12 19:15:03 | [diff] [blame] | 99 | const base::DictionaryValue* profile_metrics); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 100 | |
[email protected] | bc66d53 | 2012-03-23 01:57:05 | [diff] [blame] | 101 | // Records the current operating environment. Takes the list of installed |
[email protected] | 197c077 | 2012-05-14 23:50:51 | [diff] [blame] | 102 | // plugins and Google Update statistics as parameters because those can't be |
| 103 | // obtained synchronously from the UI thread. This is exposed as a separate |
| 104 | // method from the |RecordEnvironment()| method above because we record the |
| 105 | // environment with *each* protobuf upload, but only with the initial XML |
| 106 | // upload. |
[email protected] | bc66d53 | 2012-03-23 01:57:05 | [diff] [blame] | 107 | void RecordEnvironmentProto( |
[email protected] | 197c077 | 2012-05-14 23:50:51 | [diff] [blame] | 108 | const std::vector<webkit::WebPluginInfo>& plugin_list, |
| 109 | const GoogleUpdateMetrics& google_update_metrics); |
[email protected] | bc66d53 | 2012-03-23 01:57:05 | [diff] [blame] | 110 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 111 | // Records the input text, available choices, and selected entry when the |
| 112 | // user uses the Omnibox to open a URL. |
| 113 | void RecordOmniboxOpenedURL(const AutocompleteLog& log); |
| 114 | |
[email protected] | ed0fd00 | 2012-04-25 23:10:34 | [diff] [blame] | 115 | // Records the passed profiled data, which should be a snapshot of the |
| 116 | // browser's profiled performance during startup for a single process. |
| 117 | void RecordProfilerData( |
| 118 | const tracked_objects::ProcessDataSnapshot& process_data, |
[email protected] | f3b35769 | 2013-03-22 05:16:13 | [diff] [blame] | 119 | int process_type); |
[email protected] | ed0fd00 | 2012-04-25 23:10:34 | [diff] [blame] | 120 | |
[email protected] | 0b33f80b | 2008-12-17 21:34:36 | [diff] [blame] | 121 | // Record recent delta for critical stability metrics. We can't wait for a |
| 122 | // restart to gather these, as that delay biases our observation away from |
| 123 | // users that run happily for a looooong time. We send increments with each |
[email protected] | fe58acc2 | 2012-02-29 01:29:58 | [diff] [blame] | 124 | // uma log upload, just as we send histogram data. Takes the list of |
| 125 | // installed plugins as a parameter because that can't be obtained |
| 126 | // synchronously from the UI thread. |
| 127 | void RecordIncrementalStabilityElements( |
| 128 | const std::vector<webkit::WebPluginInfo>& plugin_list); |
[email protected] | 0b33f80b | 2008-12-17 21:34:36 | [diff] [blame] | 129 | |
[email protected] | 767c9d9 | 2012-03-02 16:04:34 | [diff] [blame] | 130 | protected: |
| 131 | // Exposed for the sake of mocking in test code. |
| 132 | |
| 133 | // Returns the PrefService from which to log metrics data. |
| 134 | virtual PrefService* GetPrefService(); |
| 135 | |
| 136 | // Returns the screen size for the primary monitor. |
| 137 | virtual gfx::Size GetScreenSize() const; |
| 138 | |
[email protected] | aa9641797 | 2012-08-22 03:16:44 | [diff] [blame] | 139 | // Returns the device scale factor for the primary monitor. |
| 140 | virtual float GetScreenDeviceScaleFactor() const; |
| 141 | |
[email protected] | 767c9d9 | 2012-03-02 16:04:34 | [diff] [blame] | 142 | // Returns the number of monitors the user is using. |
| 143 | virtual int GetScreenCount() const; |
| 144 | |
| 145 | // Fills |field_trial_ids| with the list of initialized field trials name and |
| 146 | // group ids. |
| 147 | virtual void GetFieldTrialIds( |
[email protected] | 0c8b7ad | 2012-11-06 07:08:14 | [diff] [blame] | 148 | std::vector<chrome_variations::ActiveGroupId>* field_trial_ids) const; |
[email protected] | 767c9d9 | 2012-03-02 16:04:34 | [diff] [blame] | 149 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 150 | private: |
[email protected] | c1834a9 | 2011-01-21 18:21:03 | [diff] [blame] | 151 | FRIEND_TEST_ALL_PREFIXES(MetricsLogTest, ChromeOSStabilityData); |
| 152 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 153 | // Writes application stability metrics (as part of the profile log). |
| 154 | // NOTE: Has the side-effect of clearing those counts. |
[email protected] | fe58acc2 | 2012-02-29 01:29:58 | [diff] [blame] | 155 | void WriteStabilityElement( |
| 156 | const std::vector<webkit::WebPluginInfo>& plugin_list, |
| 157 | PrefService* pref); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 158 | |
[email protected] | 147bbc0b | 2009-01-06 19:37:40 | [diff] [blame] | 159 | // Within stability group, write plugin crash stats. |
[email protected] | fe58acc2 | 2012-02-29 01:29:58 | [diff] [blame] | 160 | void WritePluginStabilityElements( |
| 161 | const std::vector<webkit::WebPluginInfo>& plugin_list, |
| 162 | PrefService* pref); |
[email protected] | 147bbc0b | 2009-01-06 19:37:40 | [diff] [blame] | 163 | |
| 164 | // Within the stability group, write required attributes. |
| 165 | void WriteRequiredStabilityAttributes(PrefService* pref); |
| 166 | |
| 167 | // Within the stability group, write attributes that need to be updated asap |
[email protected] | 0b33f80b | 2008-12-17 21:34:36 | [diff] [blame] | 168 | // and can't be delayed until the user decides to restart chromium. |
| 169 | // Delaying these stats would bias metrics away from happy long lived |
| 170 | // chromium processes (ones that don't crash, and keep on running). |
[email protected] | 147bbc0b | 2009-01-06 19:37:40 | [diff] [blame] | 171 | void WriteRealtimeStabilityAttributes(PrefService* pref); |
[email protected] | 0b33f80b | 2008-12-17 21:34:36 | [diff] [blame] | 172 | |
[email protected] | bc66d53 | 2012-03-23 01:57:05 | [diff] [blame] | 173 | // Writes the list of installed plugins. If |write_as_xml| is true, writes |
| 174 | // the XML version. Otherwise, writes the protobuf version. |
[email protected] | 191eb3f7 | 2010-12-21 06:27:50 | [diff] [blame] | 175 | void WritePluginList( |
[email protected] | bc66d53 | 2012-03-23 01:57:05 | [diff] [blame] | 176 | const std::vector<webkit::WebPluginInfo>& plugin_list, |
| 177 | bool write_as_xml); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 178 | |
[email protected] | 147bbc0b | 2009-01-06 19:37:40 | [diff] [blame] | 179 | // Within the profile group, write basic install info including appversion. |
| 180 | void WriteInstallElement(); |
| 181 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 182 | // Writes all profile metrics. This invokes WriteProfileMetrics for each key |
| 183 | // in all_profiles_metrics that starts with kProfilePrefix. |
[email protected] | f3a1c64 | 2011-07-12 19:15:03 | [diff] [blame] | 184 | void WriteAllProfilesMetrics( |
| 185 | const base::DictionaryValue& all_profiles_metrics); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 186 | |
| 187 | // Writes metrics for the profile identified by key. This writes all |
| 188 | // key/value pairs in profile_metrics. |
[email protected] | e7b418b | 2010-07-30 19:47:47 | [diff] [blame] | 189 | void WriteProfileMetrics(const std::string& key, |
[email protected] | f3a1c64 | 2011-07-12 19:15:03 | [diff] [blame] | 190 | const base::DictionaryValue& profile_metrics); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 191 | |
[email protected] | 197c077 | 2012-05-14 23:50:51 | [diff] [blame] | 192 | // Writes info about the Google Update install that is managing this client. |
| 193 | // This is a no-op if called on a non-Windows platform. |
| 194 | void WriteGoogleUpdateProto(const GoogleUpdateMetrics& google_update_metrics); |
| 195 | |
[email protected] | 611ae29a | 2013-04-29 21:32:19 | [diff] [blame] | 196 | // Sets the Bluetooth Adapter instance used for the WriteBluetoothProto() |
| 197 | // call. |
| 198 | void SetBluetoothAdapter(scoped_refptr<device::BluetoothAdapter> adapter); |
| 199 | |
| 200 | // Writes info about paired Bluetooth devices on this system. |
| 201 | // This is a no-op if called on a non-Chrome OS platform. |
| 202 | void WriteBluetoothProto(metrics::SystemProfileProto::Hardware* hardware); |
| 203 | |
[email protected] | 5eae204c | 2013-02-13 15:53:42 | [diff] [blame] | 204 | // Observes network state to provide values for SystemProfile::Network. |
| 205 | MetricsNetworkObserver network_observer_; |
| 206 | |
[email protected] | f65859e | 2013-02-04 20:00:25 | [diff] [blame] | 207 | #if defined(OS_CHROMEOS) |
| 208 | metrics::PerfProvider perf_provider_; |
| 209 | #endif |
[email protected] | 74b299e | 2013-01-29 01:24:42 | [diff] [blame] | 210 | |
[email protected] | 611ae29a | 2013-04-29 21:32:19 | [diff] [blame] | 211 | // Bluetooth Adapter instance for collecting information about paired devices. |
| 212 | scoped_refptr<device::BluetoothAdapter> adapter_; |
| 213 | |
[email protected] | 4d818fee | 2010-06-06 13:32:27 | [diff] [blame] | 214 | DISALLOW_COPY_AND_ASSIGN(MetricsLog); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 215 | }; |
| 216 | |
[email protected] | 11f485728 | 2009-11-13 19:56:17 | [diff] [blame] | 217 | #endif // CHROME_BROWSER_METRICS_METRICS_LOG_H_ |