Backed out changeset 2450366cf7ca (bug 1891629) for causing win msix mochitest failures
[gecko.git] / dom / quota / SerializationHelpers.h
blob7eb4773964e033fee375bfc503f39f001b7743c9
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
5 * You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef mozilla_dom_quota_SerializationHelpers_h
8 #define mozilla_dom_quota_SerializationHelpers_h
10 #include "ipc/EnumSerializer.h"
11 #include "ipc/IPCMessageUtils.h"
13 #include "mozilla/dom/quota/Client.h"
14 #include "mozilla/dom/quota/CommonMetadata.h"
15 #include "mozilla/dom/quota/PersistenceType.h"
16 #include "mozilla/dom/quota/UsageInfo.h"
17 #include "mozilla/OriginAttributes.h"
19 namespace IPC {
21 template <>
22 struct ParamTraits<mozilla::dom::quota::PersistenceType>
23 : public ContiguousEnumSerializer<
24 mozilla::dom::quota::PersistenceType,
25 mozilla::dom::quota::PERSISTENCE_TYPE_PERSISTENT,
26 mozilla::dom::quota::PERSISTENCE_TYPE_INVALID> {};
28 template <>
29 struct ParamTraits<mozilla::dom::quota::Client::Type>
30 : public ContiguousEnumSerializer<mozilla::dom::quota::Client::Type,
31 mozilla::dom::quota::Client::IDB,
32 mozilla::dom::quota::Client::TYPE_MAX> {};
34 template <>
35 struct ParamTraits<mozilla::dom::quota::FullOriginMetadata> {
36 using ParamType = mozilla::dom::quota::FullOriginMetadata;
38 static void Write(MessageWriter* aWriter, const ParamType& aParam) {
39 WriteParam(aWriter, aParam.mSuffix);
40 WriteParam(aWriter, aParam.mGroup);
41 WriteParam(aWriter, aParam.mOrigin);
42 WriteParam(aWriter, aParam.mStorageOrigin);
43 WriteParam(aWriter, aParam.mIsPrivate);
44 WriteParam(aWriter, aParam.mPersistenceType);
45 WriteParam(aWriter, aParam.mPersisted);
46 WriteParam(aWriter, aParam.mLastAccessTime);
49 static bool Read(MessageReader* aReader, ParamType* aResult) {
50 return ReadParam(aReader, &aResult->mSuffix) &&
51 ReadParam(aReader, &aResult->mGroup) &&
52 ReadParam(aReader, &aResult->mOrigin) &&
53 ReadParam(aReader, &aResult->mStorageOrigin) &&
54 ReadParam(aReader, &aResult->mIsPrivate) &&
55 ReadParam(aReader, &aResult->mPersistenceType) &&
56 ReadParam(aReader, &aResult->mPersisted) &&
57 ReadParam(aReader, &aResult->mLastAccessTime);
61 template <>
62 struct ParamTraits<mozilla::OriginAttributesPattern> {
63 typedef mozilla::OriginAttributesPattern paramType;
65 static void Write(MessageWriter* aWriter, const paramType& aParam) {
66 WriteParam(aWriter, aParam.mFirstPartyDomain);
67 WriteParam(aWriter, aParam.mPrivateBrowsingId);
68 WriteParam(aWriter, aParam.mUserContextId);
69 WriteParam(aWriter, aParam.mGeckoViewSessionContextId);
72 static bool Read(MessageReader* aReader, paramType* aResult) {
73 return ReadParam(aReader, &aResult->mFirstPartyDomain) &&
74 ReadParam(aReader, &aResult->mPrivateBrowsingId) &&
75 ReadParam(aReader, &aResult->mUserContextId) &&
76 ReadParam(aReader, &aResult->mGeckoViewSessionContextId);
80 template <>
81 struct ParamTraits<mozilla::dom::quota::DatabaseUsageType> {
82 using ParamType = mozilla::dom::quota::DatabaseUsageType;
84 static void Write(MessageWriter* aWriter, const ParamType& aParam) {
85 WriteParam(aWriter, aParam.GetValue());
88 static bool Read(MessageReader* aReader, ParamType* aResult) {
89 mozilla::Maybe<uint64_t> value;
90 if (!ReadParam(aReader, &value)) {
91 return false;
94 *aResult += ParamType(value);
95 return true;
99 template <>
100 struct ParamTraits<mozilla::dom::quota::FileUsageType> {
101 using ParamType = mozilla::dom::quota::FileUsageType;
103 static void Write(MessageWriter* aWriter, const ParamType& aParam) {
104 WriteParam(aWriter, aParam.GetValue());
107 static bool Read(MessageReader* aReader, ParamType* aResult) {
108 mozilla::Maybe<uint64_t> value;
109 if (!ReadParam(aReader, &value)) {
110 return false;
113 *aResult += ParamType(value);
114 return true;
118 template <>
119 struct ParamTraits<mozilla::dom::quota::UsageInfo> {
120 using ParamType = mozilla::dom::quota::UsageInfo;
122 static void Write(MessageWriter* aWriter, const ParamType& aParam) {
123 WriteParam(aWriter, aParam.DatabaseUsage());
124 WriteParam(aWriter, aParam.FileUsage());
127 static bool Read(MessageReader* aReader, ParamType* aResult) {
128 mozilla::Maybe<uint64_t> databaseUsage;
129 if (!ReadParam(aReader, &databaseUsage)) {
130 return false;
133 mozilla::Maybe<uint64_t> fileUsage;
134 if (!ReadParam(aReader, &fileUsage)) {
135 return false;
138 *aResult += mozilla::dom::quota::DatabaseUsageType(databaseUsage);
139 *aResult += mozilla::dom::quota::FileUsageType(fileUsage);
140 return true;
144 } // namespace IPC
146 #endif // mozilla_dom_quota_SerializationHelpers_h