Chromium Code Reviews| 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 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 116 | 116 |
| 117 #if defined(USE_AURA) | 117 #if defined(USE_AURA) |
| 118 #include "content/public/browser/context_factory.h" | 118 #include "content/public/browser/context_factory.h" |
| 119 #include "ui/aura/env.h" | 119 #include "ui/aura/env.h" |
| 120 #endif | 120 #endif |
| 121 | 121 |
| 122 #if defined(OS_ANDROID) | 122 #if defined(OS_ANDROID) |
| 123 #include "base/android/jni_android.h" | 123 #include "base/android/jni_android.h" |
| 124 #include "components/tracing/common/graphics_memory_dump_provider_android.h" | 124 #include "components/tracing/common/graphics_memory_dump_provider_android.h" |
| 125 #include "content/browser/android/browser_startup_controller.h" | 125 #include "content/browser/android/browser_startup_controller.h" |
| 126 #include "content/browser/android/launcher_thread.h" | |
| 126 #include "content/browser/android/scoped_surface_request_manager.h" | 127 #include "content/browser/android/scoped_surface_request_manager.h" |
| 127 #include "content/browser/android/tracing_controller_android.h" | 128 #include "content/browser/android/tracing_controller_android.h" |
| 128 #include "content/browser/media/android/browser_media_player_manager.h" | 129 #include "content/browser/media/android/browser_media_player_manager.h" |
| 129 #include "content/browser/screen_orientation/screen_orientation_delegate_android .h" | 130 #include "content/browser/screen_orientation/screen_orientation_delegate_android .h" |
| 130 #include "media/base/android/media_drm_bridge_client.h" | 131 #include "media/base/android/media_drm_bridge_client.h" |
| 131 #include "ui/android/screen_android.h" | 132 #include "ui/android/screen_android.h" |
| 132 #include "ui/display/screen.h" | 133 #include "ui/display/screen.h" |
| 133 #include "ui/gl/gl_surface.h" | 134 #include "ui/gl/gl_surface.h" |
| 134 #endif | 135 #endif |
| 135 | 136 |
| (...skipping 843 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 979 base::TaskScheduler::CreateAndSetDefaultTaskScheduler( | 980 base::TaskScheduler::CreateAndSetDefaultTaskScheduler( |
| 980 params_vector, index_to_traits_callback); | 981 params_vector, index_to_traits_callback); |
| 981 | 982 |
| 982 GetContentClient()->browser()->PerformExperimentalTaskSchedulerRedirections(); | 983 GetContentClient()->browser()->PerformExperimentalTaskSchedulerRedirections(); |
| 983 | 984 |
| 984 base::Thread::Options io_message_loop_options; | 985 base::Thread::Options io_message_loop_options; |
| 985 io_message_loop_options.message_loop_type = base::MessageLoop::TYPE_IO; | 986 io_message_loop_options.message_loop_type = base::MessageLoop::TYPE_IO; |
| 986 base::Thread::Options ui_message_loop_options; | 987 base::Thread::Options ui_message_loop_options; |
| 987 ui_message_loop_options.message_loop_type = base::MessageLoop::TYPE_UI; | 988 ui_message_loop_options.message_loop_type = base::MessageLoop::TYPE_UI; |
| 988 | 989 |
| 989 const bool redirect_nonUInonIO_browser_threads = | 990 const bool client_redirect_nonUInonIO_browser_threads = |
| 990 GetContentClient() | 991 GetContentClient() |
| 991 ->browser() | 992 ->browser() |
| 992 ->RedirectNonUINonIOBrowserThreadsToTaskScheduler(); | 993 ->RedirectNonUINonIOBrowserThreadsToTaskScheduler(); |
| 993 | 994 |
| 994 // Start threads in the order they occur in the BrowserThread::ID enumeration, | 995 // Start threads in the order they occur in the BrowserThread::ID enumeration, |
| 995 // except for BrowserThread::UI which is the main thread. | 996 // except for BrowserThread::UI which is the main thread. |
| 996 // | 997 // |
| 997 // Must be size_t so we can increment it. | 998 // Must be size_t so we can increment it. |
| 998 for (size_t thread_id = BrowserThread::UI + 1; | 999 for (size_t thread_id = BrowserThread::UI + 1; |
| 999 thread_id < BrowserThread::ID_COUNT; | 1000 thread_id < BrowserThread::ID_COUNT; |
| 1000 ++thread_id) { | 1001 ++thread_id) { |
| 1001 // If this thread ID is backed by a real thread, |thread_to_start| will be | 1002 // If this thread ID is backed by a real thread, |thread_to_start| will be |
| 1002 // set to the appropriate BrowserProcessSubThread*. And |options| can be | 1003 // set to the appropriate BrowserProcessSubThread*. And |options| can be |
| 1003 // updated away from its default. | 1004 // updated away from its default. |
| 1004 std::unique_ptr<BrowserProcessSubThread>* thread_to_start = nullptr; | 1005 std::unique_ptr<BrowserProcessSubThread>* thread_to_start = nullptr; |
| 1005 base::Thread::Options options; | 1006 base::Thread::Options options; |
| 1007 // If |message_loop| is not nullptr, then this BrowserThread will use this | |
| 1008 // message loop instead of creating a new thread. Note that means this | |
| 1009 // thread will not be joined on shutdown, and may cause use-after-free if | |
| 1010 // anything tries to access objects deleted by AtExitManager, such as | |
| 1011 // non-leaky LazyInstance. | |
| 1012 base::MessageLoop* message_loop = nullptr; | |
| 1013 bool redirect_nonUInonIO_browser_threads = | |
|
gab
2017/03/29 18:14:04
bool redirect_thread = redirect_nonUInonIO_browser
boliu
2017/03/29 18:30:07
Done, but now needs to rename all the usage of the
| |
| 1014 client_redirect_nonUInonIO_browser_threads; | |
| 1006 | 1015 |
| 1007 // Otherwise this thread ID will be backed by a SingleThreadTaskRunner using | 1016 // Otherwise this thread ID will be backed by a SingleThreadTaskRunner using |
| 1008 // |non_ui_non_io_task_runner_traits| (which can be augmented below). | 1017 // |non_ui_non_io_task_runner_traits| (which can be augmented below). |
| 1009 // TODO(gab): Existing non-UI/non-IO BrowserThreads allow sync primitives so | 1018 // TODO(gab): Existing non-UI/non-IO BrowserThreads allow sync primitives so |
| 1010 // the initial redirection will as well but they probably don't need to. | 1019 // the initial redirection will as well but they probably don't need to. |
| 1011 base::TaskTraits non_ui_non_io_task_runner_traits = | 1020 base::TaskTraits non_ui_non_io_task_runner_traits = |
| 1012 base::TaskTraits().MayBlock().WithBaseSyncPrimitives(); | 1021 base::TaskTraits().MayBlock().WithBaseSyncPrimitives(); |
| 1013 | 1022 |
| 1014 switch (thread_id) { | 1023 switch (thread_id) { |
| 1015 case BrowserThread::DB: | 1024 case BrowserThread::DB: |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1060 thread_to_start = &file_thread_; | 1069 thread_to_start = &file_thread_; |
| 1061 options = io_message_loop_options; | 1070 options = io_message_loop_options; |
| 1062 options.timer_slack = base::TIMER_SLACK_MAXIMUM; | 1071 options.timer_slack = base::TIMER_SLACK_MAXIMUM; |
| 1063 } | 1072 } |
| 1064 #endif | 1073 #endif |
| 1065 break; | 1074 break; |
| 1066 case BrowserThread::PROCESS_LAUNCHER: | 1075 case BrowserThread::PROCESS_LAUNCHER: |
| 1067 TRACE_EVENT_BEGIN1("startup", | 1076 TRACE_EVENT_BEGIN1("startup", |
| 1068 "BrowserMainLoop::CreateThreads:start", | 1077 "BrowserMainLoop::CreateThreads:start", |
| 1069 "Thread", "BrowserThread::PROCESS_LAUNCHER"); | 1078 "Thread", "BrowserThread::PROCESS_LAUNCHER"); |
| 1079 #if defined(OS_ANDROID) | |
| 1080 // Android specializes Launcher thread so it is accessible in java. | |
| 1081 // Note Android never does clean shutdown, so shutdown use-after-free | |
| 1082 // concerns is not a problem in practice. | |
|
gab
2017/03/29 18:14:04
s/is/are/
boliu
2017/03/29 18:30:07
Done.
| |
| 1083 redirect_nonUInonIO_browser_threads = false; | |
| 1084 message_loop = android::LauncherThread::GetMessageLoop(); | |
| 1085 #endif | |
| 1070 if (redirect_nonUInonIO_browser_threads) { | 1086 if (redirect_nonUInonIO_browser_threads) { |
|
gab
2017/03/29 18:38:06
Actually can't we just change this to
if (redirec
boliu
2017/03/29 18:42:20
Hmm, then in theory, that should be changed in all
gab
2017/03/29 18:46:53
Hmmm ok sure.
| |
| 1071 non_ui_non_io_task_runner_traits | 1087 non_ui_non_io_task_runner_traits |
| 1072 .WithPriority(base::TaskPriority::USER_BLOCKING) | 1088 .WithPriority(base::TaskPriority::USER_BLOCKING) |
| 1073 .WithShutdownBehavior(base::TaskShutdownBehavior::BLOCK_SHUTDOWN); | 1089 .WithShutdownBehavior(base::TaskShutdownBehavior::BLOCK_SHUTDOWN); |
| 1074 } else { | 1090 } else { |
| 1075 thread_to_start = &process_launcher_thread_; | 1091 thread_to_start = &process_launcher_thread_; |
| 1076 options.timer_slack = base::TIMER_SLACK_MAXIMUM; | 1092 options.timer_slack = base::TIMER_SLACK_MAXIMUM; |
| 1077 } | 1093 } |
| 1078 break; | 1094 break; |
| 1079 case BrowserThread::CACHE: | 1095 case BrowserThread::CACHE: |
| 1080 TRACE_EVENT_BEGIN1("startup", | 1096 TRACE_EVENT_BEGIN1("startup", |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1114 break; | 1130 break; |
| 1115 case BrowserThread::UI: // Falls through. | 1131 case BrowserThread::UI: // Falls through. |
| 1116 case BrowserThread::ID_COUNT: // Falls through. | 1132 case BrowserThread::ID_COUNT: // Falls through. |
| 1117 NOTREACHED(); | 1133 NOTREACHED(); |
| 1118 break; | 1134 break; |
| 1119 } | 1135 } |
| 1120 | 1136 |
| 1121 BrowserThread::ID id = static_cast<BrowserThread::ID>(thread_id); | 1137 BrowserThread::ID id = static_cast<BrowserThread::ID>(thread_id); |
| 1122 | 1138 |
| 1123 if (thread_to_start) { | 1139 if (thread_to_start) { |
| 1124 (*thread_to_start).reset(new BrowserProcessSubThread(id)); | 1140 (*thread_to_start) |
| 1141 .reset(message_loop ? new BrowserProcessSubThread(id, message_loop) | |
| 1142 : new BrowserProcessSubThread(id)); | |
| 1125 if (!(*thread_to_start)->StartWithOptions(options)) | 1143 if (!(*thread_to_start)->StartWithOptions(options)) |
| 1126 LOG(FATAL) << "Failed to start the browser thread: id == " << id; | 1144 LOG(FATAL) << "Failed to start the browser thread: id == " << id; |
| 1127 } else { | 1145 } else { |
| 1128 scoped_refptr<base::SingleThreadTaskRunner> redirection_task_runner = | 1146 scoped_refptr<base::SingleThreadTaskRunner> redirection_task_runner = |
| 1129 base::CreateSingleThreadTaskRunnerWithTraits( | 1147 base::CreateSingleThreadTaskRunnerWithTraits( |
| 1130 non_ui_non_io_task_runner_traits); | 1148 non_ui_non_io_task_runner_traits); |
| 1131 DCHECK(redirection_task_runner); | 1149 DCHECK(redirection_task_runner); |
| 1132 BrowserThreadImpl::RedirectThreadIDToTaskRunner( | 1150 BrowserThreadImpl::RedirectThreadIDToTaskRunner( |
| 1133 id, std::move(redirection_task_runner)); | 1151 id, std::move(redirection_task_runner)); |
| 1134 } | 1152 } |
| (...skipping 620 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1755 BrowserThread::GetTaskRunnerForThread(BrowserThread::FILE), | 1773 BrowserThread::GetTaskRunnerForThread(BrowserThread::FILE), |
| 1756 MediaInternals::GetInstance()); | 1774 MediaInternals::GetInstance()); |
| 1757 } | 1775 } |
| 1758 CHECK(audio_manager_); | 1776 CHECK(audio_manager_); |
| 1759 | 1777 |
| 1760 audio_system_ = media::AudioSystemImpl::Create(audio_manager_.get()); | 1778 audio_system_ = media::AudioSystemImpl::Create(audio_manager_.get()); |
| 1761 CHECK(audio_system_); | 1779 CHECK(audio_system_); |
| 1762 } | 1780 } |
| 1763 | 1781 |
| 1764 } // namespace content | 1782 } // namespace content |
| OLD | NEW |