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 #pragma once | 7 #pragma once |
8 | 8 |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/callback.h" | 10 #include "base/callback.h" |
11 #include "base/message_loop_proxy.h" | 11 #include "base/message_loop_proxy.h" |
12 #include "base/tracked_objects.h" | 12 #include "base/tracked_objects.h" |
13 #include "content/common/content_export.h" | 13 #include "content/common/content_export.h" |
14 #include "content/public/browser/browser_thread_delegate.h" | 14 #include "content/public/browser/browser_thread_delegate.h" |
15 | 15 |
16 #if defined(UNIT_TEST) | 16 #if defined(UNIT_TEST) |
17 #include "base/logging.h" | 17 #include "base/logging.h" |
18 #endif // UNIT_TEST | 18 #endif // UNIT_TEST |
19 | 19 |
20 class MessageLoop; | 20 class MessageLoop; |
21 | 21 |
22 namespace base { | 22 namespace base { |
| 23 class SequencedWorkerPool; |
23 class Thread; | 24 class Thread; |
24 } | 25 } |
25 | 26 |
26 namespace content { | 27 namespace content { |
27 | 28 |
28 class BrowserThreadImpl; | 29 class BrowserThreadImpl; |
29 | 30 |
30 /////////////////////////////////////////////////////////////////////////////// | 31 /////////////////////////////////////////////////////////////////////////////// |
31 // BrowserThread | 32 // BrowserThread |
32 // | 33 // |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 } | 133 } |
133 | 134 |
134 template <class T> | 135 template <class T> |
135 static bool ReleaseSoon(ID identifier, | 136 static bool ReleaseSoon(ID identifier, |
136 const tracked_objects::Location& from_here, | 137 const tracked_objects::Location& from_here, |
137 const T* object) { | 138 const T* object) { |
138 return GetMessageLoopProxyForThread(identifier)->ReleaseSoon( | 139 return GetMessageLoopProxyForThread(identifier)->ReleaseSoon( |
139 from_here, object); | 140 from_here, object); |
140 } | 141 } |
141 | 142 |
| 143 // Simplified wrappers for posting to the blocking thread pool. Use this |
| 144 // for doing things like blocking I/O. |
| 145 // |
| 146 // The first variant will run the task in the pool with no sequencing |
| 147 // semantics, so may get run in parallel with other posted tasks. The |
| 148 // second variant provides sequencing between tasks with the same |
| 149 // sequence token name. |
| 150 // |
| 151 // These tasks are guaranteed to run before shutdown. |
| 152 // |
| 153 // If you need to provide different shutdown semantics (like you have |
| 154 // something slow and noncritical that doesn't need to block shutdown), |
| 155 // or you want to manually provide a sequence token (which saves a map |
| 156 // lookup and is guaranteed unique without you having to come up with a |
| 157 // unique string), you can access the sequenced worker pool directly via |
| 158 // GetBlockingPool(). |
| 159 static bool PostBlockingPoolTask(const tracked_objects::Location& from_here, |
| 160 const base::Closure& task); |
| 161 static bool PostBlockingPoolSequencedTask( |
| 162 const std::string& sequence_token_name, |
| 163 const tracked_objects::Location& from_here, |
| 164 const base::Closure& task); |
| 165 |
| 166 // Returns the thread pool used for blocking file I/O. Use this object to |
| 167 // perform random blocking operations such as file writes or querying the |
| 168 // Windows registry. |
| 169 static base::SequencedWorkerPool* GetBlockingPool(); |
| 170 |
142 // Callable on any thread. Returns whether the given ID corresponds to a well | 171 // Callable on any thread. Returns whether the given ID corresponds to a well |
143 // known thread. | 172 // known thread. |
144 static bool IsWellKnownThread(ID identifier); | 173 static bool IsWellKnownThread(ID identifier); |
145 | 174 |
146 // Callable on any thread. Returns whether you're currently on a particular | 175 // Callable on any thread. Returns whether you're currently on a particular |
147 // thread. | 176 // thread. |
148 static bool CurrentlyOn(ID identifier); | 177 static bool CurrentlyOn(ID identifier); |
149 | 178 |
150 // Callable on any thread. Returns whether the threads message loop is valid. | 179 // Callable on any thread. Returns whether the threads message loop is valid. |
151 // If this returns false it means the thread is in the process of shutting | 180 // If this returns false it means the thread is in the process of shutting |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
226 private: | 255 private: |
227 friend class BrowserThreadImpl; | 256 friend class BrowserThreadImpl; |
228 | 257 |
229 BrowserThread() {} | 258 BrowserThread() {} |
230 DISALLOW_COPY_AND_ASSIGN(BrowserThread); | 259 DISALLOW_COPY_AND_ASSIGN(BrowserThread); |
231 }; | 260 }; |
232 | 261 |
233 } // namespace content | 262 } // namespace content |
234 | 263 |
235 #endif // CONTENT_PUBLIC_BROWSER_BROWSER_THREAD_H_ | 264 #endif // CONTENT_PUBLIC_BROWSER_BROWSER_THREAD_H_ |
OLD | NEW |