| 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_H_ | 5 #ifndef BASE_MESSAGE_LOOP_PROXY_H_ |
| 6 #define BASE_MESSAGE_LOOP_PROXY_H_ | 6 #define BASE_MESSAGE_LOOP_PROXY_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include "base/base_export.h" | 9 #include "base/base_export.h" |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 60 const base::Closure& task) = 0; | 60 const base::Closure& task) = 0; |
| 61 virtual bool PostNonNestableDelayedTask( | 61 virtual bool PostNonNestableDelayedTask( |
| 62 const tracked_objects::Location& from_here, | 62 const tracked_objects::Location& from_here, |
| 63 const base::Closure& task, | 63 const base::Closure& task, |
| 64 int64 delay_ms) = 0; | 64 int64 delay_ms) = 0; |
| 65 | 65 |
| 66 // A method which checks if the caller is currently running in the thread that | 66 // A method which checks if the caller is currently running in the thread that |
| 67 // this proxy represents. | 67 // this proxy represents. |
| 68 virtual bool BelongsToCurrentThread() = 0; | 68 virtual bool BelongsToCurrentThread() = 0; |
| 69 | 69 |
| 70 // Executes |task| on the given MessageLoopProxy. On completion, |reply| |
| 71 // is passed back to the MessageLoopProxy for the thread that called |
| 72 // PostTaskAndReply(). |
| 73 // |
| 74 // Both |task| and |reply| are guaranteed to be deleted on the thread from |
| 75 // which PostTaskAndReply() is invoked. |
| 76 // |
| 77 // This simplifies logic when an operation needs to be executed on another |
| 78 // thread, but processing of the result needs to occur on the current thread. |
| 79 // |
| 80 // Note that because of the lifetime guarantees on the |reply| Closure, it is |
| 81 // perfectly valid to use a WeakPtr<> in the bound parameters for |reply|. |
| 82 // This is useful if |reply| needs to be canceled on the originating thread |
| 83 // while |task| may still be executing. |
| 84 bool PostTaskAndReply(const tracked_objects::Location& from_here, |
| 85 const Closure& task, |
| 86 const Closure& reply); |
| 87 |
| 70 template <class T> | 88 template <class T> |
| 71 bool DeleteSoon(const tracked_objects::Location& from_here, | 89 bool DeleteSoon(const tracked_objects::Location& from_here, |
| 72 T* object) { | 90 T* object) { |
| 73 return PostNonNestableTask(from_here, new DeleteTask<T>(object)); | 91 return PostNonNestableTask(from_here, new DeleteTask<T>(object)); |
| 74 } | 92 } |
| 75 template <class T> | 93 template <class T> |
| 76 bool ReleaseSoon(const tracked_objects::Location& from_here, | 94 bool ReleaseSoon(const tracked_objects::Location& from_here, |
| 77 T* object) { | 95 T* object) { |
| 78 return PostNonNestableTask(from_here, new ReleaseTask<T>(object)); | 96 return PostNonNestableTask(from_here, new ReleaseTask<T>(object)); |
| 79 } | 97 } |
| (...skipping 16 matching lines...) Expand all Loading... |
| 96 | 114 |
| 97 struct MessageLoopProxyTraits { | 115 struct MessageLoopProxyTraits { |
| 98 static void Destruct(const MessageLoopProxy* proxy) { | 116 static void Destruct(const MessageLoopProxy* proxy) { |
| 99 proxy->OnDestruct(); | 117 proxy->OnDestruct(); |
| 100 } | 118 } |
| 101 }; | 119 }; |
| 102 | 120 |
| 103 } // namespace base | 121 } // namespace base |
| 104 | 122 |
| 105 #endif // BASE_MESSAGE_LOOP_PROXY_H_ | 123 #endif // BASE_MESSAGE_LOOP_PROXY_H_ |
| OLD | NEW |