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 = RandomAccessStreamParams streamParams =
mozilla::ipc::SerializeRandomAccessStream( mozilla::ipc::SerializeRandomAccessStream(
WrapMovingNotNullUnchecked(std::move(stream))); WrapMovingNotNullUnchecked(std::move(stream)), nullptr);
auto accessHandleParent = auto accessHandleParent =
MakeRefPtr<FileSystemAccessHandleParent>(this, aRequest.entryId()); MakeRefPtr<FileSystemAccessHandleParent>(this, aRequest.entryId());

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

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

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

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

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

@ -12,6 +12,7 @@
#include "mozilla/dom/quota/RemoteQuotaObjectChild.h" #include "mozilla/dom/quota/RemoteQuotaObjectChild.h"
#include "mozilla/dom/quota/RemoteQuotaObjectParent.h" #include "mozilla/dom/quota/RemoteQuotaObjectParent.h"
#include "mozilla/ipc/BackgroundParent.h" #include "mozilla/ipc/BackgroundParent.h"
#include "nsIInterfaceRequestor.h"
#include "RemoteQuotaObject.h" #include "RemoteQuotaObject.h"
namespace mozilla::dom::quota { namespace mozilla::dom::quota {
@ -24,7 +25,7 @@ RemoteQuotaObject* QuotaObject::AsRemoteQuotaObject() {
return mIsRemote ? static_cast<RemoteQuotaObject*>(this) : nullptr; return mIsRemote ? static_cast<RemoteQuotaObject*>(this) : nullptr;
} }
IPCQuotaObject QuotaObject::Serialize() { IPCQuotaObject QuotaObject::Serialize(nsIInterfaceRequestor* aCallbacks) {
MOZ_RELEASE_ASSERT(XRE_IsParentProcess()); MOZ_RELEASE_ASSERT(XRE_IsParentProcess());
MOZ_RELEASE_ASSERT(!NS_IsMainThread()); MOZ_RELEASE_ASSERT(!NS_IsMainThread());
MOZ_RELEASE_ASSERT(!mozilla::ipc::IsOnBackgroundThread()); MOZ_RELEASE_ASSERT(!mozilla::ipc::IsOnBackgroundThread());
@ -60,25 +61,3 @@ RefPtr<QuotaObject> QuotaObject::Deserialize(IPCQuotaObject& aQuotaObject) {
} }
} // namespace mozilla::dom::quota } // 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_ #ifndef DOM_QUOTA_QUOTAOBJECT_H_
#define DOM_QUOTA_QUOTAOBJECT_H_ #define DOM_QUOTA_QUOTAOBJECT_H_
#include "chrome/common/ipc_message_utils.h"
#include "nsISupportsImpl.h" #include "nsISupportsImpl.h"
class nsIInterfaceRequestor;
namespace mozilla::dom::quota { namespace mozilla::dom::quota {
class CanonicalQuotaObject; class CanonicalQuotaObject;
@ -39,7 +40,7 @@ class QuotaObject {
// and only with objects which haven't been previously deserialized. // and only with objects which haven't been previously deserialized.
// The serial event target where this method is called should be highly // 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. // 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. // Deserialize a QuotaObject. This method works in both the child and parent.
// The deserialized QuotaObject can only be used on the calling serial event // The deserialized QuotaObject can only be used on the calling serial event
@ -66,12 +67,4 @@ class QuotaObject {
} // namespace mozilla::dom::quota } // 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_ #endif // DOM_QUOTA_QUOTAOBJECT_H_

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

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

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

@ -24,7 +24,7 @@ class RemoteQuotaObject final : public QuotaObject {
void Close(); 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 // This method should never be called on the main thread or the PBackground
// thread or a DOM worker thread (It does sync IPC). // thread or a DOM worker thread (It does sync IPC).

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

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

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

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

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

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

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

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

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

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