| 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 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 93 // Check the first run state early; this must be done before IO is disallowed | 93 // Check the first run state early; this must be done before IO is disallowed |
| 94 // so that later calls can use the cached value. (The return value is ignored | 94 // so that later calls can use the cached value. (The return value is ignored |
| 95 // because this is only to trigger the internal lookup and caching for later | 95 // because this is only to trigger the internal lookup and caching for later |
| 96 // use.) | 96 // use.) |
| 97 FirstRun::IsChromeFirstRun(); | 97 FirstRun::IsChromeFirstRun(); |
| 98 | 98 |
| 99 // Initialize local state. | 99 // Initialize local state. |
| 100 local_state_ = application_context_->GetLocalState(); | 100 local_state_ = application_context_->GetLocalState(); |
| 101 DCHECK(local_state_); | 101 DCHECK(local_state_); |
| 102 | 102 |
| 103 flags_ui::PrefServiceFlagsStorage flags_storage_( | 103 flags_ui::PrefServiceFlagsStorage flags_storage( |
| 104 application_context_->GetLocalState()); | 104 application_context_->GetLocalState()); |
| 105 ConvertFlagsToSwitches(&flags_storage_, | 105 ConvertFlagsToSwitches(&flags_storage, |
| 106 base::CommandLine::ForCurrentProcess()); | 106 base::CommandLine::ForCurrentProcess()); |
| 107 | 107 |
| 108 // Initialize tracking synchronizer system. | 108 // Initialize tracking synchronizer system. |
| 109 tracking_synchronizer_ = new metrics::TrackingSynchronizer( | 109 tracking_synchronizer_ = new metrics::TrackingSynchronizer( |
| 110 base::WrapUnique(new base::DefaultTickClock()), | 110 base::WrapUnique(new base::DefaultTickClock()), |
| 111 base::Bind(&metrics::IOSTrackingSynchronizerDelegate::Create)); | 111 base::Bind(&metrics::IOSTrackingSynchronizerDelegate::Create)); |
| 112 | 112 |
| 113 // Now the command line has been mutated based on about:flags, we can setup | 113 // Now the command line has been mutated based on about:flags, we can setup |
| 114 // metrics and initialize field trials that are needed by IOSChromeIOThread's | 114 // metrics and initialize field trials that are needed by IOSChromeIOThread's |
| 115 // initialization which happens in ApplicationContext:PreCreateThreads. | 115 // initialization which happens in ApplicationContext:PreCreateThreads. |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 209 // Also stop the metrics service so that we don't pollute UMA. | 209 // Also stop the metrics service so that we don't pollute UMA. |
| 210 if (command_line->HasSwitch(switches::kForceFieldTrials)) { | 210 if (command_line->HasSwitch(switches::kForceFieldTrials)) { |
| 211 // Create field trials without activating them, so that this behaves in a | 211 // Create field trials without activating them, so that this behaves in a |
| 212 // consistent manner with field trials created from the server. | 212 // consistent manner with field trials created from the server. |
| 213 bool result = base::FieldTrialList::CreateTrialsFromString( | 213 bool result = base::FieldTrialList::CreateTrialsFromString( |
| 214 command_line->GetSwitchValueASCII(switches::kForceFieldTrials), | 214 command_line->GetSwitchValueASCII(switches::kForceFieldTrials), |
| 215 std::set<std::string>()); | 215 std::set<std::string>()); |
| 216 CHECK(result) << "Invalid --" << switches::kForceFieldTrials | 216 CHECK(result) << "Invalid --" << switches::kForceFieldTrials |
| 217 << " list specified."; | 217 << " list specified."; |
| 218 } | 218 } |
| 219 if (command_line->HasSwitch(switches::kIOSForceVariationIds)) { | 219 |
| 220 // Create default variation ids which will always be included in the | |
| 221 // X-Client-Data request header. | |
| 222 variations::VariationsHttpHeaderProvider* provider = | |
| 223 variations::VariationsHttpHeaderProvider::GetInstance(); | |
| 224 bool result = provider->SetDefaultVariationIds( | |
| 225 command_line->GetSwitchValueASCII(switches::kIOSForceVariationIds)); | |
| 226 CHECK(result) << "Invalid --" << switches::kIOSForceVariationIds | |
| 227 << " list specified."; | |
| 228 } | |
| 229 std::unique_ptr<base::FeatureList> feature_list(new base::FeatureList); | 220 std::unique_ptr<base::FeatureList> feature_list(new base::FeatureList); |
| 221 |
| 222 // Associate parameters chosen in about:flags and create trial/group for them. |
| 223 flags_ui::PrefServiceFlagsStorage flags_storage( |
| 224 application_context_->GetLocalState()); |
| 225 std::vector<std::string> variation_ids = |
| 226 RegisterAllFeatureVariationParameters(&flags_storage, feature_list.get()); |
| 227 |
| 228 variations::VariationsHttpHeaderProvider* http_header_provider = |
| 229 variations::VariationsHttpHeaderProvider::GetInstance(); |
| 230 // Force the variation ids selected in chrome://flags and/or specified using |
| 231 // the command-line flag. |
| 232 bool result = http_header_provider->ForceVariationIds( |
| 233 command_line->GetSwitchValueASCII(switches::kIOSForceVariationIds), |
| 234 &variation_ids); |
| 235 CHECK(result) << "Invalid list of variation ids specified (either in --" |
| 236 << switches::kIOSForceVariationIds << " or in chrome://flags)"; |
| 237 metrics->AddSyntheticTrialObserver(http_header_provider); |
| 238 |
| 230 feature_list->InitializeFromCommandLine( | 239 feature_list->InitializeFromCommandLine( |
| 231 command_line->GetSwitchValueASCII(switches::kEnableIOSFeatures), | 240 command_line->GetSwitchValueASCII(switches::kEnableIOSFeatures), |
| 232 command_line->GetSwitchValueASCII(switches::kDisableIOSFeatures)); | 241 command_line->GetSwitchValueASCII(switches::kDisableIOSFeatures)); |
| 233 | 242 |
| 234 variations::VariationsService* variations_service = | 243 variations::VariationsService* variations_service = |
| 235 application_context_->GetVariationsService(); | 244 application_context_->GetVariationsService(); |
| 236 if (variations_service) | 245 if (variations_service) |
| 237 variations_service->CreateTrialsFromSeed(feature_list.get()); | 246 variations_service->CreateTrialsFromSeed(feature_list.get()); |
| 238 | 247 |
| 239 base::FeatureList::SetInstance(std::move(feature_list)); | 248 base::FeatureList::SetInstance(std::move(feature_list)); |
| 240 | 249 |
| 241 SetupFieldTrials(parsed_command_line_, | 250 SetupFieldTrials(parsed_command_line_, |
| 242 base::Time::FromTimeT(metrics->GetInstallDate())); | 251 base::Time::FromTimeT(metrics->GetInstallDate())); |
| 243 | 252 |
| 244 // Now that field trials have been created, initializes metrics recording. | 253 // Now that field trials have been created, initializes metrics recording. |
| 245 metrics->InitializeMetricsRecordingState(); | 254 metrics->InitializeMetricsRecordingState(); |
| 246 } | 255 } |
| 247 | 256 |
| 248 void IOSChromeMainParts::StartMetricsRecording() { | 257 void IOSChromeMainParts::StartMetricsRecording() { |
| 249 bool wifiOnly = local_state_->GetBoolean(prefs::kMetricsReportingWifiOnly); | 258 bool wifiOnly = local_state_->GetBoolean(prefs::kMetricsReportingWifiOnly); |
| 250 bool isConnectionCellular = net::NetworkChangeNotifier::IsConnectionCellular( | 259 bool isConnectionCellular = net::NetworkChangeNotifier::IsConnectionCellular( |
| 251 net::NetworkChangeNotifier::GetConnectionType()); | 260 net::NetworkChangeNotifier::GetConnectionType()); |
| 252 bool mayUpload = !wifiOnly || !isConnectionCellular; | 261 bool mayUpload = !wifiOnly || !isConnectionCellular; |
| 253 | 262 |
| 254 application_context_->GetMetricsServicesManager()->UpdateUploadPermissions( | 263 application_context_->GetMetricsServicesManager()->UpdateUploadPermissions( |
| 255 mayUpload); | 264 mayUpload); |
| 256 } | 265 } |
| OLD | NEW |