Bug 1347557 - Move 2 static methods about the IPC serialization of streams into an helper class, r=qdot

This commit is contained in:
Andrea Marchesini 2017-03-21 07:47:25 +01:00
Родитель 5587bb56c5
Коммит 2e9d67bae0
8 изменённых файлов: 42 добавлений и 74 удалений

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

@ -993,7 +993,8 @@ RemoteInputStream::BlockAndWaitForStream()
nsTArray<FileDescriptor> fds;
OptionalFileDescriptorSetToFDs(optionalFDs, fds);
nsCOMPtr<nsIInputStream> stream = DeserializeInputStream(params, fds);
nsCOMPtr<nsIInputStream> stream =
InputStreamHelper::DeserializeInputStream(params, fds);
MOZ_ASSERT(stream);
SetStream(stream);
@ -4450,7 +4451,7 @@ BlobParent::RecvPBlobStreamConstructor(PBlobStreamParent* aActor,
if (mBlobImpl->IsMemoryFile()) {
InputStreamParams params;
nsTArray<FileDescriptor> fds;
SerializeInputStream(stream, params, fds);
InputStreamHelper::SerializeInputStream(stream, params, fds);
MOZ_ASSERT(params.type() != InputStreamParams::T__None);
MOZ_ASSERT(fds.IsEmpty());
@ -4788,7 +4789,8 @@ InputStreamChild::Recv__delete__(const InputStreamParams& aParams,
const_cast<OptionalFileDescriptorSet&>(aOptionalSet),
fds);
nsCOMPtr<nsIInputStream> stream = DeserializeInputStream(aParams, fds);
nsCOMPtr<nsIInputStream> stream =
InputStreamHelper::DeserializeInputStream(aParams, fds);
MOZ_ASSERT(stream);
mRemoteStream->SetStream(stream);

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

@ -392,7 +392,7 @@ DeserializeIPCStream(const IPCStream& aValue)
Unused << fdSetActor->Send__delete__(fdSetActor);
}
return DeserializeInputStream(streamWithFds.stream(), fds);
return InputStreamHelper::DeserializeInputStream(streamWithFds.stream(), fds);
}
already_AddRefed<nsIInputStream>

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

@ -40,9 +40,9 @@ namespace mozilla {
namespace ipc {
void
SerializeInputStream(nsIInputStream* aInputStream,
InputStreamParams& aParams,
nsTArray<FileDescriptor>& aFileDescriptors)
InputStreamHelper::SerializeInputStream(nsIInputStream* aInputStream,
InputStreamParams& aParams,
nsTArray<FileDescriptor>& aFileDescriptors)
{
MOZ_ASSERT(aInputStream);
@ -59,24 +59,9 @@ SerializeInputStream(nsIInputStream* aInputStream,
}
}
void
SerializeInputStream(nsIInputStream* aInputStream,
OptionalInputStreamParams& aParams,
nsTArray<FileDescriptor>& aFileDescriptors)
{
if (aInputStream) {
InputStreamParams params;
SerializeInputStream(aInputStream, params, aFileDescriptors);
aParams = params;
}
else {
aParams = mozilla::void_t();
}
}
already_AddRefed<nsIInputStream>
DeserializeInputStream(const InputStreamParams& aParams,
const nsTArray<FileDescriptor>& aFileDescriptors)
InputStreamHelper::DeserializeInputStream(const InputStreamParams& aParams,
const nsTArray<FileDescriptor>& aFileDescriptors)
{
nsCOMPtr<nsIInputStream> stream;
nsCOMPtr<nsIIPCSerializableInputStream> serializable;
@ -166,28 +151,5 @@ DeserializeInputStream(const InputStreamParams& aParams,
return stream.forget();
}
already_AddRefed<nsIInputStream>
DeserializeInputStream(const OptionalInputStreamParams& aParams,
const nsTArray<FileDescriptor>& aFileDescriptors)
{
nsCOMPtr<nsIInputStream> stream;
switch (aParams.type()) {
case OptionalInputStreamParams::Tvoid_t:
// Leave stream null.
break;
case OptionalInputStreamParams::TInputStreamParams:
stream = DeserializeInputStream(aParams.get_InputStreamParams(),
aFileDescriptors);
break;
default:
MOZ_ASSERT(false, "Unknown params!");
}
return stream.forget();
}
} // namespace ipc
} // namespace mozilla

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

@ -17,23 +17,19 @@ namespace ipc {
class FileDescriptor;
void
SerializeInputStream(nsIInputStream* aInputStream,
InputStreamParams& aParams,
nsTArray<FileDescriptor>& aFileDescriptors);
// If you want to serialize an inputStream, please use AutoIPCStream.
class InputStreamHelper
{
public:
static void
SerializeInputStream(nsIInputStream* aInputStream,
InputStreamParams& aParams,
nsTArray<FileDescriptor>& aFileDescriptors);
void
SerializeInputStream(nsIInputStream* aInputStream,
OptionalInputStreamParams& aParams,
nsTArray<FileDescriptor>& aFileDescriptors);
already_AddRefed<nsIInputStream>
DeserializeInputStream(const InputStreamParams& aParams,
const nsTArray<FileDescriptor>& aFileDescriptors);
already_AddRefed<nsIInputStream>
DeserializeInputStream(const OptionalInputStreamParams& aParams,
const nsTArray<FileDescriptor>& aFileDescriptors);
static already_AddRefed<nsIInputStream>
DeserializeInputStream(const InputStreamParams& aParams,
const nsTArray<FileDescriptor>& aFileDescriptors);
};
} // namespace ipc
} // namespace mozilla

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

