зеркало из https://github.com/mozilla/gecko-dev.git
Backed out changeset a2629286ed4c (bug 1151892)
This commit is contained in:
Родитель
a3cac582e2
Коммит
b08d4f66da
|
@ -732,7 +732,6 @@ Context::Dispatch(nsIEventTarget* aTarget, Action* aAction)
|
|||
MOZ_ASSERT(aTarget);
|
||||
MOZ_ASSERT(aAction);
|
||||
|
||||
MOZ_ASSERT(mState != STATE_CONTEXT_CANCELED);
|
||||
if (mState == STATE_CONTEXT_CANCELED) {
|
||||
return;
|
||||
} else if (mState == STATE_CONTEXT_INIT) {
|
||||
|
@ -767,18 +766,11 @@ Context::CancelAll()
|
|||
AllowToClose();
|
||||
}
|
||||
|
||||
bool
|
||||
Context::IsCanceled() const
|
||||
{
|
||||
NS_ASSERT_OWNINGTHREAD(Context);
|
||||
return mState == STATE_CONTEXT_CANCELED;
|
||||
}
|
||||
|
||||
void
|
||||
Context::Invalidate()
|
||||
{
|
||||
NS_ASSERT_OWNINGTHREAD(Context);
|
||||
mManager->NoteClosing();
|
||||
mManager->Invalidate();
|
||||
CancelAll();
|
||||
}
|
||||
|
||||
|
|
|
@ -126,9 +126,6 @@ public:
|
|||
// Only callable from the thread that created the Context.
|
||||
void CancelAll();
|
||||
|
||||
// True if CancelAll() has been called.
|
||||
bool IsCanceled() const;
|
||||
|
||||
// Like CancelAll(), but also marks the Manager as "invalid".
|
||||
void Invalidate();
|
||||
|
||||
|
|
|
@ -157,7 +157,6 @@ public:
|
|||
if (NS_WARN_IF(NS_FAILED(rv))) { return rv; }
|
||||
|
||||
ref = new Manager(aManagerId, ioThread);
|
||||
ref->Init();
|
||||
|
||||
MOZ_ASSERT(!sFactory->mManagerList.Contains(ref));
|
||||
sFactory->mManagerList.AppendElement(ref);
|
||||
|
@ -182,7 +181,7 @@ public:
|
|||
// If there is an invalid Manager finishing up and a new Manager
|
||||
// is created for the same origin, then the new Manager will
|
||||
// be blocked until QuotaManager finishes clearing the origin.
|
||||
if (!manager->IsClosing() && *manager->mManagerId == *aManagerId) {
|
||||
if (manager->IsValid() && *manager->mManagerId == *aManagerId) {
|
||||
return manager.forget();
|
||||
}
|
||||
}
|
||||
|
@ -1293,15 +1292,11 @@ public:
|
|||
if (!mManager->SetCacheIdOrphanedIfRefed(mCacheId)) {
|
||||
|
||||
// no outstanding references, delete immediately
|
||||
nsRefPtr<Context> context = mManager->mContext;
|
||||
|
||||
// TODO: note that we need to check this cache for staleness on startup (bug 1110446)
|
||||
if (!context->IsCanceled()) {
|
||||
context->CancelForCacheId(mCacheId);
|
||||
nsRefPtr<Action> action =
|
||||
new DeleteOrphanedCacheAction(mManager, mCacheId);
|
||||
context->Dispatch(mManager->mIOThread, action);
|
||||
}
|
||||
nsRefPtr<Context> context = mManager->CurrentContext();
|
||||
context->CancelForCacheId(mCacheId);
|
||||
nsRefPtr<Action> action =
|
||||
new DeleteOrphanedCacheAction(mManager, mCacheId);
|
||||
context->Dispatch(mManager->mIOThread, action);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1448,31 +1443,32 @@ Manager::RemoveContext(Context* aContext)
|
|||
MOZ_ASSERT(mContext == aContext);
|
||||
|
||||
// Whether the Context destruction was triggered from the Manager going
|
||||
// idle or the underlying storage being invalidated, we should know we
|
||||
// are closing before the Conext is destroyed.
|
||||
MOZ_ASSERT(mClosing);
|
||||
// idle or the underlying storage being invalidated, we should be invalid
|
||||
// when the context is destroyed.
|
||||
MOZ_ASSERT(!mValid);
|
||||
|
||||
mContext = nullptr;
|
||||
|
||||
// Once the context is gone, we can immediately remove ourself from the
|
||||
// Factory list. We don't need to block shutdown by staying in the list
|
||||
// any more.
|
||||
Factory::Remove(this);
|
||||
// If we're trying to shutdown, then note that we're done. This is the
|
||||
// delayed case from Manager::Shutdown().
|
||||
if (mShuttingDown) {
|
||||
Factory::Remove(this);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
Manager::NoteClosing()
|
||||
Manager::Invalidate()
|
||||
{
|
||||
NS_ASSERT_OWNINGTHREAD(Manager);
|
||||
// This can be called more than once legitimately through different paths.
|
||||
mClosing = true;
|
||||
// QuotaManager can trigger this more than once.
|
||||
mValid = false;
|
||||
}
|
||||
|
||||
bool
|
||||
Manager::IsClosing() const
|
||||
Manager::IsValid() const
|
||||
{
|
||||
NS_ASSERT_OWNINGTHREAD(Manager);
|
||||
return mClosing;
|
||||
return mValid;
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -1504,8 +1500,8 @@ Manager::ReleaseCacheId(CacheId aCacheId)
|
|||
bool orphaned = mCacheIdRefs[i].mOrphaned;
|
||||
mCacheIdRefs.RemoveElementAt(i);
|
||||
// TODO: note that we need to check this cache for staleness on startup (bug 1110446)
|
||||
nsRefPtr<Context> context = mContext;
|
||||
if (orphaned && context && !context->IsCanceled()) {
|
||||
if (orphaned && !mShuttingDown && mValid) {
|
||||
nsRefPtr<Context> context = CurrentContext();
|
||||
context->CancelForCacheId(aCacheId);
|
||||
nsRefPtr<Action> action = new DeleteOrphanedCacheAction(this,
|
||||
aCacheId);
|
||||
|
@ -1548,9 +1544,9 @@ Manager::ReleaseBodyId(const nsID& aBodyId)
|
|||
bool orphaned = mBodyIdRefs[i].mOrphaned;
|
||||
mBodyIdRefs.RemoveElementAt(i);
|
||||
// TODO: note that we need to check this body for staleness on startup (bug 1110446)
|
||||
nsRefPtr<Context> context = mContext;
|
||||
if (orphaned && context && !context->IsCanceled()) {
|
||||
if (orphaned && !mShuttingDown && mValid) {
|
||||
nsRefPtr<Action> action = new DeleteOrphanedBodyAction(aBodyId);
|
||||
nsRefPtr<Context> context = CurrentContext();
|
||||
context->Dispatch(mIOThread, action);
|
||||
}
|
||||
}
|
||||
|
@ -1593,14 +1589,12 @@ Manager::ExecuteCacheOp(Listener* aListener, CacheId aCacheId,
|
|||
MOZ_ASSERT(aOpArgs.type() != CacheOpArgs::TCacheAddAllArgs);
|
||||
MOZ_ASSERT(aOpArgs.type() != CacheOpArgs::TCachePutAllArgs);
|
||||
|
||||
if (mClosing) {
|
||||
if (mShuttingDown || !mValid) {
|
||||
aListener->OnOpComplete(NS_ERROR_FAILURE, void_t());
|
||||
return;
|
||||
}
|
||||
|
||||
nsRefPtr<Context> context = mContext;
|
||||
MOZ_ASSERT(!context->IsCanceled());
|
||||
|
||||
nsRefPtr<Context> context = CurrentContext();
|
||||
nsRefPtr<StreamList> streamList = new StreamList(this, context);
|
||||
ListenerId listenerId = SaveListener(aListener);
|
||||
|
||||
|
@ -1637,14 +1631,12 @@ Manager::ExecuteStorageOp(Listener* aListener, Namespace aNamespace,
|
|||
NS_ASSERT_OWNINGTHREAD(Manager);
|
||||
MOZ_ASSERT(aListener);
|
||||
|
||||
if (mClosing) {
|
||||
if (mShuttingDown || !mValid) {
|
||||
aListener->OnOpComplete(NS_ERROR_FAILURE, void_t());
|
||||
return;
|
||||
}
|
||||
|
||||
nsRefPtr<Context> context = mContext;
|
||||
MOZ_ASSERT(!context->IsCanceled());
|
||||
|
||||
nsRefPtr<Context> context = CurrentContext();
|
||||
nsRefPtr<StreamList> streamList = new StreamList(this, context);
|
||||
ListenerId listenerId = SaveListener(aListener);
|
||||
|
||||
|
@ -1686,14 +1678,12 @@ Manager::ExecutePutAll(Listener* aListener, CacheId aCacheId,
|
|||
NS_ASSERT_OWNINGTHREAD(Manager);
|
||||
MOZ_ASSERT(aListener);
|
||||
|
||||
if (mClosing) {
|
||||
if (mShuttingDown || !mValid) {
|
||||
aListener->OnOpComplete(NS_ERROR_FAILURE, CachePutAllResult());
|
||||
return;
|
||||
}
|
||||
|
||||
nsRefPtr<Context> context = mContext;
|
||||
MOZ_ASSERT(!context->IsCanceled());
|
||||
|
||||
nsRefPtr<Context> context = CurrentContext();
|
||||
ListenerId listenerId = SaveListener(aListener);
|
||||
|
||||
nsRefPtr<Action> action = new CachePutAllAction(this, listenerId, aCacheId,
|
||||
|
@ -1708,7 +1698,7 @@ Manager::Manager(ManagerId* aManagerId, nsIThread* aIOThread)
|
|||
, mIOThread(aIOThread)
|
||||
, mContext(nullptr)
|
||||
, mShuttingDown(false)
|
||||
, mClosing(false)
|
||||
, mValid(true)
|
||||
{
|
||||
MOZ_ASSERT(mManagerId);
|
||||
MOZ_ASSERT(mIOThread);
|
||||
|
@ -1717,8 +1707,8 @@ Manager::Manager(ManagerId* aManagerId, nsIThread* aIOThread)
|
|||
Manager::~Manager()
|
||||
{
|
||||
NS_ASSERT_OWNINGTHREAD(Manager);
|
||||
MOZ_ASSERT(mClosing);
|
||||
MOZ_ASSERT(!mContext);
|
||||
Shutdown();
|
||||
|
||||
nsCOMPtr<nsIThread> ioThread;
|
||||
mIOThread.swap(ioThread);
|
||||
|
@ -1730,19 +1720,6 @@ Manager::~Manager()
|
|||
MOZ_ALWAYS_TRUE(NS_SUCCEEDED(NS_DispatchToMainThread(runnable)));
|
||||
}
|
||||
|
||||
void
|
||||
Manager::Init()
|
||||
{
|
||||
NS_ASSERT_OWNINGTHREAD(Manager);
|
||||
|
||||
// Create the context immediately. Since there can at most be one Context
|
||||
// per Manager now, this lets us cleanly call Factory::Remove() once the
|
||||
// Context goes away.
|
||||
nsRefPtr<Action> setupAction = new SetupAction();
|
||||
nsRefPtr<Context> ref = Context::Create(this, setupAction);
|
||||
mContext = ref;
|
||||
}
|
||||
|
||||
void
|
||||
Manager::Shutdown()
|
||||
{
|
||||
|
@ -1754,20 +1731,37 @@ Manager::Shutdown()
|
|||
if (mShuttingDown) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Set a flag to prevent any new requests from coming in and creating
|
||||
// a new Context. We must ensure all Contexts and IO operations are
|
||||
// complete before shutdown proceeds.
|
||||
mShuttingDown = true;
|
||||
|
||||
// Note that we are closing to prevent any new requests from coming in and
|
||||
// creating a new Context. We must ensure all Contexts and IO operations are
|
||||
// complete before shutdown proceeds.
|
||||
NoteClosing();
|
||||
|
||||
// If there is a context, then cancel and only note that we are done after
|
||||
// its cleaned up.
|
||||
// If there is a context, then we must wait for it to complete. Cancel and
|
||||
// only note that we are done after its cleaned up.
|
||||
if (mContext) {
|
||||
nsRefPtr<Context> context = mContext;
|
||||
context->CancelAll();
|
||||
return;
|
||||
}
|
||||
|
||||
// Otherwise, note that we are complete immediately
|
||||
Factory::Remove(this);
|
||||
}
|
||||
|
||||
already_AddRefed<Context>
|
||||
Manager::CurrentContext()
|
||||
{
|
||||
NS_ASSERT_OWNINGTHREAD(Manager);
|
||||
nsRefPtr<Context> ref = mContext;
|
||||
if (!ref) {
|
||||
MOZ_ASSERT(!mShuttingDown);
|
||||
MOZ_ASSERT(mValid);
|
||||
nsRefPtr<Action> setupAction = new SetupAction();
|
||||
ref = Context::Create(this, setupAction);
|
||||
mContext = ref;
|
||||
}
|
||||
return ref.forget();
|
||||
}
|
||||
|
||||
Manager::ListenerId
|
||||
|
@ -1852,10 +1846,9 @@ Manager::NoteOrphanedBodyIdList(const nsTArray<nsID>& aDeletedBodyIdList)
|
|||
}
|
||||
}
|
||||
|
||||
// TODO: note that we need to check these bodies for staleness on startup (bug 1110446)
|
||||
nsRefPtr<Context> context = mContext;
|
||||
if (!deleteNowList.IsEmpty() && context && !context->IsCanceled()) {
|
||||
if (!deleteNowList.IsEmpty()) {
|
||||
nsRefPtr<Action> action = new DeleteOrphanedBodyAction(deleteNowList);
|
||||
nsRefPtr<Context> context = CurrentContext();
|
||||
context->Dispatch(mIOThread, action);
|
||||
}
|
||||
}
|
||||
|
@ -1870,17 +1863,16 @@ Manager::MaybeAllowContextToClose()
|
|||
// Cache state information to complete before doing this. Once we allow
|
||||
// the Context to close we may not reliably get notified of storage
|
||||
// invalidation.
|
||||
nsRefPtr<Context> context = mContext;
|
||||
if (context && mListeners.IsEmpty()
|
||||
&& mCacheIdRefs.IsEmpty()
|
||||
&& mBodyIdRefs.IsEmpty()) {
|
||||
if (mContext && mListeners.IsEmpty()
|
||||
&& mCacheIdRefs.IsEmpty()
|
||||
&& mBodyIdRefs.IsEmpty()) {
|
||||
|
||||
// Mark this Manager as invalid so that it won't get used again. We don't
|
||||
// want to start any new operations once we allow the Context to close since
|
||||
// it may race with the underlying storage getting invalidated.
|
||||
NoteClosing();
|
||||
mValid = false;
|
||||
|
||||
context->AllowToClose();
|
||||
mContext->AllowToClose();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -133,8 +133,8 @@ public:
|
|||
|
||||
// Marks the Manager "invalid". Once the Context completes no new operations
|
||||
// will be permitted with this Manager. New actors will get a new Manager.
|
||||
void NoteClosing();
|
||||
bool IsClosing() const;
|
||||
void Invalidate();
|
||||
bool IsValid() const;
|
||||
|
||||
// If an actor represents a long term reference to a cache or body stream,
|
||||
// then they must call AddRefCacheId() or AddRefBodyId(). This will
|
||||
|
@ -185,7 +185,6 @@ private:
|
|||
|
||||
Manager(ManagerId* aManagerId, nsIThread* aIOThread);
|
||||
~Manager();
|
||||
void Init();
|
||||
void Shutdown();
|
||||
already_AddRefed<Context> CurrentContext();
|
||||
|
||||
|
@ -249,7 +248,7 @@ private:
|
|||
nsTArray<StreamList*> mStreamLists;
|
||||
|
||||
bool mShuttingDown;
|
||||
bool mClosing;
|
||||
bool mValid;
|
||||
|
||||
struct CacheIdRefCounter
|
||||
{
|
||||
|
|
Загрузка…
Ссылка в новой задаче