Chromium Code Reviews| 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 samlping |rate| in per mille. | |
| 68 void AppendSamplingTrialGroup(const std::string& 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(), name, params); | |
| 74 trial->AppendGroup(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 20 matching lines...) Expand all Loading... | |
| 96 PrefService* local_state) | 107 PrefService* local_state) |
| 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 |
| 117 #if defined(OS_WIN) || defined(OS_ANDROID) | |
| 118 // static | |
| 119 void ChromeMetricsServicesManagerClient::CreateFallbackSamplingTrial( | |
| 120 base::FeatureList* feature_list) { | |
| 121 const std::string kTrialName = "MetricsAndCrashSampling"; | |
|
Alexei Svitkine (slow)
2016/08/29 19:38:42
static const char[]
same for the other ones below
jwd
2016/08/29 21:36:24
Done.
| |
| 122 scoped_refptr<base::FieldTrial> trial( | |
| 123 base::FieldTrialList::FactoryGetFieldTrial( | |
| 124 kTrialName, 1000, "Default", base::FieldTrialList::kNoExpirationYear, | |
| 125 1, 1, base::FieldTrial::ONE_TIME_RANDOMIZED, NULL)); | |
| 126 | |
| 127 // 100 per-mille sampling rate group. | |
| 128 const std::string kInSampleGroup = "InReportingSample"; | |
| 129 AppendSamplingTrialGroup(kInSampleGroup, 100, trial.get()); | |
| 130 | |
| 131 // 900 per-mille sampled out. | |
| 132 const std::string kSampledOutGroup = "OutOfReportingSample"; | |
| 133 AppendSamplingTrialGroup(kSampledOutGroup, 900, trial.get()); | |
| 134 | |
| 135 // Setup the feature. | |
| 136 const std::string& group_name = trial->GetGroupNameWithoutActivation(); | |
| 137 feature_list->RegisterFieldTrialOverride( | |
| 138 kMetricsReportingFeature.name, | |
| 139 group_name == kSampledOutGroup | |
| 140 ? base::FeatureList::OVERRIDE_DISABLE_FEATURE | |
| 141 : base::FeatureList::OVERRIDE_ENABLE_FEATURE, | |
| 142 trial.get()); | |
| 143 } | |
| 144 #endif // defined(OS_WIN) || defined(OS_ANDROID) | |
| 145 | |
| 106 // static | 146 // static |
| 107 bool ChromeMetricsServicesManagerClient::IsClientInSample() { | 147 bool ChromeMetricsServicesManagerClient::IsClientInSample() { |
| 108 // Only some clients are eligible for sampling. Clients that aren't eligible | 148 // 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 | 149 // 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 | 150 // feature state queried, because we don't want the field trial that controls |
| 111 // sampling to be reported as active. | 151 // sampling to be reported as active. |
| 112 if (!IsClientEligibleForSampling()) | 152 if (!IsClientEligibleForSampling()) |
| 113 return true; | 153 return true; |
| 114 | 154 |
| 115 return base::FeatureList::IsEnabled(kMetricsReportingFeature); | 155 return base::FeatureList::IsEnabled(kMetricsReportingFeature); |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 218 ChromeMetricsServicesManagerClient::GetMetricsStateManager() { | 258 ChromeMetricsServicesManagerClient::GetMetricsStateManager() { |
| 219 DCHECK(thread_checker_.CalledOnValidThread()); | 259 DCHECK(thread_checker_.CalledOnValidThread()); |
| 220 if (!metrics_state_manager_) { | 260 if (!metrics_state_manager_) { |
| 221 metrics_state_manager_ = metrics::MetricsStateManager::Create( | 261 metrics_state_manager_ = metrics::MetricsStateManager::Create( |
| 222 local_state_, enabled_state_provider_.get(), | 262 local_state_, enabled_state_provider_.get(), |
| 223 base::Bind(&PostStoreMetricsClientInfo), | 263 base::Bind(&PostStoreMetricsClientInfo), |
| 224 base::Bind(&GoogleUpdateSettings::LoadMetricsClientInfo)); | 264 base::Bind(&GoogleUpdateSettings::LoadMetricsClientInfo)); |
| 225 } | 265 } |
| 226 return metrics_state_manager_.get(); | 266 return metrics_state_manager_.get(); |
| 227 } | 267 } |
| OLD | NEW |