Only grant permissions to new extensions from sync if they have the expected version
[chromium-blink-merge.git] / chrome / browser / metrics / metrics_services_manager.h
blobe3e5b4dce2df66767de3d8863535a4f7f4e73bd7
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;
14 class PrefService;
16 namespace base {
17 class FilePath;
20 namespace metrics {
21 class MetricsService;
22 class MetricsStateManager;
25 namespace rappor {
26 class RapporService;
29 namespace 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 {
37 public:
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 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
56 // metrics change.
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);
62 private:
63 // Update the managed services when permissions for recording/uploading
64 // metrics change.
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.
89 bool may_upload_;
91 // The current metrics recording setting.
92 bool may_record_;
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
98 // MetricsService.
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<variations::VariationsService> variations_service_;
107 DISALLOW_COPY_AND_ASSIGN(MetricsServicesManager);
110 #endif // CHROME_BROWSER_METRICS_METRICS_SERVICES_MANAGER_H_