Commit efa8a336 authored by Sylvain Defresne's avatar Sylvain Defresne Committed by Commit Bot

Convert ui/events away from base::Bind/base::Callback

base::Bind/base::Callback are deprecated in favor of either
base::BindOnce/base::OnceCallback or base::BindRepeating/
base::RepeatingCallback (depending on whether the callback
is invoked once or multiple time).

Convert all uses of base::Bind/base::Callback in ui/events
to the recommended methods/types.

Bug: 1007850
Change-Id: Id725e2236e305a5b0b1eb5f555c3c412b8139416
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1831866
Auto-Submit: Sylvain Defresne <sdefresne@chromium.org>
Commit-Queue: Sadrul Chowdhury <sadrul@chromium.org>
Reviewed-by: default avatarSadrul Chowdhury <sadrul@chromium.org>
Cr-Commit-Position: refs/heads/master@{#701262}
parent 9ad464ef
......@@ -49,7 +49,7 @@ void DeviceDataManager::CreateInstance() {
new DeviceDataManager();
// TODO(bruthig): Replace the DeleteInstance callbacks with explicit calls.
base::AtExitManager::RegisterTask(base::Bind(DeleteInstance));
base::AtExitManager::RegisterTask(base::BindOnce(DeleteInstance));
}
// static
......
......@@ -154,7 +154,7 @@ void DeviceDataManagerX11::CreateInstance() {
// TODO(bruthig): Replace the DeleteInstance callbacks with explicit calls.
base::AtExitManager::RegisterTask(
base::Bind(DeviceDataManager::DeleteInstance));
base::BindOnce(DeviceDataManager::DeleteInstance));
}
// static
......
......@@ -336,20 +336,20 @@ class RunCallbackDuringDispatch : public TestPlatformEventDispatcher {
: TestPlatformEventDispatcher(id, list) {}
~RunCallbackDuringDispatch() override {}
void set_callback(const base::Closure& callback) {
callback_ = callback;
void set_callback(base::OnceClosure callback) {
callback_ = std::move(callback);
}
protected:
// PlatformEventDispatcher:
uint32_t DispatchEvent(const PlatformEvent& event) override {
if (!callback_.is_null())
callback_.Run();
std::move(callback_).Run();
return TestPlatformEventDispatcher::DispatchEvent(event);
}
private:
base::Closure callback_;
base::OnceClosure callback_;
DISALLOW_COPY_AND_ASSIGN(RunCallbackDuringDispatch);
};
......@@ -364,7 +364,8 @@ TEST_F(PlatformEventTest, DispatcherRemovesNextDispatcherDuringDispatch) {
TestPlatformEventDispatcher third(20, &list);
TestPlatformEventDispatcher fourth(30, &list);
second.set_callback(base::Bind(&RemoveDispatcher, base::Unretained(&third)));
second.set_callback(
base::BindOnce(&RemoveDispatcher, base::Unretained(&third)));
std::unique_ptr<PlatformEvent> event = CreatePlatformEvent();
source()->Dispatch(*event);
......@@ -384,7 +385,8 @@ TEST_F(PlatformEventTest, DispatcherRemovesSelfDuringDispatch) {
RunCallbackDuringDispatch second(15, &list);
TestPlatformEventDispatcher third(20, &list);
second.set_callback(base::Bind(&RemoveDispatcher, base::Unretained(&second)));
second.set_callback(
base::BindOnce(&RemoveDispatcher, base::Unretained(&second)));
std::unique_ptr<PlatformEvent> event = CreatePlatformEvent();
source()->Dispatch(*event);
......@@ -404,7 +406,8 @@ TEST_F(PlatformEventTest, DispatcherRemovesSelfDuringDispatchLast) {
TestPlatformEventDispatcher first(10, &list);
RunCallbackDuringDispatch second(15, &list);
second.set_callback(base::Bind(&RemoveDispatcher, base::Unretained(&second)));
second.set_callback(
base::BindOnce(&RemoveDispatcher, base::Unretained(&second)));
std::unique_ptr<PlatformEvent> event = CreatePlatformEvent();
source()->Dispatch(*event);
......@@ -423,7 +426,8 @@ TEST_F(PlatformEventTest, DispatcherRemovesPrevDispatcherDuringDispatch) {
RunCallbackDuringDispatch second(15, &list);
TestPlatformEventDispatcher third(20, &list);
second.set_callback(base::Bind(&RemoveDispatcher, base::Unretained(&first)));
second.set_callback(
base::BindOnce(&RemoveDispatcher, base::Unretained(&first)));
std::unique_ptr<PlatformEvent> event = CreatePlatformEvent();
source()->Dispatch(*event);
......@@ -444,9 +448,8 @@ TEST_F(PlatformEventTest, DispatcherRemovesPrevDispatchersDuringDispatch) {
RunCallbackDuringDispatch third(15, &list);
TestPlatformEventDispatcher fourth(20, &list);
third.set_callback(base::Bind(&RemoveDispatchers,
base::Unretained(&first),
base::Unretained(&second)));
third.set_callback(base::BindOnce(
&RemoveDispatchers, base::Unretained(&first), base::Unretained(&second)));
std::unique_ptr<PlatformEvent> event = CreatePlatformEvent();
source()->Dispatch(*event);
......@@ -475,7 +478,7 @@ TEST_F(PlatformEventTest, DispatcherAddedDuringDispatchReceivesEvent) {
EXPECT_EQ(10, list[0]);
EXPECT_EQ(15, list[1]);
second.set_callback(base::Bind(&AddDispatcher, base::Unretained(&third)));
second.set_callback(base::BindOnce(&AddDispatcher, base::Unretained(&third)));
list.clear();
source()->Dispatch(*event);
ASSERT_EQ(3u, list.size());
......@@ -483,7 +486,8 @@ TEST_F(PlatformEventTest, DispatcherAddedDuringDispatchReceivesEvent) {
EXPECT_EQ(15, list[1]);
EXPECT_EQ(20, list[2]);
second.set_callback(base::Bind(&AddDispatcher, base::Unretained(&fourth)));
second.set_callback(
base::BindOnce(&AddDispatcher, base::Unretained(&fourth)));
list.clear();
source()->Dispatch(*event);
ASSERT_EQ(4u, list.size());
......@@ -571,8 +575,8 @@ class DestroyScopedHandleDispatcher : public TestPlatformEventDispatcher {
handler_ = std::move(handler);
}
void set_callback(const base::Closure& callback) {
callback_ = callback;
void set_callback(base::OnceClosure callback) {
callback_ = std::move(callback);
}
private:
......@@ -583,14 +587,13 @@ class DestroyScopedHandleDispatcher : public TestPlatformEventDispatcher {
handler_.reset();
uint32_t action = TestPlatformEventDispatcher::DispatchEvent(event);
if (!callback_.is_null()) {
callback_.Run();
callback_ = base::Closure();
std::move(callback_).Run();
}
return action;
}
std::unique_ptr<ScopedEventDispatcher> handler_;
base::Closure callback_;
base::OnceClosure callback_;
DISALLOW_COPY_AND_ASSIGN(DestroyScopedHandleDispatcher);
};
......
......@@ -57,14 +57,14 @@ enum DeviceType {
DEVICE_TYPE_OTHER
};
typedef base::Callback<void(const std::vector<InputDevice>&)>
KeyboardDeviceCallback;
using KeyboardDeviceCallback =
base::OnceCallback<void(const std::vector<InputDevice>&)>;
typedef base::Callback<void(const std::vector<TouchscreenDevice>&)>
TouchscreenDeviceCallback;
using TouchscreenDeviceCallback =
base::OnceCallback<void(const std::vector<TouchscreenDevice>&)>;
typedef base::Callback<void(const std::vector<InputDevice>&)>
InputDeviceCallback;
using InputDeviceCallback =
base::OnceCallback<void(const std::vector<InputDevice>&)>;
// Used for updating the state on the UI thread once device information is
// parsed on helper threads.
......@@ -73,7 +73,7 @@ struct UiCallbacks {
TouchscreenDeviceCallback touchscreen_callback;
InputDeviceCallback mouse_callback;
InputDeviceCallback touchpad_callback;
base::Closure hotplug_finished_callback;
base::OnceClosure hotplug_finished_callback;
};
// Stores a copy of the XIValuatorClassInfo values so X11 device processing can
......@@ -222,10 +222,9 @@ base::FilePath GetDevicePath(XDisplay* dpy, const XIDeviceInfo& device) {
// Helper used to parse keyboard information. When it is done it uses
// |reply_runner| and |callback| to update the state on the UI thread.
void HandleKeyboardDevicesInWorker(
const std::vector<DeviceInfo>& device_infos,
scoped_refptr<base::TaskRunner> reply_runner,
const KeyboardDeviceCallback& callback) {
void HandleKeyboardDevicesInWorker(const std::vector<DeviceInfo>& device_infos,
scoped_refptr<base::TaskRunner> reply_runner,
KeyboardDeviceCallback callback) {
std::vector<InputDevice> devices;
for (const DeviceInfo& device_info : device_infos) {
......@@ -240,14 +239,15 @@ void HandleKeyboardDevicesInWorker(
devices.push_back(keyboard);
}
reply_runner->PostTask(FROM_HERE, base::BindOnce(callback, devices));
reply_runner->PostTask(FROM_HERE,
base::BindOnce(std::move(callback), devices));
}
// Helper used to parse mouse information. When it is done it uses
// |reply_runner| and |callback| to update the state on the UI thread.
void HandleMouseDevicesInWorker(const std::vector<DeviceInfo>& device_infos,
scoped_refptr<base::TaskRunner> reply_runner,
const InputDeviceCallback& callback) {
InputDeviceCallback callback) {
std::vector<InputDevice> devices;
for (const DeviceInfo& device_info : device_infos) {
if (device_info.type != DEVICE_TYPE_MOUSE ||
......@@ -259,14 +259,15 @@ void HandleMouseDevicesInWorker(const std::vector<DeviceInfo>& device_infos,
devices.push_back(InputDevice(device_info.id, type, device_info.name));
}
reply_runner->PostTask(FROM_HERE, base::BindOnce(callback, devices));
reply_runner->PostTask(FROM_HERE,
base::BindOnce(std::move(callback), devices));
}
// Helper used to parse touchpad information. When it is done it uses
// |reply_runner| and |callback| to update the state on the UI thread.
void HandleTouchpadDevicesInWorker(const std::vector<DeviceInfo>& device_infos,
scoped_refptr<base::TaskRunner> reply_runner,
const InputDeviceCallback& callback) {
InputDeviceCallback callback) {
std::vector<InputDevice> devices;
for (const DeviceInfo& device_info : device_infos) {
if (device_info.type != DEVICE_TYPE_TOUCHPAD ||
......@@ -278,7 +279,8 @@ void HandleTouchpadDevicesInWorker(const std::vector<DeviceInfo>& device_infos,
devices.push_back(InputDevice(device_info.id, type, device_info.name));
}
reply_runner->PostTask(FROM_HERE, base::BindOnce(callback, devices));
reply_runner->PostTask(FROM_HERE,
base::BindOnce(std::move(callback), devices));
}
// Helper used to parse touchscreen information. When it is done it uses
......@@ -287,7 +289,7 @@ void HandleTouchscreenDevicesInWorker(
const std::vector<DeviceInfo>& device_infos,
const DisplayState& display_state,
scoped_refptr<base::TaskRunner> reply_runner,
const TouchscreenDeviceCallback& callback) {
TouchscreenDeviceCallback callback) {
std::vector<TouchscreenDevice> devices;
if (display_state.mt_position_x == x11::None ||
display_state.mt_position_y == x11::None)
......@@ -337,23 +339,25 @@ void HandleTouchscreenDevicesInWorker(
}
}
reply_runner->PostTask(FROM_HERE, base::BindOnce(callback, devices));
reply_runner->PostTask(FROM_HERE,
base::BindOnce(std::move(callback), devices));
}
// Called on a worker thread to parse the device information.
void HandleHotplugEventInWorker(
const std::vector<DeviceInfo>& devices,
const DisplayState& display_state,
scoped_refptr<base::TaskRunner> reply_runner,
const UiCallbacks& callbacks) {
HandleTouchscreenDevicesInWorker(
devices, display_state, reply_runner, callbacks.touchscreen_callback);
HandleKeyboardDevicesInWorker(
devices, reply_runner, callbacks.keyboard_callback);
HandleMouseDevicesInWorker(devices, reply_runner, callbacks.mouse_callback);
void HandleHotplugEventInWorker(const std::vector<DeviceInfo>& devices,
const DisplayState& display_state,
scoped_refptr<base::TaskRunner> reply_runner,
UiCallbacks callbacks) {
HandleTouchscreenDevicesInWorker(devices, display_state, reply_runner,
std::move(callbacks.touchscreen_callback));
HandleKeyboardDevicesInWorker(devices, reply_runner,
std::move(callbacks.keyboard_callback));
HandleMouseDevicesInWorker(devices, reply_runner,
std::move(callbacks.mouse_callback));
HandleTouchpadDevicesInWorker(devices, reply_runner,
callbacks.touchpad_callback);
reply_runner->PostTask(FROM_HERE, callbacks.hotplug_finished_callback);
std::move(callbacks.touchpad_callback));
reply_runner->PostTask(FROM_HERE,
std::move(callbacks.hotplug_finished_callback));
}
DeviceHotplugEventObserver* GetHotplugEventObserver() {
......@@ -435,11 +439,11 @@ void X11HotplugEventHandler::OnHotplugEvent() {
display_state.mt_position_y = gfx::GetAtom("Abs MT Position Y");
UiCallbacks callbacks;
callbacks.keyboard_callback = base::Bind(&OnKeyboardDevices);
callbacks.touchscreen_callback = base::Bind(&OnTouchscreenDevices);
callbacks.mouse_callback = base::Bind(&OnMouseDevices);
callbacks.touchpad_callback = base::Bind(&OnTouchpadDevices);
callbacks.hotplug_finished_callback = base::Bind(&OnHotplugFinished);
callbacks.keyboard_callback = base::BindOnce(&OnKeyboardDevices);
callbacks.touchscreen_callback = base::BindOnce(&OnTouchscreenDevices);
callbacks.mouse_callback = base::BindOnce(&OnMouseDevices);
callbacks.touchpad_callback = base::BindOnce(&OnTouchpadDevices);
callbacks.hotplug_finished_callback = base::BindOnce(&OnHotplugFinished);
// Parse the device information asynchronously since this operation may block.
// Once the device information is extracted the parsed devices will be
......@@ -449,7 +453,8 @@ void X11HotplugEventHandler::OnHotplugEvent() {
{base::ThreadPool(), base::MayBlock(),
base::TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN},
base::BindOnce(&HandleHotplugEventInWorker, device_infos, display_state,
base::ThreadTaskRunnerHandle::Get(), callbacks));
base::ThreadTaskRunnerHandle::Get(),
std::move(callbacks)));
}
} // namespace ui
......@@ -351,7 +351,7 @@ void EventGenerator::GestureScrollSequence(const gfx::Point& start,
const base::TimeDelta& step_delay,
int steps) {
GestureScrollSequenceWithCallback(start, end, step_delay, steps,
base::Bind(&DummyCallback));
base::BindRepeating(&DummyCallback));
}
void EventGenerator::GestureScrollSequenceWithCallback(
......
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