Bug 1252998 - StorageActivityService - part 7 - StorageActivityService in QuotaManager, r=janv

This commit is contained in:
Andrea Marchesini 2018-04-18 18:19:13 +02:00
Родитель 013a32f315
Коммит e8bc84f98b
4 изменённых файлов: 51 добавлений и 1 удалений

Просмотреть файл

@ -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;
}

Просмотреть файл

@ -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

Просмотреть файл

@ -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<Runnable> r = NS_NewRunnableFunction(
"StorageActivityService::SendActivity",
[origin] () {
MOZ_ASSERT(NS_IsMainThread());
RefPtr<StorageActivityService> 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>
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();
}

Просмотреть файл

@ -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<StorageActivityService>
GetOrCreate();
@ -50,6 +54,9 @@ private:
void
SendActivityInternal(nsIPrincipal* aPrincipal);
void
SendActivityInternal(const nsACString& aOrigin);
void
SendActivityToParent(nsIPrincipal* aPrincipal);