Bug 1941046 - Part 4: Send a callback request for impression and clicks of MARS Top...
[gecko.git] / dom / quota / SerializationHelpers.h
blob74d46bd9551d7cb88d4bd7db57eaf2cd9a38fa76
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::dom::quota::OriginUsageMetadata> {
63 using ParamType = mozilla::dom::quota::OriginUsageMetadata;
65 static void Write(MessageWriter* aWriter, const ParamType& aParam) {
66 ParamTraits<mozilla::dom::quota::FullOriginMetadata>::Write(aWriter,
67 aParam);
68 WriteParam(aWriter, aParam.mUsage);
71 static bool Read(MessageReader* aReader, ParamType* aResult) {
72 return ParamTraits<mozilla::dom::quota::FullOriginMetadata>::Read(
73 aReader, aResult) &&
74 ReadParam(aReader, &aResult->mUsage);
78 template <>
79 struct ParamTraits<mozilla::OriginAttributesPattern> {
80 typedef mozilla::OriginAttributesPattern paramType;
82 static void Write(MessageWriter* aWriter, const paramType& aParam) {
83 WriteParam(aWriter, aParam.mFirstPartyDomain);
84 WriteParam(aWriter, aParam.mPrivateBrowsingId);
85 WriteParam(aWriter, aParam.mUserContextId);
86 WriteParam(aWriter, aParam.mGeckoViewSessionContextId);
87 WriteParam(aWriter, aParam.mPartitionKey);
88 WriteParam(aWriter, aParam.mPartitionKeyPattern);
91 static bool Read(MessageReader* aReader, paramType* aResult) {
92 return ReadParam(aReader, &aResult->mFirstPartyDomain) &&
93 ReadParam(aReader, &aResult->mPrivateBrowsingId) &&
94 ReadParam(aReader, &aResult->mUserContextId) &&
95 ReadParam(aReader, &aResult->mGeckoViewSessionContextId) &&
96 ReadParam(aReader, &aResult->mPartitionKey) &&
97 ReadParam(aReader, &aResult->mPartitionKeyPattern);
101 template <>
102 struct ParamTraits<mozilla::dom::PartitionKeyPatternDictionary> {
103 typedef mozilla::dom::PartitionKeyPatternDictionary paramType;
105 static void Write(MessageWriter* aWriter, const paramType& aParam) {
106 WriteParam(aWriter, aParam.mScheme);
107 WriteParam(aWriter, aParam.mBaseDomain);
108 WriteParam(aWriter, aParam.mPort);
109 WriteParam(aWriter, aParam.mForeignByAncestorContext);
112 static bool Read(MessageReader* aReader, paramType* aResult) {
113 return ReadParam(aReader, &aResult->mScheme) &&
114 ReadParam(aReader, &aResult->mBaseDomain) &&
115 ReadParam(aReader, &aResult->mPort) &&
116 ReadParam(aReader, &aResult->mForeignByAncestorContext);
120 template <>
121 struct ParamTraits<mozilla::dom::quota::DatabaseUsageType> {
122 using ParamType = mozilla::dom::quota::DatabaseUsageType;
124 static void Write(MessageWriter* aWriter, const ParamType& aParam) {
125 WriteParam(aWriter, aParam.GetValue());
128 static bool Read(MessageReader* aReader, ParamType* aResult) {
129 mozilla::Maybe<uint64_t> value;
130 if (!ReadParam(aReader, &value)) {
131 return false;
134 *aResult += ParamType(value);
135 return true;
139 template <>
140 struct ParamTraits<mozilla::dom::quota::FileUsageType> {
141 using ParamType = mozilla::dom::quota::FileUsageType;
143 static void Write(MessageWriter* aWriter, const ParamType& aParam) {
144 WriteParam(aWriter, aParam.GetValue());
147 static bool Read(MessageReader* aReader, ParamType* aResult) {
148 mozilla::Maybe<uint64_t> value;
149 if (!ReadParam(aReader, &value)) {
150 return false;
153 *aResult += ParamType(value);
154 return true;
158 template <>
159 struct ParamTraits<mozilla::dom::quota::UsageInfo> {
160 using ParamType = mozilla::dom::quota::UsageInfo;
162 static void Write(MessageWriter* aWriter, const ParamType& aParam) {
163 WriteParam(aWriter, aParam.DatabaseUsage());
164 WriteParam(aWriter, aParam.FileUsage());
167 static bool Read(MessageReader* aReader, ParamType* aResult) {
168 mozilla::Maybe<uint64_t> databaseUsage;
169 if (!ReadParam(aReader, &databaseUsage)) {
170 return false;
173 mozilla::Maybe<uint64_t> fileUsage;
174 if (!ReadParam(aReader, &fileUsage)) {
175 return false;
178 *aResult += mozilla::dom::quota::DatabaseUsageType(databaseUsage);
179 *aResult += mozilla::dom::quota::FileUsageType(fileUsage);
180 return true;
184 } // namespace IPC
186 #endif // mozilla_dom_quota_SerializationHelpers_h