Skip to content

Commit

Permalink
Remove use of deprecated MessageLoop methods in ui.
Browse files Browse the repository at this point in the history
MessageLoop::PostTask/PostDelayedTask/DeleteSoon/ReleaseSoon
are deprecated. This CL makes the following replacements to
remove some uses of these methods:

"MessageLoop::current()->PostTask" ->
  "ThreadTaskRunnerHandle::Get()->PostTask"
"MessageLoop::current()->PostDelayedTask" ->
  "ThreadTaskRunnerHandle::Get()->PostDelayedTask"
"MessageLoop::current()->DeleteSoon" ->
  "ThreadTaskRunnerHandle::Get()->DeleteSoon"
"MessageLoop::current()->ReleaseSoon" ->
  "ThreadTaskRunnerHandle::Get()->ReleaseSoon"

In files where these replacements are made, it adds these includes:
  #include "base/location.h"
  #include "base/single_thread_task_runner.h"
  #include "base/threading/thread_task_runner_handle.h"

And removes this include if it is no longer required:
  #include "base/message_loop/message_loop.h"

Why ThreadTaskRunnerHandle::Get() instead of
MessageLoop::current()->task_runner()?
 - The two are equivalent on threads that run a MessageLoop.
 - MessageLoop::current() doesn't work in base/task_scheduler
   because the scheduler's thread don't run MessageLoops.
   This CL will therefore facilitate the migration of browser
   threads to base/task_scheduler.

Steps to generate this patch:
1. Run message_loop_cleanup.py (see code on the bug).
2. Run tools/sort-headers.py on modified files.
3. Run git cl format.

BUG=616447
R=thakis@chromium.org

