Skip to content

Commit

Permalink
Migrate more base::MessageLoops to base::SingleThreadTaskExecutor
Browse files Browse the repository at this point in the history
A large but trivial migration.

TBR=fdoray@chromium.org

Bug: 891670
Change-Id: I1d3a7575703de8ba17238cb1c9e64d1d825c08d6
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1637460
Reviewed-by: Alex Clarke <alexclarke@chromium.org>
Reviewed-by: François Doray <fdoray@chromium.org>
Commit-Queue: Alex Clarke <alexclarke@chromium.org>
Cr-Commit-Position: refs/heads/master@{#666718}
  • Loading branch information
Alex Clarke authored and Commit Bot committed Jun 6, 2019
1 parent 12da0c5 commit f7fb8a8
Show file tree
Hide file tree
Showing 117 changed files with 393 additions and 347 deletions.
10 changes: 6 additions & 4 deletions android_webview/browser/aw_browser_main_parts.cc
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,12 @@ int AwBrowserMainParts::PreEarlyInitialization() {
new AwNetworkChangeNotifierFactory());
}

// Creates a MessageLoop for Android WebView if doesn't yet exist.
DCHECK(!main_message_loop_.get());
if (!base::MessageLoopCurrent::IsSet())
main_message_loop_.reset(new base::MessageLoopForUI);
// Creates a SingleThreadTaskExecutor for Android WebView if doesn't exist.
DCHECK(!main_task_executor_.get());
if (!base::MessageLoopCurrent::IsSet()) {
main_task_executor_ = std::make_unique<base::SingleThreadTaskExecutor>(
base::MessagePump::Type::UI);
}
return service_manager::RESULT_CODE_NORMAL_EXIT;
}

Expand Down
9 changes: 3 additions & 6 deletions android_webview/browser/aw_browser_main_parts.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,9 @@

#include "base/compiler_specific.h"
#include "base/macros.h"
#include "base/task/single_thread_task_executor.h"
#include "content/public/browser/browser_main_parts.h"

namespace base {
class MessageLoop;
}

