blob: f5cf34e9235085c1440661515c4a7956dd14f613 [file] [log] [blame]
[email protected]2e4cd1a2012-01-12 08:51:031// Copyright (c) 2012 The Chromium Authors. All rights reserved.
license.botbf09a502008-08-24 00:55:552// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
initial.commit09911bf2008-07-26 23:55:294
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]11f4857282009-11-13 19:56:178#ifndef CHROME_BROWSER_METRICS_METRICS_LOG_H_
9#define CHROME_BROWSER_METRICS_METRICS_LOG_H_
initial.commit09911bf2008-07-26 23:55:2910
[email protected]6ffdb9002011-11-15 00:09:2411#include <string>
12#include <vector>
13
initial.commit09911bf2008-07-26 23:55:2914#include "base/basictypes.h"
[email protected]5eae204c2013-02-13 15:53:4215#include "chrome/browser/metrics/metrics_network_observer.h"
[email protected]e182be02012-01-27 02:35:4416#include "chrome/common/metrics/metrics_log_base.h"
[email protected]197c0772012-05-14 23:50:5117#include "chrome/installer/util/google_update_settings.h"
[email protected]767c9d92012-03-02 16:04:3418#include "ui/gfx/size.h"
initial.commit09911bf2008-07-26 23:55:2919
[email protected]f65859e2013-02-04 20:00:2520#if defined(OS_CHROMEOS)
21#include "chrome/browser/metrics/perf_provider_chromeos.h"
22#endif
23
initial.commit09911bf2008-07-26 23:55:2924struct AutocompleteLog;
[email protected]5eae204c2013-02-13 15:53:4225class MetricsNetworkObserver;
initial.commit09911bf2008-07-26 23:55:2926class PrefService;
[email protected]b1de2c72013-02-06 02:45:4727class PrefRegistrySimple;
initial.commit09911bf2008-07-26 23:55:2928
[email protected]f3a1c642011-07-12 19:15:0329namespace base {
30class DictionaryValue;
31}
32
[email protected]ed0fd002012-04-25 23:10:3433namespace tracked_objects {
34struct ProcessDataSnapshot;
35}
36
[email protected]2ac73f62012-08-13 21:49:0737namespace chrome_variations {
[email protected]0c8b7ad2012-11-06 07:08:1438struct ActiveGroupId;
[email protected]ad2461c2012-04-27 21:11:0339}
40
[email protected]191eb3f72010-12-21 06:27:5041namespace webkit {
[email protected]191eb3f72010-12-21 06:27:5042struct WebPluginInfo;
43}
[email protected]191eb3f72010-12-21 06:27:5044
[email protected]197c0772012-05-14 23:50:5145// This is a small helper struct to pass Google Update metrics in a single
46// reference argument to MetricsLog::RecordEnvironment().
47struct GoogleUpdateMetrics {
48 GoogleUpdateMetrics();
49 ~GoogleUpdateMetrics();
50
51 // Defines whether this is a user-level or system-level install.
52 bool is_system_install;
53 // The time at which Google Update last started an automatic update check.
54 base::Time last_started_au;
55 // The time at which Google Update last successfully recieved update
56 // information from Google servers.
57 base::Time last_checked;
58 // Details about Google Update's attempts to update itself.
59 GoogleUpdateSettings::ProductData google_update_data;
60 // Details about Google Update's attempts to update this product.
61 GoogleUpdateSettings::ProductData product_data;
62};
63
[email protected]1226abb2010-06-10 18:01:2864class MetricsLog : public MetricsLogBase {
initial.commit09911bf2008-07-26 23:55:2965 public:
66 // Creates a new metrics log
67 // client_id is the identifier for this profile on this installation
68 // session_id is an integer that's incremented on each application launch
69 MetricsLog(const std::string& client_id, int session_id);
70 virtual ~MetricsLog();
71
[email protected]b1de2c72013-02-06 02:45:4772 static void RegisterPrefs(PrefRegistrySimple* registry);
initial.commit09911bf2008-07-26 23:55:2973
[email protected]1df44b72012-01-19 05:20:3474 // Get the amount of uptime in seconds since this function was last called.
75 // This updates the cumulative uptime metric for uninstall as a side effect.
76 static int64 GetIncrementalUptime(PrefService* pref);
77
78 // Get the current version of the application as a string.
79 static std::string GetVersionString();
80
81 // Use |extension| in all uploaded appversions in addition to the standard
82 // version string.
83 static void set_version_extension(const std::string& extension);
84 static const std::string& version_extension();
85
initial.commit09911bf2008-07-26 23:55:2986 // Records the current operating environment. Takes the list of installed
[email protected]197c0772012-05-14 23:50:5187 // plugins and Google Update statistics as parameters because those can't be
88 // obtained synchronously from the UI thread.
initial.commit09911bf2008-07-26 23:55:2989 // 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.
[email protected]191eb3f72010-12-21 06:27:5092 void RecordEnvironment(
[email protected]91d9f3d2011-08-14 05:24:4493 const std::vector<webkit::WebPluginInfo>& plugin_list,
[email protected]197c0772012-05-14 23:50:5194 const GoogleUpdateMetrics& google_update_metrics,
[email protected]f3a1c642011-07-12 19:15:0395 const base::DictionaryValue* profile_metrics);
initial.commit09911bf2008-07-26 23:55:2996
[email protected]bc66d532012-03-23 01:57:0597 // Records the current operating environment. Takes the list of installed
[email protected]197c0772012-05-14 23:50:5198 // 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
102 // upload.
[email protected]bc66d532012-03-23 01:57:05103 void RecordEnvironmentProto(
[email protected]197c0772012-05-14 23:50:51104 const std::vector<webkit::WebPluginInfo>& plugin_list,
105 const GoogleUpdateMetrics& google_update_metrics);
[email protected]bc66d532012-03-23 01:57:05106
initial.commit09911bf2008-07-26 23:55:29107 // Records the input text, available choices, and selected entry when the
108 // user uses the Omnibox to open a URL.
109 void RecordOmniboxOpenedURL(const AutocompleteLog& log);
110
[email protected]ed0fd002012-04-25 23:10:34111 // 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,
[email protected]f3b357692013-03-22 05:16:13115 int process_type);
[email protected]ed0fd002012-04-25 23:10:34116
[email protected]0b33f80b2008-12-17 21:34:36117 // 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
[email protected]fe58acc22012-02-29 01:29:58120 // 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<webkit::WebPluginInfo>& plugin_list);
[email protected]0b33f80b2008-12-17 21:34:36125
[email protected]767c9d92012-03-02 16:04:34126 protected:
127 // Exposed for the sake of mocking in test code.
128
129 // Returns the PrefService from which to log metrics data.
130 virtual PrefService* GetPrefService();
131
132 // Returns the screen size for the primary monitor.
133 virtual gfx::Size GetScreenSize() const;
134
[email protected]aa96417972012-08-22 03:16:44135 // Returns the device scale factor for the primary monitor.
136 virtual float GetScreenDeviceScaleFactor() const;
137
[email protected]767c9d92012-03-02 16:04:34138 // Returns the number of monitors the user is using.
139 virtual int GetScreenCount() const;
140
141 // Fills |field_trial_ids| with the list of initialized field trials name and
142 // group ids.
143 virtual void GetFieldTrialIds(
[email protected]0c8b7ad2012-11-06 07:08:14144 std::vector<chrome_variations::ActiveGroupId>* field_trial_ids) const;
[email protected]767c9d92012-03-02 16:04:34145
initial.commit09911bf2008-07-26 23:55:29146 private:
[email protected]c1834a92011-01-21 18:21:03147 FRIEND_TEST_ALL_PREFIXES(MetricsLogTest, ChromeOSStabilityData);
148
initial.commit09911bf2008-07-26 23:55:29149 // Writes application stability metrics (as part of the profile log).
150 // NOTE: Has the side-effect of clearing those counts.
[email protected]fe58acc22012-02-29 01:29:58151 void WriteStabilityElement(
152 const std::vector<webkit::WebPluginInfo>& plugin_list,
153 PrefService* pref);
initial.commit09911bf2008-07-26 23:55:29154
[email protected]147bbc0b2009-01-06 19:37:40155 // Within stability group, write plugin crash stats.
[email protected]fe58acc22012-02-29 01:29:58156 void WritePluginStabilityElements(
157 const std::vector<webkit::WebPluginInfo>& plugin_list,
158 PrefService* pref);
[email protected]147bbc0b2009-01-06 19:37:40159
160 // Within the stability group, write required attributes.
161 void WriteRequiredStabilityAttributes(PrefService* pref);
162
163 // Within the stability group, write attributes that need to be updated asap
[email protected]0b33f80b2008-12-17 21:34:36164 // and can't be delayed until the user decides to restart chromium.
165 // Delaying these stats would bias metrics away from happy long lived
166 // chromium processes (ones that don't crash, and keep on running).
[email protected]147bbc0b2009-01-06 19:37:40167 void WriteRealtimeStabilityAttributes(PrefService* pref);
[email protected]0b33f80b2008-12-17 21:34:36168
[email protected]bc66d532012-03-23 01:57:05169 // Writes the list of installed plugins. If |write_as_xml| is true, writes
170 // the XML version. Otherwise, writes the protobuf version.
[email protected]191eb3f72010-12-21 06:27:50171 void WritePluginList(
[email protected]bc66d532012-03-23 01:57:05172 const std::vector<webkit::WebPluginInfo>& plugin_list,
173 bool write_as_xml);
initial.commit09911bf2008-07-26 23:55:29174
[email protected]147bbc0b2009-01-06 19:37:40175 // Within the profile group, write basic install info including appversion.
176 void WriteInstallElement();
177
initial.commit09911bf2008-07-26 23:55:29178 // Writes all profile metrics. This invokes WriteProfileMetrics for each key
179 // in all_profiles_metrics that starts with kProfilePrefix.
[email protected]f3a1c642011-07-12 19:15:03180 void WriteAllProfilesMetrics(
181 const base::DictionaryValue& all_profiles_metrics);
initial.commit09911bf2008-07-26 23:55:29182
183 // Writes metrics for the profile identified by key. This writes all
184 // key/value pairs in profile_metrics.
[email protected]e7b418b2010-07-30 19:47:47185 void WriteProfileMetrics(const std::string& key,
[email protected]f3a1c642011-07-12 19:15:03186 const base::DictionaryValue& profile_metrics);
initial.commit09911bf2008-07-26 23:55:29187
[email protected]197c0772012-05-14 23:50:51188 // Writes info about the Google Update install that is managing this client.
189 // This is a no-op if called on a non-Windows platform.
190 void WriteGoogleUpdateProto(const GoogleUpdateMetrics& google_update_metrics);
191
[email protected]5eae204c2013-02-13 15:53:42192 // Observes network state to provide values for SystemProfile::Network.
193 MetricsNetworkObserver network_observer_;
194
[email protected]f65859e2013-02-04 20:00:25195#if defined(OS_CHROMEOS)
196 metrics::PerfProvider perf_provider_;
197#endif
[email protected]74b299e2013-01-29 01:24:42198
[email protected]4d818fee2010-06-06 13:32:27199 DISALLOW_COPY_AND_ASSIGN(MetricsLog);
initial.commit09911bf2008-07-26 23:55:29200};
201
[email protected]11f4857282009-11-13 19:56:17202#endif // CHROME_BROWSER_METRICS_METRICS_LOG_H_