| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 IOS_WEB_PUBLIC_WEB_THREAD_H_ | 5 #ifndef IOS_WEB_PUBLIC_WEB_THREAD_H_ |
| 6 #define IOS_WEB_PUBLIC_WEB_THREAD_H_ | 6 #define IOS_WEB_PUBLIC_WEB_THREAD_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/callback_forward.h" | 10 #include "base/callback_forward.h" |
| 11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
| 12 #include "base/logging.h" | 12 #include "base/logging.h" |
| 13 #include "base/macros.h" | 13 #include "base/macros.h" |
| 14 #include "base/message_loop/message_loop_proxy.h" |
| 14 #include "base/task_runner_util.h" | 15 #include "base/task_runner_util.h" |
| 15 | 16 |
| 16 namespace base { | 17 namespace base { |
| 17 class MessageLoop; | 18 class MessageLoop; |
| 18 class SequencedWorkerPool; | 19 class SequencedWorkerPool; |
| 19 } | 20 } |
| 20 | 21 |
| 21 namespace tracked_objects { | 22 namespace tracked_objects { |
| 22 class Location; | 23 class Location; |
| 23 } | 24 } |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 // This is the thread to handle slow HTTP cache operations. | 77 // This is the thread to handle slow HTTP cache operations. |
| 77 CACHE, | 78 CACHE, |
| 78 | 79 |
| 79 // This is the thread that processes non-blocking IO, i.e. IPC and network. | 80 // This is the thread that processes non-blocking IO, i.e. IPC and network. |
| 80 // Blocking IO should happen on other threads like DB, FILE, | 81 // Blocking IO should happen on other threads like DB, FILE, |
| 81 // FILE_USER_BLOCKING and CACHE depending on the usage. | 82 // FILE_USER_BLOCKING and CACHE depending on the usage. |
| 82 IO, | 83 IO, |
| 83 | 84 |
| 84 // NOTE: do not add new threads here that are only used by a small number of | 85 // NOTE: do not add new threads here that are only used by a small number of |
| 85 // files. Instead you should just use a Thread class and pass its | 86 // files. Instead you should just use a Thread class and pass its |
| 86 // SingleThreadTaskRunner around. Named threads there are only for threads | 87 // MessageLoopProxy around. Named threads there are only for threads that |
| 87 // that are used in many places. | 88 // are used in many places. |
| 88 | 89 |
| 89 // This identifier does not represent a thread. Instead it counts the | 90 // This identifier does not represent a thread. Instead it counts the |
| 90 // number of well-known threads. Insert new well-known threads before this | 91 // number of well-known threads. Insert new well-known threads before this |
| 91 // identifier. | 92 // identifier. |
| 92 ID_COUNT | 93 ID_COUNT |
| 93 }; | 94 }; |
| 94 | 95 |
| 95 // These are the same methods as in message_loop.h, but are guaranteed to | 96 // These are the same methods as in message_loop.h, but are guaranteed to |
| 96 // either get posted to the MessageLoop if it's still alive, or be deleted | 97 // either get posted to the MessageLoop if it's still alive, or be deleted |
| 97 // otherwise. | 98 // otherwise. |
| (...skipping 18 matching lines...) Expand all Loading... |
| 116 const tracked_objects::Location& from_here, | 117 const tracked_objects::Location& from_here, |
| 117 const base::Closure& task, | 118 const base::Closure& task, |
| 118 const base::Closure& reply); | 119 const base::Closure& reply); |
| 119 | 120 |
| 120 template <typename ReturnType, typename ReplyArgType> | 121 template <typename ReturnType, typename ReplyArgType> |
| 121 static bool PostTaskAndReplyWithResult( | 122 static bool PostTaskAndReplyWithResult( |
| 122 ID identifier, | 123 ID identifier, |
| 123 const tracked_objects::Location& from_here, | 124 const tracked_objects::Location& from_here, |
| 124 const base::Callback<ReturnType(void)>& task, | 125 const base::Callback<ReturnType(void)>& task, |
| 125 const base::Callback<void(ReplyArgType)>& reply) { | 126 const base::Callback<void(ReplyArgType)>& reply) { |
| 126 scoped_refptr<base::SingleThreadTaskRunner> task_runner = | 127 scoped_refptr<base::MessageLoopProxy> message_loop_proxy = |
| 127 GetTaskRunnerForThread(identifier); | 128 GetMessageLoopProxyForThread(identifier); |
| 128 return base::PostTaskAndReplyWithResult(task_runner.get(), from_here, task, | 129 return base::PostTaskAndReplyWithResult(message_loop_proxy.get(), from_here, |
| 129 reply); | 130 task, reply); |
| 130 } | 131 } |
| 131 | 132 |
| 132 template <class T> | 133 template <class T> |
| 133 static bool DeleteSoon(ID identifier, | 134 static bool DeleteSoon(ID identifier, |
| 134 const tracked_objects::Location& from_here, | 135 const tracked_objects::Location& from_here, |
| 135 const T* object) { | 136 const T* object) { |
| 136 return GetTaskRunnerForThread(identifier)->DeleteSoon(from_here, object); | 137 return GetMessageLoopProxyForThread(identifier) |
| 138 ->DeleteSoon(from_here, object); |
| 137 } | 139 } |
| 138 | 140 |
| 139 // Simplified wrappers for posting to the blocking thread pool. Use this | 141 // Simplified wrappers for posting to the blocking thread pool. Use this |
| 140 // for doing things like blocking I/O. | 142 // for doing things like blocking I/O. |
| 141 // | 143 // |
| 142 // The first variant will run the task in the pool with no sequencing | 144 // The first variant will run the task in the pool with no sequencing |
| 143 // semantics, so may get run in parallel with other posted tasks. The second | 145 // semantics, so may get run in parallel with other posted tasks. The second |
| 144 // variant will all post a task with no sequencing semantics, and will post a | 146 // variant will all post a task with no sequencing semantics, and will post a |
| 145 // reply task to the origin TaskRunner upon completion. The third variant | 147 // reply task to the origin TaskRunner upon completion. The third variant |
| 146 // provides sequencing between tasks with the same sequence token name. | 148 // provides sequencing between tasks with the same sequence token name. |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 193 | 195 |
| 194 // Callable on any thread. Returns whether the threads message loop is valid. | 196 // Callable on any thread. Returns whether the threads message loop is valid. |
| 195 // If this returns false it means the thread is in the process of shutting | 197 // If this returns false it means the thread is in the process of shutting |
| 196 // down. | 198 // down. |
| 197 static bool IsMessageLoopValid(ID identifier) WARN_UNUSED_RESULT; | 199 static bool IsMessageLoopValid(ID identifier) WARN_UNUSED_RESULT; |
| 198 | 200 |
| 199 // If the current message loop is one of the known threads, returns true and | 201 // If the current message loop is one of the known threads, returns true and |
| 200 // sets identifier to its ID. | 202 // sets identifier to its ID. |
| 201 static bool GetCurrentThreadIdentifier(ID* identifier) WARN_UNUSED_RESULT; | 203 static bool GetCurrentThreadIdentifier(ID* identifier) WARN_UNUSED_RESULT; |
| 202 | 204 |
| 203 // Callers can hold on to a refcounted SingleThreadTaskRunner beyond the | 205 // Callers can hold on to a refcounted MessageLoopProxy beyond the lifetime |
| 204 // lifetime of the thread. | 206 // of the thread. |
| 205 static scoped_refptr<base::SingleThreadTaskRunner> GetTaskRunnerForThread( | 207 static scoped_refptr<base::MessageLoopProxy> GetMessageLoopProxyForThread( |
| 206 ID identifier); | 208 ID identifier); |
| 207 | 209 |
| 208 // Returns an appropriate error message for when | 210 // Returns an appropriate error message for when |
| 209 // DCHECK_CURRENTLY_ON_WEB_THREAD() fails. | 211 // DCHECK_CURRENTLY_ON_WEB_THREAD() fails. |
| 210 static std::string GetDCheckCurrentlyOnErrorMessage(ID expected); | 212 static std::string GetDCheckCurrentlyOnErrorMessage(ID expected); |
| 211 | 213 |
| 212 private: | 214 private: |
| 213 friend class WebThreadImpl; | 215 friend class WebThreadImpl; |
| 214 | 216 |
| 215 WebThread() {} | 217 WebThread() {} |
| 216 DISALLOW_COPY_AND_ASSIGN(WebThread); | 218 DISALLOW_COPY_AND_ASSIGN(WebThread); |
| 217 }; | 219 }; |
| 218 | 220 |
| 219 } // namespace web | 221 } // namespace web |
| 220 | 222 |
| 221 #endif // IOS_WEB_PUBLIC_WEB_THREAD_H_ | 223 #endif // IOS_WEB_PUBLIC_WEB_THREAD_H_ |
| OLD | NEW |