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