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/weak_ptr.h" | 18 #include "base/memory/weak_ptr.h" |
19 #include "base/metrics/field_trial.h" | 19 #include "base/metrics/field_trial.h" |
20 #include "base/metrics/user_metrics.h" | 20 #include "base/metrics/user_metrics.h" |
21 #include "base/observer_list.h" | |
21 #include "base/process/kill.h" | 22 #include "base/process/kill.h" |
22 #include "base/time/time.h" | 23 #include "base/time/time.h" |
23 #include "chrome/browser/metrics/metrics_log.h" | 24 #include "chrome/browser/metrics/metrics_log.h" |
24 #include "chrome/browser/metrics/tracking_synchronizer_observer.h" | 25 #include "chrome/browser/metrics/tracking_synchronizer_observer.h" |
25 #include "chrome/common/metrics/metrics_service_base.h" | 26 #include "chrome/common/metrics/metrics_service_base.h" |
26 #include "chrome/installer/util/google_update_settings.h" | 27 #include "chrome/installer/util/google_update_settings.h" |
27 #include "content/public/browser/browser_child_process_observer.h" | 28 #include "content/public/browser/browser_child_process_observer.h" |
28 #include "content/public/browser/notification_observer.h" | 29 #include "content/public/browser/notification_observer.h" |
29 #include "content/public/browser/notification_registrar.h" | 30 #include "content/public/browser/notification_registrar.h" |
30 #include "content/public/browser/user_metrics.h" | 31 #include "content/public/browser/user_metrics.h" |
31 #include "net/url_request/url_fetcher_delegate.h" | 32 #include "net/url_request/url_fetcher_delegate.h" |
32 | 33 |
33 #if defined(OS_ANDROID) | 34 #if defined(OS_ANDROID) |
34 #include "chrome/browser/android/activity_type_ids.h" | 35 #include "chrome/browser/android/activity_type_ids.h" |
35 #elif defined(OS_CHROMEOS) | 36 #elif defined(OS_CHROMEOS) |
36 #include "chrome/browser/chromeos/external_metrics.h" | 37 #include "chrome/browser/chromeos/external_metrics.h" |
37 #endif | 38 #endif |
38 | 39 |
40 class ChromeBrowserMetricsLogObserver; | |
39 class MetricsReportingScheduler; | 41 class MetricsReportingScheduler; |
40 class PrefService; | 42 class PrefService; |
41 class PrefRegistrySimple; | 43 class PrefRegistrySimple; |
42 class Profile; | 44 class Profile; |
43 class TemplateURLService; | 45 class TemplateURLService; |
44 | 46 |
45 namespace { | 47 namespace { |
46 class CrashesDOMHandler; | 48 class CrashesDOMHandler; |
47 class FlashDOMHandler; | 49 class FlashDOMHandler; |
48 } | 50 } |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
101 private: | 103 private: |
102 friend class MetricsService; | 104 friend class MetricsService; |
103 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, RegisterSyntheticTrial); | 105 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, RegisterSyntheticTrial); |
104 | 106 |
105 // This constructor is private specifically so as to control which code is | 107 // This constructor is private specifically so as to control which code is |
106 // able to access it. New code that wishes to use it should be added as a | 108 // able to access it. New code that wishes to use it should be added as a |
107 // friend class. | 109 // friend class. |
108 SyntheticTrialGroup(uint32 trial, uint32 group); | 110 SyntheticTrialGroup(uint32 trial, uint32 group); |
109 }; | 111 }; |
110 | 112 |
113 class MetricsLogObserver { | |
Ilya Sherman
2014/05/07 01:03:16
nit: I think "MetricsServiceObserver" is more accu
bolian
2014/05/07 02:20:26
Done.
| |
114 public: | |
115 // Will be called when a new MetricsLog is created. | |
116 virtual void OnNewMetricsLog() = 0; | |
Ilya Sherman
2014/05/07 01:03:16
nit: "OnDidCreateMetricsLog()" or something else i
bolian
2014/05/07 02:20:26
Done.
| |
117 | |
118 protected: | |
119 MetricsLogObserver() {} | |
120 virtual ~MetricsLogObserver() {} | |
121 | |
122 private: | |
123 DISALLOW_COPY_AND_ASSIGN(MetricsLogObserver); | |
124 }; | |
125 | |
111 class MetricsService | 126 class MetricsService |
112 : public chrome_browser_metrics::TrackingSynchronizerObserver, | 127 : public chrome_browser_metrics::TrackingSynchronizerObserver, |
113 public content::BrowserChildProcessObserver, | 128 public content::BrowserChildProcessObserver, |
114 public content::NotificationObserver, | 129 public content::NotificationObserver, |
115 public net::URLFetcherDelegate, | 130 public net::URLFetcherDelegate, |
116 public MetricsServiceBase { | 131 public MetricsServiceBase { |
117 public: | 132 public: |
118 // The execution phase of the browser. | 133 // The execution phase of the browser. |
119 enum ExecutionPhase { | 134 enum ExecutionPhase { |
120 UNINITIALIZED_PHASE = 0, | 135 UNINITIALIZED_PHASE = 0, |
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
354 | 369 |
355 // If in_idle is true, sets idle_since_last_transmission to true. | 370 // If in_idle is true, sets idle_since_last_transmission to true. |
356 // If in_idle is false and idle_since_last_transmission_ is true, sets | 371 // If in_idle is false and idle_since_last_transmission_ is true, sets |
357 // idle_since_last_transmission to false and starts the timer (provided | 372 // idle_since_last_transmission to false and starts the timer (provided |
358 // starting the timer is permitted). | 373 // starting the timer is permitted). |
359 void HandleIdleSinceLastTransmission(bool in_idle); | 374 void HandleIdleSinceLastTransmission(bool in_idle); |
360 | 375 |
361 // Set up client ID, session ID, etc. | 376 // Set up client ID, session ID, etc. |
362 void InitializeMetricsState(); | 377 void InitializeMetricsState(); |
363 | 378 |
379 // Registers/Unregsiters |observer| to receive MetricsLog notifications. | |
Ilya Sherman
2014/05/07 01:03:16
nit: "Un" -> "un"
bolian
2014/05/07 02:20:26
Done.
| |
380 void AddMetricsLogObserver(MetricsLogObserver* observer); | |
381 void RemoveMetricsLogObserver(MetricsLogObserver* observer); | |
382 void NotifyOnNewMetricsLog(); | |
383 | |
364 // Schedule the next save of LocalState information. This is called | 384 // Schedule the next save of LocalState information. This is called |
365 // automatically by the task that performs each save to schedule the next one. | 385 // automatically by the task that performs each save to schedule the next one. |
366 void ScheduleNextStateSave(); | 386 void ScheduleNextStateSave(); |
367 | 387 |
368 // Save the LocalState information immediately. This should not be called by | 388 // Save the LocalState information immediately. This should not be called by |
369 // anybody other than the scheduler to avoid doing too many writes. When you | 389 // anybody other than the scheduler to avoid doing too many writes. When you |
370 // make a change, call ScheduleNextStateSave() instead. | 390 // make a change, call ScheduleNextStateSave() instead. |
371 void SaveLocalState(); | 391 void SaveLocalState(); |
372 | 392 |
373 // Opens a new log for recording user experience metrics. | 393 // Opens a new log for recording user experience metrics. |
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
575 // Execution phase the browser is in. | 595 // Execution phase the browser is in. |
576 static ExecutionPhase execution_phase_; | 596 static ExecutionPhase execution_phase_; |
577 | 597 |
578 // Reduntant marker to check that we completed our shutdown, and set the | 598 // Reduntant marker to check that we completed our shutdown, and set the |
579 // exited-cleanly bit in the prefs. | 599 // exited-cleanly bit in the prefs. |
580 static ShutdownCleanliness clean_shutdown_status_; | 600 static ShutdownCleanliness clean_shutdown_status_; |
581 | 601 |
582 // Field trial groups that map to Chrome configuration states. | 602 // Field trial groups that map to Chrome configuration states. |
583 SyntheticTrialGroups synthetic_trial_groups_; | 603 SyntheticTrialGroups synthetic_trial_groups_; |
584 | 604 |
605 // Observers of MetricsLog. | |
606 ObserverList<MetricsLogObserver> metrics_log_observers_; | |
607 | |
608 friend class MetricsServiceHelper; | |
609 | |
585 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, IsPluginProcess); | 610 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, IsPluginProcess); |
586 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, | 611 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, |
587 PermutedEntropyCacheClearedWhenLowEntropyReset); | 612 PermutedEntropyCacheClearedWhenLowEntropyReset); |
588 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, RegisterSyntheticTrial); | 613 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, RegisterSyntheticTrial); |
614 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, MetricsLogObserver); | |
589 | 615 |
590 DISALLOW_COPY_AND_ASSIGN(MetricsService); | 616 DISALLOW_COPY_AND_ASSIGN(MetricsService); |
591 }; | 617 }; |
592 | 618 |
593 // This class limits and documents access to the IsMetricsReportingEnabled() and | 619 // This class limits and documents access to metrics service helper methods. |
594 // IsCrashReportingEnabled() methods. Since these methods are private, each user | 620 // Since these methods are private, each user has to be explicitly declared |
595 // has to be explicitly declared as a 'friend' below. | 621 // as a 'friend' below. |
596 class MetricsServiceHelper { | 622 class MetricsServiceHelper { |
597 private: | 623 private: |
598 friend bool prerender::IsOmniboxEnabled(Profile* profile); | 624 friend bool prerender::IsOmniboxEnabled(Profile* profile); |
599 friend class ChromeRenderMessageFilter; | 625 friend class ChromeRenderMessageFilter; |
626 friend class ::ChromeBrowserMetricsLogObserver; | |
Ilya Sherman
2014/05/07 01:03:16
nit: Alphabetically, this should come before line
bolian
2014/05/07 02:20:26
Done.
| |
600 friend class ::CrashesDOMHandler; | 627 friend class ::CrashesDOMHandler; |
601 friend class extensions::ExtensionDownloader; | 628 friend class extensions::ExtensionDownloader; |
602 friend class extensions::ManifestFetchData; | 629 friend class extensions::ManifestFetchData; |
603 friend class extensions::MetricsPrivateGetIsCrashReportingEnabledFunction; | 630 friend class extensions::MetricsPrivateGetIsCrashReportingEnabledFunction; |
604 friend class ::FlashDOMHandler; | 631 friend class ::FlashDOMHandler; |
605 friend class system_logs::ChromeInternalLogSource; | 632 friend class system_logs::ChromeInternalLogSource; |
606 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, MetricsReportingEnabled); | 633 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, MetricsReportingEnabled); |
607 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, CrashReportingEnabled); | 634 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, CrashReportingEnabled); |
608 | 635 |
609 // Returns true if prefs::kMetricsReportingEnabled is set. | 636 // Returns true if prefs::kMetricsReportingEnabled is set. |
610 // TODO(asvitkine): Consolidate the method in MetricsStateManager. | 637 // TODO(asvitkine): Consolidate the method in MetricsStateManager. |
611 // TODO(asvitkine): This function does not report the correct value on | 638 // TODO(asvitkine): This function does not report the correct value on |
612 // Android and ChromeOS, see http://crbug.com/362192. | 639 // Android and ChromeOS, see http://crbug.com/362192. |
613 static bool IsMetricsReportingEnabled(); | 640 static bool IsMetricsReportingEnabled(); |
614 | 641 |
615 // 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 |
616 // level for Android and ChromeOS, and otherwise is the same as | 643 // level for Android and ChromeOS, and otherwise is the same as |
617 // IsMetricsReportingEnabled for desktop Chrome. | 644 // IsMetricsReportingEnabled for desktop Chrome. |
618 static bool IsCrashReportingEnabled(); | 645 static bool IsCrashReportingEnabled(); |
619 | 646 |
647 // Registers/Unregsiters |observer| to receive MetricsLog notifications | |
648 // from metric service. | |
649 static void AddMetricsLogObserver(MetricsLogObserver* observer); | |
650 static void RemoveMetricsLogObserver(MetricsLogObserver* observer); | |
651 | |
620 DISALLOW_IMPLICIT_CONSTRUCTORS(MetricsServiceHelper); | 652 DISALLOW_IMPLICIT_CONSTRUCTORS(MetricsServiceHelper); |
621 }; | 653 }; |
622 | 654 |
623 #endif // CHROME_BROWSER_METRICS_METRICS_SERVICE_H_ | 655 #endif // CHROME_BROWSER_METRICS_METRICS_SERVICE_H_ |
OLD | NEW |