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.
5 #ifndef CHROME_BROWSER_METRICS_METRICS_SERVICES_MANAGER_H_
6 #define CHROME_BROWSER_METRICS_METRICS_SERVICES_MANAGER_H_
8 #include "base/basictypes.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "base/threading/thread_checker.h"
11 #include "chrome/browser/safe_browsing/safe_browsing_service.h"
13 class ChromeMetricsServiceClient
;
22 class MetricsStateManager
;
29 namespace chrome_variations
{
30 class VariationsService
;
33 // MetricsServicesManager is a helper class that has ownership over the various
34 // metrics-related services in Chrome: MetricsService (via its client),
35 // RapporService and VariationsService.
36 class MetricsServicesManager
{
38 // Creates the MetricsServicesManager with the |local_state| prefs service.
39 explicit MetricsServicesManager(PrefService
* local_state
);
40 virtual ~MetricsServicesManager();
42 // Returns the MetricsService, creating it if it hasn't been created yet (and
43 // additionally creating the ChromeMetricsServiceClient in that case).
44 metrics::MetricsService
* GetMetricsService();
46 // Returns the GetRapporService, creating it if it hasn't been created yet.
47 rappor::RapporService
* GetRapporService();
49 // Returns the VariationsService, creating it if it hasn't been created yet.
50 chrome_variations::VariationsService
* GetVariationsService();
52 // Should be called when a plugin loading error occurs.
53 void OnPluginLoadingError(const base::FilePath
& plugin_path
);
55 // Update the managed services when permissions for recording/uploading
57 void UpdatePermissions(bool may_record
, bool may_upload
);
59 // Update the managed services when permissions for uploading metrics change.
60 void UpdateUploadPermissions(bool may_upload
);
63 // Update the managed services when permissions for recording/uploading
65 void UpdateRapporService();
67 // Returns the ChromeMetricsServiceClient, creating it if it hasn't been
68 // created yet (and additionally creating the MetricsService in that case).
69 ChromeMetricsServiceClient
* GetChromeMetricsServiceClient();
71 metrics::MetricsStateManager
* GetMetricsStateManager();
73 // Retrieve the latest SafeBrowsing preferences state.
74 bool GetSafeBrowsingState();
76 // Update which services are running to match current permissions.
77 void UpdateRunningServices();
79 // Ensures that all functions are called from the same thread.
80 base::ThreadChecker thread_checker_
;
82 // Weak pointer to the local state prefs store.
83 PrefService
* local_state_
;
85 // Subscription to SafeBrowsing service state changes.
86 scoped_ptr
<SafeBrowsingService::StateSubscription
> sb_state_subscription_
;
88 // The current metrics reporting setting.
91 // The current metrics recording setting.
94 // MetricsStateManager which is passed as a parameter to service constructors.
95 scoped_ptr
<metrics::MetricsStateManager
> metrics_state_manager_
;
97 // Chrome embedder implementation of the MetricsServiceClient. Owns the
99 scoped_ptr
<ChromeMetricsServiceClient
> metrics_service_client_
;
101 // The RapporService, for RAPPOR metric uploads.
102 scoped_ptr
<rappor::RapporService
> rappor_service_
;
104 // The VariationsService, for server-side experiments infrastructure.
105 scoped_ptr
<chrome_variations::VariationsService
> variations_service_
;
107 DISALLOW_COPY_AND_ASSIGN(MetricsServicesManager
);
110 #endif // CHROME_BROWSER_METRICS_METRICS_SERVICES_MANAGER_H_