michael@0: /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- michael@0: * vim: sw=2 ts=8 et : michael@0: */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef mozilla_ipc_BrowserProcessSubThread_h michael@0: #define mozilla_ipc_BrowserProcessSubThread_h michael@0: michael@0: #include "base/thread.h" michael@0: #include "base/lock.h" michael@0: michael@0: #include "nsDebug.h" michael@0: michael@0: class NotificationService; michael@0: michael@0: namespace mozilla { michael@0: namespace ipc { michael@0: michael@0: // Copied from browser_process_impl.cc, modified slightly. michael@0: class BrowserProcessSubThread : public base::Thread michael@0: { michael@0: public: michael@0: // An enumeration of the well-known threads. michael@0: enum ID { michael@0: IO, michael@0: //FILE, michael@0: //DB, michael@0: //HISTORY, michael@0: #if defined(OS_LINUX) michael@0: // This thread has a second connection to the X server and is used michael@0: // to process UI requests when routing the request to the UI michael@0: // thread would risk deadlock. michael@0: BACKGROUND_X11, michael@0: #endif michael@0: michael@0: // This identifier does not represent a thread. Instead it counts michael@0: // the number of well-known threads. Insert new well-known michael@0: // threads before this identifier. michael@0: ID_COUNT michael@0: }; michael@0: michael@0: explicit BrowserProcessSubThread(ID aId); michael@0: ~BrowserProcessSubThread(); michael@0: michael@0: static MessageLoop* GetMessageLoop(ID identifier); michael@0: michael@0: protected: michael@0: virtual void Init(); michael@0: virtual void CleanUp(); michael@0: michael@0: private: michael@0: // The identifier of this thread. Only one thread can exist with a given michael@0: // identifier at a given time. michael@0: ID mIdentifier; michael@0: michael@0: NotificationService* mNotificationService; michael@0: michael@0: // This lock protects |browser_threads_|. Do not read or modify that array michael@0: // without holding this lock. Do not block while holding this lock. michael@0: michael@0: // FIXME/cjones: XPCOM doesn't like static vars, so can't use michael@0: // mozilla::Mutex michael@0: static Lock sLock; michael@0: michael@0: // An array of the ChromeThread objects. This array is protected by |lock_|. michael@0: // The threads are not owned by this array. Typically, the threads are owned michael@0: // on the UI thread by the g_browser_process object. ChromeThreads remove michael@0: // themselves from this array upon destruction. michael@0: static BrowserProcessSubThread* sBrowserThreads[ID_COUNT]; michael@0: }; michael@0: michael@0: inline void AssertIOThread() michael@0: { michael@0: NS_ASSERTION(MessageLoop::TYPE_IO == MessageLoop::current()->type(), michael@0: "should be on the IO thread!"); michael@0: } michael@0: michael@0: } // namespace ipc michael@0: } // namespace mozilla michael@0: michael@0: #endif // mozilla_ipc_BrowserProcessSubThread_h