1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 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 8 #ifndef CHROME_BROWSER_METRICS_METRICS_LOG_H_ 9 #define CHROME_BROWSER_METRICS_METRICS_LOG_H_ 10 11 #include <string> 12 #include <vector> 13 14 #include "base/basictypes.h" 15 #include "chrome/browser/metrics/metrics_network_observer.h" 16 #include "chrome/common/metrics/metrics_log_base.h" 17 #include "chrome/installer/util/google_update_settings.h" 18 #include "ui/gfx/size.h" 19 20 #if defined(OS_CHROMEOS) 21 #include "chrome/browser/metrics/perf_provider_chromeos.h" 22 #endif 23 24 class MetricsNetworkObserver; 25 struct OmniboxLog; 26 class PrefService; 27 class PrefRegistrySimple; 28 29 namespace base { 30 class DictionaryValue; 31 } 32 33 namespace content { 34 struct WebPluginInfo; 35 } 36 37 namespace device { 38 class BluetoothAdapter; 39 } 40 41 namespace tracked_objects { 42 struct ProcessDataSnapshot; 43 } 44 45 namespace chrome_variations { 46 struct ActiveGroupId; 47 } 48 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 68 class MetricsLog : public MetricsLogBase { 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 76 static void RegisterPrefs(PrefRegistrySimple* registry); 77 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 90 // Records the current operating environment. Takes the list of installed 91 // plugins and Google Update statistics as parameters because those can't be 92 // obtained synchronously from the UI thread. 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. 96 void RecordEnvironment( 97 const std::vector<content::WebPluginInfo>& plugin_list, 98 const GoogleUpdateMetrics& google_update_metrics); 99 100 // Records the current operating environment. Takes the list of installed 101 // plugins and Google Update statistics as parameters because those can't be 102 // obtained synchronously from the UI thread. This is exposed as a separate 103 // method from the |RecordEnvironment()| method above because we record the 104 // environment with *each* protobuf upload, but only with the initial XML 105 // upload. 106 void RecordEnvironmentProto( 107 const std::vector<content::WebPluginInfo>& plugin_list, 108 const GoogleUpdateMetrics& google_update_metrics); 109 110 // Records the input text, available choices, and selected entry when the 111 // user uses the Omnibox to open a URL. 112 void RecordOmniboxOpenedURL(const OmniboxLog& log); 113 114 // Records the passed profiled data, which should be a snapshot of the 115 // browser's profiled performance during startup for a single process. 116 void RecordProfilerData( 117 const tracked_objects::ProcessDataSnapshot& process_data, 118 int process_type); 119 120 // Record recent delta for critical stability metrics. We can't wait for a 121 // restart to gather these, as that delay biases our observation away from 122 // users that run happily for a looooong time. We send increments with each 123 // uma log upload, just as we send histogram data. Takes the list of 124 // installed plugins as a parameter because that can't be obtained 125 // synchronously from the UI thread. 126 void RecordIncrementalStabilityElements( 127 const std::vector<content::WebPluginInfo>& plugin_list); 128 129 protected: 130 // Exposed for the sake of mocking in test code. 131 132 // Returns the PrefService from which to log metrics data. 133 virtual PrefService* GetPrefService(); 134 135 // Returns the screen size for the primary monitor. 136 virtual gfx::Size GetScreenSize() const; 137 138 // Returns the device scale factor for the primary monitor. 139 virtual float GetScreenDeviceScaleFactor() const; 140 141 // Returns the number of monitors the user is using. 142 virtual int GetScreenCount() const; 143 144 // Fills |field_trial_ids| with the list of initialized field trials name and 145 // group ids. 146 virtual void GetFieldTrialIds( 147 std::vector<chrome_variations::ActiveGroupId>* field_trial_ids) const; 148 149 private: 150 FRIEND_TEST_ALL_PREFIXES(MetricsLogTest, ChromeOSStabilityData); 151 152 // Writes application stability metrics (as part of the profile log). 153 // NOTE: Has the side-effect of clearing those counts. 154 void WriteStabilityElement( 155 const std::vector<content::WebPluginInfo>& plugin_list, 156 PrefService* pref); 157 158 // Within stability group, write plugin crash stats. 159 void WritePluginStabilityElements( 160 const std::vector<content::WebPluginInfo>& plugin_list, 161 PrefService* pref); 162 163 // Within the stability group, write required attributes. 164 void WriteRequiredStabilityAttributes(PrefService* pref); 165 166 // Within the stability group, write attributes that need to be updated asap 167 // and can't be delayed until the user decides to restart chromium. 168 // Delaying these stats would bias metrics away from happy long lived 169 // chromium processes (ones that don't crash, and keep on running). 170 void WriteRealtimeStabilityAttributes(PrefService* pref); 171 172 // Writes the list of installed plugins. 173 void WritePluginList(const std::vector<content::WebPluginInfo>& plugin_list); 174 175 // Writes info about the Google Update install that is managing this client. 176 // This is a no-op if called on a non-Windows platform. 177 void WriteGoogleUpdateProto(const GoogleUpdateMetrics& google_update_metrics); 178 179 // Sets the Bluetooth Adapter instance used for the WriteBluetoothProto() 180 // call. 181 void SetBluetoothAdapter(scoped_refptr<device::BluetoothAdapter> adapter); 182 183 // Writes info about paired Bluetooth devices on this system. 184 // This is a no-op if called on a non-Chrome OS platform. 185 void WriteBluetoothProto(metrics::SystemProfileProto::Hardware* hardware); 186 187 // Observes network state to provide values for SystemProfile::Network. 188 MetricsNetworkObserver network_observer_; 189 190 #if defined(OS_CHROMEOS) 191 metrics::PerfProvider perf_provider_; 192 #endif 193 194 // Bluetooth Adapter instance for collecting information about paired devices. 195 scoped_refptr<device::BluetoothAdapter> adapter_; 196 197 DISALLOW_COPY_AND_ASSIGN(MetricsLog); 198 }; 199 200 #endif // CHROME_BROWSER_METRICS_METRICS_LOG_H_ 201