Chromium Code Reviews| Index: content/browser/browser_main_loop.cc |
| diff --git a/content/browser/browser_main_loop.cc b/content/browser/browser_main_loop.cc |
| index ba276a6acc07aa22fcc09a95cd89497fa8814223..ae864f144ebf85d709bb6c99235c6c329a08f0a4 100644 |
| --- a/content/browser/browser_main_loop.cc |
| +++ b/content/browser/browser_main_loop.cc |
| @@ -123,6 +123,7 @@ |
| #include "base/android/jni_android.h" |
| #include "components/tracing/common/graphics_memory_dump_provider_android.h" |
| #include "content/browser/android/browser_startup_controller.h" |
| +#include "content/browser/android/launcher_thread.h" |
| #include "content/browser/android/scoped_surface_request_manager.h" |
| #include "content/browser/android/tracing_controller_android.h" |
| #include "content/browser/media/android/browser_media_player_manager.h" |
| @@ -986,7 +987,7 @@ int BrowserMainLoop::CreateThreads() { |
| base::Thread::Options ui_message_loop_options; |
| ui_message_loop_options.message_loop_type = base::MessageLoop::TYPE_UI; |
| - const bool redirect_nonUInonIO_browser_threads = |
| + const bool client_redirect_nonUInonIO_browser_threads = |
| GetContentClient() |
| ->browser() |
| ->RedirectNonUINonIOBrowserThreadsToTaskScheduler(); |
| @@ -1003,6 +1004,14 @@ int BrowserMainLoop::CreateThreads() { |
| // updated away from its default. |
| std::unique_ptr<BrowserProcessSubThread>* thread_to_start = nullptr; |
| base::Thread::Options options; |
| + // If |message_loop| is not nullptr, then this BrowserThread will use this |
| + // message loop instead of creating a new thread. Note that means this |
| + // thread will not be joined on shutdown, and may cause use-after-free if |
| + // anything tries to access objects deleted by AtExitManager, such as |
| + // non-leaky LazyInstance. |
| + base::MessageLoop* message_loop = nullptr; |
| + 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
|
| + client_redirect_nonUInonIO_browser_threads; |
| // Otherwise this thread ID will be backed by a SingleThreadTaskRunner using |
| // |non_ui_non_io_task_runner_traits| (which can be augmented below). |
| @@ -1067,6 +1076,13 @@ int BrowserMainLoop::CreateThreads() { |
| TRACE_EVENT_BEGIN1("startup", |
| "BrowserMainLoop::CreateThreads:start", |
| "Thread", "BrowserThread::PROCESS_LAUNCHER"); |
| +#if defined(OS_ANDROID) |
| + // Android specializes Launcher thread so it is accessible in java. |
| + // Note Android never does clean shutdown, so shutdown use-after-free |
| + // 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.
|
| + redirect_nonUInonIO_browser_threads = false; |
| + message_loop = android::LauncherThread::GetMessageLoop(); |
| +#endif |
| 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.
|
| non_ui_non_io_task_runner_traits |
| .WithPriority(base::TaskPriority::USER_BLOCKING) |
| @@ -1121,7 +1137,9 @@ int BrowserMainLoop::CreateThreads() { |
| BrowserThread::ID id = static_cast<BrowserThread::ID>(thread_id); |
| if (thread_to_start) { |
| - (*thread_to_start).reset(new BrowserProcessSubThread(id)); |
| + (*thread_to_start) |
| + .reset(message_loop ? new BrowserProcessSubThread(id, message_loop) |
| + : new BrowserProcessSubThread(id)); |
| if (!(*thread_to_start)->StartWithOptions(options)) |
| LOG(FATAL) << "Failed to start the browser thread: id == " << id; |
| } else { |