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

Side by Side Diff: ios/web/app/web_main_loop.mm

Issue 2797803002: Use TaskScheduler::InitParams to initialize TaskScheduler in web_main_loop.mm. (Closed)
Patch Set: fix-build-error Created 3 years, 8 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/web/chrome_web_client.mm ('k') | ios/web/public/web_client.h » ('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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/web/app/web_main_loop.h" 5 #include "ios/web/app/web_main_loop.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <utility> 9 #include <utility>
10 10
11 #include "base/bind.h" 11 #include "base/bind.h"
12 #include "base/command_line.h" 12 #include "base/command_line.h"
13 #include "base/logging.h" 13 #include "base/logging.h"
14 #include "base/message_loop/message_loop.h" 14 #include "base/message_loop/message_loop.h"
15 #include "base/metrics/histogram_macros.h" 15 #include "base/metrics/histogram_macros.h"
16 #include "base/path_service.h" 16 #include "base/path_service.h"
17 #include "base/power_monitor/power_monitor.h" 17 #include "base/power_monitor/power_monitor.h"
18 #include "base/power_monitor/power_monitor_device_source.h" 18 #include "base/power_monitor/power_monitor_device_source.h"
19 #include "base/process/process_metrics.h" 19 #include "base/process/process_metrics.h"
20 #include "base/system_monitor/system_monitor.h" 20 #include "base/system_monitor/system_monitor.h"
21 #include "base/task_scheduler/initialization_util.h" 21 #include "base/task_scheduler/initialization_util.h"
22 #include "base/task_scheduler/scheduler_worker_pool_params.h" 22 #include "base/task_scheduler/scheduler_worker_pool_params.h"
23 #include "base/task_scheduler/task_scheduler.h" 23 #include "base/task_scheduler/task_scheduler.h"
24 #include "base/task_scheduler/task_traits.h"
25 #include "base/threading/thread_restrictions.h" 24 #include "base/threading/thread_restrictions.h"
26 #import "ios/web/net/cookie_notification_bridge.h" 25 #import "ios/web/net/cookie_notification_bridge.h"
27 #include "ios/web/public/app/web_main_parts.h" 26 #include "ios/web/public/app/web_main_parts.h"
28 #import "ios/web/public/web_client.h" 27 #import "ios/web/public/web_client.h"
29 #include "ios/web/web_thread_impl.h" 28 #include "ios/web/web_thread_impl.h"
30 #include "ios/web/webui/url_data_manager_ios.h" 29 #include "ios/web/webui/url_data_manager_ios.h"
31 #include "net/base/network_change_notifier.h" 30 #include "net/base/network_change_notifier.h"
32 31
33 #if !defined(__has_feature) || !__has_feature(objc_arc) 32 #if !defined(__has_feature) || !__has_feature(objc_arc)
34 #error "This file requires ARC support." 33 #error "This file requires ARC support."
35 #endif 34 #endif
36 35
37 namespace web { 36 namespace web {
38 37
39 namespace { 38 namespace {
40 39
41 enum WorkerPoolType : size_t { 40 std::unique_ptr<base::TaskScheduler::InitParams>
42 BACKGROUND = 0, 41 GetDefaultTaskSchedulerInitParams() {
43 BACKGROUND_BLOCKING,
44 FOREGROUND,
45 FOREGROUND_BLOCKING,
46 WORKER_POOL_COUNT // Always last.
47 };
48
49 std::vector<base::SchedulerWorkerPoolParams>
50 GetDefaultSchedulerWorkerPoolParams() {
51 using StandbyThreadPolicy = 42 using StandbyThreadPolicy =
52 base::SchedulerWorkerPoolParams::StandbyThreadPolicy; 43 base::SchedulerWorkerPoolParams::StandbyThreadPolicy;
53 using ThreadPriority = base::ThreadPriority; 44 return base::MakeUnique<base::TaskScheduler::InitParams>(
54 std::vector<base::SchedulerWorkerPoolParams> params_vector; 45 base::SchedulerWorkerPoolParams(
55 params_vector.emplace_back( 46 StandbyThreadPolicy::ONE,
56 "Background", ThreadPriority::BACKGROUND, StandbyThreadPolicy::ONE, 47 base::RecommendedMaxNumberOfThreadsInPool(2, 8, 0.1, 0),
57 base::RecommendedMaxNumberOfThreadsInPool(2, 8, 0.1, 0), 48 base::TimeDelta::FromSeconds(30)),
58 base::TimeDelta::FromSeconds(30)); 49 base::SchedulerWorkerPoolParams(
59 params_vector.emplace_back( 50 StandbyThreadPolicy::ONE,
60 "BackgroundBlocking", ThreadPriority::BACKGROUND, 51 base::RecommendedMaxNumberOfThreadsInPool(2, 8, 0.1, 0),
61 StandbyThreadPolicy::ONE, 52 base::TimeDelta::FromSeconds(30)),
62 base::RecommendedMaxNumberOfThreadsInPool(2, 8, 0.1, 0), 53 base::SchedulerWorkerPoolParams(
63 base::TimeDelta::FromSeconds(30)); 54 StandbyThreadPolicy::ONE,
64 params_vector.emplace_back( 55 base::RecommendedMaxNumberOfThreadsInPool(3, 8, 0.3, 0),
65 "Foreground", ThreadPriority::NORMAL, StandbyThreadPolicy::ONE, 56 base::TimeDelta::FromSeconds(30)),
66 base::RecommendedMaxNumberOfThreadsInPool(3, 8, 0.3, 0), 57 base::SchedulerWorkerPoolParams(
67 base::TimeDelta::FromSeconds(30)); 58 StandbyThreadPolicy::ONE,
68 params_vector.emplace_back( 59 base::RecommendedMaxNumberOfThreadsInPool(3, 8, 0.3, 0),
69 "ForegroundBlocking", ThreadPriority::NORMAL, StandbyThreadPolicy::ONE, 60 base::TimeDelta::FromSeconds(30)));
70 base::RecommendedMaxNumberOfThreadsInPool(3, 8, 0.3, 0),
71 base::TimeDelta::FromSeconds(30));
72 DCHECK_EQ(WORKER_POOL_COUNT, params_vector.size());
73 return params_vector;
74 }
75
76 // Returns the worker pool index for |traits| defaulting to FOREGROUND or
77 // FOREGROUND_BLOCKING on any other priorities based off of worker pools defined
78 // in GetDefaultSchedulerWorkerPoolParams().
79 size_t DefaultBrowserWorkerPoolIndexForTraits(const base::TaskTraits& traits) {
80 const bool is_background =
81 traits.priority() == base::TaskPriority::BACKGROUND;
82 if (traits.may_block() || traits.with_base_sync_primitives())
83 return is_background ? BACKGROUND_BLOCKING : FOREGROUND_BLOCKING;
84
85 return is_background ? BACKGROUND : FOREGROUND;
86 } 61 }
87 62
88 } // namespace 63 } // namespace
89 64
90 // The currently-running WebMainLoop. There can be one or zero. 65 // The currently-running WebMainLoop. There can be one or zero.
91 // TODO(rohitrao): Desktop uses this to implement 66 // TODO(rohitrao): Desktop uses this to implement
92 // ImmediateShutdownAndExitProcess. If we don't need that functionality, we can 67 // ImmediateShutdownAndExitProcess. If we don't need that functionality, we can
93 // remove this. 68 // remove this.
94 WebMainLoop* g_current_web_main_loop = nullptr; 69 WebMainLoop* g_current_web_main_loop = nullptr;
95 70
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 138
164 int WebMainLoop::PreCreateThreads() { 139 int WebMainLoop::PreCreateThreads() {
165 if (parts_) { 140 if (parts_) {
166 parts_->PreCreateThreads(); 141 parts_->PreCreateThreads();
167 } 142 }
168 143
169 return result_code_; 144 return result_code_;
170 } 145 }
171 146
172 int WebMainLoop::CreateThreads() { 147 int WebMainLoop::CreateThreads() {
173 std::vector<base::SchedulerWorkerPoolParams> params_vector; 148 auto task_scheduler_init_params =
174 base::TaskScheduler::WorkerPoolIndexForTraitsCallback 149 GetWebClient()->GetTaskSchedulerInitParams();
175 index_to_traits_callback; 150 if (!task_scheduler_init_params)
176 GetWebClient()->GetTaskSchedulerInitializationParams( 151 task_scheduler_init_params = GetDefaultTaskSchedulerInitParams();
177 &params_vector, &index_to_traits_callback); 152 DCHECK(task_scheduler_init_params);
178
179 if (params_vector.empty() || index_to_traits_callback.is_null()) {
180 params_vector = GetDefaultSchedulerWorkerPoolParams();
181 index_to_traits_callback =
182 base::Bind(&DefaultBrowserWorkerPoolIndexForTraits);
183 }
184 153
185 base::TaskScheduler::CreateAndSetDefaultTaskScheduler( 154 base::TaskScheduler::CreateAndSetDefaultTaskScheduler(
186 params_vector, index_to_traits_callback); 155 "", *task_scheduler_init_params.get());
187 156
188 GetWebClient()->PerformExperimentalTaskSchedulerRedirections(); 157 GetWebClient()->PerformExperimentalTaskSchedulerRedirections();
189 158
190 base::Thread::Options io_message_loop_options; 159 base::Thread::Options io_message_loop_options;
191 io_message_loop_options.message_loop_type = base::MessageLoop::TYPE_IO; 160 io_message_loop_options.message_loop_type = base::MessageLoop::TYPE_IO;
192 161
193 // Start threads in the order they occur in the WebThread::ID 162 // Start threads in the order they occur in the WebThread::ID
194 // enumeration, except for WebThread::UI which is the main 163 // enumeration, except for WebThread::UI which is the main
195 // thread. 164 // thread.
196 // 165 //
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
337 main_thread_.reset( 306 main_thread_.reset(
338 new WebThreadImpl(WebThread::UI, base::MessageLoop::current())); 307 new WebThreadImpl(WebThread::UI, base::MessageLoop::current()));
339 } 308 }
340 309
341 int WebMainLoop::WebThreadsStarted() { 310 int WebMainLoop::WebThreadsStarted() {
342 cookie_notification_bridge_.reset(new CookieNotificationBridge); 311 cookie_notification_bridge_.reset(new CookieNotificationBridge);
343 return result_code_; 312 return result_code_;
344 } 313 }
345 314
346 } // namespace web 315 } // namespace web
OLDNEW
« no previous file with comments | « ios/chrome/browser/web/chrome_web_client.mm ('k') | ios/web/public/web_client.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698