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