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" |
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/switches.h" |
| 15 #include "base/task_scheduler/task_scheduler.h" |
14 #include "base/time/default_tick_clock.h" | 16 #include "base/time/default_tick_clock.h" |
15 #include "components/content_settings/core/browser/cookie_settings.h" | 17 #include "components/content_settings/core/browser/cookie_settings.h" |
16 #include "components/content_settings/core/common/content_settings_pattern.h" | 18 #include "components/content_settings/core/common/content_settings_pattern.h" |
17 #include "components/flags_ui/pref_service_flags_storage.h" | 19 #include "components/flags_ui/pref_service_flags_storage.h" |
18 #include "components/language_usage_metrics/language_usage_metrics.h" | 20 #include "components/language_usage_metrics/language_usage_metrics.h" |
19 #include "components/metrics/metrics_service.h" | 21 #include "components/metrics/metrics_service.h" |
20 #include "components/metrics/profiler/ios/ios_tracking_synchronizer_delegate.h" | 22 #include "components/metrics/profiler/ios/ios_tracking_synchronizer_delegate.h" |
21 #include "components/metrics/profiler/tracking_synchronizer.h" | 23 #include "components/metrics/profiler/tracking_synchronizer.h" |
22 #include "components/metrics_services_manager/metrics_services_manager.h" | 24 #include "components/metrics_services_manager/metrics_services_manager.h" |
23 #include "components/open_from_clipboard/clipboard_recent_content.h" | 25 #include "components/open_from_clipboard/clipboard_recent_content.h" |
24 #include "components/prefs/json_pref_store.h" | 26 #include "components/prefs/json_pref_store.h" |
25 #include "components/prefs/pref_service.h" | 27 #include "components/prefs/pref_service.h" |
26 #include "components/rappor/rappor_service.h" | 28 #include "components/rappor/rappor_service.h" |
| 29 #include "components/task_scheduler_util/initialization_util.h" |
27 #include "components/translate/core/browser/translate_download_manager.h" | 30 #include "components/translate/core/browser/translate_download_manager.h" |
28 #include "components/variations/service/variations_service.h" | 31 #include "components/variations/service/variations_service.h" |
29 #include "components/variations/variations_http_header_provider.h" | 32 #include "components/variations/variations_http_header_provider.h" |
30 #include "ios/chrome/browser/about_flags.h" | 33 #include "ios/chrome/browser/about_flags.h" |
31 #include "ios/chrome/browser/application_context_impl.h" | 34 #include "ios/chrome/browser/application_context_impl.h" |
32 #include "ios/chrome/browser/browser_state/chrome_browser_state.h" | 35 #include "ios/chrome/browser/browser_state/chrome_browser_state.h" |
33 #include "ios/chrome/browser/browser_state/chrome_browser_state_manager.h" | 36 #include "ios/chrome/browser/browser_state/chrome_browser_state_manager.h" |
34 #include "ios/chrome/browser/chrome_paths.h" | 37 #include "ios/chrome/browser/chrome_paths.h" |
35 #include "ios/chrome/browser/chrome_switches.h" | 38 #include "ios/chrome/browser/chrome_switches.h" |
36 #include "ios/chrome/browser/chrome_url_constants.h" | 39 #include "ios/chrome/browser/chrome_url_constants.h" |
(...skipping 11 matching lines...) Expand all Loading... |
48 #include "net/http/http_stream_factory.h" | 51 #include "net/http/http_stream_factory.h" |
49 #include "net/url_request/url_request.h" | 52 #include "net/url_request/url_request.h" |
50 #include "ui/base/l10n/l10n_util_mac.h" | 53 #include "ui/base/l10n/l10n_util_mac.h" |
51 #include "ui/base/resource/resource_bundle.h" | 54 #include "ui/base/resource/resource_bundle.h" |
52 | 55 |
53 #if defined(ENABLE_RLZ) | 56 #if defined(ENABLE_RLZ) |
54 #include "components/rlz/rlz_tracker.h" // nogncheck | 57 #include "components/rlz/rlz_tracker.h" // nogncheck |
55 #include "ios/chrome/browser/rlz/rlz_tracker_delegate_impl.h" // nogncheck | 58 #include "ios/chrome/browser/rlz/rlz_tracker_delegate_impl.h" // nogncheck |
56 #endif | 59 #endif |
57 | 60 |
| 61 namespace { |
| 62 |
| 63 void MaybeInitializeTaskScheduler() { |
| 64 static constexpr char kFieldTrialName[] = "BrowserScheduler"; |
| 65 std::map<std::string, std::string> variation_params; |
| 66 bool used_default_config = false; |
| 67 if (!variations::GetVariationParams(kFieldTrialName, &variation_params)) { |
| 68 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 69 switches::kEnableBrowserTaskScheduler)) { |
| 70 return; |
| 71 } |
| 72 |
| 73 // TODO(robliao): Remove below once iOS uses fieldtrial_testing_config.json. |
| 74 // Synchronize the below from fieldtrial_testing_config.json. |
| 75 DCHECK(variation_params.empty()); |
| 76 variation_params["Background"] = "3;8;0.1;0;30000"; |
| 77 variation_params["BackgroundFileIO"] = "3;8;0.1;0;30000"; |
| 78 variation_params["Foreground"] = "8;32;0.3;0;30000"; |
| 79 variation_params["ForegroundFileIO"] = "8;32;0.3;0;30000"; |
| 80 used_default_config = true; |
| 81 } |
| 82 |
| 83 if (!task_scheduler_util::InitializeDefaultTaskScheduler(variation_params)) |
| 84 return; |
| 85 |
| 86 // TODO(gab): Remove this when http://crbug.com/622400 concludes. |
| 87 const auto sequenced_worker_pool_param = |
| 88 variation_params.find("RedirectSequencedWorkerPools"); |
| 89 if (used_default_config || |
| 90 (sequenced_worker_pool_param != variation_params.end() && |
| 91 sequenced_worker_pool_param->second == "true")) { |
| 92 base::SequencedWorkerPool::RedirectToTaskSchedulerForProcess(); |
| 93 } |
| 94 } |
| 95 |
| 96 } // namespace |
| 97 |
58 IOSChromeMainParts::IOSChromeMainParts( | 98 IOSChromeMainParts::IOSChromeMainParts( |
59 const base::CommandLine& parsed_command_line) | 99 const base::CommandLine& parsed_command_line) |
60 : parsed_command_line_(parsed_command_line), local_state_(nullptr) { | 100 : parsed_command_line_(parsed_command_line), local_state_(nullptr) { |
61 // Chrome disallows cookies by default. All code paths that want to use | 101 // Chrome disallows cookies by default. All code paths that want to use |
62 // cookies need to go through one of Chrome's URLRequestContexts which have | 102 // cookies need to go through one of Chrome's URLRequestContexts which have |
63 // a ChromeNetworkDelegate attached that selectively allows cookies again. | 103 // a ChromeNetworkDelegate attached that selectively allows cookies again. |
64 net::URLRequest::SetDefaultCookiePolicyToBlock(); | 104 net::URLRequest::SetDefaultCookiePolicyToBlock(); |
65 } | 105 } |
66 | 106 |
67 IOSChromeMainParts::~IOSChromeMainParts() {} | 107 IOSChromeMainParts::~IOSChromeMainParts() {} |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
103 flags_ui::PrefServiceFlagsStorage flags_storage( | 143 flags_ui::PrefServiceFlagsStorage flags_storage( |
104 application_context_->GetLocalState()); | 144 application_context_->GetLocalState()); |
105 ConvertFlagsToSwitches(&flags_storage, | 145 ConvertFlagsToSwitches(&flags_storage, |
106 base::CommandLine::ForCurrentProcess()); | 146 base::CommandLine::ForCurrentProcess()); |
107 | 147 |
108 // Initialize tracking synchronizer system. | 148 // Initialize tracking synchronizer system. |
109 tracking_synchronizer_ = new metrics::TrackingSynchronizer( | 149 tracking_synchronizer_ = new metrics::TrackingSynchronizer( |
110 base::MakeUnique<base::DefaultTickClock>(), | 150 base::MakeUnique<base::DefaultTickClock>(), |
111 base::Bind(&metrics::IOSTrackingSynchronizerDelegate::Create)); | 151 base::Bind(&metrics::IOSTrackingSynchronizerDelegate::Create)); |
112 | 152 |
113 // Now the command line has been mutated based on about:flags, we can setup | 153 // IMPORTANT |
114 // metrics and initialize field trials that are needed by IOSChromeIOThread's | 154 // Do not add anything below this line until you've verified your new code |
115 // initialization which happens in ApplicationContext:PreCreateThreads. | 155 // does not interfere with the critical initialization order below. Some of |
| 156 // the calls below end up implicitly creating threads and as such new calls |
| 157 // typically either belong before them or in a later startup phase. |
| 158 |
| 159 // Now that the command line has been mutated based on about:flags, we can |
| 160 // initialize field trials and setup metrics. The field trials are needed by |
| 161 // IOThread's initialization in ApplicationContext's PreCreateThreads. |
116 SetupFieldTrials(); | 162 SetupFieldTrials(); |
| 163 |
| 164 // Task Scheduler initialization needs to be here for the following reasons: |
| 165 // * After |SetupFieldTrials()|: Initialization uses variations. |
| 166 // * Before |SetupMetrics()|: |SetupMetrics()| uses the blocking pool. The |
| 167 // Task Scheduler must do any necessary redirection before then. |
| 168 // * Near the end of |PreCreateThreads()|: The TaskScheduler needs to be |
| 169 // created before any other threads are (by contract) but it creates |
| 170 // threads itself so instantiating it earlier is also incorrect. |
| 171 // To maintain scoping symmetry, if this line is moved, the corresponding |
| 172 // shutdown call may also need to be moved. |
| 173 MaybeInitializeTaskScheduler(); |
| 174 |
117 SetupMetrics(); | 175 SetupMetrics(); |
118 | 176 |
119 // Initialize FieldTrialSynchronizer system. | 177 // Initialize FieldTrialSynchronizer system. |
120 field_trial_synchronizer_.reset(new ios::FieldTrialSynchronizer); | 178 field_trial_synchronizer_.reset(new ios::FieldTrialSynchronizer); |
121 | 179 |
122 application_context_->PreCreateThreads(); | 180 application_context_->PreCreateThreads(); |
123 } | 181 } |
124 | 182 |
125 void IOSChromeMainParts::PreMainMessageLoopRun() { | 183 void IOSChromeMainParts::PreMainMessageLoopRun() { |
126 // Now that the file thread has been started, start recording. | 184 // Now that the file thread has been started, start recording. |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
180 last_used_browser_state->GetPrefs()); | 238 last_used_browser_state->GetPrefs()); |
181 } | 239 } |
182 | 240 |
183 void IOSChromeMainParts::PostMainMessageLoopRun() { | 241 void IOSChromeMainParts::PostMainMessageLoopRun() { |
184 TranslateServiceIOS::Shutdown(); | 242 TranslateServiceIOS::Shutdown(); |
185 application_context_->StartTearDown(); | 243 application_context_->StartTearDown(); |
186 } | 244 } |
187 | 245 |
188 void IOSChromeMainParts::PostDestroyThreads() { | 246 void IOSChromeMainParts::PostDestroyThreads() { |
189 application_context_->PostDestroyThreads(); | 247 application_context_->PostDestroyThreads(); |
| 248 |
| 249 // The TaskScheduler was initialized before invoking |
| 250 // |application_context_->PreCreateThreads()|. To maintain scoping symmetry, |
| 251 // perform the shutdown after |application_context_->PostDestroyThreads()|. |
| 252 base::TaskScheduler* task_scheduler = base::TaskScheduler::GetInstance(); |
| 253 if (task_scheduler) |
| 254 task_scheduler->Shutdown(); |
190 } | 255 } |
191 | 256 |
192 // This will be called after the command-line has been mutated by about:flags | 257 // This will be called after the command-line has been mutated by about:flags |
193 void IOSChromeMainParts::SetupFieldTrials() { | 258 void IOSChromeMainParts::SetupFieldTrials() { |
194 base::SetRecordActionTaskRunner( | 259 base::SetRecordActionTaskRunner( |
195 web::WebThread::GetTaskRunnerForThread(web::WebThread::UI)); | 260 web::WebThread::GetTaskRunnerForThread(web::WebThread::UI)); |
196 | 261 |
197 // Initialize FieldTrialList to support FieldTrials that use one-time | 262 // Initialize FieldTrialList to support FieldTrials that use one-time |
198 // randomization. | 263 // randomization. |
199 DCHECK(!field_trial_list_); | 264 DCHECK(!field_trial_list_); |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
257 | 322 |
258 void IOSChromeMainParts::StartMetricsRecording() { | 323 void IOSChromeMainParts::StartMetricsRecording() { |
259 bool wifiOnly = local_state_->GetBoolean(prefs::kMetricsReportingWifiOnly); | 324 bool wifiOnly = local_state_->GetBoolean(prefs::kMetricsReportingWifiOnly); |
260 bool isConnectionCellular = net::NetworkChangeNotifier::IsConnectionCellular( | 325 bool isConnectionCellular = net::NetworkChangeNotifier::IsConnectionCellular( |
261 net::NetworkChangeNotifier::GetConnectionType()); | 326 net::NetworkChangeNotifier::GetConnectionType()); |
262 bool mayUpload = !wifiOnly || !isConnectionCellular; | 327 bool mayUpload = !wifiOnly || !isConnectionCellular; |
263 | 328 |
264 application_context_->GetMetricsServicesManager()->UpdateUploadPermissions( | 329 application_context_->GetMetricsServicesManager()->UpdateUploadPermissions( |
265 mayUpload); | 330 mayUpload); |
266 } | 331 } |
OLD | NEW |