diff options
author | paul@chromium.org <paul@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-08-18 01:27:01 +0000 |
---|---|---|
committer | paul@chromium.org <paul@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-08-18 01:27:01 +0000 |
commit | 640579651b4a52f58d96db3a693274e3db47efda (patch) | |
tree | 169fb159248ba6d10d8393183ec0e912c269558a /chrome | |
parent | efd73788611d6060d46c0802d7de497539e9814c (diff) | |
download | chromium_src-640579651b4a52f58d96db3a693274e3db47efda.zip chromium_src-640579651b4a52f58d96db3a693274e3db47efda.tar.gz chromium_src-640579651b4a52f58d96db3a693274e3db47efda.tar.bz2 |
Add the UI thread to the list of ChromeThreads.
BUG=none
TEST=none
Review URL: http://codereview.chromium.org/171088
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@23605 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/browser/browser_main.cc | 4 | ||||
-rw-r--r-- | chrome/browser/chrome_thread.cc | 18 | ||||
-rw-r--r-- | chrome/browser/chrome_thread.h | 11 |
3 files changed, 31 insertions, 2 deletions
diff --git a/chrome/browser/browser_main.cc b/chrome/browser/browser_main.cc index c111478..b1fddf6 100644 --- a/chrome/browser/browser_main.cc +++ b/chrome/browser/browser_main.cc @@ -30,6 +30,7 @@ #include "chrome/browser/browser_process.h" #include "chrome/browser/browser_process_impl.h" #include "chrome/browser/browser_shutdown.h" +#include "chrome/browser/chrome_thread.h" #include "chrome/browser/dom_ui/chrome_url_data_manager.h" #include "chrome/browser/extensions/extension_protocols.h" #include "chrome/browser/first_run.h" @@ -322,6 +323,9 @@ int BrowserMain(const MainFunctionParams& parameters) { main_message_loop.set_thread_name(thread_name); bool already_running = Upgrade::IsBrowserAlreadyRunning(); + // Register the main thread by instantiating it, but don't call any methods. + ChromeThread main_thread; + FilePath user_data_dir; PathService::Get(chrome::DIR_USER_DATA, &user_data_dir); ProcessSingleton process_singleton(user_data_dir); diff --git a/chrome/browser/chrome_thread.cc b/chrome/browser/chrome_thread.cc index 4ef8480..2124c40 100644 --- a/chrome/browser/chrome_thread.cc +++ b/chrome/browser/chrome_thread.cc @@ -6,6 +6,7 @@ // Friendly names for the well-known threads. static const char* chrome_thread_names[ChromeThread::ID_COUNT] = { + "", // UI (name assembled in browser_main.cc). "Chrome_IOThread", // IO "Chrome_FileThread", // FILE "Chrome_DBThread", // DB @@ -19,6 +20,7 @@ static const char* chrome_thread_names[ChromeThread::ID_COUNT] = { Lock ChromeThread::lock_; ChromeThread* ChromeThread::chrome_threads_[ID_COUNT] = { + NULL, // UI NULL, // IO NULL, // FILE NULL, // DB @@ -32,9 +34,20 @@ ChromeThread* ChromeThread::chrome_threads_[ID_COUNT] = { ChromeThread::ChromeThread(ChromeThread::ID identifier) : Thread(chrome_thread_names[identifier]), identifier_(identifier) { + Initialize(); +} + +ChromeThread::ChromeThread() + : Thread(MessageLoop::current()->thread_name().c_str()), + identifier_(UI) { + set_message_loop(MessageLoop::current()); + Initialize(); +} + +void ChromeThread::Initialize() { AutoLock lock(lock_); - DCHECK(identifier >= 0 && identifier < ID_COUNT); - DCHECK(chrome_threads_[identifier] == NULL); + DCHECK(identifier_ >= 0 && identifier_ < ID_COUNT); + DCHECK(chrome_threads_[identifier_] == NULL); chrome_threads_[identifier_] = this; } @@ -63,3 +76,4 @@ bool ChromeThread::CurrentlyOn(ID identifier) { MessageLoop* message_loop = GetMessageLoop(identifier); return MessageLoop::current() == message_loop; } + diff --git a/chrome/browser/chrome_thread.h b/chrome/browser/chrome_thread.h index 4978214..db95512e 100644 --- a/chrome/browser/chrome_thread.h +++ b/chrome/browser/chrome_thread.h @@ -29,6 +29,9 @@ class ChromeThread : public base::Thread { public: // An enumeration of the well-known threads. enum ID { + // The main thread in the browser. + UI, + // This is the thread that processes IPC and network messages. IO, @@ -61,6 +64,11 @@ class ChromeThread : public base::Thread { // Construct a ChromeThread with the supplied identifier. It is an error // to construct a ChromeThread that already exists. explicit ChromeThread(ID identifier); + + // Special constructor for the main (UI) thread. We use a dummy thread here + // since the main thread already exists. + ChromeThread(); + virtual ~ChromeThread(); // Callable on any thread, this helper function returns a pointer to the @@ -83,6 +91,9 @@ class ChromeThread : public base::Thread { static bool CurrentlyOn(ID identifier); private: + // Common initialization code for the constructors. + void Initialize(); + // The identifier of this thread. Only one thread can exist with a given // identifier at a given time. ID identifier_; |