| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 CONTENT_PUBLIC_BROWSER_BROWSER_THREAD_H_ | 5 #ifndef CONTENT_PUBLIC_BROWSER_BROWSER_THREAD_H_ |
| 6 #define CONTENT_PUBLIC_BROWSER_BROWSER_THREAD_H_ | 6 #define CONTENT_PUBLIC_BROWSER_BROWSER_THREAD_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/callback.h" | 10 #include "base/callback.h" |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 124 const base::Closure& task, | 124 const base::Closure& task, |
| 125 const base::Closure& reply); | 125 const base::Closure& reply); |
| 126 | 126 |
| 127 template <typename ReturnType, typename ReplyArgType> | 127 template <typename ReturnType, typename ReplyArgType> |
| 128 static bool PostTaskAndReplyWithResult( | 128 static bool PostTaskAndReplyWithResult( |
| 129 ID identifier, | 129 ID identifier, |
| 130 const tracked_objects::Location& from_here, | 130 const tracked_objects::Location& from_here, |
| 131 const base::Callback<ReturnType(void)>& task, | 131 const base::Callback<ReturnType(void)>& task, |
| 132 const base::Callback<void(ReplyArgType)>& reply) { | 132 const base::Callback<void(ReplyArgType)>& reply) { |
| 133 scoped_refptr<base::SingleThreadTaskRunner> task_runner = | 133 scoped_refptr<base::SingleThreadTaskRunner> task_runner = |
| 134 GetMessageLoopProxyForThread(identifier); | 134 GetTaskRunnerForThread(identifier); |
| 135 return base::PostTaskAndReplyWithResult(task_runner.get(), from_here, task, | 135 return base::PostTaskAndReplyWithResult(task_runner.get(), from_here, task, |
| 136 reply); | 136 reply); |
| 137 } | 137 } |
| 138 | 138 |
| 139 template <class T> | 139 template <class T> |
| 140 static bool DeleteSoon(ID identifier, | 140 static bool DeleteSoon(ID identifier, |
| 141 const tracked_objects::Location& from_here, | 141 const tracked_objects::Location& from_here, |
| 142 const T* object) { | 142 const T* object) { |
| 143 return GetMessageLoopProxyForThread(identifier)->DeleteSoon( | 143 return GetTaskRunnerForThread(identifier)->DeleteSoon(from_here, object); |
| 144 from_here, object); | |
| 145 } | 144 } |
| 146 | 145 |
| 147 template <class T> | 146 template <class T> |
| 148 static bool ReleaseSoon(ID identifier, | 147 static bool ReleaseSoon(ID identifier, |
| 149 const tracked_objects::Location& from_here, | 148 const tracked_objects::Location& from_here, |
| 150 const T* object) { | 149 const T* object) { |
| 151 return GetMessageLoopProxyForThread(identifier)->ReleaseSoon( | 150 return GetTaskRunnerForThread(identifier)->ReleaseSoon(from_here, object); |
| 152 from_here, object); | |
| 153 } | 151 } |
| 154 | 152 |
| 155 // Simplified wrappers for posting to the blocking thread pool. Use this | 153 // Simplified wrappers for posting to the blocking thread pool. Use this |
| 156 // for doing things like blocking I/O. | 154 // for doing things like blocking I/O. |
| 157 // | 155 // |
| 158 // The first variant will run the task in the pool with no sequencing | 156 // The first variant will run the task in the pool with no sequencing |
| 159 // semantics, so may get run in parallel with other posted tasks. The second | 157 // semantics, so may get run in parallel with other posted tasks. The second |
| 160 // variant will all post a task with no sequencing semantics, and will post a | 158 // variant will all post a task with no sequencing semantics, and will post a |
| 161 // reply task to the origin TaskRunner upon completion. The third variant | 159 // reply task to the origin TaskRunner upon completion. The third variant |
| 162 // provides sequencing between tasks with the same sequence token name. | 160 // provides sequencing between tasks with the same sequence token name. |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 211 // If this returns false it means the thread is in the process of shutting | 209 // If this returns false it means the thread is in the process of shutting |
| 212 // down. | 210 // down. |
| 213 static bool IsMessageLoopValid(ID identifier) WARN_UNUSED_RESULT; | 211 static bool IsMessageLoopValid(ID identifier) WARN_UNUSED_RESULT; |
| 214 | 212 |
| 215 // If the current message loop is one of the known threads, returns true and | 213 // If the current message loop is one of the known threads, returns true and |
| 216 // sets identifier to its ID. Otherwise returns false. | 214 // sets identifier to its ID. Otherwise returns false. |
| 217 static bool GetCurrentThreadIdentifier(ID* identifier) WARN_UNUSED_RESULT; | 215 static bool GetCurrentThreadIdentifier(ID* identifier) WARN_UNUSED_RESULT; |
| 218 | 216 |
| 219 // Callers can hold on to a refcounted task runner beyond the lifetime | 217 // Callers can hold on to a refcounted task runner beyond the lifetime |
| 220 // of the thread. | 218 // of the thread. |
| 221 static scoped_refptr<base::SingleThreadTaskRunner> | 219 static scoped_refptr<base::SingleThreadTaskRunner> GetTaskRunnerForThread( |
| 222 GetMessageLoopProxyForThread(ID identifier); | 220 ID identifier); |
| 223 | 221 |
| 224 // Returns a pointer to the thread's message loop, which will become | 222 // Returns a pointer to the thread's message loop, which will become |
| 225 // invalid during shutdown, so you probably shouldn't hold onto it. | 223 // invalid during shutdown, so you probably shouldn't hold onto it. |
| 226 // | 224 // |
| 227 // This must not be called before the thread is started, or after | 225 // This must not be called before the thread is started, or after |
| 228 // the thread is stopped, or it will DCHECK. | 226 // the thread is stopped, or it will DCHECK. |
| 229 // | 227 // |
| 230 // Ownership remains with the BrowserThread implementation, so you | 228 // Ownership remains with the BrowserThread implementation, so you |
| 231 // must not delete the pointer. | 229 // must not delete the pointer. |
| 232 static base::MessageLoop* UnsafeGetMessageLoopForThread(ID identifier); | 230 static base::MessageLoop* UnsafeGetMessageLoopForThread(ID identifier); |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 297 private: | 295 private: |
| 298 friend class BrowserThreadImpl; | 296 friend class BrowserThreadImpl; |
| 299 | 297 |
| 300 BrowserThread() {} | 298 BrowserThread() {} |
| 301 DISALLOW_COPY_AND_ASSIGN(BrowserThread); | 299 DISALLOW_COPY_AND_ASSIGN(BrowserThread); |
| 302 }; | 300 }; |
| 303 | 301 |
| 304 } // namespace content | 302 } // namespace content |
| 305 | 303 |
| 306 #endif // CONTENT_PUBLIC_BROWSER_BROWSER_THREAD_H_ | 304 #endif // CONTENT_PUBLIC_BROWSER_BROWSER_THREAD_H_ |
| OLD | NEW |