[email protected] | c3cac95 | 2014-05-09 01:51:18 | [diff] [blame] | 1 | // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef CHROME_BROWSER_METRICS_METRICS_SERVICES_MANAGER_H_ |
| 6 | #define CHROME_BROWSER_METRICS_METRICS_SERVICES_MANAGER_H_ |
| 7 | |
| 8 | #include "base/basictypes.h" |
| 9 | #include "base/memory/scoped_ptr.h" |
holte | 873fb7c9 | 2015-02-19 23:41:26 | [diff] [blame^] | 10 | #include "base/prefs/pref_change_registrar.h" |
[email protected] | c3cac95 | 2014-05-09 01:51:18 | [diff] [blame] | 11 | #include "base/threading/thread_checker.h" |
holte | ce6a45c | 2015-02-14 01:41:45 | [diff] [blame] | 12 | #include "components/rappor/rappor_service.h" |
[email protected] | c3cac95 | 2014-05-09 01:51:18 | [diff] [blame] | 13 | |
[email protected] | 037642f | 2014-05-29 20:40:50 | [diff] [blame] | 14 | class ChromeMetricsServiceClient; |
[email protected] | c3cac95 | 2014-05-09 01:51:18 | [diff] [blame] | 15 | class PrefService; |
| 16 | |
[email protected] | 544246e | 2014-06-06 11:22:28 | [diff] [blame] | 17 | namespace base { |
| 18 | class FilePath; |
| 19 | } |
| 20 | |
[email protected] | c3cac95 | 2014-05-09 01:51:18 | [diff] [blame] | 21 | namespace metrics { |
asvitkine | cbd42073 | 2014-08-26 22:15:40 | [diff] [blame] | 22 | class MetricsService; |
[email protected] | c3cac95 | 2014-05-09 01:51:18 | [diff] [blame] | 23 | class MetricsStateManager; |
| 24 | } |
| 25 | |
| 26 | namespace rappor { |
| 27 | class RapporService; |
| 28 | } |
| 29 | |
| 30 | namespace chrome_variations { |
| 31 | class VariationsService; |
| 32 | } |
| 33 | |
| 34 | // MetricsServicesManager is a helper class that has ownership over the various |
[email protected] | 037642f | 2014-05-29 20:40:50 | [diff] [blame] | 35 | // metrics-related services in Chrome: MetricsService (via its client), |
| 36 | // RapporService and VariationsService. |
[email protected] | c3cac95 | 2014-05-09 01:51:18 | [diff] [blame] | 37 | class MetricsServicesManager { |
| 38 | public: |
| 39 | // Creates the MetricsServicesManager with the |local_state| prefs service. |
| 40 | explicit MetricsServicesManager(PrefService* local_state); |
| 41 | virtual ~MetricsServicesManager(); |
| 42 | |
[email protected] | 4a55a71 | 2014-06-08 16:50:34 | [diff] [blame] | 43 | // Returns the MetricsService, creating it if it hasn't been created yet (and |
| 44 | // additionally creating the ChromeMetricsServiceClient in that case). |
asvitkine | cbd42073 | 2014-08-26 22:15:40 | [diff] [blame] | 45 | metrics::MetricsService* GetMetricsService(); |
[email protected] | c3cac95 | 2014-05-09 01:51:18 | [diff] [blame] | 46 | |
| 47 | // Returns the GetRapporService, creating it if it hasn't been created yet. |
| 48 | rappor::RapporService* GetRapporService(); |
| 49 | |
| 50 | // Returns the VariationsService, creating it if it hasn't been created yet. |
| 51 | chrome_variations::VariationsService* GetVariationsService(); |
| 52 | |
[email protected] | 544246e | 2014-06-06 11:22:28 | [diff] [blame] | 53 | // Should be called when a plugin loading error occurs. |
| 54 | void OnPluginLoadingError(const base::FilePath& plugin_path); |
| 55 | |
holte | 5a7ed7c | 2015-01-09 23:52:46 | [diff] [blame] | 56 | // Update the managed services when permissions for recording/uploading |
| 57 | // metrics change. |
| 58 | void UpdatePermissions(bool may_record, bool may_upload); |
| 59 | |
anthonyvd | 40dd030 | 2015-02-19 16:11:34 | [diff] [blame] | 60 | // Update the managed services when permissions for uploading metrics change. |
| 61 | void UpdateUploadPermissions(bool may_upload); |
holte | 5a7ed7c | 2015-01-09 23:52:46 | [diff] [blame] | 62 | |
holte | ce6a45c | 2015-02-14 01:41:45 | [diff] [blame] | 63 | // Returns true iff Rappor reporting is enabled. |
| 64 | bool IsRapporEnabled(bool metrics_enabled) const; |
| 65 | |
| 66 | // Returns the recording level for Rappor metrics. |
| 67 | rappor::RecordingLevel GetRapporRecordingLevel(bool metrics_enabled) const; |
| 68 | |
[email protected] | c3cac95 | 2014-05-09 01:51:18 | [diff] [blame] | 69 | private: |
holte | 873fb7c9 | 2015-02-19 23:41:26 | [diff] [blame^] | 70 | // Update the managed services when permissions for recording/uploading |
| 71 | // metrics change. |
| 72 | void UpdateRapporService(); |
| 73 | |
[email protected] | 4a55a71 | 2014-06-08 16:50:34 | [diff] [blame] | 74 | // Returns the ChromeMetricsServiceClient, creating it if it hasn't been |
| 75 | // created yet (and additionally creating the MetricsService in that case). |
| 76 | ChromeMetricsServiceClient* GetChromeMetricsServiceClient(); |
| 77 | |
[email protected] | c3cac95 | 2014-05-09 01:51:18 | [diff] [blame] | 78 | metrics::MetricsStateManager* GetMetricsStateManager(); |
| 79 | |
[email protected] | c3cac95 | 2014-05-09 01:51:18 | [diff] [blame] | 80 | // Ensures that all functions are called from the same thread. |
| 81 | base::ThreadChecker thread_checker_; |
| 82 | |
| 83 | // Weak pointer to the local state prefs store. |
| 84 | PrefService* local_state_; |
| 85 | |
holte | 873fb7c9 | 2015-02-19 23:41:26 | [diff] [blame^] | 86 | // A change registrar for local_state_; |
| 87 | PrefChangeRegistrar pref_change_registrar_; |
| 88 | |
| 89 | // The current metrics reporting setting. |
| 90 | bool may_upload_; |
| 91 | |
| 92 | // The current metrics recording setting. |
| 93 | bool may_record_; |
| 94 | |
[email protected] | c3cac95 | 2014-05-09 01:51:18 | [diff] [blame] | 95 | // MetricsStateManager which is passed as a parameter to service constructors. |
| 96 | scoped_ptr<metrics::MetricsStateManager> metrics_state_manager_; |
| 97 | |
[email protected] | 037642f | 2014-05-29 20:40:50 | [diff] [blame] | 98 | // Chrome embedder implementation of the MetricsServiceClient. Owns the |
| 99 | // MetricsService. |
| 100 | scoped_ptr<ChromeMetricsServiceClient> metrics_service_client_; |
[email protected] | c3cac95 | 2014-05-09 01:51:18 | [diff] [blame] | 101 | |
| 102 | // The RapporService, for RAPPOR metric uploads. |
| 103 | scoped_ptr<rappor::RapporService> rappor_service_; |
| 104 | |
| 105 | // The VariationsService, for server-side experiments infrastructure. |
| 106 | scoped_ptr<chrome_variations::VariationsService> variations_service_; |
| 107 | |
| 108 | DISALLOW_COPY_AND_ASSIGN(MetricsServicesManager); |
| 109 | }; |
| 110 | |
| 111 | #endif // CHROME_BROWSER_METRICS_METRICS_SERVICES_MANAGER_H_ |