Commit 6a2f39b2 authored by Carlos Caballero's avatar Carlos Caballero Committed by Commit Bot

Remove MessageLoop in //base

MessageLoop is going away. Also had to fix a lot of includes as a bunch
of files were not directly including their dependencies.

Bug: 891670
Change-Id: I1b962b9513596b399175498278ad526fba2240f6
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1807504
Commit-Queue: Carlos Caballero <carlscab@google.com>
Reviewed-by: default avatarGabriel Charette <gab@chromium.org>
Cr-Commit-Position: refs/heads/master@{#699658}
parent 08d1887f
...@@ -23,10 +23,6 @@ ...@@ -23,10 +23,6 @@
namespace base { namespace base {
namespace internal {
class MessageLoopThreadDelegate;
} // namespace internal
class MessageLoopImpl; class MessageLoopImpl;
class MessagePump; class MessagePump;
class TaskObserver; class TaskObserver;
...@@ -160,7 +156,6 @@ class BASE_EXPORT MessageLoop { ...@@ -160,7 +156,6 @@ class BASE_EXPORT MessageLoop {
friend class MessageLoopTypedTest; friend class MessageLoopTypedTest;
friend class ScheduleWorkTest; friend class ScheduleWorkTest;
friend class Thread; friend class Thread;
friend class internal::MessageLoopThreadDelegate;
friend class sequence_manager::internal::SequenceManagerImpl; friend class sequence_manager::internal::SequenceManagerImpl;
FRIEND_TEST_ALL_PREFIXES(MessageLoopTest, DeleteUnboundLoop); FRIEND_TEST_ALL_PREFIXES(MessageLoopTest, DeleteUnboundLoop);
......
...@@ -9,7 +9,6 @@ ...@@ -9,7 +9,6 @@
#include "base/bind_helpers.h" #include "base/bind_helpers.h"
#include "base/format_macros.h" #include "base/format_macros.h"
#include "base/memory/ptr_util.h" #include "base/memory/ptr_util.h"
#include "base/message_loop/message_loop.h"
#include "base/message_loop/message_loop_current.h" #include "base/message_loop/message_loop_current.h"
#include "base/message_loop/message_pump_type.h" #include "base/message_loop/message_pump_type.h"
#include "base/single_thread_task_runner.h" #include "base/single_thread_task_runner.h"
...@@ -98,12 +97,7 @@ class ScheduleWorkTest : public testing::Test { ...@@ -98,12 +97,7 @@ class ScheduleWorkTest : public testing::Test {
target_.reset(new Thread("test")); target_.reset(new Thread("test"));
Thread::Options options(target_type, 0u); Thread::Options options(target_type, 0u);
options.message_pump_type = target_type;
std::unique_ptr<MessageLoop> message_loop =
MessageLoop::CreateUnbound(target_type);
message_loop_ = message_loop.get();
options.delegate =
new internal::MessageLoopThreadDelegate(std::move(message_loop));
target_->StartWithOptions(options); target_->StartWithOptions(options);
// Without this, it's possible for the scheduling threads to start and run // Without this, it's possible for the scheduling threads to start and run
...@@ -203,7 +197,6 @@ class ScheduleWorkTest : public testing::Test { ...@@ -203,7 +197,6 @@ class ScheduleWorkTest : public testing::Test {
private: private:
std::unique_ptr<Thread> target_; std::unique_ptr<Thread> target_;
MessageLoop* message_loop_;
#if defined(OS_ANDROID) #if defined(OS_ANDROID)
std::unique_ptr<JavaHandlerThreadForTest> java_thread_; std::unique_ptr<JavaHandlerThreadForTest> java_thread_;
#endif #endif
......
...@@ -9,8 +9,8 @@ ...@@ -9,8 +9,8 @@
#include "base/command_line.h" #include "base/command_line.h"
#include "base/files/file_util.h" #include "base/files/file_util.h"
#include "base/memory/ref_counted_memory.h" #include "base/memory/ref_counted_memory.h"
#include "base/message_loop/message_loop.h"
#include "base/run_loop.h" #include "base/run_loop.h"
#include "base/test/task_environment.h"
#include "base/threading/thread_task_runner_handle.h" #include "base/threading/thread_task_runner_handle.h"
#include "base/trace_event/trace_buffer.h" #include "base/trace_event/trace_buffer.h"
#include "base/trace_event/trace_log.h" #include "base/trace_event/trace_log.h"
...@@ -96,10 +96,10 @@ void TraceToFile::EndTracingIfNeeded() { ...@@ -96,10 +96,10 @@ void TraceToFile::EndTracingIfNeeded() {
buffer.SetOutputCallback( buffer.SetOutputCallback(
BindRepeating(&TraceToFile::TraceOutputCallback, Unretained(this))); BindRepeating(&TraceToFile::TraceOutputCallback, Unretained(this)));
// In tests we might not have a MessageLoop, create one if needed. // In tests we might not have a TaskEnvironment, create one if needed.
std::unique_ptr<MessageLoop> message_loop; std::unique_ptr<SingleThreadTaskEnvironment> task_environment;
if (!ThreadTaskRunnerHandle::IsSet()) if (!ThreadTaskRunnerHandle::IsSet())
message_loop = std::make_unique<MessageLoop>(); task_environment = std::make_unique<SingleThreadTaskEnvironment>();
RunLoop run_loop; RunLoop run_loop;
trace_event::TraceLog::GetInstance()->Flush(BindRepeating( trace_event::TraceLog::GetInstance()->Flush(BindRepeating(
......
...@@ -4,14 +4,21 @@ ...@@ -4,14 +4,21 @@
#include "base/threading/thread.h" #include "base/threading/thread.h"
#include <type_traits>
#include "base/bind.h" #include "base/bind.h"
#include "base/bind_helpers.h" #include "base/bind_helpers.h"
#include "base/lazy_instance.h" #include "base/lazy_instance.h"
#include "base/location.h" #include "base/location.h"
#include "base/logging.h" #include "base/logging.h"
#include "base/memory/ptr_util.h" #include "base/memory/ptr_util.h"
#include "base/memory/scoped_refptr.h"
#include "base/message_loop/message_loop_current.h"
#include "base/message_loop/message_pump.h"
#include "base/run_loop.h" #include "base/run_loop.h"
#include "base/synchronization/waitable_event.h" #include "base/synchronization/waitable_event.h"
#include "base/task/sequence_manager/sequence_manager_impl.h"
#include "base/task/sequence_manager/task_queue.h"
#include "base/third_party/dynamic_annotations/dynamic_annotations.h" #include "base/third_party/dynamic_annotations/dynamic_annotations.h"
#include "base/threading/thread_id_name_manager.h" #include "base/threading/thread_id_name_manager.h"
#include "base/threading/thread_local.h" #include "base/threading/thread_local.h"
...@@ -38,6 +45,56 @@ namespace { ...@@ -38,6 +45,56 @@ namespace {
base::LazyInstance<base::ThreadLocalBoolean>::Leaky lazy_tls_bool = base::LazyInstance<base::ThreadLocalBoolean>::Leaky lazy_tls_bool =
LAZY_INSTANCE_INITIALIZER; LAZY_INSTANCE_INITIALIZER;
class SequenceManagerThreadDelegate : public Thread::Delegate {
public:
explicit SequenceManagerThreadDelegate(
MessagePumpType message_pump_type,
OnceCallback<std::unique_ptr<MessagePump>()> message_pump_factory)
: sequence_manager_(
sequence_manager::internal::SequenceManagerImpl::CreateUnbound(
sequence_manager::SequenceManager::Settings::Builder()
.SetMessagePumpType(message_pump_type)
.Build())),
default_task_queue_(sequence_manager_->CreateTaskQueue(
sequence_manager::TaskQueue::Spec("default_tq"))),
message_pump_factory_(std::move(message_pump_factory)) {
sequence_manager_->SetDefaultTaskRunner(default_task_queue_->task_runner());
}
~SequenceManagerThreadDelegate() override = default;
scoped_refptr<SingleThreadTaskRunner> GetDefaultTaskRunner() override {
// Surprisingly this might not be default_task_queue_->task_runner() which
// we set in the constructor. The Thread::Init() method could create a
// SequenceManager on top of the current one and call
// SequenceManager::SetDefaultTaskRunner which would propagate the new
// TaskRunner down to our SequenceManager. Turns out, code actually relies
// on this and somehow relies on
// SequenceManagerThreadDelegate::GetDefaultTaskRunner returning this new
// TaskRunner. So instead of returning default_task_queue_->task_runner() we
// need to query the SequenceManager for it.
// The underlying problem here is that Subclasses of Thread can do crazy
// stuff in Init() but they are not really in control of what happens in the
// Thread::Delegate, as this is passed in on calling StartWithOptions which
// could happen far away from where the Thread is created. We should
// consider getting rid of StartWithOptions, and pass them as a constructor
// argument instead.
return sequence_manager_->GetTaskRunner();
}
void BindToCurrentThread(TimerSlack timer_slack) override {
sequence_manager_->BindToMessagePump(
std::move(message_pump_factory_).Run());
sequence_manager_->SetTimerSlack(timer_slack);
}
private:
std::unique_ptr<sequence_manager::internal::SequenceManagerImpl>
sequence_manager_;
scoped_refptr<sequence_manager::TaskQueue> default_task_queue_;
OnceCallback<std::unique_ptr<MessagePump>()> message_pump_factory_;
};
} // namespace } // namespace
Thread::Options::Options() = default; Thread::Options::Options() = default;
...@@ -100,11 +157,13 @@ bool Thread::StartWithOptions(const Options& options) { ...@@ -100,11 +157,13 @@ bool Thread::StartWithOptions(const Options& options) {
DCHECK(!options.message_pump_factory); DCHECK(!options.message_pump_factory);
delegate_ = WrapUnique(options.delegate); delegate_ = WrapUnique(options.delegate);
} else if (options.message_pump_factory) { } else if (options.message_pump_factory) {
delegate_ = std::make_unique<internal::MessageLoopThreadDelegate>( delegate_ = std::make_unique<SequenceManagerThreadDelegate>(
MessageLoop::CreateUnbound(options.message_pump_factory.Run())); MessagePumpType::CUSTOM, options.message_pump_factory);
} else { } else {
delegate_ = std::make_unique<internal::MessageLoopThreadDelegate>( delegate_ = std::make_unique<SequenceManagerThreadDelegate>(
MessageLoop::CreateUnbound(options.message_pump_type)); options.message_pump_type,
BindOnce([](MessagePumpType type) { return MessagePump::Create(type); },
options.message_pump_type));
} }
start_event_.Reset(); start_event_.Reset();
...@@ -291,9 +350,10 @@ void Thread::ThreadMain() { ...@@ -291,9 +350,10 @@ void Thread::ThreadMain() {
#if defined(OS_WIN) #if defined(OS_WIN)
std::unique_ptr<win::ScopedCOMInitializer> com_initializer; std::unique_ptr<win::ScopedCOMInitializer> com_initializer;
if (com_status_ != NONE) { if (com_status_ != NONE) {
com_initializer.reset((com_status_ == STA) ? com_initializer.reset(
new win::ScopedCOMInitializer() : (com_status_ == STA)
new win::ScopedCOMInitializer(win::ScopedCOMInitializer::kMTA)); ? new win::ScopedCOMInitializer()
: new win::ScopedCOMInitializer(win::ScopedCOMInitializer::kMTA));
} }
#endif #endif
...@@ -337,24 +397,4 @@ void Thread::ThreadQuitHelper() { ...@@ -337,24 +397,4 @@ void Thread::ThreadQuitHelper() {
SetThreadWasQuitProperly(true); SetThreadWasQuitProperly(true);
} }
namespace internal {
MessageLoopThreadDelegate::MessageLoopThreadDelegate(
std::unique_ptr<MessageLoop> message_loop)
: message_loop_(std::move(message_loop)) {}
MessageLoopThreadDelegate::~MessageLoopThreadDelegate() {}
scoped_refptr<SingleThreadTaskRunner>
MessageLoopThreadDelegate::GetDefaultTaskRunner() {
return message_loop_->task_runner();
}
void MessageLoopThreadDelegate::BindToCurrentThread(TimerSlack timer_slack) {
message_loop_->BindToCurrentThread();
message_loop_->SetTimerSlack(timer_slack);
}
} // namespace internal
} // namespace base } // namespace base
...@@ -13,8 +13,6 @@ ...@@ -13,8 +13,6 @@
#include "base/base_export.h" #include "base/base_export.h"
#include "base/callback.h" #include "base/callback.h"
#include "base/macros.h" #include "base/macros.h"
#include "base/message_loop/message_loop.h"
#include "base/message_loop/message_loop_current.h"
#include "base/message_loop/message_pump_type.h" #include "base/message_loop/message_pump_type.h"
#include "base/message_loop/timer_slack.h" #include "base/message_loop/timer_slack.h"
#include "base/sequence_checker.h" #include "base/sequence_checker.h"
...@@ -331,24 +329,6 @@ class BASE_EXPORT Thread : PlatformThread::Delegate { ...@@ -331,24 +329,6 @@ class BASE_EXPORT Thread : PlatformThread::Delegate {
DISALLOW_COPY_AND_ASSIGN(Thread); DISALLOW_COPY_AND_ASSIGN(Thread);
}; };
namespace internal {
class BASE_EXPORT MessageLoopThreadDelegate : public Thread::Delegate {
public:
explicit MessageLoopThreadDelegate(std::unique_ptr<MessageLoop> message_loop);
~MessageLoopThreadDelegate() override;
// Thread::Delegate:
scoped_refptr<SingleThreadTaskRunner> GetDefaultTaskRunner() override;
void BindToCurrentThread(TimerSlack timer_slack) override;
private:
std::unique_ptr<MessageLoop> message_loop_;
};
} // namespace internal
} // namespace base } // namespace base
#endif // BASE_THREADING_THREAD_H_ #endif // BASE_THREADING_THREAD_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