namespace android_webview {

class AwContentBrowserClient;
Expand All @@ -33,8 +30,8 @@ class AwBrowserMainParts : public content::BrowserMainParts {
content::ServiceManagerConnection* connection) override;

private:
// Android specific UI MessageLoop.
std::unique_ptr<base::MessageLoop> main_message_loop_;
// Android specific UI SingleThreadTaskExecutor.
std::unique_ptr<base::SingleThreadTaskExecutor> main_task_executor_;

AwContentBrowserClient* browser_client_;

Expand Down
5 changes: 3 additions & 2 deletions ash/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
#include "base/feature_list.h"
#include "base/files/file_path.h"
#include "base/logging.h"
#include "base/message_loop/message_loop.h"
#include "base/path_service.h"
#include "base/run_loop.h"
#include "base/task/single_thread_task_executor.h"
#include "ui/base/material_design/material_design_controller.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/base/ui_base_features.h"
Expand Down Expand Up @@ -59,6 +59,7 @@ void ServiceMain(service_manager::mojom::ServiceRequest request) {

ui::MaterialDesignController::Initialize();

base::MessageLoop message_loop(base::MessageLoop::TYPE_UI);
base::SingleThreadTaskExecutor main_task_executor(
base::MessagePump::Type::UI);
ash::AshService(std::move(request)).RunUntilTermination();
}
21 changes: 15 additions & 6 deletions base/task/single_thread_task_executor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,29 @@

#include "base/message_loop/message_pump.h"
#include "base/task/sequence_manager/sequence_manager.h"
#include "base/task/sequence_manager/sequence_manager_impl.h"
#include "build/build_config.h"

namespace base {

SingleThreadTaskExecutor::SingleThreadTaskExecutor(MessagePump::Type type)
: sequence_manager_(
sequence_manager::CreateSequenceManagerOnCurrentThreadWithPump(
MessagePump::Create(type),
sequence_manager::SequenceManager::Settings::Builder()
.SetMessagePumpType(type)
.Build())),
: sequence_manager_(sequence_manager::CreateUnboundSequenceManager(
sequence_manager::SequenceManager::Settings::Builder()
.SetMessagePumpType(type)
.Build())),
default_task_queue_(sequence_manager_->CreateTaskQueue(
sequence_manager::TaskQueue::Spec("default_tq"))),
type_(type) {
sequence_manager_->SetDefaultTaskRunner(default_task_queue_->task_runner());
sequence_manager_->BindToMessagePump(MessagePump::Create(type));

#if defined(OS_IOS)
if (type == MessagePump::Type::UI) {
static_cast<sequence_manager::internal::SequenceManagerImpl*>(
sequence_manager_.get())
->AttachToMessagePump();
}
#endif
}

SingleThreadTaskExecutor::~SingleThreadTaskExecutor() = default;
Expand Down
10 changes: 5 additions & 5 deletions build/fuchsia/layout_test_proxy/layout_test_proxy.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
// found in the LICENSE file.

#include "base/command_line.h"
#include "base/message_loop/message_loop.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_split.h"
#include "base/task/single_thread_task_executor.h"
#include "net/base/ip_endpoint.h"
#include "net/test/tcp_socket_proxy.h"

Expand Down Expand Up @@ -55,13 +55,13 @@ int main(int argc, char** argv) {
return 1;
}

base::MessageLoopForIO message_loop;
base::SingleThreadTaskExecutor io_task_executor(base::MessagePump::Type::IO);

std::vector<std::unique_ptr<net::TcpSocketProxy>> proxies;

for (int port : ports) {
auto test_server_proxy =
std::make_unique<net::TcpSocketProxy>(message_loop.task_runner());
std::make_unique<net::TcpSocketProxy>(io_task_executor.task_runner());
if (!test_server_proxy->Initialize(port)) {
LOG(ERROR) << "Can't bind proxy to port " << port;
return 1;
Expand All @@ -71,8 +71,8 @@ int main(int argc, char** argv) {
proxies.push_back(std::move(test_server_proxy));
}

// Run the message loop indefinitely.
// Run the task executor indefinitely.
base::RunLoop().Run();

return 0;
}
}
7 changes: 4 additions & 3 deletions chrome/app_shim/chrome_main_app_mode_mac.mm
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@
#include "base/mac/mac_logging.h"
#include "base/mac/scoped_nsautorelease_pool.h"
#include "base/macros.h"
#include "base/message_loop/message_loop.h"
#include "base/run_loop.h"
#include "base/strings/sys_string_conversions.h"
#include "base/strings/utf_string_conversions.h"
#include "base/task/single_thread_task_executor.h"
#include "base/threading/thread.h"
#include "chrome/app/chrome_crash_reporter_client.h"
#include "chrome/app_shim/app_shim_controller.h"
Expand Down Expand Up @@ -136,8 +136,9 @@ int APP_SHIM_ENTRY_POINT_NAME(const app_mode::ChromeAppModeInfo* info) {
[AppShimApplication sharedApplication];
CHECK([NSApp isKindOfClass:[AppShimApplication class]]);

base::MessageLoopForUI main_message_loop;
ui::WindowResizeHelperMac::Get()->Init(main_message_loop.task_runner());
base::SingleThreadTaskExecutor main_task_executor(
base::MessagePump::Type::UI);
ui::WindowResizeHelperMac::Get()->Init(main_task_executor.task_runner());
base::PlatformThread::SetName("CrAppShimMain");

// TODO(https://crbug.com/925998): This workaround ensures that there is
Expand Down
7 changes: 4 additions & 3 deletions chrome/browser/vr/testapp/vr_testapp.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
#include "base/bind.h"
#include "base/command_line.h"
#include "base/macros.h"
#include "base/message_loop/message_loop.h"
#include "base/run_loop.h"
#include "base/task/single_thread_task_executor.h"
#include "base/task/thread_pool/thread_pool.h"
#include "base/threading/thread_task_runner_handle.h"
#include "base/trace_event/trace_event.h"
Expand Down Expand Up @@ -284,9 +284,10 @@ int main(int argc, char** argv) {
base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
switches::kUseGL, gl::kGLImplementationEGLName);

// Build UI thread message loop. This is used by platform
// Build UI thread task executor. This is used by platform
// implementations for event polling & running background tasks.
base::MessageLoopForUI message_loop;
base::SingleThreadTaskExecutor main_task_executor(
base::MessagePump::Type::UI);
base::ThreadPoolInstance::CreateAndStartWithDefaultParams("VrUiViewer");

ui::OzonePlatform::InitParams params;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <utility>

#include "base/bind_helpers.h"
#include "base/task/single_thread_task_executor.h"
#include "chrome/chrome_cleaner/engines/common/engine_result_codes.h"
#include "chrome/chrome_cleaner/os/early_exit.h"
#include "chrome/chrome_cleaner/os/initializer.h"
Expand Down Expand Up @@ -138,7 +139,7 @@ SandboxChildProcess::GetCleanerEngineRequestsProxy() {
}

void SandboxChildProcess::UnbindRequestsPtrs() {
base::MessageLoop message_loop;
base::SingleThreadTaskExecutor main_task_executor;
base::RunLoop run_loop;
if (GetCleanerEngineRequestsProxy() != nullptr) {
mojo_task_runner_->PostTask(
Expand Down
9 changes: 5 additions & 4 deletions chrome/chrome_cleaner/executables/chrome_cleaner_main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@
#include "base/logging.h"
#include "base/macros.h"
#include "base/memory/ref_counted.h"
#include "base/message_loop/message_loop.h"
#include "base/run_loop.h"
#include "base/sequenced_task_runner.h"
#include "base/strings/utf_string_conversions.h"
#include "base/task/single_thread_task_executor.h"
#include "base/task/thread_pool/thread_pool.h"
#include "base/threading/sequenced_task_runner_handle.h"
#include "base/threading/thread_task_runner_handle.h"
Expand Down Expand Up @@ -97,7 +97,7 @@ void LogsUploadCallback(bool* succeeded,
if (succeeded)
*succeeded = success;
// Use a task instead of a direct call to QuitWhenIdle, in case we are called
// synchronously because of an upload error, and the message loop is not
// synchronously because of an upload error, and the task executor is not
// running yet.
base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE,
std::move(quit_closure));
Expand Down Expand Up @@ -517,9 +517,10 @@ int APIENTRY wWinMain(HINSTANCE, HINSTANCE, wchar_t*, int) {
LOG(ERROR) << "Failed to remove zone identifier.";
}

// Many pieces of code below need a message loop to have been instantiated
// Many pieces of code below need a task executor to have been instantiated
// before them.
base::MessageLoopForUI ui_message_loop;
base::SingleThreadTaskExecutor main_task_executor(
base::MessagePump::Type::UI);

// The rebooter must be at the outermost scope so it can be called to reboot
// before exiting, when appropriate.
Expand Down
7 changes: 4 additions & 3 deletions chrome/chrome_cleaner/executables/chrome_reporter_main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_refptr.h"
#include "base/memory/weak_ptr.h"
#include "base/message_loop/message_loop.h"
#include "base/sequenced_task_runner.h"
#include "base/strings/string16.h"
#include "base/strings/string_util.h"
#include "base/task/single_thread_task_executor.h"
#include "base/task/thread_pool/thread_pool.h"
#include "base/threading/sequenced_task_runner_handle.h"
#include "base/win/registry.h"
Expand Down Expand Up @@ -230,11 +230,12 @@ int APIENTRY wWinMain(HINSTANCE, HINSTANCE, wchar_t*, int) {
&registry_logger);
}

// Many pieces of code below need a message loop to have been instantiated
// Many pieces of code below need a task executor to have been instantiated
// before them.
base::ThreadPoolInstance::CreateAndStartWithDefaultParams(
"software reporter");
base::MessageLoopForUI ui_message_loop;
base::SingleThreadTaskExecutor main_task_executor(
base::MessagePump::Type::UI);

shutdown_sequence.mojo_task_runner = MojoTaskRunner::Create();

Expand Down
2 changes: 1 addition & 1 deletion chrome/chrome_watcher/chrome_watcher_main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ extern "C" int WatcherMain(const base::char16* registry_path,
base::win::RegisterInvalidParamHandler();
base::win::SetupCRT(cmd_line);

// Run a UI message loop on the main thread.
// Run a UI task executor on the main thread.
base::PlatformThread::SetName("WatcherMainThread");
base::SingleThreadTaskExecutor main_thread_task_executor(
base::MessagePump::Type::UI);
Expand Down
2 changes: 1 addition & 1 deletion chrome/test/chromedriver/net/test_http_server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ TestHttpServer::~TestHttpServer() {
}

bool TestHttpServer::Start() {
base::Thread::Options options(base::MessageLoop::TYPE_IO, 0);
base::Thread::Options options(base::MessagePump::Type::IO, 0);
bool thread_started = thread_.StartWithOptions(options);
EXPECT_TRUE(thread_started);
if (!thread_started)
Expand Down
12 changes: 6 additions & 6 deletions chrome/test/chromedriver/server/chromedriver_server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
#include "base/files/file_util.h"
#include "base/lazy_instance.h"
#include "base/logging.h"
#include "base/message_loop/message_loop.h"
#include "base/run_loop.h"
#include "base/single_thread_task_runner.h"
#include "base/stl_util.h"
Expand All @@ -29,6 +28,7 @@
#include "base/strings/string_util.h"
#include "base/strings/stringprintf.h"
#include "base/synchronization/waitable_event.h"
#include "base/task/single_thread_task_executor.h"
#include "base/task/thread_pool/thread_pool.h"
#include "base/threading/thread.h"
#include "base/threading/thread_local.h"
Expand Down Expand Up @@ -356,18 +356,18 @@ void RunServer(uint16_t port,
CHECK(io_thread.StartWithOptions(
base::Thread::Options(base::MessageLoop::TYPE_IO, 0)));

base::MessageLoop cmd_loop;
base::SingleThreadTaskExecutor main_task_executor;
base::RunLoop cmd_run_loop;
HttpHandler handler(cmd_run_loop.QuitClosure(), io_thread.task_runner(),
url_base, adb_port);
HttpRequestHandlerFunc handle_request_func =
base::Bind(&HandleRequestOnCmdThread, &handler, whitelisted_ips);

io_thread.task_runner()->PostTask(
FROM_HERE,
base::BindOnce(&StartServerOnIOThread, port, allow_remote,
base::Bind(&HandleRequestOnIOThread,
cmd_loop.task_runner(), handle_request_func)));
FROM_HERE, base::BindOnce(&StartServerOnIOThread, port, allow_remote,
base::Bind(&HandleRequestOnIOThread,
main_task_executor.task_runner(),
handle_request_func)));
// Run the command loop. This loop is quit after the response for a shutdown
// request is posted to the IO loop. After the command loop quits, a task
// is posted to the IO loop to stop the server. Lastly, the IO thread is
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@

#include "base/at_exit.h"
#include "base/bind.h"
#include "base/message_loop/message_loop.h"
#include "base/run_loop.h"
#include "base/task/single_thread_task_executor.h"
#include "chrome/browser/local_discovery/service_discovery_client_impl.h"
#include "net/dns/mdns_client.h"

Expand Down Expand Up @@ -98,7 +98,7 @@ void ServiceTypePrinter::OnServiceUpdated(ServiceWatcher::UpdateType update,

int main(int argc, char** argv) {
base::AtExitManager at_exit_manager;
base::MessageLoopForIO message_loop;
base::SingleThreadTaskExecutor io_task_executor(base::MessagePump::Type::IO);

if (argc != 2) {
printf("Please provide exactly 1 argument.\n");
Expand Down
5 changes: 3 additions & 2 deletions chrome/updater/updater.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@
#include "base/files/file_path.h"
#include "base/logging.h"
#include "base/memory/scoped_refptr.h"
#include "base/message_loop/message_loop.h"
#include "base/optional.h"
#include "base/run_loop.h"
#include "base/stl_util.h"
#include "base/task/post_task.h"
#include "base/task/single_thread_task_executor.h"
#include "base/task/thread_pool/thread_pool.h"
#include "base/task_runner.h"
#include "base/threading/platform_thread.h"
Expand Down Expand Up @@ -150,7 +150,8 @@ int UpdaterMain(int argc, const char* const* argv) {
installer->FindInstallOfApp();
const auto component = installer->MakeCrxComponent();

base::MessageLoopForUI message_loop;
base::SingleThreadTaskExecutor main_task_executor(
base::MessagePump::Type::UI);
base::RunLoop runloop;
DCHECK(base::ThreadTaskRunnerHandle::IsSet());

Expand Down
4 changes: 2 additions & 2 deletions chrome/utility/importer/firefox_importer_unittest_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
class FFDecryptorServerChannelListener;

namespace base {
class MessageLoopForIO;
class SingleThreadTaskExecutor;
}

// On OS X NSSDecryptor needs to run in a separate process. To allow us to use
Expand All @@ -44,7 +44,7 @@ class FFUnitTestDecryptorProxy {
#if defined(OS_MACOSX)
base::Process child_process_;
std::unique_ptr<FFDecryptorServerChannelListener> listener_;
std::unique_ptr<base::MessageLoopForIO> message_loop_;
std::unique_ptr<base::SingleThreadTaskExecutor> main_task_executor_;
#else
NSSDecryptor decryptor_;
#endif // !OS_MACOSX
Expand Down
Loading

0 comments on commit f7fb8a8

Please sign in to comment.