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 991 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1002 // thread will not be joined on shutdown, and may cause use-after-free if | 1002 // thread will not be joined on shutdown, and may cause use-after-free if |
1003 // anything tries to access objects deleted by AtExitManager, such as | 1003 // anything tries to access objects deleted by AtExitManager, such as |
1004 // non-leaky LazyInstance. | 1004 // non-leaky LazyInstance. |
1005 base::MessageLoop* message_loop = nullptr; | 1005 base::MessageLoop* message_loop = nullptr; |
1006 bool redirect_thread = redirect_nonUInonIO_browser_threads; | 1006 bool redirect_thread = redirect_nonUInonIO_browser_threads; |
1007 | 1007 |
1008 // Otherwise this thread ID will be backed by a SingleThreadTaskRunner using | 1008 // Otherwise this thread ID will be backed by a SingleThreadTaskRunner using |
1009 // |non_ui_non_io_task_runner_traits| (which can be augmented below). | 1009 // |non_ui_non_io_task_runner_traits| (which can be augmented below). |
1010 // TODO(gab): Existing non-UI/non-IO BrowserThreads allow sync primitives so | 1010 // TODO(gab): Existing non-UI/non-IO BrowserThreads allow sync primitives so |
1011 // the initial redirection will as well but they probably don't need to. | 1011 // the initial redirection will as well but they probably don't need to. |
1012 base::TaskTraits non_ui_non_io_task_runner_traits = | 1012 base::TaskTraits non_ui_non_io_task_runner_traits; |
1013 base::TaskTraits().MayBlock().WithBaseSyncPrimitives(); | 1013 |
1014 constexpr base::TaskTraits kUserVisibleTraits = { | |
gab
2017/05/04 14:09:02
// Note: if you're copying these TaskTraits elsewh
fdoray
2017/05/04 18:50:39
Done.
| |
1015 base::MayBlock(), base::WithBaseSyncPrimitives(), | |
1016 base::TaskPriority::USER_VISIBLE, | |
1017 base::TaskShutdownBehavior::BLOCK_SHUTDOWN}; | |
1018 constexpr base::TaskTraits kUserBlockingTraits = { | |
1019 base::MayBlock(), base::WithBaseSyncPrimitives(), | |
1020 base::TaskPriority::USER_BLOCKING, | |
1021 base::TaskShutdownBehavior::BLOCK_SHUTDOWN}; | |
1014 | 1022 |
1015 switch (thread_id) { | 1023 switch (thread_id) { |
1016 case BrowserThread::DB: | 1024 case BrowserThread::DB: |
1017 TRACE_EVENT_BEGIN1("startup", | 1025 TRACE_EVENT_BEGIN1("startup", |
1018 "BrowserMainLoop::CreateThreads:start", | 1026 "BrowserMainLoop::CreateThreads:start", |
1019 "Thread", "BrowserThread::DB"); | 1027 "Thread", "BrowserThread::DB"); |
1020 if (redirect_thread) { | 1028 if (redirect_thread) { |
1021 non_ui_non_io_task_runner_traits | 1029 non_ui_non_io_task_runner_traits = kUserVisibleTraits; |
1022 .WithPriority(base::TaskPriority::USER_VISIBLE) | |
1023 .WithShutdownBehavior(base::TaskShutdownBehavior::BLOCK_SHUTDOWN); | |
1024 } else { | 1030 } else { |
1025 thread_to_start = &db_thread_; | 1031 thread_to_start = &db_thread_; |
1026 options.timer_slack = base::TIMER_SLACK_MAXIMUM; | 1032 options.timer_slack = base::TIMER_SLACK_MAXIMUM; |
1027 } | 1033 } |
1028 break; | 1034 break; |
1029 case BrowserThread::FILE_USER_BLOCKING: | 1035 case BrowserThread::FILE_USER_BLOCKING: |
1030 TRACE_EVENT_BEGIN1("startup", | 1036 TRACE_EVENT_BEGIN1("startup", |
1031 "BrowserMainLoop::CreateThreads:start", | 1037 "BrowserMainLoop::CreateThreads:start", |
1032 "Thread", "BrowserThread::FILE_USER_BLOCKING"); | 1038 "Thread", "BrowserThread::FILE_USER_BLOCKING"); |
1033 if (redirect_thread) { | 1039 if (redirect_thread) { |
1034 non_ui_non_io_task_runner_traits | 1040 non_ui_non_io_task_runner_traits = kUserBlockingTraits; |
1035 .WithPriority(base::TaskPriority::USER_BLOCKING) | |
1036 .WithShutdownBehavior(base::TaskShutdownBehavior::BLOCK_SHUTDOWN); | |
1037 } else { | 1041 } else { |
1038 thread_to_start = &file_user_blocking_thread_; | 1042 thread_to_start = &file_user_blocking_thread_; |
1039 } | 1043 } |
1040 break; | 1044 break; |
1041 case BrowserThread::FILE: | 1045 case BrowserThread::FILE: |
1042 TRACE_EVENT_BEGIN1("startup", | 1046 TRACE_EVENT_BEGIN1("startup", |
1043 "BrowserMainLoop::CreateThreads:start", | 1047 "BrowserMainLoop::CreateThreads:start", |
1044 "Thread", "BrowserThread::FILE"); | 1048 "Thread", "BrowserThread::FILE"); |
1045 | 1049 |
1046 #if defined(OS_WIN) | 1050 #if defined(OS_WIN) |
1047 // On Windows, the FILE thread needs to have a UI message loop which | 1051 // On Windows, the FILE thread needs to have a UI message loop which |
1048 // pumps messages in such a way that Google Update can communicate back | 1052 // pumps messages in such a way that Google Update can communicate back |
1049 // to us. | 1053 // to us. |
1050 // TODO(robliao): Need to support COM in TaskScheduler before | 1054 // TODO(robliao): Need to support COM in TaskScheduler before |
1051 // redirecting the FILE thread on Windows. http://crbug.com/662122 | 1055 // redirecting the FILE thread on Windows. http://crbug.com/662122 |
1052 thread_to_start = &file_thread_; | 1056 thread_to_start = &file_thread_; |
1053 options = ui_message_loop_options; | 1057 options = ui_message_loop_options; |
1054 options.timer_slack = base::TIMER_SLACK_MAXIMUM; | 1058 options.timer_slack = base::TIMER_SLACK_MAXIMUM; |
1055 #else | 1059 #else |
1056 if (redirect_thread) { | 1060 if (redirect_thread) { |
1057 non_ui_non_io_task_runner_traits | 1061 non_ui_non_io_task_runner_traits = kUserVisibleTraits; |
1058 .WithPriority(base::TaskPriority::USER_VISIBLE) | |
1059 .WithShutdownBehavior(base::TaskShutdownBehavior::BLOCK_SHUTDOWN); | |
1060 } else { | 1062 } else { |
1061 thread_to_start = &file_thread_; | 1063 thread_to_start = &file_thread_; |
1062 options = io_message_loop_options; | 1064 options = io_message_loop_options; |
1063 options.timer_slack = base::TIMER_SLACK_MAXIMUM; | 1065 options.timer_slack = base::TIMER_SLACK_MAXIMUM; |
1064 } | 1066 } |
1065 #endif | 1067 #endif |
1066 break; | 1068 break; |
1067 case BrowserThread::PROCESS_LAUNCHER: | 1069 case BrowserThread::PROCESS_LAUNCHER: |
1068 TRACE_EVENT_BEGIN1("startup", | 1070 TRACE_EVENT_BEGIN1("startup", |
1069 "BrowserMainLoop::CreateThreads:start", | 1071 "BrowserMainLoop::CreateThreads:start", |
1070 "Thread", "BrowserThread::PROCESS_LAUNCHER"); | 1072 "Thread", "BrowserThread::PROCESS_LAUNCHER"); |
1071 #if defined(OS_ANDROID) | 1073 #if defined(OS_ANDROID) |
1072 // Android specializes Launcher thread so it is accessible in java. | 1074 // Android specializes Launcher thread so it is accessible in java. |
1073 // Note Android never does clean shutdown, so shutdown use-after-free | 1075 // Note Android never does clean shutdown, so shutdown use-after-free |
1074 // concerns are not a problem in practice. | 1076 // concerns are not a problem in practice. |
1075 redirect_thread = false; | 1077 redirect_thread = false; |
1076 message_loop = android::LauncherThread::GetMessageLoop(); | 1078 message_loop = android::LauncherThread::GetMessageLoop(); |
1077 DCHECK(message_loop); | 1079 DCHECK(message_loop); |
1078 #endif | 1080 #endif |
1079 if (redirect_thread) { | 1081 if (redirect_thread) { |
1080 non_ui_non_io_task_runner_traits | 1082 non_ui_non_io_task_runner_traits = kUserBlockingTraits; |
1081 .WithPriority(base::TaskPriority::USER_BLOCKING) | |
1082 .WithShutdownBehavior(base::TaskShutdownBehavior::BLOCK_SHUTDOWN); | |
1083 } else { | 1083 } else { |
1084 thread_to_start = &process_launcher_thread_; | 1084 thread_to_start = &process_launcher_thread_; |
1085 options.timer_slack = base::TIMER_SLACK_MAXIMUM; | 1085 options.timer_slack = base::TIMER_SLACK_MAXIMUM; |
1086 } | 1086 } |
1087 break; | 1087 break; |
1088 case BrowserThread::CACHE: | 1088 case BrowserThread::CACHE: |
1089 TRACE_EVENT_BEGIN1("startup", | 1089 TRACE_EVENT_BEGIN1("startup", |
1090 "BrowserMainLoop::CreateThreads:start", | 1090 "BrowserMainLoop::CreateThreads:start", |
1091 "Thread", "BrowserThread::CACHE"); | 1091 "Thread", "BrowserThread::CACHE"); |
1092 #if defined(OS_WIN) | 1092 #if defined(OS_WIN) |
1093 // TaskScheduler doesn't support async I/O on Windows as CACHE thread is | 1093 // TaskScheduler doesn't support async I/O on Windows as CACHE thread is |
1094 // the only user and this use case is going away in | 1094 // the only user and this use case is going away in |
1095 // https://codereview.chromium.org/2216583003/. | 1095 // https://codereview.chromium.org/2216583003/. |
1096 // TODO(gavinp): Remove this ifdef (and thus enable redirection of the | 1096 // TODO(gavinp): Remove this ifdef (and thus enable redirection of the |
1097 // CACHE thread on Windows) once that CL lands. | 1097 // CACHE thread on Windows) once that CL lands. |
1098 thread_to_start = &cache_thread_; | 1098 thread_to_start = &cache_thread_; |
1099 options = io_message_loop_options; | 1099 options = io_message_loop_options; |
1100 options.timer_slack = base::TIMER_SLACK_MAXIMUM; | 1100 options.timer_slack = base::TIMER_SLACK_MAXIMUM; |
1101 #else // OS_WIN | 1101 #else // OS_WIN |
1102 if (redirect_thread) { | 1102 if (redirect_thread) { |
1103 non_ui_non_io_task_runner_traits | 1103 non_ui_non_io_task_runner_traits = kUserBlockingTraits; |
1104 .WithPriority(base::TaskPriority::USER_BLOCKING) | |
1105 .WithShutdownBehavior(base::TaskShutdownBehavior::BLOCK_SHUTDOWN); | |
1106 } else { | 1104 } else { |
1107 thread_to_start = &cache_thread_; | 1105 thread_to_start = &cache_thread_; |
1108 options.timer_slack = base::TIMER_SLACK_MAXIMUM; | 1106 options.timer_slack = base::TIMER_SLACK_MAXIMUM; |
1109 } | 1107 } |
1110 #endif // OS_WIN | 1108 #endif // OS_WIN |
1111 break; | 1109 break; |
1112 case BrowserThread::IO: | 1110 case BrowserThread::IO: |
1113 TRACE_EVENT_BEGIN1("startup", | 1111 TRACE_EVENT_BEGIN1("startup", |
1114 "BrowserMainLoop::CreateThreads:start", | 1112 "BrowserMainLoop::CreateThreads:start", |
1115 "Thread", "BrowserThread::IO"); | 1113 "Thread", "BrowserThread::IO"); |
(...skipping 652 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1768 BrowserThread::GetTaskRunnerForThread(BrowserThread::FILE), | 1766 BrowserThread::GetTaskRunnerForThread(BrowserThread::FILE), |
1769 MediaInternals::GetInstance()); | 1767 MediaInternals::GetInstance()); |
1770 } | 1768 } |
1771 CHECK(audio_manager_); | 1769 CHECK(audio_manager_); |
1772 | 1770 |
1773 audio_system_ = media::AudioSystemImpl::Create(audio_manager_.get()); | 1771 audio_system_ = media::AudioSystemImpl::Create(audio_manager_.get()); |
1774 CHECK(audio_system_); | 1772 CHECK(audio_system_); |
1775 } | 1773 } |
1776 | 1774 |
1777 } // namespace content | 1775 } // namespace content |
OLD | NEW |