|
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/. */ |
|
7 |
|
8 #ifndef mozilla_ipc_BrowserProcessSubThread_h |
|
9 #define mozilla_ipc_BrowserProcessSubThread_h |
|
10 |
|
11 #include "base/thread.h" |
|
12 #include "base/lock.h" |
|
13 |
|
14 #include "nsDebug.h" |
|
15 |
|
16 class NotificationService; |
|
17 |
|
18 namespace mozilla { |
|
19 namespace ipc { |
|
20 |
|
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 |
|
37 |
|
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 }; |
|
43 |
|
44 explicit BrowserProcessSubThread(ID aId); |
|
45 ~BrowserProcessSubThread(); |
|
46 |
|
47 static MessageLoop* GetMessageLoop(ID identifier); |
|
48 |
|
49 protected: |
|
50 virtual void Init(); |
|
51 virtual void CleanUp(); |
|
52 |
|
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; |
|
57 |
|
58 NotificationService* mNotificationService; |
|
59 |
|
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. |
|
62 |
|
63 // FIXME/cjones: XPCOM doesn't like static vars, so can't use |
|
64 // mozilla::Mutex |
|
65 static Lock sLock; |
|
66 |
|
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 }; |
|
73 |
|
74 inline void AssertIOThread() |
|
75 { |
|
76 NS_ASSERTION(MessageLoop::TYPE_IO == MessageLoop::current()->type(), |
|
77 "should be on the IO thread!"); |
|
78 } |
|
79 |
|
80 } // namespace ipc |
|
81 } // namespace mozilla |
|
82 |
|
83 #endif // mozilla_ipc_BrowserProcessSubThread_h |