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 308 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
357 | 361 |
358 // If in_idle is true, sets idle_since_last_transmission to true. | 362 // If in_idle is true, sets idle_since_last_transmission to true. |
359 // If in_idle is false and idle_since_last_transmission_ is true, sets | 363 // If in_idle is false and idle_since_last_transmission_ is true, sets |
360 // idle_since_last_transmission to false and starts the timer (provided | 364 // idle_since_last_transmission to false and starts the timer (provided |
361 // starting the timer is permitted). | 365 // starting the timer is permitted). |
362 void HandleIdleSinceLastTransmission(bool in_idle); | 366 void HandleIdleSinceLastTransmission(bool in_idle); |
363 | 367 |
364 // Set up client ID, session ID, etc. | 368 // Set up client ID, session ID, etc. |
365 void InitializeMetricsState(); | 369 void InitializeMetricsState(); |
366 | 370 |
| 371 // Registers/unregisters |observer| to receive MetricsLog notifications. |
| 372 void AddObserver(MetricsServiceObserver* observer); |
| 373 void RemoveObserver(MetricsServiceObserver* observer); |
| 374 void NotifyOnDidCreateMetricsLog(); |
| 375 |
367 // Schedule the next save of LocalState information. This is called | 376 // Schedule the next save of LocalState information. This is called |
368 // automatically by the task that performs each save to schedule the next one. | 377 // automatically by the task that performs each save to schedule the next one. |
369 void ScheduleNextStateSave(); | 378 void ScheduleNextStateSave(); |
370 | 379 |
371 // Save the LocalState information immediately. This should not be called by | 380 // Save the LocalState information immediately. This should not be called by |
372 // anybody other than the scheduler to avoid doing too many writes. When you | 381 // anybody other than the scheduler to avoid doing too many writes. When you |
373 // make a change, call ScheduleNextStateSave() instead. | 382 // make a change, call ScheduleNextStateSave() instead. |
374 void SaveLocalState(); | 383 void SaveLocalState(); |
375 | 384 |
376 // Opens a new log for recording user experience metrics. | 385 // Opens a new log for recording user experience metrics. |
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
578 // Execution phase the browser is in. | 587 // Execution phase the browser is in. |
579 static ExecutionPhase execution_phase_; | 588 static ExecutionPhase execution_phase_; |
580 | 589 |
581 // Reduntant marker to check that we completed our shutdown, and set the | 590 // Reduntant marker to check that we completed our shutdown, and set the |
582 // exited-cleanly bit in the prefs. | 591 // exited-cleanly bit in the prefs. |
583 static ShutdownCleanliness clean_shutdown_status_; | 592 static ShutdownCleanliness clean_shutdown_status_; |
584 | 593 |
585 // Field trial groups that map to Chrome configuration states. | 594 // Field trial groups that map to Chrome configuration states. |
586 SyntheticTrialGroups synthetic_trial_groups_; | 595 SyntheticTrialGroups synthetic_trial_groups_; |
587 | 596 |
| 597 ObserverList<MetricsServiceObserver> observers_; |
| 598 |
| 599 // Confirms single-threaded access to |observers_| in debug builds. |
| 600 base::ThreadChecker thread_checker_; |
| 601 |
| 602 friend class MetricsServiceHelper; |
| 603 |
588 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, IsPluginProcess); | 604 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, IsPluginProcess); |
| 605 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, MetricsServiceObserver); |
589 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, | 606 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, |
590 PermutedEntropyCacheClearedWhenLowEntropyReset); | 607 PermutedEntropyCacheClearedWhenLowEntropyReset); |
591 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, RegisterSyntheticTrial); | 608 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, RegisterSyntheticTrial); |
592 | 609 |
593 DISALLOW_COPY_AND_ASSIGN(MetricsService); | 610 DISALLOW_COPY_AND_ASSIGN(MetricsService); |
594 }; | 611 }; |
595 | 612 |
596 // This class limits and documents access to the IsMetricsReportingEnabled() and | 613 // This class limits and documents access to metrics service helper methods. |
597 // IsCrashReportingEnabled() methods. Since these methods are private, each user | 614 // Since these methods are private, each user has to be explicitly declared |
598 // has to be explicitly declared as a 'friend' below. | 615 // as a 'friend' below. |
599 class MetricsServiceHelper { | 616 class MetricsServiceHelper { |
600 private: | 617 private: |
601 friend bool prerender::IsOmniboxEnabled(Profile* profile); | 618 friend bool prerender::IsOmniboxEnabled(Profile* profile); |
| 619 friend class ::ChromeBrowserMetricsServiceObserver; |
602 friend class ChromeRenderMessageFilter; | 620 friend class ChromeRenderMessageFilter; |
603 friend class ::CrashesDOMHandler; | 621 friend class ::CrashesDOMHandler; |
604 friend class extensions::ExtensionDownloader; | 622 friend class extensions::ExtensionDownloader; |
605 friend class extensions::ManifestFetchData; | 623 friend class extensions::ManifestFetchData; |
606 friend class extensions::MetricsPrivateGetIsCrashReportingEnabledFunction; | 624 friend class extensions::MetricsPrivateGetIsCrashReportingEnabledFunction; |
607 friend class ::FlashDOMHandler; | 625 friend class ::FlashDOMHandler; |
608 friend class system_logs::ChromeInternalLogSource; | 626 friend class system_logs::ChromeInternalLogSource; |
609 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, MetricsReportingEnabled); | 627 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, MetricsReportingEnabled); |
610 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, CrashReportingEnabled); | 628 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, CrashReportingEnabled); |
611 | 629 |
612 // Returns true if prefs::kMetricsReportingEnabled is set. | 630 // Returns true if prefs::kMetricsReportingEnabled is set. |
613 // TODO(asvitkine): Consolidate the method in MetricsStateManager. | 631 // TODO(asvitkine): Consolidate the method in MetricsStateManager. |
614 // TODO(asvitkine): This function does not report the correct value on | 632 // TODO(asvitkine): This function does not report the correct value on |
615 // Android and ChromeOS, see http://crbug.com/362192. | 633 // Android and ChromeOS, see http://crbug.com/362192. |
616 static bool IsMetricsReportingEnabled(); | 634 static bool IsMetricsReportingEnabled(); |
617 | 635 |
618 // Returns true if crash reporting is enabled. This is set at the platform | 636 // Returns true if crash reporting is enabled. This is set at the platform |
619 // level for Android and ChromeOS, and otherwise is the same as | 637 // level for Android and ChromeOS, and otherwise is the same as |
620 // IsMetricsReportingEnabled for desktop Chrome. | 638 // IsMetricsReportingEnabled for desktop Chrome. |
621 static bool IsCrashReportingEnabled(); | 639 static bool IsCrashReportingEnabled(); |
622 | 640 |
| 641 // Registers/unregisters |observer| to receive MetricsLog notifications |
| 642 // from metrics service. |
| 643 static void AddMetricsServiceObserver(MetricsServiceObserver* observer); |
| 644 static void RemoveMetricsServiceObserver(MetricsServiceObserver* observer); |
| 645 |
623 DISALLOW_IMPLICIT_CONSTRUCTORS(MetricsServiceHelper); | 646 DISALLOW_IMPLICIT_CONSTRUCTORS(MetricsServiceHelper); |
624 }; | 647 }; |
625 | 648 |
626 #endif // CHROME_BROWSER_METRICS_METRICS_SERVICE_H_ | 649 #endif // CHROME_BROWSER_METRICS_METRICS_SERVICE_H_ |
OLD | NEW |