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

Migrate MessageLoop::current() to MessageLoopCurrent in /ui/aura

These changes were scripted as part of the effort to restrict exposure of the
raw MessageLoop*.

Note that many static methods exposed on MessageLoopCurrent are also deprecated
so it is very well possible that this is migrating to an already deprecated
method.

The goal of this pass is to reduce usage of MessageLoop::current() (and
ultimately make it impossible to obtain the MessageLoop* statically).

As such I will not edit this CL unless the script did something logically wrong.
I defer to owners to fix highlighted usage of already deprecated APIs.

Possible script screw ups / things to look out for in this review:
 - Storing MessageLoopCurrent in a MessageLoop* variable or comparing it against
   one (I will go over that in a separate pass).

Includes should have been stripped if that was the last usage of message_loop.h
in that file.

Please CQ if LGTY

This CL was uploaded by git cl split.

R=sky@chromium.org

Bug: 825327
Change-Id: I7be1ff97076aa234b31b3b3320bd7f6f3adfce63
Reviewed-on: https://chromium-review.googlesource.com/1024802
Commit-Queue: Gabriel Charette <gab@chromium.org>
Commit-Queue: Scott Violet <sky@chromium.org>
Reviewed-by: default avatarScott Violet <sky@chromium.org>
Cr-Commit-Position: refs/heads/master@{#552860}
parent cc80b13e
......@@ -11,7 +11,6 @@
#include "base/bind.h"
#include "base/macros.h"
#include "base/message_loop/message_loop.h"
#include "base/run_loop.h"
#include "base/single_thread_task_runner.h"
#include "base/stl_util.h"
......@@ -2150,21 +2149,22 @@ class WindowEventDispatcherTestWithMessageLoop
// (e.g. mouse-move events if the mouse cursor is over the window).
handler_.Reset();
base::RunLoop loop(base::RunLoop::Type::kNestableTasksAllowed);
// Start a nested message-loop, post an event to be dispatched, and then
// terminate the message-loop. When the message-loop unwinds and gets back,
// the reposted event should not have fired.
std::unique_ptr<ui::MouseEvent> mouse(new ui::MouseEvent(
ui::ET_MOUSE_PRESSED, gfx::Point(10, 10), gfx::Point(10, 10),
ui::EventTimeForNow(), ui::EF_NONE, ui::EF_NONE));
message_loop()->task_runner()->PostTask(
base::ThreadTaskRunnerHandle::Get()->PostTask(
FROM_HERE,
base::BindOnce(
&WindowEventDispatcherTestWithMessageLoop::RepostEventHelper,
host()->dispatcher(), std::move(mouse)));
message_loop()->task_runner()->PostTask(
FROM_HERE, message_loop()->QuitWhenIdleClosure());
base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE,
loop.QuitWhenIdleClosure());
base::RunLoop loop(base::RunLoop::Type::kNestableTasksAllowed);
loop.Run();
EXPECT_EQ(0, handler_.num_mouse_events());
......@@ -2172,10 +2172,6 @@ class WindowEventDispatcherTestWithMessageLoop
// message-loop when it receives the reposted event.
}
base::MessageLoop* message_loop() {
return base::MessageLoopForUI::current();
}
protected:
void SetUp() override {
WindowEventDispatcherTest::SetUp();
......@@ -2205,7 +2201,7 @@ TEST_P(WindowEventDispatcherTestWithMessageLoop, EventRepostedInNonNestedLoop) {
ASSERT_FALSE(base::RunLoop::IsRunningOnCurrentThread());
// Perform the test in a callback, so that it runs after the message-loop
// starts.
message_loop()->task_runner()->PostTask(
base::ThreadTaskRunnerHandle::Get()->PostTask(
FROM_HERE,
base::BindOnce(&WindowEventDispatcherTestWithMessageLoop::RunTest,
base::Unretained(this)));
......@@ -3206,7 +3202,7 @@ class NestedLocationDelegate : public test::TestWindowDelegate {
// at this point). The second RunLoop (created in InInitialMessageLoop())
// is considered the first nested loop.
base::RunLoop run_loop;
base::MessageLoop::current()->task_runner()->PostTask(
base::ThreadTaskRunnerHandle::Get()->PostTask(
FROM_HERE, base::BindOnce(&NestedLocationDelegate::InInitialMessageLoop,
base::Unretained(this), &run_loop));
run_loop.Run();
......@@ -3217,7 +3213,7 @@ class NestedLocationDelegate : public test::TestWindowDelegate {
// See comments in OnMouseEvent() for details on which this creates another
// RunLoop.
base::RunLoop run_loop(base::RunLoop::Type::kNestableTasksAllowed);
base::MessageLoop::current()->task_runner()->PostTask(
base::ThreadTaskRunnerHandle::Get()->PostTask(
FROM_HERE, base::BindOnce(&NestedLocationDelegate::InRunMessageLoop,
base::Unretained(this), &run_loop));
run_loop.Run();
......
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