Chromium Code Reviews| 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/message_loop/message_loop_proxy.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 #include "base/time/time.h" | 16 #include "base/time/time.h" |
| 16 #include "content/common/content_export.h" | 17 #include "content/common/content_export.h" |
| 17 | 18 |
| 18 #if defined(UNIT_TEST) | |
| 19 #include "base/logging.h" | |
| 20 #endif // UNIT_TEST | |
| 21 | |
| 22 namespace base { | 19 namespace base { |
| 23 class MessageLoop; | 20 class MessageLoop; |
| 24 class SequencedWorkerPool; | 21 class SequencedWorkerPool; |
| 25 class Thread; | 22 class Thread; |
| 26 } | 23 } |
| 27 | 24 |
| 28 namespace content { | 25 namespace content { |
| 29 | 26 |
| 30 class BrowserThreadDelegate; | 27 class BrowserThreadDelegate; |
| 31 class BrowserThreadImpl; | 28 class BrowserThreadImpl; |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 181 // Returns the thread pool used for blocking file I/O. Use this object to | 178 // Returns the thread pool used for blocking file I/O. Use this object to |
| 182 // perform random blocking operations such as file writes or querying the | 179 // perform random blocking operations such as file writes or querying the |
| 183 // Windows registry. | 180 // Windows registry. |
| 184 static base::SequencedWorkerPool* GetBlockingPool(); | 181 static base::SequencedWorkerPool* GetBlockingPool(); |
| 185 | 182 |
| 186 // Callable on any thread. Returns whether the given well-known thread is | 183 // Callable on any thread. Returns whether the given well-known thread is |
| 187 // initialized. | 184 // initialized. |
| 188 static bool IsThreadInitialized(ID identifier); | 185 static bool IsThreadInitialized(ID identifier); |
| 189 | 186 |
| 190 // Callable on any thread. Returns whether you're currently on a particular | 187 // Callable on any thread. Returns whether you're currently on a particular |
| 191 // thread. | 188 // thread. To DCHECK this, see the DCHECK_CURRENTLY_ON() macro below. |
| 192 static bool CurrentlyOn(ID identifier); | 189 static bool CurrentlyOn(ID identifier); |
| 193 | 190 |
| 194 // Callable on any thread. Returns whether the threads message loop is valid. | 191 // 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 | 192 // If this returns false it means the thread is in the process of shutting |
| 196 // down. | 193 // down. |
| 197 static bool IsMessageLoopValid(ID identifier); | 194 static bool IsMessageLoopValid(ID identifier); |
| 198 | 195 |
| 199 // If the current message loop is one of the known threads, returns true and | 196 // If the current message loop is one of the known threads, returns true and |
| 200 // sets identifier to its ID. Otherwise returns false. | 197 // sets identifier to its ID. Otherwise returns false. |
| 201 static bool GetCurrentThreadIdentifier(ID* identifier); | 198 static bool GetCurrentThreadIdentifier(ID* identifier); |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 259 // private: | 256 // private: |
| 260 // friend struct BrowserThread::DeleteOnThread<BrowserThread::IO>; | 257 // friend struct BrowserThread::DeleteOnThread<BrowserThread::IO>; |
| 261 // friend class base::DeleteHelper<Foo>; | 258 // friend class base::DeleteHelper<Foo>; |
| 262 // | 259 // |
| 263 // ~Foo(); | 260 // ~Foo(); |
| 264 struct DeleteOnUIThread : public DeleteOnThread<UI> { }; | 261 struct DeleteOnUIThread : public DeleteOnThread<UI> { }; |
| 265 struct DeleteOnIOThread : public DeleteOnThread<IO> { }; | 262 struct DeleteOnIOThread : public DeleteOnThread<IO> { }; |
| 266 struct DeleteOnFileThread : public DeleteOnThread<FILE> { }; | 263 struct DeleteOnFileThread : public DeleteOnThread<FILE> { }; |
| 267 struct DeleteOnDBThread : public DeleteOnThread<DB> { }; | 264 struct DeleteOnDBThread : public DeleteOnThread<DB> { }; |
| 268 | 265 |
| 266 // Returns an appropriate error message for when DCHECK_CURRENTLY_ON() fails. | |
| 267 static std::string GetDCheckCurrentlyOnErrorMessage(ID expected); | |
| 268 | |
| 269 private: | 269 private: |
| 270 friend class BrowserThreadImpl; | 270 friend class BrowserThreadImpl; |
| 271 | 271 |
| 272 BrowserThread() {} | 272 BrowserThread() {} |
| 273 DISALLOW_COPY_AND_ASSIGN(BrowserThread); | 273 DISALLOW_COPY_AND_ASSIGN(BrowserThread); |
| 274 }; | 274 }; |
| 275 | 275 |
| 276 #define DCHECK_CURRENTLY_ON(thread_identifier) \ | |
|
Jói
2014/03/11 08:41:25
nit: This would be more discoverable if placed at
Jeffrey Yasskin
2014/03/11 19:11:22
SG. Done, thanks.
| |
| 277 (DCHECK(::content::BrowserThread::CurrentlyOn(thread_identifier)) \ | |
| 278 << ::content::BrowserThread::GetDCheckCurrentlyOnErrorMessage( \ | |
| 279 thread_identifier)) | |
| 280 | |
| 276 } // namespace content | 281 } // namespace content |
| 277 | 282 |
| 278 #endif // CONTENT_PUBLIC_BROWSER_BROWSER_THREAD_H_ | 283 #endif // CONTENT_PUBLIC_BROWSER_BROWSER_THREAD_H_ |
| OLD | NEW |