Commit 507e59c3 authored by Gabriel Charette's avatar Gabriel Charette Committed by Commit Bot

Migrate MessageLoop::current() to MessageLoopCurrent in /base/threading

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=jam@chromium.org

Bug: 825327
Change-Id: I1ad5896d82d6b03cff3a481e6898b054157c1ab4
Reviewed-on: https://chromium-review.googlesource.com/1024659
Commit-Queue: John Abd-El-Malek <jam@chromium.org>
Reviewed-by: default avatarJohn Abd-El-Malek <jam@chromium.org>
Cr-Commit-Position: refs/heads/master@{#553123}
parent ede7651e
...@@ -43,7 +43,7 @@ class RunLoop; ...@@ -43,7 +43,7 @@ class RunLoop;
// //
// (1) Thread::CleanUp() // (1) Thread::CleanUp()
// (2) MessageLoop::~MessageLoop // (2) MessageLoop::~MessageLoop
// (3.b) MessageLoop::DestructionObserver::WillDestroyCurrentMessageLoop // (3.b) MessageLoopCurrent::DestructionObserver::WillDestroyCurrentMessageLoop
// //
// This API is not thread-safe: unless indicated otherwise its methods are only // This API is not thread-safe: unless indicated otherwise its methods are only
// valid from the owning sequence (which is the one from which Start() is // valid from the owning sequence (which is the one from which Start() is
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
#include "base/macros.h" #include "base/macros.h"
#include "base/memory/ptr_util.h" #include "base/memory/ptr_util.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/waitable_event.h" #include "base/synchronization/waitable_event.h"
...@@ -100,7 +101,7 @@ class CaptureToEventList : public Thread { ...@@ -100,7 +101,7 @@ class CaptureToEventList : public Thread {
// Observer that writes a value into |event_list| when a message loop has been // Observer that writes a value into |event_list| when a message loop has been
// destroyed. // destroyed.
class CapturingDestructionObserver class CapturingDestructionObserver
: public base::MessageLoop::DestructionObserver { : public base::MessageLoopCurrent::DestructionObserver {
public: public:
// |event_list| must remain valid throughout the observer's lifetime. // |event_list| must remain valid throughout the observer's lifetime.
explicit CapturingDestructionObserver(EventList* event_list) explicit CapturingDestructionObserver(EventList* event_list)
...@@ -121,8 +122,8 @@ class CapturingDestructionObserver ...@@ -121,8 +122,8 @@ class CapturingDestructionObserver
// Task that adds a destruction observer to the current message loop. // Task that adds a destruction observer to the current message loop.
void RegisterDestructionObserver( void RegisterDestructionObserver(
base::MessageLoop::DestructionObserver* observer) { base::MessageLoopCurrent::DestructionObserver* observer) {
base::MessageLoop::current()->AddDestructionObserver(observer); base::MessageLoopCurrent::Get()->AddDestructionObserver(observer);
} }
// Task that calls GetThreadId() of |thread|, stores the result into |id|, then // Task that calls GetThreadId() of |thread|, stores the result into |id|, then
...@@ -446,7 +447,7 @@ TEST_F(ThreadTest, SleepInsideInit) { ...@@ -446,7 +447,7 @@ TEST_F(ThreadTest, SleepInsideInit) {
// //
// (1) Thread::CleanUp() // (1) Thread::CleanUp()
// (2) MessageLoop::~MessageLoop() // (2) MessageLoop::~MessageLoop()
// MessageLoop::DestructionObservers called. // MessageLoopCurrent::DestructionObservers called.
TEST_F(ThreadTest, CleanUp) { TEST_F(ThreadTest, CleanUp) {
EventList captured_events; EventList captured_events;
CapturingDestructionObserver loop_destruction_observer(&captured_events); CapturingDestructionObserver loop_destruction_observer(&captured_events);
......
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