зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1168135 P1 Execute Cache init Action on same target thread used for other Actions. r=ehsan
This commit is contained in:
Родитель
bb41d221a3
Коммит
47b8771d37
|
@ -131,11 +131,13 @@ class Context::QuotaInitRunnable final : public nsIRunnable
|
|||
public:
|
||||
QuotaInitRunnable(Context* aContext,
|
||||
Manager* aManager,
|
||||
Action* aQuotaIOThreadAction)
|
||||
nsIThread* aTarget,
|
||||
Action* aInitAction)
|
||||
: mContext(aContext)
|
||||
, mThreadsafeHandle(aContext->CreateThreadsafeHandle())
|
||||
, mManager(aManager)
|
||||
, mQuotaIOThreadAction(aQuotaIOThreadAction)
|
||||
, mTarget(aTarget)
|
||||
, mInitAction(aInitAction)
|
||||
, mInitiatingThread(NS_GetCurrentThread())
|
||||
, mResult(NS_OK)
|
||||
, mState(STATE_INIT)
|
||||
|
@ -144,6 +146,7 @@ public:
|
|||
{
|
||||
MOZ_ASSERT(mContext);
|
||||
MOZ_ASSERT(mManager);
|
||||
MOZ_ASSERT(mTarget);
|
||||
MOZ_ASSERT(mInitiatingThread);
|
||||
}
|
||||
|
||||
|
@ -166,7 +169,7 @@ public:
|
|||
NS_ASSERT_OWNINGTHREAD(QuotaInitRunnable);
|
||||
MOZ_ASSERT(!mCanceled);
|
||||
mCanceled = true;
|
||||
mQuotaIOThreadAction->CancelOnInitiatingThread();
|
||||
mInitAction->CancelOnInitiatingThread();
|
||||
}
|
||||
|
||||
private:
|
||||
|
@ -202,7 +205,7 @@ private:
|
|||
{
|
||||
MOZ_ASSERT(mState == STATE_COMPLETE);
|
||||
MOZ_ASSERT(!mContext);
|
||||
MOZ_ASSERT(!mQuotaIOThreadAction);
|
||||
MOZ_ASSERT(!mInitAction);
|
||||
}
|
||||
|
||||
enum State
|
||||
|
@ -211,6 +214,7 @@ private:
|
|||
STATE_CALL_WAIT_FOR_OPEN_ALLOWED,
|
||||
STATE_WAIT_FOR_OPEN_ALLOWED,
|
||||
STATE_ENSURE_ORIGIN_INITIALIZED,
|
||||
STATE_RUN_ON_TARGET,
|
||||
STATE_RUNNING,
|
||||
STATE_COMPLETING,
|
||||
STATE_COMPLETE
|
||||
|
@ -222,13 +226,14 @@ private:
|
|||
MOZ_ASSERT(mContext);
|
||||
mContext = nullptr;
|
||||
mManager = nullptr;
|
||||
mQuotaIOThreadAction = nullptr;
|
||||
mInitAction = nullptr;
|
||||
}
|
||||
|
||||
nsRefPtr<Context> mContext;
|
||||
nsRefPtr<ThreadsafeHandle> mThreadsafeHandle;
|
||||
nsRefPtr<Manager> mManager;
|
||||
nsRefPtr<Action> mQuotaIOThreadAction;
|
||||
nsCOMPtr<nsIThread> mTarget;
|
||||
nsRefPtr<Action> mInitAction;
|
||||
nsCOMPtr<nsIThread> mInitiatingThread;
|
||||
nsresult mResult;
|
||||
QuotaInfo mQuotaInfo;
|
||||
|
@ -266,9 +271,14 @@ NS_IMPL_ISUPPORTS(mozilla::dom::cache::Context::QuotaInitRunnable, nsIRunnable);
|
|||
// | (Quota IO Thread) +----------------+
|
||||
// +----------+------------+ |
|
||||
// | |
|
||||
// +----------v------------+ |
|
||||
// | RunOnTarget | Resolve(error) |
|
||||
// | (Target Thread) +----------------+
|
||||
// +----------+------------+ |
|
||||
// | |
|
||||
// +---------v---------+ +------v------+
|
||||
// | Running | | Completing |
|
||||
// | (Quota IO Thread) +------------>(Orig Thread)|
|
||||
// | (Target Thread) +------------>(Orig Thread)|
|
||||
// +-------------------+ +------+------+
|
||||
// |
|
||||
// +-----v----+
|
||||
|
@ -384,16 +394,27 @@ Context::QuotaInitRunnable::Run()
|
|||
break;
|
||||
}
|
||||
|
||||
mState = STATE_RUNNING;
|
||||
|
||||
if (!mQuotaIOThreadAction) {
|
||||
if (!mInitAction) {
|
||||
resolver->Resolve(NS_OK);
|
||||
break;
|
||||
}
|
||||
|
||||
mState = STATE_RUN_ON_TARGET;
|
||||
|
||||
MOZ_ALWAYS_TRUE(NS_SUCCEEDED(
|
||||
mTarget->Dispatch(this, nsIThread::DISPATCH_NORMAL)));
|
||||
break;
|
||||
}
|
||||
// -------------------
|
||||
case STATE_RUN_ON_TARGET:
|
||||
{
|
||||
MOZ_ASSERT(NS_GetCurrentThread() == mTarget);
|
||||
|
||||
mState = STATE_RUNNING;
|
||||
|
||||
// Execute the provided initialization Action. The Action must Resolve()
|
||||
// before returning.
|
||||
mQuotaIOThreadAction->RunOnTarget(resolver, mQuotaInfo, nullptr);
|
||||
mInitAction->RunOnTarget(resolver, mQuotaInfo, nullptr);
|
||||
MOZ_ASSERT(resolver->Resolved());
|
||||
|
||||
break;
|
||||
|
@ -402,8 +423,8 @@ Context::QuotaInitRunnable::Run()
|
|||
case STATE_COMPLETING:
|
||||
{
|
||||
NS_ASSERT_OWNINGTHREAD(QuotaInitRunnable);
|
||||
if (mQuotaIOThreadAction) {
|
||||
mQuotaIOThreadAction->CompleteOnInitiatingThread(mResult);
|
||||
if (mInitAction) {
|
||||
mInitAction->CompleteOnInitiatingThread(mResult);
|
||||
}
|
||||
mContext->OnQuotaInit(mResult, mQuotaInfo, mOfflineStorage);
|
||||
mState = STATE_COMPLETE;
|
||||
|
@ -776,14 +797,14 @@ Context::ThreadsafeHandle::ContextDestroyed(Context* aContext)
|
|||
// static
|
||||
already_AddRefed<Context>
|
||||
Context::Create(Manager* aManager, nsIThread* aTarget,
|
||||
Action* aQuotaIOThreadAction, Context* aOldContext)
|
||||
Action* aInitAction, Context* aOldContext)
|
||||
{
|
||||
nsRefPtr<Context> context = new Context(aManager, aTarget);
|
||||
|
||||
// Do this here to avoid doing an AddRef() in the constructor
|
||||
// TODO: pass context->mData to allow connetion sharing with init
|
||||
context->mInitRunnable = new QuotaInitRunnable(context, aManager,
|
||||
aQuotaIOThreadAction);
|
||||
aTarget, aInitAction);
|
||||
|
||||
if (aOldContext) {
|
||||
aOldContext->SetNextContext(context);
|
||||
|
|
|
@ -112,7 +112,7 @@ public:
|
|||
// be execute synchronously.
|
||||
static already_AddRefed<Context>
|
||||
Create(Manager* aManager, nsIThread* aTarget,
|
||||
Action* aQuotaIOThreadAction, Context* aOldContext);
|
||||
Action* aInitAction, Context* aOldContext);
|
||||
|
||||
// Execute given action on the target once the quota manager has been
|
||||
// initialized.
|
||||
|
|
Загрузка…
Ссылка в новой задаче