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

Side by Side Diff: chrome/browser/metrics/metrics_reporting_state.cc

Issue 1951553002: Enabled client side sampling for user metrics reporting. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 5 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "chrome/browser/metrics/metrics_reporting_state.h" 5 #include "chrome/browser/metrics/metrics_reporting_state.h"
6 6
7 #include "base/callback.h" 7 #include "base/callback.h"
8 #include "base/metrics/histogram.h" 8 #include "base/metrics/histogram.h"
9 #include "build/build_config.h" 9 #include "build/build_config.h"
10 #include "chrome/browser/browser_process.h" 10 #include "chrome/browser/browser_process.h"
11 #include "chrome/browser/metrics/chrome_metrics_service_accessor.h" 11 #include "chrome/browser/metrics/chrome_metrics_service_accessor.h"
12 #include "chrome/common/pref_names.h" 12 #include "chrome/common/pref_names.h"
13 #include "chrome/installer/util/google_update_settings.h" 13 #include "chrome/installer/util/google_update_settings.h"
14 #include "components/metrics/metrics_pref_names.h" 14 #include "components/metrics/metrics_pref_names.h"
15 #include "components/metrics/metrics_service.h" 15 #include "components/metrics/metrics_service.h"
16 #include "components/metrics_services_manager/metrics_services_manager.h"
16 #include "components/prefs/pref_registry_simple.h" 17 #include "components/prefs/pref_registry_simple.h"
17 #include "components/prefs/pref_service.h" 18 #include "components/prefs/pref_service.h"
18 #include "content/public/browser/browser_thread.h" 19 #include "content/public/browser/browser_thread.h"
19 20
20 #if defined(OS_CHROMEOS) 21 #if defined(OS_CHROMEOS)
21 #include "chrome/browser/chromeos/settings/cros_settings.h" 22 #include "chrome/browser/chromeos/settings/cros_settings.h"
22 #include "chromeos/settings/cros_settings_names.h" 23 #include "chromeos/settings/cros_settings_names.h"
23 #endif // defined(OS_CHROMEOS) 24 #endif // defined(OS_CHROMEOS)
24 25
25 namespace { 26 namespace {
(...skipping 27 matching lines...) Expand all
53 // As arguments this function gets: 54 // As arguments this function gets:
54 // |to_update_pref| which indicates what the desired update should be, 55 // |to_update_pref| which indicates what the desired update should be,
55 // |callback_fn| is the callback function to be called in the end 56 // |callback_fn| is the callback function to be called in the end
56 // |updated_pref| is the result of attempted update. 57 // |updated_pref| is the result of attempted update.
57 // Update considers to be successful if |to_update_pref| and |updated_pref| are 58 // Update considers to be successful if |to_update_pref| and |updated_pref| are
58 // the same. 59 // the same.
59 void SetMetricsReporting(bool to_update_pref, 60 void SetMetricsReporting(bool to_update_pref,
60 const OnMetricsReportingCallbackType& callback_fn, 61 const OnMetricsReportingCallbackType& callback_fn,
61 bool updated_pref) { 62 bool updated_pref) {
62 metrics::MetricsService* metrics = g_browser_process->metrics_service(); 63 metrics::MetricsService* metrics = g_browser_process->metrics_service();
63 if (metrics) {
64 if (updated_pref)
65 metrics->Start();
66 else
67 metrics->Stop();
68 }
69 64
70 #if !defined(OS_ANDROID) 65 #if !defined(OS_ANDROID)
71 g_browser_process->local_state()->SetBoolean( 66 g_browser_process->local_state()->SetBoolean(
72 metrics::prefs::kMetricsReportingEnabled, updated_pref); 67 metrics::prefs::kMetricsReportingEnabled, updated_pref);
73 #endif // !defined(OS_ANDROID) 68 #endif // !defined(OS_ANDROID)
74 69
70 // Uses the current state of whether reporting is enabled to enabled services.
71 g_browser_process->GetMetricsServicesManager()->UpdateUploadPermissions(true);
Alexei Svitkine (slow) 2016/07/19 15:23:59 Shouldn't this be updated_pref value and not |true
jwd 2016/07/19 21:21:49 No, the true refers to the "can upload" permission
72
75 // When a user opts in to the metrics reporting service, the previously 73 // When a user opts in to the metrics reporting service, the previously
76 // collected data should be cleared to ensure that nothing is reported before 74 // collected data should be cleared to ensure that nothing is reported before
77 // a user opts in and all reported data is accurate. 75 // a user opts in and all reported data is accurate.
78 if (updated_pref && metrics) 76 if (updated_pref && metrics)
79 metrics->ClearSavedStabilityMetrics(); 77 metrics->ClearSavedStabilityMetrics();
80 78
81 if (to_update_pref == updated_pref) { 79 if (to_update_pref == updated_pref) {
82 RecordMetricsReportingHistogramValue(updated_pref ? 80 RecordMetricsReportingHistogramValue(updated_pref ?
83 METRICS_REPORTING_ENABLED : METRICS_REPORTING_DISABLED); 81 METRICS_REPORTING_ENABLED : METRICS_REPORTING_DISABLED);
84 } else { 82 } else {
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 // will trigger this function and kMetricsReportinEnabled as well as metrics 133 // will trigger this function and kMetricsReportinEnabled as well as metrics
136 // service state will be updated accordingly. 134 // service state will be updated accordingly.
137 void SetupMetricsStateForChromeOS() { 135 void SetupMetricsStateForChromeOS() {
138 #if defined(OS_CHROMEOS) 136 #if defined(OS_CHROMEOS)
139 chromeos::CrosSettings::Get()->AddSettingsObserver( 137 chromeos::CrosSettings::Get()->AddSettingsObserver(
140 chromeos::kStatsReportingPref, base::Bind(&OnDeviceSettingChange)); 138 chromeos::kStatsReportingPref, base::Bind(&OnDeviceSettingChange));
141 139
142 OnDeviceSettingChange(); 140 OnDeviceSettingChange();
143 #endif // defined(OS_CHROMEOS) 141 #endif // defined(OS_CHROMEOS)
144 } 142 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698