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

Side by Side Diff: ios/chrome/browser/ios_chrome_main_parts.mm

Issue 2376123004: Rearrange iOS SetupMetricsAndFieldTrials to SetupFieldTrials and SetupMetrics (Closed)
Patch Set: Created 4 years, 2 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
« no previous file with comments | « ios/chrome/browser/ios_chrome_main_parts.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 base::CommandLine::ForCurrentProcess()); 107 base::CommandLine::ForCurrentProcess());
108 108
109 // Initialize tracking synchronizer system. 109 // Initialize tracking synchronizer system.
110 tracking_synchronizer_ = new metrics::TrackingSynchronizer( 110 tracking_synchronizer_ = new metrics::TrackingSynchronizer(
111 base::MakeUnique<base::DefaultTickClock>(), 111 base::MakeUnique<base::DefaultTickClock>(),
112 base::Bind(&metrics::IOSTrackingSynchronizerDelegate::Create)); 112 base::Bind(&metrics::IOSTrackingSynchronizerDelegate::Create));
113 113
114 // Now the command line has been mutated based on about:flags, we can setup 114 // Now the command line has been mutated based on about:flags, we can setup
115 // metrics and initialize field trials that are needed by IOSChromeIOThread's 115 // metrics and initialize field trials that are needed by IOSChromeIOThread's
116 // initialization which happens in ApplicationContext:PreCreateThreads. 116 // initialization which happens in ApplicationContext:PreCreateThreads.
117 SetUpMetricsAndFieldTrials(); 117 SetupFieldTrials();
118 SetupMetrics();
118 119
119 // Initialize FieldTrialSynchronizer system. 120 // Initialize FieldTrialSynchronizer system.
120 field_trial_synchronizer_.reset(new ios::FieldTrialSynchronizer); 121 field_trial_synchronizer_.reset(new ios::FieldTrialSynchronizer);
121 122
122 application_context_->PreCreateThreads(); 123 application_context_->PreCreateThreads();
123 } 124 }
124 125
125 void IOSChromeMainParts::PreMainMessageLoopRun() { 126 void IOSChromeMainParts::PreMainMessageLoopRun() {
126 // Now that the file thread has been started, start recording. 127 // Now that the file thread has been started, start recording.
127 StartMetricsRecording(); 128 StartMetricsRecording();
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
185 void IOSChromeMainParts::PostMainMessageLoopRun() { 186 void IOSChromeMainParts::PostMainMessageLoopRun() {
186 TranslateServiceIOS::Shutdown(); 187 TranslateServiceIOS::Shutdown();
187 application_context_->StartTearDown(); 188 application_context_->StartTearDown();
188 } 189 }
189 190
190 void IOSChromeMainParts::PostDestroyThreads() { 191 void IOSChromeMainParts::PostDestroyThreads() {
191 application_context_->PostDestroyThreads(); 192 application_context_->PostDestroyThreads();
192 } 193 }
193 194
194 // This will be called after the command-line has been mutated by about:flags 195 // This will be called after the command-line has been mutated by about:flags
195 void IOSChromeMainParts::SetUpMetricsAndFieldTrials() { 196 void IOSChromeMainParts::SetupFieldTrials() {
196 base::SetRecordActionTaskRunner( 197 base::SetRecordActionTaskRunner(
197 web::WebThread::GetTaskRunnerForThread(web::WebThread::UI)); 198 web::WebThread::GetTaskRunnerForThread(web::WebThread::UI));
198 199
199 // Initialize FieldTrialList to support FieldTrials that use one-time 200 // Initialize FieldTrialList to support FieldTrials that use one-time
200 // randomization. 201 // randomization.
201 DCHECK(!field_trial_list_); 202 DCHECK(!field_trial_list_);
202 field_trial_list_.reset( 203 field_trial_list_.reset(
203 new base::FieldTrialList(application_context_->GetMetricsServicesManager() 204 new base::FieldTrialList(application_context_->GetMetricsServicesManager()
204 ->CreateEntropyProvider())); 205 ->CreateEntropyProvider()));
205 206
(...skipping 12 matching lines...) Expand all
218 } 219 }
219 220
220 std::unique_ptr<base::FeatureList> feature_list(new base::FeatureList); 221 std::unique_ptr<base::FeatureList> feature_list(new base::FeatureList);
221 222
222 // Associate parameters chosen in about:flags and create trial/group for them. 223 // Associate parameters chosen in about:flags and create trial/group for them.
223 flags_ui::PrefServiceFlagsStorage flags_storage( 224 flags_ui::PrefServiceFlagsStorage flags_storage(
224 application_context_->GetLocalState()); 225 application_context_->GetLocalState());
225 std::vector<std::string> variation_ids = 226 std::vector<std::string> variation_ids =
226 RegisterAllFeatureVariationParameters(&flags_storage, feature_list.get()); 227 RegisterAllFeatureVariationParameters(&flags_storage, feature_list.get());
227 228
228 // Must initialize metrics after about:flags have been converted into
229 // switches, but before field trials are set up (so that client ID is
230 // available for one-time randomized field trials).
231 metrics::MetricsService* metrics = application_context_->GetMetricsService();
232
233 variations::VariationsHttpHeaderProvider* http_header_provider = 229 variations::VariationsHttpHeaderProvider* http_header_provider =
234 variations::VariationsHttpHeaderProvider::GetInstance(); 230 variations::VariationsHttpHeaderProvider::GetInstance();
235 // Force the variation ids selected in chrome://flags and/or specified using 231 // Force the variation ids selected in chrome://flags and/or specified using
236 // the command-line flag. 232 // the command-line flag.
237 bool result = http_header_provider->ForceVariationIds( 233 bool result = http_header_provider->ForceVariationIds(
238 command_line->GetSwitchValueASCII(switches::kIOSForceVariationIds), 234 command_line->GetSwitchValueASCII(switches::kIOSForceVariationIds),
239 &variation_ids); 235 &variation_ids);
240 CHECK(result) << "Invalid list of variation ids specified (either in --" 236 CHECK(result) << "Invalid list of variation ids specified (either in --"
241 << switches::kIOSForceVariationIds << " or in chrome://flags)"; 237 << switches::kIOSForceVariationIds << " or in chrome://flags)";
242 metrics->AddSyntheticTrialObserver(http_header_provider);
243 238
244 feature_list->InitializeFromCommandLine( 239 feature_list->InitializeFromCommandLine(
245 command_line->GetSwitchValueASCII(switches::kEnableIOSFeatures), 240 command_line->GetSwitchValueASCII(switches::kEnableIOSFeatures),
246 command_line->GetSwitchValueASCII(switches::kDisableIOSFeatures)); 241 command_line->GetSwitchValueASCII(switches::kDisableIOSFeatures));
247 242
248 variations::VariationsService* variations_service = 243 variations::VariationsService* variations_service =
249 application_context_->GetVariationsService(); 244 application_context_->GetVariationsService();
250 if (variations_service) 245 if (variations_service)
251 variations_service->CreateTrialsFromSeed(feature_list.get()); 246 variations_service->CreateTrialsFromSeed(feature_list.get());
252 247
253 base::FeatureList::SetInstance(std::move(feature_list)); 248 base::FeatureList::SetInstance(std::move(feature_list));
254 249
255 SetupFieldTrials(parsed_command_line_, 250 SetupIOSFieldTrials();
256 base::Time::FromTimeT(metrics->GetInstallDate())); 251 }
257 252
253 void IOSChromeMainParts::SetupMetrics() {
254 metrics::MetricsService* metrics = application_context_->GetMetricsService();
255 metrics->AddSyntheticTrialObserver(
256 variations::VariationsHttpHeaderProvider::GetInstance());
258 // Now that field trials have been created, initializes metrics recording. 257 // Now that field trials have been created, initializes metrics recording.
259 metrics->InitializeMetricsRecordingState(); 258 metrics->InitializeMetricsRecordingState();
260 } 259 }
261 260
262 void IOSChromeMainParts::StartMetricsRecording() { 261 void IOSChromeMainParts::StartMetricsRecording() {
263 bool wifiOnly = local_state_->GetBoolean(prefs::kMetricsReportingWifiOnly); 262 bool wifiOnly = local_state_->GetBoolean(prefs::kMetricsReportingWifiOnly);
264 bool isConnectionCellular = net::NetworkChangeNotifier::IsConnectionCellular( 263 bool isConnectionCellular = net::NetworkChangeNotifier::IsConnectionCellular(
265 net::NetworkChangeNotifier::GetConnectionType()); 264 net::NetworkChangeNotifier::GetConnectionType());
266 bool mayUpload = !wifiOnly || !isConnectionCellular; 265 bool mayUpload = !wifiOnly || !isConnectionCellular;
267 266
268 application_context_->GetMetricsServicesManager()->UpdateUploadPermissions( 267 application_context_->GetMetricsServicesManager()->UpdateUploadPermissions(
269 mayUpload); 268 mayUpload);
270 } 269 }
OLDNEW
« no previous file with comments | « ios/chrome/browser/ios_chrome_main_parts.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698