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 |
11 #include <map> | 11 #include <map> |
12 #include <string> | 12 #include <string> |
13 #include <vector> | 13 #include <vector> |
14 | 14 |
15 #include "base/basictypes.h" | 15 #include "base/basictypes.h" |
16 #include "base/gtest_prod_util.h" | 16 #include "base/gtest_prod_util.h" |
17 #include "base/memory/scoped_ptr.h" | 17 #include "base/memory/scoped_ptr.h" |
18 #include "base/memory/scoped_vector.h" | 18 #include "base/memory/scoped_vector.h" |
19 #include "base/memory/weak_ptr.h" | 19 #include "base/memory/weak_ptr.h" |
20 #include "base/metrics/field_trial.h" | 20 #include "base/metrics/field_trial.h" |
| 21 #include "base/metrics/histogram_flattener.h" |
| 22 #include "base/metrics/histogram_snapshot_manager.h" |
21 #include "base/metrics/user_metrics.h" | 23 #include "base/metrics/user_metrics.h" |
22 #include "base/observer_list.h" | 24 #include "base/observer_list.h" |
23 #include "base/process/kill.h" | 25 #include "base/process/kill.h" |
24 #include "base/threading/thread_checker.h" | 26 #include "base/threading/thread_checker.h" |
25 #include "base/time/time.h" | 27 #include "base/time/time.h" |
26 #include "chrome/browser/metrics/metrics_log.h" | 28 #include "chrome/browser/metrics/metrics_log.h" |
27 #include "chrome/browser/metrics/tracking_synchronizer_observer.h" | 29 #include "chrome/browser/metrics/tracking_synchronizer_observer.h" |
28 #include "chrome/common/metrics/metrics_service_base.h" | |
29 #include "chrome/installer/util/google_update_settings.h" | 30 #include "chrome/installer/util/google_update_settings.h" |
| 31 #include "components/metrics/metrics_log_manager.h" |
30 #include "components/metrics/metrics_provider.h" | 32 #include "components/metrics/metrics_provider.h" |
31 #include "components/metrics/metrics_service_observer.h" | 33 #include "components/metrics/metrics_service_observer.h" |
32 #include "components/variations/active_field_trials.h" | 34 #include "components/variations/active_field_trials.h" |
33 #include "content/public/browser/browser_child_process_observer.h" | 35 #include "content/public/browser/browser_child_process_observer.h" |
34 #include "content/public/browser/notification_observer.h" | 36 #include "content/public/browser/notification_observer.h" |
35 #include "content/public/browser/notification_registrar.h" | 37 #include "content/public/browser/notification_registrar.h" |
36 #include "content/public/browser/user_metrics.h" | 38 #include "content/public/browser/user_metrics.h" |
37 #include "net/url_request/url_fetcher_delegate.h" | 39 #include "net/url_request/url_fetcher_delegate.h" |
38 | 40 |
39 #if defined(OS_ANDROID) | 41 #if defined(OS_ANDROID) |
40 #include "chrome/browser/android/activity_type_ids.h" | 42 #include "chrome/browser/android/activity_type_ids.h" |
41 #endif | 43 #endif |
42 | 44 |
43 class ChromeBrowserMetricsServiceObserver; | 45 class ChromeBrowserMetricsServiceObserver; |
44 class MetricsReportingScheduler; | 46 class MetricsReportingScheduler; |
45 class PrefService; | 47 class PrefService; |
46 class PrefRegistrySimple; | 48 class PrefRegistrySimple; |
47 class Profile; | 49 class Profile; |
48 class TemplateURLService; | 50 class TemplateURLService; |
49 | 51 |
50 namespace { | 52 namespace { |
51 class CrashesDOMHandler; | 53 class CrashesDOMHandler; |
52 class FlashDOMHandler; | 54 class FlashDOMHandler; |
53 } | 55 } |
54 | 56 |
55 namespace base { | 57 namespace base { |
56 class DictionaryValue; | 58 class DictionaryValue; |
| 59 class HistogramSamples; |
57 class MessageLoopProxy; | 60 class MessageLoopProxy; |
58 } | 61 } |
59 | 62 |
60 namespace variations { | 63 namespace variations { |
61 struct ActiveGroupId; | 64 struct ActiveGroupId; |
62 } | 65 } |
63 | 66 |
64 namespace content { | 67 namespace content { |
65 class RenderProcessHost; | 68 class RenderProcessHost; |
66 class WebContents; | 69 class WebContents; |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
108 friend class MetricsService; | 111 friend class MetricsService; |
109 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, RegisterSyntheticTrial); | 112 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, RegisterSyntheticTrial); |
110 | 113 |
111 // This constructor is private specifically so as to control which code is | 114 // This constructor is private specifically so as to control which code is |
112 // able to access it. New code that wishes to use it should be added as a | 115 // able to access it. New code that wishes to use it should be added as a |
113 // friend class. | 116 // friend class. |
114 SyntheticTrialGroup(uint32 trial, uint32 group); | 117 SyntheticTrialGroup(uint32 trial, uint32 group); |
115 }; | 118 }; |
116 | 119 |
117 class MetricsService | 120 class MetricsService |
118 : public chrome_browser_metrics::TrackingSynchronizerObserver, | 121 : public base::HistogramFlattener, |
| 122 public chrome_browser_metrics::TrackingSynchronizerObserver, |
119 public content::BrowserChildProcessObserver, | 123 public content::BrowserChildProcessObserver, |
120 public content::NotificationObserver, | 124 public content::NotificationObserver, |
121 public net::URLFetcherDelegate, | 125 public net::URLFetcherDelegate { |
122 public MetricsServiceBase { | |
123 public: | 126 public: |
124 // The execution phase of the browser. | 127 // The execution phase of the browser. |
125 enum ExecutionPhase { | 128 enum ExecutionPhase { |
126 UNINITIALIZED_PHASE = 0, | 129 UNINITIALIZED_PHASE = 0, |
127 START_METRICS_RECORDING = 100, | 130 START_METRICS_RECORDING = 100, |
128 CREATE_PROFILE = 200, | 131 CREATE_PROFILE = 200, |
129 STARTUP_TIMEBOMB_ARM = 300, | 132 STARTUP_TIMEBOMB_ARM = 300, |
130 THREAD_WATCHER_START = 400, | 133 THREAD_WATCHER_START = 400, |
131 MAIN_MESSAGE_LOOP_RUN = 500, | 134 MAIN_MESSAGE_LOOP_RUN = 500, |
132 SHUTDOWN_TIMEBOMB_ARM = 600, | 135 SHUTDOWN_TIMEBOMB_ARM = 600, |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
191 #if defined(OS_ANDROID) | 194 #if defined(OS_ANDROID) |
192 static void RegisterPrefsAndroid(PrefRegistrySimple* registry); | 195 static void RegisterPrefsAndroid(PrefRegistrySimple* registry); |
193 #endif // defined(OS_ANDROID) | 196 #endif // defined(OS_ANDROID) |
194 | 197 |
195 // Set up notifications which indicate that a user is performing work. This is | 198 // Set up notifications which indicate that a user is performing work. This is |
196 // useful to allow some features to sleep, until the machine becomes active, | 199 // useful to allow some features to sleep, until the machine becomes active, |
197 // such as precluding UMA uploads unless there was recent activity. | 200 // such as precluding UMA uploads unless there was recent activity. |
198 static void SetUpNotifications(content::NotificationRegistrar* registrar, | 201 static void SetUpNotifications(content::NotificationRegistrar* registrar, |
199 content::NotificationObserver* observer); | 202 content::NotificationObserver* observer); |
200 | 203 |
| 204 // HistogramFlattener: |
| 205 virtual void RecordDelta(const base::HistogramBase& histogram, |
| 206 const base::HistogramSamples& snapshot) OVERRIDE; |
| 207 virtual void InconsistencyDetected( |
| 208 base::HistogramBase::Inconsistency problem) OVERRIDE; |
| 209 virtual void UniqueInconsistencyDetected( |
| 210 base::HistogramBase::Inconsistency problem) OVERRIDE; |
| 211 virtual void InconsistencyDetectedInLoggedCount(int amount) OVERRIDE; |
| 212 |
201 // Implementation of content::BrowserChildProcessObserver | 213 // Implementation of content::BrowserChildProcessObserver |
202 virtual void BrowserChildProcessHostConnected( | 214 virtual void BrowserChildProcessHostConnected( |
203 const content::ChildProcessData& data) OVERRIDE; | 215 const content::ChildProcessData& data) OVERRIDE; |
204 virtual void BrowserChildProcessCrashed( | 216 virtual void BrowserChildProcessCrashed( |
205 const content::ChildProcessData& data) OVERRIDE; | 217 const content::ChildProcessData& data) OVERRIDE; |
206 virtual void BrowserChildProcessInstanceCreated( | 218 virtual void BrowserChildProcessInstanceCreated( |
207 const content::ChildProcessData& data) OVERRIDE; | 219 const content::ChildProcessData& data) OVERRIDE; |
208 | 220 |
209 // Implementation of content::NotificationObserver | 221 // content::NotificationObserver: |
210 virtual void Observe(int type, | 222 virtual void Observe(int type, |
211 const content::NotificationSource& source, | 223 const content::NotificationSource& source, |
212 const content::NotificationDetails& details) OVERRIDE; | 224 const content::NotificationDetails& details) OVERRIDE; |
213 | 225 |
214 // Invoked when we get a WM_SESSIONEND. This places a value in prefs that is | 226 // Invoked when we get a WM_SESSIONEND. This places a value in prefs that is |
215 // reset when RecordCompletedSessionEnd is invoked. | 227 // reset when RecordCompletedSessionEnd is invoked. |
216 void RecordStartOfSessionEnd(); | 228 void RecordStartOfSessionEnd(); |
217 | 229 |
218 // This should be called when the application is shutting down. It records | 230 // This should be called when the application is shutting down. It records |
219 // that session end was successful. | 231 // that session end was successful. |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
285 // Register the specified |provider| to provide additional metrics into the | 297 // Register the specified |provider| to provide additional metrics into the |
286 // UMA log. Should be called during MetricsService initialization only. | 298 // UMA log. Should be called during MetricsService initialization only. |
287 void RegisterMetricsProvider(scoped_ptr<metrics::MetricsProvider> provider); | 299 void RegisterMetricsProvider(scoped_ptr<metrics::MetricsProvider> provider); |
288 | 300 |
289 // Check if this install was cloned or imaged from another machine. If a | 301 // Check if this install was cloned or imaged from another machine. If a |
290 // clone is detected, reset the client id and low entropy source. This | 302 // clone is detected, reset the client id and low entropy source. This |
291 // should not be called more than once. | 303 // should not be called more than once. |
292 void CheckForClonedInstall( | 304 void CheckForClonedInstall( |
293 scoped_refptr<base::SingleThreadTaskRunner> task_runner); | 305 scoped_refptr<base::SingleThreadTaskRunner> task_runner); |
294 | 306 |
| 307 protected: |
| 308 // Exposed for testing. |
| 309 metrics::MetricsLogManager* log_manager() { return &log_manager_; } |
| 310 |
295 private: | 311 private: |
296 // The MetricsService has a lifecycle that is stored as a state. | 312 // The MetricsService has a lifecycle that is stored as a state. |
297 // See metrics_service.cc for description of this lifecycle. | 313 // See metrics_service.cc for description of this lifecycle. |
298 enum State { | 314 enum State { |
299 INITIALIZED, // Constructor was called. | 315 INITIALIZED, // Constructor was called. |
300 INIT_TASK_SCHEDULED, // Waiting for deferred init tasks to | 316 INIT_TASK_SCHEDULED, // Waiting for deferred init tasks to |
301 // complete. | 317 // complete. |
302 INIT_TASK_DONE, // Waiting for timer to send initial log. | 318 INIT_TASK_DONE, // Waiting for timer to send initial log. |
303 SENDING_INITIAL_STABILITY_LOG, // Initial stability log being sent. | 319 SENDING_INITIAL_STABILITY_LOG, // Initial stability log being sent. |
304 SENDING_INITIAL_METRICS_LOG, // Initial metrics log being sent. | 320 SENDING_INITIAL_METRICS_LOG, // Initial metrics log being sent. |
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
481 | 497 |
482 // Returns true if process of type |type| should be counted as a plugin | 498 // Returns true if process of type |type| should be counted as a plugin |
483 // process, and false otherwise. | 499 // process, and false otherwise. |
484 static bool IsPluginProcess(int process_type); | 500 static bool IsPluginProcess(int process_type); |
485 | 501 |
486 // Returns a list of synthetic field trials that were active for the entire | 502 // Returns a list of synthetic field trials that were active for the entire |
487 // duration of the current log. | 503 // duration of the current log. |
488 void GetCurrentSyntheticFieldTrials( | 504 void GetCurrentSyntheticFieldTrials( |
489 std::vector<variations::ActiveGroupId>* synthetic_trials); | 505 std::vector<variations::ActiveGroupId>* synthetic_trials); |
490 | 506 |
| 507 // Record complete list of histograms into the current log. |
| 508 // Called when we close a log. |
| 509 void RecordCurrentHistograms(); |
| 510 |
| 511 // Record complete list of stability histograms into the current log, |
| 512 // i.e., histograms with the |kUmaStabilityHistogramFlag| flag set. |
| 513 void RecordCurrentStabilityHistograms(); |
| 514 |
| 515 // Manager for the various in-flight logs. |
| 516 metrics::MetricsLogManager log_manager_; |
| 517 |
| 518 // |histogram_snapshot_manager_| prepares histogram deltas for transmission. |
| 519 base::HistogramSnapshotManager histogram_snapshot_manager_; |
| 520 |
491 // Used to manage various metrics reporting state prefs, such as client id, | 521 // Used to manage various metrics reporting state prefs, such as client id, |
492 // low entropy source and whether metrics reporting is enabled. Weak pointer. | 522 // low entropy source and whether metrics reporting is enabled. Weak pointer. |
493 metrics::MetricsStateManager* const state_manager_; | 523 metrics::MetricsStateManager* const state_manager_; |
494 | 524 |
495 // Used to interact with the embedder. Weak pointer; must outlive |this| | 525 // Used to interact with the embedder. Weak pointer; must outlive |this| |
496 // instance. | 526 // instance. |
497 metrics::MetricsServiceClient* const client_; | 527 metrics::MetricsServiceClient* const client_; |
498 | 528 |
499 // Registered metrics providers. | 529 // Registered metrics providers. |
500 ScopedVector<metrics::MetricsProvider> metrics_providers_; | 530 ScopedVector<metrics::MetricsProvider> metrics_providers_; |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
647 | 677 |
648 // Registers/unregisters |observer| to receive MetricsLog notifications | 678 // Registers/unregisters |observer| to receive MetricsLog notifications |
649 // from metrics service. | 679 // from metrics service. |
650 static void AddMetricsServiceObserver(MetricsServiceObserver* observer); | 680 static void AddMetricsServiceObserver(MetricsServiceObserver* observer); |
651 static void RemoveMetricsServiceObserver(MetricsServiceObserver* observer); | 681 static void RemoveMetricsServiceObserver(MetricsServiceObserver* observer); |
652 | 682 |
653 DISALLOW_IMPLICIT_CONSTRUCTORS(MetricsServiceHelper); | 683 DISALLOW_IMPLICIT_CONSTRUCTORS(MetricsServiceHelper); |
654 }; | 684 }; |
655 | 685 |
656 #endif // CHROME_BROWSER_METRICS_METRICS_SERVICE_H_ | 686 #endif // CHROME_BROWSER_METRICS_METRICS_SERVICE_H_ |
OLD | NEW |