Commit 760ab2a1 authored by Gabriel Charette's avatar Gabriel Charette Committed by Commit Bot

Use modern base APIs to avoid base::MessageLoop::current() calls in /ui/events

This is a precusor cleanup extracted from
https://chromium-review.googlesource.com/c/chromium/src/+/957760/7
in the broader effort to restrict usage of MessageLoop::current().

This CL was uploaded by git cl split.

R=sadrul@chromium.org

Bug: 825327
Change-Id: I6f8ceff1f344ac21727f1b90a3e35291718f88af
Reviewed-on: https://chromium-review.googlesource.com/986537
Commit-Queue: Gabriel Charette <gab@chromium.org>
Reviewed-by: default avatarSadrul Chowdhury <sadrul@chromium.org>
Cr-Commit-Position: refs/heads/master@{#547725}
parent 0d4a6010
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
#include "base/message_loop/message_loop.h" #include "base/message_loop/message_loop.h"
#include "base/run_loop.h" #include "base/run_loop.h"
#include "base/single_thread_task_runner.h" #include "base/single_thread_task_runner.h"
#include "base/threading/thread_task_runner_handle.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
#include "ui/events/platform/platform_event_dispatcher.h" #include "ui/events/platform/platform_event_dispatcher.h"
#include "ui/events/platform/platform_event_observer.h" #include "ui/events/platform/platform_event_observer.h"
...@@ -647,9 +648,7 @@ class DestroyedNestedOverriddenDispatcherQuitsNestedLoopIteration ...@@ -647,9 +648,7 @@ class DestroyedNestedOverriddenDispatcherQuitsNestedLoopIteration
list.clear(); list.clear();
overriding.SetScopedHandle(std::move(override_handle)); overriding.SetScopedHandle(std::move(override_handle));
base::MessageLoopForUI* loop = base::MessageLoopForUI::current(); base::ThreadTaskRunnerHandle::Get()->PostTask(
base::MessageLoopForUI::ScopedNestableTaskAllower allow_nested(loop);
loop->task_runner()->PostTask(
FROM_HERE, FROM_HERE,
base::BindOnce( base::BindOnce(
&DestroyedNestedOverriddenDispatcherQuitsNestedLoopIteration:: &DestroyedNestedOverriddenDispatcherQuitsNestedLoopIteration::
...@@ -666,7 +665,7 @@ class DestroyedNestedOverriddenDispatcherQuitsNestedLoopIteration ...@@ -666,7 +665,7 @@ class DestroyedNestedOverriddenDispatcherQuitsNestedLoopIteration
} }
private: private:
base::RunLoop run_loop_; base::RunLoop run_loop_{base::RunLoop::Type::kNestableTasksAllowed};
}; };
RUN_TEST_IN_MESSAGE_LOOP( RUN_TEST_IN_MESSAGE_LOOP(
...@@ -710,11 +709,9 @@ class ConsecutiveOverriddenDispatcherInTheSameMessageLoopIteration ...@@ -710,11 +709,9 @@ class ConsecutiveOverriddenDispatcherInTheSameMessageLoopIteration
second_overriding.SetScopedHandle(std::move(second_override_handle)); second_overriding.SetScopedHandle(std::move(second_override_handle));
second_overriding.set_post_dispatch_action(POST_DISPATCH_NONE); second_overriding.set_post_dispatch_action(POST_DISPATCH_NONE);
base::RunLoop run_loop; base::RunLoop run_loop(base::RunLoop::Type::kNestableTasksAllowed);
second_overriding.set_callback(run_loop.QuitClosure()); second_overriding.set_callback(run_loop.QuitClosure());
base::MessageLoopForUI* loop = base::MessageLoopForUI::current(); base::ThreadTaskRunnerHandle::Get()->PostTask(
base::MessageLoopForUI::ScopedNestableTaskAllower allow_nested(loop);
loop->task_runner()->PostTask(
FROM_HERE, FROM_HERE,
base::BindOnce(base::IgnoreResult(&TestPlatformEventSource::Dispatch), base::BindOnce(base::IgnoreResult(&TestPlatformEventSource::Dispatch),
base::Unretained(source()), *event)); base::Unretained(source()), *event));
...@@ -749,9 +746,7 @@ class ConsecutiveOverriddenDispatcherInTheSameMessageLoopIteration ...@@ -749,9 +746,7 @@ class ConsecutiveOverriddenDispatcherInTheSameMessageLoopIteration
// Start a nested message-loop, and destroy |override_handle| in the nested // Start a nested message-loop, and destroy |override_handle| in the nested
// loop. That should terminate the nested loop, restore the previous // loop. That should terminate the nested loop, restore the previous
// dispatchers, and return control to this function. // dispatchers, and return control to this function.
base::MessageLoopForUI* loop = base::MessageLoopForUI::current(); base::ThreadTaskRunnerHandle::Get()->PostTask(
base::MessageLoopForUI::ScopedNestableTaskAllower allow_nested(loop);
loop->task_runner()->PostTask(
FROM_HERE, FROM_HERE,
base::BindOnce( base::BindOnce(
&ConsecutiveOverriddenDispatcherInTheSameMessageLoopIteration:: &ConsecutiveOverriddenDispatcherInTheSameMessageLoopIteration::
...@@ -768,7 +763,7 @@ class ConsecutiveOverriddenDispatcherInTheSameMessageLoopIteration ...@@ -768,7 +763,7 @@ class ConsecutiveOverriddenDispatcherInTheSameMessageLoopIteration
} }
private: private:
base::RunLoop run_loop_; base::RunLoop run_loop_{base::RunLoop::Type::kNestableTasksAllowed};
}; };
RUN_TEST_IN_MESSAGE_LOOP( RUN_TEST_IN_MESSAGE_LOOP(
......
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