diff --git a/dom/quota/ActorsParent.cpp b/dom/quota/ActorsParent.cpp index 0298fc4af97c..e31d631ff96c 100644 --- a/dom/quota/ActorsParent.cpp +++ b/dom/quota/ActorsParent.cpp @@ -36,6 +36,7 @@ #include "mozilla/dom/quota/PQuotaParent.h" #include "mozilla/dom/quota/PQuotaRequestParent.h" #include "mozilla/dom/quota/PQuotaUsageRequestParent.h" +#include "mozilla/dom/StorageActivityService.h" #include "mozilla/ipc/BackgroundParent.h" #include "mozilla/ipc/BackgroundUtils.h" #include "mozilla/IntegerRange.h" @@ -3025,6 +3026,11 @@ QuotaObject::LockedMaybeUpdateSize(int64_t aSize, bool aTruncate) quotaManager->mQuotaMutex.AssertCurrentThreadOwns(); + if (mWritingDone == false && mOriginInfo) { + mWritingDone = true; + StorageActivityService::SendActivity(mOriginInfo->mOrigin); + } + if (mQuotaCheckDisabled) { return true; } diff --git a/dom/quota/QuotaObject.h b/dom/quota/QuotaObject.h index fba31edbf2cf..2dfbd9667fe9 100644 --- a/dom/quota/QuotaObject.h +++ b/dom/quota/QuotaObject.h @@ -56,6 +56,7 @@ private: , mPath(aPath) , mSize(aSize) , mQuotaCheckDisabled(false) + , mWritingDone(false) { MOZ_COUNT_CTOR(QuotaObject); } @@ -86,6 +87,7 @@ private: int64_t mSize; bool mQuotaCheckDisabled; + bool mWritingDone; }; END_QUOTA_NAMESPACE diff --git a/dom/storage/StorageActivityService.cpp b/dom/storage/StorageActivityService.cpp index 9fe07382345b..edc56c133a13 100644 --- a/dom/storage/StorageActivityService.cpp +++ b/dom/storage/StorageActivityService.cpp @@ -64,6 +64,34 @@ StorageActivityService::SendActivity(const mozilla::ipc::PrincipalInfo& aPrincip SystemGroup::Dispatch(TaskCategory::Other, r.forget()); } +/* static */ void +StorageActivityService::SendActivity(const nsACString& aOrigin) +{ + MOZ_ASSERT(XRE_IsParentProcess()); + + nsCString origin; + origin.Assign(aOrigin); + + RefPtr r = NS_NewRunnableFunction( + "StorageActivityService::SendActivity", + [origin] () { + MOZ_ASSERT(NS_IsMainThread()); + + RefPtr service = GetOrCreate(); + if (NS_WARN_IF(!service)) { + return; + } + + service->SendActivityInternal(origin); + }); + + if (NS_IsMainThread()) { + Unused << r->Run(); + } else { + SystemGroup::Dispatch(TaskCategory::Other, r.forget()); + } +} + /* static */ already_AddRefed StorageActivityService::GetOrCreate() { @@ -118,8 +146,15 @@ StorageActivityService::SendActivityInternal(nsIPrincipal* aPrincipal) return; } - mActivities.Put(origin, PR_Now()); + SendActivityInternal(origin); +} +void +StorageActivityService::SendActivityInternal(const nsACString& aOrigin) +{ + MOZ_ASSERT(XRE_IsParentProcess()); + + mActivities.Put(aOrigin, PR_Now()); MaybeStartTimer(); } diff --git a/dom/storage/StorageActivityService.h b/dom/storage/StorageActivityService.h index 815831c72e54..84f2d303e5e7 100644 --- a/dom/storage/StorageActivityService.h +++ b/dom/storage/StorageActivityService.h @@ -39,6 +39,10 @@ public: static void SendActivity(const mozilla::ipc::PrincipalInfo& aPrincipalInfo); + // Thread-safe but for parent process only! + static void + SendActivity(const nsACString& aOrigin); + // Used by XPCOM. Don't use it, use SendActivity() instead. static already_AddRefed GetOrCreate(); @@ -50,6 +54,9 @@ private: void SendActivityInternal(nsIPrincipal* aPrincipal); + void + SendActivityInternal(const nsACString& aOrigin); + void SendActivityToParent(nsIPrincipal* aPrincipal);