diff --git a/dom/cache/Context.cpp b/dom/cache/Context.cpp index 3f58742dbfa6..0818a232ebd1 100644 --- a/dom/cache/Context.cpp +++ b/dom/cache/Context.cpp @@ -786,19 +786,21 @@ already_AddRefed Context::Create(Manager* aManager, nsIThread* aTarget, Action* aInitAction, Context* aOldContext) { - nsRefPtr context = new Context(aManager, aTarget); - context->Init(aInitAction, aOldContext); + nsRefPtr context = new Context(aManager, aTarget, aInitAction); + context->Init(aOldContext); return context.forget(); } -Context::Context(Manager* aManager, nsIThread* aTarget) +Context::Context(Manager* aManager, nsIThread* aTarget, Action* aInitAction) : mManager(aManager) , mTarget(aTarget) , mData(new Data(aTarget)) , mState(STATE_CONTEXT_PREINIT) , mOrphanedData(false) + , mInitAction(aInitAction) { MOZ_ASSERT(mManager); + MOZ_ASSERT(mTarget); } void @@ -826,10 +828,11 @@ Context::CancelAll() { NS_ASSERT_OWNINGTHREAD(Context); - // In PREINIT state we have not dispatch the init runnable yet. Just + // In PREINIT state we have not dispatch the init action yet. Just // forget it. if (mState == STATE_CONTEXT_PREINIT) { - mInitRunnable = nullptr; + MOZ_ASSERT(!mInitRunnable); + mInitAction = nullptr; // In INIT state we have dispatched the runnable, but not received the // async completion yet. Cancel the runnable, but don't forget about it @@ -918,14 +921,9 @@ Context::~Context() } void -Context::Init(Action* aInitAction, Context* aOldContext) +Context::Init(Context* aOldContext) { NS_ASSERT_OWNINGTHREAD(Context); - MOZ_ASSERT(!mInitRunnable); - - // Do this here to avoid doing an AddRef() in the constructor - mInitRunnable = new QuotaInitRunnable(this, mManager, mData, mTarget, - aInitAction); if (aOldContext) { aOldContext->SetNextContext(this); @@ -944,10 +942,17 @@ Context::Start() // In this case, just do nothing here. if (mState == STATE_CONTEXT_CANCELED) { MOZ_ASSERT(!mInitRunnable); + MOZ_ASSERT(!mInitAction); return; } MOZ_ASSERT(mState == STATE_CONTEXT_PREINIT); + MOZ_ASSERT(!mInitRunnable); + + mInitRunnable = new QuotaInitRunnable(this, mManager, mData, mTarget, + mInitAction); + mInitAction = nullptr; + mState = STATE_CONTEXT_INIT; nsresult rv = mInitRunnable->Dispatch(); diff --git a/dom/cache/Context.h b/dom/cache/Context.h index 156dc605f421..e6300794d671 100644 --- a/dom/cache/Context.h +++ b/dom/cache/Context.h @@ -184,9 +184,9 @@ private: nsRefPtr mAction; }; - Context(Manager* aManager, nsIThread* aTarget); + Context(Manager* aManager, nsIThread* aTarget, Action* aInitAction); ~Context(); - void Init(Action* aInitAction, Context* aOldContext); + void Init(Context* aOldContext); void Start(); void DispatchAction(Action* aAction, bool aDoomData = false); void OnQuotaInit(nsresult aRv, const QuotaInfo& aQuotaInfo, @@ -208,6 +208,7 @@ private: bool mOrphanedData; QuotaInfo mQuotaInfo; nsRefPtr mInitRunnable; + nsRefPtr mInitAction; nsTArray mPendingActions; // Weak refs since activites must remove themselves from this list before