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

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

mercurial