| 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" |
| 11 | 12 |
| 12 class MetricsServicesManagerClient; | 13 class ChromeMetricsServiceClient; |
| 14 class PrefService; |
| 13 | 15 |
| 14 namespace base { | 16 namespace base { |
| 15 class FilePath; | 17 class FilePath; |
| 16 } | 18 } |
| 17 | 19 |
| 18 namespace metrics { | 20 namespace metrics { |
| 19 class MetricsService; | 21 class MetricsService; |
| 20 class MetricsServiceClient; | |
| 21 class MetricsStateManager; | 22 class MetricsStateManager; |
| 22 } | 23 } |
| 23 | 24 |
| 24 namespace rappor { | 25 namespace rappor { |
| 25 class RapporService; | 26 class RapporService; |
| 26 } | 27 } |
| 27 | 28 |
| 28 namespace variations { | 29 namespace variations { |
| 29 class VariationsService; | 30 class VariationsService; |
| 30 } | 31 } |
| 31 | 32 |
| 32 // MetricsServicesManager is a helper class for embedders that use the various | 33 // MetricsServicesManager is a helper class that has ownership over the various |
| 33 // metrics-related services in a Chrome-like fashion: MetricsService (via its | 34 // metrics-related services in Chrome: MetricsService (via its client), |
| 34 // client), RapporService and VariationsService. | 35 // RapporService and VariationsService. |
| 35 class MetricsServicesManager { | 36 class MetricsServicesManager { |
| 36 public: | 37 public: |
| 37 // Creates the MetricsServicesManager with the given client. | 38 // Creates the MetricsServicesManager with the |local_state| prefs service. |
| 38 explicit MetricsServicesManager( | 39 explicit MetricsServicesManager(PrefService* local_state); |
| 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 MetricsServiceClient in that case). | 43 // additionally creating the ChromeMetricsServiceClient in that case). |
| 44 metrics::MetricsService* GetMetricsService(); | 44 metrics::MetricsService* GetMetricsService(); |
| 45 | 45 |
| 46 // Returns the RapporService, creating it if it hasn't been created yet. | 46 // Returns the GetRapporService, 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 MetricsServiceClient, creating it if it hasn't been | 67 // Returns the ChromeMetricsServiceClient, 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 metrics::MetricsServiceClient* GetMetricsServiceClient(); | 69 ChromeMetricsServiceClient* GetChromeMetricsServiceClient(); |
| 70 | 70 |
| 71 metrics::MetricsStateManager* GetMetricsStateManager(); | 71 metrics::MetricsStateManager* GetMetricsStateManager(); |
| 72 | 72 |
| 73 // Retrieve the latest SafeBrowsing preferences state. |
| 74 bool GetSafeBrowsingState(); |
| 75 |
| 73 // Update which services are running to match current permissions. | 76 // Update which services are running to match current permissions. |
| 74 void UpdateRunningServices(); | 77 void UpdateRunningServices(); |
| 75 | 78 |
| 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 |
| 82 // The current metrics reporting setting. | 88 // The current metrics reporting setting. |
| 83 bool may_upload_; | 89 bool may_upload_; |
| 84 | 90 |
| 85 // The current metrics recording setting. | 91 // The current metrics recording setting. |
| 86 bool may_record_; | 92 bool may_record_; |
| 87 | 93 |
| 88 // The MetricsServiceClient. Owns the MetricsService. | 94 // MetricsStateManager which is passed as a parameter to service constructors. |
| 89 scoped_ptr<metrics::MetricsServiceClient> metrics_service_client_; | 95 scoped_ptr<metrics::MetricsStateManager> metrics_state_manager_; |
| 96 |
| 97 // Chrome embedder implementation of the MetricsServiceClient. Owns the |
| 98 // MetricsService. |
| 99 scoped_ptr<ChromeMetricsServiceClient> metrics_service_client_; |
| 90 | 100 |
| 91 // The RapporService, for RAPPOR metric uploads. | 101 // The RapporService, for RAPPOR metric uploads. |
| 92 scoped_ptr<rappor::RapporService> rappor_service_; | 102 scoped_ptr<rappor::RapporService> rappor_service_; |
| 93 | 103 |
| 94 // The VariationsService, for server-side experiments infrastructure. | 104 // The VariationsService, for server-side experiments infrastructure. |
| 95 scoped_ptr<variations::VariationsService> variations_service_; | 105 scoped_ptr<variations::VariationsService> variations_service_; |
| 96 | 106 |
| 97 DISALLOW_COPY_AND_ASSIGN(MetricsServicesManager); | 107 DISALLOW_COPY_AND_ASSIGN(MetricsServicesManager); |
| 98 }; | 108 }; |
| 99 | 109 |
| 100 #endif // CHROME_BROWSER_METRICS_METRICS_SERVICES_MANAGER_H_ | 110 #endif // CHROME_BROWSER_METRICS_METRICS_SERVICES_MANAGER_H_ |
| OLD | NEW |