@ -554,7 +554,8 @@ nsBufferedInputStream::Serialize(InputStreamParams& aParams,
MOZ_ASSERT(stream);
InputStreamParams wrappedParams;
SerializeInputStream(stream, wrappedParams, aFileDescriptors);
InputStreamHelper::SerializeInputStream(stream, wrappedParams,
aFileDescriptors);
params.optionalStream() = wrappedParams;
}
@ -582,8 +583,9 @@ nsBufferedInputStream::Deserialize(const InputStreamParams& aParams,
nsCOMPtr<nsIInputStream> stream;
if (wrappedParams.type() == OptionalInputStreamParams::TInputStreamParams) {
stream = DeserializeInputStream(wrappedParams.get_InputStreamParams(),
aFileDescriptors);
stream =
InputStreamHelper::DeserializeInputStream(wrappedParams.get_InputStreamParams(),
aFileDescriptors);
if (!stream) {
NS_WARNING("Failed to deserialize wrapped stream!");
return false;

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

@ -269,7 +269,8 @@ nsMIMEInputStream::Serialize(InputStreamParams& aParams,
if (mStream) {
InputStreamParams wrappedParams;
SerializeInputStream(mStream, wrappedParams, aFileDescriptors);
InputStreamHelper::SerializeInputStream(mStream, wrappedParams,
aFileDescriptors);
NS_ASSERTION(wrappedParams.type() != InputStreamParams::T__None,
"Wrapped stream failed to serialize!");
@ -304,8 +305,9 @@ nsMIMEInputStream::Deserialize(const InputStreamParams& aParams,
if (wrappedParams.type() == OptionalInputStreamParams::TInputStreamParams) {
nsCOMPtr<nsIInputStream> stream;
stream = DeserializeInputStream(wrappedParams.get_InputStreamParams(),
aFileDescriptors);
stream =
InputStreamHelper::DeserializeInputStream(wrappedParams.get_InputStreamParams(),
aFileDescriptors);
if (!stream) {
NS_WARNING("Failed to deserialize wrapped stream!");
return false;

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

@ -256,7 +256,8 @@ SlicedInputStream::Serialize(mozilla::ipc::InputStreamParams& aParams,
MOZ_ASSERT(mWeakIPCSerializableInputStream);
SlicedInputStreamParams params;
SerializeInputStream(mInputStream, params.stream(), aFileDescriptors);
InputStreamHelper::SerializeInputStream(mInputStream, params.stream(),
aFileDescriptors);
params.start() = mStart;
params.length() = mLength;
params.curPos() = mCurPos;
@ -282,7 +283,8 @@ SlicedInputStream::Deserialize(const mozilla::ipc::InputStreamParams& aParams,
aParams.get_SlicedInputStreamParams();
nsCOMPtr<nsIInputStream> stream =
DeserializeInputStream(params.stream(), aFileDescriptors);
InputStreamHelper::DeserializeInputStream(params.stream(),
aFileDescriptors);
if (!stream) {
NS_WARNING("Deserialize failed!");
return false;

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

@ -709,8 +709,9 @@ nsMultiplexInputStream::Serialize(InputStreamParams& aParams,
streams.SetCapacity(streamCount);
for (uint32_t index = 0; index < streamCount; index++) {
InputStreamParams childStreamParams;
SerializeInputStream(mStreams[index], childStreamParams,
aFileDescriptors);
InputStreamHelper::SerializeInputStream(mStreams[index],
childStreamParams,
aFileDescriptors);
streams.AppendElement(childStreamParams);
}
@ -741,7 +742,8 @@ nsMultiplexInputStream::Deserialize(const InputStreamParams& aParams,
uint32_t streamCount = streams.Length();
for (uint32_t index = 0; index < streamCount; index++) {
nsCOMPtr<nsIInputStream> stream =
DeserializeInputStream(streams[index], aFileDescriptors);
InputStreamHelper::DeserializeInputStream(streams[index],
aFileDescriptors);
if (!stream) {
NS_WARNING("Deserialize failed!");
return false;