Bug 1791750 - Add a new argument to serialization methods for passing optional callbacks; r=dom-storage-reviewers,ipc-reviewers,nika,jari

This just about adding a new argument to all relevant places.

Differential Revision: https://phabricator.services.mozilla.com/D164340
This commit is contained in:
Jan Varga 2022-12-16 06:38:12 +00:00
Родитель 323253d8d7
Коммит cb23cc0476
12 изменённых файлов: 33 добавлений и 50 удалений

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

@ -149,7 +149,7 @@ mozilla::ipc::IPCResult FileSystemManagerParent::RecvGetAccessHandle(
RandomAccessStreamParams streamParams =
mozilla::ipc::SerializeRandomAccessStream(
WrapMovingNotNullUnchecked(std::move(stream)));
WrapMovingNotNullUnchecked(std::move(stream)), nullptr);
auto accessHandleParent =
MakeRefPtr<FileSystemAccessHandleParent>(this, aRequest.entryId());

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

@ -102,7 +102,8 @@ NS_IMETHODIMP FileQuotaStreamWithWrite<FileStreamBase>::Write(
return NS_OK;
}
mozilla::ipc::RandomAccessStreamParams FileRandomAccessStream::Serialize() {
mozilla::ipc::RandomAccessStreamParams FileRandomAccessStream::Serialize(
nsIInterfaceRequestor* aCallbacks) {
MOZ_RELEASE_ASSERT(XRE_IsParentProcess());
MOZ_RELEASE_ASSERT(!mDeserialized);
MOZ_ASSERT(mOpenParams.localFile);
@ -114,10 +115,10 @@ mozilla::ipc::RandomAccessStreamParams FileRandomAccessStream::Serialize() {
mPersistenceType, mOriginMetadata, mClientType, mOpenParams.localFile);
MOZ_ASSERT(quotaObject);
IPCQuotaObject ipcQuotaObject = quotaObject->Serialize();
IPCQuotaObject ipcQuotaObject = quotaObject->Serialize(aCallbacks);
mozilla::ipc::RandomAccessStreamParams randomAccessStreamParams =
nsFileRandomAccessStream::Serialize();
nsFileRandomAccessStream::Serialize(aCallbacks);
MOZ_ASSERT(
randomAccessStreamParams.type() ==

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

@ -141,7 +141,8 @@ class FileRandomAccessStream
// Serialize this FileRandomAccessStream. This method works only in the
// parent process and only with streams which haven't been previously
// deserialized.
mozilla::ipc::RandomAccessStreamParams Serialize() override;
mozilla::ipc::RandomAccessStreamParams Serialize(
nsIInterfaceRequestor* aCallbacks) override;
// Deserialize this FileRandomAccessStream. This method works in both the
// child and parent.

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

@ -12,6 +12,7 @@
#include "mozilla/dom/quota/RemoteQuotaObjectChild.h"
#include "mozilla/dom/quota/RemoteQuotaObjectParent.h"
#include "mozilla/ipc/BackgroundParent.h"
#include "nsIInterfaceRequestor.h"
#include "RemoteQuotaObject.h"
namespace mozilla::dom::quota {
@ -24,7 +25,7 @@ RemoteQuotaObject* QuotaObject::AsRemoteQuotaObject() {
return mIsRemote ? static_cast<RemoteQuotaObject*>(this) : nullptr;
}
IPCQuotaObject QuotaObject::Serialize() {
IPCQuotaObject QuotaObject::Serialize(nsIInterfaceRequestor* aCallbacks) {
MOZ_RELEASE_ASSERT(XRE_IsParentProcess());
MOZ_RELEASE_ASSERT(!NS_IsMainThread());
MOZ_RELEASE_ASSERT(!mozilla::ipc::IsOnBackgroundThread());
@ -60,25 +61,3 @@ RefPtr<QuotaObject> QuotaObject::Deserialize(IPCQuotaObject& aQuotaObject) {
}
} // namespace mozilla::dom::quota
namespace IPC {
void ParamTraits<mozilla::dom::quota::QuotaObject*>::Write(
MessageWriter* aWriter, mozilla::dom::quota::QuotaObject* aParam) {
mozilla::dom::quota::IPCQuotaObject ipcQuotaObject = aParam->Serialize();
WriteParam(aWriter, std::move(ipcQuotaObject));
}
bool ParamTraits<mozilla::dom::quota::QuotaObject*>::Read(
MessageReader* aReader, RefPtr<mozilla::dom::quota::QuotaObject>* aResult) {
mozilla::dom::quota::IPCQuotaObject ipcQuotaObject;
if (!ReadParam(aReader, &ipcQuotaObject)) {
return false;
}
*aResult = mozilla::dom::quota::QuotaObject::Deserialize(ipcQuotaObject);
return true;
}
} // namespace IPC

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

@ -7,9 +7,10 @@
#ifndef DOM_QUOTA_QUOTAOBJECT_H_
#define DOM_QUOTA_QUOTAOBJECT_H_
#include "chrome/common/ipc_message_utils.h"
#include "nsISupportsImpl.h"
class nsIInterfaceRequestor;
namespace mozilla::dom::quota {
class CanonicalQuotaObject;
@ -39,7 +40,7 @@ class QuotaObject {
// and only with objects which haven't been previously deserialized.
// The serial event target where this method is called should be highly
// available, as it will be used to process requests from the remote variant.
IPCQuotaObject Serialize();
IPCQuotaObject Serialize(nsIInterfaceRequestor* aCallbacks);
// Deserialize a QuotaObject. This method works in both the child and parent.
// The deserialized QuotaObject can only be used on the calling serial event
@ -66,12 +67,4 @@ class QuotaObject {
} // namespace mozilla::dom::quota
template <>
struct IPC::ParamTraits<mozilla::dom::quota::QuotaObject*> {
static void Write(IPC::MessageWriter* aWriter,
mozilla::dom::quota::QuotaObject* aParam);
static bool Read(IPC::MessageReader* aReader,
RefPtr<mozilla::dom::quota::QuotaObject>* aResult);
};
#endif // DOM_QUOTA_QUOTAOBJECT_H_

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

@ -41,6 +41,8 @@ void RemoteQuotaObject::Close() {
MOZ_ASSERT(!mActor);
}
const nsAString& RemoteQuotaObject::Path() const { return EmptyString(); }
bool RemoteQuotaObject::MaybeUpdateSize(int64_t aSize, bool aTruncate) {
MOZ_ASSERT(!NS_IsMainThread());
MOZ_ASSERT(!mozilla::ipc::IsOnBackgroundThread());

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

@ -24,7 +24,7 @@ class RemoteQuotaObject final : public QuotaObject {
void Close();
const nsAString& Path() const override { return EmptyString(); }
const nsAString& Path() const override;
// This method should never be called on the main thread or the PBackground
// thread or a DOM worker thread (It does sync IPC).

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

@ -12,15 +12,17 @@
#include "mozilla/dom/quota/FileStreams.h"
#include "mozilla/ipc/RandomAccessStreamParams.h"
#include "nsFileStreams.h"
#include "nsIInterfaceRequestor.h"
#include "nsIRandomAccessStream.h"
namespace mozilla::ipc {
RandomAccessStreamParams SerializeRandomAccessStream(
MovingNotNull<nsCOMPtr<nsIRandomAccessStream>> aStream) {
MovingNotNull<nsCOMPtr<nsIRandomAccessStream>> aStream,
nsIInterfaceRequestor* aCallbacks) {
NotNull<nsCOMPtr<nsIRandomAccessStream>> stream = std::move(aStream);
RandomAccessStreamParams streamParams = stream->Serialize();
RandomAccessStreamParams streamParams = stream->Serialize(aCallbacks);
MOZ_ASSERT(streamParams.type() != RandomAccessStreamParams::T__None);
@ -28,13 +30,14 @@ RandomAccessStreamParams SerializeRandomAccessStream(
}
Maybe<RandomAccessStreamParams> SerializeRandomAccessStream(
nsCOMPtr<nsIRandomAccessStream> aStream) {
nsCOMPtr<nsIRandomAccessStream> aStream,
nsIInterfaceRequestor* aCallbacks) {
if (!aStream) {
return Nothing();
}
return Some(SerializeRandomAccessStream(
WrapMovingNotNullUnchecked(std::move(aStream))));
WrapMovingNotNullUnchecked(std::move(aStream)), aCallbacks));
}
Result<MovingNotNull<nsCOMPtr<nsIRandomAccessStream>>, bool>

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

@ -10,6 +10,7 @@
template <class T>
class nsCOMPtr;
class nsIInterfaceRequestor;
class nsIRandomAccessStream;
namespace mozilla {
@ -29,10 +30,11 @@ class RandomAccessStreamParams;
// Serialize an nsIRandomAccessStream to be sent over IPC infallibly.
RandomAccessStreamParams SerializeRandomAccessStream(
MovingNotNull<nsCOMPtr<nsIRandomAccessStream>> aStream);
MovingNotNull<nsCOMPtr<nsIRandomAccessStream>> aStream,
nsIInterfaceRequestor* aCallbacks);
Maybe<RandomAccessStreamParams> SerializeRandomAccessStream(
nsCOMPtr<nsIRandomAccessStream> aStream);
nsCOMPtr<nsIRandomAccessStream> aStream, nsIInterfaceRequestor* aCallbacks);
// Deserialize an nsIRandomAccessStream received from an actor call. These
// methods work in both the child and parent.

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

@ -105,7 +105,7 @@ TEST(RandomAccessStreamUtils, NullRandomAccessStream_MaybeSerialize)
nsCOMPtr<nsIRandomAccessStream> stream;
Maybe<RandomAccessStreamParams> streamParams =
SerializeRandomAccessStream(stream);
SerializeRandomAccessStream(stream, nullptr);
ASSERT_TRUE(streamParams.isNothing());
@ -139,7 +139,7 @@ TEST(RandomAccessStreamUtils, FileRandomAccessStream_Serialize)
ASSERT_EQ(numWritten, dataSize);
RandomAccessStreamParams streamParams = SerializeRandomAccessStream(
WrapMovingNotNullUnchecked(std::move(stream)));
WrapMovingNotNullUnchecked(std::move(stream)), nullptr);
ASSERT_EQ(streamParams.type(),
RandomAccessStreamParams::TFileRandomAccessStreamParams);
@ -187,7 +187,7 @@ TEST(RandomAccessStreamUtils, FileRandomAccessStream_MaybeSerialize)
ASSERT_EQ(numWritten, dataSize);
Maybe<RandomAccessStreamParams> streamParams =
SerializeRandomAccessStream(stream);
SerializeRandomAccessStream(stream, nullptr);
ASSERT_TRUE(streamParams);
ASSERT_EQ(streamParams->type(),

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

@ -901,7 +901,8 @@ nsIInputStream* nsFileRandomAccessStream::InputStream() { return this; }
nsIOutputStream* nsFileRandomAccessStream::OutputStream() { return this; }
RandomAccessStreamParams nsFileRandomAccessStream::Serialize() {
RandomAccessStreamParams nsFileRandomAccessStream::Serialize(
nsIInterfaceRequestor* aCallbacks) {
FileRandomAccessStreamParams params;
if (NS_SUCCEEDED(DoPendingOpen())) {

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

@ -7,6 +7,7 @@
#include "nsISeekableStream.idl"
interface nsIInputStream;
interface nsIInterfaceRequestor;
interface nsIOutputStream;
%{C++
@ -55,7 +56,7 @@ interface nsIRandomAccessStream : nsISeekableStream
*/
[notxpcom, nostdcall] nsIOutputStream outputStream();
[notxpcom, nostdcall] RandomAccessStreamParams serialize();
[notxpcom, nostdcall] RandomAccessStreamParams serialize(in nsIInterfaceRequestor aCallbacks);
[notxpcom, nostdcall] bool deserialize(inout RandomAccessStreamParamsRef params);
};