blob: 4d9565063fba40bcd3b8aed8823787e0483b7691 [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]e182be02012-01-27 02:35:4415#include "chrome/common/metrics/metrics_log_base.h"
[email protected]197c0772012-05-14 23:50:5116#include "chrome/installer/util/google_update_settings.h"
[email protected]ed0fd002012-04-25 23:10:3417#include "content/public/common/process_type.h"
[email protected]767c9d92012-03-02 16:04:3418#include "ui/gfx/size.h"
initial.commit09911bf2008-07-26 23:55:2919
20struct AutocompleteLog;
initial.commit09911bf2008-07-26 23:55:2921class PrefService;
[email protected]5b199522012-12-22 17:24:4422class PrefServiceSimple;
initial.commit09911bf2008-07-26 23:55:2923
[email protected]f3a1c642011-07-12 19:15:0324namespace base {
25class DictionaryValue;
26}
27
[email protected]ed0fd002012-04-25 23:10:3428namespace tracked_objects {
29struct ProcessDataSnapshot;
30}
31
[email protected]2ac73f62012-08-13 21:49:0732namespace chrome_variations {
[email protected]0c8b7ad2012-11-06 07:08:1433struct ActiveGroupId;
[email protected]ad2461c2012-04-27 21:11:0334}
35
[email protected]191eb3f72010-12-21 06:27:5036namespace webkit {
[email protected]191eb3f72010-12-21 06:27:5037struct WebPluginInfo;
38}
[email protected]191eb3f72010-12-21 06:27:5039
[email protected]197c0772012-05-14 23:50:5140// This is a small helper struct to pass Google Update metrics in a single
41// reference argument to MetricsLog::RecordEnvironment().
42struct GoogleUpdateMetrics {
43 GoogleUpdateMetrics();
44 ~GoogleUpdateMetrics();
45
46 // Defines whether this is a user-level or system-level install.
47 bool is_system_install;
48 // The time at which Google Update last started an automatic update check.
49 base::Time last_started_au;
50 // The time at which Google Update last successfully recieved update
51 // information from Google servers.
52 base::Time last_checked;
53 // Details about Google Update's attempts to update itself.
54 GoogleUpdateSettings::ProductData google_update_data;
55 // Details about Google Update's attempts to update this product.
56 GoogleUpdateSettings::ProductData product_data;
57};
58
[email protected]1226abb2010-06-10 18:01:2859class MetricsLog : public MetricsLogBase {
initial.commit09911bf2008-07-26 23:55:2960 public:
61 // Creates a new metrics log
62 // client_id is the identifier for this profile on this installation
63 // session_id is an integer that's incremented on each application launch
64 MetricsLog(const std::string& client_id, int session_id);
65 virtual ~MetricsLog();
66
[email protected]5b199522012-12-22 17:24:4467 static void RegisterPrefs(PrefServiceSimple* prefs);
initial.commit09911bf2008-07-26 23:55:2968
[email protected]1df44b72012-01-19 05:20:3469 // Get the amount of uptime in seconds since this function was last called.
70 // This updates the cumulative uptime metric for uninstall as a side effect.
71 static int64 GetIncrementalUptime(PrefService* pref);
72
73 // Get the current version of the application as a string.
74 static std::string GetVersionString();
75
76 // Use |extension| in all uploaded appversions in addition to the standard
77 // version string.
78 static void set_version_extension(const std::string& extension);
79 static const std::string& version_extension();
80
initial.commit09911bf2008-07-26 23:55:2981 // Records the current operating environment. Takes the list of installed
[email protected]197c0772012-05-14 23:50:5182 // plugins and Google Update statistics as parameters because those can't be
83 // obtained synchronously from the UI thread.
initial.commit09911bf2008-07-26 23:55:2984 // profile_metrics, if non-null, gives a dictionary of all profile metrics
85 // that are to be recorded. Each value in profile_metrics should be a
86 // dictionary giving the metrics for the profile.
[email protected]191eb3f72010-12-21 06:27:5087 void RecordEnvironment(
[email protected]91d9f3d2011-08-14 05:24:4488 const std::vector<webkit::WebPluginInfo>& plugin_list,
[email protected]197c0772012-05-14 23:50:5189 const GoogleUpdateMetrics& google_update_metrics,
[email protected]f3a1c642011-07-12 19:15:0390 const base::DictionaryValue* profile_metrics);
initial.commit09911bf2008-07-26 23:55:2991
[email protected]bc66d532012-03-23 01:57:0592 // Records the current operating environment. Takes the list of installed
[email protected]197c0772012-05-14 23:50:5193 // plugins and Google Update statistics as parameters because those can't be
94 // obtained synchronously from the UI thread. This is exposed as a separate
95 // method from the |RecordEnvironment()| method above because we record the
96 // environment with *each* protobuf upload, but only with the initial XML
97 // upload.
[email protected]bc66d532012-03-23 01:57:0598 void RecordEnvironmentProto(
[email protected]197c0772012-05-14 23:50:5199 const std::vector<webkit::WebPluginInfo>& plugin_list,
100 const GoogleUpdateMetrics& google_update_metrics);
[email protected]bc66d532012-03-23 01:57:05101
initial.commit09911bf2008-07-26 23:55:29102 // Records the input text, available choices, and selected entry when the
103 // user uses the Omnibox to open a URL.
104 void RecordOmniboxOpenedURL(const AutocompleteLog& log);
105
[email protected]ed0fd002012-04-25 23:10:34106 // Records the passed profiled data, which should be a snapshot of the
107 // browser's profiled performance during startup for a single process.
108 void RecordProfilerData(
109 const tracked_objects::ProcessDataSnapshot& process_data,
110 content::ProcessType process_type);
111
[email protected]0b33f80b2008-12-17 21:34:36112 // Record recent delta for critical stability metrics. We can't wait for a
113 // restart to gather these, as that delay biases our observation away from
114 // users that run happily for a looooong time. We send increments with each
[email protected]fe58acc22012-02-29 01:29:58115 // uma log upload, just as we send histogram data. Takes the list of
116 // installed plugins as a parameter because that can't be obtained
117 // synchronously from the UI thread.
118 void RecordIncrementalStabilityElements(
119 const std::vector<webkit::WebPluginInfo>& plugin_list);
[email protected]0b33f80b2008-12-17 21:34:36120
[email protected]767c9d92012-03-02 16:04:34121 protected:
122 // Exposed for the sake of mocking in test code.
123
124 // Returns the PrefService from which to log metrics data.
125 virtual PrefService* GetPrefService();
126
127 // Returns the screen size for the primary monitor.
128 virtual gfx::Size GetScreenSize() const;
129
[email protected]aa96417972012-08-22 03:16:44130 // Returns the device scale factor for the primary monitor.
131 virtual float GetScreenDeviceScaleFactor() const;
132
[email protected]767c9d92012-03-02 16:04:34133 // Returns the number of monitors the user is using.
134 virtual int GetScreenCount() const;
135
136 // Fills |field_trial_ids| with the list of initialized field trials name and
137 // group ids.
138 virtual void GetFieldTrialIds(
[email protected]0c8b7ad2012-11-06 07:08:14139 std::vector<chrome_variations::ActiveGroupId>* field_trial_ids) const;
[email protected]767c9d92012-03-02 16:04:34140
initial.commit09911bf2008-07-26 23:55:29141 private:
[email protected]c1834a92011-01-21 18:21:03142 FRIEND_TEST_ALL_PREFIXES(MetricsLogTest, ChromeOSStabilityData);
143
[email protected]74b299e2013-01-29 01:24:42144 class NetworkObserver;
145
initial.commit09911bf2008-07-26 23:55:29146 // Writes application stability metrics (as part of the profile log).
147 // NOTE: Has the side-effect of clearing those counts.
[email protected]fe58acc22012-02-29 01:29:58148 void WriteStabilityElement(
149 const std::vector<webkit::WebPluginInfo>& plugin_list,
150 PrefService* pref);
initial.commit09911bf2008-07-26 23:55:29151
[email protected]147bbc0b2009-01-06 19:37:40152 // Within stability group, write plugin crash stats.
[email protected]fe58acc22012-02-29 01:29:58153 void WritePluginStabilityElements(
154 const std::vector<webkit::WebPluginInfo>& plugin_list,
155 PrefService* pref);
[email protected]147bbc0b2009-01-06 19:37:40156
157 // Within the stability group, write required attributes.
158 void WriteRequiredStabilityAttributes(PrefService* pref);
159
160 // Within the stability group, write attributes that need to be updated asap
[email protected]0b33f80b2008-12-17 21:34:36161 // and can't be delayed until the user decides to restart chromium.
162 // Delaying these stats would bias metrics away from happy long lived
163 // chromium processes (ones that don't crash, and keep on running).
[email protected]147bbc0b2009-01-06 19:37:40164 void WriteRealtimeStabilityAttributes(PrefService* pref);
[email protected]0b33f80b2008-12-17 21:34:36165
[email protected]bc66d532012-03-23 01:57:05166 // Writes the list of installed plugins. If |write_as_xml| is true, writes
167 // the XML version. Otherwise, writes the protobuf version.
[email protected]191eb3f72010-12-21 06:27:50168 void WritePluginList(
[email protected]bc66d532012-03-23 01:57:05169 const std::vector<webkit::WebPluginInfo>& plugin_list,
170 bool write_as_xml);
initial.commit09911bf2008-07-26 23:55:29171
[email protected]147bbc0b2009-01-06 19:37:40172 // Within the profile group, write basic install info including appversion.
173 void WriteInstallElement();
174
initial.commit09911bf2008-07-26 23:55:29175 // Writes all profile metrics. This invokes WriteProfileMetrics for each key
176 // in all_profiles_metrics that starts with kProfilePrefix.
[email protected]f3a1c642011-07-12 19:15:03177 void WriteAllProfilesMetrics(
178 const base::DictionaryValue& all_profiles_metrics);
initial.commit09911bf2008-07-26 23:55:29179
180 // Writes metrics for the profile identified by key. This writes all
181 // key/value pairs in profile_metrics.
[email protected]e7b418b2010-07-30 19:47:47182 void WriteProfileMetrics(const std::string& key,
[email protected]f3a1c642011-07-12 19:15:03183 const base::DictionaryValue& profile_metrics);
initial.commit09911bf2008-07-26 23:55:29184
[email protected]197c0772012-05-14 23:50:51185 // Writes info about the Google Update install that is managing this client.
186 // This is a no-op if called on a non-Windows platform.
187 void WriteGoogleUpdateProto(const GoogleUpdateMetrics& google_update_metrics);
188
[email protected]74b299e2013-01-29 01:24:42189 // Registers as observer with net::NetworkChangeNotifier and keeps track of
190 // the network environment.
191 scoped_ptr<NetworkObserver> network_observer_;
192
[email protected]4d818fee2010-06-06 13:32:27193 DISALLOW_COPY_AND_ASSIGN(MetricsLog);
initial.commit09911bf2008-07-26 23:55:29194};
195
[email protected]11f4857282009-11-13 19:56:17196#endif // CHROME_BROWSER_METRICS_METRICS_LOG_H_