Index: chrome/browser/metrics/metrics_reporting_state.cc |
diff --git a/chrome/browser/metrics/metrics_reporting_state.cc b/chrome/browser/metrics/metrics_reporting_state.cc |
index 6c72ba66de08962bcf8ecef206143fdbd2e00fe4..be0352fc0abc92bcd36aadfc68ad07bc39ef3cf0 100644 |
--- a/chrome/browser/metrics/metrics_reporting_state.cc |
+++ b/chrome/browser/metrics/metrics_reporting_state.cc |
@@ -4,33 +4,92 @@ |
#include "chrome/browser/metrics/metrics_reporting_state.h" |
-#include "base/threading/thread_restrictions.h" |
+#include "base/callback.h" |
+#include "base/metrics/histogram.h" |
+#include "base/prefs/pref_service.h" |
#include "chrome/browser/browser_process.h" |
+#include "chrome/common/pref_names.h" |
#include "chrome/installer/util/google_update_settings.h" |
+#include "chromeos/settings/cros_settings_names.h" |
#include "components/metrics/metrics_service.h" |
+#include "content/public/browser/browser_thread.h" |
-bool ResolveMetricsReportingEnabled(bool enabled) { |
- // GoogleUpdateSettings touches the disk from the UI thread. MetricsService |
- // also calls GoogleUpdateSettings below. http://crbug/62626 |
- base::ThreadRestrictions::ScopedAllowIO allow_io; |
+namespace { |
+enum MetricsReportingChangeHistogramValue { |
+ METRICS_REPORTING_ERROR, |
+ METRICS_REPORTING_DISABLED, |
+ METRICS_REPORTING_ENABLED, |
+ METRICS_REPORTING_MAX |
+}; |
+ |
+void RecordMetricsReportingHistogramValue( |
+ MetricsReportingChangeHistogramValue value) { |
+ UMA_HISTOGRAM_ENUMERATION( |
+ "UMA.MetricsReporting", value, METRICS_REPORTING_MAX); |
+} |
+ |
+// Tries to set crash stats upload consent to |enabled|. |
+bool SetGoogleUpdateSettings(bool enabled) { |
GoogleUpdateSettings::SetCollectStatsConsent(enabled); |
- bool update_pref = GoogleUpdateSettings::GetCollectStatsConsent(); |
+ bool updated_pref = GoogleUpdateSettings::GetCollectStatsConsent(); |
+ if (enabled != updated_pref) |
+ DVLOG(1) << "Unable to set metrics reporting status to " << enabled; |
- if (enabled != update_pref) |
- DVLOG(1) << "Unable to set crash report status to " << enabled; |
+ return updated_pref; |
+} |
+// Does the necessary changes for MetricsReportingEnabled changes which needs |
+// to be done in the main thread. |
+void SetMetricsReporting(bool enabled, |
+ const base::Callback<void(bool)> callback_fn, |
+ bool updated_pref) { |
// Only change the pref if GoogleUpdateSettings::GetCollectStatsConsent |
// succeeds. |
- enabled = update_pref; |
- |
metrics::MetricsService* metrics = g_browser_process->metrics_service(); |
if (metrics) { |
- if (enabled) |
+ if (updated_pref) |
metrics->Start(); |
else |
metrics->Stop(); |
} |
+#if !defined(OS_CHROMEOS) |
+ g_browser_process->local_state()->SetBoolean( |
+ prefs::kMetricsReportingEnabled, enabled); |
+#endif |
+ if (enabled == updated_pref) { |
+ RecordMetricsReportingHistogramValue(enabled ? METRICS_REPORTING_ENABLED : |
+ METRICS_REPORTING_DISABLED); |
+ } |
+ else { |
Alexei Svitkine (slow)
2014/09/09 15:27:15
Nit: Put on same line as }
gayane -on leave until 09-2017
2014/09/09 19:40:51
Done.
|
+ RecordMetricsReportingHistogramValue(METRICS_REPORTING_ERROR); |
+ } |
+ if (!callback_fn.is_null()) |
+ callback_fn.Run(updated_pref); |
+} |
+ |
+} // namespace |
+ |
+void InitiateMetricsReportingChange( |
+ bool enabled, const base::Callback<void(bool)> callback_fn) { |
Alexei Svitkine (slow)
2014/09/09 15:27:15
If you're wrapping the first param, then it should
gayane -on leave until 09-2017
2014/09/09 19:40:51
Done.
|
+ if (!IsMetricsReportingUserChangable()) { |
+ if (!callback_fn.is_null()) |
+ callback_fn.Run(false); |
+ return; |
+ } |
+ |
+ // Posts on FILE thread as SetGoogleUpdateSettings does IO operations. |
Alexei Svitkine (slow)
2014/09/09 15:27:15
Nit: "Posts on" -> "Posts to".
gayane -on leave until 09-2017
2014/09/09 19:40:51
Done.
|
+ content::BrowserThread::PostTaskAndReplyWithResult( |
+ content::BrowserThread::FILE, |
+ FROM_HERE, |
+ base::Bind(&SetGoogleUpdateSettings, enabled), |
+ base::Bind(&SetMetricsReporting, enabled, callback_fn)); |
+} |
+ |
+bool IsMetricsReportingUserChangable() { |
+ const PrefService* pref_service = g_browser_process->local_state(); |
- return enabled; |
+ const PrefService::Preference* pref = |
+ pref_service->FindPreference(prefs::kMetricsReportingEnabled); |
+ return pref && pref->IsManaged(); |
} |