| 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 #include "chrome/browser/chrome_thread.h" | 5 #include "chrome/browser/chrome_thread.h" |
| 6 | 6 |
| 7 // Friendly names for the well-known threads. | 7 // Friendly names for the well-known threads. |
| 8 static const char* chrome_thread_names[ChromeThread::ID_COUNT] = { | 8 static const char* chrome_thread_names[ChromeThread::ID_COUNT] = { |
| 9 "", // UI (name assembled in browser_main.cc). | 9 "", // UI (name assembled in browser_main.cc). |
| 10 "Chrome_DBThread", // DB | 10 "Chrome_DBThread", // DB |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 47 // Double check that the threads are ordererd correctly in the enumeration. | 47 // Double check that the threads are ordererd correctly in the enumeration. |
| 48 for (int i = identifier_ + 1; i < ID_COUNT; ++i) { | 48 for (int i = identifier_ + 1; i < ID_COUNT; ++i) { |
| 49 DCHECK(!chrome_threads_[i]) << | 49 DCHECK(!chrome_threads_[i]) << |
| 50 "Threads must be listed in the reverse order that they die"; | 50 "Threads must be listed in the reverse order that they die"; |
| 51 } | 51 } |
| 52 #endif | 52 #endif |
| 53 } | 53 } |
| 54 | 54 |
| 55 // static | 55 // static |
| 56 bool ChromeThread::CurrentlyOn(ID identifier) { | 56 bool ChromeThread::CurrentlyOn(ID identifier) { |
| 57 // chrome_threads_[identifier] will be NULL if none is running. This is often | |
| 58 // true when running under unit tests. This behavior actually works out | |
| 59 // pretty conveniently but it's worth noting here. | |
| 60 AutoLock lock(lock_); | 57 AutoLock lock(lock_); |
| 61 DCHECK(identifier >= 0 && identifier < ID_COUNT); | 58 DCHECK(identifier >= 0 && identifier < ID_COUNT); |
| 62 return chrome_threads_[identifier] && | 59 return chrome_threads_[identifier] && |
| 63 chrome_threads_[identifier]->message_loop() == MessageLoop::current(); | 60 chrome_threads_[identifier]->message_loop() == MessageLoop::current(); |
| 64 } | 61 } |
| 65 | 62 |
| 66 // static | 63 // static |
| 67 bool ChromeThread::PostTask(ID identifier, | 64 bool ChromeThread::PostTask(ID identifier, |
| 68 const tracked_objects::Location& from_here, | 65 const tracked_objects::Location& from_here, |
| 69 Task* task) { | 66 Task* task) { |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 141 } | 138 } |
| 142 } else { | 139 } else { |
| 143 delete task; | 140 delete task; |
| 144 } | 141 } |
| 145 | 142 |
| 146 if (!guaranteed_to_outlive_target_thread) | 143 if (!guaranteed_to_outlive_target_thread) |
| 147 lock_.Release(); | 144 lock_.Release(); |
| 148 | 145 |
| 149 return !!message_loop; | 146 return !!message_loop; |
| 150 } | 147 } |
| OLD | NEW |