OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef BASE_MESSAGE_LOOP_PROXY_H_ |
| 6 #define BASE_MESSAGE_LOOP_PROXY_H_ |
| 7 |
| 8 #include "base/basictypes.h" |
| 9 #include "base/ref_counted.h" |
| 10 #include "base/task.h" |
| 11 |
| 12 // This class provides a thread-safe refcounted interface to the Post* methods |
| 13 // of a message loop. This class can outlive the target message loop. |
| 14 class MessageLoopProxy : public base::RefCountedThreadSafe<MessageLoopProxy> { |
| 15 public: |
| 16 // These are the same methods in message_loop.h, but are guaranteed to either |
| 17 // get posted to the MessageLoop if it's still alive, or be deleted otherwise. |
| 18 // They return true iff the thread existed and the task was posted. Note that |
| 19 // even if the task is posted, there's no guarantee that it will run, since |
| 20 // the target thread may already have a Quit message in its queue. |
| 21 virtual bool PostTask(const tracked_objects::Location& from_here, |
| 22 Task* task) = 0; |
| 23 virtual bool PostDelayedTask(const tracked_objects::Location& from_here, |
| 24 Task* task, int64 delay_ms) = 0; |
| 25 virtual bool PostNonNestableTask(const tracked_objects::Location& from_here, |
| 26 Task* task) = 0; |
| 27 virtual bool PostNonNestableDelayedTask( |
| 28 const tracked_objects::Location& from_here, |
| 29 Task* task, |
| 30 int64 delay_ms) = 0; |
| 31 |
| 32 template <class T> |
| 33 bool DeleteSoon(const tracked_objects::Location& from_here, |
| 34 T* object) { |
| 35 return PostNonNestableTask(from_here, new DeleteTask<T>(object)); |
| 36 } |
| 37 template <class T> |
| 38 bool ReleaseSoon(const tracked_objects::Location& from_here, |
| 39 T* object) { |
| 40 return PostNonNestableTask(from_here, new ReleaseTask<T>(object)); |
| 41 } |
| 42 }; |
| 43 |
| 44 #endif // BASE_MESSAGE_LOOP_PROXY_H_ |
| 45 |
OLD | NEW |