Review-Url: https://codereview.chromium.org/2049493004
Cr-Commit-Position: refs/heads/master@{#399705}
  • Loading branch information
fdoray authored and Commit bot committed Jun 14, 2016
1 parent 4ee6cc2 commit 1649dd3
Show file tree
Hide file tree
Showing 24 changed files with 163 additions and 129 deletions.
11 changes: 6 additions & 5 deletions ui/app_list/views/search_result_container_view.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
#include "ui/app_list/views/search_result_container_view.h"

#include "base/bind.h"
#include "base/message_loop/message_loop.h"
#include "base/location.h"
#include "base/single_thread_task_runner.h"
#include "base/threading/thread_task_runner_handle.h"

namespace app_list {

Expand Down Expand Up @@ -55,10 +57,9 @@ void SearchResultContainerView::ScheduleUpdate() {
// When search results are added one by one, each addition generates an update
// request. Consolidates those update requests into one Update call.
if (!update_factory_.HasWeakPtrs()) {
base::MessageLoop::current()->PostTask(
FROM_HERE,
base::Bind(&SearchResultContainerView::DoUpdate,
update_factory_.GetWeakPtr()));
base::ThreadTaskRunnerHandle::Get()->PostTask(
FROM_HERE, base::Bind(&SearchResultContainerView::DoUpdate,
update_factory_.GetWeakPtr()));
}
}

Expand Down
13 changes: 7 additions & 6 deletions ui/aura/gestures/gesture_recognizer_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,13 @@
#include <list>

#include "base/command_line.h"
#include "base/location.h"
#include "base/macros.h"
#include "base/run_loop.h"
#include "base/single_thread_task_runner.h"
#include "base/strings/string_number_conversions.h"
#include "base/test/simple_test_tick_clock.h"
#include "base/threading/thread_task_runner_handle.h"
#include "base/timer/timer.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/aura/env.h"
Expand Down Expand Up @@ -623,19 +626,17 @@ class RemoveOnTouchCancelHandler : public TestEventHandler {
void DelayByLongPressTimeout() {
ui::GestureProvider::Config config;
base::RunLoop run_loop;
base::MessageLoop::current()->PostDelayedTask(
FROM_HERE,
run_loop.QuitClosure(),
base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
FROM_HERE, run_loop.QuitClosure(),
config.gesture_detector_config.longpress_timeout * 2);
run_loop.Run();
}

void DelayByShowPressTimeout() {
ui::GestureProvider::Config config;
base::RunLoop run_loop;
base::MessageLoop::current()->PostDelayedTask(
FROM_HERE,
run_loop.QuitClosure(),
base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
FROM_HERE, run_loop.QuitClosure(),
config.gesture_detector_config.showpress_timeout * 2);
run_loop.Run();
}
Expand Down
17 changes: 8 additions & 9 deletions ui/aura/test/ui_controls_factory_ozone.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@
// found in the LICENSE file.

#include "base/bind.h"
#include "base/location.h"
#include "base/logging.h"
#include "base/macros.h"
#include "base/single_thread_task_runner.h"
#include "base/threading/thread_task_runner_handle.h"
#include "ui/aura/client/screen_position_client.h"
#include "ui/aura/env.h"
#include "ui/aura/test/aura_test_utils.h"
Expand Down Expand Up @@ -173,7 +176,7 @@ class UIControlsOzone : public ui_controls::UIControlsAura {
void RunClosureAfterAllPendingUIEvents(
const base::Closure& closure) override {
if (!closure.is_null())
base::MessageLoop::current()->PostTask(FROM_HERE, closure);
base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, closure);
}

private:
Expand All @@ -186,13 +189,9 @@ class UIControlsOzone : public ui_controls::UIControlsAura {
}

void PostKeyEvent(ui::EventType type, ui::KeyboardCode key_code, int flags) {
base::MessageLoop::current()->PostTask(
FROM_HERE,
base::Bind(&UIControlsOzone::PostKeyEventTask,
base::Unretained(this),
type,
key_code,
flags));
base::ThreadTaskRunnerHandle::Get()->PostTask(
FROM_HERE, base::Bind(&UIControlsOzone::PostKeyEventTask,
base::Unretained(this), type, key_code, flags));
}

void PostKeyEventTask(ui::EventType type,
Expand All @@ -209,7 +208,7 @@ class UIControlsOzone : public ui_controls::UIControlsAura {
const gfx::Point& host_location,
int flags,
int changed_button_flags) {
base::MessageLoop::current()->PostTask(
base::ThreadTaskRunnerHandle::Get()->PostTask(
FROM_HERE,
base::Bind(&UIControlsOzone::PostMouseEventTask, base::Unretained(this),
type, host_location, flags, changed_button_flags));
Expand Down
11 changes: 6 additions & 5 deletions ui/base/ime/chromeos/ime_keyboard_x11.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
#include <X11/XKBlib.h>
#include <X11/Xlib.h>

#include "base/location.h"
#include "base/single_thread_task_runner.h"
#include "base/threading/thread_task_runner_handle.h"
#include "ui/gfx/x/x11_types.h"

namespace chromeos {
Expand Down Expand Up @@ -183,11 +186,9 @@ void ImeKeyboardX11::PollUntilChildFinish(const base::ProcessHandle handle) {
switch (base::GetTerminationStatus(handle, &exit_code)) {
case base::TERMINATION_STATUS_STILL_RUNNING:
DVLOG(1) << "PollUntilChildFinish: Try waiting again";
base::MessageLoop::current()->PostDelayedTask(
FROM_HERE,
base::Bind(&ImeKeyboardX11::PollUntilChildFinish,
weak_factory_.GetWeakPtr(),
handle),
base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
FROM_HERE, base::Bind(&ImeKeyboardX11::PollUntilChildFinish,
weak_factory_.GetWeakPtr(), handle),
base::TimeDelta::FromMilliseconds(kSetLayoutCommandCheckDelayMs));
return;

Expand Down
6 changes: 4 additions & 2 deletions ui/base/models/simple_menu_model.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
#include <stddef.h>

#include "base/bind.h"
#include "base/message_loop/message_loop.h"
#include "base/location.h"
#include "base/single_thread_task_runner.h"
#include "base/threading/thread_task_runner_handle.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/gfx/image/image.h"

Expand Down Expand Up @@ -393,7 +395,7 @@ void SimpleMenuModel::MenuClosed() {
// Due to how menus work on the different platforms, ActivatedAt will be
// called after this. It's more convenient for the delegate to be called
// afterwards though, so post a task.
base::MessageLoop::current()->PostTask(
base::ThreadTaskRunnerHandle::Get()->PostTask(
FROM_HERE,
base::Bind(&SimpleMenuModel::OnMenuClosed, method_factory_.GetWeakPtr()));
}
Expand Down
8 changes: 5 additions & 3 deletions ui/base/test/ui_controls_internal_win.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@

#include "base/bind.h"
#include "base/callback.h"
#include "base/location.h"
#include "base/logging.h"
#include "base/macros.h"
#include "base/memory/ref_counted.h"
#include "base/message_loop/message_loop.h"
#include "base/single_thread_task_runner.h"
#include "base/threading/thread_task_runner_handle.h"
#include "ui/events/keycodes/keyboard_code_conversion_win.h"
#include "ui/events/keycodes/keyboard_codes.h"

Expand Down Expand Up @@ -126,7 +128,7 @@ void InputDispatcher::MatchingMessageFound() {
UninstallHook(this);
// At the time we're invoked the event has not actually been processed.
// Use PostTask to make sure the event has been processed before notifying.
base::MessageLoop::current()->PostTask(
base::ThreadTaskRunnerHandle::Get()->PostTask(
FROM_HERE, base::Bind(&InputDispatcher::NotifyTask, this));
}

Expand Down Expand Up @@ -251,7 +253,7 @@ bool SendMouseMoveImpl(long screen_x,
::GetCursorPos(&current_pos);
if (screen_x == current_pos.x && screen_y == current_pos.y) {
if (!task.is_null())
base::MessageLoop::current()->PostTask(FROM_HERE, task);
base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, task);
return true;
}

Expand Down
12 changes: 7 additions & 5 deletions ui/base/win/osk_display_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@

#include "base/bind.h"
#include "base/debug/leak_annotations.h"
#include "base/location.h"
#include "base/logging.h"
#include "base/message_loop/message_loop.h"
#include "base/single_thread_task_runner.h"
#include "base/strings/string_util.h"
#include "base/threading/thread_task_runner_handle.h"
#include "base/win/registry.h"
#include "base/win/scoped_co_mem.h"
#include "base/win/win_util.h"
Expand Down Expand Up @@ -122,7 +124,7 @@ void OnScreenKeyboardDetector::DetectKeyboard(HWND main_window) {
// OnScreenKeyboardDisplayManager::DisplayVirtualKeyboard() function. We use
// a delayed task to check if the keyboard is visible because of the possible
// delay between the ShellExecute call and the keyboard becoming visible.
base::MessageLoop::current()->PostDelayedTask(
base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
FROM_HERE, base::Bind(&OnScreenKeyboardDetector::CheckIfKeyboardVisible,
keyboard_detector_factory_.GetWeakPtr()),
base::TimeDelta::FromMilliseconds(kCheckOSKDelayMs));
Expand All @@ -143,7 +145,7 @@ bool OnScreenKeyboardDetector::DismissKeyboard() {
keyboard_dismiss_retry_count_++;
// Please refer to the comments in the DetectKeyboard() function for more
// information as to why we need a delayed task here.
base::MessageLoop::current()->PostDelayedTask(
base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
FROM_HERE, base::Bind(base::IgnoreResult(
&OnScreenKeyboardDetector::DismissKeyboard),
keyboard_detector_factory_.GetWeakPtr()),
Expand Down Expand Up @@ -206,7 +208,7 @@ void OnScreenKeyboardDetector::HideIfNecessary() {
DismissKeyboard();
}
} else {
base::MessageLoop::current()->PostDelayedTask(
base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
FROM_HERE, base::Bind(&OnScreenKeyboardDetector::HideIfNecessary,
keyboard_detector_factory_.GetWeakPtr()),
base::TimeDelta::FromMilliseconds(kCheckOSKDelayMs));
Expand All @@ -221,7 +223,7 @@ void OnScreenKeyboardDetector::HandleKeyboardVisible() {
OnKeyboardVisible(osk_rect_pixels_));

// Now that the keyboard is visible, run the task to detect if it was hidden.
base::MessageLoop::current()->PostDelayedTask(
base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
FROM_HERE, base::Bind(&OnScreenKeyboardDetector::HideIfNecessary,
keyboard_detector_factory_.GetWeakPtr()),
base::TimeDelta::FromMilliseconds(kCheckOSKDelayMs));
Expand Down
11 changes: 7 additions & 4 deletions ui/base/x/x11_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@

#include "ui/base/x/x11_util.h"

#include <X11/Xcursor/Xcursor.h>
#include <X11/extensions/XInput2.h>
#include <X11/extensions/shape.h>
#include <ctype.h>
#include <sys/ipc.h>
#include <sys/shm.h>
#include <X11/extensions/shape.h>
#include <X11/extensions/XInput2.h>
#include <X11/Xcursor/Xcursor.h>

#include <list>
#include <map>
Expand All @@ -22,17 +22,20 @@
#include <vector>

#include "base/bind.h"
#include "base/location.h"
#include "base/logging.h"
#include "base/macros.h"
#include "base/memory/singleton.h"
#include "base/message_loop/message_loop.h"
#include "base/metrics/histogram.h"
#include "base/single_thread_task_runner.h"
#include "base/stl_util.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_util.h"
#include "base/strings/stringprintf.h"
#include "base/sys_byteorder.h"
#include "base/threading/thread.h"
#include "base/threading/thread_task_runner_handle.h"
#include "base/trace_event/trace_event.h"
#include "build/build_config.h"
#include "skia/ext/image_operations.h"
Expand Down Expand Up @@ -71,7 +74,7 @@ namespace {

int DefaultX11ErrorHandler(XDisplay* d, XErrorEvent* e) {
if (base::MessageLoop::current()) {
base::MessageLoop::current()->PostTask(
base::ThreadTaskRunnerHandle::Get()->PostTask(
FROM_HERE, base::Bind(&LogErrorEventDescription, d, *e));
} else {
LOG(ERROR)
Expand Down
12 changes: 7 additions & 5 deletions ui/display/chromeos/test/test_native_display_delegate.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
#include "ui/display/chromeos/test/test_native_display_delegate.h"

#include "base/bind.h"
#include "base/message_loop/message_loop.h"
#include "base/location.h"
#include "base/single_thread_task_runner.h"
#include "base/threading/thread_task_runner_handle.h"
#include "ui/display/chromeos/test/action_logger.h"
#include "ui/display/types/display_mode.h"

Expand Down Expand Up @@ -63,8 +65,8 @@ void TestNativeDisplayDelegate::ForceDPMSOn() {
void TestNativeDisplayDelegate::GetDisplays(
const GetDisplaysCallback& callback) {
if (run_async_) {
base::MessageLoop::current()->PostTask(FROM_HERE,
base::Bind(callback, outputs_));
base::ThreadTaskRunnerHandle::Get()->PostTask(
FROM_HERE, base::Bind(callback, outputs_));
} else {
callback.Run(outputs_);
}
Expand Down Expand Up @@ -95,8 +97,8 @@ void TestNativeDisplayDelegate::Configure(const DisplaySnapshot& output,
const ConfigureCallback& callback) {
bool result = Configure(output, mode, origin);
if (run_async_) {
base::MessageLoop::current()->PostTask(FROM_HERE,
base::Bind(callback, result));
base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE,
base::Bind(callback, result));
} else {
callback.Run(result);
}
Expand Down
5 changes: 4 additions & 1 deletion ui/events/gesture_detection/gesture_provider_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,11 @@

#include <memory>

#include "base/location.h"
#include "base/logging.h"
#include "base/message_loop/message_loop.h"
#include "base/single_thread_task_runner.h"
#include "base/threading/thread_task_runner_handle.h"
#include "base/time/time.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/events/event_constants.h"
Expand Down Expand Up @@ -413,7 +416,7 @@ class GestureProviderTest : public testing::Test, public GestureProviderClient {
}

static void RunTasksAndWait(base::TimeDelta delay) {
base::MessageLoop::current()->PostDelayedTask(
base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
FROM_HERE, base::MessageLoop::QuitWhenIdleClosure(), delay);
base::MessageLoop::current()->Run();
}
Expand Down
6 changes: 4 additions & 2 deletions ui/events/test/platform_event_waiter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@

#include "ui/events/test/platform_event_waiter.h"

#include "base/message_loop/message_loop.h"
#include "base/location.h"
#include "base/single_thread_task_runner.h"
#include "base/threading/thread_task_runner_handle.h"
#include "ui/events/platform/platform_event_source.h"

namespace ui {
Expand All @@ -23,7 +25,7 @@ PlatformEventWaiter::~PlatformEventWaiter() {

void PlatformEventWaiter::WillProcessEvent(const PlatformEvent& event) {
if (event_matcher_.Run(event)) {
base::MessageLoop::current()->PostTask(FROM_HERE, success_callback_);
base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, success_callback_);
delete this;
}
}
Expand Down
5 changes: 4 additions & 1 deletion ui/gl/gl_context_cgl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@
#include <memory>
#include <vector>

#include "base/location.h"
#include "base/logging.h"
#include "base/single_thread_task_runner.h"
#include "base/threading/thread_task_runner_handle.h"
#include "base/trace_event/trace_event.h"
#include "ui/gl/gl_bindings.h"
#include "ui/gl/gl_implementation.h"
Expand Down Expand Up @@ -146,7 +149,7 @@ void GLContextCGL::Destroy() {
if (base::MessageLoop::current() != nullptr) {
// Delay releasing the pixel format for 10 seconds to reduce the number of
// unnecessary GPU switches.
base::MessageLoop::current()->PostDelayedTask(
base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
FROM_HERE, base::Bind(&CGLReleasePixelFormat, discrete_pixelformat_),
base::TimeDelta::FromSeconds(10));
} else {
Expand Down
5 changes: 4 additions & 1 deletion ui/keyboard/keyboard_controller.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@

#include "base/bind.h"
#include "base/command_line.h"
#include "base/location.h"
#include "base/macros.h"
#include "base/single_thread_task_runner.h"
#include "base/threading/thread_task_runner_handle.h"
#include "build/build_config.h"
#include "ui/aura/window.h"
#include "ui/aura/window_delegate.h"
Expand Down Expand Up @@ -360,7 +363,7 @@ void KeyboardController::OnTextInputStateChanged(
// Set the visibility state here so that any queries for visibility
// before the timer fires returns the correct future value.
keyboard_visible_ = false;
base::MessageLoop::current()->PostDelayedTask(
base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
FROM_HERE,
base::Bind(&KeyboardController::HideKeyboard,
weak_factory_.GetWeakPtr(), HIDE_REASON_AUTOMATIC),
Expand Down
Loading

0 comments on commit 1649dd3

Please sign in to comment.