ipc/glue/BrowserProcessSubThread.h

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

michael@0 1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
michael@0 2 * vim: sw=2 ts=8 et :
michael@0 3 */
michael@0 4 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 5 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 6 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 7
michael@0 8 #ifndef mozilla_ipc_BrowserProcessSubThread_h
michael@0 9 #define mozilla_ipc_BrowserProcessSubThread_h
michael@0 10
michael@0 11 #include "base/thread.h"
michael@0 12 #include "base/lock.h"
michael@0 13
michael@0 14 #include "nsDebug.h"
michael@0 15
michael@0 16 class NotificationService;
michael@0 17
michael@0 18 namespace mozilla {
michael@0 19 namespace ipc {
michael@0 20
michael@0 21 // Copied from browser_process_impl.cc, modified slightly.
michael@0 22 class BrowserProcessSubThread : public base::Thread
michael@0 23 {
michael@0 24 public:
michael@0 25 // An enumeration of the well-known threads.
michael@0 26 enum ID {
michael@0 27 IO,
michael@0 28 //FILE,
michael@0 29 //DB,
michael@0 30 //HISTORY,
michael@0 31 #if defined(OS_LINUX)
michael@0 32 // This thread has a second connection to the X server and is used
michael@0 33 // to process UI requests when routing the request to the UI
michael@0 34 // thread would risk deadlock.
michael@0 35 BACKGROUND_X11,
michael@0 36 #endif
michael@0 37
michael@0 38 // This identifier does not represent a thread. Instead it counts
michael@0 39 // the number of well-known threads. Insert new well-known
michael@0 40 // threads before this identifier.
michael@0 41 ID_COUNT
michael@0 42 };
michael@0 43
michael@0 44 explicit BrowserProcessSubThread(ID aId);
michael@0 45 ~BrowserProcessSubThread();
michael@0 46
michael@0 47 static MessageLoop* GetMessageLoop(ID identifier);
michael@0 48
michael@0 49 protected:
michael@0 50 virtual void Init();
michael@0 51 virtual void CleanUp();
michael@0 52
michael@0 53 private:
michael@0 54 // The identifier of this thread. Only one thread can exist with a given
michael@0 55 // identifier at a given time.
michael@0 56 ID mIdentifier;
michael@0 57
michael@0 58 NotificationService* mNotificationService;
michael@0 59
michael@0 60 // This lock protects |browser_threads_|. Do not read or modify that array
michael@0 61 // without holding this lock. Do not block while holding this lock.
michael@0 62
michael@0 63 // FIXME/cjones: XPCOM doesn't like static vars, so can't use
michael@0 64 // mozilla::Mutex
michael@0 65 static Lock sLock;
michael@0 66
michael@0 67 // An array of the ChromeThread objects. This array is protected by |lock_|.
michael@0 68 // The threads are not owned by this array. Typically, the threads are owned
michael@0 69 // on the UI thread by the g_browser_process object. ChromeThreads remove
michael@0 70 // themselves from this array upon destruction.
michael@0 71 static BrowserProcessSubThread* sBrowserThreads[ID_COUNT];
michael@0 72 };
michael@0 73
michael@0 74 inline void AssertIOThread()
michael@0 75 {
michael@0 76 NS_ASSERTION(MessageLoop::TYPE_IO == MessageLoop::current()->type(),
michael@0 77 "should be on the IO thread!");
michael@0 78 }
michael@0 79
michael@0 80 } // namespace ipc
michael@0 81 } // namespace mozilla
michael@0 82
michael@0 83 #endif // mozilla_ipc_BrowserProcessSubThread_h

mercurial