Chromium Code Reviews| Index: base/message_loop/message_loop_proxy_impl.h |
| diff --git a/base/message_loop/message_loop_proxy_impl.h b/base/message_loop/message_loop_proxy_impl.h |
| index 2269023ac2d19c0f9074fcadf181a3a9da1f3f51..6aba68d957d6dd86484fd66aaac0e437b542f455 100644 |
| --- a/base/message_loop/message_loop_proxy_impl.h |
| +++ b/base/message_loop/message_loop_proxy_impl.h |
| @@ -8,15 +8,19 @@ |
| #include "base/base_export.h" |
| #include "base/message_loop.h" |
| #include "base/message_loop/message_loop_proxy.h" |
| +#include "base/pending_task.h" |
| #include "base/synchronization/lock.h" |
| +#include "base/time/time.h" |
| namespace base { |
| // A stock implementation of MessageLoopProxy that is created and managed by a |
| -// MessageLoop. For now a MessageLoopProxyImpl can only be created as part of a |
| +// MessageLoop. For now a ProxyImpl can only be created as part of a |
| // MessageLoop. |
| -class BASE_EXPORT MessageLoopProxyImpl : public MessageLoopProxy { |
| +class BASE_EXPORT MessageLoop::ProxyImpl : public MessageLoopProxy { |
| public: |
| + ProxyImpl(); |
| + |
| // MessageLoopProxy implementation |
| virtual bool PostDelayedTask(const tracked_objects::Location& from_here, |
| const base::Closure& task, |
| @@ -27,34 +31,75 @@ class BASE_EXPORT MessageLoopProxyImpl : public MessageLoopProxy { |
| base::TimeDelta delay) OVERRIDE; |
| virtual bool RunsTasksOnCurrentThread() const OVERRIDE; |
| - protected: |
| - virtual ~MessageLoopProxyImpl(); |
| + // Acquires |incoming_queue_lock_| and appends a task to |incoming_queue_|. |
| + // Posting of all tasks is routed though AddToIncomingQueue() or |
| + // TryAddToIncomingQueue() to make sure that posting task is properly |
| + // synchronized between different threads. |
| + // |
| + // Returns true if the task was successfully added to the queue, otherwise |
| + // returns false. In all cases, the ownership of |task| is transferred to the |
| + // called method. |
| + bool AddToIncomingQueue(const tracked_objects::Location& from_here, |
| + const Closure& task, |
| + TimeDelta delay, |
| + bool nestable); |
| + |
| + // Returns true if the message loop has high resolution timers enabled. |
| + // Provided for testing. |
| + bool IsHishResolutionTimersEnabledForTest(); |
| + |
| + // Returns true if the message loop is "idle". Provided for testing. |
| + bool IsIdleForTest(); |
| + |
| + // Loads tasks from the |incoming_queue_| into |*work_queue|. Must be called |
| + // from the thread that is running the loop. |
| + void ReloadWorkQueue(TaskQueue* work_queue); |
| - // Override OnDestruct so that we can delete the object on the target message |
| - // loop if it still exists. |
| - virtual void OnDestruct() const OVERRIDE; |
| + // Same as AddToIncomingQueue() except that it will avoid blocking if the lock |
| + // is already held, and will in that case (when the lock is contended) fail to |
| + // add the task, and will return false. |
| + bool TryAddToIncomingQueue(const tracked_objects::Location& from_here, |
| + const Closure& task); |
| + |
| + // Diconnects |this| from the parent message loop. |
|
rvargas (doing something else)
2013/07/10 00:24:42
type: disconnects
alexeypa (please no reviews)
2013/07/10 16:14:27
Done.
|
| + void WillDestroyCurrentMessageLoop(); |
| + |
| + protected: |
| + virtual ~ProxyImpl(); |
|
rvargas (doing something else)
2013/07/10 00:24:42
nit: send it to the private section?
alexeypa (please no reviews)
2013/07/10 16:14:27
Done.
|
| private: |
| - // Allow the MessageLoop to create a MessageLoopProxyImpl. |
| - friend class MessageLoop; |
| - friend class DeleteHelper<MessageLoopProxyImpl>; |
| + friend class MessageLoopLockTest; |
| + friend class DeleteHelper<ProxyImpl>; |
| + |
| + // Calculates the time at which a PendingTask should run. |
| + TimeTicks CalculateDelayedRuntime(TimeDelta delay); |
| + |
| + // Adds a task to |incoming_queue_|. The caller retains ownership of |
| + // |pending_task|, but this function will reset the value of |
| + // |pending_task->task|. This is needed to ensure that the posting call stack |
| + // does not retain |pending_task->task| beyond this function call. |
| + bool PostPendingTask(PendingTask* pending_task); |
| - MessageLoopProxyImpl(); |
| +#if defined(OS_WIN) |
| + TimeTicks high_resolution_timer_expiration_; |
| +#endif |
| - // Called directly by MessageLoop::~MessageLoop. |
| - virtual void WillDestroyCurrentMessageLoop(); |
| + // The lock that protects access to |incoming_queue_|, |message_loop_| and |
| + // |next_sequence_num_|. |
| + mutable base::Lock incoming_queue_lock_; |
| + // An incoming queue of tasks that are acquired under a mutex for processing |
| + // on this instance's thread. These tasks have not yet been been pushed to |
| + // |message_loop_|. |
| + TaskQueue incoming_queue_; |
| - bool PostTaskHelper(const tracked_objects::Location& from_here, |
| - const base::Closure& task, |
| - base::TimeDelta delay, |
| - bool nestable); |
| + // Points to the message loop that owns |this|. |
| + MessageLoop* message_loop_; |
| - // The lock that protects access to target_message_loop_. |
| - mutable base::Lock message_loop_lock_; |
| - MessageLoop* target_message_loop_; |
| + // The next sequence number to use for delayed tasks. |
| + int next_sequence_num_; |
| - DISALLOW_COPY_AND_ASSIGN(MessageLoopProxyImpl); |
| + DISALLOW_COPY_AND_ASSIGN(ProxyImpl); |
| }; |
| } // namespace base |