Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "ios/chrome/browser/ios_chrome_main_parts.h" | 5 #include "ios/chrome/browser/ios_chrome_main_parts.h" |
| 6 | 6 |
| 7 #include "base/base_switches.h" | 7 #include "base/base_switches.h" |
| 8 #include "base/feature_list.h" | 8 #include "base/feature_list.h" |
| 9 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 186 | 186 |
| 187 void IOSChromeMainParts::PostDestroyThreads() { | 187 void IOSChromeMainParts::PostDestroyThreads() { |
| 188 application_context_->PostDestroyThreads(); | 188 application_context_->PostDestroyThreads(); |
| 189 } | 189 } |
| 190 | 190 |
| 191 // This will be called after the command-line has been mutated by about:flags | 191 // This will be called after the command-line has been mutated by about:flags |
| 192 void IOSChromeMainParts::SetUpMetricsAndFieldTrials() { | 192 void IOSChromeMainParts::SetUpMetricsAndFieldTrials() { |
| 193 base::SetRecordActionTaskRunner( | 193 base::SetRecordActionTaskRunner( |
| 194 web::WebThread::GetTaskRunnerForThread(web::WebThread::UI)); | 194 web::WebThread::GetTaskRunnerForThread(web::WebThread::UI)); |
| 195 | 195 |
| 196 // Must initialize metrics after labs have been converted into switches, | |
| 197 // but before field trials are set up (so that client ID is available for | |
| 198 // one-time randomized field trials). | |
| 199 metrics::MetricsService* metrics = application_context_->GetMetricsService(); | |
| 200 | |
| 201 // Initialize FieldTrialList to support FieldTrials that use one-time | 196 // Initialize FieldTrialList to support FieldTrials that use one-time |
| 202 // randomization. | 197 // randomization. |
| 198 DCHECK(!field_trial_list_); | |
| 203 field_trial_list_.reset( | 199 field_trial_list_.reset( |
| 204 new base::FieldTrialList(metrics->CreateEntropyProvider().release())); | 200 new base::FieldTrialList(application_context_->GetMetricsServicesManager() |
| 201 ->CreateEntropyProvider() | |
|
brettw
2016/09/14 22:22:03
Ditto with unfortunate unique_ptr usage.
robliao
2016/09/15 14:31:18
Agreed.
| |
| 202 .release())); | |
| 205 | 203 |
| 206 const base::CommandLine* command_line = | 204 const base::CommandLine* command_line = |
| 207 base::CommandLine::ForCurrentProcess(); | 205 base::CommandLine::ForCurrentProcess(); |
| 208 // Ensure any field trials specified on the command line are initialized. | 206 // Ensure any field trials specified on the command line are initialized. |
| 209 // Also stop the metrics service so that we don't pollute UMA. | 207 // Also stop the metrics service so that we don't pollute UMA. |
| 210 if (command_line->HasSwitch(switches::kForceFieldTrials)) { | 208 if (command_line->HasSwitch(switches::kForceFieldTrials)) { |
| 211 // Create field trials without activating them, so that this behaves in a | 209 // Create field trials without activating them, so that this behaves in a |
| 212 // consistent manner with field trials created from the server. | 210 // consistent manner with field trials created from the server. |
| 213 bool result = base::FieldTrialList::CreateTrialsFromString( | 211 bool result = base::FieldTrialList::CreateTrialsFromString( |
| 214 command_line->GetSwitchValueASCII(switches::kForceFieldTrials), | 212 command_line->GetSwitchValueASCII(switches::kForceFieldTrials), |
| 215 std::set<std::string>()); | 213 std::set<std::string>()); |
| 216 CHECK(result) << "Invalid --" << switches::kForceFieldTrials | 214 CHECK(result) << "Invalid --" << switches::kForceFieldTrials |
| 217 << " list specified."; | 215 << " list specified."; |
| 218 } | 216 } |
| 219 | 217 |
| 220 std::unique_ptr<base::FeatureList> feature_list(new base::FeatureList); | 218 std::unique_ptr<base::FeatureList> feature_list(new base::FeatureList); |
| 221 | 219 |
| 222 // Associate parameters chosen in about:flags and create trial/group for them. | 220 // Associate parameters chosen in about:flags and create trial/group for them. |
| 223 flags_ui::PrefServiceFlagsStorage flags_storage( | 221 flags_ui::PrefServiceFlagsStorage flags_storage( |
| 224 application_context_->GetLocalState()); | 222 application_context_->GetLocalState()); |
| 225 std::vector<std::string> variation_ids = | 223 std::vector<std::string> variation_ids = |
| 226 RegisterAllFeatureVariationParameters(&flags_storage, feature_list.get()); | 224 RegisterAllFeatureVariationParameters(&flags_storage, feature_list.get()); |
| 227 | 225 |
| 226 // Must initialize metrics after about:flags have been converted into | |
| 227 // switches, but before field trials are set up (so that client ID is | |
| 228 // available for one-time randomized field trials). | |
| 229 metrics::MetricsService* metrics = application_context_->GetMetricsService(); | |
| 230 | |
| 228 variations::VariationsHttpHeaderProvider* http_header_provider = | 231 variations::VariationsHttpHeaderProvider* http_header_provider = |
| 229 variations::VariationsHttpHeaderProvider::GetInstance(); | 232 variations::VariationsHttpHeaderProvider::GetInstance(); |
| 230 // Force the variation ids selected in chrome://flags and/or specified using | 233 // Force the variation ids selected in chrome://flags and/or specified using |
| 231 // the command-line flag. | 234 // the command-line flag. |
| 232 bool result = http_header_provider->ForceVariationIds( | 235 bool result = http_header_provider->ForceVariationIds( |
| 233 command_line->GetSwitchValueASCII(switches::kIOSForceVariationIds), | 236 command_line->GetSwitchValueASCII(switches::kIOSForceVariationIds), |
| 234 &variation_ids); | 237 &variation_ids); |
| 235 CHECK(result) << "Invalid list of variation ids specified (either in --" | 238 CHECK(result) << "Invalid list of variation ids specified (either in --" |
| 236 << switches::kIOSForceVariationIds << " or in chrome://flags)"; | 239 << switches::kIOSForceVariationIds << " or in chrome://flags)"; |
| 237 metrics->AddSyntheticTrialObserver(http_header_provider); | 240 metrics->AddSyntheticTrialObserver(http_header_provider); |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 256 | 259 |
| 257 void IOSChromeMainParts::StartMetricsRecording() { | 260 void IOSChromeMainParts::StartMetricsRecording() { |
| 258 bool wifiOnly = local_state_->GetBoolean(prefs::kMetricsReportingWifiOnly); | 261 bool wifiOnly = local_state_->GetBoolean(prefs::kMetricsReportingWifiOnly); |
| 259 bool isConnectionCellular = net::NetworkChangeNotifier::IsConnectionCellular( | 262 bool isConnectionCellular = net::NetworkChangeNotifier::IsConnectionCellular( |
| 260 net::NetworkChangeNotifier::GetConnectionType()); | 263 net::NetworkChangeNotifier::GetConnectionType()); |
| 261 bool mayUpload = !wifiOnly || !isConnectionCellular; | 264 bool mayUpload = !wifiOnly || !isConnectionCellular; |
| 262 | 265 |
| 263 application_context_->GetMetricsServicesManager()->UpdateUploadPermissions( | 266 application_context_->GetMetricsServicesManager()->UpdateUploadPermissions( |
| 264 mayUpload); | 267 mayUpload); |
| 265 } | 268 } |
| OLD | NEW |