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"
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
> {};
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
> {};
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
);
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
,
68 WriteParam(aWriter
, aParam
.mUsage
);
71 static bool Read(MessageReader
* aReader
, ParamType
* aResult
) {
72 return ParamTraits
<mozilla::dom::quota::FullOriginMetadata
>::Read(
74 ReadParam(aReader
, &aResult
->mUsage
);
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
);
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
);
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
)) {
134 *aResult
+= ParamType(value
);
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
)) {
153 *aResult
+= ParamType(value
);
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
)) {
173 mozilla::Maybe
<uint64_t> fileUsage
;
174 if (!ReadParam(aReader
, &fileUsage
)) {
178 *aResult
+= mozilla::dom::quota::DatabaseUsageType(databaseUsage
);
179 *aResult
+= mozilla::dom::quota::FileUsageType(fileUsage
);
186 #endif // mozilla_dom_quota_SerializationHelpers_h