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 864 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1000 base::TaskScheduler::CreateAndSetDefaultTaskScheduler( | 1001 base::TaskScheduler::CreateAndSetDefaultTaskScheduler( |
1001 params_vector, index_to_traits_callback); | 1002 params_vector, index_to_traits_callback); |
1002 | 1003 |
1003 GetContentClient()->browser()->PerformExperimentalTaskSchedulerRedirections(); | 1004 GetContentClient()->browser()->PerformExperimentalTaskSchedulerRedirections(); |
1004 | 1005 |
1005 base::Thread::Options io_message_loop_options; | 1006 base::Thread::Options io_message_loop_options; |
1006 io_message_loop_options.message_loop_type = base::MessageLoop::TYPE_IO; | 1007 io_message_loop_options.message_loop_type = base::MessageLoop::TYPE_IO; |
1007 base::Thread::Options ui_message_loop_options; | 1008 base::Thread::Options ui_message_loop_options; |
1008 ui_message_loop_options.message_loop_type = base::MessageLoop::TYPE_UI; | 1009 ui_message_loop_options.message_loop_type = base::MessageLoop::TYPE_UI; |
1009 | 1010 |
1010 const bool redirect_nonUInonIO_browser_threads = | 1011 bool redirect_nonUInonIO_browser_threads = |
1011 GetContentClient() | 1012 GetContentClient() |
1012 ->browser() | 1013 ->browser() |
1013 ->RedirectNonUINonIOBrowserThreadsToTaskScheduler(); | 1014 ->RedirectNonUINonIOBrowserThreadsToTaskScheduler(); |
1014 | 1015 |
1015 // Start threads in the order they occur in the BrowserThread::ID enumeration, | 1016 // Start threads in the order they occur in the BrowserThread::ID enumeration, |
1016 // except for BrowserThread::UI which is the main thread. | 1017 // except for BrowserThread::UI which is the main thread. |
1017 // | 1018 // |
1018 // Must be size_t so we can increment it. | 1019 // Must be size_t so we can increment it. |
1019 for (size_t thread_id = BrowserThread::UI + 1; | 1020 for (size_t thread_id = BrowserThread::UI + 1; |
1020 thread_id < BrowserThread::ID_COUNT; | 1021 thread_id < BrowserThread::ID_COUNT; |
1021 ++thread_id) { | 1022 ++thread_id) { |
1022 // If this thread ID is backed by a real thread, |thread_to_start| will be | 1023 // If this thread ID is backed by a real thread, |thread_to_start| will be |
1023 // set to the appropriate BrowserProcessSubThread*. And |options| can be | 1024 // set to the appropriate BrowserProcessSubThread*. And |options| can be |
1024 // updated away from its default. | 1025 // updated away from its default. |
1025 std::unique_ptr<BrowserProcessSubThread>* thread_to_start = nullptr; | 1026 std::unique_ptr<BrowserProcessSubThread>* thread_to_start = nullptr; |
1026 base::Thread::Options options; | 1027 base::Thread::Options options; |
1028 base::MessageLoop* message_loop = nullptr; | |
1027 | 1029 |
1028 // Otherwise this thread ID will be backed by a SingleThreadTaskRunner using | 1030 // Otherwise this thread ID will be backed by a SingleThreadTaskRunner using |
1029 // |non_ui_non_io_task_runner_traits| (which can be augmented below). | 1031 // |non_ui_non_io_task_runner_traits| (which can be augmented below). |
1030 // TODO(gab): Existing non-UI/non-IO BrowserThreads allow sync primitives so | 1032 // TODO(gab): Existing non-UI/non-IO BrowserThreads allow sync primitives so |
1031 // the initial redirection will as well but they probably don't need to. | 1033 // the initial redirection will as well but they probably don't need to. |
1032 base::TaskTraits non_ui_non_io_task_runner_traits = | 1034 base::TaskTraits non_ui_non_io_task_runner_traits = |
1033 base::TaskTraits().MayBlock().WithBaseSyncPrimitives(); | 1035 base::TaskTraits().MayBlock().WithBaseSyncPrimitives(); |
1034 | 1036 |
1035 switch (thread_id) { | 1037 switch (thread_id) { |
1036 case BrowserThread::DB: | 1038 case BrowserThread::DB: |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1081 thread_to_start = &file_thread_; | 1083 thread_to_start = &file_thread_; |
1082 options = io_message_loop_options; | 1084 options = io_message_loop_options; |
1083 options.timer_slack = base::TIMER_SLACK_MAXIMUM; | 1085 options.timer_slack = base::TIMER_SLACK_MAXIMUM; |
1084 } | 1086 } |
1085 #endif | 1087 #endif |
1086 break; | 1088 break; |
1087 case BrowserThread::PROCESS_LAUNCHER: | 1089 case BrowserThread::PROCESS_LAUNCHER: |
1088 TRACE_EVENT_BEGIN1("startup", | 1090 TRACE_EVENT_BEGIN1("startup", |
1089 "BrowserMainLoop::CreateThreads:start", | 1091 "BrowserMainLoop::CreateThreads:start", |
1090 "Thread", "BrowserThread::PROCESS_LAUNCHER"); | 1092 "Thread", "BrowserThread::PROCESS_LAUNCHER"); |
1093 #if defined(OS_ANDROID) | |
1094 redirect_nonUInonIO_browser_threads = false; | |
1095 message_loop = android::LauncherThread::GetLauncherMessageLoop(); | |
agrieve
2017/03/28 19:59:32
nit: might be nicer to drop the double "Launcher":
boliu
2017/03/28 23:30:52
Done.
| |
1096 #endif | |
1091 if (redirect_nonUInonIO_browser_threads) { | 1097 if (redirect_nonUInonIO_browser_threads) { |
1092 non_ui_non_io_task_runner_traits | 1098 non_ui_non_io_task_runner_traits |
1093 .WithPriority(base::TaskPriority::USER_BLOCKING) | 1099 .WithPriority(base::TaskPriority::USER_BLOCKING) |
1094 .WithShutdownBehavior(base::TaskShutdownBehavior::BLOCK_SHUTDOWN); | 1100 .WithShutdownBehavior(base::TaskShutdownBehavior::BLOCK_SHUTDOWN); |
1095 } else { | 1101 } else { |
1096 thread_to_start = &process_launcher_thread_; | 1102 thread_to_start = &process_launcher_thread_; |
1097 options.timer_slack = base::TIMER_SLACK_MAXIMUM; | 1103 options.timer_slack = base::TIMER_SLACK_MAXIMUM; |
1098 } | 1104 } |
1099 break; | 1105 break; |
1100 case BrowserThread::CACHE: | 1106 case BrowserThread::CACHE: |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1135 break; | 1141 break; |
1136 case BrowserThread::UI: // Falls through. | 1142 case BrowserThread::UI: // Falls through. |
1137 case BrowserThread::ID_COUNT: // Falls through. | 1143 case BrowserThread::ID_COUNT: // Falls through. |
1138 NOTREACHED(); | 1144 NOTREACHED(); |
1139 break; | 1145 break; |
1140 } | 1146 } |
1141 | 1147 |
1142 BrowserThread::ID id = static_cast<BrowserThread::ID>(thread_id); | 1148 BrowserThread::ID id = static_cast<BrowserThread::ID>(thread_id); |
1143 | 1149 |
1144 if (thread_to_start) { | 1150 if (thread_to_start) { |
1145 (*thread_to_start).reset(new BrowserProcessSubThread(id)); | 1151 (*thread_to_start) |
1152 .reset(message_loop ? new BrowserProcessSubThread(id, message_loop) | |
1153 : new BrowserProcessSubThread(id)); | |
1146 if (!(*thread_to_start)->StartWithOptions(options)) | 1154 if (!(*thread_to_start)->StartWithOptions(options)) |
1147 LOG(FATAL) << "Failed to start the browser thread: id == " << id; | 1155 LOG(FATAL) << "Failed to start the browser thread: id == " << id; |
1148 } else { | 1156 } else { |
1149 scoped_refptr<base::SingleThreadTaskRunner> redirection_task_runner = | 1157 scoped_refptr<base::SingleThreadTaskRunner> redirection_task_runner = |
1150 base::CreateSingleThreadTaskRunnerWithTraits( | 1158 base::CreateSingleThreadTaskRunnerWithTraits( |
1151 non_ui_non_io_task_runner_traits); | 1159 non_ui_non_io_task_runner_traits); |
1152 DCHECK(redirection_task_runner); | 1160 DCHECK(redirection_task_runner); |
1153 BrowserThreadImpl::RedirectThreadIDToTaskRunner( | 1161 BrowserThreadImpl::RedirectThreadIDToTaskRunner( |
1154 id, std::move(redirection_task_runner)); | 1162 id, std::move(redirection_task_runner)); |
1155 } | 1163 } |
(...skipping 620 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1776 BrowserThread::GetTaskRunnerForThread(BrowserThread::FILE), | 1784 BrowserThread::GetTaskRunnerForThread(BrowserThread::FILE), |
1777 MediaInternals::GetInstance()); | 1785 MediaInternals::GetInstance()); |
1778 } | 1786 } |
1779 CHECK(audio_manager_); | 1787 CHECK(audio_manager_); |
1780 | 1788 |
1781 audio_system_ = media::AudioSystemImpl::Create(audio_manager_.get()); | 1789 audio_system_ = media::AudioSystemImpl::Create(audio_manager_.get()); |
1782 CHECK(audio_system_); | 1790 CHECK(audio_system_); |
1783 } | 1791 } |
1784 | 1792 |
1785 } // namespace content | 1793 } // namespace content |
OLD | NEW |