Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2523)

Unified Diff: components/metrics_services_manager/metrics_services_manager.cc

Issue 2653693004: UKM Sync Observer (Closed)
Patch Set: MSVC struct initializer Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « components/metrics_services_manager/metrics_services_manager.h ('k') | components/ukm/BUILD.gn » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/metrics_services_manager/metrics_services_manager.cc
diff --git a/components/metrics_services_manager/metrics_services_manager.cc b/components/metrics_services_manager/metrics_services_manager.cc
index e1ec65096b3e21b946d8fdb24bb489d1c3b6fc71..7b87f884a91557cc8324d8fd549feb9aa10960ed 100644
--- a/components/metrics_services_manager/metrics_services_manager.cc
+++ b/components/metrics_services_manager/metrics_services_manager.cc
@@ -68,27 +68,40 @@ void MetricsServicesManager::OnRendererProcessCrash() {
metrics::MetricsServiceClient*
MetricsServicesManager::GetMetricsServiceClient() {
DCHECK(thread_checker_.CalledOnValidThread());
- if (!metrics_service_client_)
+ if (!metrics_service_client_) {
metrics_service_client_ = client_->CreateMetricsServiceClient();
+ // base::Unretained is safe since |this| owns the metrics_service_client_.
+ metrics_service_client_->SetUpdateRunningServicesCallback(
+ base::Bind(&MetricsServicesManager::UpdateRunningServices,
+ base::Unretained(this)));
+ }
return metrics_service_client_.get();
}
-void MetricsServicesManager::UpdatePermissions(bool may_record,
- bool may_upload) {
+void MetricsServicesManager::UpdatePermissions(bool current_may_record,
+ bool current_may_upload) {
DCHECK(thread_checker_.CalledOnValidThread());
+ // If the user has opted out of metrics, delete local UKM state.
+ if (may_record_ && !current_may_record) {
+ ukm::UkmService* ukm = GetUkmService();
+ if (ukm) {
+ ukm->Purge();
+ ukm->ResetClientId();
+ }
+ }
+
// Stash the current permissions so that we can update the RapporServiceImpl
// 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;
+ may_record_ = current_may_record;
+ may_upload_ = current_may_upload;
UpdateRunningServices();
}
void MetricsServicesManager::UpdateRunningServices() {
DCHECK(thread_checker_.CalledOnValidThread());
metrics::MetricsService* metrics = GetMetricsService();
- ukm::UkmService* ukm = GetUkmService();
if (client_->OnlyDoMetricsRecording()) {
metrics->StartRecordingForTests();
@@ -102,23 +115,16 @@ void MetricsServicesManager::UpdateRunningServices() {
if (may_record_) {
if (!metrics->recording_active())
metrics->Start();
-
- if (may_upload_) {
+ if (may_upload_)
metrics->EnableReporting();
-#if !defined(OFFICIAL_BUILD)
- // TODO(holte): Make UKM check sync state instead of official build.
- if (ukm)
- ukm->EnableReporting();
-#endif
- } else {
+ else
metrics->DisableReporting();
- if (ukm)
- ukm->DisableReporting();
- }
} else {
metrics->Stop();
}
+ UpdateUkmService();
+
int recording_groups = 0;
#if defined(GOOGLE_CHROME_BUILD)
if (may_record_)
@@ -137,6 +143,24 @@ void MetricsServicesManager::UpdateRunningServices() {
GetRapporServiceImpl()->Update(recording_groups, may_upload_);
}
+void MetricsServicesManager::UpdateUkmService() {
+ ukm::UkmService* ukm = GetUkmService();
+ if (!ukm)
+ return;
+ bool sync_enabled =
+ metrics_service_client_->IsHistorySyncEnabledOnAllProfiles();
+ if (may_record_ && sync_enabled) {
+ ukm->EnableRecording();
+ if (may_upload_)
+ ukm->EnableReporting();
+ else
+ ukm->DisableReporting();
+ } else {
+ ukm->DisableRecording();
+ ukm->DisableReporting();
+ }
+}
+
void MetricsServicesManager::UpdateUploadPermissions(bool may_upload) {
UpdatePermissions(client_->IsMetricsReportingEnabled(), may_upload);
}
« no previous file with comments | « components/metrics_services_manager/metrics_services_manager.h ('k') | components/ukm/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698