| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/chrome_metrics_services_manager_client.h" | 5 #include "chrome/browser/metrics/chrome_metrics_services_manager_client.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/feature_list.h" | 8 #include "base/feature_list.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 56 base::FEATURE_ENABLED_BY_DEFAULT}; | 56 base::FEATURE_ENABLED_BY_DEFAULT}; |
| 57 | 57 |
| 58 // Posts |GoogleUpdateSettings::StoreMetricsClientInfo| on blocking pool thread | 58 // Posts |GoogleUpdateSettings::StoreMetricsClientInfo| on blocking pool thread |
| 59 // because it needs access to IO and cannot work from UI thread. | 59 // because it needs access to IO and cannot work from UI thread. |
| 60 void PostStoreMetricsClientInfo(const metrics::ClientInfo& client_info) { | 60 void PostStoreMetricsClientInfo(const metrics::ClientInfo& client_info) { |
| 61 content::BrowserThread::GetBlockingPool()->PostTask( | 61 content::BrowserThread::GetBlockingPool()->PostTask( |
| 62 FROM_HERE, | 62 FROM_HERE, |
| 63 base::Bind(&GoogleUpdateSettings::StoreMetricsClientInfo, client_info)); | 63 base::Bind(&GoogleUpdateSettings::StoreMetricsClientInfo, client_info)); |
| 64 } | 64 } |
| 65 | 65 |
| 66 // Appends a group to the sampling controlling |trial|. The group will be |
| 67 // associated with a variation param for reporting sampling |rate| in per mille. |
| 68 void AppendSamplingTrialGroup(const std::string& group_name, |
| 69 int rate, |
| 70 base::FieldTrial* trial) { |
| 71 std::map<std::string, std::string> params = { |
| 72 {kRateParamName, base::IntToString(rate)}}; |
| 73 variations::AssociateVariationParams(trial->trial_name(), group_name, params); |
| 74 trial->AppendGroup(group_name, rate); |
| 75 } |
| 76 |
| 66 // Only clients that were given an opt-out metrics-reporting consent flow are | 77 // Only clients that were given an opt-out metrics-reporting consent flow are |
| 67 // eligible for sampling. | 78 // eligible for sampling. |
| 68 bool IsClientEligibleForSampling() { | 79 bool IsClientEligibleForSampling() { |
| 69 return metrics::GetMetricsReportingDefaultState( | 80 return metrics::GetMetricsReportingDefaultState( |
| 70 g_browser_process->local_state()) == | 81 g_browser_process->local_state()) == |
| 71 metrics::EnableMetricsDefault::OPT_OUT; | 82 metrics::EnableMetricsDefault::OPT_OUT; |
| 72 } | 83 } |
| 73 | 84 |
| 74 } // namespace | 85 } // namespace |
| 75 | 86 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 97 : enabled_state_provider_(new ChromeEnabledStateProvider()), | 108 : enabled_state_provider_(new ChromeEnabledStateProvider()), |
| 98 local_state_(local_state) { | 109 local_state_(local_state) { |
| 99 DCHECK(local_state); | 110 DCHECK(local_state); |
| 100 | 111 |
| 101 SetupMetricsStateForChromeOS(); | 112 SetupMetricsStateForChromeOS(); |
| 102 } | 113 } |
| 103 | 114 |
| 104 ChromeMetricsServicesManagerClient::~ChromeMetricsServicesManagerClient() {} | 115 ChromeMetricsServicesManagerClient::~ChromeMetricsServicesManagerClient() {} |
| 105 | 116 |
| 106 // static | 117 // static |
| 118 void ChromeMetricsServicesManagerClient::CreateFallbackSamplingTrial( |
| 119 base::FeatureList* feature_list) { |
| 120 // The trial name must be kept in sync with the server config controlling |
| 121 // sampling. If they don't match, then clients will be shuffled into different |
| 122 // groups when the server config takes over from the fallback trial. |
| 123 static const char kTrialName[] = "MetricsAndCrashSampling"; |
| 124 scoped_refptr<base::FieldTrial> trial( |
| 125 base::FieldTrialList::FactoryGetFieldTrial( |
| 126 kTrialName, 1000, "Default", base::FieldTrialList::kNoExpirationYear, |
| 127 1, 1, base::FieldTrial::ONE_TIME_RANDOMIZED, nullptr)); |
| 128 |
| 129 // Like the trial name, the order that these two groups are added to the trial |
| 130 // must be kept in sync with the order that they appear in the server |
| 131 // config. |
| 132 |
| 133 // 100 per-mille sampling rate group. |
| 134 static const char kInSampleGroup[] = "InReportingSample"; |
| 135 AppendSamplingTrialGroup(kInSampleGroup, 100, trial.get()); |
| 136 |
| 137 // 900 per-mille sampled out. |
| 138 static const char kSampledOutGroup[] = "OutOfReportingSample"; |
| 139 AppendSamplingTrialGroup(kSampledOutGroup, 900, trial.get()); |
| 140 |
| 141 // Setup the feature. |
| 142 const std::string& group_name = trial->GetGroupNameWithoutActivation(); |
| 143 feature_list->RegisterFieldTrialOverride( |
| 144 kMetricsReportingFeature.name, |
| 145 group_name == kSampledOutGroup |
| 146 ? base::FeatureList::OVERRIDE_DISABLE_FEATURE |
| 147 : base::FeatureList::OVERRIDE_ENABLE_FEATURE, |
| 148 trial.get()); |
| 149 } |
| 150 |
| 151 // static |
| 107 bool ChromeMetricsServicesManagerClient::IsClientInSample() { | 152 bool ChromeMetricsServicesManagerClient::IsClientInSample() { |
| 108 // Only some clients are eligible for sampling. Clients that aren't eligible | 153 // Only some clients are eligible for sampling. Clients that aren't eligible |
| 109 // will always be considered "in sample". In this case, we don't want the | 154 // will always be considered "in sample". In this case, we don't want the |
| 110 // feature state queried, because we don't want the field trial that controls | 155 // feature state queried, because we don't want the field trial that controls |
| 111 // sampling to be reported as active. | 156 // sampling to be reported as active. |
| 112 if (!IsClientEligibleForSampling()) | 157 if (!IsClientEligibleForSampling()) |
| 113 return true; | 158 return true; |
| 114 | 159 |
| 115 return base::FeatureList::IsEnabled(kMetricsReportingFeature); | 160 return base::FeatureList::IsEnabled(kMetricsReportingFeature); |
| 116 } | 161 } |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 218 ChromeMetricsServicesManagerClient::GetMetricsStateManager() { | 263 ChromeMetricsServicesManagerClient::GetMetricsStateManager() { |
| 219 DCHECK(thread_checker_.CalledOnValidThread()); | 264 DCHECK(thread_checker_.CalledOnValidThread()); |
| 220 if (!metrics_state_manager_) { | 265 if (!metrics_state_manager_) { |
| 221 metrics_state_manager_ = metrics::MetricsStateManager::Create( | 266 metrics_state_manager_ = metrics::MetricsStateManager::Create( |
| 222 local_state_, enabled_state_provider_.get(), | 267 local_state_, enabled_state_provider_.get(), |
| 223 base::Bind(&PostStoreMetricsClientInfo), | 268 base::Bind(&PostStoreMetricsClientInfo), |
| 224 base::Bind(&GoogleUpdateSettings::LoadMetricsClientInfo)); | 269 base::Bind(&GoogleUpdateSettings::LoadMetricsClientInfo)); |
| 225 } | 270 } |
| 226 return metrics_state_manager_.get(); | 271 return metrics_state_manager_.get(); |
| 227 } | 272 } |
| OLD | NEW |