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

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

Issue 2570693003: Move Task Scheduler Initialization From ios/chrome/browser to Web (Closed)
Patch Set: Merge Fixes Created 4 years 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/DEPS ('k') | ios/web/app/web_main_loop.mm » ('j') | 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"
11 #include "base/memory/ptr_util.h" 11 #include "base/memory/ptr_util.h"
12 #include "base/metrics/user_metrics.h" 12 #include "base/metrics/user_metrics.h"
13 #include "base/path_service.h" 13 #include "base/path_service.h"
14 #include "base/task_scheduler/task_scheduler.h"
15 #include "base/time/default_tick_clock.h" 14 #include "base/time/default_tick_clock.h"
16 #include "components/content_settings/core/browser/cookie_settings.h" 15 #include "components/content_settings/core/browser/cookie_settings.h"
17 #include "components/content_settings/core/common/content_settings_pattern.h" 16 #include "components/content_settings/core/common/content_settings_pattern.h"
18 #include "components/flags_ui/pref_service_flags_storage.h" 17 #include "components/flags_ui/pref_service_flags_storage.h"
19 #include "components/language_usage_metrics/language_usage_metrics.h" 18 #include "components/language_usage_metrics/language_usage_metrics.h"
20 #include "components/metrics/metrics_service.h" 19 #include "components/metrics/metrics_service.h"
21 #include "components/metrics/profiler/ios/ios_tracking_synchronizer_delegate.h" 20 #include "components/metrics/profiler/ios/ios_tracking_synchronizer_delegate.h"
22 #include "components/metrics/profiler/tracking_synchronizer.h" 21 #include "components/metrics/profiler/tracking_synchronizer.h"
23 #include "components/metrics_services_manager/metrics_services_manager.h" 22 #include "components/metrics_services_manager/metrics_services_manager.h"
24 #include "components/open_from_clipboard/clipboard_recent_content.h" 23 #include "components/open_from_clipboard/clipboard_recent_content.h"
25 #include "components/prefs/json_pref_store.h" 24 #include "components/prefs/json_pref_store.h"
26 #include "components/prefs/pref_service.h" 25 #include "components/prefs/pref_service.h"
27 #include "components/rappor/rappor_service_impl.h" 26 #include "components/rappor/rappor_service_impl.h"
28 #include "components/task_scheduler_util/initialization_util.h"
29 #include "components/translate/core/browser/translate_download_manager.h" 27 #include "components/translate/core/browser/translate_download_manager.h"
30 #include "components/variations/field_trial_config/field_trial_util.h" 28 #include "components/variations/field_trial_config/field_trial_util.h"
31 #include "components/variations/service/variations_service.h" 29 #include "components/variations/service/variations_service.h"
32 #include "components/variations/variations_http_header_provider.h" 30 #include "components/variations/variations_http_header_provider.h"
33 #include "components/variations/variations_switches.h" 31 #include "components/variations/variations_switches.h"
34 #include "ios/chrome/browser/about_flags.h" 32 #include "ios/chrome/browser/about_flags.h"
35 #include "ios/chrome/browser/application_context_impl.h" 33 #include "ios/chrome/browser/application_context_impl.h"
36 #include "ios/chrome/browser/browser_state/browser_state_keyed_service_factories .h" 34 #include "ios/chrome/browser/browser_state/browser_state_keyed_service_factories .h"
37 #include "ios/chrome/browser/browser_state/chrome_browser_state.h" 35 #include "ios/chrome/browser/browser_state/chrome_browser_state.h"
38 #include "ios/chrome/browser/browser_state/chrome_browser_state_manager.h" 36 #include "ios/chrome/browser/browser_state/chrome_browser_state_manager.h"
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 std::string(), nullptr, ResourceBundle::LOAD_COMMON_RESOURCES); 80 std::string(), nullptr, ResourceBundle::LOAD_COMMON_RESOURCES);
83 CHECK(!loaded_locale.empty()); 81 CHECK(!loaded_locale.empty());
84 82
85 base::FilePath resources_pack_path; 83 base::FilePath resources_pack_path;
86 PathService::Get(ios::FILE_RESOURCES_PACK, &resources_pack_path); 84 PathService::Get(ios::FILE_RESOURCES_PACK, &resources_pack_path);
87 ResourceBundle::GetSharedInstance().AddDataPackFromPath( 85 ResourceBundle::GetSharedInstance().AddDataPackFromPath(
88 resources_pack_path, ui::SCALE_FACTOR_100P); 86 resources_pack_path, ui::SCALE_FACTOR_100P);
89 } 87 }
90 88
91 void IOSChromeMainParts::PreCreateThreads() { 89 void IOSChromeMainParts::PreCreateThreads() {
90 // IMPORTANT
91 // Calls in this function should not post tasks or create threads as
92 // components used to handle those tasks are not yet available. This work
93 // should be deferred to PreMainMessageLoopRunImpl.
94
92 base::FilePath local_state_path; 95 base::FilePath local_state_path;
93 CHECK(PathService::Get(ios::FILE_LOCAL_STATE, &local_state_path)); 96 CHECK(PathService::Get(ios::FILE_LOCAL_STATE, &local_state_path));
94 scoped_refptr<base::SequencedTaskRunner> local_state_task_runner = 97 scoped_refptr<base::SequencedTaskRunner> local_state_task_runner =
95 JsonPrefStore::GetTaskRunnerForFile(local_state_path, 98 JsonPrefStore::GetTaskRunnerForFile(local_state_path,
96 web::WebThread::GetBlockingPool()); 99 web::WebThread::GetBlockingPool());
97 application_context_.reset(new ApplicationContextImpl( 100 application_context_.reset(new ApplicationContextImpl(
98 local_state_task_runner.get(), parsed_command_line_, 101 local_state_task_runner.get(), parsed_command_line_,
99 l10n_util::GetLocaleOverride())); 102 l10n_util::GetLocaleOverride()));
100 DCHECK_EQ(application_context_.get(), GetApplicationContext()); 103 DCHECK_EQ(application_context_.get(), GetApplicationContext());
101 104
(...skipping 10 matching lines...) Expand all
112 flags_ui::PrefServiceFlagsStorage flags_storage( 115 flags_ui::PrefServiceFlagsStorage flags_storage(
113 application_context_->GetLocalState()); 116 application_context_->GetLocalState());
114 ConvertFlagsToSwitches(&flags_storage, 117 ConvertFlagsToSwitches(&flags_storage,
115 base::CommandLine::ForCurrentProcess()); 118 base::CommandLine::ForCurrentProcess());
116 119
117 // Initialize tracking synchronizer system. 120 // Initialize tracking synchronizer system.
118 tracking_synchronizer_ = new metrics::TrackingSynchronizer( 121 tracking_synchronizer_ = new metrics::TrackingSynchronizer(
119 base::MakeUnique<base::DefaultTickClock>(), 122 base::MakeUnique<base::DefaultTickClock>(),
120 base::Bind(&metrics::IOSTrackingSynchronizerDelegate::Create)); 123 base::Bind(&metrics::IOSTrackingSynchronizerDelegate::Create));
121 124
122 // IMPORTANT
123 // Do not add anything below this line until you've verified your new code
124 // does not interfere with the critical initialization order below. Some of
125 // the calls below end up implicitly creating threads and as such new calls
126 // typically either belong before them or in a later startup phase.
127
128 // Now that the command line has been mutated based on about:flags, we can 125 // Now that the command line has been mutated based on about:flags, we can
129 // initialize field trials and setup metrics. The field trials are needed by 126 // initialize field trials. The field trials are needed by IOThread's
130 // IOThread's initialization in ApplicationContext's PreCreateThreads. 127 // initialization which happens in BrowserProcess:PreCreateThreads. Metrics
128 // initialization is handled in PreMainMessageLoopRun since it posts tasks.
131 SetupFieldTrials(); 129 SetupFieldTrials();
132 130
133 // Task Scheduler initialization needs to be here for the following reasons:
134 // * After |SetupFieldTrials()|: Initialization uses variations.
135 // * Near the end of |PreCreateThreads()|: The TaskScheduler needs to be
136 // created before any other threads are (by contract) but it creates
137 // threads itself so instantiating it earlier is also incorrect.
138 // To maintain scoping symmetry, if this line is moved, the corresponding
139 // shutdown call may also need to be moved.
140 task_scheduler_util::InitializeDefaultBrowserTaskScheduler();
141
142
143 // Initialize FieldTrialSynchronizer system. 131 // Initialize FieldTrialSynchronizer system.
144 field_trial_synchronizer_.reset(new ios::FieldTrialSynchronizer); 132 field_trial_synchronizer_.reset(new ios::FieldTrialSynchronizer);
145 133
146 application_context_->PreCreateThreads(); 134 application_context_->PreCreateThreads();
147 } 135 }
148 136
149 void IOSChromeMainParts::PreMainMessageLoopRun() { 137 void IOSChromeMainParts::PreMainMessageLoopRun() {
150 // This must occur at PreMainMessageLoopRun because |SetupMetrics()| uses the 138 // This must occur at PreMainMessageLoopRun because |SetupMetrics()| uses the
151 // blocking pool, which is disabled until the CreateThreads phase of startup. 139 // blocking pool, which is disabled until the CreateThreads phase of startup.
152 SetupMetrics(); 140 SetupMetrics();
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 last_used_browser_state->GetPrefs()); 197 last_used_browser_state->GetPrefs());
210 } 198 }
211 199
212 void IOSChromeMainParts::PostMainMessageLoopRun() { 200 void IOSChromeMainParts::PostMainMessageLoopRun() {
213 TranslateServiceIOS::Shutdown(); 201 TranslateServiceIOS::Shutdown();
214 application_context_->StartTearDown(); 202 application_context_->StartTearDown();
215 } 203 }
216 204
217 void IOSChromeMainParts::PostDestroyThreads() { 205 void IOSChromeMainParts::PostDestroyThreads() {
218 application_context_->PostDestroyThreads(); 206 application_context_->PostDestroyThreads();
219
220 // The TaskScheduler was initialized before invoking
221 // |application_context_->PreCreateThreads()|. To maintain scoping symmetry,
222 // perform the shutdown after |application_context_->PostDestroyThreads()|.
223 base::TaskScheduler* task_scheduler = base::TaskScheduler::GetInstance();
224 if (task_scheduler)
225 task_scheduler->Shutdown();
226 } 207 }
227 208
228 // This will be called after the command-line has been mutated by about:flags 209 // This will be called after the command-line has been mutated by about:flags
229 void IOSChromeMainParts::SetupFieldTrials() { 210 void IOSChromeMainParts::SetupFieldTrials() {
230 base::SetRecordActionTaskRunner( 211 base::SetRecordActionTaskRunner(
231 web::WebThread::GetTaskRunnerForThread(web::WebThread::UI)); 212 web::WebThread::GetTaskRunnerForThread(web::WebThread::UI));
232 213
233 // Initialize FieldTrialList to support FieldTrials that use one-time 214 // Initialize FieldTrialList to support FieldTrials that use one-time
234 // randomization. 215 // randomization.
235 DCHECK(!field_trial_list_); 216 DCHECK(!field_trial_list_);
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
302 283
303 void IOSChromeMainParts::StartMetricsRecording() { 284 void IOSChromeMainParts::StartMetricsRecording() {
304 bool wifiOnly = local_state_->GetBoolean(prefs::kMetricsReportingWifiOnly); 285 bool wifiOnly = local_state_->GetBoolean(prefs::kMetricsReportingWifiOnly);
305 bool isConnectionCellular = net::NetworkChangeNotifier::IsConnectionCellular( 286 bool isConnectionCellular = net::NetworkChangeNotifier::IsConnectionCellular(
306 net::NetworkChangeNotifier::GetConnectionType()); 287 net::NetworkChangeNotifier::GetConnectionType());
307 bool mayUpload = !wifiOnly || !isConnectionCellular; 288 bool mayUpload = !wifiOnly || !isConnectionCellular;
308 289
309 application_context_->GetMetricsServicesManager()->UpdateUploadPermissions( 290 application_context_->GetMetricsServicesManager()->UpdateUploadPermissions(
310 mayUpload); 291 mayUpload);
311 } 292 }
OLDNEW
« no previous file with comments | « ios/chrome/browser/DEPS ('k') | ios/web/app/web_main_loop.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698