Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / metrics / metrics_log.h
blobbd67ff85defd312a5ec2733cfb859633502a0335
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_
11 #include <string>
12 #include <vector>
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/common/metrics/variations/variations_util.h"
18 #include "chrome/installer/util/google_update_settings.h"
19 #include "ui/gfx/size.h"
21 #if defined(OS_CHROMEOS)
22 #include "chrome/browser/metrics/perf_provider_chromeos.h"
23 #endif
25 class MetricsNetworkObserver;
26 struct OmniboxLog;
27 class PrefService;
28 class PrefRegistrySimple;
30 namespace base {
31 class DictionaryValue;
34 namespace content {
35 struct WebPluginInfo;
38 namespace device {
39 class BluetoothAdapter;
42 namespace tracked_objects {
43 struct ProcessDataSnapshot;
46 namespace chrome_variations {
47 struct ActiveGroupId;
50 // This is a small helper struct to pass Google Update metrics in a single
51 // reference argument to MetricsLog::RecordEnvironment().
52 struct GoogleUpdateMetrics {
53 GoogleUpdateMetrics();
54 ~GoogleUpdateMetrics();
56 // Defines whether this is a user-level or system-level install.
57 bool is_system_install;
58 // The time at which Google Update last started an automatic update check.
59 base::Time last_started_au;
60 // The time at which Google Update last successfully recieved update
61 // information from Google servers.
62 base::Time last_checked;
63 // Details about Google Update's attempts to update itself.
64 GoogleUpdateSettings::ProductData google_update_data;
65 // Details about Google Update's attempts to update this product.
66 GoogleUpdateSettings::ProductData product_data;
69 class MetricsLog : public MetricsLogBase {
70 public:
71 // Creates a new metrics log
72 // client_id is the identifier for this profile on this installation
73 // session_id is an integer that's incremented on each application launch
74 MetricsLog(const std::string& client_id, int session_id);
75 virtual ~MetricsLog();
77 static void RegisterPrefs(PrefRegistrySimple* registry);
79 // Get the current version of the application as a string.
80 static std::string GetVersionString();
82 // Use |extension| in all uploaded appversions in addition to the standard
83 // version string.
84 static void set_version_extension(const std::string& extension);
85 static const std::string& version_extension();
87 // Records the current operating environment. Takes the list of installed
88 // plugins, Google Update statistics, and synthetic trial IDs as parameters
89 // because those can't be obtained synchronously from the UI thread.
90 // A synthetic trial is one that is set up dynamically by code in Chrome. For
91 // example, a pref may be mapped to a synthetic trial such that the group
92 // is determined by the pref value.
93 void RecordEnvironment(
94 const std::vector<content::WebPluginInfo>& plugin_list,
95 const GoogleUpdateMetrics& google_update_metrics,
96 const std::vector<chrome_variations::ActiveGroupId>& synthetic_trials);
98 // Loads the environment proto that was saved by the last RecordEnvironment()
99 // call from prefs and clears the pref value. Returns true on success or false
100 // if there was no saved environment in prefs or it could not be decoded.
101 bool LoadSavedEnvironmentFromPrefs();
103 // Records the input text, available choices, and selected entry when the
104 // user uses the Omnibox to open a URL.
105 void RecordOmniboxOpenedURL(const OmniboxLog& log);
107 // Records the passed profiled data, which should be a snapshot of the
108 // browser's profiled performance during startup for a single process.
109 void RecordProfilerData(
110 const tracked_objects::ProcessDataSnapshot& process_data,
111 int process_type);
113 // Writes application stability metrics (as part of the profile log). The
114 // system profile portion of the log must have already been filled in by a
115 // call to RecordEnvironment() or LoadSavedEnvironmentFromPrefs().
116 // NOTE: Has the side-effect of clearing the stability prefs..
118 // If |log_type| is INITIAL_LOG, records additional info such as number of
119 // incomplete shutdowns as well as extra breakpad and debugger stats.
120 void RecordStabilityMetrics(
121 base::TimeDelta incremental_uptime,
122 LogType log_type);
124 const base::TimeTicks& creation_time() const {
125 return creation_time_;
128 protected:
129 // Exposed for the sake of mocking in test code.
131 // Returns the PrefService from which to log metrics data.
132 virtual PrefService* GetPrefService();
134 // Returns the screen size for the primary monitor.
135 virtual gfx::Size GetScreenSize() const;
137 // Returns the device scale factor for the primary monitor.
138 virtual float GetScreenDeviceScaleFactor() const;
140 // Returns the number of monitors the user is using.
141 virtual int GetScreenCount() const;
143 // Fills |field_trial_ids| with the list of initialized field trials name and
144 // group ids.
145 virtual void GetFieldTrialIds(
146 std::vector<chrome_variations::ActiveGroupId>* field_trial_ids) const;
148 private:
149 FRIEND_TEST_ALL_PREFIXES(MetricsLogTest, ChromeOSStabilityData);
151 // Returns true if the environment has already been filled in by a call to
152 // RecordEnvironment() or LoadSavedEnvironmentFromPrefs().
153 bool HasEnvironment() const;
155 // Returns true if the stability metrics have already been filled in by a
156 // call to RecordStabilityMetrics().
157 bool HasStabilityMetrics() const;
159 // Within stability group, write plugin crash stats.
160 void WritePluginStabilityElements(PrefService* pref);
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()
180 // call.
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 virtual void WriteBluetoothProto(
186 metrics::SystemProfileProto::Hardware* hardware);
188 #if defined(OS_CHROMEOS)
189 // Update the number of users logged into a multi-profile session.
190 // If the number of users change while the log is open, the call invalidates
191 // the user count value.
192 void UpdateMultiProfileUserCount();
193 #endif
195 // Observes network state to provide values for SystemProfile::Network.
196 MetricsNetworkObserver network_observer_;
198 #if defined(OS_CHROMEOS)
199 metrics::PerfProvider perf_provider_;
200 #endif
202 // Bluetooth Adapter instance for collecting information about paired devices.
203 scoped_refptr<device::BluetoothAdapter> adapter_;
205 // The time when the current log was created.
206 const base::TimeTicks creation_time_;
208 DISALLOW_COPY_AND_ASSIGN(MetricsLog);
211 #endif // CHROME_BROWSER_METRICS_METRICS_LOG_H_