Skip to content

Commit

Permalink
Revert of base: Remove use of MessageLoopProxy (patchset chromium#6 i…
Browse files Browse the repository at this point in the history
…d:100001 of https://codereview.chromium.org/1100773004/)

Reason for revert:
This CL caused this failure:
http://build.chromium.org/p/chromium.chromiumos/builders/Linux%20ChromiumOS%20Tests%20%281%29/builds/2126

I would strongly recommend doing this in smaller pieces since it combines mechanical changes with more subtle ones (base/prefs, base/task).

Original issue's description:
> base: Remove use of MessageLoopProxy
>
> Replace usage of MessageLoopProxy under base/ with SingleThreadTaskRunner
> and ThreadTaskRunnerHandle (excluding the implementation of MessageLoopProxy
> itself which will removed later).
>
> This patch was mostly autogenerated with
> https://codereview.chromium.org/1010073002.
>
> Depends on https://codereview.chromium.org/1086733002/.
>
> BUG=465354
> TBR=nkostylev@chromium.org,pkasting@chromium.org,pauljensen@chromium.org
>
> Committed: https://crrev.com/62aa5ca413e15738ebebbb9acd271138ec808739
> Cr-Commit-Position: refs/heads/master@{#327512}

TBR=danakj@chromium.org,skyostil@chromium.org
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true
BUG=465354

Review URL: https://codereview.chromium.org/1113953002

Cr-Commit-Position: refs/heads/master@{#327573}
  • Loading branch information
stevenjb authored and Commit bot committed Apr 29, 2015
1 parent fd2d6d7 commit 7669182
Show file tree
Hide file tree
Showing 67 changed files with 504 additions and 444 deletions.
7 changes: 4 additions & 3 deletions base/android/application_status_listener_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include "base/callback_forward.h"
#include "base/logging.h"
#include "base/memory/scoped_ptr.h"
#include "base/message_loop/message_loop.h"
#include "base/message_loop/message_loop_proxy.h"
#include "base/run_loop.h"
#include "base/synchronization/waitable_event.h"
#include "base/threading/thread.h"
Expand Down Expand Up @@ -49,8 +49,9 @@ class MultiThreadedTest {
void Run() {
// Start the thread and tell it to register for events.
thread_.Start();
thread_.task_runner()->PostTask(
FROM_HERE, base::Bind(&MultiThreadedTest::RegisterThreadForEvents,
thread_.message_loop()
->PostTask(FROM_HERE,
base::Bind(&MultiThreadedTest::RegisterThreadForEvents,
base::Unretained(this)));

// Wait for its completion.
Expand Down
17 changes: 7 additions & 10 deletions base/async_socket_io_handler_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@
#include "base/async_socket_io_handler.h"

#include "base/bind.h"
#include "base/location.h"
#include "base/single_thread_task_runner.h"
#include "base/thread_task_runner_handle.h"
#include "testing/gtest/include/gtest/gtest.h"

namespace {
Expand Down Expand Up @@ -107,8 +104,8 @@ TEST(AsyncSocketIoHandlerTest, SynchronousReadWithMessageLoop) {
TestSocketReader reader(&pair[0], -1, false, false);

pair[1].Send(kAsyncSocketIoTestString, kAsyncSocketIoTestStringLength);
base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
FROM_HERE, base::MessageLoop::QuitClosure(),
base::MessageLoop::current()->PostDelayedTask(FROM_HERE,
base::MessageLoop::QuitClosure(),
base::TimeDelta::FromMilliseconds(100));
base::MessageLoop::current()->Run();

Expand Down Expand Up @@ -138,15 +135,15 @@ TEST(AsyncSocketIoHandlerTest, ReadFromCallback) {
// Issue sends on an interval to satisfy the Read() requirements.
int64 milliseconds = 0;
for (int i = 0; i < kReadOperationCount; ++i) {
base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
FROM_HERE, base::Bind(&SendData, &pair[1], kAsyncSocketIoTestString,
kAsyncSocketIoTestStringLength),
base::MessageLoop::current()->PostDelayedTask(FROM_HERE,
base::Bind(&SendData, &pair[1], kAsyncSocketIoTestString,
kAsyncSocketIoTestStringLength),
base::TimeDelta::FromMilliseconds(milliseconds));
milliseconds += 10;
}

base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
FROM_HERE, base::MessageLoop::QuitClosure(),
base::MessageLoop::current()->PostDelayedTask(FROM_HERE,
base::MessageLoop::QuitClosure(),
base::TimeDelta::FromMilliseconds(100 + milliseconds));

base::MessageLoop::current()->Run();
Expand Down
2 changes: 1 addition & 1 deletion base/bind_helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@
// Passed() is particularly useful with PostTask() when you are transferring
// ownership of an argument into a task, but don't necessarily know if the
// task will always be executed. This can happen if the task is cancellable
// or if it is posted to a TaskRunner.
// or if it is posted to a MessageLoopProxy.
//
//
// SIMPLE FUNCTIONS AND UTILITIES.
Expand Down
8 changes: 3 additions & 5 deletions base/cancelable_callback_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,9 @@

#include "base/bind.h"
#include "base/bind_helpers.h"
#include "base/location.h"
#include "base/memory/ref_counted.h"
#include "base/message_loop/message_loop.h"
#include "base/run_loop.h"
#include "base/single_thread_task_runner.h"
#include "base/thread_task_runner_handle.h"
#include "testing/gtest/include/gtest/gtest.h"

namespace base {
Expand Down Expand Up @@ -167,12 +165,12 @@ TEST(CancelableCallbackTest, PostTask) {
CancelableClosure cancelable(base::Bind(&Increment,
base::Unretained(&count)));

ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, cancelable.callback());
MessageLoop::current()->PostTask(FROM_HERE, cancelable.callback());
RunLoop().RunUntilIdle();

EXPECT_EQ(1, count);

ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, cancelable.callback());
MessageLoop::current()->PostTask(FROM_HERE, cancelable.callback());

// Cancel before running the message loop.
cancelable.Cancel();
Expand Down
9 changes: 5 additions & 4 deletions base/chromeos/memory_pressure_monitor_chromeos.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
#include <fcntl.h>
#include <sys/select.h>

#include "base/message_loop/message_loop.h"
#include "base/metrics/histogram_macros.h"
#include "base/posix/eintr_wrapper.h"
#include "base/process/process_metrics.h"
#include "base/thread_task_runner_handle.h"
#include "base/time/time.h"

namespace base {
Expand Down Expand Up @@ -120,9 +120,10 @@ MemoryPressureMonitorChromeOS::~MemoryPressureMonitorChromeOS() {
}

void MemoryPressureMonitorChromeOS::ScheduleEarlyCheck() {
ThreadTaskRunnerHandle::Get()->PostTask(
FROM_HERE, Bind(&MemoryPressureMonitorChromeOS::CheckMemoryPressure,
weak_ptr_factory_.GetWeakPtr()));
MessageLoop::current()->PostTask(
FROM_HERE,
Bind(&MemoryPressureMonitorChromeOS::CheckMemoryPressure,
weak_ptr_factory_.GetWeakPtr()));
}

MemoryPressureListener::MemoryPressureLevel
Expand Down
2 changes: 1 addition & 1 deletion base/critical_closure.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class CriticalClosure {
// returned.
//
// Example:
// file_task_runner_->PostTask(
// file_message_loop_proxy_->PostTask(
// FROM_HERE,
// MakeCriticalClosure(base::Bind(&WriteToDiskTask, path_, data)));
//
Expand Down
32 changes: 19 additions & 13 deletions base/deferred_sequenced_task_runner_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
#include "base/basictypes.h"
#include "base/bind.h"
#include "base/bind_helpers.h"
#include "base/location.h"
#include "base/memory/ref_counted.h"
#include "base/single_thread_task_runner.h"
#include "base/message_loop/message_loop.h"
#include "base/message_loop/message_loop_proxy.h"
#include "base/threading/non_thread_safe.h"
#include "base/threading/thread.h"
#include "testing/gmock/include/gmock/gmock.h"
Expand Down Expand Up @@ -58,9 +58,11 @@ class DeferredSequencedTaskRunnerTest : public testing::Test,
}

protected:
DeferredSequencedTaskRunnerTest()
: loop_(),
runner_(new base::DeferredSequencedTaskRunner(loop_.task_runner())) {}
DeferredSequencedTaskRunnerTest() :
loop_(),
runner_(
new base::DeferredSequencedTaskRunner(loop_.message_loop_proxy())) {
}

base::MessageLoop loop_;
scoped_refptr<base::DeferredSequencedTaskRunner> runner_;
Expand Down Expand Up @@ -124,18 +126,21 @@ TEST_F(DeferredSequencedTaskRunnerTest, DeferredStartWithMultipleThreads) {
thread1.Start();
thread2.Start();
for (int i = 0; i < 5; ++i) {
thread1.task_runner()->PostTask(
thread1.message_loop()->PostTask(
FROM_HERE,
base::Bind(&DeferredSequencedTaskRunnerTest::PostExecuteTask,
base::Unretained(this), 2 * i));
thread2.task_runner()->PostTask(
base::Unretained(this),
2 * i));
thread2.message_loop()->PostTask(
FROM_HERE,
base::Bind(&DeferredSequencedTaskRunnerTest::PostExecuteTask,
base::Unretained(this), 2 * i + 1));
base::Unretained(this),
2 * i + 1));
if (i == 2) {
thread1.task_runner()->PostTask(
FROM_HERE, base::Bind(&DeferredSequencedTaskRunnerTest::StartRunner,
base::Unretained(this)));
thread1.message_loop()->PostTask(
FROM_HERE,
base::Bind(&DeferredSequencedTaskRunnerTest::StartRunner,
base::Unretained(this)));
}
}
}
Expand All @@ -149,7 +154,8 @@ TEST_F(DeferredSequencedTaskRunnerTest, ObjectDestructionOrder) {
{
base::Thread thread("DeferredSequencedTaskRunnerTestThread");
thread.Start();
runner_ = new base::DeferredSequencedTaskRunner(thread.task_runner());
runner_ =
new base::DeferredSequencedTaskRunner(thread.message_loop_proxy());
for (int i = 0; i < 5; ++i) {
{
// Use a block to ensure that no reference to |short_lived_object|
Expand Down
13 changes: 6 additions & 7 deletions base/files/file_path_watcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#include "base/callback.h"
#include "base/files/file_path.h"
#include "base/memory/ref_counted.h"
#include "base/single_thread_task_runner.h"
#include "base/message_loop/message_loop_proxy.h"

namespace base {

Expand Down Expand Up @@ -58,13 +58,12 @@ class BASE_EXPORT FilePathWatcher {
// check |is_cancelled()| to avoid duplicate work.
virtual void CancelOnMessageLoopThread() = 0;

scoped_refptr<base::SingleThreadTaskRunner> task_runner() const {
return task_runner_;
scoped_refptr<base::MessageLoopProxy> message_loop() const {
return message_loop_;
}

void set_task_runner(
scoped_refptr<base::SingleThreadTaskRunner> task_runner) {
task_runner_ = task_runner.Pass();
void set_message_loop(const scoped_refptr<base::MessageLoopProxy>& loop) {
message_loop_ = loop;
}

// Must be called before the PlatformDelegate is deleted.
Expand All @@ -77,7 +76,7 @@ class BASE_EXPORT FilePathWatcher {
}

private:
scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
scoped_refptr<base::MessageLoopProxy> message_loop_;
bool cancelled_;
};

Expand Down
17 changes: 8 additions & 9 deletions base/files/file_path_watcher_fsevents.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
#include "base/mac/libdispatch_task_runner.h"
#include "base/mac/scoped_cftyperef.h"
#include "base/message_loop/message_loop.h"
#include "base/thread_task_runner_handle.h"

namespace base {

Expand Down Expand Up @@ -93,7 +92,7 @@ bool FilePathWatcherFSEvents::Watch(const FilePath& path,
if (!recursive)
return false;

set_task_runner(ThreadTaskRunnerHandle::Get());
set_message_loop(MessageLoopProxy::current());
callback_ = callback;

FSEventStreamEventId start_event = FSEventsGetCurrentEventId();
Expand Down Expand Up @@ -153,7 +152,7 @@ void FilePathWatcherFSEvents::FSEventsCallback(
}

FilePathWatcherFSEvents::~FilePathWatcherFSEvents() {
// This method may be called on either the libdispatch or task_runner()
// This method may be called on either the libdispatch or message_loop()
// thread. Checking callback_ on the libdispatch thread here is safe because
// it is executing in a task posted by Cancel() which first reset callback_.
// PostTask forms a sufficient memory barrier to ensure that the value is
Expand All @@ -166,15 +165,15 @@ void FilePathWatcherFSEvents::OnFilePathsChanged(
const std::vector<FilePath>& paths) {
DCHECK(g_task_runner.Get().RunsTasksOnCurrentThread());
DCHECK(!resolved_target_.empty());
task_runner()->PostTask(
message_loop()->PostTask(
FROM_HERE, Bind(&FilePathWatcherFSEvents::DispatchEvents, this, paths,
target_, resolved_target_));
}

void FilePathWatcherFSEvents::DispatchEvents(const std::vector<FilePath>& paths,
const FilePath& target,
const FilePath& resolved_target) {
DCHECK(task_runner()->RunsTasksOnCurrentThread());
DCHECK(message_loop()->RunsTasksOnCurrentThread());

// Don't issue callbacks after Cancel() has been called.
if (is_cancelled() || callback_.is_null()) {
Expand All @@ -191,7 +190,7 @@ void FilePathWatcherFSEvents::DispatchEvents(const std::vector<FilePath>& paths,

void FilePathWatcherFSEvents::CancelOnMessageLoopThread() {
// For all other implementations, the "message loop thread" is the IO thread,
// as returned by task_runner(). This implementation, however, needs to
// as returned by message_loop(). This implementation, however, needs to
// cancel pending work on the Dispatch Queue thread.
DCHECK(g_task_runner.Get().RunsTasksOnCurrentThread());

Expand Down Expand Up @@ -240,7 +239,7 @@ void FilePathWatcherFSEvents::UpdateEventStream(
g_task_runner.Get().GetDispatchQueue());

if (!FSEventStreamStart(fsevent_stream_)) {
task_runner()->PostTask(
message_loop()->PostTask(
FROM_HERE, Bind(&FilePathWatcherFSEvents::ReportError, this, target_));
}
}
Expand All @@ -251,14 +250,14 @@ bool FilePathWatcherFSEvents::ResolveTargetPath() {
bool changed = resolved != resolved_target_;
resolved_target_ = resolved;
if (resolved_target_.empty()) {
task_runner()->PostTask(
message_loop()->PostTask(
FROM_HERE, Bind(&FilePathWatcherFSEvents::ReportError, this, target_));
}
return changed;
}

void FilePathWatcherFSEvents::ReportError(const FilePath& target) {
DCHECK(task_runner()->RunsTasksOnCurrentThread());
DCHECK(message_loop()->RunsTasksOnCurrentThread());
if (!callback_.is_null()) {
callback_.Run(target, true);
}
Expand Down
15 changes: 7 additions & 8 deletions base/files/file_path_watcher_kqueue.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
#include "base/files/file_util.h"
#include "base/logging.h"
#include "base/strings/stringprintf.h"
#include "base/thread_task_runner_handle.h"

// On some platforms these are not defined.
#if !defined(EV_RECEIPT)
Expand Down Expand Up @@ -328,7 +327,7 @@ bool FilePathWatcherKQueue::Watch(const FilePath& path,
target_ = path;

MessageLoop::current()->AddDestructionObserver(this);
io_task_runner_ = ThreadTaskRunnerHandle::Get();
io_message_loop_ = base::MessageLoopProxy::current();

kqueue_ = kqueue();
if (kqueue_ == -1) {
Expand Down Expand Up @@ -357,14 +356,14 @@ bool FilePathWatcherKQueue::Watch(const FilePath& path,
}

void FilePathWatcherKQueue::Cancel() {
SingleThreadTaskRunner* task_runner = io_task_runner_.get();
if (!task_runner) {
base::MessageLoopProxy* proxy = io_message_loop_.get();
if (!proxy) {
set_cancelled();
return;
}
if (!task_runner->BelongsToCurrentThread()) {
task_runner->PostTask(FROM_HERE,
base::Bind(&FilePathWatcherKQueue::Cancel, this));
if (!proxy->BelongsToCurrentThread()) {
proxy->PostTask(FROM_HERE,
base::Bind(&FilePathWatcherKQueue::Cancel, this));
return;
}
CancelOnMessageLoopThread();
Expand All @@ -381,7 +380,7 @@ void FilePathWatcherKQueue::CancelOnMessageLoopThread() {
kqueue_ = -1;
std::for_each(events_.begin(), events_.end(), ReleaseEvent);
events_.clear();
io_task_runner_ = NULL;
io_message_loop_ = NULL;
MessageLoop::current()->RemoveDestructionObserver(this);
callback_.Reset();
}
Expand Down
6 changes: 3 additions & 3 deletions base/files/file_path_watcher_kqueue.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#include "base/files/file_path.h"
#include "base/files/file_path_watcher.h"
#include "base/message_loop/message_loop.h"
#include "base/single_thread_task_runner.h"
#include "base/message_loop/message_loop_proxy.h"

namespace base {

Expand Down Expand Up @@ -59,7 +59,7 @@ class FilePathWatcherKQueue : public FilePathWatcher::PlatformDelegate,

typedef std::vector<struct kevent> EventVector;

// Can only be called on |io_task_runner_|'s thread.
// Can only be called on |io_message_loop_|'s thread.
void CancelOnMessageLoopThread() override;

// Returns true if the kevent values are error free.
Expand Down Expand Up @@ -118,7 +118,7 @@ class FilePathWatcherKQueue : public FilePathWatcher::PlatformDelegate,
}

EventVector events_;
scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_;
scoped_refptr<base::MessageLoopProxy> io_message_loop_;
MessageLoopForIO::FileDescriptorWatcher kqueue_watcher_;
FilePathWatcher::Callback callback_;
FilePath target_;
Expand Down
Loading

0 comments on commit 7669182

Please sign in to comment.