Commit 17cf8347 authored by Alex Clarke's avatar Alex Clarke Committed by Commit Bot

Remove unused external message loop support from base::Thread

The callsites were removed in crrev.com/618761.

Bug: 826465
Change-Id: If1b36e9b95b83183653bf5c927d8bdd8dbee7959
Reviewed-on: https://chromium-review.googlesource.com/c/1478893Reviewed-by: default avatarGabriel Charette <gab@chromium.org>
Commit-Queue: Gabriel Charette <gab@chromium.org>
Cr-Commit-Position: refs/heads/master@{#634300}
parent fa1fa225
...@@ -208,15 +208,6 @@ void Thread::StopSoon() { ...@@ -208,15 +208,6 @@ void Thread::StopSoon() {
stopping_ = true; stopping_ = true;
if (using_external_message_loop_) {
// Setting |stopping_| to true above should have been sufficient for this
// thread to be considered "stopped" per it having never set its |running_|
// bit by lack of its own ThreadMain.
DCHECK(!IsRunning());
message_loop_base_ = nullptr;
return;
}
task_runner()->PostTask( task_runner()->PostTask(
FROM_HERE, base::BindOnce(&Thread::ThreadQuitHelper, Unretained(this))); FROM_HERE, base::BindOnce(&Thread::ThreadQuitHelper, Unretained(this)));
} }
...@@ -272,19 +263,6 @@ bool Thread::GetThreadWasQuitProperly() { ...@@ -272,19 +263,6 @@ bool Thread::GetThreadWasQuitProperly() {
return quit_properly; return quit_properly;
} }
void Thread::SetMessageLoop(MessageLoop* message_loop) {
DCHECK(owning_sequence_checker_.CalledOnValidSequence());
DCHECK(message_loop);
// Setting |message_loop_base_| should suffice for this thread to be
// considered as "running", until Stop() is invoked.
DCHECK(!IsRunning());
message_loop_base_ = message_loop->GetMessageLoopBase();
DCHECK(IsRunning());
using_external_message_loop_ = true;
}
void Thread::ThreadMain() { void Thread::ThreadMain() {
// First, make GetThreadId() available to avoid deadlocks. It could be called // First, make GetThreadId() available to avoid deadlocks. It could be called
// any place in the following thread initialization code. // any place in the following thread initialization code.
......
...@@ -248,16 +248,6 @@ class BASE_EXPORT Thread : PlatformThread::Delegate { ...@@ -248,16 +248,6 @@ class BASE_EXPORT Thread : PlatformThread::Delegate {
static void SetThreadWasQuitProperly(bool flag); static void SetThreadWasQuitProperly(bool flag);
static bool GetThreadWasQuitProperly(); static bool GetThreadWasQuitProperly();
// Bind this Thread to an existing MessageLoop instead of starting a new one.
// TODO(gab): Remove this after ios/ has undergone the same surgery as
// BrowserThreadImpl (ref.
// https://chromium-review.googlesource.com/c/chromium/src/+/969104).
void SetMessageLoop(MessageLoop* message_loop);
bool using_external_message_loop() const {
return using_external_message_loop_;
}
// Returns the message loop for this thread. Use the MessageLoop's // Returns the message loop for this thread. Use the MessageLoop's
// PostTask methods to execute code on the thread. This only returns // PostTask methods to execute code on the thread. This only returns
// non-null after a successful call to Start. After Stop has been called, // non-null after a successful call to Start. After Stop has been called,
...@@ -331,13 +321,6 @@ class BASE_EXPORT Thread : PlatformThread::Delegate { ...@@ -331,13 +321,6 @@ class BASE_EXPORT Thread : PlatformThread::Delegate {
MessageLoopBase* message_loop_base_ = nullptr; MessageLoopBase* message_loop_base_ = nullptr;
RunLoop* run_loop_ = nullptr; RunLoop* run_loop_ = nullptr;
// True only if |message_loop_base_| was externally provided by |
// SetMessageLoop()| in which case this Thread has no underlying |thread_| and
// should merely drop |message_loop_base_| on Stop(). In that event, this
// remains true after Stop() was invoked so that subclasses can use this state
// to build their own cleanup logic as required.
bool using_external_message_loop_ = false;
// Stores Options::timer_slack_ until the sequence manager has been bound to // Stores Options::timer_slack_ until the sequence manager has been bound to
// a thread. // a thread.
TimerSlack timer_slack_ = TIMER_SLACK_NONE; TimerSlack timer_slack_ = TIMER_SLACK_NONE;
......
...@@ -522,61 +522,6 @@ TEST_F(ThreadTest, FlushForTesting) { ...@@ -522,61 +522,6 @@ TEST_F(ThreadTest, FlushForTesting) {
a.FlushForTesting(); a.FlushForTesting();
} }
namespace {
// A Thread which uses a MessageLoop on the stack. It won't start a real
// underlying thread (instead its messages can be processed by a RunLoop on the
// stack).
class ExternalMessageLoopThread : public Thread {
public:
ExternalMessageLoopThread() : Thread("ExternalMessageLoopThread") {}
~ExternalMessageLoopThread() override { Stop(); }
void InstallMessageLoop() { SetMessageLoop(&external_message_loop_); }
void VerifyUsingExternalMessageLoop(
bool expected_using_external_message_loop) {
EXPECT_EQ(expected_using_external_message_loop,
using_external_message_loop());
}
private:
base::MessageLoop external_message_loop_;
DISALLOW_COPY_AND_ASSIGN(ExternalMessageLoopThread);
};
} // namespace
TEST_F(ThreadTest, ExternalMessageLoop) {
ExternalMessageLoopThread a;
EXPECT_FALSE(a.task_runner());
EXPECT_FALSE(a.IsRunning());
a.VerifyUsingExternalMessageLoop(false);
a.InstallMessageLoop();
EXPECT_TRUE(a.task_runner());
EXPECT_TRUE(a.IsRunning());
a.VerifyUsingExternalMessageLoop(true);
bool ran = false;
a.task_runner()->PostTask(
FROM_HERE, base::BindOnce([](bool* toggled) { *toggled = true; }, &ran));
base::RunLoop().RunUntilIdle();
EXPECT_TRUE(ran);
a.Stop();
EXPECT_FALSE(a.task_runner());
EXPECT_FALSE(a.IsRunning());
a.VerifyUsingExternalMessageLoop(true);
// Confirm that running any remaining tasks posted from Stop() goes smoothly
// (e.g. https://codereview.chromium.org/2135413003/#ps300001 crashed if
// StopSoon() posted Thread::ThreadQuitHelper() while |run_loop_| was null).
base::RunLoop().RunUntilIdle();
}
TEST_F(ThreadTest, ProvidedMessageLoopBase) { TEST_F(ThreadTest, ProvidedMessageLoopBase) {
Thread thread("ProvidedMessageLoopBase"); Thread thread("ProvidedMessageLoopBase");
std::unique_ptr<base::sequence_manager::internal::SequenceManagerImpl> std::unique_ptr<base::sequence_manager::internal::SequenceManagerImpl>
......
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