Files
palemoon27/ipc/glue/MessagePump.h
T
roytam1 ef3af9173b import changes from `dev' branch of rmottola/Arctic-Fox:
- Bug 777067 - "Fuzzing: IPC Protocol Definition Language (IPDL) Protocols". r=wmccloskey (248c48ba96)
- Bug 1269056: Part 1 - Implement a rough PostDelayedTask equivalent on nsThread. r=froydnj (f9d8694b4d)
- Bug 1269056: Part 2 - Consolidate XPCOM and chromium event queues for non-main nsThreads. r=froydnj (14e156126b)
- Bug 1269056: Part 3 - Consolidate XPCOM and chromium event queues for the main thread. r=froydnj (90e5dabb4d)
- Bug 1271102 - Revert back to 256 MiB message limit. r=billm (d71cb26d74)
- Bug 950401 - Add process logging to OS X / BSD. r=bsmedberg (f3819e7f3b)
- Bug 1269319 - Make AlignedStorage/AlignedStorage2 non-copyable to fix strict aliasing issues. r=Waldo (d86ae927e1)
- Bug 1268754 - Tweak some MFBT return values. r=Ms2ger. (a71415c34e)
- Bug 1269317 - Don't use AlignedStorage2 in RegisterSets.h. r=nbp (f628be93a2)
- Bug 1269319 followup - Don't swap an entry with itself to avoid Variant self assignment. r=bustage (929bc926ca)
- mfbt: Alignment.h: partly disable changes of Bug 1269319 for VC2013 or older as they can't handle this. (253e78c5e6)
2024-10-09 07:22:03 +08:00

170 lines
3.5 KiB
C++

/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef __IPC_GLUE_MESSAGEPUMP_H__
#define __IPC_GLUE_MESSAGEPUMP_H__
#include "base/message_pump_default.h"
#if defined(XP_WIN)
#include "base/message_pump_win.h"
#endif
#include "base/time.h"
#include "mozilla/Attributes.h"
#include "mozilla/Mutex.h"
#include "nsAutoPtr.h"
#include "nsCOMPtr.h"
#include "nsIThreadInternal.h"
class nsIThread;
class nsITimer;
namespace mozilla {
namespace ipc {
class DoWorkRunnable;
class MessagePump : public base::MessagePumpDefault
{
friend class DoWorkRunnable;
public:
explicit MessagePump(nsIThread* aThread);
// From base::MessagePump.
virtual void
Run(base::MessagePump::Delegate* aDelegate) override;
// From base::MessagePump.
virtual void
ScheduleWork() override;
// From base::MessagePump.
virtual void
ScheduleWorkForNestedLoop() override;
// From base::MessagePump.
virtual void
ScheduleDelayedWork(const base::TimeTicks& aDelayedWorkTime) override;
virtual nsIEventTarget*
GetXPCOMThread() override;
protected:
virtual ~MessagePump();
private:
// Only called by DoWorkRunnable.
void DoDelayedWork(base::MessagePump::Delegate* aDelegate);
protected:
nsIThread* mThread;
// mDelayedWorkTimer and mThread are set in Run() by this class or its
// subclasses.
nsCOMPtr<nsITimer> mDelayedWorkTimer;
private:
// Only accessed by this class.
RefPtr<DoWorkRunnable> mDoWorkEvent;
};
class MessagePumpForChildProcess final: public MessagePump
{
public:
MessagePumpForChildProcess()
: MessagePump(nullptr),
mFirstRun(true)
{ }
virtual void Run(base::MessagePump::Delegate* aDelegate) override;
private:
~MessagePumpForChildProcess()
{ }
bool mFirstRun;
};
class MessagePumpForNonMainThreads final : public MessagePump
{
public:
explicit MessagePumpForNonMainThreads(nsIThread* aThread)
: MessagePump(aThread)
{ }
virtual void Run(base::MessagePump::Delegate* aDelegate) override;
private:
~MessagePumpForNonMainThreads()
{ }
};
#if defined(XP_WIN)
// Extends the TYPE_UI message pump to process xpcom events. Currently only
// implemented for Win.
class MessagePumpForNonMainUIThreads final:
public base::MessagePumpForUI,
public nsIThreadObserver
{
public:
// We don't want xpcom refing, chromium controls our lifetime via
// RefCountedThreadSafe.
NS_IMETHOD_(MozExternalRefCountType) AddRef(void) override {
return 2;
}
NS_IMETHOD_(MozExternalRefCountType) Release(void) override {
return 1;
}
NS_IMETHOD QueryInterface(REFNSIID aIID, void** aInstancePtr) override;
NS_DECL_NSITHREADOBSERVER
public:
explicit MessagePumpForNonMainUIThreads(nsIThread* aThread) :
mInWait(false),
mWaitLock("mInWait")
{
}
// The main run loop for this thread.
virtual void DoRunLoop() override;
virtual nsIEventTarget*
GetXPCOMThread() override
{
return nullptr; // not sure what to do with this one
}
protected:
void SetInWait() {
MutexAutoLock lock(mWaitLock);
mInWait = true;
}
void ClearInWait() {
MutexAutoLock lock(mWaitLock);
mInWait = false;
}
bool GetInWait() {
MutexAutoLock lock(mWaitLock);
return mInWait;
}
private:
~MessagePumpForNonMainUIThreads()
{
}
bool mInWait;
mozilla::Mutex mWaitLock;
};
#endif // defined(XP_WIN)
} /* namespace ipc */
} /* namespace mozilla */
#endif /* __IPC_GLUE_MESSAGEPUMP_H__ */