[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 | |||||
blundell | 6eb91b7b | 2015-10-23 07:04:43 | [diff] [blame^] | 57 | // Some embedders use this method to notify the metrics system when a |
58 | // renderer process exits unexpectedly. | ||||
59 | void OnRendererProcessCrash(); | ||||
60 | |||||
holte | 5a7ed7c | 2015-01-09 23:52:46 | [diff] [blame] | 61 | // Update the managed services when permissions for recording/uploading |
62 | // metrics change. | ||||
63 | void UpdatePermissions(bool may_record, bool may_upload); | ||||
64 | |||||
anthonyvd | 40dd030 | 2015-02-19 16:11:34 | [diff] [blame] | 65 | // Update the managed services when permissions for uploading metrics change. |
66 | void UpdateUploadPermissions(bool may_upload); | ||||
holte | 5a7ed7c | 2015-01-09 23:52:46 | [diff] [blame] | 67 | |
[email protected] | c3cac95 | 2014-05-09 01:51:18 | [diff] [blame] | 68 | private: |
holte | 873fb7c9 | 2015-02-19 23:41:26 | [diff] [blame] | 69 | // Update the managed services when permissions for recording/uploading |
70 | // metrics change. | ||||
71 | void UpdateRapporService(); | ||||
72 | |||||
blundell | fecea528d | 2015-10-21 10:10:22 | [diff] [blame] | 73 | // Returns the MetricsServiceClient, creating it if it hasn't been |
[email protected] | 4a55a71 | 2014-06-08 16:50:34 | [diff] [blame] | 74 | // created yet (and additionally creating the MetricsService in that case). |
blundell | fecea528d | 2015-10-21 10:10:22 | [diff] [blame] | 75 | metrics::MetricsServiceClient* GetMetricsServiceClient(); |
[email protected] | 4a55a71 | 2014-06-08 16:50:34 | [diff] [blame] | 76 | |
[email protected] | c3cac95 | 2014-05-09 01:51:18 | [diff] [blame] | 77 | metrics::MetricsStateManager* GetMetricsStateManager(); |
78 | |||||
holte | 585f466 | 2015-06-18 19:13:52 | [diff] [blame] | 79 | // Update which services are running to match current permissions. |
80 | void UpdateRunningServices(); | ||||
81 | |||||
blundell | fecea528d | 2015-10-21 10:10:22 | [diff] [blame] | 82 | // The client passed in from the embedder. |
83 | scoped_ptr<MetricsServicesManagerClient> client_; | ||||
84 | |||||
[email protected] | c3cac95 | 2014-05-09 01:51:18 | [diff] [blame] | 85 | // Ensures that all functions are called from the same thread. |
86 | base::ThreadChecker thread_checker_; | ||||
87 | |||||
holte | 873fb7c9 | 2015-02-19 23:41:26 | [diff] [blame] | 88 | // The current metrics reporting setting. |
89 | bool may_upload_; | ||||
90 | |||||
91 | // The current metrics recording setting. | ||||
92 | bool may_record_; | ||||
93 | |||||
blundell | fecea528d | 2015-10-21 10:10:22 | [diff] [blame] | 94 | // The MetricsServiceClient. Owns the MetricsService. |
95 | scoped_ptr<metrics::MetricsServiceClient> metrics_service_client_; | ||||
[email protected] | c3cac95 | 2014-05-09 01:51:18 | [diff] [blame] | 96 | |
97 | // The RapporService, for RAPPOR metric uploads. | ||||
98 | scoped_ptr<rappor::RapporService> rappor_service_; | ||||
99 | |||||
100 | // The VariationsService, for server-side experiments infrastructure. | ||||
blundell | 57bcfed | 2015-09-04 08:44:45 | [diff] [blame] | 101 | scoped_ptr<variations::VariationsService> variations_service_; |
[email protected] | c3cac95 | 2014-05-09 01:51:18 | [diff] [blame] | 102 | |
103 | DISALLOW_COPY_AND_ASSIGN(MetricsServicesManager); | ||||
104 | }; | ||||
105 | |||||
blundell | 695d61f | 2015-10-21 11:25:53 | [diff] [blame] | 106 | } // namespace metrics_services_manager |
107 | |||||
108 | #endif // COMPONENTS_METRICS_SERVICES_MANAGER_METRICS_SERVICES_MANAGER_H_ |