Bug 1350637 - Part 3: Move mozilla::dom::Optional serialization helper to ipc/glue/IPCMessageUtils.h to make it available to other consumers; r=billm

This commit is contained in:
Jan Varga 2017-08-08 23:01:03 +02:00
parent c186d54bb2
commit 9ea37e48ab
2 changed files with 36 additions and 36 deletions

View File

@ -16,42 +16,6 @@ typedef mozilla::dom::Sequence<nsString> WebrtcGlobalLog;
namespace IPC {
template<typename T>
struct ParamTraits<mozilla::dom::Optional<T>>
{
typedef mozilla::dom::Optional<T> paramType;
static void Write(Message* aMsg, const paramType& aParam)
{
if (aParam.WasPassed()) {
WriteParam(aMsg, true);
WriteParam(aMsg, aParam.Value());
return;
}
WriteParam(aMsg, false);
}
static bool Read(const Message* aMsg, PickleIterator* aIter, paramType* aResult)
{
bool was_passed = false;
if (!ReadParam(aMsg, aIter, &was_passed)) {
return false;
}
aResult->Reset(); //XXX Optional_base seems to reach this point with isSome true.
if (was_passed) {
if (!ReadParam(aMsg, aIter, &(aResult->Construct()))) {
return false;
}
}
return true;
}
};
template<typename T>
struct ParamTraits<mozilla::dom::Sequence<T>>
{

View File

@ -979,6 +979,42 @@ struct ParamTraits<mozilla::Variant<Ts...>>
}
};
template<typename T>
struct ParamTraits<mozilla::dom::Optional<T>>
{
typedef mozilla::dom::Optional<T> paramType;
static void Write(Message* aMsg, const paramType& aParam)
{
if (aParam.WasPassed()) {
WriteParam(aMsg, true);
WriteParam(aMsg, aParam.Value());
return;
}
WriteParam(aMsg, false);
}
static bool Read(const Message* aMsg, PickleIterator* aIter, paramType* aResult)
{
bool wasPassed = false;
if (!ReadParam(aMsg, aIter, &wasPassed)) {
return false;
}
aResult->Reset();
if (wasPassed) {
if (!ReadParam(aMsg, aIter, &aResult->Construct())) {
return false;
}
}
return true;
}
};
} /* namespace IPC */
#endif /* __IPC_GLUE_IPCMESSAGEUTILS_H__ */