| 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; | |
| 24 class Thread; | 23 class Thread; |
| 25 } | 24 } |
| 26 | 25 |
| 27 namespace content { | 26 namespace content { |
| 28 | 27 |
| 29 class BrowserThreadImpl; | 28 class BrowserThreadImpl; |
| 30 | 29 |
| 31 /////////////////////////////////////////////////////////////////////////////// | 30 /////////////////////////////////////////////////////////////////////////////// |
| 32 // BrowserThread | 31 // BrowserThread |
| 33 // | 32 // |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 133 } | 132 } |
| 134 | 133 |
| 135 template <class T> | 134 template <class T> |
| 136 static bool ReleaseSoon(ID identifier, | 135 static bool ReleaseSoon(ID identifier, |
| 137 const tracked_objects::Location& from_here, | 136 const tracked_objects::Location& from_here, |
| 138 const T* object) { | 137 const T* object) { |
| 139 return GetMessageLoopProxyForThread(identifier)->ReleaseSoon( | 138 return GetMessageLoopProxyForThread(identifier)->ReleaseSoon( |
| 140 from_here, object); | 139 from_here, object); |
| 141 } | 140 } |
| 142 | 141 |
| 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 | |
| 171 // Callable on any thread. Returns whether the given ID corresponds to a well | 142 // Callable on any thread. Returns whether the given ID corresponds to a well |
| 172 // known thread. | 143 // known thread. |
| 173 static bool IsWellKnownThread(ID identifier); | 144 static bool IsWellKnownThread(ID identifier); |
| 174 | 145 |
| 175 // Callable on any thread. Returns whether you're currently on a particular | 146 // Callable on any thread. Returns whether you're currently on a particular |
| 176 // thread. | 147 // thread. |
| 177 static bool CurrentlyOn(ID identifier); | 148 static bool CurrentlyOn(ID identifier); |
| 178 | 149 |
| 179 // Callable on any thread. Returns whether the threads message loop is valid. | 150 // Callable on any thread. Returns whether the threads message loop is valid. |
| 180 // If this returns false it means the thread is in the process of shutting | 151 // 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... |
| 255 private: | 226 private: |
| 256 friend class BrowserThreadImpl; | 227 friend class BrowserThreadImpl; |
| 257 | 228 |
| 258 BrowserThread() {} | 229 BrowserThread() {} |
| 259 DISALLOW_COPY_AND_ASSIGN(BrowserThread); | 230 DISALLOW_COPY_AND_ASSIGN(BrowserThread); |
| 260 }; | 231 }; |
| 261 | 232 |
| 262 } // namespace content | 233 } // namespace content |
| 263 | 234 |
| 264 #endif // CONTENT_PUBLIC_BROWSER_BROWSER_THREAD_H_ | 235 #endif // CONTENT_PUBLIC_BROWSER_BROWSER_THREAD_H_ |
| OLD | NEW |