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

Side by Side Diff: components/metrics_services_manager/metrics_services_manager.cc

Issue 2653693004: UKM Sync Observer (Closed)
Patch Set: Split 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 unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "components/metrics_services_manager/metrics_services_manager.h" 5 #include "components/metrics_services_manager/metrics_services_manager.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "components/metrics/metrics_service.h" 10 #include "components/metrics/metrics_service.h"
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 GetMetricsServiceClient()->OnPluginLoadingError(plugin_path); 61 GetMetricsServiceClient()->OnPluginLoadingError(plugin_path);
62 } 62 }
63 63
64 void MetricsServicesManager::OnRendererProcessCrash() { 64 void MetricsServicesManager::OnRendererProcessCrash() {
65 GetMetricsServiceClient()->OnRendererProcessCrash(); 65 GetMetricsServiceClient()->OnRendererProcessCrash();
66 } 66 }
67 67
68 metrics::MetricsServiceClient* 68 metrics::MetricsServiceClient*
69 MetricsServicesManager::GetMetricsServiceClient() { 69 MetricsServicesManager::GetMetricsServiceClient() {
70 DCHECK(thread_checker_.CalledOnValidThread()); 70 DCHECK(thread_checker_.CalledOnValidThread());
71 if (!metrics_service_client_) 71 if (!metrics_service_client_) {
72 metrics_service_client_ = client_->CreateMetricsServiceClient(); 72 metrics_service_client_ = client_->CreateMetricsServiceClient();
73 // base::Unretained is safe since |this| owns the metrics_service_client_.
74 metrics_service_client_->SetUpdateRunningServicesCallback(
75 base::Bind(&MetricsServicesManager::UpdateRunningServices,
76 base::Unretained(this)));
77 }
73 return metrics_service_client_.get(); 78 return metrics_service_client_.get();
74 } 79 }
75 80
76 void MetricsServicesManager::UpdatePermissions(bool may_record, 81 void MetricsServicesManager::UpdatePermissions(bool may_record,
77 bool may_upload) { 82 bool may_upload) {
78 DCHECK(thread_checker_.CalledOnValidThread()); 83 DCHECK(thread_checker_.CalledOnValidThread());
84 // If the user has opted out of metrics, delete local UKM state.
85 if (may_record_ && !may_record) {
rkaplow 2017/02/01 16:40:55 nit - this just looks confusing. May want to renam
Steven Holte 2017/02/03 00:04:34 Done.
86 ukm::UkmService* ukm = GetUkmService();
87 if (ukm)
88 ukm->Purge();
89 }
90
79 // Stash the current permissions so that we can update the RapporServiceImpl 91 // Stash the current permissions so that we can update the RapporServiceImpl
80 // correctly when the Rappor preference changes. The metrics recording 92 // correctly when the Rappor preference changes. The metrics recording
81 // preference partially determines the initial rappor setting, and also 93 // preference partially determines the initial rappor setting, and also
82 // controls whether FINE metrics are sent. 94 // controls whether FINE metrics are sent.
83 may_record_ = may_record; 95 may_record_ = may_record;
84 may_upload_ = may_upload; 96 may_upload_ = may_upload;
85 UpdateRunningServices(); 97 UpdateRunningServices();
86 } 98 }
87 99
88 void MetricsServicesManager::UpdateRunningServices() { 100 void MetricsServicesManager::UpdateRunningServices() {
89 DCHECK(thread_checker_.CalledOnValidThread()); 101 DCHECK(thread_checker_.CalledOnValidThread());
90 metrics::MetricsService* metrics = GetMetricsService(); 102 metrics::MetricsService* metrics = GetMetricsService();
91 ukm::UkmService* ukm = GetUkmService(); 103 ukm::UkmService* ukm = GetUkmService();
92 104
93 if (client_->OnlyDoMetricsRecording()) { 105 if (client_->OnlyDoMetricsRecording()) {
94 metrics->StartRecordingForTests(); 106 metrics->StartRecordingForTests();
95 GetRapporServiceImpl()->Update( 107 GetRapporServiceImpl()->Update(
96 rappor::UMA_RAPPOR_GROUP | rappor::SAFEBROWSING_RAPPOR_GROUP, false); 108 rappor::UMA_RAPPOR_GROUP | rappor::SAFEBROWSING_RAPPOR_GROUP, false);
97 return; 109 return;
98 } 110 }
99 111
100 client_->UpdateRunningServices(may_record_, may_upload_); 112 client_->UpdateRunningServices(may_record_, may_upload_);
101 113
102 if (may_record_) { 114 if (may_record_) {
103 if (!metrics->recording_active()) 115 if (!metrics->recording_active())
104 metrics->Start(); 116 metrics->Start();
105 117
106 if (may_upload_) { 118 if (may_upload_) {
107 metrics->EnableReporting(); 119 metrics->EnableReporting();
108 #if !defined(OFFICIAL_BUILD) 120 if (ukm && metrics_service_client_->IsHistorySyncEnabledOnAllProfiles())
109 // TODO(holte): Make UKM check sync state instead of official build.
110 if (ukm)
111 ukm->EnableReporting(); 121 ukm->EnableReporting();
112 #endif
113 } else { 122 } else {
114 metrics->DisableReporting(); 123 metrics->DisableReporting();
115 if (ukm) 124 if (ukm)
116 ukm->DisableReporting(); 125 ukm->DisableReporting();
117 } 126 }
118 } else { 127 } else {
119 metrics->Stop(); 128 metrics->Stop();
120 } 129 }
121 130
122 int recording_groups = 0; 131 int recording_groups = 0;
(...skipping 12 matching lines...) Expand all
135 recording_groups |= rappor::SAFEBROWSING_RAPPOR_GROUP; 144 recording_groups |= rappor::SAFEBROWSING_RAPPOR_GROUP;
136 #endif // defined(GOOGLE_CHROME_BUILD) 145 #endif // defined(GOOGLE_CHROME_BUILD)
137 GetRapporServiceImpl()->Update(recording_groups, may_upload_); 146 GetRapporServiceImpl()->Update(recording_groups, may_upload_);
138 } 147 }
139 148
140 void MetricsServicesManager::UpdateUploadPermissions(bool may_upload) { 149 void MetricsServicesManager::UpdateUploadPermissions(bool may_upload) {
141 UpdatePermissions(client_->IsMetricsReportingEnabled(), may_upload); 150 UpdatePermissions(client_->IsMetricsReportingEnabled(), may_upload);
142 } 151 }
143 152
144 } // namespace metrics_services_manager 153 } // namespace metrics_services_manager
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698