| 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/basictypes.h" | 10 #include "base/basictypes.h" |
| 11 #include "base/callback.h" | 11 #include "base/callback.h" |
| 12 #include "base/location.h" | 12 #include "base/location.h" |
| 13 #include "base/logging.h" | 13 #include "base/logging.h" |
| 14 #include "base/message_loop/message_loop_proxy.h" | 14 #include "base/single_thread_task_runner.h" |
| 15 #include "base/task_runner_util.h" | 15 #include "base/task_runner_util.h" |
| 16 #include "base/time/time.h" | 16 #include "base/time/time.h" |
| 17 #include "content/common/content_export.h" | 17 #include "content/common/content_export.h" |
| 18 | 18 |
| 19 namespace base { | 19 namespace base { |
| 20 class MessageLoop; | 20 class MessageLoop; |
| 21 class SequencedWorkerPool; | 21 class SequencedWorkerPool; |
| 22 class Thread; | 22 class Thread; |
| 23 } | 23 } |
| 24 | 24 |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 81 // This is the thread to handle slow HTTP cache operations. | 81 // This is the thread to handle slow HTTP cache operations. |
| 82 CACHE, | 82 CACHE, |
| 83 | 83 |
| 84 // This is the thread that processes non-blocking IO, i.e. IPC and network. | 84 // This is the thread that processes non-blocking IO, i.e. IPC and network. |
| 85 // Blocking IO should happen on other threads like DB, FILE, | 85 // Blocking IO should happen on other threads like DB, FILE, |
| 86 // FILE_USER_BLOCKING and CACHE depending on the usage. | 86 // FILE_USER_BLOCKING and CACHE depending on the usage. |
| 87 IO, | 87 IO, |
| 88 | 88 |
| 89 // NOTE: do not add new threads here that are only used by a small number of | 89 // NOTE: do not add new threads here that are only used by a small number of |
| 90 // files. Instead you should just use a Thread class and pass its | 90 // files. Instead you should just use a Thread class and pass its |
| 91 // MessageLoopProxy around. Named threads there are only for threads that | 91 // task runner around. Named threads there are only for threads that |
| 92 // are used in many places. | 92 // are used in many places. |
| 93 | 93 |
| 94 // This identifier does not represent a thread. Instead it counts the | 94 // This identifier does not represent a thread. Instead it counts the |
| 95 // number of well-known threads. Insert new well-known threads before this | 95 // number of well-known threads. Insert new well-known threads before this |
| 96 // identifier. | 96 // identifier. |
| 97 ID_COUNT | 97 ID_COUNT |
| 98 }; | 98 }; |
| 99 | 99 |
| 100 // These are the same methods in message_loop.h, but are guaranteed to either | 100 // These are the same methods in message_loop.h, but are guaranteed to either |
| 101 // get posted to the MessageLoop if it's still alive, or be deleted otherwise. | 101 // get posted to the MessageLoop if it's still alive, or be deleted otherwise. |
| (...skipping 21 matching lines...) Expand all Loading... |
| 123 const tracked_objects::Location& from_here, | 123 const tracked_objects::Location& from_here, |
| 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::MessageLoopProxy> message_loop_proxy = | 133 scoped_refptr<base::SingleThreadTaskRunner> task_runner = |
| 134 GetMessageLoopProxyForThread(identifier); | 134 GetMessageLoopProxyForThread(identifier); |
| 135 return base::PostTaskAndReplyWithResult( | 135 return base::PostTaskAndReplyWithResult(task_runner.get(), from_here, task, |
| 136 message_loop_proxy.get(), from_here, task, 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 GetMessageLoopProxyForThread(identifier)->DeleteSoon( |
| 144 from_here, object); | 144 from_here, object); |
| 145 } | 145 } |
| 146 | 146 |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 209 | 209 |
| 210 // Callable on any thread. Returns whether the threads message loop is valid. | 210 // Callable on any thread. Returns whether the threads message loop is valid. |
| 211 // If this returns false it means the thread is in the process of shutting | 211 // If this returns false it means the thread is in the process of shutting |
| 212 // down. | 212 // down. |
| 213 static bool IsMessageLoopValid(ID identifier) WARN_UNUSED_RESULT; | 213 static bool IsMessageLoopValid(ID identifier) WARN_UNUSED_RESULT; |
| 214 | 214 |
| 215 // If the current message loop is one of the known threads, returns true and | 215 // If the current message loop is one of the known threads, returns true and |
| 216 // sets identifier to its ID. Otherwise returns false. | 216 // sets identifier to its ID. Otherwise returns false. |
| 217 static bool GetCurrentThreadIdentifier(ID* identifier) WARN_UNUSED_RESULT; | 217 static bool GetCurrentThreadIdentifier(ID* identifier) WARN_UNUSED_RESULT; |
| 218 | 218 |
| 219 // Callers can hold on to a refcounted MessageLoopProxy beyond the lifetime | 219 // Callers can hold on to a refcounted task runner beyond the lifetime |
| 220 // of the thread. | 220 // of the thread. |
| 221 static scoped_refptr<base::MessageLoopProxy> GetMessageLoopProxyForThread( | 221 static scoped_refptr<base::SingleThreadTaskRunner> |
| 222 ID identifier); | 222 GetMessageLoopProxyForThread(ID identifier); |
| 223 | 223 |
| 224 // Returns a pointer to the thread's message loop, which will become | 224 // Returns a pointer to the thread's message loop, which will become |
| 225 // invalid during shutdown, so you probably shouldn't hold onto it. | 225 // invalid during shutdown, so you probably shouldn't hold onto it. |
| 226 // | 226 // |
| 227 // This must not be called before the thread is started, or after | 227 // This must not be called before the thread is started, or after |
| 228 // the thread is stopped, or it will DCHECK. | 228 // the thread is stopped, or it will DCHECK. |
| 229 // | 229 // |
| 230 // Ownership remains with the BrowserThread implementation, so you | 230 // Ownership remains with the BrowserThread implementation, so you |
| 231 // must not delete the pointer. | 231 // must not delete the pointer. |
| 232 static base::MessageLoop* UnsafeGetMessageLoopForThread(ID identifier); | 232 static base::MessageLoop* UnsafeGetMessageLoopForThread(ID identifier); |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 297 private: | 297 private: |
| 298 friend class BrowserThreadImpl; | 298 friend class BrowserThreadImpl; |
| 299 | 299 |
| 300 BrowserThread() {} | 300 BrowserThread() {} |
| 301 DISALLOW_COPY_AND_ASSIGN(BrowserThread); | 301 DISALLOW_COPY_AND_ASSIGN(BrowserThread); |
| 302 }; | 302 }; |
| 303 | 303 |
| 304 } // namespace content | 304 } // namespace content |
| 305 | 305 |
| 306 #endif // CONTENT_PUBLIC_BROWSER_BROWSER_THREAD_H_ | 306 #endif // CONTENT_PUBLIC_BROWSER_BROWSER_THREAD_H_ |
| OLD | NEW |