[email protected] | 2e4cd1a | 2012-01-12 08:51:03 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
license.bot | bf09a50 | 2008-08-24 00:55:55 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4 | |
| 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] | 11f485728 | 2009-11-13 19:56:17 | [diff] [blame] | 8 | #ifndef CHROME_BROWSER_METRICS_METRICS_LOG_H_ |
| 9 | #define CHROME_BROWSER_METRICS_METRICS_LOG_H_ |
[email protected] | 32b76ef | 2010-07-26 23:08:24 | [diff] [blame] | 10 | #pragma once |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 11 | |
[email protected] | 6ffdb900 | 2011-11-15 00:09:24 | [diff] [blame] | 12 | #include <string> |
| 13 | #include <vector> |
| 14 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 15 | #include "base/basictypes.h" |
[email protected] | 767c9d9 | 2012-03-02 16:04:34 | [diff] [blame^] | 16 | #include "base/metrics/field_trial.h" |
[email protected] | e182be0 | 2012-01-27 02:35:44 | [diff] [blame] | 17 | #include "chrome/common/metrics/metrics_log_base.h" |
[email protected] | 767c9d9 | 2012-03-02 16:04:34 | [diff] [blame^] | 18 | #include "ui/gfx/size.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 19 | |
| 20 | struct AutocompleteLog; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 21 | class PrefService; |
| 22 | |
[email protected] | f3a1c64 | 2011-07-12 19:15:03 | [diff] [blame] | 23 | namespace base { |
| 24 | class DictionaryValue; |
| 25 | } |
| 26 | |
[email protected] | 191eb3f7 | 2010-12-21 06:27:50 | [diff] [blame] | 27 | namespace webkit { |
[email protected] | 191eb3f7 | 2010-12-21 06:27:50 | [diff] [blame] | 28 | struct WebPluginInfo; |
| 29 | } |
[email protected] | 191eb3f7 | 2010-12-21 06:27:50 | [diff] [blame] | 30 | |
[email protected] | 1226abb | 2010-06-10 18:01:28 | [diff] [blame] | 31 | class MetricsLog : public MetricsLogBase { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 32 | public: |
| 33 | // Creates a new metrics log |
| 34 | // client_id is the identifier for this profile on this installation |
| 35 | // session_id is an integer that's incremented on each application launch |
| 36 | MetricsLog(const std::string& client_id, int session_id); |
| 37 | virtual ~MetricsLog(); |
| 38 | |
| 39 | static void RegisterPrefs(PrefService* prefs); |
| 40 | |
[email protected] | 1df44b7 | 2012-01-19 05:20:34 | [diff] [blame] | 41 | // Get the amount of uptime in seconds since this function was last called. |
| 42 | // This updates the cumulative uptime metric for uninstall as a side effect. |
| 43 | static int64 GetIncrementalUptime(PrefService* pref); |
| 44 | |
| 45 | // Get the current version of the application as a string. |
| 46 | static std::string GetVersionString(); |
| 47 | |
| 48 | // Use |extension| in all uploaded appversions in addition to the standard |
| 49 | // version string. |
| 50 | static void set_version_extension(const std::string& extension); |
| 51 | static const std::string& version_extension(); |
| 52 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 53 | // Records the current operating environment. Takes the list of installed |
| 54 | // plugins as a parameter because that can't be obtained synchronously |
| 55 | // from the UI thread. |
| 56 | // profile_metrics, if non-null, gives a dictionary of all profile metrics |
| 57 | // that are to be recorded. Each value in profile_metrics should be a |
| 58 | // dictionary giving the metrics for the profile. |
[email protected] | 191eb3f7 | 2010-12-21 06:27:50 | [diff] [blame] | 59 | void RecordEnvironment( |
[email protected] | 91d9f3d | 2011-08-14 05:24:44 | [diff] [blame] | 60 | const std::vector<webkit::WebPluginInfo>& plugin_list, |
[email protected] | f3a1c64 | 2011-07-12 19:15:03 | [diff] [blame] | 61 | const base::DictionaryValue* profile_metrics); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 62 | |
| 63 | // Records the input text, available choices, and selected entry when the |
| 64 | // user uses the Omnibox to open a URL. |
| 65 | void RecordOmniboxOpenedURL(const AutocompleteLog& log); |
| 66 | |
[email protected] | 0b33f80b | 2008-12-17 21:34:36 | [diff] [blame] | 67 | // Record recent delta for critical stability metrics. We can't wait for a |
| 68 | // restart to gather these, as that delay biases our observation away from |
| 69 | // users that run happily for a looooong time. We send increments with each |
[email protected] | fe58acc2 | 2012-02-29 01:29:58 | [diff] [blame] | 70 | // uma log upload, just as we send histogram data. Takes the list of |
| 71 | // installed plugins as a parameter because that can't be obtained |
| 72 | // synchronously from the UI thread. |
| 73 | void RecordIncrementalStabilityElements( |
| 74 | const std::vector<webkit::WebPluginInfo>& plugin_list); |
[email protected] | 0b33f80b | 2008-12-17 21:34:36 | [diff] [blame] | 75 | |
[email protected] | 767c9d9 | 2012-03-02 16:04:34 | [diff] [blame^] | 76 | protected: |
| 77 | // Exposed for the sake of mocking in test code. |
| 78 | |
| 79 | // Returns the PrefService from which to log metrics data. |
| 80 | virtual PrefService* GetPrefService(); |
| 81 | |
| 82 | // Returns the screen size for the primary monitor. |
| 83 | virtual gfx::Size GetScreenSize() const; |
| 84 | |
| 85 | // Returns the number of monitors the user is using. |
| 86 | virtual int GetScreenCount() const; |
| 87 | |
| 88 | // Fills |field_trial_ids| with the list of initialized field trials name and |
| 89 | // group ids. |
| 90 | virtual void GetFieldTrialIds( |
| 91 | std::vector<base::FieldTrial::NameGroupId>* field_trial_ids) const; |
| 92 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 93 | private: |
[email protected] | c1834a9 | 2011-01-21 18:21:03 | [diff] [blame] | 94 | FRIEND_TEST_ALL_PREFIXES(MetricsLogTest, ChromeOSStabilityData); |
| 95 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 96 | // Writes application stability metrics (as part of the profile log). |
| 97 | // NOTE: Has the side-effect of clearing those counts. |
[email protected] | fe58acc2 | 2012-02-29 01:29:58 | [diff] [blame] | 98 | void WriteStabilityElement( |
| 99 | const std::vector<webkit::WebPluginInfo>& plugin_list, |
| 100 | PrefService* pref); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 101 | |
[email protected] | 147bbc0b | 2009-01-06 19:37:40 | [diff] [blame] | 102 | // Within stability group, write plugin crash stats. |
[email protected] | fe58acc2 | 2012-02-29 01:29:58 | [diff] [blame] | 103 | void WritePluginStabilityElements( |
| 104 | const std::vector<webkit::WebPluginInfo>& plugin_list, |
| 105 | PrefService* pref); |
[email protected] | 147bbc0b | 2009-01-06 19:37:40 | [diff] [blame] | 106 | |
| 107 | // Within the stability group, write required attributes. |
| 108 | void WriteRequiredStabilityAttributes(PrefService* pref); |
| 109 | |
| 110 | // Within the stability group, write attributes that need to be updated asap |
[email protected] | 0b33f80b | 2008-12-17 21:34:36 | [diff] [blame] | 111 | // and can't be delayed until the user decides to restart chromium. |
| 112 | // Delaying these stats would bias metrics away from happy long lived |
| 113 | // chromium processes (ones that don't crash, and keep on running). |
[email protected] | 147bbc0b | 2009-01-06 19:37:40 | [diff] [blame] | 114 | void WriteRealtimeStabilityAttributes(PrefService* pref); |
[email protected] | 0b33f80b | 2008-12-17 21:34:36 | [diff] [blame] | 115 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 116 | // Writes the list of installed plugins. |
[email protected] | 191eb3f7 | 2010-12-21 06:27:50 | [diff] [blame] | 117 | void WritePluginList( |
[email protected] | 91d9f3d | 2011-08-14 05:24:44 | [diff] [blame] | 118 | const std::vector<webkit::WebPluginInfo>& plugin_list); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 119 | |
[email protected] | 147bbc0b | 2009-01-06 19:37:40 | [diff] [blame] | 120 | // Within the profile group, write basic install info including appversion. |
| 121 | void WriteInstallElement(); |
| 122 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 123 | // Writes all profile metrics. This invokes WriteProfileMetrics for each key |
| 124 | // in all_profiles_metrics that starts with kProfilePrefix. |
[email protected] | f3a1c64 | 2011-07-12 19:15:03 | [diff] [blame] | 125 | void WriteAllProfilesMetrics( |
| 126 | const base::DictionaryValue& all_profiles_metrics); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 127 | |
| 128 | // Writes metrics for the profile identified by key. This writes all |
| 129 | // key/value pairs in profile_metrics. |
[email protected] | e7b418b | 2010-07-30 19:47:47 | [diff] [blame] | 130 | void WriteProfileMetrics(const std::string& key, |
[email protected] | f3a1c64 | 2011-07-12 19:15:03 | [diff] [blame] | 131 | const base::DictionaryValue& profile_metrics); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 132 | |
[email protected] | 4d818fee | 2010-06-06 13:32:27 | [diff] [blame] | 133 | DISALLOW_COPY_AND_ASSIGN(MetricsLog); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 134 | }; |
| 135 | |
[email protected] | 11f485728 | 2009-11-13 19:56:17 | [diff] [blame] | 136 | #endif // CHROME_BROWSER_METRICS_METRICS_LOG_H_ |