OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // This file defines a service that collects information about the user | 5 // This file defines a service that collects information about the user |
6 // experience in order to help improve future versions of the app. | 6 // experience in order to help improve future versions of the app. |
7 | 7 |
8 #ifndef CHROME_BROWSER_METRICS_METRICS_SERVICE_H_ | 8 #ifndef CHROME_BROWSER_METRICS_METRICS_SERVICE_H_ |
9 #define CHROME_BROWSER_METRICS_METRICS_SERVICE_H_ | 9 #define CHROME_BROWSER_METRICS_METRICS_SERVICE_H_ |
10 | 10 |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
47 class TemplateURLService; | 47 class TemplateURLService; |
48 | 48 |
49 namespace { | 49 namespace { |
50 class CrashesDOMHandler; | 50 class CrashesDOMHandler; |
51 class FlashDOMHandler; | 51 class FlashDOMHandler; |
52 } | 52 } |
53 | 53 |
54 namespace base { | 54 namespace base { |
55 class DictionaryValue; | 55 class DictionaryValue; |
56 class MessageLoopProxy; | 56 class MessageLoopProxy; |
57 class PrefService; | |
57 } | 58 } |
58 | 59 |
59 namespace chrome_variations { | 60 namespace chrome_variations { |
60 struct ActiveGroupId; | 61 struct ActiveGroupId; |
61 } | 62 } |
62 | 63 |
63 namespace content { | 64 namespace content { |
64 class RenderProcessHost; | 65 class RenderProcessHost; |
65 class WebContents; | 66 class WebContents; |
66 struct WebPluginInfo; | 67 struct WebPluginInfo; |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
124 UNINITIALIZED_PHASE = 0, | 125 UNINITIALIZED_PHASE = 0, |
125 START_METRICS_RECORDING = 100, | 126 START_METRICS_RECORDING = 100, |
126 CREATE_PROFILE = 200, | 127 CREATE_PROFILE = 200, |
127 STARTUP_TIMEBOMB_ARM = 300, | 128 STARTUP_TIMEBOMB_ARM = 300, |
128 THREAD_WATCHER_START = 400, | 129 THREAD_WATCHER_START = 400, |
129 MAIN_MESSAGE_LOOP_RUN = 500, | 130 MAIN_MESSAGE_LOOP_RUN = 500, |
130 SHUTDOWN_TIMEBOMB_ARM = 600, | 131 SHUTDOWN_TIMEBOMB_ARM = 600, |
131 SHUTDOWN_COMPLETE = 700, | 132 SHUTDOWN_COMPLETE = 700, |
132 }; | 133 }; |
133 | 134 |
134 // Creates the MetricsService with the given |state_manager|. Does not take | 135 // Creates the MetricsService with the given |state_manager| and |
135 // ownership of |state_manager|, instead stores a weak pointer to it. Caller | 136 // |local_state|. Does not take ownership of the parameters, instead stores |
136 // should ensure that |state_manager| is valid for the lifetime of this class. | 137 // weak pointers. Caller should ensure that the passed-in objects are valid |
137 explicit MetricsService(metrics::MetricsStateManager* state_manager); | 138 // for the lifetime of this class. |
139 MetricsService(metrics::MetricsStateManager* state_manager, | |
140 PrefService* local_state); | |
138 virtual ~MetricsService(); | 141 virtual ~MetricsService(); |
139 | 142 |
140 // Initializes metrics recording state. Updates various bookkeeping values in | 143 // Initializes metrics recording state. Updates various bookkeeping values in |
141 // prefs and sets up the scheduler. This is a separate function rather than | 144 // prefs and sets up the scheduler. This is a separate function rather than |
142 // being done by the constructor so that field trials could be created before | 145 // being done by the constructor so that field trials could be created before |
143 // this is run. | 146 // this is run. |
144 void InitializeMetricsRecordingState(); | 147 void InitializeMetricsRecordingState(); |
145 | 148 |
146 // Starts the metrics system, turning on recording and uploading of metrics. | 149 // Starts the metrics system, turning on recording and uploading of metrics. |
147 // Should be called when starting up with metrics enabled, or when metrics | 150 // Should be called when starting up with metrics enabled, or when metrics |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
228 #endif // defined(OS_ANDROID) | 231 #endif // defined(OS_ANDROID) |
229 | 232 |
230 #if defined(OS_ANDROID) || defined(OS_IOS) | 233 #if defined(OS_ANDROID) || defined(OS_IOS) |
231 // Called when the application is going into background mode. | 234 // Called when the application is going into background mode. |
232 void OnAppEnterBackground(); | 235 void OnAppEnterBackground(); |
233 | 236 |
234 // Called when the application is coming out of background mode. | 237 // Called when the application is coming out of background mode. |
235 void OnAppEnterForeground(); | 238 void OnAppEnterForeground(); |
236 #else | 239 #else |
237 // Set the dirty flag, which will require a later call to LogCleanShutdown(). | 240 // Set the dirty flag, which will require a later call to LogCleanShutdown(). |
238 static void LogNeedForCleanShutdown(); | 241 static void LogNeedForCleanShutdown(PrefService* local_state); |
239 #endif // defined(OS_ANDROID) || defined(OS_IOS) | 242 #endif // defined(OS_ANDROID) || defined(OS_IOS) |
240 | 243 |
241 static void SetExecutionPhase(ExecutionPhase execution_phase); | 244 static void SetExecutionPhase(ExecutionPhase execution_phase, |
245 PrefService* local_state); | |
242 | 246 |
243 // Saves in the preferences if the crash report registration was successful. | 247 // Saves in the preferences if the crash report registration was successful. |
244 // This count is eventually send via UMA logs. | 248 // This count is eventually send via UMA logs. |
245 void RecordBreakpadRegistration(bool success); | 249 void RecordBreakpadRegistration(bool success); |
246 | 250 |
247 // Saves in the preferences if the browser is running under a debugger. | 251 // Saves in the preferences if the browser is running under a debugger. |
248 // This count is eventually send via UMA logs. | 252 // This count is eventually send via UMA logs. |
249 void RecordBreakpadHasDebugger(bool has_debugger); | 253 void RecordBreakpadHasDebugger(bool has_debugger); |
250 | 254 |
251 #if defined(OS_WIN) | 255 #if defined(OS_WIN) |
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
480 | 484 |
481 // Returns a list of synthetic field trials that were active for the entire | 485 // Returns a list of synthetic field trials that were active for the entire |
482 // duration of the current log. | 486 // duration of the current log. |
483 void GetCurrentSyntheticFieldTrials( | 487 void GetCurrentSyntheticFieldTrials( |
484 std::vector<chrome_variations::ActiveGroupId>* synthetic_trials); | 488 std::vector<chrome_variations::ActiveGroupId>* synthetic_trials); |
485 | 489 |
486 // Used to manage various metrics reporting state prefs, such as client id, | 490 // Used to manage various metrics reporting state prefs, such as client id, |
487 // low entropy source and whether metrics reporting is enabled. Weak pointer. | 491 // low entropy source and whether metrics reporting is enabled. Weak pointer. |
488 metrics::MetricsStateManager* state_manager_; | 492 metrics::MetricsStateManager* state_manager_; |
489 | 493 |
494 PrefService* local_state_; | |
495 | |
490 base::ActionCallback action_callback_; | 496 base::ActionCallback action_callback_; |
491 | 497 |
492 content::NotificationRegistrar registrar_; | 498 content::NotificationRegistrar registrar_; |
493 | 499 |
494 // Set to true when |ResetMetricsIDsIfNecessary| is called for the first time. | 500 // Set to true when |ResetMetricsIDsIfNecessary| is called for the first time. |
495 // This prevents multiple resets within the same Chrome session. | 501 // This prevents multiple resets within the same Chrome session. |
496 bool metrics_ids_reset_check_performed_; | 502 bool metrics_ids_reset_check_performed_; |
497 | 503 |
498 // Indicate whether recording and reporting are currently happening. | 504 // Indicate whether recording and reporting are currently happening. |
499 // These should not be set directly, but by calling SetRecording and | 505 // These should not be set directly, but by calling SetRecording and |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
624 friend class extensions::MetricsPrivateGetIsCrashReportingEnabledFunction; | 630 friend class extensions::MetricsPrivateGetIsCrashReportingEnabledFunction; |
625 friend class ::FlashDOMHandler; | 631 friend class ::FlashDOMHandler; |
626 friend class system_logs::ChromeInternalLogSource; | 632 friend class system_logs::ChromeInternalLogSource; |
627 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, MetricsReportingEnabled); | 633 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, MetricsReportingEnabled); |
628 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, CrashReportingEnabled); | 634 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, CrashReportingEnabled); |
629 | 635 |
630 // Returns true if prefs::kMetricsReportingEnabled is set. | 636 // Returns true if prefs::kMetricsReportingEnabled is set. |
631 // TODO(asvitkine): Consolidate the method in MetricsStateManager. | 637 // TODO(asvitkine): Consolidate the method in MetricsStateManager. |
632 // TODO(asvitkine): This function does not report the correct value on | 638 // TODO(asvitkine): This function does not report the correct value on |
633 // Android and ChromeOS, see http://crbug.com/362192. | 639 // Android and ChromeOS, see http://crbug.com/362192. |
634 static bool IsMetricsReportingEnabled(); | 640 static bool IsMetricsReportingEnabled(const PrefService* local_state); |
Alexei Svitkine (slow)
2014/05/19 13:13:54
Hmm, so we have a separate bug to move MetricsServ
blundell
2014/05/19 13:49:28
Are we not going to need to access this API from t
Alexei Svitkine (slow)
2014/05/19 13:53:44
Not quite. The idea is that the implementation sho
| |
635 | 641 |
636 // Returns true if crash reporting is enabled. This is set at the platform | 642 // Returns true if crash reporting is enabled. This is set at the platform |
637 // level for Android and ChromeOS, and otherwise is the same as | 643 // level for Android and ChromeOS, and otherwise is the same as |
638 // IsMetricsReportingEnabled for desktop Chrome. | 644 // IsMetricsReportingEnabled for desktop Chrome. |
639 static bool IsCrashReportingEnabled(); | 645 static bool IsCrashReportingEnabled(const PrefService* local_state); |
640 | 646 |
641 // Registers/unregisters |observer| to receive MetricsLog notifications | 647 // Registers/unregisters |observer| to receive MetricsLog notifications |
642 // from metrics service. | 648 // from metrics service. |
643 static void AddMetricsServiceObserver(MetricsServiceObserver* observer); | 649 static void AddMetricsServiceObserver(MetricsServiceObserver* observer); |
644 static void RemoveMetricsServiceObserver(MetricsServiceObserver* observer); | 650 static void RemoveMetricsServiceObserver(MetricsServiceObserver* observer); |
645 | 651 |
646 DISALLOW_IMPLICIT_CONSTRUCTORS(MetricsServiceHelper); | 652 DISALLOW_IMPLICIT_CONSTRUCTORS(MetricsServiceHelper); |
647 }; | 653 }; |
648 | 654 |
649 #endif // CHROME_BROWSER_METRICS_METRICS_SERVICE_H_ | 655 #endif // CHROME_BROWSER_METRICS_METRICS_SERVICE_H_ |
OLD | NEW |