Commit d8839445 authored by Gabriel Charette's avatar Gabriel Charette Committed by Commit Bot

Cleanup base APIs after PROCESS_LAUNCHER removal.

Follow-up to https://chromium-review.googlesource.com/c/chromium/src/+/941264

Now that only BrowserThread::UI/IO remain: APIs used to prevent
further abuse in other BrowserThreads during their deprecation are no
longer needed :).

R=fdoray@chromium.org

Bug: 815225
Change-Id: Ifa952367cd2ba87d035c14f0428393644503ef18
Reviewed-on: https://chromium-review.googlesource.com/963361
Commit-Queue: Gabriel Charette <gab@chromium.org>
Reviewed-by: default avatarFrançois Doray <fdoray@chromium.org>
Reviewed-by: default avatarKen Rockot <rockot@chromium.org>
Cr-Commit-Position: refs/heads/master@{#543462}
parent 490cbadc
......@@ -225,8 +225,6 @@ Closure MessageLoop::QuitWhenIdleClosure() {
void MessageLoop::SetNestableTasksAllowed(bool allowed) {
if (allowed) {
CHECK(RunLoop::IsNestingAllowedOnCurrentThread());
// Kick the native pump just in case we enter a OS-driven nested message
// loop that does not go through RunLoop::Run().
pump_->ScheduleWork();
......@@ -243,13 +241,11 @@ bool MessageLoop::NestableTasksAllowed() const {
// implementation detail. http://crbug.com/703346
void MessageLoop::AddTaskObserver(TaskObserver* task_observer) {
DCHECK_EQ(this, current());
CHECK(allow_task_observers_);
task_observers_.AddObserver(task_observer);
}
void MessageLoop::RemoveTaskObserver(TaskObserver* task_observer) {
DCHECK_EQ(this, current());
CHECK(allow_task_observers_);
task_observers_.RemoveObserver(task_observer);
}
......
......@@ -276,10 +276,6 @@ class BASE_EXPORT MessageLoop : public MessagePump::Delegate,
// Runs the specified PendingTask.
void RunTask(PendingTask* pending_task);
// Disallow task observers. After this is called, calling
// Add/RemoveTaskObserver() on this MessageLoop will crash.
void DisallowTaskObservers() { allow_task_observers_ = false; }
//----------------------------------------------------------------------------
protected:
std::unique_ptr<MessagePump> pump_;
......@@ -399,9 +395,6 @@ class BASE_EXPORT MessageLoop : public MessagePump::Delegate,
// MessageLoop is bound to its thread and constant forever after.
PlatformThreadId thread_id_ = kInvalidThreadId;
// Whether task observers are allowed.
bool allow_task_observers_ = true;
// Holds data stored through the SequenceLocalStorageSlot API.
internal::SequenceLocalStorageMap sequence_local_storage_map_;
......
......@@ -103,9 +103,6 @@ RunLoop::RunLoop(Type type)
DCHECK(delegate_) << "A RunLoop::Delegate must be bound to this thread prior "
"to using RunLoop.";
DCHECK(origin_task_runner_);
DCHECK(IsNestingAllowedOnCurrentThread() ||
type_ != Type::kNestableTasksAllowed);
}
RunLoop::~RunLoop() {
......@@ -219,7 +216,6 @@ bool RunLoop::IsNestedOnCurrentThread() {
void RunLoop::AddNestingObserverOnCurrentThread(NestingObserver* observer) {
Delegate* delegate = tls_delegate.Get().Get();
DCHECK(delegate);
CHECK(delegate->allow_nesting_);
delegate->nesting_observers_.AddObserver(observer);
}
......@@ -227,20 +223,9 @@ void RunLoop::AddNestingObserverOnCurrentThread(NestingObserver* observer) {
void RunLoop::RemoveNestingObserverOnCurrentThread(NestingObserver* observer) {
Delegate* delegate = tls_delegate.Get().Get();
DCHECK(delegate);
CHECK(delegate->allow_nesting_);
delegate->nesting_observers_.RemoveObserver(observer);
}
// static
bool RunLoop::IsNestingAllowedOnCurrentThread() {
return tls_delegate.Get().Get()->allow_nesting_;
}
// static
void RunLoop::DisallowNestingOnCurrentThread() {
tls_delegate.Get().Get()->allow_nesting_ = false;
}
// static
void RunLoop::QuitCurrentDeprecated() {
DCHECK(IsRunningOnCurrentThread());
......@@ -301,7 +286,6 @@ bool RunLoop::BeforeRun() {
const bool is_nested = active_run_loops_.size() > 1;
if (is_nested) {
CHECK(delegate_->allow_nesting_);
for (auto& observer : delegate_->nesting_observers_)
observer.OnBeginNestedRunLoop();
if (type_ == Type::kNestableTasksAllowed)
......
......@@ -50,9 +50,7 @@ class BASE_EXPORT RunLoop {
// recursive task processing is disabled.
//
// In general, nestable RunLoops are to be avoided. They are dangerous and
// difficult to get right, so please use with extreme caution. To further
// protect this: kNestableTasksAllowed RunLoops are only allowed on threads
// where IsNestingAllowedOnCurrentThread().
// difficult to get right, so please use with extreme caution.
//
// A specific example where this makes a difference is:
// - The thread is running a RunLoop.
......@@ -145,13 +143,6 @@ class BASE_EXPORT RunLoop {
static void AddNestingObserverOnCurrentThread(NestingObserver* observer);
static void RemoveNestingObserverOnCurrentThread(NestingObserver* observer);
// Returns true if nesting is allowed on this thread.
static bool IsNestingAllowedOnCurrentThread();
// Disallow nesting. After this is called, running a nested RunLoop or calling
// Add/RemoveNestingObserverOnCurrentThread() on this thread will crash.
static void DisallowNestingOnCurrentThread();
// A RunLoop::Delegate is a generic interface that allows RunLoop to be
// separate from the underlying implementation of the message loop for this
// thread. It holds private state used by RunLoops on its associated thread.
......@@ -207,7 +198,6 @@ class BASE_EXPORT RunLoop {
// have more than a few entries.
using RunLoopStack = base::stack<RunLoop*, std::vector<RunLoop*>>;
bool allow_nesting_ = true;
RunLoopStack active_run_loops_;
ObserverList<RunLoop::NestingObserver> nesting_observers_;
......
......@@ -596,8 +596,6 @@ class MockTask {
} // namespace
TEST_P(RunLoopTest, NestingObservers) {
EXPECT_TRUE(RunLoop::IsNestingAllowedOnCurrentThread());
testing::StrictMock<MockNestingObserver> nesting_observer;
testing::StrictMock<MockTask> mock_task_a;
testing::StrictMock<MockTask> mock_task_b;
......@@ -606,10 +604,6 @@ TEST_P(RunLoopTest, NestingObservers) {
const RepeatingClosure run_nested_loop = Bind([]() {
RunLoop nested_run_loop(RunLoop::Type::kNestableTasksAllowed);
ThreadTaskRunnerHandle::Get()->PostTask(
FROM_HERE, BindOnce([]() {
EXPECT_TRUE(RunLoop::IsNestingAllowedOnCurrentThread());
}));
ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE,
nested_run_loop.QuitClosure());
nested_run_loop.Run();
......@@ -617,7 +611,9 @@ TEST_P(RunLoopTest, NestingObservers) {
// Generate a stack of nested RunLoops. OnBeginNestedRunLoop() is expected
// when beginning each nesting depth and OnExitNestedRunLoop() is expected
// when exiting each nesting depth.
// when exiting each nesting depth. Each one of these tasks is ahead of the
// QuitClosures as those are only posted at the end of the queue when
// |run_nested_loop| is executed.
ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, run_nested_loop);
ThreadTaskRunnerHandle::Get()->PostTask(
FROM_HERE,
......@@ -640,21 +636,6 @@ TEST_P(RunLoopTest, NestingObservers) {
RunLoop::RemoveNestingObserverOnCurrentThread(&nesting_observer);
}
// Disabled on Android per http://crbug.com/643760.
#if defined(GTEST_HAS_DEATH_TEST) && !defined(OS_ANDROID)
TEST_P(RunLoopTest, DisallowNestingDeathTest) {
EXPECT_TRUE(RunLoop::IsNestingAllowedOnCurrentThread());
RunLoop::DisallowNestingOnCurrentThread();
EXPECT_FALSE(RunLoop::IsNestingAllowedOnCurrentThread());
ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, BindOnce([]() {
RunLoop nested_run_loop;
nested_run_loop.RunUntilIdle();
}));
EXPECT_DEATH({ run_loop_.RunUntilIdle(); }, "");
}
#endif // defined(GTEST_HAS_DEATH_TEST) && !defined(OS_ANDROID)
TEST_P(RunLoopTest, DisallowRunningForTesting) {
RunLoop::ScopedDisallowRunningForTesting disallow_running;
EXPECT_DCHECK_DEATH({ run_loop_.Run(); });
......
......@@ -89,10 +89,8 @@ class Connector::RunLoopNestingObserver
}
static RunLoopNestingObserver* GetForThread() {
if (!base::MessageLoop::current() ||
!base::RunLoop::IsNestingAllowedOnCurrentThread()) {
if (!base::MessageLoop::current())
return nullptr;
}
auto* observer = static_cast<RunLoopNestingObserver*>(
g_tls_nesting_observer.Get().Get());
if (!observer) {
......
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