Commit e1d6adc5 authored by Alexander Timin's avatar Alexander Timin Committed by Commit Bot

[message_loop] Move MessageLoopFor{UI|IO} to message_loop.{h|cc}

As MessageLoopForUI and IO are not part of MessageLoopImpl (they are
just talking to the relevant pump), move them to the main file.

R=gab@chromium.org
BUG=891670

Change-Id: Ifdbb7916c43e8c51331a34b73902d58a3d8a9ecb
Reviewed-on: https://chromium-review.googlesource.com/c/1313589Reviewed-by: default avatarGabriel Charette <gab@chromium.org>
Commit-Queue: Alexander Timin <altimin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#604907}
parent efa139ae
...@@ -462,6 +462,7 @@ jumbo_component("base") { ...@@ -462,6 +462,7 @@ jumbo_component("base") {
"memory/weak_ptr.h", "memory/weak_ptr.h",
"memory/writable_shared_memory_region.cc", "memory/writable_shared_memory_region.cc",
"memory/writable_shared_memory_region.h", "memory/writable_shared_memory_region.h",
"message_loop/message_loop.cc",
"message_loop/message_loop.h", "message_loop/message_loop.h",
"message_loop/message_loop_current.cc", "message_loop/message_loop_current.cc",
"message_loop/message_loop_current.h", "message_loop/message_loop_current.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.
#include "base/message_loop/message_loop.h"
#include "build/build_config.h"
namespace base {
#if !defined(OS_NACL)
//------------------------------------------------------------------------------
// MessageLoopForUI
MessageLoopForUI::MessageLoopForUI(Type type) : MessageLoop(type) {
#if defined(OS_ANDROID)
DCHECK(type == TYPE_UI || type == TYPE_JAVA);
#else
DCHECK_EQ(type, TYPE_UI);
#endif
}
// static
MessageLoopCurrentForUI MessageLoopForUI::current() {
return MessageLoopCurrentForUI::Get();
}
// static
bool MessageLoopForUI::IsCurrent() {
return MessageLoopCurrentForUI::IsSet();
}
#if defined(OS_IOS)
void MessageLoopForUI::Attach() {
static_cast<MessagePumpUIApplication*>(pump_.get())->Attach(this);
}
#endif // defined(OS_IOS)
#if defined(OS_ANDROID)
void MessageLoopForUI::Abort() {
static_cast<MessagePumpForUI*>(pump_.get())->Abort();
}
bool MessageLoopForUI::IsAborted() {
return static_cast<MessagePumpForUI*>(pump_.get())->IsAborted();
}
void MessageLoopForUI::QuitWhenIdle(base::OnceClosure callback) {
static_cast<MessagePumpForUI*>(pump_.get())
->QuitWhenIdle(std::move(callback));
}
#endif // defined(OS_ANDROID)
#if defined(OS_WIN)
void MessageLoopForUI::EnableWmQuit() {
static_cast<MessagePumpForUI*>(pump_.get())->EnableWmQuit();
}
#endif // defined(OS_WIN)
#endif // !defined(OS_NACL)
//------------------------------------------------------------------------------
// MessageLoopForIO
// static
MessageLoopCurrentForIO MessageLoopForIO::current() {
return MessageLoopCurrentForIO::Get();
}
// static
bool MessageLoopForIO::IsCurrent() {
return MessageLoopCurrentForIO::IsSet();
}
} // namespace
...@@ -6,8 +6,94 @@ ...@@ -6,8 +6,94 @@
#define BASE_MESSAGE_LOOP_MESSAGE_LOOP_FORWARD_H_ #define BASE_MESSAGE_LOOP_MESSAGE_LOOP_FORWARD_H_
#include "base/message_loop/message_loop_impl.h" #include "base/message_loop/message_loop_impl.h"
#include "build/build_config.h"
// TODO(crbug.com/891670) : Extract a common interface for base::MessageLoop // TODO(crbug.com/891670) : Extract a common interface for base::MessageLoop
// in this file (to be shared with base::SequenceManager during the migration). // in this file (to be shared with base::SequenceManager during the migration).
namespace base {
#if !defined(OS_NACL)
//-----------------------------------------------------------------------------
// MessageLoopForUI extends MessageLoop with methods that are particular to a
// MessageLoop instantiated with TYPE_UI.
//
// By instantiating a MessageLoopForUI on the current thread, the owner enables
// native UI message pumping.
//
// MessageLoopCurrentForUI is exposed statically on its thread via
// MessageLoopCurrentForUI::Get() to provide additional functionality.
//
class BASE_EXPORT MessageLoopForUI : public MessageLoop {
public:
explicit MessageLoopForUI(Type type = TYPE_UI);
// TODO(gab): Mass migrate callers to MessageLoopCurrentForUI::Get()/IsSet().
static MessageLoopCurrentForUI current();
static bool IsCurrent();
#if defined(OS_IOS)
// On iOS, the main message loop cannot be Run(). Instead call Attach(),
// which connects this MessageLoop to the UI thread's CFRunLoop and allows
// PostTask() to work.
void Attach();
#endif
#if defined(OS_ANDROID)
// On Android there are cases where we want to abort immediately without
// calling Quit(), in these cases we call Abort().
void Abort();
// True if this message pump has been aborted.
bool IsAborted();
// Since Run() is never called on Android, and the message loop is run by the
// java Looper, quitting the RunLoop won't join the thread, so we need a
// callback to run when the RunLoop goes idle to let the Java thread know when
// it can safely quit.
void QuitWhenIdle(base::OnceClosure callback);
#endif
#if defined(OS_WIN)
// See method of the same name in the Windows MessagePumpForUI implementation.
void EnableWmQuit();
#endif
};
// Do not add any member variables to MessageLoopForUI! This is important b/c
// MessageLoopForUI is often allocated via MessageLoop(TYPE_UI). Any extra
// data that you need should be stored on the MessageLoop's pump_ instance.
static_assert(sizeof(MessageLoop) == sizeof(MessageLoopForUI),
"MessageLoopForUI should not have extra member variables");
#endif // !defined(OS_NACL)
//-----------------------------------------------------------------------------
// MessageLoopForIO extends MessageLoop with methods that are particular to a
// MessageLoop instantiated with TYPE_IO.
//
// By instantiating a MessageLoopForIO on the current thread, the owner enables
// native async IO message pumping.
//
// MessageLoopCurrentForIO is exposed statically on its thread via
// MessageLoopCurrentForIO::Get() to provide additional functionality.
//
class BASE_EXPORT MessageLoopForIO : public MessageLoop {
public:
MessageLoopForIO() : MessageLoop(TYPE_IO) {}
// TODO(gab): Mass migrate callers to MessageLoopCurrentForIO::Get()/IsSet().
static MessageLoopCurrentForIO current();
static bool IsCurrent();
};
// Do not add any member variables to MessageLoopForIO! This is important b/c
// MessageLoopForIO is often allocated via MessageLoop(TYPE_IO). Any extra
// data that you need should be stored on the MessageLoop's pump_ instance.
static_assert(sizeof(MessageLoop) == sizeof(MessageLoopForIO),
"MessageLoopForIO should not have extra member variables");
} // namespace base
#endif // BASE_MESSAGE_LOOP_MESSAGE_LOOP_FORWARD_H_ #endif // BASE_MESSAGE_LOOP_MESSAGE_LOOP_FORWARD_H_
...@@ -711,69 +711,4 @@ bool MessageLoop::DoIdleWork() { ...@@ -711,69 +711,4 @@ bool MessageLoop::DoIdleWork() {
return false; return false;
} }
#if !defined(OS_NACL)
//------------------------------------------------------------------------------
// MessageLoopForUI
MessageLoopForUI::MessageLoopForUI(Type type) : MessageLoop(type) {
#if defined(OS_ANDROID)
DCHECK(type == TYPE_UI || type == TYPE_JAVA);
#else
DCHECK_EQ(type, TYPE_UI);
#endif
}
// static
MessageLoopCurrentForUI MessageLoopForUI::current() {
return MessageLoopCurrentForUI::Get();
}
// static
bool MessageLoopForUI::IsCurrent() {
return MessageLoopCurrentForUI::IsSet();
}
#if defined(OS_IOS)
void MessageLoopForUI::Attach() {
static_cast<MessagePumpUIApplication*>(pump_.get())->Attach(this);
}
#endif // defined(OS_IOS)
#if defined(OS_ANDROID)
void MessageLoopForUI::Abort() {
static_cast<MessagePumpForUI*>(pump_.get())->Abort();
}
bool MessageLoopForUI::IsAborted() {
return static_cast<MessagePumpForUI*>(pump_.get())->IsAborted();
}
void MessageLoopForUI::QuitWhenIdle(base::OnceClosure callback) {
static_cast<MessagePumpForUI*>(pump_.get())
->QuitWhenIdle(std::move(callback));
}
#endif // defined(OS_ANDROID)
#if defined(OS_WIN)
void MessageLoopForUI::EnableWmQuit() {
static_cast<MessagePumpForUI*>(pump_.get())->EnableWmQuit();
}
#endif // defined(OS_WIN)
#endif // !defined(OS_NACL)
//------------------------------------------------------------------------------
// MessageLoopForIO
// static
MessageLoopCurrentForIO MessageLoopForIO::current() {
return MessageLoopCurrentForIO::Get();
}
// static
bool MessageLoopForIO::IsCurrent() {
return MessageLoopCurrentForIO::IsSet();
}
} // namespace base } // namespace base
...@@ -357,87 +357,6 @@ class BASE_EXPORT MessageLoop : public MessagePump::Delegate, ...@@ -357,87 +357,6 @@ class BASE_EXPORT MessageLoop : public MessagePump::Delegate,
DISALLOW_COPY_AND_ASSIGN(MessageLoop); DISALLOW_COPY_AND_ASSIGN(MessageLoop);
}; };
#if !defined(OS_NACL)
//-----------------------------------------------------------------------------
// MessageLoopForUI extends MessageLoop with methods that are particular to a
// MessageLoop instantiated with TYPE_UI.
//
// By instantiating a MessageLoopForUI on the current thread, the owner enables
// native UI message pumping.
//
// MessageLoopCurrentForUI is exposed statically on its thread via
// MessageLoopCurrentForUI::Get() to provide additional functionality.
//
class BASE_EXPORT MessageLoopForUI : public MessageLoop {
public:
explicit MessageLoopForUI(Type type = TYPE_UI);
// TODO(gab): Mass migrate callers to MessageLoopCurrentForUI::Get()/IsSet().
static MessageLoopCurrentForUI current();
static bool IsCurrent();
#if defined(OS_IOS)
// On iOS, the main message loop cannot be Run(). Instead call Attach(),
// which connects this MessageLoop to the UI thread's CFRunLoop and allows
// PostTask() to work.
void Attach();
#endif
#if defined(OS_ANDROID)
// On Android there are cases where we want to abort immediately without
// calling Quit(), in these cases we call Abort().
void Abort();
// True if this message pump has been aborted.
bool IsAborted();
// Since Run() is never called on Android, and the message loop is run by the
// java Looper, quitting the RunLoop won't join the thread, so we need a
// callback to run when the RunLoop goes idle to let the Java thread know when
// it can safely quit.
void QuitWhenIdle(base::OnceClosure callback);
#endif
#if defined(OS_WIN)
// See method of the same name in the Windows MessagePumpForUI implementation.
void EnableWmQuit();
#endif
};
// Do not add any member variables to MessageLoopForUI! This is important b/c
// MessageLoopForUI is often allocated via MessageLoop(TYPE_UI). Any extra
// data that you need should be stored on the MessageLoop's pump_ instance.
static_assert(sizeof(MessageLoop) == sizeof(MessageLoopForUI),
"MessageLoopForUI should not have extra member variables");
#endif // !defined(OS_NACL)
//-----------------------------------------------------------------------------
// MessageLoopForIO extends MessageLoop with methods that are particular to a
// MessageLoop instantiated with TYPE_IO.
//
// By instantiating a MessageLoopForIO on the current thread, the owner enables
// native async IO message pumping.
//
// MessageLoopCurrentForIO is exposed statically on its thread via
// MessageLoopCurrentForIO::Get() to provide additional functionality.
//
class BASE_EXPORT MessageLoopForIO : public MessageLoop {
public:
MessageLoopForIO() : MessageLoop(TYPE_IO) {}
// TODO(gab): Mass migrate callers to MessageLoopCurrentForIO::Get()/IsSet().
static MessageLoopCurrentForIO current();
static bool IsCurrent();
};
// Do not add any member variables to MessageLoopForIO! This is important b/c
// MessageLoopForIO is often allocated via MessageLoop(TYPE_IO). Any extra
// data that you need should be stored on the MessageLoop's pump_ instance.
static_assert(sizeof(MessageLoop) == sizeof(MessageLoopForIO),
"MessageLoopForIO should not have extra member variables");
} // namespace base } // namespace base
#endif // BASE_MESSAGE_LOOP_MESSAGE_LOOP_H_ #endif // BASE_MESSAGE_LOOP_MESSAGE_LOOP_H_
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