| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 CHROME_BROWSER_CHROME_THREAD_H_ | 5 #ifndef CHROME_BROWSER_CHROME_THREAD_H_ |
| 6 #define CHROME_BROWSER_CHROME_THREAD_H_ | 6 #define CHROME_BROWSER_CHROME_THREAD_H_ |
| 7 | 7 |
| 8 #include "base/lock.h" | 8 #include "base/lock.h" |
| 9 #include "base/task.h" | 9 #include "base/task.h" |
| 10 #include "base/thread.h" | 10 #include "base/thread.h" |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 114 // Callable on any thread. Returns whether you're currently on a particular | 114 // Callable on any thread. Returns whether you're currently on a particular |
| 115 // thread. | 115 // thread. |
| 116 // | 116 // |
| 117 // WARNING: | 117 // WARNING: |
| 118 // When running under unit-tests, this will return true if you're on the | 118 // When running under unit-tests, this will return true if you're on the |
| 119 // main thread and the thread ID you pass in isn't running. This is | 119 // main thread and the thread ID you pass in isn't running. This is |
| 120 // normally the correct behavior because you want to ignore these asserts | 120 // normally the correct behavior because you want to ignore these asserts |
| 121 // unless you've specifically spun up the threads, but be mindful of it. | 121 // unless you've specifically spun up the threads, but be mindful of it. |
| 122 static bool CurrentlyOn(ID identifier); | 122 static bool CurrentlyOn(ID identifier); |
| 123 | 123 |
| 124 // If the current message loop is one of the known threads, returns true and |
| 125 // sets identifier to its ID. Otherwise returns false. |
| 126 static bool GetCurrentThreadIdentifier(ID* identifier); |
| 127 |
| 124 private: | 128 private: |
| 125 // Common initialization code for the constructors. | 129 // Common initialization code for the constructors. |
| 126 void Initialize(); | 130 void Initialize(); |
| 127 | 131 |
| 128 // If the current message loop is one of the known threads, returns true and | |
| 129 // sets identifier to its ID. Otherwise returns false. | |
| 130 static bool GetCurrentThreadIdentifier(ID* identifier); | |
| 131 | |
| 132 static bool PostTaskHelper( | 132 static bool PostTaskHelper( |
| 133 ID identifier, | 133 ID identifier, |
| 134 const tracked_objects::Location& from_here, | 134 const tracked_objects::Location& from_here, |
| 135 Task* task, | 135 Task* task, |
| 136 int64 delay_ms, | 136 int64 delay_ms, |
| 137 bool nestable); | 137 bool nestable); |
| 138 | 138 |
| 139 // The identifier of this thread. Only one thread can exist with a given | 139 // The identifier of this thread. Only one thread can exist with a given |
| 140 // identifier at a given time. | 140 // identifier at a given time. |
| 141 ID identifier_; | 141 ID identifier_; |
| 142 | 142 |
| 143 // This lock protects |chrome_threads_|. Do not read or modify that array | 143 // This lock protects |chrome_threads_|. Do not read or modify that array |
| 144 // without holding this lock. Do not block while holding this lock. | 144 // without holding this lock. Do not block while holding this lock. |
| 145 static Lock lock_; | 145 static Lock lock_; |
| 146 | 146 |
| 147 // An array of the ChromeThread objects. This array is protected by |lock_|. | 147 // An array of the ChromeThread objects. This array is protected by |lock_|. |
| 148 // The threads are not owned by this array. Typically, the threads are owned | 148 // The threads are not owned by this array. Typically, the threads are owned |
| 149 // on the UI thread by the g_browser_process object. ChromeThreads remove | 149 // on the UI thread by the g_browser_process object. ChromeThreads remove |
| 150 // themselves from this array upon destruction. | 150 // themselves from this array upon destruction. |
| 151 static ChromeThread* chrome_threads_[ID_COUNT]; | 151 static ChromeThread* chrome_threads_[ID_COUNT]; |
| 152 }; | 152 }; |
| 153 | 153 |
| 154 #endif // #ifndef CHROME_BROWSER_CHROME_THREAD_H_ | 154 #endif // #ifndef CHROME_BROWSER_CHROME_THREAD_H_ |
| OLD | NEW |