Commit 873fb7c9 authored by holte's avatar holte Committed by Commit bot

Propogate RAPPOR permission changes

BUG=

Review URL: https://codereview.chromium.org/937013002

Cr-Commit-Position: refs/heads/master@{#317172}
parent e3f99439
...@@ -58,8 +58,14 @@ void PostStoreMetricsClientInfo(const metrics::ClientInfo& client_info) { ...@@ -58,8 +58,14 @@ void PostStoreMetricsClientInfo(const metrics::ClientInfo& client_info) {
} // namespace } // namespace
MetricsServicesManager::MetricsServicesManager(PrefService* local_state) MetricsServicesManager::MetricsServicesManager(PrefService* local_state)
: local_state_(local_state) { : local_state_(local_state),
may_upload_(false),
may_record_(false) {
DCHECK(local_state); DCHECK(local_state);
pref_change_registrar_.Init(local_state);
pref_change_registrar_.Add(rappor::prefs::kRapporEnabled,
base::Bind(&MetricsServicesManager::UpdateRapporService,
base::Unretained(this)));
} }
MetricsServicesManager::~MetricsServicesManager() { MetricsServicesManager::~MetricsServicesManager() {
...@@ -144,8 +150,19 @@ rappor::RecordingLevel MetricsServicesManager::GetRapporRecordingLevel( ...@@ -144,8 +150,19 @@ rappor::RecordingLevel MetricsServicesManager::GetRapporRecordingLevel(
return recording_level; return recording_level;
} }
void MetricsServicesManager::UpdateRapporService() {
GetRapporService()->Update(GetRapporRecordingLevel(may_record_), may_upload_);
}
void MetricsServicesManager::UpdatePermissions(bool may_record, void MetricsServicesManager::UpdatePermissions(bool may_record,
bool may_upload) { bool may_upload) {
// Stash the current permissions so that we can update the RapporService
// correctly when the Rappor preference changes. The metrics recording
// preference partially determines the initial rappor setting, and also
// controls whether FINE metrics are sent.
may_record_ = may_record;
may_upload_ = may_upload;
metrics::MetricsService* metrics = GetMetricsService(); metrics::MetricsService* metrics = GetMetricsService();
const base::CommandLine* cmdline = base::CommandLine::ForCurrentProcess(); const base::CommandLine* cmdline = base::CommandLine::ForCurrentProcess();
...@@ -172,7 +189,7 @@ void MetricsServicesManager::UpdatePermissions(bool may_record, ...@@ -172,7 +189,7 @@ void MetricsServicesManager::UpdatePermissions(bool may_record,
metrics->Stop(); metrics->Stop();
} }
GetRapporService()->Update(GetRapporRecordingLevel(may_record), may_upload); UpdateRapporService();
} }
void MetricsServicesManager::UpdateUploadPermissions(bool may_upload) { void MetricsServicesManager::UpdateUploadPermissions(bool may_upload) {
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include "base/basictypes.h" #include "base/basictypes.h"
#include "base/memory/scoped_ptr.h" #include "base/memory/scoped_ptr.h"
#include "base/prefs/pref_change_registrar.h"
#include "base/threading/thread_checker.h" #include "base/threading/thread_checker.h"
#include "components/rappor/rappor_service.h" #include "components/rappor/rappor_service.h"
...@@ -66,6 +67,10 @@ class MetricsServicesManager { ...@@ -66,6 +67,10 @@ class MetricsServicesManager {
rappor::RecordingLevel GetRapporRecordingLevel(bool metrics_enabled) const; rappor::RecordingLevel GetRapporRecordingLevel(bool metrics_enabled) const;
private: private:
// Update the managed services when permissions for recording/uploading
// metrics change.
void UpdateRapporService();
// Returns the ChromeMetricsServiceClient, creating it if it hasn't been // Returns the ChromeMetricsServiceClient, creating it if it hasn't been
// created yet (and additionally creating the MetricsService in that case). // created yet (and additionally creating the MetricsService in that case).
ChromeMetricsServiceClient* GetChromeMetricsServiceClient(); ChromeMetricsServiceClient* GetChromeMetricsServiceClient();
...@@ -78,6 +83,15 @@ class MetricsServicesManager { ...@@ -78,6 +83,15 @@ class MetricsServicesManager {
// Weak pointer to the local state prefs store. // Weak pointer to the local state prefs store.
PrefService* local_state_; PrefService* local_state_;
// A change registrar for local_state_;
PrefChangeRegistrar pref_change_registrar_;
// The current metrics reporting setting.
bool may_upload_;
// The current metrics recording setting.
bool may_record_;
// MetricsStateManager which is passed as a parameter to service constructors. // MetricsStateManager which is passed as a parameter to service constructors.
scoped_ptr<metrics::MetricsStateManager> metrics_state_manager_; scoped_ptr<metrics::MetricsStateManager> metrics_state_manager_;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment