Bug 1919555 - LSNG: Start PBackgroundLSDatabase construction in the parent; r=dom-storage-reviewers,asuth

The construction currently starts in the child using a datastore id. This extra
step and complexity is not needed anymore since a received endpoint for a top
level actor can be bound to any event target.

Differential Revision: https://phabricator.services.mozilla.com/D222420
This commit is contained in:
Jan Varga 2024-10-03 11:26:39 +00:00
parent 6ba69dd029
commit deda722602
10 changed files with 43 additions and 65 deletions

View File

@ -197,11 +197,11 @@ void LSRequestChild::ActorDestroy(ActorDestroyReason aWhy) {
}
mozilla::ipc::IPCResult LSRequestChild::Recv__delete__(
const LSRequestResponse& aResponse) {
LSRequestResponse&& aResponse) {
AssertIsOnOwningThread();
MOZ_ASSERT(mCallback);
mCallback->OnResponse(aResponse);
mCallback->OnResponse(std::move(aResponse));
mCallback = nullptr;

View File

@ -175,7 +175,7 @@ class LSRequestChild final : public PBackgroundLSRequestChild {
void ActorDestroy(ActorDestroyReason aWhy) override;
mozilla::ipc::IPCResult Recv__delete__(
const LSRequestResponse& aResponse) override;
LSRequestResponse&& aResponse) override;
mozilla::ipc::IPCResult RecvReady() override;
};
@ -184,7 +184,7 @@ class NS_NO_VTABLE LSRequestChildCallback {
public:
NS_INLINE_DECL_PURE_VIRTUAL_REFCOUNTING
virtual void OnResponse(const LSRequestResponse& aResponse) = 0;
virtual void OnResponse(LSRequestResponse&& aResponse) = 0;
protected:
virtual ~LSRequestChildCallback() = default;

View File

@ -3208,6 +3208,8 @@ void InitializeLocalStorage() {
namespace {
// XXX Merge these three methods into a new factory method Database::Create
already_AddRefed<PBackgroundLSDatabaseParent> AllocPBackgroundLSDatabaseParent(
const PrincipalInfo& aPrincipalInfo, const uint32_t& aPrivateBrowsingId,
const uint64_t& aDatastoreId) {
@ -3274,8 +3276,6 @@ bool RecvPBackgroundLSDatabaseConstructor(PBackgroundLSDatabaseParent* aActor,
return true;
}
} // namespace
bool RecvCreateBackgroundLSDatabaseParent(
const PrincipalInfo& aPrincipalInfo, const uint32_t& aPrivateBrowsingId,
const uint64_t& aDatastoreId,
@ -3293,6 +3293,8 @@ bool RecvCreateBackgroundLSDatabaseParent(
aPrivateBrowsingId, aDatastoreId);
}
} // namespace
PBackgroundLSObserverParent* AllocPBackgroundLSObserverParent(
const uint64_t& aObserverId) {
AssertIsOnBackgroundThread();
@ -6426,7 +6428,8 @@ void LSRequestBase::SendResults() {
response = ResultCode();
}
Unused << PBackgroundLSRequestParent::Send__delete__(this, response);
Unused << PBackgroundLSRequestParent::Send__delete__(this,
std::move(response));
}
Cleanup();
@ -7517,10 +7520,28 @@ void PrepareDatastoreOp::GetResponse(LSRequestResponse& aResponse) {
aResponse = preloadDatastoreResponse;
} else {
LSRequestPrepareDatastoreResponse prepareDatastoreResponse;
prepareDatastoreResponse.datastoreId() = mDatastoreId;
const LSRequestCommonParams& commonParams =
mParams.get_LSRequestPrepareDatastoreParams().commonParams();
aResponse = prepareDatastoreResponse;
const PrincipalInfo& storagePrincipalInfo =
commonParams.storagePrincipalInfo();
Endpoint<PBackgroundLSDatabaseParent> parentEndpoint;
Endpoint<PBackgroundLSDatabaseChild> childEndpoint;
MOZ_ALWAYS_SUCCEEDS(PBackgroundLSDatabase::CreateEndpoints(&parentEndpoint,
&childEndpoint));
if (!RecvCreateBackgroundLSDatabaseParent(storagePrincipalInfo,
mPrivateBrowsingId, mDatastoreId,
std::move(parentEndpoint))) {
aResponse = NS_ERROR_FAILURE;
} else {
LSRequestPrepareDatastoreResponse prepareDatastoreResponse;
prepareDatastoreResponse.databaseChildEndpoint() =
std::move(childEndpoint);
aResponse = std::move(prepareDatastoreResponse);
}
}
}

View File

@ -14,8 +14,6 @@ namespace mozilla {
namespace ipc {
template <class T>
class Endpoint;
class PBackgroundParent;
class PrincipalInfo;
@ -38,11 +36,6 @@ class Client;
void InitializeLocalStorage();
bool RecvCreateBackgroundLSDatabaseParent(
const mozilla::ipc::PrincipalInfo& aPrincipalInfo,
const uint32_t& aPrivateBrowsingId, const uint64_t& aDatastoreId,
mozilla::ipc::Endpoint<PBackgroundLSDatabaseParent>&& aParentEndpoint);
PBackgroundLSObserverParent* AllocPBackgroundLSObserverParent(
const uint64_t& aObserverId);

View File

@ -184,7 +184,7 @@ class RequestHelper final : public Runnable, public LSRequestChildCallback {
NS_DECL_NSIRUNNABLE
// LSRequestChildCallback
void OnResponse(const LSRequestResponse& aResponse) override;
void OnResponse(LSRequestResponse&& aResponse) override;
};
void AssertExplicitSnapshotInvariants(const LSObject& aObject) {
@ -922,10 +922,11 @@ nsresult LSObject::EnsureDatabase() {
MOZ_ASSERT(response.type() ==
LSRequestResponse::TLSRequestPrepareDatastoreResponse);
const LSRequestPrepareDatastoreResponse& prepareDatastoreResponse =
response.get_LSRequestPrepareDatastoreResponse();
LSRequestPrepareDatastoreResponse prepareDatastoreResponse =
std::move(response.get_LSRequestPrepareDatastoreResponse());
uint64_t datastoreId = prepareDatastoreResponse.datastoreId();
auto childEndpoint =
std::move(prepareDatastoreResponse.databaseChildEndpoint());
// The datastore is now ready on the parent side (prepared by the asynchronous
// request on the RemoteLazyInputStream thread).
@ -938,17 +939,8 @@ nsresult LSObject::EnsureDatabase() {
RefPtr<LSDatabaseChild> actor = new LSDatabaseChild(database);
mozilla::ipc::Endpoint<PBackgroundLSDatabaseParent> parentEndpoint;
mozilla::ipc::Endpoint<PBackgroundLSDatabaseChild> childEndpoint;
MOZ_ALWAYS_SUCCEEDS(
PBackgroundLSDatabase::CreateEndpoints(&parentEndpoint, &childEndpoint));
MOZ_ALWAYS_TRUE(childEndpoint.Bind(actor));
MOZ_ALWAYS_TRUE(backgroundActor->SendCreateBackgroundLSDatabaseParent(
*mStoragePrincipalInfo, mPrivateBrowsingId, datastoreId,
std::move(parentEndpoint)));
database->SetActor(actor);
glean::ls_preparelsdatabase::processing_time.StopAndAccumulate(
@ -1165,7 +1157,7 @@ RequestHelper::Run() {
}
}
void RequestHelper::OnResponse(const LSRequestResponse& aResponse) {
void RequestHelper::OnResponse(LSRequestResponse&& aResponse) {
AssertIsOnDOMFileThread();
MonitorAutoLock lock(mMonitor);
@ -1174,7 +1166,7 @@ void RequestHelper::OnResponse(const LSRequestResponse& aResponse) {
mActor = nullptr;
mResponse = aResponse;
mResponse = std::move(aResponse);
mState = State::Complete;

View File

@ -131,7 +131,7 @@ class AsyncRequestHelper final : public Runnable,
NS_DECL_NSIRUNNABLE
// LSRequestChildCallback
void OnResponse(const LSRequestResponse& aResponse) override;
void OnResponse(LSRequestResponse&& aResponse) override;
};
class SimpleRequestResolver final : public LSSimpleRequestChildCallback {
@ -562,13 +562,13 @@ AsyncRequestHelper::Run() {
return NS_OK;
}
void AsyncRequestHelper::OnResponse(const LSRequestResponse& aResponse) {
void AsyncRequestHelper::OnResponse(LSRequestResponse&& aResponse) {
AssertIsOnDOMFileThread();
MOZ_ASSERT(mState == State::ResponsePending);
mActor = nullptr;
mResponse = aResponse;
mResponse = std::move(aResponse);
mState = State::Finishing;

View File

@ -3,6 +3,7 @@
* You can obtain one at http://mozilla.org/MPL/2.0/. */
include protocol PBackground;
include protocol PBackgroundLSDatabase;
using struct mozilla::null_t from "mozilla/ipc/IPCCore.h";
@ -16,7 +17,7 @@ struct LSRequestPreloadDatastoreResponse
struct LSRequestPrepareDatastoreResponse
{
uint64_t datastoreId;
Endpoint<PBackgroundLSDatabaseChild> databaseChildEndpoint;
};
struct LSRequestPrepareObserverResponse

View File

@ -274,23 +274,6 @@ BackgroundParentImpl::RecvPBackgroundSDBConnectionConstructor(
return IPC_OK();
}
mozilla::ipc::IPCResult
BackgroundParentImpl::RecvCreateBackgroundLSDatabaseParent(
const PrincipalInfo& aPrincipalInfo, const uint32_t& aPrivateBrowsingId,
const uint64_t& aDatastoreId,
Endpoint<PBackgroundLSDatabaseParent>&& aParentEndpoint) {
AssertIsInMainProcess();
AssertIsOnBackgroundThread();
if (!mozilla::dom::RecvCreateBackgroundLSDatabaseParent(
aPrincipalInfo, aPrivateBrowsingId, aDatastoreId,
std::move(aParentEndpoint))) {
return IPC_FAIL_NO_REASON(this);
}
return IPC_OK();
}
BackgroundParentImpl::PBackgroundLSObserverParent*
BackgroundParentImpl::AllocPBackgroundLSObserverParent(
const uint64_t& aObserverId) {

View File

@ -56,11 +56,6 @@ class BackgroundParentImpl : public PBackgroundParent {
const PersistenceType& aPersistenceType,
const PrincipalInfo& aPrincipalInfo) override;
mozilla::ipc::IPCResult RecvCreateBackgroundLSDatabaseParent(
const PrincipalInfo& aPrincipalInfo, const uint32_t& aPrivateBrowsingId,
const uint64_t& aDatastoreId,
Endpoint<PBackgroundLSDatabaseParent>&& aParentEndpoint) override;
PBackgroundLSObserverParent* AllocPBackgroundLSObserverParent(
const uint64_t& aObserverId) override;

View File

@ -6,7 +6,6 @@ include protocol PBackgroundDataBridge;
include protocol PBackgroundIDBFactory;
include protocol PBackgroundIndexedDBUtils;
include protocol PBackgroundSDBConnection;
include protocol PBackgroundLSDatabase;
include protocol PBackgroundLSObserver;
include protocol PBackgroundLSRequest;
include protocol PBackgroundLSSimpleRequest;
@ -138,12 +137,6 @@ parent:
async PBackgroundSDBConnection(PersistenceType persistenceType,
PrincipalInfo principalInfo);
async CreateBackgroundLSDatabaseParent(
PrincipalInfo principalInfo,
uint32_t privateBrowsingId,
uint64_t datastoreId,
Endpoint<PBackgroundLSDatabaseParent> aParentEndpoint);
async PBackgroundLSObserver(uint64_t observerId);
/**