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 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
215 | 215 |
216 // If the current message loop is one of the known threads, returns true and | 216 // If the current message loop is one of the known threads, returns true and |
217 // sets identifier to its ID. Otherwise returns false. | 217 // sets identifier to its ID. Otherwise returns false. |
218 static bool GetCurrentThreadIdentifier(ID* identifier) WARN_UNUSED_RESULT; | 218 static bool GetCurrentThreadIdentifier(ID* identifier) WARN_UNUSED_RESULT; |
219 | 219 |
220 // Callers can hold on to a refcounted task runner beyond the lifetime | 220 // Callers can hold on to a refcounted task runner beyond the lifetime |
221 // of the thread. | 221 // of the thread. |
222 static scoped_refptr<base::SingleThreadTaskRunner> GetTaskRunnerForThread( | 222 static scoped_refptr<base::SingleThreadTaskRunner> GetTaskRunnerForThread( |
223 ID identifier); | 223 ID identifier); |
224 | 224 |
225 // Sets the delegate for the specified BrowserThread. | 225 // Sets the delegate for BrowserThread::IO. |
226 // | 226 // |
227 // Only one delegate may be registered at a time. Delegates may be | 227 // This only supports the IO thread as it doesn't work for potentially |
| 228 // redirected threads (ref. http://crbug.com/653916) and also doesn't make |
| 229 // sense for the UI thread. |
| 230 // |
| 231 // Only one delegate may be registered at a time. The delegate may be |
228 // unregistered by providing a nullptr pointer. | 232 // unregistered by providing a nullptr pointer. |
229 // | 233 // |
230 // If the caller unregisters a delegate before CleanUp has been | 234 // If the caller unregisters the delegate before CleanUp has been called, it |
231 // called, it must perform its own locking to ensure the delegate is | 235 // must perform its own locking to ensure the delegate is not deleted while |
232 // not deleted while unregistering. | 236 // unregistering. |
233 static void SetDelegate(ID identifier, BrowserThreadDelegate* delegate); | 237 static void SetIOThreadDelegate(BrowserThreadDelegate* delegate); |
234 | 238 |
235 // Use these templates in conjunction with RefCountedThreadSafe or scoped_ptr | 239 // Use these templates in conjunction with RefCountedThreadSafe or scoped_ptr |
236 // when you want to ensure that an object is deleted on a specific thread. | 240 // when you want to ensure that an object is deleted on a specific thread. |
237 // This is needed when an object can hop between threads | 241 // This is needed when an object can hop between threads |
238 // (i.e. IO -> FILE -> IO), and thread switching delays can mean that the | 242 // (i.e. IO -> FILE -> IO), and thread switching delays can mean that the |
239 // final IO tasks executes before the FILE task's stack unwinds. | 243 // final IO tasks executes before the FILE task's stack unwinds. |
240 // This would lead to the object destructing on the FILE thread, which often | 244 // This would lead to the object destructing on the FILE thread, which often |
241 // is not what you want (i.e. to unregister from NotificationService, to | 245 // is not what you want (i.e. to unregister from NotificationService, to |
242 // notify other objects on the creating thread etc). | 246 // notify other objects on the creating thread etc). |
243 template<ID thread> | 247 template<ID thread> |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
288 private: | 292 private: |
289 friend class BrowserThreadImpl; | 293 friend class BrowserThreadImpl; |
290 | 294 |
291 BrowserThread() {} | 295 BrowserThread() {} |
292 DISALLOW_COPY_AND_ASSIGN(BrowserThread); | 296 DISALLOW_COPY_AND_ASSIGN(BrowserThread); |
293 }; | 297 }; |
294 | 298 |
295 } // namespace content | 299 } // namespace content |
296 | 300 |
297 #endif // CONTENT_PUBLIC_BROWSER_BROWSER_THREAD_H_ | 301 #endif // CONTENT_PUBLIC_BROWSER_BROWSER_THREAD_H_ |
OLD | NEW |