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" |
| 23 #include "base/threading/thread_checker.h" |
22 #include "base/time/time.h" | 24 #include "base/time/time.h" |
23 #include "chrome/browser/metrics/metrics_log.h" | 25 #include "chrome/browser/metrics/metrics_log.h" |
| 26 #include "chrome/browser/metrics/metrics_service_observer.h" |
24 #include "chrome/browser/metrics/tracking_synchronizer_observer.h" | 27 #include "chrome/browser/metrics/tracking_synchronizer_observer.h" |
25 #include "chrome/common/metrics/metrics_service_base.h" | 28 #include "chrome/common/metrics/metrics_service_base.h" |
26 #include "chrome/installer/util/google_update_settings.h" | 29 #include "chrome/installer/util/google_update_settings.h" |
27 #include "content/public/browser/browser_child_process_observer.h" | 30 #include "content/public/browser/browser_child_process_observer.h" |
28 #include "content/public/browser/notification_observer.h" | 31 #include "content/public/browser/notification_observer.h" |
29 #include "content/public/browser/notification_registrar.h" | 32 #include "content/public/browser/notification_registrar.h" |
30 #include "content/public/browser/user_metrics.h" | 33 #include "content/public/browser/user_metrics.h" |
31 #include "net/url_request/url_fetcher_delegate.h" | 34 #include "net/url_request/url_fetcher_delegate.h" |
32 | 35 |
33 #if defined(OS_ANDROID) | 36 #if defined(OS_ANDROID) |
34 #include "chrome/browser/android/activity_type_ids.h" | 37 #include "chrome/browser/android/activity_type_ids.h" |
35 #elif defined(OS_CHROMEOS) | 38 #elif defined(OS_CHROMEOS) |
36 #include "chrome/browser/chromeos/external_metrics.h" | 39 #include "chrome/browser/chromeos/external_metrics.h" |
37 #endif | 40 #endif |
38 | 41 |
| 42 class ChromeBrowserMetricsServiceObserver; |
39 class MetricsReportingScheduler; | 43 class MetricsReportingScheduler; |
40 class PrefService; | 44 class PrefService; |
41 class PrefRegistrySimple; | 45 class PrefRegistrySimple; |
42 class Profile; | 46 class Profile; |
43 class TemplateURLService; | 47 class TemplateURLService; |
44 | 48 |
45 namespace { | 49 namespace { |
46 class CrashesDOMHandler; | 50 class CrashesDOMHandler; |
47 class FlashDOMHandler; | 51 class FlashDOMHandler; |
48 } | 52 } |
(...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
354 | 358 |
355 // If in_idle is true, sets idle_since_last_transmission to true. | 359 // 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 | 360 // 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 | 361 // idle_since_last_transmission to false and starts the timer (provided |
358 // starting the timer is permitted). | 362 // starting the timer is permitted). |
359 void HandleIdleSinceLastTransmission(bool in_idle); | 363 void HandleIdleSinceLastTransmission(bool in_idle); |
360 | 364 |
361 // Set up client ID, session ID, etc. | 365 // Set up client ID, session ID, etc. |
362 void InitializeMetricsState(); | 366 void InitializeMetricsState(); |
363 | 367 |
| 368 // Registers/unregisters |observer| to receive MetricsLog notifications. |
| 369 void AddObserver(MetricsServiceObserver* observer); |
| 370 void RemoveObserver(MetricsServiceObserver* observer); |
| 371 void NotifyOnDidCreateMetricsLog(); |
| 372 |
364 // Schedule the next save of LocalState information. This is called | 373 // Schedule the next save of LocalState information. This is called |
365 // automatically by the task that performs each save to schedule the next one. | 374 // automatically by the task that performs each save to schedule the next one. |
366 void ScheduleNextStateSave(); | 375 void ScheduleNextStateSave(); |
367 | 376 |
368 // Save the LocalState information immediately. This should not be called by | 377 // 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 | 378 // anybody other than the scheduler to avoid doing too many writes. When you |
370 // make a change, call ScheduleNextStateSave() instead. | 379 // make a change, call ScheduleNextStateSave() instead. |
371 void SaveLocalState(); | 380 void SaveLocalState(); |
372 | 381 |
373 // Opens a new log for recording user experience metrics. | 382 // 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. | 584 // Execution phase the browser is in. |
576 static ExecutionPhase execution_phase_; | 585 static ExecutionPhase execution_phase_; |
577 | 586 |
578 // Reduntant marker to check that we completed our shutdown, and set the | 587 // Reduntant marker to check that we completed our shutdown, and set the |
579 // exited-cleanly bit in the prefs. | 588 // exited-cleanly bit in the prefs. |
580 static ShutdownCleanliness clean_shutdown_status_; | 589 static ShutdownCleanliness clean_shutdown_status_; |
581 | 590 |
582 // Field trial groups that map to Chrome configuration states. | 591 // Field trial groups that map to Chrome configuration states. |
583 SyntheticTrialGroups synthetic_trial_groups_; | 592 SyntheticTrialGroups synthetic_trial_groups_; |
584 | 593 |
| 594 ObserverList<MetricsServiceObserver> observers_; |
| 595 |
| 596 // Confirms single-threaded access to |observers_| in debug builds. |
| 597 base::ThreadChecker thread_checker_; |
| 598 |
| 599 friend class MetricsServiceHelper; |
| 600 |
585 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, IsPluginProcess); | 601 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, IsPluginProcess); |
| 602 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, MetricsServiceObserver); |
586 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, | 603 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, |
587 PermutedEntropyCacheClearedWhenLowEntropyReset); | 604 PermutedEntropyCacheClearedWhenLowEntropyReset); |
588 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, RegisterSyntheticTrial); | 605 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, RegisterSyntheticTrial); |
589 | 606 |
590 DISALLOW_COPY_AND_ASSIGN(MetricsService); | 607 DISALLOW_COPY_AND_ASSIGN(MetricsService); |
591 }; | 608 }; |
592 | 609 |
593 // This class limits and documents access to the IsMetricsReportingEnabled() and | 610 // This class limits and documents access to metrics service helper methods. |
594 // IsCrashReportingEnabled() methods. Since these methods are private, each user | 611 // Since these methods are private, each user has to be explicitly declared |
595 // has to be explicitly declared as a 'friend' below. | 612 // as a 'friend' below. |
596 class MetricsServiceHelper { | 613 class MetricsServiceHelper { |
597 private: | 614 private: |
598 friend bool prerender::IsOmniboxEnabled(Profile* profile); | 615 friend bool prerender::IsOmniboxEnabled(Profile* profile); |
| 616 friend class ::ChromeBrowserMetricsServiceObserver; |
599 friend class ChromeRenderMessageFilter; | 617 friend class ChromeRenderMessageFilter; |
600 friend class ::CrashesDOMHandler; | 618 friend class ::CrashesDOMHandler; |
601 friend class extensions::ExtensionDownloader; | 619 friend class extensions::ExtensionDownloader; |
602 friend class extensions::ManifestFetchData; | 620 friend class extensions::ManifestFetchData; |
603 friend class extensions::MetricsPrivateGetIsCrashReportingEnabledFunction; | 621 friend class extensions::MetricsPrivateGetIsCrashReportingEnabledFunction; |
604 friend class ::FlashDOMHandler; | 622 friend class ::FlashDOMHandler; |
605 friend class system_logs::ChromeInternalLogSource; | 623 friend class system_logs::ChromeInternalLogSource; |
606 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, MetricsReportingEnabled); | 624 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, MetricsReportingEnabled); |
607 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, CrashReportingEnabled); | 625 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, CrashReportingEnabled); |
608 | 626 |
609 // Returns true if prefs::kMetricsReportingEnabled is set. | 627 // Returns true if prefs::kMetricsReportingEnabled is set. |
610 // TODO(asvitkine): Consolidate the method in MetricsStateManager. | 628 // TODO(asvitkine): Consolidate the method in MetricsStateManager. |
611 // TODO(asvitkine): This function does not report the correct value on | 629 // TODO(asvitkine): This function does not report the correct value on |
612 // Android and ChromeOS, see http://crbug.com/362192. | 630 // Android and ChromeOS, see http://crbug.com/362192. |
613 static bool IsMetricsReportingEnabled(); | 631 static bool IsMetricsReportingEnabled(); |
614 | 632 |
615 // Returns true if crash reporting is enabled. This is set at the platform | 633 // 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 | 634 // level for Android and ChromeOS, and otherwise is the same as |
617 // IsMetricsReportingEnabled for desktop Chrome. | 635 // IsMetricsReportingEnabled for desktop Chrome. |
618 static bool IsCrashReportingEnabled(); | 636 static bool IsCrashReportingEnabled(); |
619 | 637 |
| 638 // Registers/unregisters |observer| to receive MetricsLog notifications |
| 639 // from metrics service. |
| 640 static void AddMetricsServiceObserver(MetricsServiceObserver* observer); |
| 641 static void RemoveMetricsServiceObserver(MetricsServiceObserver* observer); |
| 642 |
620 DISALLOW_IMPLICIT_CONSTRUCTORS(MetricsServiceHelper); | 643 DISALLOW_IMPLICIT_CONSTRUCTORS(MetricsServiceHelper); |
621 }; | 644 }; |
622 | 645 |
623 #endif // CHROME_BROWSER_METRICS_METRICS_SERVICE_H_ | 646 #endif // CHROME_BROWSER_METRICS_METRICS_SERVICE_H_ |
OLD | NEW |