Skip to content

Commit

Permalink
net: Use base::MessageLoop.
Browse files Browse the repository at this point in the history
BUG=236029
R=agl@chromium.org

Review URL: https://chromiumcodereview.appspot.com/14021017

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@201882 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
xhwang@chromium.org committed May 23, 2013
1 parent 954f56f commit 2da659e
Show file tree
Hide file tree
Showing 158 changed files with 1,123 additions and 1,088 deletions.
4 changes: 2 additions & 2 deletions net/android/network_change_notifier_android_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,13 @@ class BaseNetworkChangeNotifierAndroidTest : public testing::Test {
void SetOnline() {
delegate_.SetOnline();
// Note that this is needed because ObserverListThreadSafe uses PostTask().
MessageLoop::current()->RunUntilIdle();
base::MessageLoop::current()->RunUntilIdle();
}

void SetOffline() {
delegate_.SetOffline();
// See comment above.
MessageLoop::current()->RunUntilIdle();
base::MessageLoop::current()->RunUntilIdle();
}

NetworkChangeNotifierDelegateAndroid delegate_;
Expand Down
4 changes: 2 additions & 2 deletions net/base/address_tracker_linux.cc
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,8 @@ void AddressTrackerLinux::Init() {
is_offline_initialized_cv_.Signal();
}

rv = MessageLoopForIO::current()->WatchFileDescriptor(
netlink_fd_, true, MessageLoopForIO::WATCH_READ, &watcher_, this);
rv = base::MessageLoopForIO::current()->WatchFileDescriptor(
netlink_fd_, true, base::MessageLoopForIO::WATCH_READ, &watcher_, this);
if (rv < 0) {
PLOG(ERROR) << "Could not watch NETLINK socket";
AbortAndForceOnline();
Expand Down
6 changes: 3 additions & 3 deletions net/base/address_tracker_linux.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ namespace internal {

// Keeps track of network interface addresses using rtnetlink. Used by
// NetworkChangeNotifier to provide signals to registered IPAddressObservers.
class NET_EXPORT_PRIVATE AddressTrackerLinux
: public MessageLoopForIO::Watcher {
class NET_EXPORT_PRIVATE AddressTrackerLinux :
public base::MessageLoopForIO::Watcher {
public:
typedef std::map<IPAddressNumber, struct ifaddrmsg> AddressMap;

Expand Down Expand Up @@ -79,7 +79,7 @@ class NET_EXPORT_PRIVATE AddressTrackerLinux
base::Closure link_callback_;

int netlink_fd_;
MessageLoopForIO::FileDescriptorWatcher watcher_;
base::MessageLoopForIO::FileDescriptorWatcher watcher_;

mutable base::Lock address_map_lock_;
AddressMap address_map_;
Expand Down
14 changes: 7 additions & 7 deletions net/base/directory_lister_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ class ListerDelegate : public DirectoryLister::DirectoryListerDelegate {
file_list_.push_back(data.info);
paths_.push_back(data.path);
if (quit_loop_after_each_file_)
MessageLoop::current()->Quit();
base::MessageLoop::current()->Quit();
}

virtual void OnListDone(int error) OVERRIDE {
error_ = error;
MessageLoop::current()->Quit();
base::MessageLoop::current()->Quit();
if (recursive_)
CheckRecursiveSort();
else
Expand Down Expand Up @@ -143,7 +143,7 @@ TEST_F(DirectoryListerTest, BigDirTest) {
DirectoryLister lister(root_path(), &delegate);
lister.Start();

MessageLoop::current()->Run();
base::MessageLoop::current()->Run();

EXPECT_EQ(OK, delegate.error());
}
Expand All @@ -154,7 +154,7 @@ TEST_F(DirectoryListerTest, BigDirRecursiveTest) {
&delegate);
lister.Start();

MessageLoop::current()->Run();
base::MessageLoop::current()->Run();

EXPECT_EQ(OK, delegate.error());
}
Expand All @@ -164,13 +164,13 @@ TEST_F(DirectoryListerTest, CancelTest) {
DirectoryLister lister(root_path(), &delegate);
lister.Start();

MessageLoop::current()->Run();
base::MessageLoop::current()->Run();

int num_files = delegate.num_files();

lister.Cancel();

MessageLoop::current()->RunUntilIdle();
base::MessageLoop::current()->RunUntilIdle();

EXPECT_EQ(num_files, delegate.num_files());
}
Expand All @@ -185,7 +185,7 @@ TEST_F(DirectoryListerTest, EmptyDirTest) {
DirectoryLister lister(tempDir.path(), &delegate);
lister.Start();

MessageLoop::current()->Run();
base::MessageLoop::current()->Run();

// Contains only the parent directory ("..")
EXPECT_EQ(1, delegate.num_files());
Expand Down
2 changes: 1 addition & 1 deletion net/base/dns_reloader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class DnsReloader : public net::NetworkChangeNotifier::DNSObserver {

// NetworkChangeNotifier::DNSObserver:
virtual void OnDNSChanged() OVERRIDE {
DCHECK_EQ(MessageLoop::current()->type(), MessageLoop::TYPE_IO);
DCHECK_EQ(base::MessageLoop::current()->type(), base::MessageLoop::TYPE_IO);
base::AutoLock l(lock_);
resolver_generation_++;
}
Expand Down
6 changes: 3 additions & 3 deletions net/base/file_stream_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ namespace net {
class IOBuffer;

#if defined(OS_WIN)
class FileStream::Context : public MessageLoopForIO::IOHandler {
class FileStream::Context : public base::MessageLoopForIO::IOHandler {
#elif defined(OS_POSIX)
class FileStream::Context {
#endif
Expand Down Expand Up @@ -192,7 +192,7 @@ class FileStream::Context {
void IOCompletionIsPending(const CompletionCallback& callback, IOBuffer* buf);

// Implementation of MessageLoopForIO::IOHandler.
virtual void OnIOCompleted(MessageLoopForIO::IOContext* context,
virtual void OnIOCompleted(base::MessageLoopForIO::IOContext* context,
DWORD bytes_read,
DWORD error) OVERRIDE;
#elif defined(OS_POSIX)
Expand All @@ -213,7 +213,7 @@ class FileStream::Context {
BoundNetLog bound_net_log_;

#if defined(OS_WIN)
MessageLoopForIO::IOContext io_context_;
base::MessageLoopForIO::IOContext io_context_;
CompletionCallback callback_;
scoped_refptr<IOBuffer> in_flight_buf_;
FileErrorSource error_source_;
Expand Down
9 changes: 5 additions & 4 deletions net/base/file_stream_context_win.cc
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ int FileStream::Context::Truncate(int64 bytes) {
}

void FileStream::Context::OnAsyncFileOpened() {
MessageLoopForIO::current()->RegisterIOHandler(file_, this);
base::MessageLoopForIO::current()->RegisterIOHandler(file_, this);
}

FileStream::Context::IOResult FileStream::Context::SeekFileImpl(Whence whence,
Expand Down Expand Up @@ -202,9 +202,10 @@ void FileStream::Context::IOCompletionIsPending(
async_in_progress_ = true;
}

void FileStream::Context::OnIOCompleted(MessageLoopForIO::IOContext* context,
DWORD bytes_read,
DWORD error) {
void FileStream::Context::OnIOCompleted(
base::MessageLoopForIO::IOContext* context,
DWORD bytes_read,
DWORD error) {
DCHECK_EQ(&io_context_, context);
DCHECK(!callback_.is_null());
DCHECK(async_in_progress_);
Expand Down
17 changes: 9 additions & 8 deletions net/base/file_stream_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ TEST_F(FileStreamTest, AsyncRead_EarlyDelete) {
if (rv < 0) {
EXPECT_EQ(ERR_IO_PENDING, rv);
// The callback should not be called if the request is cancelled.
MessageLoop::current()->RunUntilIdle();
base::MessageLoop::current()->RunUntilIdle();
EXPECT_FALSE(callback.have_result());
} else {
EXPECT_EQ(std::string(kTestData, rv), std::string(buf->data(), rv));
Expand Down Expand Up @@ -460,7 +460,7 @@ TEST_F(FileStreamTest, AsyncWrite_EarlyDelete) {
if (rv < 0) {
EXPECT_EQ(ERR_IO_PENDING, rv);
// The callback should not be called if the request is cancelled.
MessageLoop::current()->RunUntilIdle();
base::MessageLoop::current()->RunUntilIdle();
EXPECT_FALSE(callback.have_result());
} else {
ok = file_util::GetFileSize(temp_file_path(), &file_size);
Expand Down Expand Up @@ -780,7 +780,7 @@ class TestWriteReadCompletionCallback {
DCHECK(!waiting_for_result_);
while (!have_result_) {
waiting_for_result_ = true;
MessageLoop::current()->Run();
base::MessageLoop::current()->Run();
waiting_for_result_ = false;
}
have_result_ = false; // auto-reset for next callback
Expand Down Expand Up @@ -818,7 +818,8 @@ class TestWriteReadCompletionCallback {
scoped_refptr<IOBufferWithSize> buf = new IOBufferWithSize(4);
rv = stream_->Read(buf, buf->size(), callback.callback());
if (rv == ERR_IO_PENDING) {
MessageLoop::ScopedNestableTaskAllower allow(MessageLoop::current());
base::MessageLoop::ScopedNestableTaskAllower allow(
base::MessageLoop::current());
rv = callback.WaitForResult();
}
EXPECT_LE(0, rv);
Expand All @@ -832,7 +833,7 @@ class TestWriteReadCompletionCallback {
result_ = *total_bytes_written_;
have_result_ = true;
if (waiting_for_result_)
MessageLoop::current()->Quit();
base::MessageLoop::current()->Quit();
}

int result_;
Expand Down Expand Up @@ -913,7 +914,7 @@ class TestWriteCloseCompletionCallback {
DCHECK(!waiting_for_result_);
while (!have_result_) {
waiting_for_result_ = true;
MessageLoop::current()->Run();
base::MessageLoop::current()->Run();
waiting_for_result_ = false;
}
have_result_ = false; // auto-reset for next callback
Expand Down Expand Up @@ -944,7 +945,7 @@ class TestWriteCloseCompletionCallback {
result_ = *total_bytes_written_;
have_result_ = true;
if (waiting_for_result_)
MessageLoop::current()->Quit();
base::MessageLoop::current()->Quit();
}

int result_;
Expand Down Expand Up @@ -1037,7 +1038,7 @@ TEST_F(FileStreamTest, AsyncOpenAndDelete) {
// complete. Should be safe.
stream.reset();
// open_callback won't be called.
MessageLoop::current()->RunUntilIdle();
base::MessageLoop::current()->RunUntilIdle();
EXPECT_FALSE(open_callback.have_result());
}

Expand Down
2 changes: 1 addition & 1 deletion net/base/network_change_notifier_linux.cc
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ NetworkChangeNotifierLinux::NetworkChangeNotifierLinux()
// We create this notifier thread because the notification implementation
// needs a MessageLoopForIO, and there's no guarantee that
// MessageLoop::current() meets that criterion.
base::Thread::Options thread_options(MessageLoop::TYPE_IO, 0);
base::Thread::Options thread_options(base::MessageLoop::TYPE_IO, 0);
notifier_thread_->StartWithOptions(thread_options);
}

Expand Down
2 changes: 1 addition & 1 deletion net/base/network_change_notifier_mac.cc
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ NetworkChangeNotifierMac::NetworkChangeNotifierMac()
// SetInitialConnectionType().
config_watcher_.reset(new NetworkConfigWatcherMac(&forwarder_));
dns_config_service_thread_->StartWithOptions(
base::Thread::Options(MessageLoop::TYPE_IO, 0));
base::Thread::Options(base::MessageLoop::TYPE_IO, 0));
}

NetworkChangeNotifierMac::~NetworkChangeNotifierMac() {
Expand Down
4 changes: 2 additions & 2 deletions net/base/network_change_notifier_win.cc
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ NetworkChangeNotifierWin::NetworkChangeNotifierWin()
memset(&addr_overlapped_, 0, sizeof addr_overlapped_);
addr_overlapped_.hEvent = WSACreateEvent();
dns_config_service_thread_->StartWithOptions(
base::Thread::Options(MessageLoop::TYPE_IO, 0));
base::Thread::Options(base::MessageLoop::TYPE_IO, 0));
}

NetworkChangeNotifierWin::~NetworkChangeNotifierWin() {
Expand Down Expand Up @@ -253,7 +253,7 @@ void NetworkChangeNotifierWin::WatchForAddressChange() {
sequential_failures_);
}

MessageLoop::current()->PostDelayedTask(
base::MessageLoop::current()->PostDelayedTask(
FROM_HERE,
base::Bind(&NetworkChangeNotifierWin::WatchForAddressChange,
weak_factory_.GetWeakPtr()),
Expand Down
25 changes: 12 additions & 13 deletions net/base/network_change_notifier_win_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class TestIPAddressObserver
};

bool ExitMessageLoopAndReturnFalse() {
MessageLoop::current()->Quit();
base::MessageLoop::current()->Quit();
return false;
}

Expand Down Expand Up @@ -89,7 +89,7 @@ class NetworkChangeNotifierWinTest : public testing::Test {

// If a task to notify observers of the IP address change event was
// incorrectly posted, make sure it gets run to trigger a failure.
MessageLoop::current()->RunUntilIdle();
base::MessageLoop::current()->RunUntilIdle();
}

// Calls WatchForAddressChange, and simulates a WatchForAddressChangeInternal
Expand All @@ -112,7 +112,7 @@ class NetworkChangeNotifierWinTest : public testing::Test {

// If a task to notify observers of the IP address change event was
// incorrectly posted, make sure it gets run.
MessageLoop::current()->RunUntilIdle();
base::MessageLoop::current()->RunUntilIdle();
}

// Simulates a network change event, resulting in a call to OnObjectSignaled.
Expand All @@ -132,7 +132,7 @@ class NetworkChangeNotifierWinTest : public testing::Test {
EXPECT_EQ(0, network_change_notifier_.sequential_failures());

// Run the task to notify observers of the IP address change event.
MessageLoop::current()->RunUntilIdle();
base::MessageLoop::current()->RunUntilIdle();
}

// Simulates a network change event, resulting in a call to OnObjectSignaled.
Expand All @@ -154,7 +154,7 @@ class NetworkChangeNotifierWinTest : public testing::Test {
EXPECT_LT(0, network_change_notifier_.sequential_failures());

// Run the task to notify observers of the IP address change event.
MessageLoop::current()->RunUntilIdle();
base::MessageLoop::current()->RunUntilIdle();
}

// Runs the message loop until WatchForAddressChange is called again, as a
Expand All @@ -165,14 +165,13 @@ class NetworkChangeNotifierWinTest : public testing::Test {
EXPECT_FALSE(network_change_notifier_.is_watching());
EXPECT_LT(0, network_change_notifier_.sequential_failures());

EXPECT_CALL(test_ip_address_observer_, OnIPAddressChanged())
.Times(1)
.WillOnce(Invoke(MessageLoop::current(), &MessageLoop::Quit));
EXPECT_CALL(test_ip_address_observer_, OnIPAddressChanged()).Times(1)
.WillOnce(
Invoke(base::MessageLoop::current(), &base::MessageLoop::Quit));
EXPECT_CALL(network_change_notifier_, WatchForAddressChangeInternal())
.Times(1)
.WillOnce(Return(true));
.Times(1).WillOnce(Return(true));

MessageLoop::current()->Run();
base::MessageLoop::current()->Run();

EXPECT_TRUE(network_change_notifier_.is_watching());
EXPECT_EQ(0, network_change_notifier_.sequential_failures());
Expand All @@ -196,15 +195,15 @@ class NetworkChangeNotifierWinTest : public testing::Test {
.Times(AtLeast(1))
.WillRepeatedly(Invoke(ExitMessageLoopAndReturnFalse));

MessageLoop::current()->Run();
base::MessageLoop::current()->Run();

EXPECT_FALSE(network_change_notifier_.is_watching());
EXPECT_LT(initial_sequential_failures,
network_change_notifier_.sequential_failures());

// If a task to notify observers of the IP address change event was
// incorrectly posted, make sure it gets run.
MessageLoop::current()->RunUntilIdle();
base::MessageLoop::current()->RunUntilIdle();
}

private:
Expand Down
2 changes: 1 addition & 1 deletion net/base/network_config_watcher_mac.cc
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ NetworkConfigWatcherMac::NetworkConfigWatcherMac(Delegate* delegate)
// We create this notifier thread because the notification implementation
// needs a thread with a CFRunLoop, and there's no guarantee that
// MessageLoop::current() meets that criterion.
base::Thread::Options thread_options(MessageLoop::TYPE_UI, 0);
base::Thread::Options thread_options(base::MessageLoop::TYPE_UI, 0);
notifier_thread_->StartWithOptions(thread_options);
}

Expand Down
4 changes: 2 additions & 2 deletions net/base/network_time_notifier.cc
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ void NetworkTimeNotifier::UpdateNetworkTime(const base::Time& network_time,
base::TimeDelta::FromMilliseconds(kTicksResolutionMs);

for (size_t i = 0; i < observers_.size(); ++i) {
MessageLoop::current()->PostTask(
base::MessageLoop::current()->PostTask(
FROM_HERE,
base::Bind(observers_[i],
network_time_,
Expand All @@ -79,7 +79,7 @@ void NetworkTimeNotifier::AddObserver(
DCHECK(thread_checker_.CalledOnValidThread());
observers_.push_back(observer_callback);
if (!network_time_.is_null()) {
MessageLoop::current()->PostTask(
base::MessageLoop::current()->PostTask(
FROM_HERE,
base::Bind(observer_callback,
network_time_,
Expand Down
4 changes: 2 additions & 2 deletions net/base/test_completion_callback.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ namespace internal {
void TestCompletionCallbackBaseInternal::DidSetResult() {
have_result_ = true;
if (waiting_for_result_)
MessageLoop::current()->Quit();
base::MessageLoop::current()->Quit();
}

void TestCompletionCallbackBaseInternal::WaitForResult() {
DCHECK(!waiting_for_result_);
while (!have_result_) {
waiting_for_result_ = true;
MessageLoop::current()->Run();
base::MessageLoop::current()->Run();
waiting_for_result_ = false;
}
have_result_ = false; // Auto-reset for next callback.
Expand Down
Loading

0 comments on commit 2da659e

Please sign in to comment.