OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef REMOTING_BASE_TASK_THREAD_PROXY_H_ |
| 6 #define REMOTING_BASE_TASK_THREAD_PROXY_H_ |
| 7 |
| 8 #include "base/message_loop.h" |
| 9 |
| 10 namespace remoting { |
| 11 |
| 12 // This is a refcounted class that is used to switch to the appropriate thread |
| 13 // before running a task on a target object. It should be used whenever you |
| 14 // need to post to an object, but: |
| 15 // (1) You don't know when the object might be deleted, and |
| 16 // (2) You cannot subclass the target from RefCountedThreadSafe. |
| 17 // |
| 18 // Example usage: |
| 19 // Instead of: |
| 20 // MyClass* obj; |
| 21 // obj->Method(param); |
| 22 // Use: |
| 23 // proxy->Call(base::Bind(&MyClass::Method, |
| 24 // base::Unretained(obj), |
| 25 // param); |
| 26 class TaskThreadProxy : public base::RefCountedThreadSafe<TaskThreadProxy> { |
| 27 public: |
| 28 TaskThreadProxy(MessageLoop* loop); |
| 29 |
| 30 // Detach should be called when the target of the posted task is being |
| 31 // destroyed. |
| 32 void Detach(); |
| 33 |
| 34 void Call(const base::Closure& closure); |
| 35 |
| 36 private: |
| 37 friend class base::RefCountedThreadSafe<TaskThreadProxy>; |
| 38 |
| 39 virtual ~TaskThreadProxy(); |
| 40 |
| 41 void CallClosure(const base::Closure& closure); |
| 42 |
| 43 MessageLoop* message_loop_; |
| 44 |
| 45 DISALLOW_COPY_AND_ASSIGN(TaskThreadProxy); |
| 46 }; |
| 47 |
| 48 } // namespace remoting |
| 49 |
| 50 #endif // REMOTING_BASE_TASK_THREAD_PROXY_H_ |
OLD | NEW |