OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "content/browser/browser_main_loop.h" | 5 #include "content/browser/browser_main_loop.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 #include <utility> | 10 #include <utility> |
(...skipping 12 matching lines...) Expand all Loading... | |
23 #include "base/metrics/histogram_macros.h" | 23 #include "base/metrics/histogram_macros.h" |
24 #include "base/metrics/user_metrics.h" | 24 #include "base/metrics/user_metrics.h" |
25 #include "base/pending_task.h" | 25 #include "base/pending_task.h" |
26 #include "base/power_monitor/power_monitor.h" | 26 #include "base/power_monitor/power_monitor.h" |
27 #include "base/power_monitor/power_monitor_device_source.h" | 27 #include "base/power_monitor/power_monitor_device_source.h" |
28 #include "base/process/process_metrics.h" | 28 #include "base/process/process_metrics.h" |
29 #include "base/run_loop.h" | 29 #include "base/run_loop.h" |
30 #include "base/single_thread_task_runner.h" | 30 #include "base/single_thread_task_runner.h" |
31 #include "base/strings/string_number_conversions.h" | 31 #include "base/strings/string_number_conversions.h" |
32 #include "base/strings/string_split.h" | 32 #include "base/strings/string_split.h" |
33 #include "base/synchronization/waitable_event.h" | |
33 #include "base/system_monitor/system_monitor.h" | 34 #include "base/system_monitor/system_monitor.h" |
35 #include "base/task_scheduler/post_task.h" | |
36 #include "base/task_scheduler/task_traits.h" | |
34 #include "base/threading/thread_restrictions.h" | 37 #include "base/threading/thread_restrictions.h" |
35 #include "base/threading/thread_task_runner_handle.h" | 38 #include "base/threading/thread_task_runner_handle.h" |
36 #include "base/timer/hi_res_timer_manager.h" | 39 #include "base/timer/hi_res_timer_manager.h" |
37 #include "base/trace_event/memory_dump_manager.h" | 40 #include "base/trace_event/memory_dump_manager.h" |
38 #include "base/trace_event/trace_event.h" | 41 #include "base/trace_event/trace_event.h" |
39 #include "build/build_config.h" | 42 #include "build/build_config.h" |
40 #include "components/discardable_memory/service/discardable_shared_memory_manage r.h" | 43 #include "components/discardable_memory/service/discardable_shared_memory_manage r.h" |
41 #include "components/tracing/browser/trace_config_file.h" | 44 #include "components/tracing/browser/trace_config_file.h" |
42 #include "components/tracing/common/process_metrics_memory_dump_provider.h" | 45 #include "components/tracing/common/process_metrics_memory_dump_provider.h" |
43 #include "components/tracing/common/trace_to_console.h" | 46 #include "components/tracing/common/trace_to_console.h" |
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
291 void OnStoppedStartupTracing(const base::FilePath& trace_file) { | 294 void OnStoppedStartupTracing(const base::FilePath& trace_file) { |
292 VLOG(0) << "Completed startup tracing to " << trace_file.value(); | 295 VLOG(0) << "Completed startup tracing to " << trace_file.value(); |
293 } | 296 } |
294 | 297 |
295 // Disable optimizations for this block of functions so the compiler doesn't | 298 // Disable optimizations for this block of functions so the compiler doesn't |
296 // merge them all together. This makes it possible to tell what thread was | 299 // merge them all together. This makes it possible to tell what thread was |
297 // unresponsive by inspecting the callstack. | 300 // unresponsive by inspecting the callstack. |
298 MSVC_DISABLE_OPTIMIZE() | 301 MSVC_DISABLE_OPTIMIZE() |
299 MSVC_PUSH_DISABLE_WARNING(4748) | 302 MSVC_PUSH_DISABLE_WARNING(4748) |
300 | 303 |
301 NOINLINE void ResetThread_DB(std::unique_ptr<BrowserProcessSubThread> thread) { | 304 // Takes ownership of |task_runner| and blocks until it's empty. |
305 void FlushThreadTaskRunner( | |
306 scoped_refptr<base::SingleThreadTaskRunner> task_runner) { | |
307 base::WaitableEvent thread_terminated( | |
308 base::WaitableEvent::ResetPolicy::MANUAL, | |
309 base::WaitableEvent::InitialState::NOT_SIGNALED); | |
310 task_runner->PostTask(FROM_HERE, | |
311 base::Bind(&base::WaitableEvent::Signal, | |
312 base::Unretained(&thread_terminated))); | |
313 thread_terminated.Wait(); | |
314 } | |
315 | |
316 NOINLINE void ResetThread_DB( | |
317 std::unique_ptr<BrowserProcessSubThread> thread, | |
318 scoped_refptr<base::SingleThreadTaskRunner> task_runner) { | |
319 DCHECK(!thread || !task_runner); | |
Avi (use Gerrit)
2016/11/08 16:16:15
This checks that we don't have both.
Do we want t
gab
2016/11/08 20:40:44
Right, made this
DCHECK((thread && !task_runner) |
| |
302 volatile int inhibit_comdat = __LINE__; | 320 volatile int inhibit_comdat = __LINE__; |
303 ALLOW_UNUSED_LOCAL(inhibit_comdat); | 321 ALLOW_UNUSED_LOCAL(inhibit_comdat); |
304 thread.reset(); | 322 if (thread) { |
323 thread.reset(); | |
324 } else { | |
325 BrowserThreadImpl::RedirectThreadIDToTaskRunner(BrowserThread::DB, nullptr); | |
326 FlushThreadTaskRunner(std::move(task_runner)); | |
327 } | |
305 } | 328 } |
306 | 329 |
307 NOINLINE void ResetThread_FILE( | 330 NOINLINE void ResetThread_FILE( |
308 std::unique_ptr<BrowserProcessSubThread> thread) { | 331 std::unique_ptr<BrowserProcessSubThread> thread, |
332 scoped_refptr<base::SingleThreadTaskRunner> task_runner) { | |
333 DCHECK(!thread || !task_runner); | |
309 volatile int inhibit_comdat = __LINE__; | 334 volatile int inhibit_comdat = __LINE__; |
310 ALLOW_UNUSED_LOCAL(inhibit_comdat); | 335 ALLOW_UNUSED_LOCAL(inhibit_comdat); |
311 thread.reset(); | 336 if (thread) { |
337 thread.reset(); | |
338 } else { | |
339 BrowserThreadImpl::RedirectThreadIDToTaskRunner(BrowserThread::FILE, | |
340 nullptr); | |
341 FlushThreadTaskRunner(std::move(task_runner)); | |
342 } | |
312 } | 343 } |
313 | 344 |
314 NOINLINE void ResetThread_FILE_USER_BLOCKING( | 345 NOINLINE void ResetThread_FILE_USER_BLOCKING( |
315 std::unique_ptr<BrowserProcessSubThread> thread) { | 346 std::unique_ptr<BrowserProcessSubThread> thread, |
347 scoped_refptr<base::SingleThreadTaskRunner> task_runner) { | |
348 DCHECK(!thread || !task_runner); | |
316 volatile int inhibit_comdat = __LINE__; | 349 volatile int inhibit_comdat = __LINE__; |
317 ALLOW_UNUSED_LOCAL(inhibit_comdat); | 350 ALLOW_UNUSED_LOCAL(inhibit_comdat); |
318 thread.reset(); | 351 if (thread) { |
352 thread.reset(); | |
353 } else { | |
354 BrowserThreadImpl::RedirectThreadIDToTaskRunner( | |
355 BrowserThread::FILE_USER_BLOCKING, nullptr); | |
356 FlushThreadTaskRunner(std::move(task_runner)); | |
357 } | |
319 } | 358 } |
320 | 359 |
321 NOINLINE void ResetThread_PROCESS_LAUNCHER( | 360 NOINLINE void ResetThread_PROCESS_LAUNCHER( |
322 std::unique_ptr<BrowserProcessSubThread> thread) { | 361 std::unique_ptr<BrowserProcessSubThread> thread, |
362 scoped_refptr<base::SingleThreadTaskRunner> task_runner) { | |
363 DCHECK(!thread || !task_runner); | |
323 volatile int inhibit_comdat = __LINE__; | 364 volatile int inhibit_comdat = __LINE__; |
324 ALLOW_UNUSED_LOCAL(inhibit_comdat); | 365 ALLOW_UNUSED_LOCAL(inhibit_comdat); |
325 thread.reset(); | 366 if (thread) { |
367 thread.reset(); | |
368 } else { | |
369 BrowserThreadImpl::RedirectThreadIDToTaskRunner( | |
370 BrowserThread::PROCESS_LAUNCHER, nullptr); | |
371 FlushThreadTaskRunner(std::move(task_runner)); | |
372 } | |
326 } | 373 } |
327 | 374 |
328 NOINLINE void ResetThread_CACHE( | 375 NOINLINE void ResetThread_CACHE( |
329 std::unique_ptr<BrowserProcessSubThread> thread) { | 376 std::unique_ptr<BrowserProcessSubThread> thread, |
377 scoped_refptr<base::SingleThreadTaskRunner> task_runner) { | |
378 DCHECK(!thread || !task_runner); | |
330 volatile int inhibit_comdat = __LINE__; | 379 volatile int inhibit_comdat = __LINE__; |
331 ALLOW_UNUSED_LOCAL(inhibit_comdat); | 380 ALLOW_UNUSED_LOCAL(inhibit_comdat); |
332 thread.reset(); | 381 if (thread) { |
382 thread.reset(); | |
383 } else { | |
384 BrowserThreadImpl::RedirectThreadIDToTaskRunner(BrowserThread::CACHE, | |
385 nullptr); | |
386 FlushThreadTaskRunner(std::move(task_runner)); | |
387 } | |
333 } | 388 } |
334 | 389 |
335 NOINLINE void ResetThread_IO(std::unique_ptr<BrowserProcessSubThread> thread) { | 390 NOINLINE void ResetThread_IO(std::unique_ptr<BrowserProcessSubThread> thread) { |
336 volatile int inhibit_comdat = __LINE__; | 391 volatile int inhibit_comdat = __LINE__; |
337 ALLOW_UNUSED_LOCAL(inhibit_comdat); | 392 ALLOW_UNUSED_LOCAL(inhibit_comdat); |
338 thread.reset(); | 393 thread.reset(); |
339 } | 394 } |
340 | 395 |
341 NOINLINE void ResetThread_IndexedDb(std::unique_ptr<base::Thread> thread) { | 396 NOINLINE void ResetThread_IndexedDb(std::unique_ptr<base::Thread> thread) { |
342 volatile int inhibit_comdat = __LINE__; | 397 volatile int inhibit_comdat = __LINE__; |
(...skipping 517 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
860 ui_message_loop_options.message_loop_type = base::MessageLoop::TYPE_UI; | 915 ui_message_loop_options.message_loop_type = base::MessageLoop::TYPE_UI; |
861 | 916 |
862 // Start threads in the order they occur in the BrowserThread::ID | 917 // Start threads in the order they occur in the BrowserThread::ID |
863 // enumeration, except for BrowserThread::UI which is the main | 918 // enumeration, except for BrowserThread::UI which is the main |
864 // thread. | 919 // thread. |
865 // | 920 // |
866 // Must be size_t so we can increment it. | 921 // Must be size_t so we can increment it. |
867 for (size_t thread_id = BrowserThread::UI + 1; | 922 for (size_t thread_id = BrowserThread::UI + 1; |
868 thread_id < BrowserThread::ID_COUNT; | 923 thread_id < BrowserThread::ID_COUNT; |
869 ++thread_id) { | 924 ++thread_id) { |
870 std::unique_ptr<BrowserProcessSubThread>* thread_to_start = NULL; | 925 // If this thread ID is backed by a real thread, |thread_to_start| will be |
926 // set to the appropriate |BrowserProcessSubThread*|. And |options| can be | |
927 // updated away from its default. | |
928 std::unique_ptr<BrowserProcessSubThread>* thread_to_start = nullptr; | |
871 base::Thread::Options options; | 929 base::Thread::Options options; |
872 | 930 |
931 // Otherwise this thread ID will be backed by a SingleThreadTaskRunner in | |
932 // which case |task_runner_to_create| will be set to the appropriate | |
933 // |SingleThreadTaskRunner*| and |task_runner_traits| can be updated away | |
934 // from its default. |execution_mode| defaults to |SINGLE_THREADED| as-is | |
935 // appropriate to map most old browser threads but can also be updated in | |
936 // the switch statement below if a thread has specific requirements. | |
937 scoped_refptr<base::SingleThreadTaskRunner>* task_runner_to_create = | |
938 nullptr; | |
939 base::TaskTraits task_runner_traits; | |
940 | |
941 const bool redirect_nonUInonIO_browser_threads = | |
942 GetContentClient() | |
943 ->browser() | |
944 ->RedirectNonUINonIOBrowserThreadsToTaskScheduler(); | |
945 | |
873 switch (thread_id) { | 946 switch (thread_id) { |
874 case BrowserThread::DB: | 947 case BrowserThread::DB: |
875 TRACE_EVENT_BEGIN1("startup", | 948 TRACE_EVENT_BEGIN1("startup", |
876 "BrowserMainLoop::CreateThreads:start", | 949 "BrowserMainLoop::CreateThreads:start", |
877 "Thread", "BrowserThread::DB"); | 950 "Thread", "BrowserThread::DB"); |
878 thread_to_start = &db_thread_; | 951 if (redirect_nonUInonIO_browser_threads) { |
879 options.timer_slack = base::TIMER_SLACK_MAXIMUM; | 952 task_runner_to_create = &db_task_runner_; |
953 task_runner_traits.WithFileIO() | |
954 .WithPriority(base::TaskPriority::USER_VISIBLE) | |
955 .WithShutdownBehavior(base::TaskShutdownBehavior::BLOCK_SHUTDOWN); | |
956 } else { | |
957 thread_to_start = &db_thread_; | |
958 options.timer_slack = base::TIMER_SLACK_MAXIMUM; | |
959 } | |
880 break; | 960 break; |
881 case BrowserThread::FILE_USER_BLOCKING: | 961 case BrowserThread::FILE_USER_BLOCKING: |
882 TRACE_EVENT_BEGIN1("startup", | 962 TRACE_EVENT_BEGIN1("startup", |
883 "BrowserMainLoop::CreateThreads:start", | 963 "BrowserMainLoop::CreateThreads:start", |
884 "Thread", "BrowserThread::FILE_USER_BLOCKING"); | 964 "Thread", "BrowserThread::FILE_USER_BLOCKING"); |
885 thread_to_start = &file_user_blocking_thread_; | 965 if (redirect_nonUInonIO_browser_threads) { |
966 task_runner_to_create = &file_user_blocking_task_runner_; | |
967 task_runner_traits.WithFileIO() | |
968 .WithPriority(base::TaskPriority::USER_BLOCKING) | |
969 .WithShutdownBehavior(base::TaskShutdownBehavior::BLOCK_SHUTDOWN); | |
970 } else { | |
971 thread_to_start = &file_user_blocking_thread_; | |
972 } | |
886 break; | 973 break; |
887 case BrowserThread::FILE: | 974 case BrowserThread::FILE: |
888 TRACE_EVENT_BEGIN1("startup", | 975 TRACE_EVENT_BEGIN1("startup", |
889 "BrowserMainLoop::CreateThreads:start", | 976 "BrowserMainLoop::CreateThreads:start", |
890 "Thread", "BrowserThread::FILE"); | 977 "Thread", "BrowserThread::FILE"); |
978 | |
979 #if defined(OS_WIN) | |
980 // On Windows, the FILE thread needs to be have a UI message loop which | |
981 // pumps messages in such a way that Google Update can communicate back | |
982 // to us. | |
983 // TODO(robliao): Need to support COM in TaskScheduler before | |
984 // redirecting the FILE thread on Windows. http://crbug.com/662122 | |
985 // TODO(gab): Also need to support clipboard (see below). | |
891 thread_to_start = &file_thread_; | 986 thread_to_start = &file_thread_; |
892 #if defined(OS_WIN) | |
893 // On Windows, the FILE thread needs to be have a UI message loop | |
894 // which pumps messages in such a way that Google Update can | |
895 // communicate back to us. | |
896 options = ui_message_loop_options; | 987 options = ui_message_loop_options; |
897 #else | 988 #else |
898 options = io_message_loop_options; | 989 if (redirect_nonUInonIO_browser_threads) { |
990 task_runner_to_create = &file_task_runner_; | |
991 task_runner_traits.WithFileIO() | |
992 .WithPriority(base::TaskPriority::BACKGROUND) | |
993 .WithShutdownBehavior(base::TaskShutdownBehavior::BLOCK_SHUTDOWN); | |
994 } else { | |
995 thread_to_start = &file_thread_; | |
996 options = io_message_loop_options; | |
997 options.timer_slack = base::TIMER_SLACK_MAXIMUM; | |
998 } | |
899 #endif | 999 #endif |
900 options.timer_slack = base::TIMER_SLACK_MAXIMUM; | |
901 break; | 1000 break; |
902 case BrowserThread::PROCESS_LAUNCHER: | 1001 case BrowserThread::PROCESS_LAUNCHER: |
903 TRACE_EVENT_BEGIN1("startup", | 1002 TRACE_EVENT_BEGIN1("startup", |
904 "BrowserMainLoop::CreateThreads:start", | 1003 "BrowserMainLoop::CreateThreads:start", |
905 "Thread", "BrowserThread::PROCESS_LAUNCHER"); | 1004 "Thread", "BrowserThread::PROCESS_LAUNCHER"); |
906 thread_to_start = &process_launcher_thread_; | 1005 if (redirect_nonUInonIO_browser_threads) { |
907 options.timer_slack = base::TIMER_SLACK_MAXIMUM; | 1006 task_runner_to_create = &process_launcher_task_runner_; |
1007 task_runner_traits.WithFileIO() | |
1008 .WithPriority(base::TaskPriority::USER_BLOCKING) | |
1009 .WithShutdownBehavior(base::TaskShutdownBehavior::BLOCK_SHUTDOWN); | |
1010 } else { | |
1011 thread_to_start = &process_launcher_thread_; | |
1012 options.timer_slack = base::TIMER_SLACK_MAXIMUM; | |
1013 } | |
908 break; | 1014 break; |
909 case BrowserThread::CACHE: | 1015 case BrowserThread::CACHE: |
910 TRACE_EVENT_BEGIN1("startup", | 1016 TRACE_EVENT_BEGIN1("startup", |
911 "BrowserMainLoop::CreateThreads:start", | 1017 "BrowserMainLoop::CreateThreads:start", |
912 "Thread", "BrowserThread::CACHE"); | 1018 "Thread", "BrowserThread::CACHE"); |
1019 #if defined(OS_WIN) | |
1020 // TaskScheduler doesn't support async I/O on Windows as CACHE thread is | |
1021 // the only user and this use case is going away in | |
1022 // https://codereview.chromium.org/2216583003/. TODO(gavinp): Remove | |
1023 // this ifdef (and thus enable redirection of the CACHE thread on | |
1024 // Windows) once that CL lands. | |
913 thread_to_start = &cache_thread_; | 1025 thread_to_start = &cache_thread_; |
914 #if defined(OS_WIN) | |
915 options = io_message_loop_options; | 1026 options = io_message_loop_options; |
916 #endif // defined(OS_WIN) | |
917 options.timer_slack = base::TIMER_SLACK_MAXIMUM; | 1027 options.timer_slack = base::TIMER_SLACK_MAXIMUM; |
1028 #else // OS_WIN | |
1029 if (redirect_nonUInonIO_browser_threads) { | |
1030 task_runner_to_create = &cache_task_runner_; | |
1031 task_runner_traits.WithFileIO() | |
1032 .WithPriority(base::TaskPriority::USER_BLOCKING) | |
1033 .WithShutdownBehavior(base::TaskShutdownBehavior::BLOCK_SHUTDOWN); | |
1034 } else { | |
1035 thread_to_start = &cache_thread_; | |
1036 options.timer_slack = base::TIMER_SLACK_MAXIMUM; | |
1037 } | |
1038 #endif // OS_WIN | |
918 break; | 1039 break; |
919 case BrowserThread::IO: | 1040 case BrowserThread::IO: |
920 TRACE_EVENT_BEGIN1("startup", | 1041 TRACE_EVENT_BEGIN1("startup", |
921 "BrowserMainLoop::CreateThreads:start", | 1042 "BrowserMainLoop::CreateThreads:start", |
922 "Thread", "BrowserThread::IO"); | 1043 "Thread", "BrowserThread::IO"); |
923 thread_to_start = &io_thread_; | 1044 thread_to_start = &io_thread_; |
924 options = io_message_loop_options; | 1045 options = io_message_loop_options; |
925 #if defined(OS_ANDROID) || defined(OS_CHROMEOS) | 1046 #if defined(OS_ANDROID) || defined(OS_CHROMEOS) |
926 // Up the priority of the |io_thread_| as some of its IPCs relate to | 1047 // Up the priority of the |io_thread_| as some of its IPCs relate to |
927 // display tasks. | 1048 // display tasks. |
928 options.priority = base::ThreadPriority::DISPLAY; | 1049 options.priority = base::ThreadPriority::DISPLAY; |
929 #endif | 1050 #endif |
930 break; | 1051 break; |
931 case BrowserThread::UI: | 1052 case BrowserThread::UI: // Falls through. |
932 case BrowserThread::ID_COUNT: | 1053 case BrowserThread::ID_COUNT: // Falls through. |
933 default: | |
934 NOTREACHED(); | 1054 NOTREACHED(); |
935 break; | 1055 break; |
936 } | 1056 } |
937 | 1057 |
938 BrowserThread::ID id = static_cast<BrowserThread::ID>(thread_id); | 1058 BrowserThread::ID id = static_cast<BrowserThread::ID>(thread_id); |
939 | 1059 |
940 if (thread_to_start) { | 1060 if (thread_to_start) { |
1061 DCHECK(!task_runner_to_create); | |
941 (*thread_to_start).reset(new BrowserProcessSubThread(id)); | 1062 (*thread_to_start).reset(new BrowserProcessSubThread(id)); |
942 if (!(*thread_to_start)->StartWithOptions(options)) { | 1063 if (!(*thread_to_start)->StartWithOptions(options)) { |
943 LOG(FATAL) << "Failed to start the browser thread: id == " << id; | 1064 LOG(FATAL) << "Failed to start the browser thread: id == " << id; |
944 } | 1065 } |
1066 } else if (task_runner_to_create) { | |
1067 *task_runner_to_create = | |
1068 base::CreateSingleThreadTaskRunnerWithTraits(task_runner_traits); | |
1069 DCHECK(*task_runner_to_create); | |
1070 BrowserThreadImpl::RedirectThreadIDToTaskRunner( | |
1071 id, task_runner_to_create->get()); | |
945 } else { | 1072 } else { |
946 NOTREACHED(); | 1073 NOTREACHED(); |
947 } | 1074 } |
948 | 1075 |
949 TRACE_EVENT_END0("startup", "BrowserMainLoop::CreateThreads:start"); | 1076 TRACE_EVENT_END0("startup", "BrowserMainLoop::CreateThreads:start"); |
950 } | 1077 } |
951 created_threads_ = true; | 1078 created_threads_ = true; |
952 return result_code_; | 1079 return result_code_; |
953 } | 1080 } |
954 | 1081 |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1082 // - The IO thread is the only user of the CACHE thread. | 1209 // - The IO thread is the only user of the CACHE thread. |
1083 // | 1210 // |
1084 // - The PROCESS_LAUNCHER thread must be stopped after IO in case | 1211 // - The PROCESS_LAUNCHER thread must be stopped after IO in case |
1085 // the IO thread posted a task to terminate a process on the | 1212 // the IO thread posted a task to terminate a process on the |
1086 // process launcher thread. | 1213 // process launcher thread. |
1087 // | 1214 // |
1088 // - (Not sure why DB stops last.) | 1215 // - (Not sure why DB stops last.) |
1089 switch (thread_id) { | 1216 switch (thread_id) { |
1090 case BrowserThread::DB: { | 1217 case BrowserThread::DB: { |
1091 TRACE_EVENT0("shutdown", "BrowserMainLoop::Subsystem:DBThread"); | 1218 TRACE_EVENT0("shutdown", "BrowserMainLoop::Subsystem:DBThread"); |
1092 ResetThread_DB(std::move(db_thread_)); | 1219 ResetThread_DB(std::move(db_thread_), std::move(db_task_runner_)); |
1093 break; | 1220 break; |
1094 } | 1221 } |
1095 case BrowserThread::FILE: { | 1222 case BrowserThread::FILE: { |
1096 TRACE_EVENT0("shutdown", "BrowserMainLoop::Subsystem:FileThread"); | 1223 TRACE_EVENT0("shutdown", "BrowserMainLoop::Subsystem:FileThread"); |
1097 // Clean up state that lives on or uses the file_thread_ before | 1224 // Clean up state that lives on or uses the file_thread_ before it goes |
1098 // it goes away. | 1225 // away. |
1099 save_file_manager_->Shutdown(); | 1226 save_file_manager_->Shutdown(); |
1100 ResetThread_FILE(std::move(file_thread_)); | 1227 ResetThread_FILE(std::move(file_thread_), std::move(file_task_runner_)); |
1101 break; | 1228 break; |
1102 } | 1229 } |
1103 case BrowserThread::FILE_USER_BLOCKING: { | 1230 case BrowserThread::FILE_USER_BLOCKING: { |
1104 TRACE_EVENT0("shutdown", | 1231 TRACE_EVENT0("shutdown", |
1105 "BrowserMainLoop::Subsystem:FileUserBlockingThread"); | 1232 "BrowserMainLoop::Subsystem:FileUserBlockingThread"); |
1106 ResetThread_FILE_USER_BLOCKING(std::move(file_user_blocking_thread_)); | 1233 ResetThread_FILE_USER_BLOCKING( |
1234 std::move(file_user_blocking_thread_), | |
1235 std::move(file_user_blocking_task_runner_)); | |
1107 break; | 1236 break; |
1108 } | 1237 } |
1109 case BrowserThread::PROCESS_LAUNCHER: { | 1238 case BrowserThread::PROCESS_LAUNCHER: { |
1110 TRACE_EVENT0("shutdown", "BrowserMainLoop::Subsystem:LauncherThread"); | 1239 TRACE_EVENT0("shutdown", "BrowserMainLoop::Subsystem:LauncherThread"); |
1111 ResetThread_PROCESS_LAUNCHER(std::move(process_launcher_thread_)); | 1240 ResetThread_PROCESS_LAUNCHER(std::move(process_launcher_thread_), |
1241 std::move(process_launcher_task_runner_)); | |
1112 break; | 1242 break; |
1113 } | 1243 } |
1114 case BrowserThread::CACHE: { | 1244 case BrowserThread::CACHE: { |
1115 TRACE_EVENT0("shutdown", "BrowserMainLoop::Subsystem:CacheThread"); | 1245 TRACE_EVENT0("shutdown", "BrowserMainLoop::Subsystem:CacheThread"); |
1116 ResetThread_CACHE(std::move(cache_thread_)); | 1246 ResetThread_CACHE(std::move(cache_thread_), |
1247 std::move(cache_task_runner_)); | |
1117 break; | 1248 break; |
1118 } | 1249 } |
1119 case BrowserThread::IO: { | 1250 case BrowserThread::IO: { |
1120 TRACE_EVENT0("shutdown", "BrowserMainLoop::Subsystem:IOThread"); | 1251 TRACE_EVENT0("shutdown", "BrowserMainLoop::Subsystem:IOThread"); |
1121 ResetThread_IO(std::move(io_thread_)); | 1252 ResetThread_IO(std::move(io_thread_)); |
1122 break; | 1253 break; |
1123 } | 1254 } |
1124 case BrowserThread::UI: | 1255 case BrowserThread::UI: |
1125 case BrowserThread::ID_COUNT: | 1256 case BrowserThread::ID_COUNT: |
1126 default: | |
1127 NOTREACHED(); | 1257 NOTREACHED(); |
1128 break; | 1258 break; |
1129 } | 1259 } |
1130 } | 1260 } |
1131 { | 1261 { |
1132 TRACE_EVENT0("shutdown", "BrowserMainLoop::Subsystem:IndexedDBThread"); | 1262 TRACE_EVENT0("shutdown", "BrowserMainLoop::Subsystem:IndexedDBThread"); |
1133 ResetThread_IndexedDb(std::move(indexed_db_thread_)); | 1263 ResetThread_IndexedDb(std::move(indexed_db_thread_)); |
1134 } | 1264 } |
1135 | 1265 |
1136 // Close the blocking I/O pool after the other threads. Other threads such | 1266 // Close the blocking I/O pool after the other threads. Other threads such |
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1354 save_file_manager_ = new SaveFileManager(); | 1484 save_file_manager_ = new SaveFileManager(); |
1355 } | 1485 } |
1356 | 1486 |
1357 // Alert the clipboard class to which threads are allowed to access the | 1487 // Alert the clipboard class to which threads are allowed to access the |
1358 // clipboard: | 1488 // clipboard: |
1359 std::vector<base::PlatformThreadId> allowed_clipboard_threads; | 1489 std::vector<base::PlatformThreadId> allowed_clipboard_threads; |
1360 // The current thread is the UI thread. | 1490 // The current thread is the UI thread. |
1361 allowed_clipboard_threads.push_back(base::PlatformThread::CurrentId()); | 1491 allowed_clipboard_threads.push_back(base::PlatformThread::CurrentId()); |
1362 #if defined(OS_WIN) | 1492 #if defined(OS_WIN) |
1363 // On Windows, clipboards are also used on the FILE or IO threads. | 1493 // On Windows, clipboards are also used on the FILE or IO threads. |
1494 // TODO(gab): Figure out how to selectively allow clipboard via TaskTraits for | |
1495 // TaskScheduler. http://crbug.com/662055 | |
1364 allowed_clipboard_threads.push_back(file_thread_->GetThreadId()); | 1496 allowed_clipboard_threads.push_back(file_thread_->GetThreadId()); |
1365 allowed_clipboard_threads.push_back(io_thread_->GetThreadId()); | 1497 allowed_clipboard_threads.push_back(io_thread_->GetThreadId()); |
1366 #endif | 1498 #endif |
1367 ui::Clipboard::SetAllowedThreads(allowed_clipboard_threads); | 1499 ui::Clipboard::SetAllowedThreads(allowed_clipboard_threads); |
1368 | 1500 |
1369 // When running the GPU thread in-process, avoid optimistically starting it | 1501 // When running the GPU thread in-process, avoid optimistically starting it |
1370 // since creating the GPU thread races against creation of the one-and-only | 1502 // since creating the GPU thread races against creation of the one-and-only |
1371 // ChildProcess instance which is created by the renderer thread. | 1503 // ChildProcess instance which is created by the renderer thread. |
1372 if (GpuDataManagerImpl::GetInstance()->GpuAccessAllowed(NULL) && | 1504 if (GpuDataManagerImpl::GetInstance()->GpuAccessAllowed(NULL) && |
1373 !established_gpu_channel && always_uses_gpu && !UsingInProcessGpu() && | 1505 !established_gpu_channel && always_uses_gpu && !UsingInProcessGpu() && |
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1599 scoped_refptr<base::SingleThreadTaskRunner> worker_task_runner = | 1731 scoped_refptr<base::SingleThreadTaskRunner> worker_task_runner = |
1600 audio_thread_->task_runner(); | 1732 audio_thread_->task_runner(); |
1601 audio_manager_ = media::AudioManager::Create(std::move(audio_task_runner), | 1733 audio_manager_ = media::AudioManager::Create(std::move(audio_task_runner), |
1602 std::move(worker_task_runner), | 1734 std::move(worker_task_runner), |
1603 MediaInternals::GetInstance()); | 1735 MediaInternals::GetInstance()); |
1604 } | 1736 } |
1605 CHECK(audio_manager_); | 1737 CHECK(audio_manager_); |
1606 } | 1738 } |
1607 | 1739 |
1608 } // namespace content | 1740 } // namespace content |
OLD | NEW |