| 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 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 106 template <class T> | 106 template <class T> |
| 107 static bool ReleaseSoon(ID identifier, | 107 static bool ReleaseSoon(ID identifier, |
| 108 const tracked_objects::Location& from_here, | 108 const tracked_objects::Location& from_here, |
| 109 T* object) { | 109 T* object) { |
| 110 return PostNonNestableTask( | 110 return PostNonNestableTask( |
| 111 identifier, from_here, new ReleaseTask<T>(object)); | 111 identifier, from_here, new ReleaseTask<T>(object)); |
| 112 } | 112 } |
| 113 | 113 |
| 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 // | |
| 117 // WARNING: | |
| 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 | |
| 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. | |
| 122 static bool CurrentlyOn(ID identifier); | 116 static bool CurrentlyOn(ID identifier); |
| 123 | 117 |
| 124 // If the current message loop is one of the known threads, returns true and | 118 // If the current message loop is one of the known threads, returns true and |
| 125 // sets identifier to its ID. Otherwise returns false. | 119 // sets identifier to its ID. Otherwise returns false. |
| 126 static bool GetCurrentThreadIdentifier(ID* identifier); | 120 static bool GetCurrentThreadIdentifier(ID* identifier); |
| 127 | 121 |
| 128 // Use these templates in conjuction with RefCountedThreadSafe when you want | 122 // Use these templates in conjuction with RefCountedThreadSafe when you want |
| 129 // to ensure that an object is deleted on a specific thread. This is needed | 123 // to ensure that an object is deleted on a specific thread. This is needed |
| 130 // when an object can hop between threads (i.e. IO -> FILE -> IO), and thread | 124 // when an object can hop between threads (i.e. IO -> FILE -> IO), and thread |
| 131 // switching delays can mean that the final IO tasks executes before the FILE | 125 // switching delays can mean that the final IO tasks executes before the FILE |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 174 static Lock lock_; | 168 static Lock lock_; |
| 175 | 169 |
| 176 // An array of the ChromeThread objects. This array is protected by |lock_|. | 170 // An array of the ChromeThread objects. This array is protected by |lock_|. |
| 177 // The threads are not owned by this array. Typically, the threads are owned | 171 // The threads are not owned by this array. Typically, the threads are owned |
| 178 // on the UI thread by the g_browser_process object. ChromeThreads remove | 172 // on the UI thread by the g_browser_process object. ChromeThreads remove |
| 179 // themselves from this array upon destruction. | 173 // themselves from this array upon destruction. |
| 180 static ChromeThread* chrome_threads_[ID_COUNT]; | 174 static ChromeThread* chrome_threads_[ID_COUNT]; |
| 181 }; | 175 }; |
| 182 | 176 |
| 183 #endif // #ifndef CHROME_BROWSER_CHROME_THREAD_H_ | 177 #endif // #ifndef CHROME_BROWSER_CHROME_THREAD_H_ |
| OLD | NEW |