Bug 1517089 - Part 13: Use separate IPC params and response for datastore preloading; r=asuth

Differential Revision: https://phabricator.services.mozilla.com/D19207
This commit is contained in:
Jan Varga 2019-02-08 21:02:11 +01:00
Родитель f5f2ed7bcb
Коммит 2e11851013
6 изменённых файлов: 83 добавлений и 55 удалений

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

@ -5320,8 +5320,8 @@ nsresult ContentParent::AboutToLoadHttpFtpDocumentForChild(
nsCOMPtr<nsISupports> dummy;
rv = lsm->Preload(principal, nullptr, getter_AddRefs(dummy));
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
if (NS_FAILED(rv)) {
NS_WARNING("Failed to preload local storage!");
}
}

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

@ -2228,7 +2228,7 @@ class PrepareDatastoreOp : public LSRequestBase, public OpenDirectoryListener {
LoadDataOp* mLoadDataOp;
nsDataHashtable<nsStringHashKey, nsString> mValues;
nsTArray<LSItemInfo> mOrderedItems;
const LSRequestPrepareDatastoreParams mParams;
const LSRequestCommonParams mParams;
Maybe<ContentParentId> mContentParentId;
nsCString mSuffix;
nsCString mGroup;
@ -2241,6 +2241,7 @@ class PrepareDatastoreOp : public LSRequestBase, public OpenDirectoryListener {
int64_t mSizeOfKeys;
int64_t mSizeOfItems;
NestedState mNestedState;
const bool mCreateIfNotExists;
bool mDatabaseNotAvailable;
bool mRequestedDirectoryLock;
bool mInvalidated;
@ -3130,9 +3131,20 @@ bool VerifyRequestParams(const LSRequestParams& aParams) {
MOZ_ASSERT(aParams.type() != LSRequestParams::T__None);
switch (aParams.type()) {
case LSRequestParams::TLSRequestPreloadDatastoreParams: {
const LSRequestCommonParams& params =
aParams.get_LSRequestPreloadDatastoreParams().commonParams();
if (NS_WARN_IF(!VerifyPrincipalInfo(params.principalInfo()))) {
ASSERT_UNLESS_FUZZING();
return false;
}
break;
}
case LSRequestParams::TLSRequestPrepareDatastoreParams: {
const LSRequestPrepareDatastoreParams& params =
aParams.get_LSRequestPrepareDatastoreParams();
const LSRequestCommonParams& params =
aParams.get_LSRequestPrepareDatastoreParams().commonParams();
if (NS_WARN_IF(!VerifyPrincipalInfo(params.principalInfo()))) {
ASSERT_UNLESS_FUZZING();
@ -3190,6 +3202,7 @@ PBackgroundLSRequestParent* AllocPBackgroundLSRequestParent(
RefPtr<LSRequestBase> actor;
switch (aParams.type()) {
case LSRequestParams::TLSRequestPreloadDatastoreParams:
case LSRequestParams::TLSRequestPrepareDatastoreParams: {
Maybe<ContentParentId> contentParentId;
@ -5684,13 +5697,18 @@ PrepareDatastoreOp::PrepareDatastoreOp(
: LSRequestBase(aMainEventTarget),
mMainEventTarget(aMainEventTarget),
mLoadDataOp(nullptr),
mParams(aParams.get_LSRequestPrepareDatastoreParams()),
mParams(
aParams.type() == LSRequestParams::TLSRequestPreloadDatastoreParams
? aParams.get_LSRequestPreloadDatastoreParams().commonParams()
: aParams.get_LSRequestPrepareDatastoreParams().commonParams()),
mContentParentId(aContentParentId),
mPrivateBrowsingId(0),
mUsage(0),
mSizeOfKeys(0),
mSizeOfItems(0),
mNestedState(NestedState::BeforeNesting),
mCreateIfNotExists(aParams.type() ==
LSRequestParams::TLSRequestPrepareDatastoreParams),
mDatabaseNotAvailable(false),
mRequestedDirectoryLock(false),
mInvalidated(false)
@ -5699,8 +5717,9 @@ PrepareDatastoreOp::PrepareDatastoreOp(
mDEBUGUsage(0)
#endif
{
MOZ_ASSERT(aParams.type() ==
LSRequestParams::TLSRequestPrepareDatastoreParams);
MOZ_ASSERT(
aParams.type() == LSRequestParams::TLSRequestPreloadDatastoreParams ||
aParams.type() == LSRequestParams::TLSRequestPrepareDatastoreParams);
}
PrepareDatastoreOp::~PrepareDatastoreOp() {
@ -6016,7 +6035,7 @@ nsresult PrepareDatastoreOp::DatabaseWork() {
bool hasDataForMigration = mArchivedOriginScope->HasMatches(gArchivedOrigins);
bool createIfNotExists = mParams.createIfNotExists() || hasDataForMigration;
bool createIfNotExists = mCreateIfNotExists || hasDataForMigration;
nsCOMPtr<nsIFile> directoryEntry;
rv = quotaManager->EnsureOriginIsInitialized(
@ -6462,12 +6481,11 @@ void PrepareDatastoreOp::GetResponse(LSRequestResponse& aResponse) {
MOZ_ASSERT(NS_SUCCEEDED(ResultCode()));
if (mDatabaseNotAvailable) {
MOZ_ASSERT(!mParams.createIfNotExists());
MOZ_ASSERT(!mCreateIfNotExists);
LSRequestPrepareDatastoreResponse prepareDatastoreResponse;
prepareDatastoreResponse.datastoreId() = null_t();
LSRequestPreloadDatastoreResponse preloadDatastoreResponse;
aResponse = prepareDatastoreResponse;
aResponse = preloadDatastoreResponse;
return;
}
@ -6501,7 +6519,7 @@ void PrepareDatastoreOp::GetResponse(LSRequestResponse& aResponse) {
nsAutoPtr<PreparedDatastore> preparedDatastore(
new PreparedDatastore(mDatastore, mContentParentId, mOrigin, datastoreId,
/* aForPreload */ !mParams.createIfNotExists()));
/* aForPreload */ !mCreateIfNotExists));
if (!gPreparedDatastores) {
gPreparedDatastores = new PreparedDatastoreHashtable();
@ -6514,10 +6532,16 @@ void PrepareDatastoreOp::GetResponse(LSRequestResponse& aResponse) {
preparedDatastore.forget();
LSRequestPrepareDatastoreResponse prepareDatastoreResponse;
prepareDatastoreResponse.datastoreId() = datastoreId;
if (mCreateIfNotExists) {
LSRequestPrepareDatastoreResponse prepareDatastoreResponse;
prepareDatastoreResponse.datastoreId() = datastoreId;
aResponse = prepareDatastoreResponse;
aResponse = prepareDatastoreResponse;
} else {
LSRequestPreloadDatastoreResponse preloadDatastoreResponse;
aResponse = preloadDatastoreResponse;
}
}
void PrepareDatastoreOp::Cleanup() {

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

@ -746,10 +746,11 @@ nsresult LSObject::EnsureDatabase() {
return NS_ERROR_FAILURE;
}
LSRequestPrepareDatastoreParams params;
params.principalInfo() = *mPrincipalInfo;
params.originKey() = mOriginKey;
params.createIfNotExists() = true;
LSRequestCommonParams commonParams;
commonParams.principalInfo() = *mPrincipalInfo;
commonParams.originKey() = mOriginKey;
LSRequestPrepareDatastoreParams params(commonParams);
LSRequestResponse response;
@ -764,10 +765,7 @@ nsresult LSObject::EnsureDatabase() {
const LSRequestPrepareDatastoreResponse& prepareDatastoreResponse =
response.get_LSRequestPrepareDatastoreResponse();
const NullableDatastoreId& datastoreId =
prepareDatastoreResponse.datastoreId();
MOZ_ASSERT(datastoreId.type() == NullableDatastoreId::Tuint64_t);
uint64_t datastoreId = prepareDatastoreResponse.datastoreId();
// The datastore is now ready on the parent side (prepared by the asynchronous
// request on the DOM File thread).

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

@ -27,7 +27,7 @@ class RequestResolver final : public LSRequestChildCallback {
void HandleResponse(nsresult aResponse);
void HandleResponse(const NullableDatastoreId& aDatastoreId);
void HandleResponse();
// LSRequestChildCallback
void OnResponse(const LSRequestResponse& aResponse) override;
@ -192,7 +192,18 @@ LocalStorageManager2::Preload(nsIPrincipal* aPrincipal, JSContext* aContext,
MOZ_ASSERT(aPrincipal);
MOZ_ASSERT(_retval);
nsresult rv;
nsCString originAttrSuffix;
nsCString originKey;
nsresult rv = GenerateOriginKey(aPrincipal, originAttrSuffix, originKey);
if (NS_FAILED(rv)) {
return NS_ERROR_NOT_AVAILABLE;
}
nsAutoPtr<PrincipalInfo> principalInfo(new PrincipalInfo());
rv = CheckedPrincipalToPrincipalInfo(aPrincipal, *principalInfo);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
RefPtr<Promise> promise;
@ -203,13 +214,11 @@ LocalStorageManager2::Preload(nsIPrincipal* aPrincipal, JSContext* aContext,
}
}
LSRequestPrepareDatastoreParams params;
params.createIfNotExists() = false;
LSRequestCommonParams commonParams;
commonParams.principalInfo() = *principalInfo;
commonParams.originKey() = originKey;
rv = CheckedPrincipalToPrincipalInfo(aPrincipal, params.principalInfo());
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
LSRequestPreloadDatastoreParams params(commonParams);
rv = StartRequest(promise, params);
if (NS_WARN_IF(NS_FAILED(rv))) {
@ -303,25 +312,14 @@ void RequestResolver::HandleResponse(nsresult aResponse) {
mPromise->MaybeReject(aResponse);
}
void RequestResolver::HandleResponse(const NullableDatastoreId& aDatastoreId) {
void RequestResolver::HandleResponse() {
MOZ_ASSERT(NS_IsMainThread());
if (!mPromise) {
return;
}
switch (aDatastoreId.type()) {
case NullableDatastoreId::Tnull_t:
mPromise->MaybeResolve(JS::NullHandleValue);
break;
case NullableDatastoreId::Tuint64_t:
mPromise->MaybeResolve(aDatastoreId.get_uint64_t());
break;
default:
MOZ_CRASH("Unknown datastore id type!");
}
mPromise->MaybeResolveWithUndefined();
}
void RequestResolver::OnResponse(const LSRequestResponse& aResponse) {
@ -332,9 +330,8 @@ void RequestResolver::OnResponse(const LSRequestResponse& aResponse) {
HandleResponse(aResponse.get_nsresult());
break;
case LSRequestResponse::TLSRequestPrepareDatastoreResponse:
HandleResponse(
aResponse.get_LSRequestPrepareDatastoreResponse().datastoreId());
case LSRequestResponse::TLSRequestPreloadDatastoreResponse:
HandleResponse();
break;
default:
MOZ_CRASH("Unknown response type!");

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

@ -10,15 +10,13 @@ using struct mozilla::null_t
namespace mozilla {
namespace dom {
union NullableDatastoreId
struct LSRequestPreloadDatastoreResponse
{
null_t;
uint64_t;
};
struct LSRequestPrepareDatastoreResponse
{
NullableDatastoreId datastoreId;
uint64_t datastoreId;
};
struct LSRequestPrepareObserverResponse
@ -33,6 +31,7 @@ struct LSRequestPrepareObserverResponse
union LSRequestResponse
{
nsresult;
LSRequestPreloadDatastoreResponse;
LSRequestPrepareDatastoreResponse;
LSRequestPrepareObserverResponse;
};

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

@ -7,11 +7,20 @@ include PBackgroundSharedTypes;
namespace mozilla {
namespace dom {
struct LSRequestPrepareDatastoreParams
struct LSRequestCommonParams
{
PrincipalInfo principalInfo;
nsCString originKey;
bool createIfNotExists;
};
struct LSRequestPreloadDatastoreParams
{
LSRequestCommonParams commonParams;
};
struct LSRequestPrepareDatastoreParams
{
LSRequestCommonParams commonParams;
};
struct LSRequestPrepareObserverParams
@ -21,6 +30,7 @@ struct LSRequestPrepareObserverParams
union LSRequestParams
{
LSRequestPreloadDatastoreParams;
LSRequestPrepareDatastoreParams;
LSRequestPrepareObserverParams;
};