Enable Enterprise enrollment on desktop builds.
[chromium-blink-merge.git] / chrome / browser / metrics / metrics_log.h
blob0c063c56d8fb35f35349b777203c46440673957f
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/extension_metrics.h"
16 #include "chrome/browser/metrics/metrics_network_observer.h"
17 #include "chrome/common/metrics/variations/variations_util.h"
18 #include "chrome/installer/util/google_update_settings.h"
19 #include "components/metrics/metrics_log_base.h"
20 #include "ui/gfx/size.h"
22 class HashedExtensionMetrics;
23 class MetricsNetworkObserver;
24 struct OmniboxLog;
25 class PrefService;
26 class PrefRegistrySimple;
28 #if defined(OS_CHROMEOS)
29 class MetricsLogChromeOS;
30 #endif
32 namespace base {
33 class DictionaryValue;
36 namespace content {
37 struct WebPluginInfo;
40 namespace tracked_objects {
41 struct ProcessDataSnapshot;
44 namespace chrome_variations {
45 struct ActiveGroupId;
48 // This is a small helper struct to pass Google Update metrics in a single
49 // reference argument to MetricsLog::RecordEnvironment().
50 struct GoogleUpdateMetrics {
51 GoogleUpdateMetrics();
52 ~GoogleUpdateMetrics();
54 // Defines whether this is a user-level or system-level install.
55 bool is_system_install;
56 // The time at which Google Update last started an automatic update check.
57 base::Time last_started_au;
58 // The time at which Google Update last successfully recieved update
59 // information from Google servers.
60 base::Time last_checked;
61 // Details about Google Update's attempts to update itself.
62 GoogleUpdateSettings::ProductData google_update_data;
63 // Details about Google Update's attempts to update this product.
64 GoogleUpdateSettings::ProductData product_data;
67 class MetricsLog : public metrics::MetricsLogBase {
68 public:
69 // Creates a new metrics log of the specified type.
70 // client_id is the identifier for this profile on this installation
71 // session_id is an integer that's incremented on each application launch
72 MetricsLog(const std::string& client_id, int session_id, LogType log_type);
73 virtual ~MetricsLog();
75 static void RegisterPrefs(PrefRegistrySimple* registry);
77 // Get the current version of the application as a string.
78 static std::string GetVersionString();
80 // Use |extension| in all uploaded appversions in addition to the standard
81 // version string.
82 static void set_version_extension(const std::string& extension);
83 static const std::string& version_extension();
85 // Records the current operating environment. Takes the list of installed
86 // plugins, Google Update statistics, and synthetic trial IDs as parameters
87 // because those can't be obtained synchronously from the UI thread.
88 // A synthetic trial is one that is set up dynamically by code in Chrome. For
89 // example, a pref may be mapped to a synthetic trial such that the group
90 // is determined by the pref value.
91 void RecordEnvironment(
92 const std::vector<content::WebPluginInfo>& plugin_list,
93 const GoogleUpdateMetrics& google_update_metrics,
94 const std::vector<chrome_variations::ActiveGroupId>& synthetic_trials);
96 // Loads the environment proto that was saved by the last RecordEnvironment()
97 // call from prefs and clears the pref value. Returns true on success or false
98 // if there was no saved environment in prefs or it could not be decoded.
99 bool LoadSavedEnvironmentFromPrefs();
101 // Records the input text, available choices, and selected entry when the
102 // user uses the Omnibox to open a URL.
103 void RecordOmniboxOpenedURL(const OmniboxLog& log);
105 // Records the passed profiled data, which should be a snapshot of the
106 // browser's profiled performance during startup for a single process.
107 void RecordProfilerData(
108 const tracked_objects::ProcessDataSnapshot& process_data,
109 int process_type);
111 // Writes application stability metrics (as part of the profile log). The
112 // system profile portion of the log must have already been filled in by a
113 // call to RecordEnvironment() or LoadSavedEnvironmentFromPrefs().
114 // NOTE: Has the side-effect of clearing the stability prefs..
116 // If this log is of type INITIAL_STABILITY_LOG, records additional info such
117 // as number of incomplete shutdowns as well as extra breakpad and debugger
118 // stats.
119 void RecordStabilityMetrics(base::TimeDelta incremental_uptime,
120 base::TimeDelta uptime);
122 const base::TimeTicks& creation_time() const {
123 return creation_time_;
126 protected:
127 // Exposed for the sake of mocking in test code.
129 // Returns the PrefService from which to log metrics data.
130 virtual PrefService* GetPrefService();
132 // Returns the screen size for the primary monitor.
133 virtual gfx::Size GetScreenSize() const;
135 // Returns the device scale factor for the primary monitor.
136 virtual float GetScreenDeviceScaleFactor() const;
138 // Returns the number of monitors the user is using.
139 virtual int GetScreenCount() const;
141 // Fills |field_trial_ids| with the list of initialized field trials name and
142 // group ids.
143 virtual void GetFieldTrialIds(
144 std::vector<chrome_variations::ActiveGroupId>* field_trial_ids) const;
146 // Exposed to allow dependency injection for tests.
147 #if defined(OS_CHROMEOS)
148 scoped_ptr<MetricsLogChromeOS> metrics_log_chromeos_;
149 #endif
151 private:
152 FRIEND_TEST_ALL_PREFIXES(MetricsLogTest, ChromeOSStabilityData);
154 // Returns true if the environment has already been filled in by a call to
155 // RecordEnvironment() or LoadSavedEnvironmentFromPrefs().
156 bool HasEnvironment() const;
158 // Returns true if the stability metrics have already been filled in by a
159 // call to RecordStabilityMetrics().
160 bool HasStabilityMetrics() const;
162 // Within stability group, write plugin crash stats.
163 void WritePluginStabilityElements(PrefService* pref);
165 // Within the stability group, write required attributes.
166 void WriteRequiredStabilityAttributes(PrefService* pref);
168 // Within the stability group, write attributes that need to be updated asap
169 // and can't be delayed until the user decides to restart chromium.
170 // Delaying these stats would bias metrics away from happy long lived
171 // chromium processes (ones that don't crash, and keep on running).
172 void WriteRealtimeStabilityAttributes(PrefService* pref,
173 base::TimeDelta incremental_uptime,
174 base::TimeDelta uptime);
176 // Writes the list of installed plugins.
177 void WritePluginList(const std::vector<content::WebPluginInfo>& plugin_list);
179 // Writes info about the Google Update install that is managing this client.
180 // This is a no-op if called on a non-Windows platform.
181 void WriteGoogleUpdateProto(const GoogleUpdateMetrics& google_update_metrics);
183 // Observes network state to provide values for SystemProfile::Network.
184 MetricsNetworkObserver network_observer_;
186 // The time when the current log was created.
187 const base::TimeTicks creation_time_;
189 // For including information on which extensions are installed in reports.
190 HashedExtensionMetrics extension_metrics_;
192 DISALLOW_COPY_AND_ASSIGN(MetricsLog);
195 #endif // CHROME_BROWSER_METRICS_METRICS_LOG_H_