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.
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.
8 #ifndef CHROME_BROWSER_METRICS_METRICS_LOG_H_
9 #define CHROME_BROWSER_METRICS_METRICS_LOG_H_
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"
20 #if defined(OS_CHROMEOS)
21 #include "chrome/browser/metrics/perf_provider_chromeos.h"
24 class MetricsNetworkObserver;
27 class PrefRegistrySimple;
30 class DictionaryValue;
38 class BluetoothAdapter;
41 namespace tracked_objects {
42 struct ProcessDataSnapshot;
45 namespace chrome_variations {
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();
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;
68 class MetricsLog : public MetricsLogBase {
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();
76 static void RegisterPrefs(PrefRegistrySimple* registry);
78 // Get the current version of the application as a string.
79 static std::string GetVersionString();
81 // Use |extension| in all uploaded appversions in addition to the standard
83 static void set_version_extension(const std::string& extension);
84 static const std::string& version_extension();
86 // Records the current operating environment. Takes the list of installed
87 // plugins and Google Update statistics as parameters because those can't be
88 // obtained synchronously from the UI thread.
89 // profile_metrics, if non-null, gives a dictionary of all profile metrics
90 // that are to be recorded. Each value in profile_metrics should be a
91 // dictionary giving the metrics for the profile.
92 void RecordEnvironment(
93 const std::vector<content::WebPluginInfo>& plugin_list,
94 const GoogleUpdateMetrics& google_update_metrics,
95 base::TimeDelta incremental_uptime);
97 // Records the current operating environment. Takes the list of installed
98 // plugins and Google Update statistics as parameters because those can't be
99 // obtained synchronously from the UI thread. This is exposed as a separate
100 // method from the |RecordEnvironment()| method above because we record the
101 // environment with *each* protobuf upload, but only with the initial XML
103 void RecordEnvironmentProto(
104 const std::vector<content::WebPluginInfo>& plugin_list,
105 const GoogleUpdateMetrics& google_update_metrics);
107 // Records the input text, available choices, and selected entry when the
108 // user uses the Omnibox to open a URL.
109 void RecordOmniboxOpenedURL(const OmniboxLog& log);
111 // Records the passed profiled data, which should be a snapshot of the
112 // browser's profiled performance during startup for a single process.
113 void RecordProfilerData(
114 const tracked_objects::ProcessDataSnapshot& process_data,
117 // Record recent delta for critical stability metrics. We can't wait for a
118 // restart to gather these, as that delay biases our observation away from
119 // users that run happily for a looooong time. We send increments with each
120 // uma log upload, just as we send histogram data. Takes the list of
121 // installed plugins as a parameter because that can't be obtained
122 // synchronously from the UI thread.
123 void RecordIncrementalStabilityElements(
124 const std::vector<content::WebPluginInfo>& plugin_list,
125 base::TimeDelta incremental_uptime);
128 // Exposed for the sake of mocking in test code.
130 // Returns the PrefService from which to log metrics data.
131 virtual PrefService* GetPrefService();
133 // Returns the screen size for the primary monitor.
134 virtual gfx::Size GetScreenSize() const;
136 // Returns the device scale factor for the primary monitor.
137 virtual float GetScreenDeviceScaleFactor() const;
139 // Returns the number of monitors the user is using.
140 virtual int GetScreenCount() const;
142 // Fills |field_trial_ids| with the list of initialized field trials name and
144 virtual void GetFieldTrialIds(
145 std::vector<chrome_variations::ActiveGroupId>* field_trial_ids) const;
148 FRIEND_TEST_ALL_PREFIXES(MetricsLogTest, ChromeOSStabilityData);
150 // Writes application stability metrics (as part of the profile log).
151 // NOTE: Has the side-effect of clearing those counts.
152 void WriteStabilityElement(
153 const std::vector<content::WebPluginInfo>& plugin_list,
154 base::TimeDelta incremental_uptime,
157 // Within stability group, write plugin crash stats.
158 void WritePluginStabilityElements(
159 const std::vector<content::WebPluginInfo>& plugin_list,
162 // Within the stability group, write required attributes.
163 void WriteRequiredStabilityAttributes(PrefService* pref);
165 // Within the stability group, write attributes that need to be updated asap
166 // and can't be delayed until the user decides to restart chromium.
167 // Delaying these stats would bias metrics away from happy long lived
168 // chromium processes (ones that don't crash, and keep on running).
169 void WriteRealtimeStabilityAttributes(PrefService* pref,
170 base::TimeDelta incremental_uptime);
172 // Writes the list of installed plugins.
173 void WritePluginList(const std::vector<content::WebPluginInfo>& plugin_list);
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);
179 // Sets the Bluetooth Adapter instance used for the WriteBluetoothProto()
181 void SetBluetoothAdapter(scoped_refptr<device::BluetoothAdapter> adapter);
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);
187 #if defined(OS_CHROMEOS)
188 // Update the number of users logged into a multi-profile session.
189 // If the number of users change while the log is open, the call invalidates
190 // the user count value.
191 void UpdateMultiProfileUserCount();
194 // Observes network state to provide values for SystemProfile::Network.
195 MetricsNetworkObserver network_observer_;
197 #if defined(OS_CHROMEOS)
198 metrics::PerfProvider perf_provider_;
201 // Bluetooth Adapter instance for collecting information about paired devices.
202 scoped_refptr<device::BluetoothAdapter> adapter_;
204 DISALLOW_COPY_AND_ASSIGN(MetricsLog);
207 #endif // CHROME_BROWSER_METRICS_METRICS_LOG_H_