mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-17 15:25:52 +00:00
Part 6: Bug 1700623 - Add data querying to SessionStorageManager in parent process. r=nika,dom-storage-reviewers,asuth
To collect session storage data for session store, we make it possible to query the background session storage managar for data. Depends on D111432 Differential Revision: https://phabricator.services.mozilla.com/D111433
This commit is contained in:
parent
f39a2a4d60
commit
1e98905bd8
@ -5,6 +5,8 @@
|
||||
include protocol PBackground;
|
||||
include protocol PBackgroundSessionStorageManager;
|
||||
|
||||
include PBackgroundSharedTypes;
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
|
||||
@ -33,6 +35,13 @@ union SSWriteInfo
|
||||
SSClearInfo;
|
||||
};
|
||||
|
||||
struct SSCacheCopy {
|
||||
nsCString originKey;
|
||||
nsCString originAttributes;
|
||||
SSSetItemInfo[] defaultData;
|
||||
SSSetItemInfo[] sessionData;
|
||||
};
|
||||
|
||||
sync refcounted protocol PBackgroundSessionStorageCache
|
||||
{
|
||||
manager PBackgroundSessionStorageManager;
|
||||
|
@ -13,10 +13,15 @@
|
||||
#include "StorageUtils.h"
|
||||
#include "mozilla/ClearOnShutdown.h"
|
||||
#include "mozilla/OriginAttributes.h"
|
||||
#include "mozilla/PrincipalHashKey.h"
|
||||
#include "mozilla/StoragePrincipalHelper.h"
|
||||
#include "mozilla/dom/CanonicalBrowsingContext.h"
|
||||
#include "mozilla/dom/ContentChild.h"
|
||||
#include "mozilla/dom/LocalStorageCommon.h"
|
||||
#include "mozilla/dom/PBackgroundSessionStorageCache.h"
|
||||
#include "mozilla/dom/PBackgroundSessionStorageManager.h"
|
||||
#include "mozilla/dom/PermissionMessageUtils.h"
|
||||
#include "mozilla/dom/WindowGlobalParent.h"
|
||||
#include "mozilla/ipc/BackgroundChild.h"
|
||||
#include "mozilla/ipc/BackgroundParent.h"
|
||||
#include "mozilla/ipc/PBackgroundChild.h"
|
||||
@ -67,6 +72,30 @@ bool RecvRemoveBackgroundSessionStorageManager(uint64_t aTopContextId) {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool RecvGetSessionStorageData(
|
||||
uint64_t aTopContextId, uint32_t aSizeLimit,
|
||||
::mozilla::ipc::PBackgroundParent::GetSessionStorageManagerDataResolver&&
|
||||
aResolver) {
|
||||
nsTArray<mozilla::dom::SSCacheCopy> data;
|
||||
auto resolve = MakeScopeExit([&]() { aResolver(std::move(data)); });
|
||||
|
||||
if (!sManagers) {
|
||||
return true;
|
||||
}
|
||||
|
||||
RefPtr<BackgroundSessionStorageManager> manager =
|
||||
sManagers->Get(aTopContextId);
|
||||
if (!manager) {
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
manager->GetData(aSizeLimit, data);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
SessionStorageManagerBase::OriginRecord*
|
||||
SessionStorageManagerBase::GetOriginRecord(
|
||||
const nsACString& aOriginAttrs, const nsACString& aOriginKey,
|
||||
@ -662,6 +691,58 @@ void BackgroundSessionStorageManager::CopyDataToContentProcess(
|
||||
originRecord->mCache->SerializeData(SessionStorageCache::eSessionSetType);
|
||||
}
|
||||
|
||||
/* static */
|
||||
RefPtr<BackgroundSessionStorageManager::DataPromise>
|
||||
BackgroundSessionStorageManager::GetData(BrowsingContext* aContext,
|
||||
uint32_t aSizeLimit) {
|
||||
MOZ_ASSERT(XRE_IsParentProcess());
|
||||
MOZ_ASSERT(aContext->IsTop());
|
||||
|
||||
AssertIsOnMainThread();
|
||||
|
||||
::mozilla::ipc::PBackgroundChild* backgroundActor =
|
||||
::mozilla::ipc::BackgroundChild::GetOrCreateForCurrentThread();
|
||||
if (NS_WARN_IF(!backgroundActor)) {
|
||||
return DataPromise::CreateAndReject(
|
||||
::mozilla::ipc::ResponseRejectReason::SendError, __func__);
|
||||
}
|
||||
|
||||
return backgroundActor->SendGetSessionStorageManagerData(
|
||||
aContext->Id(), aSizeLimit, aClearSessionStoreTimer);
|
||||
}
|
||||
|
||||
void BackgroundSessionStorageManager::GetData(
|
||||
uint32_t aSizeLimit, nsTArray<SSCacheCopy>& aCacheCopyList) {
|
||||
for (auto attributesIter = mOATable.ConstIter(); !attributesIter.Done();
|
||||
attributesIter.Next()) {
|
||||
for (auto originIter = attributesIter.UserData()->ConstIter();
|
||||
!originIter.Done(); originIter.Next()) {
|
||||
const auto& cache = originIter.UserData()->mCache;
|
||||
int64_t size =
|
||||
cache->GetOriginQuotaUsage(SessionStorageCache::eDefaultSetType) +
|
||||
cache->GetOriginQuotaUsage(SessionStorageCache::eSessionSetType);
|
||||
if (size > aSizeLimit) {
|
||||
continue;
|
||||
}
|
||||
|
||||
nsTArray<SSSetItemInfo> defaultData =
|
||||
cache->SerializeData(SessionStorageCache::eDefaultSetType);
|
||||
nsTArray<SSSetItemInfo> sessionData =
|
||||
cache->SerializeData(SessionStorageCache::eSessionSetType);
|
||||
|
||||
if (defaultData.IsEmpty() && sessionData.IsEmpty()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
SSCacheCopy& cacheCopy = *aCacheCopyList.AppendElement();
|
||||
cacheCopy.originKey() = originIter.Key();
|
||||
cacheCopy.originAttributes() = attributesIter.Key();
|
||||
cacheCopy.defaultData().SwapElements(defaultData);
|
||||
cacheCopy.sessionData().SwapElements(sessionData);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void BackgroundSessionStorageManager::UpdateData(
|
||||
const nsACString& aOriginAttrs, const nsACString& aOriginKey,
|
||||
const nsTArray<SSWriteInfo>& aDefaultWriteInfos,
|
||||
|
@ -15,6 +15,11 @@
|
||||
#include "nsCycleCollectionParticipant.h"
|
||||
#include "nsHashKeys.h"
|
||||
|
||||
#include "mozilla/ipc/PBackgroundChild.h"
|
||||
#include "mozilla/ipc/PBackgroundParent.h"
|
||||
|
||||
class nsIPrincipal;
|
||||
|
||||
namespace mozilla {
|
||||
class OriginAttributesPattern;
|
||||
|
||||
@ -25,6 +30,11 @@ void RecvPropagateBackgroundSessionStorageManager(uint64_t aCurrentTopContextId,
|
||||
uint64_t aTargetTopContextId);
|
||||
bool RecvRemoveBackgroundSessionStorageManager(uint64_t aTopContextId);
|
||||
|
||||
bool RecvGetSessionStorageData(
|
||||
uint64_t aTopContextId, uint32_t aSizeLimit,
|
||||
::mozilla::ipc::PBackgroundParent::GetSessionStorageManagerDataResolver&&
|
||||
aResolver);
|
||||
|
||||
class BrowsingContext;
|
||||
class ContentParent;
|
||||
class SSSetItemInfo;
|
||||
@ -169,6 +179,13 @@ class BackgroundSessionStorageManager final : public SessionStorageManagerBase {
|
||||
// process.
|
||||
static void RemoveManager(uint64_t aTopContextId);
|
||||
|
||||
using DataPromise =
|
||||
::mozilla::ipc::PBackgroundChild::GetSessionStorageManagerDataPromise;
|
||||
static RefPtr<DataPromise> GetData(BrowsingContext* aContext,
|
||||
uint32_t aSizeLimit);
|
||||
|
||||
void GetData(uint32_t aSizeLimit, nsTArray<SSCacheCopy>& aCacheCopyList);
|
||||
|
||||
void CopyDataToContentProcess(const nsACString& aOriginAttrs,
|
||||
const nsACString& aOriginKey,
|
||||
nsTArray<SSSetItemInfo>& aDefaultData,
|
||||
|
@ -69,6 +69,7 @@
|
||||
#include "mozilla/net/BackgroundDataBridgeParent.h"
|
||||
#include "mozilla/net/HttpBackgroundChannelParent.h"
|
||||
#include "mozilla/psm/VerifySSLServerCertParent.h"
|
||||
#include "nsIPrincipal.h"
|
||||
#include "nsNetUtil.h"
|
||||
#include "nsProxyRelease.h"
|
||||
#include "nsThreadUtils.h"
|
||||
@ -1139,6 +1140,24 @@ BackgroundParentImpl::RecvRemoveBackgroundSessionStorageManager(
|
||||
return IPC_OK();
|
||||
}
|
||||
|
||||
mozilla::ipc::IPCResult BackgroundParentImpl::RecvGetSessionStorageManagerData(
|
||||
const uint64_t& aTopContextId, const uint32_t& aSizeLimit,
|
||||
GetSessionStorageManagerDataResolver&& aResolver) {
|
||||
AssertIsInMainProcess();
|
||||
AssertIsOnBackgroundThread();
|
||||
|
||||
if (BackgroundParent::IsOtherProcessActor(this)) {
|
||||
return IPC_FAIL(this, "Wrong actor");
|
||||
}
|
||||
|
||||
if (!mozilla::dom::RecvGetSessionStorageData(aTopContextId, aSizeLimit,
|
||||
std::move(aResolver))) {
|
||||
return IPC_FAIL(this, "Couldn't get session storage data");
|
||||
}
|
||||
|
||||
return IPC_OK();
|
||||
}
|
||||
|
||||
already_AddRefed<dom::PFileSystemRequestParent>
|
||||
BackgroundParentImpl::AllocPFileSystemRequestParent(
|
||||
const FileSystemParams& aParams) {
|
||||
|
@ -318,6 +318,10 @@ class BackgroundParentImpl : public PBackgroundParent,
|
||||
mozilla::ipc::IPCResult RecvRemoveBackgroundSessionStorageManager(
|
||||
const uint64_t& aTopContextId) override;
|
||||
|
||||
mozilla::ipc::IPCResult RecvGetSessionStorageManagerData(
|
||||
const uint64_t& aTopContextId, const uint32_t& aSizeLimit,
|
||||
GetSessionStorageManagerDataResolver&& aResolver) override;
|
||||
|
||||
already_AddRefed<PFileSystemRequestParent> AllocPFileSystemRequestParent(
|
||||
const FileSystemParams&) override;
|
||||
|
||||
|
@ -66,11 +66,14 @@ include MIDITypes;
|
||||
|
||||
include "mozilla/dom/cache/IPCUtils.h";
|
||||
include "mozilla/dom/quota/SerializationHelpers.h";
|
||||
include "mozilla/dom/PermissionMessageUtils.h";
|
||||
include "mozilla/layers/LayersMessageUtils.h";
|
||||
|
||||
using mozilla::dom::cache::Namespace
|
||||
from "mozilla/dom/cache/Types.h";
|
||||
|
||||
using class mozilla::dom::SSCacheCopy from "mozilla/dom/PBackgroundSessionStorageCache.h";
|
||||
|
||||
namespace mozilla {
|
||||
namespace ipc {
|
||||
|
||||
@ -207,6 +210,10 @@ parent:
|
||||
|
||||
async RemoveBackgroundSessionStorageManager(uint64_t topContextId);
|
||||
|
||||
async GetSessionStorageManagerData(
|
||||
uint64_t aTopContextId, uint32_t aSizeLimit)
|
||||
returns(SSCacheCopy[] aCacheCopy);
|
||||
|
||||
async PFileSystemRequest(FileSystemParams params);
|
||||
|
||||
async PGamepadEventChannel();
|
||||
|
Loading…
Reference in New Issue
Block a user