Skip to content

Commit

Permalink
Remove remaining calls to deprecated MessageLoop methods on Mac.
Browse files Browse the repository at this point in the history
With this CL, there is no remaining call to these methods on Mac:
- MessageLoop::PostTask
- MessageLoop::PostDelayedTask
- MessageLoop::ReleaseSoon
- MessageLoop::DeleteSoon
- MessageLoop::Run
- MessageLoop::RunUntilIdle

Note that this CL also removes calls to these methods from files that
are not built on Mac.

These calls were not migrated by the clang-tidy script used previously
for various reasons (Objective-C code, templates, macros, header files,
std::unique_ptr<MessageLoop>...).

This CL was generated manually (with the help of a few regular
expressions).

BUG=616447
CQ_INCLUDE_TRYBOTS=tryserver.chromium.linux:linux_optional_gpu_tests_rel;tryserver.chromium.mac:mac_optional_gpu_tests_rel;tryserver.chromium.win:win_optional_gpu_tests_rel
TBR=sdefresne@chromium.org (for ios/'s trivial application of this refactoring)

Review-Url: https://codereview.chromium.org/2132593002
Cr-Commit-Position: refs/heads/master@{#406148}
  • Loading branch information
fdoray authored and Commit bot committed Jul 18, 2016
1 parent e91b4fc commit 2df4a9e
Show file tree
Hide file tree
Showing 70 changed files with 423 additions and 367 deletions.
6 changes: 3 additions & 3 deletions base/files/file_path_watcher_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -197,9 +197,9 @@ class FilePathWatcherTest : public testing::Test {
bool WaitForEvents() WARN_UNUSED_RESULT {
collector_->Reset();
// Make sure we timeout if we don't get notified.
loop_.PostDelayedTask(FROM_HERE,
MessageLoop::QuitWhenIdleClosure(),
TestTimeouts::action_timeout());
loop_.task_runner()->PostDelayedTask(FROM_HERE,
MessageLoop::QuitWhenIdleClosure(),
TestTimeouts::action_timeout());
RunLoop().Run();
return collector_->Success();
}
Expand Down
3 changes: 2 additions & 1 deletion base/ios/weak_nsobject_unittest.mm
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "base/ios/weak_nsobject.h"
#include "base/mac/scoped_nsobject.h"
#include "base/message_loop/message_loop.h"
#include "base/run_loop.h"
#include "base/single_thread_task_runner.h"
#include "base/threading/thread.h"
#include "testing/gtest/include/gtest/gtest.h"
Expand Down Expand Up @@ -129,7 +130,7 @@ void CopyWeakNSObjectAndPost(const WeakNSObject<NSMutableData>& weak_object,
other_thread.task_runner()->PostTask(
FROM_HERE, Bind(&CopyWeakNSObjectAndPost, weak, runner));
other_thread.Stop();
loop.RunUntilIdle();
RunLoop().RunUntilIdle();

// Check that TouchWeakData was called and the object touched twice.
EXPECT_EQ(2u, [data length]);
Expand Down
5 changes: 3 additions & 2 deletions base/memory/memory_pressure_listener_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#include "base/bind.h"
#include "base/message_loop/message_loop.h"
#include "base/run_loop.h"
#include "testing/gmock/include/gmock/gmock.h"

namespace base {
Expand All @@ -31,15 +32,15 @@ class MemoryPressureListenerTest : public testing::Test {
MemoryPressureLevel level) {
EXPECT_CALL(*this, OnMemoryPressure(level)).Times(1);
notification_function(level);
message_loop_->RunUntilIdle();
RunLoop().RunUntilIdle();
}

void ExpectNoNotification(
void (*notification_function)(MemoryPressureLevel),
MemoryPressureLevel level) {
EXPECT_CALL(*this, OnMemoryPressure(testing::_)).Times(0);
notification_function(level);
message_loop_->RunUntilIdle();
RunLoop().RunUntilIdle();
}

private:
Expand Down
5 changes: 2 additions & 3 deletions base/message_loop/message_loop_task_runner_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
#include "base/message_loop/message_loop.h"
#include "base/message_loop/message_loop_task_runner.h"
#include "base/run_loop.h"
#include "base/single_thread_task_runner.h"
#include "base/synchronization/waitable_event.h"
#include "base/threading/thread.h"
#include "base/threading/thread_task_runner_handle.h"
Expand Down Expand Up @@ -125,7 +124,7 @@ TEST_F(MessageLoopTaskRunnerTest, PostTaskAndReply_Basic) {
ASSERT_FALSE(reply_deleted_on);

UnblockTaskThread();
current_loop_->Run();
RunLoop().Run();

EXPECT_EQ(task_thread_.message_loop(), task_run_on);
EXPECT_EQ(current_loop_.get(), task_deleted_on);
Expand Down Expand Up @@ -192,7 +191,7 @@ TEST_F(MessageLoopTaskRunnerTest, PostTaskAndReply_SameLoop) {
ASSERT_FALSE(task_deleted_on);
ASSERT_FALSE(reply_deleted_on);

current_loop_->Run();
RunLoop().Run();

EXPECT_EQ(current_loop_.get(), task_run_on);
EXPECT_EQ(current_loop_.get(), task_deleted_on);
Expand Down
20 changes: 11 additions & 9 deletions base/message_loop/message_loop_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
#include "base/pending_task.h"
#include "base/posix/eintr_wrapper.h"
#include "base/run_loop.h"
#include "base/single_thread_task_runner.h"
#include "base/synchronization/waitable_event.h"
#include "base/test/test_simple_task_runner.h"
#include "base/threading/platform_thread.h"
Expand Down Expand Up @@ -260,7 +259,7 @@ void RecursiveFunc(TaskList* order, int cookie, int depth,
if (depth > 0) {
if (is_reentrant)
MessageLoop::current()->SetNestableTasksAllowed(true);
MessageLoop::current()->PostTask(
ThreadTaskRunnerHandle::Get()->PostTask(
FROM_HERE,
Bind(&RecursiveFunc, order, cookie, depth - 1, is_reentrant));
}
Expand Down Expand Up @@ -861,8 +860,10 @@ TEST(MessageLoopTest, IsType) {
void EmptyFunction() {}

void PostMultipleTasks() {
MessageLoop::current()->PostTask(FROM_HERE, base::Bind(&EmptyFunction));
MessageLoop::current()->PostTask(FROM_HERE, base::Bind(&EmptyFunction));
ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE,
base::Bind(&EmptyFunction));
ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE,
base::Bind(&EmptyFunction));
}

static const int kSignalMsg = WM_USER + 2;
Expand Down Expand Up @@ -890,19 +891,20 @@ LRESULT CALLBACK TestWndProcThunk(HWND hwnd, UINT message,
// First, we post a task that will post multiple no-op tasks to make sure
// that the pump's incoming task queue does not become empty during the
// test.
MessageLoop::current()->PostTask(FROM_HERE, base::Bind(&PostMultipleTasks));
ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE,
base::Bind(&PostMultipleTasks));
// Next, we post a task that posts a windows message to trigger the second
// stage of the test.
MessageLoop::current()->PostTask(FROM_HERE,
base::Bind(&PostWindowsMessage, hwnd));
ThreadTaskRunnerHandle::Get()->PostTask(
FROM_HERE, base::Bind(&PostWindowsMessage, hwnd));
break;
case 2:
// Since we're about to enter a modal loop, tell the message loop that we
// intend to nest tasks.
MessageLoop::current()->SetNestableTasksAllowed(true);
bool did_run = false;
MessageLoop::current()->PostTask(FROM_HERE,
base::Bind(&EndTest, &did_run, hwnd));
ThreadTaskRunnerHandle::Get()->PostTask(
FROM_HERE, base::Bind(&EndTest, &did_run, hwnd));
// Run a nested windows-style message loop and verify that our task runs. If
// it doesn't, then we'll loop here until the test times out.
MSG msg;
Expand Down
45 changes: 21 additions & 24 deletions base/message_loop/message_pump_glib_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "base/message_loop/message_loop.h"
#include "base/run_loop.h"
#include "base/threading/thread.h"
#include "base/threading/thread_task_runner_handle.h"
#include "testing/gtest/include/gtest/gtest.h"

namespace base {
Expand Down Expand Up @@ -153,7 +154,7 @@ void ExpectProcessedEvents(EventInjector* injector, int count) {
// Posts a task on the current message loop.
void PostMessageLoopTask(const tracked_objects::Location& from_here,
const Closure& task) {
MessageLoop::current()->PostTask(from_here, task);
ThreadTaskRunnerHandle::Get()->PostTask(from_here, task);
}

// Test fixture.
Expand Down Expand Up @@ -311,7 +312,7 @@ class ConcurrentHelper : public RefCounted<ConcurrentHelper> {
if (task_count_ == 0 && event_count_ == 0) {
MessageLoop::current()->QuitWhenIdle();
} else {
MessageLoop::current()->PostTask(
ThreadTaskRunnerHandle::Get()->PostTask(
FROM_HERE, Bind(&ConcurrentHelper::FromTask, this));
}
}
Expand Down Expand Up @@ -382,8 +383,8 @@ void AddEventsAndDrainGLib(EventInjector* injector) {
injector->AddEvent(0, MessageLoop::QuitWhenIdleClosure());

// Post a couple of dummy tasks
MessageLoop::current()->PostTask(FROM_HERE, Bind(&DoNothing));
MessageLoop::current()->PostTask(FROM_HERE, Bind(&DoNothing));
ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, Bind(&DoNothing));
ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, Bind(&DoNothing));

// Drain the events
while (g_main_context_pending(NULL)) {
Expand Down Expand Up @@ -448,21 +449,19 @@ void TestGLibLoopInternal(EventInjector* injector) {
injector->AddDummyEvent(0);
injector->AddDummyEvent(0);
// Post a couple of dummy tasks
MessageLoop::current()->PostTask(
FROM_HERE, Bind(&IncrementInt, &task_count));
MessageLoop::current()->PostTask(
FROM_HERE, Bind(&IncrementInt, &task_count));
ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE,
Bind(&IncrementInt, &task_count));
ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE,
Bind(&IncrementInt, &task_count));
// Delayed events
injector->AddDummyEvent(10);
injector->AddDummyEvent(10);
// Delayed work
MessageLoop::current()->PostDelayedTask(
FROM_HERE,
Bind(&IncrementInt, &task_count),
ThreadTaskRunnerHandle::Get()->PostDelayedTask(
FROM_HERE, Bind(&IncrementInt, &task_count),
TimeDelta::FromMilliseconds(30));
MessageLoop::current()->PostDelayedTask(
FROM_HERE,
Bind(&GLibLoopRunner::Quit, runner.get()),
ThreadTaskRunnerHandle::Get()->PostDelayedTask(
FROM_HERE, Bind(&GLibLoopRunner::Quit, runner.get()),
TimeDelta::FromMilliseconds(40));

// Run a nested, straight GLib message loop.
Expand All @@ -483,21 +482,19 @@ void TestGtkLoopInternal(EventInjector* injector) {
injector->AddDummyEvent(0);
injector->AddDummyEvent(0);
// Post a couple of dummy tasks
MessageLoop::current()->PostTask(
FROM_HERE, Bind(&IncrementInt, &task_count));
MessageLoop::current()->PostTask(
FROM_HERE, Bind(&IncrementInt, &task_count));
ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE,
Bind(&IncrementInt, &task_count));
ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE,
Bind(&IncrementInt, &task_count));
// Delayed events
injector->AddDummyEvent(10);
injector->AddDummyEvent(10);
// Delayed work
MessageLoop::current()->PostDelayedTask(
FROM_HERE,
Bind(&IncrementInt, &task_count),
ThreadTaskRunnerHandle::Get()->PostDelayedTask(
FROM_HERE, Bind(&IncrementInt, &task_count),
TimeDelta::FromMilliseconds(30));
MessageLoop::current()->PostDelayedTask(
FROM_HERE,
Bind(&GLibLoopRunner::Quit, runner.get()),
ThreadTaskRunnerHandle::Get()->PostDelayedTask(
FROM_HERE, Bind(&GLibLoopRunner::Quit, runner.get()),
TimeDelta::FromMilliseconds(40));

// Run a nested, straight Gtk message loop.
Expand Down
12 changes: 5 additions & 7 deletions chrome/app_shim/chrome_main_app_mode_mac.mm
Original file line number Diff line number Diff line change
Expand Up @@ -686,20 +686,18 @@ int ChromeAppModeStart_v4(const app_mode::ChromeAppModeInfo* info) {
[ReplyEventHandler pingProcess:psn
andCall:on_ping_chrome_reply];

main_message_loop.PostDelayedTask(
FROM_HERE,
base::Bind(&AppShimController::OnPingChromeTimeout,
base::Unretained(&controller)),
main_message_loop.task_runner()->PostDelayedTask(
FROM_HERE, base::Bind(&AppShimController::OnPingChromeTimeout,
base::Unretained(&controller)),
base::TimeDelta::FromSeconds(kPingChromeTimeoutSeconds));
} else {
// Chrome already running. Proceed to init. This could still fail if Chrome
// is still starting up or shutting down, but the process will exit quickly,
// which is preferable to waiting for the Apple Event to timeout after one
// minute.
main_message_loop.PostTask(
main_message_loop.task_runner()->PostTask(
FROM_HERE,
base::Bind(&AppShimController::Init,
base::Unretained(&controller)));
base::Bind(&AppShimController::Init, base::Unretained(&controller)));
}

main_message_loop.Run();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

#include "base/logging.h"
#include "base/macros.h"
#include "base/message_loop/message_loop.h"
#include "base/run_loop.h"

// This template can be used for the StartFetching methods of the browsing data
// helper classes. It is supposed to be instantiated with the respective
Expand All @@ -22,18 +22,19 @@ class BrowsingDataHelperCallback {
BrowsingDataHelperCallback() {}

const std::list<T>& result() {
base::MessageLoop::current()->Run();
run_loop_.Run();
DCHECK(has_result_);
return result_;
}

void callback(const std::list<T>& info) {
result_ = info;
has_result_ = true;
base::MessageLoop::current()->QuitWhenIdle();
run_loop_.QuitWhenIdle();
}

private:
base::RunLoop run_loop_;
bool has_result_ = false;
std::list<T> result_;

Expand Down
15 changes: 9 additions & 6 deletions chrome/browser/devtools/device/port_forwarding_browsertest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "base/bind.h"
#include "base/bind_helpers.h"
#include "base/command_line.h"
#include "base/compiler_specific.h"
#include "base/location.h"
#include "base/single_thread_task_runner.h"
#include "base/strings/string_number_conversions.h"
#include "base/threading/thread_task_runner_handle.h"
#include "chrome/browser/devtools/device/devtools_android_bridge.h"
Expand Down Expand Up @@ -177,10 +177,13 @@ IN_PROC_BROWSER_TEST_F(PortForwardingDisconnectTest, DisconnectOnRelease) {
std::unique_ptr<Listener> wait_for_port_forwarding(new Listener(profile));
content::RunMessageLoop();

base::RunLoop run_loop;

self_provider->set_release_callback_for_test(
base::Bind(&base::MessageLoop::PostTask,
base::Unretained(base::MessageLoop::current()), FROM_HERE,
base::MessageLoop::QuitWhenIdleClosure()));
base::Bind(base::IgnoreResult(&base::SingleThreadTaskRunner::PostTask),
base::ThreadTaskRunnerHandle::Get(), FROM_HERE,
run_loop.QuitWhenIdleClosure()));
wait_for_port_forwarding.reset();
content::RunMessageLoop();

content::RunThisRunLoop(&run_loop);
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,15 @@
#include <tuple>

#include "base/bind.h"
#include "base/bind_helpers.h"
#include "base/callback.h"
#include "base/files/file_path.h"
#include "base/json/json_reader.h"
#include "base/json/json_string_value_serializer.h"
#include "base/location.h"
#include "base/macros.h"
#include "base/memory/ptr_util.h"
#include "base/memory/weak_ptr.h"
#include "base/run_loop.h"
#include "base/single_thread_task_runner.h"
#include "base/stl_util.h"
#include "base/strings/string_piece.h"
#include "base/strings/string_split.h"
Expand Down Expand Up @@ -464,16 +463,18 @@ TEST_F(ExtensionWebRequestTest, SimulateChancelWhileBlocked) {
&profile_, extension_id, kEventName, kEventName + "/1",
request->identifier(), response));

base::RunLoop run_loop;

// Extension response for OnErrorOccurred: Terminate the message loop.
ipc_sender_.PushTask(
base::Bind(&base::MessageLoop::PostTask,
base::Unretained(base::MessageLoop::current()), FROM_HERE,
base::MessageLoop::QuitWhenIdleClosure()));
base::Bind(base::IgnoreResult(&base::SingleThreadTaskRunner::PostTask),
base::ThreadTaskRunnerHandle::Get(), FROM_HERE,
run_loop.QuitWhenIdleClosure()));

request->Start();
// request->Start() will have submitted OnBeforeRequest by the time we cancel.
request->Cancel();
base::RunLoop().Run();
run_loop.Run();

EXPECT_TRUE(!request->is_pending());
EXPECT_EQ(net::URLRequestStatus::CANCELED, request->status().status());
Expand Down
9 changes: 4 additions & 5 deletions chrome/browser/ui/cocoa/app_menu/app_menu_controller.mm
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
#include "base/mac/bundle_locations.h"
#include "base/macros.h"
#include "base/memory/weak_ptr.h"
#include "base/message_loop/message_loop.h"
#include "base/metrics/histogram_macros.h"
#include "base/scoped_observer.h"
#include "base/strings/string16.h"
#include "base/strings/sys_string_conversions.h"
#include "base/threading/thread_task_runner_handle.h"
#include "chrome/app/chrome_command_ids.h"
#import "chrome/browser/app_controller_mac.h"
#include "chrome/browser/profiles/profile.h"
Expand Down Expand Up @@ -142,10 +142,9 @@ void OnToolbarActionsBarDidStartResize() override {
// Edge case: If the resize is caused by an action being added while the
// menu is open, we need to wait for both toolbars to be updated. This can
// happen if a user's data is synced with the menu open.
base::MessageLoop::current()->PostTask(
FROM_HERE,
base::Bind(&ToolbarActionsBarObserverHelper::UpdateSubmenu,
weak_ptr_factory_.GetWeakPtr()));
base::ThreadTaskRunnerHandle::Get()->PostTask(
FROM_HERE, base::Bind(&ToolbarActionsBarObserverHelper::UpdateSubmenu,
weak_ptr_factory_.GetWeakPtr()));
}

void UpdateSubmenu() {
Expand Down
Loading

0 comments on commit 2df4a9e

Please sign in to comment.