1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 #ifndef __IPC_GLUE_MESSAGEPUMP_H__
6 #define __IPC_GLUE_MESSAGEPUMP_H__
8 #include "base/message_pump_default.h"
10 #include "base/message_pump_win.h"
13 #include "base/time.h"
14 #include "mozilla/Attributes.h"
15 #include "mozilla/Mutex.h"
16 #include "nsAutoPtr.h"
18 #include "nsIThreadInternal.h"
28 class MessagePump
: public base::MessagePumpDefault
30 friend class DoWorkRunnable
;
35 // From base::MessagePump.
37 Run(base::MessagePump::Delegate
* aDelegate
) override
;
39 // From base::MessagePump.
41 ScheduleWork() override
;
43 // From base::MessagePump.
45 ScheduleWorkForNestedLoop() override
;
47 // From base::MessagePump.
49 ScheduleDelayedWork(const base::TimeTicks
& aDelayedWorkTime
) override
;
52 virtual ~MessagePump();
55 // Only called by DoWorkRunnable.
56 void DoDelayedWork(base::MessagePump::Delegate
* aDelegate
);
59 // mDelayedWorkTimer and mThread are set in Run() by this class or its
61 nsCOMPtr
<nsITimer
> mDelayedWorkTimer
;
65 // Only accessed by this class.
66 nsRefPtr
<DoWorkRunnable
> mDoWorkEvent
;
69 class MessagePumpForChildProcess final
: public MessagePump
72 MessagePumpForChildProcess()
76 virtual void Run(base::MessagePump::Delegate
* aDelegate
) override
;
79 ~MessagePumpForChildProcess()
85 class MessagePumpForNonMainThreads final
: public MessagePump
88 MessagePumpForNonMainThreads()
91 virtual void Run(base::MessagePump::Delegate
* aDelegate
) override
;
94 ~MessagePumpForNonMainThreads()
99 // Extends the TYPE_UI message pump to process xpcom events. Currently only
100 // implemented for Win.
101 class MessagePumpForNonMainUIThreads final
:
102 public base::MessagePumpForUI
,
103 public nsIThreadObserver
106 // We don't want xpcom refing, chromium controls our lifetime via
107 // RefCountedThreadSafe.
108 NS_IMETHOD_(MozExternalRefCountType
) AddRef(void) {
111 NS_IMETHOD_(MozExternalRefCountType
) Release(void) {
114 NS_IMETHOD
QueryInterface(REFNSIID aIID
, void** aInstancePtr
);
116 NS_DECL_NSITHREADOBSERVER
119 MessagePumpForNonMainUIThreads() :
126 // The main run loop for this thread.
127 virtual void DoRunLoop();
133 MutexAutoLock
lock(mWaitLock
);
138 MutexAutoLock
lock(mWaitLock
);
143 MutexAutoLock
lock(mWaitLock
);
148 ~MessagePumpForNonMainUIThreads()
153 mozilla::Mutex mWaitLock
;
155 #endif // defined(XP_WIN)
157 } /* namespace ipc */
158 } /* namespace mozilla */
160 #endif /* __IPC_GLUE_MESSAGEPUMP_H__ */