Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1278)

Side by Side Diff: content/browser/browser_main_loop.cc

Issue 2774363003: android: Java-based launcher thread (Closed)
Patch Set: comment on test Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
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 bool 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.
gab 2017/03/29 17:19:53 Document |message_loop| here.
boliu 2017/03/29 18:02:39 Done.
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 base::MessageLoop* message_loop = nullptr;
1006 1008
1007 // Otherwise this thread ID will be backed by a SingleThreadTaskRunner using 1009 // Otherwise this thread ID will be backed by a SingleThreadTaskRunner using
1008 // |non_ui_non_io_task_runner_traits| (which can be augmented below). 1010 // |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 1011 // 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. 1012 // the initial redirection will as well but they probably don't need to.
1011 base::TaskTraits non_ui_non_io_task_runner_traits = 1013 base::TaskTraits non_ui_non_io_task_runner_traits =
1012 base::TaskTraits().MayBlock().WithBaseSyncPrimitives(); 1014 base::TaskTraits().MayBlock().WithBaseSyncPrimitives();
1013 1015
1014 switch (thread_id) { 1016 switch (thread_id) {
1015 case BrowserThread::DB: 1017 case BrowserThread::DB:
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
1060 thread_to_start = &file_thread_; 1062 thread_to_start = &file_thread_;
1061 options = io_message_loop_options; 1063 options = io_message_loop_options;
1062 options.timer_slack = base::TIMER_SLACK_MAXIMUM; 1064 options.timer_slack = base::TIMER_SLACK_MAXIMUM;
1063 } 1065 }
1064 #endif 1066 #endif
1065 break; 1067 break;
1066 case BrowserThread::PROCESS_LAUNCHER: 1068 case BrowserThread::PROCESS_LAUNCHER:
1067 TRACE_EVENT_BEGIN1("startup", 1069 TRACE_EVENT_BEGIN1("startup",
1068 "BrowserMainLoop::CreateThreads:start", 1070 "BrowserMainLoop::CreateThreads:start",
1069 "Thread", "BrowserThread::PROCESS_LAUNCHER"); 1071 "Thread", "BrowserThread::PROCESS_LAUNCHER");
1072 #if defined(OS_ANDROID)
1073 redirect_nonUInonIO_browser_threads = false;
gab 2017/03/29 17:19:53 That's a large hammer since this bool is set outsi
boliu 2017/03/29 18:02:39 Oh good catch! Added a bool in the loop instead
1074 message_loop = android::LauncherThread::GetMessageLoop();
1075 #endif
1070 if (redirect_nonUInonIO_browser_threads) { 1076 if (redirect_nonUInonIO_browser_threads) {
1071 non_ui_non_io_task_runner_traits 1077 non_ui_non_io_task_runner_traits
1072 .WithPriority(base::TaskPriority::USER_BLOCKING) 1078 .WithPriority(base::TaskPriority::USER_BLOCKING)
1073 .WithShutdownBehavior(base::TaskShutdownBehavior::BLOCK_SHUTDOWN); 1079 .WithShutdownBehavior(base::TaskShutdownBehavior::BLOCK_SHUTDOWN);
1074 } else { 1080 } else {
1075 thread_to_start = &process_launcher_thread_; 1081 thread_to_start = &process_launcher_thread_;
1076 options.timer_slack = base::TIMER_SLACK_MAXIMUM; 1082 options.timer_slack = base::TIMER_SLACK_MAXIMUM;
1077 } 1083 }
1078 break; 1084 break;
1079 case BrowserThread::CACHE: 1085 case BrowserThread::CACHE:
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
1114 break; 1120 break;
1115 case BrowserThread::UI: // Falls through. 1121 case BrowserThread::UI: // Falls through.
1116 case BrowserThread::ID_COUNT: // Falls through. 1122 case BrowserThread::ID_COUNT: // Falls through.
1117 NOTREACHED(); 1123 NOTREACHED();
1118 break; 1124 break;
1119 } 1125 }
1120 1126
1121 BrowserThread::ID id = static_cast<BrowserThread::ID>(thread_id); 1127 BrowserThread::ID id = static_cast<BrowserThread::ID>(thread_id);
1122 1128
1123 if (thread_to_start) { 1129 if (thread_to_start) {
1124 (*thread_to_start).reset(new BrowserProcessSubThread(id)); 1130 (*thread_to_start)
1131 .reset(message_loop ? new BrowserProcessSubThread(id, message_loop)
1132 : new BrowserProcessSubThread(id));
gab 2017/03/29 17:19:53 This will alter shutdown behavior of PROCESS_LAUNC
boliu 2017/03/29 18:02:39 Noted. Thankfully, android never does clean shutdo
1125 if (!(*thread_to_start)->StartWithOptions(options)) 1133 if (!(*thread_to_start)->StartWithOptions(options))
1126 LOG(FATAL) << "Failed to start the browser thread: id == " << id; 1134 LOG(FATAL) << "Failed to start the browser thread: id == " << id;
1127 } else { 1135 } else {
1128 scoped_refptr<base::SingleThreadTaskRunner> redirection_task_runner = 1136 scoped_refptr<base::SingleThreadTaskRunner> redirection_task_runner =
1129 base::CreateSingleThreadTaskRunnerWithTraits( 1137 base::CreateSingleThreadTaskRunnerWithTraits(
1130 non_ui_non_io_task_runner_traits); 1138 non_ui_non_io_task_runner_traits);
1131 DCHECK(redirection_task_runner); 1139 DCHECK(redirection_task_runner);
1132 BrowserThreadImpl::RedirectThreadIDToTaskRunner( 1140 BrowserThreadImpl::RedirectThreadIDToTaskRunner(
1133 id, std::move(redirection_task_runner)); 1141 id, std::move(redirection_task_runner));
1134 } 1142 }
(...skipping 620 matching lines...) Expand 10 before | Expand all | Expand 10 after
1755 BrowserThread::GetTaskRunnerForThread(BrowserThread::FILE), 1763 BrowserThread::GetTaskRunnerForThread(BrowserThread::FILE),
1756 MediaInternals::GetInstance()); 1764 MediaInternals::GetInstance());
1757 } 1765 }
1758 CHECK(audio_manager_); 1766 CHECK(audio_manager_);
1759 1767
1760 audio_system_ = media::AudioSystemImpl::Create(audio_manager_.get()); 1768 audio_system_ = media::AudioSystemImpl::Create(audio_manager_.get());
1761 CHECK(audio_system_); 1769 CHECK(audio_system_);
1762 } 1770 }
1763 1771
1764 } // namespace content 1772 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698