Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(401)

Side by Side Diff: chrome/browser/metrics/metrics_service.h

Issue 253203002: Log operator code histogram on new metric log (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@api_move
Patch Set: . Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 {
114 public:
115 // Will be called when a new MetricsLog is created.
116 virtual void OnNewMetricsLog() = 0;
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 274 matching lines...) Expand 10 before | Expand all | Expand 10 after
395 // idle_since_last_transmission to false and starts the timer (provided 410 // idle_since_last_transmission to false and starts the timer (provided
396 // starting the timer is permitted). 411 // starting the timer is permitted).
397 void HandleIdleSinceLastTransmission(bool in_idle); 412 void HandleIdleSinceLastTransmission(bool in_idle);
398 413
399 // Set up client ID, session ID, etc. 414 // Set up client ID, session ID, etc.
400 void InitializeMetricsState(ReportingState reporting_state); 415 void InitializeMetricsState(ReportingState reporting_state);
401 416
402 // Generates a new client ID to use to identify self to metrics server. 417 // Generates a new client ID to use to identify self to metrics server.
403 static std::string GenerateClientID(); 418 static std::string GenerateClientID();
404 419
420 // Registers/Unregsiters |observer| to receive MetricsLog notifications.
421 void AddMetricsLogObserver(MetricsLogObserver* observer);
422 void RemoveMetricsLogObserver(MetricsLogObserver* observer);
423 void NotifyOnNewMetricsLog();
424
405 // Schedule the next save of LocalState information. This is called 425 // Schedule the next save of LocalState information. This is called
406 // automatically by the task that performs each save to schedule the next one. 426 // automatically by the task that performs each save to schedule the next one.
407 void ScheduleNextStateSave(); 427 void ScheduleNextStateSave();
408 428
409 // Save the LocalState information immediately. This should not be called by 429 // Save the LocalState information immediately. This should not be called by
410 // anybody other than the scheduler to avoid doing too many writes. When you 430 // anybody other than the scheduler to avoid doing too many writes. When you
411 // make a change, call ScheduleNextStateSave() instead. 431 // make a change, call ScheduleNextStateSave() instead.
412 void SaveLocalState(); 432 void SaveLocalState();
413 433
414 // Opens a new log for recording user experience metrics. 434 // Opens a new log for recording user experience metrics.
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after
621 // Execution phase the browser is in. 641 // Execution phase the browser is in.
622 static ExecutionPhase execution_phase_; 642 static ExecutionPhase execution_phase_;
623 643
624 // Reduntant marker to check that we completed our shutdown, and set the 644 // Reduntant marker to check that we completed our shutdown, and set the
625 // exited-cleanly bit in the prefs. 645 // exited-cleanly bit in the prefs.
626 static ShutdownCleanliness clean_shutdown_status_; 646 static ShutdownCleanliness clean_shutdown_status_;
627 647
628 // Field trial groups that map to Chrome configuration states. 648 // Field trial groups that map to Chrome configuration states.
629 SyntheticTrialGroups synthetic_trial_groups_; 649 SyntheticTrialGroups synthetic_trial_groups_;
630 650
651 // Observers of MetricsLog.
652 ObserverList<MetricsLogObserver> metrics_log_observers_;
653
631 scoped_ptr<metrics::ClonedInstallDetector> cloned_install_detector_; 654 scoped_ptr<metrics::ClonedInstallDetector> cloned_install_detector_;
632 655
656 friend class MetricsServiceHelper;
657
633 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, ClientIdCorrectlyFormatted); 658 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, ClientIdCorrectlyFormatted);
634 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, IsPluginProcess); 659 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, IsPluginProcess);
635 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, LowEntropySource0NotReset); 660 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, LowEntropySource0NotReset);
636 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, 661 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest,
637 PermutedEntropyCacheClearedWhenLowEntropyReset); 662 PermutedEntropyCacheClearedWhenLowEntropyReset);
638 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, RegisterSyntheticTrial); 663 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, RegisterSyntheticTrial);
639 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, ResetMetricsIDs); 664 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, ResetMetricsIDs);
640 FRIEND_TEST_ALL_PREFIXES(MetricsServiceBrowserTest, 665 FRIEND_TEST_ALL_PREFIXES(MetricsServiceBrowserTest,
641 CheckLowEntropySourceUsed); 666 CheckLowEntropySourceUsed);
642 FRIEND_TEST_ALL_PREFIXES(MetricsServiceReportingTest, 667 FRIEND_TEST_ALL_PREFIXES(MetricsServiceReportingTest,
643 CheckHighEntropySourceUsed); 668 CheckHighEntropySourceUsed);
644 669
645 DISALLOW_COPY_AND_ASSIGN(MetricsService); 670 DISALLOW_COPY_AND_ASSIGN(MetricsService);
646 }; 671 };
647 672
648 // This class limits and documents access to the IsMetricsReportingEnabled() and 673 // This class limits and documents access to metrics service helper methods.
649 // IsCrashReportingEnabled() methods. Since these methods are private, each user 674 // Since these methods are private, each user has to be explicitly declared
650 // has to be explicitly declared as a 'friend' below. 675 // as a 'friend' below.
651 class MetricsServiceHelper { 676 class MetricsServiceHelper {
652 private: 677 private:
653 friend bool prerender::IsOmniboxEnabled(Profile* profile); 678 friend bool prerender::IsOmniboxEnabled(Profile* profile);
654 friend class ChromeRenderMessageFilter; 679 friend class ChromeRenderMessageFilter;
680 friend class ::ChromeBrowserMetricsLogObserver;
655 friend class ::CrashesDOMHandler; 681 friend class ::CrashesDOMHandler;
656 friend class extensions::ExtensionDownloader; 682 friend class extensions::ExtensionDownloader;
657 friend class extensions::ManifestFetchData; 683 friend class extensions::ManifestFetchData;
658 friend class extensions::MetricsPrivateGetIsCrashReportingEnabledFunction; 684 friend class extensions::MetricsPrivateGetIsCrashReportingEnabledFunction;
659 friend class ::FlashDOMHandler; 685 friend class ::FlashDOMHandler;
660 friend class system_logs::ChromeInternalLogSource; 686 friend class system_logs::ChromeInternalLogSource;
661 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, MetricsReportingEnabled); 687 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, MetricsReportingEnabled);
662 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, CrashReportingEnabled); 688 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, CrashReportingEnabled);
663 689
664 // Returns true if prefs::kMetricsReportingEnabled is set. 690 // Returns true if prefs::kMetricsReportingEnabled is set.
665 static bool IsMetricsReportingEnabled(); 691 static bool IsMetricsReportingEnabled();
666 692
667 // Returns true if crash reporting is enabled. This is set at the platform 693 // Returns true if crash reporting is enabled. This is set at the platform
668 // level for Android and ChromeOS, and otherwise is the same as 694 // level for Android and ChromeOS, and otherwise is the same as
669 // IsMetricsReportingEnabled for desktop Chrome. 695 // IsMetricsReportingEnabled for desktop Chrome.
670 static bool IsCrashReportingEnabled(); 696 static bool IsCrashReportingEnabled();
671 697
698 // Registers/Unregsiters |observer| to receive MetricsLog notifications
699 // from metric service.
700 static void AddMetricsLogObserver(MetricsLogObserver* observer);
701 static void RemoveMetricsLogObserver(MetricsLogObserver* observer);
702
672 DISALLOW_IMPLICIT_CONSTRUCTORS(MetricsServiceHelper); 703 DISALLOW_IMPLICIT_CONSTRUCTORS(MetricsServiceHelper);
673 }; 704 };
674 705
675 #endif // CHROME_BROWSER_METRICS_METRICS_SERVICE_H_ 706 #endif // CHROME_BROWSER_METRICS_METRICS_SERVICE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698