Bug 1363877 - Label IPC shmem messages as SystemGroup (r=dvander)

MozReview-Commit-ID: 3I5ny0wxVHI
This commit is contained in:
Bill McCloskey 2017-05-10 12:52:20 -07:00
parent 068699332f
commit 2f2e996bf5
4 changed files with 25 additions and 0 deletions

View File

@ -19,6 +19,7 @@
#include "mozilla/ipc/MessageChannel.h"
#include "mozilla/ipc/Transport.h"
#include "mozilla/StaticMutex.h"
#include "mozilla/SystemGroup.h"
#include "mozilla/Unused.h"
#include "nsPrintfCString.h"
@ -632,6 +633,7 @@ IToplevelProtocol::Open(mozilla::ipc::Transport* aTransport,
MessageLoop* aThread,
mozilla::ipc::Side aSide)
{
mIsMainThreadProtocol = NS_IsMainThread();
SetOtherProcessId(aOtherPid);
return GetIPCChannel()->Open(aTransport, aThread, aSide);
}
@ -641,6 +643,7 @@ IToplevelProtocol::Open(MessageChannel* aChannel,
MessageLoop* aMessageLoop,
mozilla::ipc::Side aSide)
{
mIsMainThreadProtocol = NS_IsMainThread();
SetOtherProcessId(base::GetCurrentProcId());
return GetIPCChannel()->Open(aChannel, aMessageLoop, aSide);
}
@ -815,6 +818,13 @@ IToplevelProtocol::ShmemDestroyed(const Message& aMsg)
already_AddRefed<nsIEventTarget>
IToplevelProtocol::GetMessageEventTarget(const Message& aMsg)
{
if (IsMainThreadProtocol() && SystemGroup::Initialized()) {
if (aMsg.type() == SHMEM_CREATED_MESSAGE_TYPE ||
aMsg.type() == SHMEM_DESTROYED_MESSAGE_TYPE) {
return do_AddRef(SystemGroup::EventTargetFor(TaskCategory::Other));
}
}
int32_t route = aMsg.routing_id();
Maybe<MutexAutoLock> lock;

View File

@ -386,6 +386,9 @@ public:
GetActorEventTarget();
virtual void OnChannelReceivedMessage(const Message& aMsg) {}
bool IsMainThreadProtocol() const { return mIsMainThreadProtocol; }
protected:
// Override this method in top-level protocols to change the event target
// for a new actor (and its sub-actors).
@ -413,6 +416,7 @@ protected:
int32_t mLastRouteId;
IDMap<Shmem::SharedMemory*> mShmemMap;
Shmem::id_t mLastShmemId;
bool mIsMainThreadProtocol;
Mutex mEventTargetMutex;
IDMap<nsCOMPtr<nsIEventTarget>> mEventTargetMap;

View File

@ -22,6 +22,8 @@ public:
static void ShutdownStatic();
static SystemGroupImpl* Get();
static bool Initialized() { return !!sSingleton; }
NS_METHOD_(MozExternalRefCountType) AddRef(void)
{
return 2;
@ -76,6 +78,12 @@ SystemGroup::Shutdown()
SystemGroupImpl::ShutdownStatic();
}
bool
SystemGroup::Initialized()
{
return SystemGroupImpl::Initialized();
}
/* static */ nsresult
SystemGroup::Dispatch(const char* aName,
TaskCategory aCategory,

View File

@ -34,6 +34,9 @@ class SystemGroup
static void InitStatic();
static void Shutdown();
// Returns true if SystemGroup has been initialized.
static bool Initialized();
};
} // namespace mozilla