[email protected] | 6ffdb900 | 2011-11-15 00:09:24 | [diff] [blame^] | 1 | // Copyright (c) 2011 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] | 1226abb | 2010-06-10 18:01:28 | [diff] [blame] | 16 | #include "chrome/common/metrics_helpers.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 17 | |
| 18 | struct AutocompleteLog; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 19 | class PrefService; |
| 20 | |
[email protected] | f3a1c64 | 2011-07-12 19:15:03 | [diff] [blame] | 21 | namespace base { |
| 22 | class DictionaryValue; |
| 23 | } |
| 24 | |
[email protected] | 191eb3f7 | 2010-12-21 06:27:50 | [diff] [blame] | 25 | namespace webkit { |
[email protected] | 191eb3f7 | 2010-12-21 06:27:50 | [diff] [blame] | 26 | struct WebPluginInfo; |
| 27 | } |
[email protected] | 191eb3f7 | 2010-12-21 06:27:50 | [diff] [blame] | 28 | |
[email protected] | 1226abb | 2010-06-10 18:01:28 | [diff] [blame] | 29 | class MetricsLog : public MetricsLogBase { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 30 | public: |
| 31 | // Creates a new metrics log |
| 32 | // client_id is the identifier for this profile on this installation |
| 33 | // session_id is an integer that's incremented on each application launch |
| 34 | MetricsLog(const std::string& client_id, int session_id); |
| 35 | virtual ~MetricsLog(); |
| 36 | |
| 37 | static void RegisterPrefs(PrefService* prefs); |
| 38 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 39 | // Records the current operating environment. Takes the list of installed |
| 40 | // plugins as a parameter because that can't be obtained synchronously |
| 41 | // from the UI thread. |
| 42 | // profile_metrics, if non-null, gives a dictionary of all profile metrics |
| 43 | // that are to be recorded. Each value in profile_metrics should be a |
| 44 | // dictionary giving the metrics for the profile. |
[email protected] | 191eb3f7 | 2010-12-21 06:27:50 | [diff] [blame] | 45 | void RecordEnvironment( |
[email protected] | 91d9f3d | 2011-08-14 05:24:44 | [diff] [blame] | 46 | const std::vector<webkit::WebPluginInfo>& plugin_list, |
[email protected] | f3a1c64 | 2011-07-12 19:15:03 | [diff] [blame] | 47 | const base::DictionaryValue* profile_metrics); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 48 | |
| 49 | // Records the input text, available choices, and selected entry when the |
| 50 | // user uses the Omnibox to open a URL. |
| 51 | void RecordOmniboxOpenedURL(const AutocompleteLog& log); |
| 52 | |
[email protected] | 0b33f80b | 2008-12-17 21:34:36 | [diff] [blame] | 53 | // Record recent delta for critical stability metrics. We can't wait for a |
| 54 | // restart to gather these, as that delay biases our observation away from |
| 55 | // users that run happily for a looooong time. We send increments with each |
| 56 | // uma log upload, just as we send histogram data. |
| 57 | void RecordIncrementalStabilityElements(); |
| 58 | |
[email protected] | 9165f74 | 2010-03-10 22:55:01 | [diff] [blame] | 59 | // Get the amount of uptime in seconds since this function was last called. |
| 60 | // This updates the cumulative uptime metric for uninstall as a side effect. |
| 61 | static int64 GetIncrementalUptime(PrefService* pref); |
| 62 | |
[email protected] | 1226abb | 2010-06-10 18:01:28 | [diff] [blame] | 63 | // Get the current version of the application as a string. |
| 64 | static std::string GetVersionString(); |
| 65 | |
[email protected] | dec76e80 | 2010-09-23 22:43:53 | [diff] [blame] | 66 | virtual MetricsLog* AsMetricsLog(); |
[email protected] | 85ed9d4 | 2010-06-08 22:37:44 | [diff] [blame] | 67 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 68 | private: |
[email protected] | c1834a9 | 2011-01-21 18:21:03 | [diff] [blame] | 69 | FRIEND_TEST_ALL_PREFIXES(MetricsLogTest, ChromeOSStabilityData); |
| 70 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 71 | // Returns the date at which the current metrics client ID was created as |
| 72 | // a string containing milliseconds since the epoch, or "0" if none was found. |
| 73 | std::string GetInstallDate() const; |
| 74 | |
[email protected] | 1226abb | 2010-06-10 18:01:28 | [diff] [blame] | 75 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 76 | // Writes application stability metrics (as part of the profile log). |
| 77 | // NOTE: Has the side-effect of clearing those counts. |
[email protected] | c1834a9 | 2011-01-21 18:21:03 | [diff] [blame] | 78 | void WriteStabilityElement(PrefService* pref); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 79 | |
[email protected] | 147bbc0b | 2009-01-06 19:37:40 | [diff] [blame] | 80 | // Within stability group, write plugin crash stats. |
| 81 | void WritePluginStabilityElements(PrefService* pref); |
| 82 | |
| 83 | // Within the stability group, write required attributes. |
| 84 | void WriteRequiredStabilityAttributes(PrefService* pref); |
| 85 | |
| 86 | // Within the stability group, write attributes that need to be updated asap |
[email protected] | 0b33f80b | 2008-12-17 21:34:36 | [diff] [blame] | 87 | // and can't be delayed until the user decides to restart chromium. |
| 88 | // Delaying these stats would bias metrics away from happy long lived |
| 89 | // chromium processes (ones that don't crash, and keep on running). |
[email protected] | 147bbc0b | 2009-01-06 19:37:40 | [diff] [blame] | 90 | void WriteRealtimeStabilityAttributes(PrefService* pref); |
[email protected] | 0b33f80b | 2008-12-17 21:34:36 | [diff] [blame] | 91 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 92 | // Writes the list of installed plugins. |
[email protected] | 191eb3f7 | 2010-12-21 06:27:50 | [diff] [blame] | 93 | void WritePluginList( |
[email protected] | 91d9f3d | 2011-08-14 05:24:44 | [diff] [blame] | 94 | const std::vector<webkit::WebPluginInfo>& plugin_list); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 95 | |
[email protected] | 147bbc0b | 2009-01-06 19:37:40 | [diff] [blame] | 96 | // Within the profile group, write basic install info including appversion. |
| 97 | void WriteInstallElement(); |
| 98 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 99 | // Writes all profile metrics. This invokes WriteProfileMetrics for each key |
| 100 | // in all_profiles_metrics that starts with kProfilePrefix. |
[email protected] | f3a1c64 | 2011-07-12 19:15:03 | [diff] [blame] | 101 | void WriteAllProfilesMetrics( |
| 102 | const base::DictionaryValue& all_profiles_metrics); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 103 | |
| 104 | // Writes metrics for the profile identified by key. This writes all |
| 105 | // key/value pairs in profile_metrics. |
[email protected] | e7b418b | 2010-07-30 19:47:47 | [diff] [blame] | 106 | void WriteProfileMetrics(const std::string& key, |
[email protected] | f3a1c64 | 2011-07-12 19:15:03 | [diff] [blame] | 107 | const base::DictionaryValue& profile_metrics); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 108 | |
[email protected] | 4d818fee | 2010-06-06 13:32:27 | [diff] [blame] | 109 | DISALLOW_COPY_AND_ASSIGN(MetricsLog); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 110 | }; |
| 111 | |
[email protected] | 11f485728 | 2009-11-13 19:56:17 | [diff] [blame] | 112 | #endif // CHROME_BROWSER_METRICS_METRICS_LOG_H_ |