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