Chromium Code Reviews| Index: base/run_loop.h |
| diff --git a/base/run_loop.h b/base/run_loop.h |
| index 077d097ba9a2a35c6ec51d017f588b9f195e48c0..398ddc46406aa5f9e247abe9fd97b19e91554b3d 100644 |
| --- a/base/run_loop.h |
| +++ b/base/run_loop.h |
| @@ -43,7 +43,10 @@ class BASE_EXPORT RunLoop { |
| // when repeating tasks such as animated web pages have been shut down. |
| void RunUntilIdle(); |
| - bool running() const { return running_; } |
| + bool running() const { |
| + DCHECK(thread_checker_.CalledOnValidThread()); |
| + return running_; |
| + } |
| // Quit() quits an earlier call to Run() immediately. QuitWhenIdle() quits an |
| // earlier call to Run() when there aren't any tasks or messages in the queue. |
| @@ -72,6 +75,34 @@ class BASE_EXPORT RunLoop { |
| base::Closure QuitClosure(); |
| base::Closure QuitWhenIdleClosure(); |
| + // Returns true if there is an active RunLoop on this thread. |
| + static bool IsRunningOnCurrentThread(); |
| + |
| + // Returns true if there is an active RunLoop on this thread and it's nested |
| + // within another active RunLoop. |
| + static bool IsNestedOnCurrentThread(); |
| + |
| + // A NestingObserver is notified when a nested run loop begins. The observers |
| + // are notified before the current thread's RunLoop::Delegate::Run() is |
| + // invoked and nested work begins. |
| + class BASE_EXPORT NestingObserver { |
| + public: |
| + virtual void OnBeginNestedMessageLoop() = 0; |
|
Sami
2017/04/20 10:13:22
nit: TODO to rename this to OnBeginNestedRunLoop (
gab
2017/04/20 14:21:18
Ah yes, missed that one, definitely doing it now,
danakj
2017/04/20 14:57:32
+1
gab
2017/04/20 16:22:02
Done.
|
| + |
| + protected: |
|
danakj
2017/04/20 14:57:32
why protected
gab
2017/04/20 16:22:02
Copied as-is from MessageLoop::NestingObserver.
I
|
| + virtual ~NestingObserver() = default; |
| + }; |
| + |
| + static void AddNestingObserverOnCurrentThread(NestingObserver* observer); |
| + static void RemoveNestingObserverOnCurrentThread(NestingObserver* observer); |
| + |
| + // Returns true if nesting is allowed on this thread. |
| + static bool IsNestingAllowedOnCurrentThread(); |
| + |
| + // Disallow nesting. After this is called, running a nested RunLoop or calling |
| + // Add/RemoveNestingObserverOnCurrentThread() on this thread will crash. |
| + static void DisallowNestingOnCurrentThread(); |
| + |
| private: |
| friend class MessageLoop; |
| #if defined(OS_ANDROID) |
| @@ -92,20 +123,15 @@ class BASE_EXPORT RunLoop { |
| MessageLoop* loop_; |
| - // Parent RunLoop or NULL if this is the top-most RunLoop. |
| - RunLoop* previous_run_loop_; |
| - |
| - // Used to count how many nested Run() invocations are on the stack. |
| - int run_depth_; |
| - |
| - bool run_called_; |
| - bool quit_called_; |
| - bool running_; |
| + bool run_called_ = false; |
| + bool quit_called_ = false; |
| + bool running_ = false; |
| // Used to record that QuitWhenIdle() was called on the MessageLoop, meaning |
| // that we should quit Run once it becomes idle. |
| - bool quit_when_idle_received_; |
| + bool quit_when_idle_received_ = false; |
| + // RunLoop's non-static methods are affine to the thread it's running on. |
| base::ThreadChecker thread_checker_; |
| // WeakPtrFactory for QuitClosure safety. |