Commit 943d66db authored by Gabriel Charette's avatar Gabriel Charette Committed by Commit Bot

Extract declarations of per-platform MessagePumpForUI/IO types from MessageLoop's impl.

This is a precursor for an upcoming change that will split the public bits
of the MessageLoop class (used through MessageLoop(ForUI|IO)::current())
to another class.

Bug: 825327
Change-Id: I3cda2a0e1b2ff48aaeeaeeb68d99c5dda926350f
Reviewed-on: https://chromium-review.googlesource.com/978776
Commit-Queue: Gabriel Charette <gab@chromium.org>
Reviewed-by: default avatarkylechar <kylechar@chromium.org>
Reviewed-by: default avatardanakj <danakj@chromium.org>
Cr-Commit-Position: refs/heads/master@{#548109}
parent dc341a3c
......@@ -559,6 +559,8 @@ jumbo_component("base") {
"message_loop/message_pump_android.h",
"message_loop/message_pump_default.cc",
"message_loop/message_pump_default.h",
"message_loop/message_pump_for_io.h",
"message_loop/message_pump_for_ui.h",
"message_loop/message_pump_glib.cc",
"message_loop/message_pump_glib.h",
"message_loop/message_pump_io_ios.cc",
......
......@@ -12,6 +12,7 @@
#include "base/logging.h"
#include "base/memory/ptr_util.h"
#include "base/message_loop/message_pump_default.h"
#include "base/message_loop/message_pump_for_ui.h"
#include "base/run_loop.h"
#include "base/third_party/dynamic_annotations/dynamic_annotations.h"
#include "base/threading/thread_id_name_manager.h"
......@@ -22,18 +23,6 @@
#if defined(OS_MACOSX)
#include "base/message_loop/message_pump_mac.h"
#endif
#if defined(OS_POSIX) && !defined(OS_IOS) && !defined(OS_FUCHSIA)
#include "base/message_loop/message_pump_libevent.h"
#endif
#if defined(OS_FUCHSIA)
#include "base/message_loop/message_pump_fuchsia.h"
#endif
#if defined(OS_ANDROID)
#include "base/message_loop/message_pump_android.h"
#endif
#if defined(USE_GLIB)
#include "base/message_loop/message_pump_glib.h"
#endif
namespace base {
......@@ -47,22 +36,6 @@ base::ThreadLocalPointer<MessageLoop>* GetTLSMessageLoop() {
}
MessageLoop::MessagePumpFactory* message_pump_for_ui_factory_ = nullptr;
#if defined(OS_IOS)
using MessagePumpForIO = MessagePumpIOSForIO;
#elif defined(OS_NACL_SFI)
using MessagePumpForIO = MessagePumpDefault;
#elif defined(OS_FUCHSIA)
using MessagePumpForIO = MessagePumpFuchsia;
#elif defined(OS_POSIX)
using MessagePumpForIO = MessagePumpLibevent;
#endif
#if !defined(OS_NACL_SFI)
MessagePumpForIO* ToPumpIO(MessagePump* pump) {
return static_cast<MessagePumpForIO*>(pump);
}
#endif // !defined(OS_NACL_SFI)
std::unique_ptr<MessagePump> ReturnPump(std::unique_ptr<MessagePump> pump) {
return pump;
}
......@@ -161,30 +134,21 @@ bool MessageLoop::InitMessagePumpForUIFactory(MessagePumpFactory* factory) {
// static
std::unique_ptr<MessagePump> MessageLoop::CreateMessagePumpForType(Type type) {
// TODO(rvargas): Get rid of the OS guards.
#if defined(USE_GLIB) && !defined(OS_NACL)
using MessagePumpForUI = MessagePumpGlib;
#elif (defined(OS_LINUX) && !defined(OS_NACL)) || defined(OS_BSD)
using MessagePumpForUI = MessagePumpLibevent;
#elif defined(OS_FUCHSIA)
using MessagePumpForUI = MessagePumpFuchsia;
#endif
if (type == MessageLoop::TYPE_UI) {
if (message_pump_for_ui_factory_)
return message_pump_for_ui_factory_();
#if defined(OS_IOS) || defined(OS_MACOSX)
#define MESSAGE_PUMP_UI std::unique_ptr<MessagePump>(MessagePumpMac::Create())
return MessagePumpMac::Create();
#elif defined(OS_NACL) || defined(OS_AIX)
// Currently NaCl and AIX don't have a UI MessageLoop.
// TODO(abarth): Figure out if we need this.
#define MESSAGE_PUMP_UI std::unique_ptr<MessagePump>()
// Currently NaCl and AIX don't have a UI MessageLoop.
// TODO(abarth): Figure out if we need this.
NOTREACHED();
return nullptr;
#else
#define MESSAGE_PUMP_UI std::unique_ptr<MessagePump>(new MessagePumpForUI())
return std::make_unique<MessagePumpForUI>();
#endif
if (type == MessageLoop::TYPE_UI) {
if (message_pump_for_ui_factory_)
return message_pump_for_ui_factory_();
return MESSAGE_PUMP_UI;
}
if (type == MessageLoop::TYPE_IO)
return std::unique_ptr<MessagePump>(new MessagePumpForIO());
......@@ -539,14 +503,10 @@ bool MessageLoopForUI::WatchFileDescriptor(
int fd,
bool persistent,
MessagePumpLibevent::Mode mode,
MessagePumpLibevent::FileDescriptorWatcher *controller,
MessagePumpLibevent::Watcher *delegate) {
return static_cast<MessagePumpLibevent*>(pump_.get())->WatchFileDescriptor(
fd,
persistent,
mode,
controller,
delegate);
MessagePumpLibevent::FileDescriptorWatcher* controller,
MessagePumpLibevent::Watcher* delegate) {
return static_cast<MessagePumpForUI*>(pump_.get())
->WatchFileDescriptor(fd, persistent, mode, controller, delegate);
}
#endif
......@@ -557,6 +517,14 @@ bool MessageLoopForUI::WatchFileDescriptor(
#if !defined(OS_NACL_SFI)
namespace {
MessagePumpForIO* ToPumpIO(MessagePump* pump) {
return static_cast<MessagePumpForIO*>(pump);
}
} // namespace
#if defined(OS_WIN)
void MessageLoopForIO::RegisterIOHandler(HANDLE file, IOHandler* handler) {
ToPumpIO(pump_.get())->RegisterIOHandler(file, handler);
......
......@@ -17,6 +17,7 @@
#include "base/message_loop/incoming_task_queue.h"
#include "base/message_loop/message_loop_task_runner.h"
#include "base/message_loop/message_pump.h"
#include "base/message_loop/message_pump_for_io.h"
#include "base/message_loop/timer_slack.h"
#include "base/observer_list.h"
#include "base/pending_task.h"
......@@ -26,17 +27,6 @@
#include "base/time/time.h"
#include "build/build_config.h"
// TODO(sky): these includes should not be necessary. Nuke them.
#if defined(OS_WIN)
#include "base/message_loop/message_pump_win.h"
#elif defined(OS_FUCHSIA)
#include "base/message_loop/message_pump_fuchsia.h"
#elif defined(OS_IOS)
#include "base/message_loop/message_pump_io_ios.h"
#elif defined(OS_POSIX)
#include "base/message_loop/message_pump_libevent.h"
#endif
namespace base {
class ThreadTaskRunnerHandle;
......
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef BASE_MESSAGE_LOOP_MESSAGE_PUMP_FOR_IO_H_
#define BASE_MESSAGE_LOOP_MESSAGE_PUMP_FOR_IO_H_
// This header is a forwarding header to coalesce the various platform specific
// types representing MessagePumpForIO.
#include "build/build_config.h"
#if defined(OS_WIN)
#include "base/message_loop/message_pump_win.h"
#elif defined(OS_IOS)
#include "base/message_loop/message_pump_io_ios.h"
#elif defined(OS_NACL_SFI)
#include "base/message_loop/message_pump_default.h"
#elif defined(OS_FUCHSIA)
#include "base/message_loop/message_pump_fuchsia.h"
#elif defined(OS_POSIX)
#include "base/message_loop/message_pump_libevent.h"
#endif
namespace base {
#if defined(OS_WIN)
// Windows defines it as-is.
using MessagePumpForIO = MessagePumpForIO;
#elif defined(OS_IOS)
using MessagePumpForIO = MessagePumpIOSForIO;
#elif defined(OS_NACL_SFI)
using MessagePumpForIO = MessagePumpDefault;
#elif defined(OS_FUCHSIA)
using MessagePumpForIO = MessagePumpFuchsia;
#elif defined(OS_POSIX)
using MessagePumpForIO = MessagePumpLibevent;
#else
#error Platform doesn't define MessagePumpForIO
#endif
} // namespace base
#endif // BASE_MESSAGE_LOOP_MESSAGE_PUMP_FOR_IO_H_
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef BASE_MESSAGE_LOOP_MESSAGE_PUMP_FOR_UI_H_
#define BASE_MESSAGE_LOOP_MESSAGE_PUMP_FOR_UI_H_
// This header is a forwarding header to coalesce the various platform specific
// implementations of MessagePumpForUI.
#include "build/build_config.h"
#if defined(OS_WIN)
#include "base/message_loop/message_pump_win.h"
#elif defined(OS_ANDROID)
#include "base/message_loop/message_pump_android.h"
#elif defined(OS_MACOSX)
// No MessagePumpForUI, see below.
#elif defined(OS_NACL) || defined(OS_AIX)
// No MessagePumpForUI, see below.
#elif defined(USE_GLIB)
#include "base/message_loop/message_pump_glib.h"
#elif defined(OS_LINUX) || defined(OS_BSD)
#include "base/message_loop/message_pump_libevent.h"
#elif defined(OS_FUCHSIA)
#include "base/message_loop/message_pump_fuchsia.h"
#endif
namespace base {
#if defined(OS_WIN)
// Windows defines it as-is.
using MessagePumpForUI = MessagePumpForUI;
#elif defined(OS_ANDROID)
// Android defines it as-is.
using MessagePumpForUI = MessagePumpForUI;
#elif defined(OS_MACOSX)
// MessagePumpForUI doesn't exists on Mac, MessagePumpMac::Create defines which
// Mac specific pump is used.
#elif defined(OS_NACL) || defined(OS_AIX)
// Currently NaCl and AIX don't have a MessagePumpForUI.
// TODO(abarth): Figure out if we need this.
#elif defined(USE_GLIB)
using MessagePumpForUI = MessagePumpGlib;
#elif defined(OS_LINUX) || defined(OS_BSD)
using MessagePumpForUI = MessagePumpLibevent;
#elif defined(OS_FUCHSIA)
using MessagePumpForUI = MessagePumpFuchsia;
#else
#error Platform doesn't define MessagePumpForUI
#endif
} // namespace base
#endif // BASE_MESSAGE_LOOP_MESSAGE_PUMP_FOR_UI_H_
......@@ -376,7 +376,7 @@ class BASE_EXPORT MessagePumpMac {
//
// Otherwise creates an instance of MessagePumpNSApplication using a
// default NSApplication.
static MessagePump* Create();
static std::unique_ptr<MessagePump> Create();
#if !defined(OS_IOS)
// If a pump is created before the required CrAppProtocol is
......
......@@ -918,13 +918,13 @@ bool MessagePumpMac::IsHandlingSendEvent() {
#endif // !defined(OS_IOS)
// static
MessagePump* MessagePumpMac::Create() {
std::unique_ptr<MessagePump> MessagePumpMac::Create() {
if ([NSThread isMainThread]) {
#if defined(OS_IOS)
return new MessagePumpUIApplication;
return std::make_unique<MessagePumpUIApplication>();
#else
if ([NSApp conformsToProtocol:@protocol(CrAppProtocol)])
return new MessagePumpCrApplication;
return std::make_unique<MessagePumpCrApplication>();
// The main-thread MessagePump implementations REQUIRE an NSApp.
// Executables which have specific requirements for their
......@@ -932,11 +932,11 @@ MessagePump* MessagePumpMac::Create() {
// creating an event loop.
[NSApplication sharedApplication];
g_not_using_cr_app = true;
return new MessagePumpNSApplication;
return std::make_unique<MessagePumpNSApplication>();
#endif
}
return new MessagePumpNSRunLoop;
return std::make_unique<MessagePumpNSRunLoop>();
}
} // namespace base
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment