Bumping manifests a=b2g-bump
[gecko.git] / ipc / glue / MessagePump.h
blobff9ab38fad8f20eee872970979430b79fb798f8e
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"
9 #if defined(XP_WIN)
10 #include "base/message_pump_win.h"
11 #endif
13 #include "base/time.h"
14 #include "mozilla/Attributes.h"
15 #include "mozilla/Mutex.h"
16 #include "nsAutoPtr.h"
17 #include "nsCOMPtr.h"
18 #include "nsIThreadInternal.h"
20 class nsIThread;
21 class nsITimer;
23 namespace mozilla {
24 namespace ipc {
26 class DoWorkRunnable;
28 class MessagePump : public base::MessagePumpDefault
30 friend class DoWorkRunnable;
32 public:
33 MessagePump();
35 // From base::MessagePump.
36 virtual void
37 Run(base::MessagePump::Delegate* aDelegate) MOZ_OVERRIDE;
39 // From base::MessagePump.
40 virtual void
41 ScheduleWork() MOZ_OVERRIDE;
43 // From base::MessagePump.
44 virtual void
45 ScheduleWorkForNestedLoop() MOZ_OVERRIDE;
47 // From base::MessagePump.
48 virtual void
49 ScheduleDelayedWork(const base::TimeTicks& aDelayedWorkTime) MOZ_OVERRIDE;
51 protected:
52 virtual ~MessagePump();
54 private:
55 // Only called by DoWorkRunnable.
56 void DoDelayedWork(base::MessagePump::Delegate* aDelegate);
58 protected:
59 // mDelayedWorkTimer and mThread are set in Run() by this class or its
60 // subclasses.
61 nsCOMPtr<nsITimer> mDelayedWorkTimer;
62 nsIThread* mThread;
64 private:
65 // Only accessed by this class.
66 nsRefPtr<DoWorkRunnable> mDoWorkEvent;
69 class MessagePumpForChildProcess MOZ_FINAL: public MessagePump
71 public:
72 MessagePumpForChildProcess()
73 : mFirstRun(true)
74 { }
76 virtual void Run(base::MessagePump::Delegate* aDelegate) MOZ_OVERRIDE;
78 private:
79 ~MessagePumpForChildProcess()
80 { }
82 bool mFirstRun;
85 class MessagePumpForNonMainThreads MOZ_FINAL : public MessagePump
87 public:
88 MessagePumpForNonMainThreads()
89 { }
91 virtual void Run(base::MessagePump::Delegate* aDelegate) MOZ_OVERRIDE;
93 private:
94 ~MessagePumpForNonMainThreads()
95 { }
98 #if defined(XP_WIN)
99 // Extends the TYPE_UI message pump to process xpcom events. Currently only
100 // implemented for Win.
101 class MessagePumpForNonMainUIThreads MOZ_FINAL:
102 public base::MessagePumpForUI,
103 public nsIThreadObserver
105 public:
106 // We don't want xpcom refing, chromium controls our lifetime via
107 // RefCountedThreadSafe.
108 NS_IMETHOD_(MozExternalRefCountType) AddRef(void) {
109 return 2;
111 NS_IMETHOD_(MozExternalRefCountType) Release(void) {
112 return 1;
114 NS_IMETHOD QueryInterface(REFNSIID aIID, void** aInstancePtr);
116 NS_DECL_NSITHREADOBSERVER
118 public:
119 MessagePumpForNonMainUIThreads() :
120 mThread(nullptr),
121 mInWait(false),
122 mWaitLock("mInWait")
126 // The main run loop for this thread.
127 virtual void DoRunLoop();
129 protected:
130 nsIThread* mThread;
132 void SetInWait() {
133 MutexAutoLock lock(mWaitLock);
134 mInWait = true;
137 void ClearInWait() {
138 MutexAutoLock lock(mWaitLock);
139 mInWait = false;
142 bool GetInWait() {
143 MutexAutoLock lock(mWaitLock);
144 return mInWait;
147 private:
148 ~MessagePumpForNonMainUIThreads()
152 bool mInWait;
153 mozilla::Mutex mWaitLock;
155 #endif // defined(XP_WIN)
157 } /* namespace ipc */
158 } /* namespace mozilla */
160 #endif /* __IPC_GLUE_MESSAGEPUMP_H__ */