| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 "Chrome_IOThread", // IO | 9 "Chrome_IOThread", // IO |
| 10 "Chrome_FileThread", // FILE | 10 "Chrome_FileThread", // FILE |
| 11 "Chrome_DBThread", // DB | 11 "Chrome_DBThread", // DB |
| 12 "Chrome_WebKitThread", // WEBKIT |
| 12 "Chrome_HistoryThread", // HISTORY | 13 "Chrome_HistoryThread", // HISTORY |
| 13 #if defined(OS_LINUX) | 14 #if defined(OS_LINUX) |
| 14 "Chrome_Background_X11Thread", // BACKGROUND_X11 | 15 "Chrome_Background_X11Thread", // BACKGROUND_X11 |
| 15 #endif | 16 #endif |
| 16 }; | 17 }; |
| 17 | 18 |
| 18 Lock ChromeThread::lock_; | 19 Lock ChromeThread::lock_; |
| 19 | 20 |
| 20 ChromeThread* ChromeThread::chrome_threads_[ID_COUNT] = { | 21 ChromeThread* ChromeThread::chrome_threads_[ID_COUNT] = { |
| 21 NULL, // IO | 22 NULL, // IO |
| 22 NULL, // FILE | 23 NULL, // FILE |
| 23 NULL, // DB | 24 NULL, // DB |
| 25 NULL, // WEBKIT |
| 24 NULL, // HISTORY | 26 NULL, // HISTORY |
| 25 #if defined(OS_LINUX) | 27 #if defined(OS_LINUX) |
| 26 NULL, // BACKGROUND_X11 | 28 NULL, // BACKGROUND_X11 |
| 27 #endif | 29 #endif |
| 28 }; | 30 }; |
| 29 | 31 |
| 30 ChromeThread::ChromeThread(ChromeThread::ID identifier) | 32 ChromeThread::ChromeThread(ChromeThread::ID identifier) |
| 31 : Thread(chrome_thread_names[identifier]), | 33 : Thread(chrome_thread_names[identifier]), |
| 32 identifier_(identifier) { | 34 identifier_(identifier) { |
| 33 AutoLock lock(lock_); | 35 AutoLock lock(lock_); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 44 // static | 46 // static |
| 45 MessageLoop* ChromeThread::GetMessageLoop(ID identifier) { | 47 MessageLoop* ChromeThread::GetMessageLoop(ID identifier) { |
| 46 AutoLock lock(lock_); | 48 AutoLock lock(lock_); |
| 47 DCHECK(identifier >= 0 && identifier < ID_COUNT); | 49 DCHECK(identifier >= 0 && identifier < ID_COUNT); |
| 48 | 50 |
| 49 if (chrome_threads_[identifier]) | 51 if (chrome_threads_[identifier]) |
| 50 return chrome_threads_[identifier]->message_loop(); | 52 return chrome_threads_[identifier]->message_loop(); |
| 51 | 53 |
| 52 return NULL; | 54 return NULL; |
| 53 } | 55 } |
| 56 |
| 57 // static |
| 58 bool ChromeThread::CurrentlyOn(ID identifier) { |
| 59 // MessageLoop::current() will return NULL if none is running. This is often |
| 60 // true when running under unit tests. This behavior actually works out |
| 61 // pretty convienently (as is mentioned in the header file comment), but it's |
| 62 // worth noting here. |
| 63 MessageLoop* message_loop = GetMessageLoop(identifier); |
| 64 return MessageLoop::current() == message_loop; |
| 65 } |
| OLD | NEW |