Fire an error if a pref used in the UI is missing once all prefs are fetched.
[chromium-blink-merge.git] / chrome / browser / metrics / metrics_services_manager.h
blob72ec3f797ff4d0a6f11961349a13bcf7f42806d5
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/prefs/pref_change_registrar.h"
11 #include "base/threading/thread_checker.h"
12 #include "components/rappor/rappor_service.h"
14 class ChromeMetricsServiceClient;
15 class PrefService;
17 namespace base {
18 class FilePath;
21 namespace metrics {
22 class MetricsService;
23 class MetricsStateManager;
26 namespace rappor {
27 class RapporService;
30 namespace chrome_variations {
31 class VariationsService;
34 // MetricsServicesManager is a helper class that has ownership over the various
35 // metrics-related services in Chrome: MetricsService (via its client),
36 // RapporService and VariationsService.
37 class MetricsServicesManager {
38 public:
39 // Creates the MetricsServicesManager with the |local_state| prefs service.
40 explicit MetricsServicesManager(PrefService* local_state);
41 virtual ~MetricsServicesManager();
43 // Returns the MetricsService, creating it if it hasn't been created yet (and
44 // additionally creating the ChromeMetricsServiceClient in that case).
45 metrics::MetricsService* GetMetricsService();
47 // Returns the GetRapporService, creating it if it hasn't been created yet.
48 rappor::RapporService* GetRapporService();
50 // Returns the VariationsService, creating it if it hasn't been created yet.
51 chrome_variations::VariationsService* GetVariationsService();
53 // Should be called when a plugin loading error occurs.
54 void OnPluginLoadingError(const base::FilePath& plugin_path);
56 // Update the managed services when permissions for recording/uploading
57 // metrics change.
58 void UpdatePermissions(bool may_record, bool may_upload);
60 // Update the managed services when permissions for uploading metrics change.
61 void UpdateUploadPermissions(bool may_upload);
63 // Returns true iff Rappor reporting is enabled.
64 bool IsRapporEnabled(bool metrics_enabled) const;
66 // Returns the recording level for Rappor metrics.
67 rappor::RecordingLevel GetRapporRecordingLevel(bool metrics_enabled) const;
69 private:
70 // Update the managed services when permissions for recording/uploading
71 // metrics change.
72 void UpdateRapporService();
74 // Returns the ChromeMetricsServiceClient, creating it if it hasn't been
75 // created yet (and additionally creating the MetricsService in that case).
76 ChromeMetricsServiceClient* GetChromeMetricsServiceClient();
78 metrics::MetricsStateManager* GetMetricsStateManager();
80 // Ensures that all functions are called from the same thread.
81 base::ThreadChecker thread_checker_;
83 // Weak pointer to the local state prefs store.
84 PrefService* local_state_;
86 // A change registrar for local_state_;
87 PrefChangeRegistrar pref_change_registrar_;
89 // The current metrics reporting setting.
90 bool may_upload_;
92 // The current metrics recording setting.
93 bool may_record_;
95 // MetricsStateManager which is passed as a parameter to service constructors.
96 scoped_ptr<metrics::MetricsStateManager> metrics_state_manager_;
98 // Chrome embedder implementation of the MetricsServiceClient. Owns the
99 // MetricsService.
100 scoped_ptr<ChromeMetricsServiceClient> metrics_service_client_;
102 // The RapporService, for RAPPOR metric uploads.
103 scoped_ptr<rappor::RapporService> rappor_service_;
105 // The VariationsService, for server-side experiments infrastructure.
106 scoped_ptr<chrome_variations::VariationsService> variations_service_;
108 DISALLOW_COPY_AND_ASSIGN(MetricsServicesManager);
111 #endif // CHROME_BROWSER_METRICS_METRICS_SERVICES_MANAGER_H_