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
;
23 class MetricsStateManager
;
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
{
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
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;
70 // Update the managed services when permissions for recording/uploading
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.
92 // The current metrics recording setting.
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
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_