Bug 1125030 - Handle VsyncChild shutdown in ActorDestroy(). r=bent

This commit is contained in:
JerryShih
2015-01-29 22:19:00 +01:00
parent 01d4c273bc
commit 00c6a1afac
4 changed files with 25 additions and 8 deletions

View File

@@ -190,7 +190,10 @@ BackgroundChildImpl::DeallocPFileDescriptorSetChild(
BackgroundChildImpl::PVsyncChild* BackgroundChildImpl::PVsyncChild*
BackgroundChildImpl::AllocPVsyncChild() BackgroundChildImpl::AllocPVsyncChild()
{ {
return new mozilla::layout::VsyncChild(); nsRefPtr<mozilla::layout::VsyncChild> actor = new mozilla::layout::VsyncChild();
// There still has one ref-count after return, and it will be released in
// DeallocPVsyncChild().
return actor.forget().take();
} }
bool bool
@@ -198,7 +201,9 @@ BackgroundChildImpl::DeallocPVsyncChild(PVsyncChild* aActor)
{ {
MOZ_ASSERT(aActor); MOZ_ASSERT(aActor);
delete static_cast<mozilla::layout::VsyncChild*>(aActor); // This actor already has one ref-count. Please check AllocPVsyncChild().
nsRefPtr<mozilla::layout::VsyncChild> actor =
dont_AddRef(static_cast<mozilla::layout::VsyncChild*>(aActor));
return true; return true;
} }

View File

@@ -440,9 +440,13 @@ private:
Tick(vsyncJsNow, aTimeStamp); Tick(vsyncJsNow, aTimeStamp);
} }
nsRefPtr<RefreshTimerVsyncDispatcher> mVsyncDispatcher;
nsRefPtr<RefreshDriverVsyncObserver> mVsyncObserver; nsRefPtr<RefreshDriverVsyncObserver> mVsyncObserver;
VsyncChild* mVsyncChild; // Used for parent process.
nsRefPtr<RefreshTimerVsyncDispatcher> mVsyncDispatcher;
// Used for child process.
// The mVsyncChild will be always available before VsncChild::ActorDestroy().
// After ActorDestroy(), StartTimer() and StopTimer() calls will be non-op.
nsRefPtr<VsyncChild> mVsyncChild;
}; // VsyncRefreshDriverTimer }; // VsyncRefreshDriverTimer
/* /*

View File

@@ -13,6 +13,7 @@ namespace layout {
VsyncChild::VsyncChild() VsyncChild::VsyncChild()
: mObservingVsync(false) : mObservingVsync(false)
, mIsShutdown(false)
{ {
MOZ_ASSERT(NS_IsMainThread()); MOZ_ASSERT(NS_IsMainThread());
} }
@@ -26,9 +27,9 @@ bool
VsyncChild::SendObserve() VsyncChild::SendObserve()
{ {
MOZ_ASSERT(NS_IsMainThread()); MOZ_ASSERT(NS_IsMainThread());
if (!mObservingVsync) { if (!mObservingVsync && !mIsShutdown) {
PVsyncChild::SendObserve();
mObservingVsync = true; mObservingVsync = true;
PVsyncChild::SendObserve();
} }
return true; return true;
} }
@@ -37,9 +38,9 @@ bool
VsyncChild::SendUnobserve() VsyncChild::SendUnobserve()
{ {
MOZ_ASSERT(NS_IsMainThread()); MOZ_ASSERT(NS_IsMainThread());
if (mObservingVsync) { if (mObservingVsync && !mIsShutdown) {
PVsyncChild::SendUnobserve();
mObservingVsync = false; mObservingVsync = false;
PVsyncChild::SendUnobserve();
} }
return true; return true;
} }
@@ -48,6 +49,8 @@ void
VsyncChild::ActorDestroy(ActorDestroyReason aActorDestroyReason) VsyncChild::ActorDestroy(ActorDestroyReason aActorDestroyReason)
{ {
MOZ_ASSERT(NS_IsMainThread()); MOZ_ASSERT(NS_IsMainThread());
MOZ_ASSERT(!mIsShutdown);
mIsShutdown = true;
mObserver = nullptr; mObserver = nullptr;
} }
@@ -55,6 +58,7 @@ bool
VsyncChild::RecvNotify(const TimeStamp& aVsyncTimestamp) VsyncChild::RecvNotify(const TimeStamp& aVsyncTimestamp)
{ {
MOZ_ASSERT(NS_IsMainThread()); MOZ_ASSERT(NS_IsMainThread());
MOZ_ASSERT(!mIsShutdown);
if (mObservingVsync && mObserver) { if (mObservingVsync && mObserver) {
mObserver->NotifyVsync(aVsyncTimestamp); mObserver->NotifyVsync(aVsyncTimestamp);
} }

View File

@@ -7,6 +7,7 @@
#define mozilla_layout_ipc_VsyncChild_h #define mozilla_layout_ipc_VsyncChild_h
#include "mozilla/layout/PVsyncChild.h" #include "mozilla/layout/PVsyncChild.h"
#include "nsISupportsImpl.h"
#include "nsRefPtr.h" #include "nsRefPtr.h"
namespace mozilla { namespace mozilla {
@@ -25,6 +26,8 @@ namespace layout {
// PVsyncParent actor dies. // PVsyncParent actor dies.
class VsyncChild MOZ_FINAL : public PVsyncChild class VsyncChild MOZ_FINAL : public PVsyncChild
{ {
NS_INLINE_DECL_REFCOUNTING(VsyncChild)
friend class mozilla::ipc::BackgroundChildImpl; friend class mozilla::ipc::BackgroundChildImpl;
public: public:
@@ -44,6 +47,7 @@ private:
virtual void ActorDestroy(ActorDestroyReason aActorDestroyReason) MOZ_OVERRIDE; virtual void ActorDestroy(ActorDestroyReason aActorDestroyReason) MOZ_OVERRIDE;
bool mObservingVsync; bool mObservingVsync;
bool mIsShutdown;
// The content side vsync observer. // The content side vsync observer.
nsRefPtr<VsyncObserver> mObserver; nsRefPtr<VsyncObserver> mObserver;