| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef BASE_MESSAGE_LOOP_PROXY_IMPL_H_ | 5 #ifndef BASE_MESSAGE_LOOP_PROXY_IMPL_H_ |
| 6 #define BASE_MESSAGE_LOOP_PROXY_IMPL_H_ | 6 #define BASE_MESSAGE_LOOP_PROXY_IMPL_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include "base/base_api.h" | 9 #include "base/base_api.h" |
| 10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
| 11 #include "base/message_loop_proxy.h" | 11 #include "base/message_loop_proxy.h" |
| 12 #include "base/synchronization/lock.h" | 12 #include "base/synchronization/lock.h" |
| 13 | 13 |
| 14 namespace base { | 14 namespace base { |
| 15 | 15 |
| 16 // A stock implementation of MessageLoopProxy that takes in a MessageLoop | 16 // A stock implementation of MessageLoopProxy that takes in a MessageLoop |
| 17 // and keeps track of its lifetime using the MessageLoop DestructionObserver. | 17 // and keeps track of its lifetime using the MessageLoop DestructionObserver. |
| 18 // For now a MessageLoopProxyImpl can only be created for the current thread. | 18 // For now a MessageLoopProxyImpl can only be created for the current thread. |
| 19 class BASE_API MessageLoopProxyImpl : public MessageLoopProxy, | 19 class BASE_API MessageLoopProxyImpl : public MessageLoopProxy, |
| 20 public MessageLoop::DestructionObserver { | 20 public MessageLoop::DestructionObserver { |
| 21 public: | 21 public: |
| 22 virtual ~MessageLoopProxyImpl(); | 22 virtual ~MessageLoopProxyImpl(); |
| 23 | 23 |
| 24 // MessageLoopProxy implementation | 24 // MessageLoopProxy implementation |
| 25 virtual bool PostTask(const tracked_objects::Location& from_here, | 25 virtual bool PostTask(const tracked_objects::Location& from_here, |
| 26 Task* task); | 26 Task* task); |
| 27 virtual bool PostDelayedTask(const tracked_objects::Location& from_here, | 27 virtual bool PostDelayedTask(const tracked_objects::Location& from_here, |
| 28 Task* task, int64 delay_ms); | 28 Task* task, |
| 29 int64 delay_ms); |
| 29 virtual bool PostNonNestableTask(const tracked_objects::Location& from_here, | 30 virtual bool PostNonNestableTask(const tracked_objects::Location& from_here, |
| 30 Task* task); | 31 Task* task); |
| 31 virtual bool PostNonNestableDelayedTask( | 32 virtual bool PostNonNestableDelayedTask( |
| 32 const tracked_objects::Location& from_here, | 33 const tracked_objects::Location& from_here, |
| 33 Task* task, | 34 Task* task, |
| 34 int64 delay_ms); | 35 int64 delay_ms); |
| 36 virtual bool PostTask(const tracked_objects::Location& from_here, |
| 37 const base::Closure& task); |
| 38 virtual bool PostDelayedTask(const tracked_objects::Location& from_here, |
| 39 const base::Closure& task, |
| 40 int64 delay_ms); |
| 41 virtual bool PostNonNestableTask(const tracked_objects::Location& from_here, |
| 42 const base::Closure& task); |
| 43 virtual bool PostNonNestableDelayedTask( |
| 44 const tracked_objects::Location& from_here, |
| 45 const base::Closure& task, |
| 46 int64 delay_ms); |
| 35 virtual bool BelongsToCurrentThread(); | 47 virtual bool BelongsToCurrentThread(); |
| 36 | 48 |
| 37 // MessageLoop::DestructionObserver implementation | 49 // MessageLoop::DestructionObserver implementation |
| 38 virtual void WillDestroyCurrentMessageLoop(); | 50 virtual void WillDestroyCurrentMessageLoop(); |
| 39 | 51 |
| 40 protected: | 52 protected: |
| 41 // Override OnDestruct so that we can delete the object on the target message | 53 // Override OnDestruct so that we can delete the object on the target message |
| 42 // loop if it still exists. | 54 // loop if it still exists. |
| 43 virtual void OnDestruct() const; | 55 virtual void OnDestruct() const; |
| 44 | 56 |
| 45 private: | 57 private: |
| 46 MessageLoopProxyImpl(); | 58 MessageLoopProxyImpl(); |
| 59 // TODO(ajwong): Remove this after we've fully migrated to base::Closure. |
| 47 bool PostTaskHelper(const tracked_objects::Location& from_here, | 60 bool PostTaskHelper(const tracked_objects::Location& from_here, |
| 48 Task* task, int64 delay_ms, bool nestable); | 61 Task* task, |
| 62 int64 delay_ms, |
| 63 bool nestable); |
| 64 bool PostTaskHelper(const tracked_objects::Location& from_here, |
| 65 const base::Closure& task, |
| 66 int64 delay_ms, |
| 67 bool nestable); |
| 49 | 68 |
| 50 // For the factory method to work | 69 // For the factory method to work |
| 51 friend class MessageLoopProxy; | 70 friend class MessageLoopProxy; |
| 52 | 71 |
| 53 // The lock that protects access to target_message_loop_. | 72 // The lock that protects access to target_message_loop_. |
| 54 mutable base::Lock message_loop_lock_; | 73 mutable base::Lock message_loop_lock_; |
| 55 MessageLoop* target_message_loop_; | 74 MessageLoop* target_message_loop_; |
| 56 | 75 |
| 57 DISALLOW_COPY_AND_ASSIGN(MessageLoopProxyImpl); | 76 DISALLOW_COPY_AND_ASSIGN(MessageLoopProxyImpl); |
| 58 }; | 77 }; |
| 59 | 78 |
| 60 } // namespace base | 79 } // namespace base |
| 61 | 80 |
| 62 #endif // BASE_MESSAGE_LOOP_PROXY_IMPL_H_ | 81 #endif // BASE_MESSAGE_LOOP_PROXY_IMPL_H_ |
| 63 | |
| OLD | NEW |