OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_METRICS_METRICS_SERVICES_MANAGER_H_ | 5 #ifndef CHROME_BROWSER_METRICS_METRICS_SERVICES_MANAGER_H_ |
6 #define CHROME_BROWSER_METRICS_METRICS_SERVICES_MANAGER_H_ | 6 #define CHROME_BROWSER_METRICS_METRICS_SERVICES_MANAGER_H_ |
7 | 7 |
8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/threading/thread_checker.h" | 10 #include "base/threading/thread_checker.h" |
11 #include "chrome/browser/safe_browsing/safe_browsing_service.h" | |
12 | 11 |
13 class ChromeMetricsServiceClient; | 12 class MetricsServicesManagerClient; |
14 class PrefService; | |
15 | 13 |
16 namespace base { | 14 namespace base { |
17 class FilePath; | 15 class FilePath; |
18 } | 16 } |
19 | 17 |
20 namespace metrics { | 18 namespace metrics { |
21 class MetricsService; | 19 class MetricsService; |
| 20 class MetricsServiceClient; |
22 class MetricsStateManager; | 21 class MetricsStateManager; |
23 } | 22 } |
24 | 23 |
25 namespace rappor { | 24 namespace rappor { |
26 class RapporService; | 25 class RapporService; |
27 } | 26 } |
28 | 27 |
29 namespace variations { | 28 namespace variations { |
30 class VariationsService; | 29 class VariationsService; |
31 } | 30 } |
32 | 31 |
33 // MetricsServicesManager is a helper class that has ownership over the various | 32 // MetricsServicesManager is a helper class for embedders that use the various |
34 // metrics-related services in Chrome: MetricsService (via its client), | 33 // metrics-related services in a Chrome-like fashion: MetricsService (via its |
35 // RapporService and VariationsService. | 34 // client), RapporService and VariationsService. |
36 class MetricsServicesManager { | 35 class MetricsServicesManager { |
37 public: | 36 public: |
38 // Creates the MetricsServicesManager with the |local_state| prefs service. | 37 // Creates the MetricsServicesManager with the given client. |
39 explicit MetricsServicesManager(PrefService* local_state); | 38 explicit MetricsServicesManager( |
| 39 scoped_ptr<MetricsServicesManagerClient> client); |
40 virtual ~MetricsServicesManager(); | 40 virtual ~MetricsServicesManager(); |
41 | 41 |
42 // Returns the MetricsService, creating it if it hasn't been created yet (and | 42 // Returns the MetricsService, creating it if it hasn't been created yet (and |
43 // additionally creating the ChromeMetricsServiceClient in that case). | 43 // additionally creating the MetricsServiceClient in that case). |
44 metrics::MetricsService* GetMetricsService(); | 44 metrics::MetricsService* GetMetricsService(); |
45 | 45 |
46 // Returns the GetRapporService, creating it if it hasn't been created yet. | 46 // Returns the RapporService, creating it if it hasn't been created yet. |
47 rappor::RapporService* GetRapporService(); | 47 rappor::RapporService* GetRapporService(); |
48 | 48 |
49 // Returns the VariationsService, creating it if it hasn't been created yet. | 49 // Returns the VariationsService, creating it if it hasn't been created yet. |
50 variations::VariationsService* GetVariationsService(); | 50 variations::VariationsService* GetVariationsService(); |
51 | 51 |
52 // Should be called when a plugin loading error occurs. | 52 // Should be called when a plugin loading error occurs. |
53 void OnPluginLoadingError(const base::FilePath& plugin_path); | 53 void OnPluginLoadingError(const base::FilePath& plugin_path); |
54 | 54 |
55 // Update the managed services when permissions for recording/uploading | 55 // Update the managed services when permissions for recording/uploading |
56 // metrics change. | 56 // metrics change. |
57 void UpdatePermissions(bool may_record, bool may_upload); | 57 void UpdatePermissions(bool may_record, bool may_upload); |
58 | 58 |
59 // Update the managed services when permissions for uploading metrics change. | 59 // Update the managed services when permissions for uploading metrics change. |
60 void UpdateUploadPermissions(bool may_upload); | 60 void UpdateUploadPermissions(bool may_upload); |
61 | 61 |
62 private: | 62 private: |
63 // Update the managed services when permissions for recording/uploading | 63 // Update the managed services when permissions for recording/uploading |
64 // metrics change. | 64 // metrics change. |
65 void UpdateRapporService(); | 65 void UpdateRapporService(); |
66 | 66 |
67 // Returns the ChromeMetricsServiceClient, creating it if it hasn't been | 67 // Returns the MetricsServiceClient, creating it if it hasn't been |
68 // created yet (and additionally creating the MetricsService in that case). | 68 // created yet (and additionally creating the MetricsService in that case). |
69 ChromeMetricsServiceClient* GetChromeMetricsServiceClient(); | 69 metrics::MetricsServiceClient* GetMetricsServiceClient(); |
70 | 70 |
71 metrics::MetricsStateManager* GetMetricsStateManager(); | 71 metrics::MetricsStateManager* GetMetricsStateManager(); |
72 | 72 |
73 // Retrieve the latest SafeBrowsing preferences state. | |
74 bool GetSafeBrowsingState(); | |
75 | |
76 // Update which services are running to match current permissions. | 73 // Update which services are running to match current permissions. |
77 void UpdateRunningServices(); | 74 void UpdateRunningServices(); |
78 | 75 |
| 76 // The client passed in from the embedder. |
| 77 scoped_ptr<MetricsServicesManagerClient> client_; |
| 78 |
79 // Ensures that all functions are called from the same thread. | 79 // Ensures that all functions are called from the same thread. |
80 base::ThreadChecker thread_checker_; | 80 base::ThreadChecker thread_checker_; |
81 | 81 |
82 // Weak pointer to the local state prefs store. | |
83 PrefService* local_state_; | |
84 | |
85 // Subscription to SafeBrowsing service state changes. | |
86 scoped_ptr<SafeBrowsingService::StateSubscription> sb_state_subscription_; | |
87 | |
88 // The current metrics reporting setting. | 82 // The current metrics reporting setting. |
89 bool may_upload_; | 83 bool may_upload_; |
90 | 84 |
91 // The current metrics recording setting. | 85 // The current metrics recording setting. |
92 bool may_record_; | 86 bool may_record_; |
93 | 87 |
94 // MetricsStateManager which is passed as a parameter to service constructors. | 88 // The MetricsServiceClient. Owns the MetricsService. |
95 scoped_ptr<metrics::MetricsStateManager> metrics_state_manager_; | 89 scoped_ptr<metrics::MetricsServiceClient> metrics_service_client_; |
96 | |
97 // Chrome embedder implementation of the MetricsServiceClient. Owns the | |
98 // MetricsService. | |
99 scoped_ptr<ChromeMetricsServiceClient> metrics_service_client_; | |
100 | 90 |
101 // The RapporService, for RAPPOR metric uploads. | 91 // The RapporService, for RAPPOR metric uploads. |
102 scoped_ptr<rappor::RapporService> rappor_service_; | 92 scoped_ptr<rappor::RapporService> rappor_service_; |
103 | 93 |
104 // The VariationsService, for server-side experiments infrastructure. | 94 // The VariationsService, for server-side experiments infrastructure. |
105 scoped_ptr<variations::VariationsService> variations_service_; | 95 scoped_ptr<variations::VariationsService> variations_service_; |
106 | 96 |
107 DISALLOW_COPY_AND_ASSIGN(MetricsServicesManager); | 97 DISALLOW_COPY_AND_ASSIGN(MetricsServicesManager); |
108 }; | 98 }; |
109 | 99 |
110 #endif // CHROME_BROWSER_METRICS_METRICS_SERVICES_MANAGER_H_ | 100 #endif // CHROME_BROWSER_METRICS_METRICS_SERVICES_MANAGER_H_ |
OLD | NEW |