Commit 1e5bed44 authored by Gabriel Charette's avatar Gabriel Charette Committed by Commit Bot

Migrate MessageLoop::current() to MessageLoopCurrent in /net

These changes were scripted as part of the effort to restrict exposure of the
raw MessageLoop*.

Note that many static methods exposed on MessageLoopCurrent are also deprecated
so it is very well possible that this is migrating to an already deprecated
method.

The goal of this pass is to reduce usage of MessageLoop::current() (and
ultimately make it impossible to obtain the MessageLoop* statically).

As such I will not edit this CL unless the script did something logically wrong.
I defer to owners to fix highlighted usage of already deprecated APIs.

Possible script screw ups / things to look out for in this review:
 - Storing MessageLoopCurrent in a MessageLoop* variable or comparing it against
   one (I will go over that in a separate pass).

Includes should have been stripped if that was the last usage of message_loop.h
in that file.

Please CQ if LGTY

This CL was uploaded by git cl split.

R=juliatuttle@chromium.org

Bug: 825327
Change-Id: Iddd6fb67987e98cbc4fa6a4b09167124e1f31388
Reviewed-on: https://chromium-review.googlesource.com/1024470Reviewed-by: default avatarJulia Tuttle <juliatuttle@chromium.org>
Commit-Queue: Gabriel Charette <gab@chromium.org>
Cr-Commit-Position: refs/heads/master@{#553356}
parent 110508e1
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include "base/bind_helpers.h" #include "base/bind_helpers.h"
#include "base/files/scoped_file.h" #include "base/files/scoped_file.h"
#include "base/logging.h" #include "base/logging.h"
#include "base/message_loop/message_loop_current.h"
#include "base/posix/eintr_wrapper.h" #include "base/posix/eintr_wrapper.h"
#include "base/threading/thread_restrictions.h" #include "base/threading/thread_restrictions.h"
#include "net/base/network_interfaces_linux.h" #include "net/base/network_interfaces_linux.h"
...@@ -230,7 +231,7 @@ void AddressTrackerLinux::Init() { ...@@ -230,7 +231,7 @@ void AddressTrackerLinux::Init() {
} }
if (tracking_) { if (tracking_) {
rv = base::MessageLoopForIO::current()->WatchFileDescriptor( rv = base::MessageLoopCurrentForIO::Get()->WatchFileDescriptor(
netlink_fd_, true, base::MessagePumpForIO::WATCH_READ, &watcher_, this); netlink_fd_, true, base::MessagePumpForIO::WATCH_READ, &watcher_, this);
if (rv < 0) { if (rv < 0) {
PLOG(ERROR) << "Could not watch NETLINK socket"; PLOG(ERROR) << "Could not watch NETLINK socket";
......
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
#include "base/files/file_path.h" #include "base/files/file_path.h"
#include "base/location.h" #include "base/location.h"
#include "base/logging.h" #include "base/logging.h"
#include "base/message_loop/message_loop.h" #include "base/message_loop/message_loop_current.h"
#include "base/message_loop/message_pump_for_io.h" #include "base/message_loop/message_pump_for_io.h"
#include "base/single_thread_task_runner.h" #include "base/single_thread_task_runner.h"
#include "base/task_runner.h" #include "base/task_runner.h"
...@@ -119,8 +119,8 @@ FileStream::Context::IOResult FileStream::Context::SeekFileImpl( ...@@ -119,8 +119,8 @@ FileStream::Context::IOResult FileStream::Context::SeekFileImpl(
} }
void FileStream::Context::OnFileOpened() { void FileStream::Context::OnFileOpened() {
base::MessageLoopForIO::current()->RegisterIOHandler(file_.GetPlatformFile(), base::MessageLoopCurrentForIO::Get()->RegisterIOHandler(
this); file_.GetPlatformFile(), this);
} }
void FileStream::Context::IOCompletionIsPending(CompletionOnceCallback callback, void FileStream::Context::IOCompletionIsPending(CompletionOnceCallback callback,
......
...@@ -101,7 +101,7 @@ NetworkChangeNotifierLinux::NetworkChangeNotifierLinux( ...@@ -101,7 +101,7 @@ NetworkChangeNotifierLinux::NetworkChangeNotifierLinux(
notifier_thread_(new Thread(ignored_interfaces)) { notifier_thread_(new Thread(ignored_interfaces)) {
// We create this notifier thread because the notification implementation // We create this notifier thread because the notification implementation
// needs a MessageLoopForIO, and there's no guarantee that // needs a MessageLoopForIO, and there's no guarantee that
// MessageLoop::current() meets that criterion. // MessageLoopCurrent::Get() meets that criterion.
base::Thread::Options thread_options(base::MessageLoop::TYPE_IO, 0); base::Thread::Options thread_options(base::MessageLoop::TYPE_IO, 0);
notifier_thread_->StartWithOptions(thread_options); notifier_thread_->StartWithOptions(thread_options);
} }
......
...@@ -265,7 +265,7 @@ NetworkConfigWatcherMac::NetworkConfigWatcherMac(Delegate* delegate) ...@@ -265,7 +265,7 @@ NetworkConfigWatcherMac::NetworkConfigWatcherMac(Delegate* delegate)
: notifier_thread_(new NetworkConfigWatcherMacThread(delegate)) { : notifier_thread_(new NetworkConfigWatcherMacThread(delegate)) {
// We create this notifier thread because the notification implementation // We create this notifier thread because the notification implementation
// needs a thread with a CFRunLoop, and there's no guarantee that // needs a thread with a CFRunLoop, and there's no guarantee that
// MessageLoop::current() meets that criterion. // MessageLoopCurrent::Get() meets that criterion.
base::Thread::Options thread_options(base::MessageLoop::TYPE_UI, 0); base::Thread::Options thread_options(base::MessageLoop::TYPE_UI, 0);
notifier_thread_->StartWithOptions(thread_options); notifier_thread_->StartWithOptions(thread_options);
} }
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
#include <notify.h> #include <notify.h>
#include "base/logging.h" #include "base/logging.h"
#include "base/message_loop/message_loop.h" #include "base/message_loop/message_loop_current.h"
#include "base/posix/eintr_wrapper.h" #include "base/posix/eintr_wrapper.h"
namespace net { namespace net {
...@@ -28,7 +28,7 @@ bool NotifyWatcherMac::Watch(const char* key, const CallbackType& callback) { ...@@ -28,7 +28,7 @@ bool NotifyWatcherMac::Watch(const char* key, const CallbackType& callback) {
if (status != NOTIFY_STATUS_OK) if (status != NOTIFY_STATUS_OK)
return false; return false;
DCHECK_GE(notify_fd_, 0); DCHECK_GE(notify_fd_, 0);
if (!base::MessageLoopForIO::current()->WatchFileDescriptor( if (!base::MessageLoopCurrentForIO::Get()->WatchFileDescriptor(
notify_fd_, true, base::MessagePumpForIO::WATCH_READ, &watcher_, notify_fd_, true, base::MessagePumpForIO::WATCH_READ, &watcher_,
this)) { this)) {
Cancel(); Cancel();
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include "base/bind.h" #include "base/bind.h"
#include "base/location.h" #include "base/location.h"
#include "base/message_loop/message_loop.h" #include "base/message_loop/message_loop.h"
#include "base/message_loop/message_loop_current.h"
#include "base/run_loop.h" #include "base/run_loop.h"
#include "base/single_thread_task_runner.h" #include "base/single_thread_task_runner.h"
#include "base/synchronization/lock.h" #include "base/synchronization/lock.h"
...@@ -109,7 +110,7 @@ class SerialWorkerTest : public testing::Test { ...@@ -109,7 +110,7 @@ class SerialWorkerTest : public testing::Test {
// test::Test methods // test::Test methods
void SetUp() override { void SetUp() override {
message_loop_ = base::MessageLoop::current(); message_loop_ = base::MessageLoopCurrent::Get();
worker_ = new TestSerialWorker(this); worker_ = new TestSerialWorker(this);
} }
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
#include "base/callback_helpers.h" #include "base/callback_helpers.h"
#include "base/files/file_util.h" #include "base/files/file_util.h"
#include "base/logging.h" #include "base/logging.h"
#include "base/message_loop/message_loop.h" #include "base/message_loop/message_loop_current.h"
#include "base/posix/eintr_wrapper.h" #include "base/posix/eintr_wrapper.h"
#include "base/trace_event/trace_event.h" #include "base/trace_event/trace_event.h"
#include "build/build_config.h" #include "build/build_config.h"
...@@ -174,7 +174,7 @@ int SocketPosix::Accept(std::unique_ptr<SocketPosix>* socket, ...@@ -174,7 +174,7 @@ int SocketPosix::Accept(std::unique_ptr<SocketPosix>* socket,
if (rv != ERR_IO_PENDING) if (rv != ERR_IO_PENDING)
return rv; return rv;
if (!base::MessageLoopForIO::current()->WatchFileDescriptor( if (!base::MessageLoopCurrentForIO::Get()->WatchFileDescriptor(
socket_fd_, true, base::MessagePumpForIO::WATCH_READ, socket_fd_, true, base::MessagePumpForIO::WATCH_READ,
&accept_socket_watcher_, this)) { &accept_socket_watcher_, this)) {
PLOG(ERROR) << "WatchFileDescriptor failed on accept, errno " << errno; PLOG(ERROR) << "WatchFileDescriptor failed on accept, errno " << errno;
...@@ -199,7 +199,7 @@ int SocketPosix::Connect(const SockaddrStorage& address, ...@@ -199,7 +199,7 @@ int SocketPosix::Connect(const SockaddrStorage& address,
if (rv != ERR_IO_PENDING) if (rv != ERR_IO_PENDING)
return rv; return rv;
if (!base::MessageLoopForIO::current()->WatchFileDescriptor( if (!base::MessageLoopCurrentForIO::Get()->WatchFileDescriptor(
socket_fd_, true, base::MessagePumpForIO::WATCH_WRITE, socket_fd_, true, base::MessagePumpForIO::WATCH_WRITE,
&write_socket_watcher_, this)) { &write_socket_watcher_, this)) {
PLOG(ERROR) << "WatchFileDescriptor failed on connect, errno " << errno; PLOG(ERROR) << "WatchFileDescriptor failed on connect, errno " << errno;
...@@ -337,7 +337,7 @@ int SocketPosix::ReadIfReady(IOBuffer* buf, ...@@ -337,7 +337,7 @@ int SocketPosix::ReadIfReady(IOBuffer* buf,
if (rv != ERR_IO_PENDING) if (rv != ERR_IO_PENDING)
return rv; return rv;
if (!base::MessageLoopForIO::current()->WatchFileDescriptor( if (!base::MessageLoopCurrentForIO::Get()->WatchFileDescriptor(
socket_fd_, true, base::MessagePumpForIO::WATCH_READ, socket_fd_, true, base::MessagePumpForIO::WATCH_READ,
&read_socket_watcher_, this)) { &read_socket_watcher_, this)) {
PLOG(ERROR) << "WatchFileDescriptor failed on read, errno " << errno; PLOG(ERROR) << "WatchFileDescriptor failed on read, errno " << errno;
...@@ -377,7 +377,7 @@ int SocketPosix::WaitForWrite(IOBuffer* buf, ...@@ -377,7 +377,7 @@ int SocketPosix::WaitForWrite(IOBuffer* buf,
DCHECK(!callback.is_null()); DCHECK(!callback.is_null());
DCHECK_LT(0, buf_len); DCHECK_LT(0, buf_len);
if (!base::MessageLoopForIO::current()->WatchFileDescriptor( if (!base::MessageLoopCurrentForIO::Get()->WatchFileDescriptor(
socket_fd_, true, base::MessagePumpForIO::WATCH_WRITE, socket_fd_, true, base::MessagePumpForIO::WATCH_WRITE,
&write_socket_watcher_, this)) { &write_socket_watcher_, this)) {
PLOG(ERROR) << "WatchFileDescriptor failed on write, errno " << errno; PLOG(ERROR) << "WatchFileDescriptor failed on write, errno " << errno;
......
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
#include "base/debug/alias.h" #include "base/debug/alias.h"
#include "base/files/file_util.h" #include "base/files/file_util.h"
#include "base/logging.h" #include "base/logging.h"
#include "base/message_loop/message_loop.h" #include "base/message_loop/message_loop_current.h"
#include "base/metrics/histogram_functions.h" #include "base/metrics/histogram_functions.h"
#include "base/posix/eintr_wrapper.h" #include "base/posix/eintr_wrapper.h"
#include "base/rand_util.h" #include "base/rand_util.h"
...@@ -408,7 +408,7 @@ int UDPSocketPosix::RecvFrom(IOBuffer* buf, ...@@ -408,7 +408,7 @@ int UDPSocketPosix::RecvFrom(IOBuffer* buf,
if (nread != ERR_IO_PENDING) if (nread != ERR_IO_PENDING)
return nread; return nread;
if (!base::MessageLoopForIO::current()->WatchFileDescriptor( if (!base::MessageLoopCurrentForIO::Get()->WatchFileDescriptor(
socket_, true, base::MessagePumpForIO::WATCH_READ, socket_, true, base::MessagePumpForIO::WATCH_READ,
&read_socket_watcher_, &read_watcher_)) { &read_socket_watcher_, &read_watcher_)) {
PLOG(ERROR) << "WatchFileDescriptor failed on read"; PLOG(ERROR) << "WatchFileDescriptor failed on read";
...@@ -453,7 +453,7 @@ int UDPSocketPosix::SendToOrWrite(IOBuffer* buf, ...@@ -453,7 +453,7 @@ int UDPSocketPosix::SendToOrWrite(IOBuffer* buf,
if (result != ERR_IO_PENDING) if (result != ERR_IO_PENDING)
return result; return result;
if (!base::MessageLoopForIO::current()->WatchFileDescriptor( if (!base::MessageLoopCurrentForIO::Get()->WatchFileDescriptor(
socket_, true, base::MessagePumpForIO::WATCH_WRITE, socket_, true, base::MessagePumpForIO::WATCH_WRITE,
&write_socket_watcher_, &write_watcher_)) { &write_socket_watcher_, &write_watcher_)) {
DVLOG(1) << "WatchFileDescriptor failed on write, errno " << errno; DVLOG(1) << "WatchFileDescriptor failed on write, errno " << errno;
...@@ -1466,7 +1466,7 @@ void UDPSocketPosix::StopWatchingFileDescriptor() { ...@@ -1466,7 +1466,7 @@ void UDPSocketPosix::StopWatchingFileDescriptor() {
} }
bool UDPSocketPosix::InternalWatchFileDescriptor() { bool UDPSocketPosix::InternalWatchFileDescriptor() {
return base::MessageLoopForIO::current()->WatchFileDescriptor( return base::MessageLoopCurrentForIO::Get()->WatchFileDescriptor(
socket_, true, base::MessagePumpForIO::WATCH_WRITE, socket_, true, base::MessagePumpForIO::WATCH_WRITE,
&write_socket_watcher_, write_async_watcher_.get()); &write_socket_watcher_, write_async_watcher_.get());
} }
......
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include "base/location.h" #include "base/location.h"
#include "base/logging.h" #include "base/logging.h"
#include "base/message_loop/message_loop.h" #include "base/message_loop/message_loop.h"
#include "base/message_loop/message_loop_current.h"
#include "base/path_service.h" #include "base/path_service.h"
#include "base/process/process_metrics.h" #include "base/process/process_metrics.h"
#include "base/run_loop.h" #include "base/run_loop.h"
...@@ -479,7 +480,7 @@ bool EmbeddedTestServer::PostTaskToIOThreadAndWait( ...@@ -479,7 +480,7 @@ bool EmbeddedTestServer::PostTaskToIOThreadAndWait(
// To handle this situation, create temporary message loop to support the // To handle this situation, create temporary message loop to support the
// PostTaskAndReply operation if the current thread as no message loop. // PostTaskAndReply operation if the current thread as no message loop.
std::unique_ptr<base::MessageLoop> temporary_loop; std::unique_ptr<base::MessageLoop> temporary_loop;
if (!base::MessageLoop::current()) if (!base::MessageLoopCurrent::Get())
temporary_loop.reset(new base::MessageLoop()); temporary_loop.reset(new base::MessageLoop());
base::RunLoop run_loop; base::RunLoop run_loop;
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
#include "base/files/file_util.h" #include "base/files/file_util.h"
#include "base/location.h" #include "base/location.h"
#include "base/message_loop/message_loop.h" #include "base/message_loop/message_loop.h"
#include "base/message_loop/message_loop_current.h"
#include "base/run_loop.h" #include "base/run_loop.h"
#include "base/single_thread_task_runner.h" #include "base/single_thread_task_runner.h"
#include "base/strings/string_number_conversions.h" #include "base/strings/string_number_conversions.h"
...@@ -405,7 +406,7 @@ void GDig::Start() { ...@@ -405,7 +406,7 @@ void GDig::Start() {
void GDig::Finish(Result result) { void GDig::Finish(Result result) {
DCHECK_NE(RESULT_PENDING, result); DCHECK_NE(RESULT_PENDING, result);
result_ = result; result_ = result;
if (base::MessageLoop::current()) if (base::MessageLoopCurrent::Get())
base::RunLoop::QuitCurrentWhenIdleDeprecated(); base::RunLoop::QuitCurrentWhenIdleDeprecated();
} }
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#include "base/logging.h" #include "base/logging.h"
#include "base/message_loop/message_loop.h" #include "base/message_loop/message_loop.h"
#include "base/message_loop/message_loop_current.h"
#include "base/stl_util.h" #include "base/stl_util.h"
#include "net/url_request/url_request.h" #include "net/url_request/url_request.h"
#include "net/url_request/url_request_job_factory_impl.h" #include "net/url_request/url_request_job_factory_impl.h"
...@@ -16,15 +17,14 @@ namespace { ...@@ -16,15 +17,14 @@ namespace {
// When adding interceptors, DCHECK that this function returns true. // When adding interceptors, DCHECK that this function returns true.
bool OnMessageLoopForInterceptorAddition() { bool OnMessageLoopForInterceptorAddition() {
base::MessageLoop* message_loop = base::MessageLoop::current();
// Return true if called on a MessageLoopForIO or if there is no MessageLoop. // Return true if called on a MessageLoopForIO or if there is no MessageLoop.
// Checking for a MessageLoopForIO is a best effort at determining whether the // Checking for a MessageLoopForIO is a best effort at determining whether the
// current thread is a networking thread. Allowing cases without a // current thread is a networking thread. Allowing cases without a
// MessageLoop is required for some tests where there is no chance to insert // MessageLoop is required for some tests where there is no chance to insert
// an interceptor between a networking thread being started and a resource // an interceptor between a networking thread being started and a resource
// request being issued. // request being issued.
return message_loop == nullptr || return base::MessageLoopCurrentForIO::IsSet() ||
message_loop->type() == base::MessageLoop::TYPE_IO; !base::MessageLoopCurrent::IsSet();
} }
// When removing interceptors, DCHECK that this function returns true. // When removing interceptors, DCHECK that this function returns true.
...@@ -113,7 +113,7 @@ void URLRequestFilter::ClearHandlers() { ...@@ -113,7 +113,7 @@ void URLRequestFilter::ClearHandlers() {
URLRequestJob* URLRequestFilter::MaybeInterceptRequest( URLRequestJob* URLRequestFilter::MaybeInterceptRequest(
URLRequest* request, URLRequest* request,
NetworkDelegate* network_delegate) const { NetworkDelegate* network_delegate) const {
DCHECK(base::MessageLoopForIO::current()); DCHECK(base::MessageLoopCurrentForIO::Get());
URLRequestJob* job = NULL; URLRequestJob* job = NULL;
if (!request->url().is_valid()) if (!request->url().is_valid())
return NULL; return NULL;
......
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