1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/ipc/glue/BrowserProcessSubThread.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,83 @@ 1.4 +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- 1.5 + * vim: sw=2 ts=8 et : 1.6 + */ 1.7 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.8 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.9 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.10 + 1.11 +#ifndef mozilla_ipc_BrowserProcessSubThread_h 1.12 +#define mozilla_ipc_BrowserProcessSubThread_h 1.13 + 1.14 +#include "base/thread.h" 1.15 +#include "base/lock.h" 1.16 + 1.17 +#include "nsDebug.h" 1.18 + 1.19 +class NotificationService; 1.20 + 1.21 +namespace mozilla { 1.22 +namespace ipc { 1.23 + 1.24 +// Copied from browser_process_impl.cc, modified slightly. 1.25 +class BrowserProcessSubThread : public base::Thread 1.26 +{ 1.27 +public: 1.28 + // An enumeration of the well-known threads. 1.29 + enum ID { 1.30 + IO, 1.31 + //FILE, 1.32 + //DB, 1.33 + //HISTORY, 1.34 +#if defined(OS_LINUX) 1.35 + // This thread has a second connection to the X server and is used 1.36 + // to process UI requests when routing the request to the UI 1.37 + // thread would risk deadlock. 1.38 + BACKGROUND_X11, 1.39 +#endif 1.40 + 1.41 + // This identifier does not represent a thread. Instead it counts 1.42 + // the number of well-known threads. Insert new well-known 1.43 + // threads before this identifier. 1.44 + ID_COUNT 1.45 + }; 1.46 + 1.47 + explicit BrowserProcessSubThread(ID aId); 1.48 + ~BrowserProcessSubThread(); 1.49 + 1.50 + static MessageLoop* GetMessageLoop(ID identifier); 1.51 + 1.52 +protected: 1.53 + virtual void Init(); 1.54 + virtual void CleanUp(); 1.55 + 1.56 +private: 1.57 + // The identifier of this thread. Only one thread can exist with a given 1.58 + // identifier at a given time. 1.59 + ID mIdentifier; 1.60 + 1.61 + NotificationService* mNotificationService; 1.62 + 1.63 + // This lock protects |browser_threads_|. Do not read or modify that array 1.64 + // without holding this lock. Do not block while holding this lock. 1.65 + 1.66 + // FIXME/cjones: XPCOM doesn't like static vars, so can't use 1.67 + // mozilla::Mutex 1.68 + static Lock sLock; 1.69 + 1.70 + // An array of the ChromeThread objects. This array is protected by |lock_|. 1.71 + // The threads are not owned by this array. Typically, the threads are owned 1.72 + // on the UI thread by the g_browser_process object. ChromeThreads remove 1.73 + // themselves from this array upon destruction. 1.74 + static BrowserProcessSubThread* sBrowserThreads[ID_COUNT]; 1.75 +}; 1.76 + 1.77 +inline void AssertIOThread() 1.78 +{ 1.79 + NS_ASSERTION(MessageLoop::TYPE_IO == MessageLoop::current()->type(), 1.80 + "should be on the IO thread!"); 1.81 +} 1.82 + 1.83 +} // namespace ipc 1.84 +} // namespace mozilla 1.85 + 1.86 +#endif // mozilla_ipc_BrowserProcessSubThread_h