[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" | ||||
10 | #include "base/threading/thread_checker.h" | ||||
holte | 585f466 | 2015-06-18 19:13:52 | [diff] [blame] | 11 | #include "chrome/browser/safe_browsing/safe_browsing_service.h" |
[email protected] | c3cac95 | 2014-05-09 01:51:18 | [diff] [blame] | 12 | |
[email protected] | 037642f | 2014-05-29 20:40:50 | [diff] [blame] | 13 | class ChromeMetricsServiceClient; |
[email protected] | c3cac95 | 2014-05-09 01:51:18 | [diff] [blame] | 14 | class PrefService; |
15 | |||||
[email protected] | 544246e | 2014-06-06 11:22:28 | [diff] [blame] | 16 | namespace base { |
17 | class FilePath; | ||||
18 | } | ||||
19 | |||||
[email protected] | c3cac95 | 2014-05-09 01:51:18 | [diff] [blame] | 20 | namespace metrics { |
asvitkine | cbd42073 | 2014-08-26 22:15:40 | [diff] [blame] | 21 | class MetricsService; |
[email protected] | c3cac95 | 2014-05-09 01:51:18 | [diff] [blame] | 22 | class MetricsStateManager; |
23 | } | ||||
24 | |||||
25 | namespace rappor { | ||||
26 | class RapporService; | ||||
27 | } | ||||
28 | |||||
blundell | 57bcfed | 2015-09-04 08:44:45 | [diff] [blame^] | 29 | namespace variations { |
[email protected] | c3cac95 | 2014-05-09 01:51:18 | [diff] [blame] | 30 | class VariationsService; |
31 | } | ||||
32 | |||||
33 | // MetricsServicesManager is a helper class that has ownership over the various | ||||
[email protected] | 037642f | 2014-05-29 20:40:50 | [diff] [blame] | 34 | // metrics-related services in Chrome: MetricsService (via its client), |
35 | // RapporService and VariationsService. | ||||
[email protected] | c3cac95 | 2014-05-09 01:51:18 | [diff] [blame] | 36 | class MetricsServicesManager { |
37 | public: | ||||
38 | // Creates the MetricsServicesManager with the |local_state| prefs service. | ||||
39 | explicit MetricsServicesManager(PrefService* local_state); | ||||
40 | virtual ~MetricsServicesManager(); | ||||
41 | |||||
[email protected] | 4a55a71 | 2014-06-08 16:50:34 | [diff] [blame] | 42 | // Returns the MetricsService, creating it if it hasn't been created yet (and |
43 | // additionally creating the ChromeMetricsServiceClient in that case). | ||||
asvitkine | cbd42073 | 2014-08-26 22:15:40 | [diff] [blame] | 44 | metrics::MetricsService* GetMetricsService(); |
[email protected] | c3cac95 | 2014-05-09 01:51:18 | [diff] [blame] | 45 | |
46 | // Returns the GetRapporService, creating it if it hasn't been created yet. | ||||
47 | rappor::RapporService* GetRapporService(); | ||||
48 | |||||
49 | // Returns the VariationsService, creating it if it hasn't been created yet. | ||||
blundell | 57bcfed | 2015-09-04 08:44:45 | [diff] [blame^] | 50 | variations::VariationsService* GetVariationsService(); |
[email protected] | c3cac95 | 2014-05-09 01:51:18 | [diff] [blame] | 51 | |
[email protected] | 544246e | 2014-06-06 11:22:28 | [diff] [blame] | 52 | // Should be called when a plugin loading error occurs. |
53 | void OnPluginLoadingError(const base::FilePath& plugin_path); | ||||
54 | |||||
holte | 5a7ed7c | 2015-01-09 23:52:46 | [diff] [blame] | 55 | // Update the managed services when permissions for recording/uploading |
56 | // metrics change. | ||||
57 | void UpdatePermissions(bool may_record, bool may_upload); | ||||
58 | |||||
anthonyvd | 40dd030 | 2015-02-19 16:11:34 | [diff] [blame] | 59 | // Update the managed services when permissions for uploading metrics change. |
60 | void UpdateUploadPermissions(bool may_upload); | ||||
holte | 5a7ed7c | 2015-01-09 23:52:46 | [diff] [blame] | 61 | |
[email protected] | c3cac95 | 2014-05-09 01:51:18 | [diff] [blame] | 62 | private: |
holte | 873fb7c9 | 2015-02-19 23:41:26 | [diff] [blame] | 63 | // Update the managed services when permissions for recording/uploading |
64 | // metrics change. | ||||
65 | void UpdateRapporService(); | ||||
66 | |||||
[email protected] | 4a55a71 | 2014-06-08 16:50:34 | [diff] [blame] | 67 | // Returns the ChromeMetricsServiceClient, creating it if it hasn't been |
68 | // created yet (and additionally creating the MetricsService in that case). | ||||
69 | ChromeMetricsServiceClient* GetChromeMetricsServiceClient(); | ||||
70 | |||||
[email protected] | c3cac95 | 2014-05-09 01:51:18 | [diff] [blame] | 71 | metrics::MetricsStateManager* GetMetricsStateManager(); |
72 | |||||
holte | 585f466 | 2015-06-18 19:13:52 | [diff] [blame] | 73 | // Retrieve the latest SafeBrowsing preferences state. |
74 | bool GetSafeBrowsingState(); | ||||
75 | |||||
76 | // Update which services are running to match current permissions. | ||||
77 | void UpdateRunningServices(); | ||||
78 | |||||
[email protected] | c3cac95 | 2014-05-09 01:51:18 | [diff] [blame] | 79 | // Ensures that all functions are called from the same thread. |
80 | base::ThreadChecker thread_checker_; | ||||
81 | |||||
82 | // Weak pointer to the local state prefs store. | ||||
83 | PrefService* local_state_; | ||||
84 | |||||
holte | 585f466 | 2015-06-18 19:13:52 | [diff] [blame] | 85 | // Subscription to SafeBrowsing service state changes. |
86 | scoped_ptr<SafeBrowsingService::StateSubscription> sb_state_subscription_; | ||||
holte | 873fb7c9 | 2015-02-19 23:41:26 | [diff] [blame] | 87 | |
88 | // The current metrics reporting setting. | ||||
89 | bool may_upload_; | ||||
90 | |||||
91 | // The current metrics recording setting. | ||||
92 | bool may_record_; | ||||
93 | |||||
[email protected] | c3cac95 | 2014-05-09 01:51:18 | [diff] [blame] | 94 | // MetricsStateManager which is passed as a parameter to service constructors. |
95 | scoped_ptr<metrics::MetricsStateManager> metrics_state_manager_; | ||||
96 | |||||
[email protected] | 037642f | 2014-05-29 20:40:50 | [diff] [blame] | 97 | // Chrome embedder implementation of the MetricsServiceClient. Owns the |
98 | // MetricsService. | ||||
99 | scoped_ptr<ChromeMetricsServiceClient> metrics_service_client_; | ||||
[email protected] | c3cac95 | 2014-05-09 01:51:18 | [diff] [blame] | 100 | |
101 | // The RapporService, for RAPPOR metric uploads. | ||||
102 | scoped_ptr<rappor::RapporService> rappor_service_; | ||||
103 | |||||
104 | // The VariationsService, for server-side experiments infrastructure. | ||||
blundell | 57bcfed | 2015-09-04 08:44:45 | [diff] [blame^] | 105 | scoped_ptr<variations::VariationsService> variations_service_; |
[email protected] | c3cac95 | 2014-05-09 01:51:18 | [diff] [blame] | 106 | |
107 | DISALLOW_COPY_AND_ASSIGN(MetricsServicesManager); | ||||
108 | }; | ||||
109 | |||||
110 | #endif // CHROME_BROWSER_METRICS_METRICS_SERVICES_MANAGER_H_ |