1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "content/common/indexed_db/indexed_db_param_traits.h"
9 #include "content/common/indexed_db/indexed_db_key.h"
10 #include "content/common/indexed_db/indexed_db_key_path.h"
11 #include "content/common/indexed_db/indexed_db_key_range.h"
12 #include "ipc/ipc_message_utils.h"
14 using content::IndexedDBKey
;
15 using content::IndexedDBKeyPath
;
16 using content::IndexedDBKeyRange
;
18 using blink::WebIDBKeyPathTypeArray
;
19 using blink::WebIDBKeyPathTypeNull
;
20 using blink::WebIDBKeyPathTypeString
;
21 using blink::WebIDBKeyType
;
22 using blink::WebIDBKeyTypeArray
;
23 using blink::WebIDBKeyTypeBinary
;
24 using blink::WebIDBKeyTypeDate
;
25 using blink::WebIDBKeyTypeInvalid
;
26 using blink::WebIDBKeyTypeMin
;
27 using blink::WebIDBKeyTypeNull
;
28 using blink::WebIDBKeyTypeNumber
;
29 using blink::WebIDBKeyTypeString
;
33 void ParamTraits
<IndexedDBKey
>::Write(Message
* m
, const param_type
& p
) {
34 WriteParam(m
, static_cast<int>(p
.type()));
36 case WebIDBKeyTypeArray
:
37 WriteParam(m
, p
.array());
39 case WebIDBKeyTypeBinary
:
40 WriteParam(m
, p
.binary());
42 case WebIDBKeyTypeString
:
43 WriteParam(m
, p
.string());
45 case WebIDBKeyTypeDate
:
46 WriteParam(m
, p
.date());
48 case WebIDBKeyTypeNumber
:
49 WriteParam(m
, p
.number());
51 case WebIDBKeyTypeInvalid
:
52 case WebIDBKeyTypeNull
:
54 case WebIDBKeyTypeMin
:
61 bool ParamTraits
<IndexedDBKey
>::Read(const Message
* m
,
62 base::PickleIterator
* iter
,
65 if (!ReadParam(m
, iter
, &type
))
67 WebIDBKeyType web_type
= static_cast<WebIDBKeyType
>(type
);
70 case WebIDBKeyTypeArray
: {
71 std::vector
<IndexedDBKey
> array
;
72 if (!ReadParam(m
, iter
, &array
))
74 *r
= IndexedDBKey(array
);
77 case WebIDBKeyTypeBinary
: {
79 if (!ReadParam(m
, iter
, &binary
))
81 *r
= IndexedDBKey(binary
);
84 case WebIDBKeyTypeString
: {
85 base::string16 string
;
86 if (!ReadParam(m
, iter
, &string
))
88 *r
= IndexedDBKey(string
);
91 case WebIDBKeyTypeDate
:
92 case WebIDBKeyTypeNumber
: {
94 if (!ReadParam(m
, iter
, &number
))
96 *r
= IndexedDBKey(number
, web_type
);
99 case WebIDBKeyTypeInvalid
:
100 case WebIDBKeyTypeNull
:
101 *r
= IndexedDBKey(web_type
);
103 case WebIDBKeyTypeMin
:
110 void ParamTraits
<IndexedDBKey
>::Log(const param_type
& p
, std::string
* l
) {
111 l
->append("<IndexedDBKey>(");
113 case WebIDBKeyTypeArray
: {
117 for (const IndexedDBKey
& key
: p
.array()) {
126 case WebIDBKeyTypeBinary
:
127 l
->append("binary=");
128 LogParam(p
.binary(), l
);
130 case WebIDBKeyTypeString
:
131 l
->append("string=");
132 LogParam(p
.string(), l
);
134 case WebIDBKeyTypeDate
:
136 LogParam(p
.date(), l
);
138 case WebIDBKeyTypeNumber
:
139 l
->append("number=");
140 LogParam(p
.number(), l
);
142 case WebIDBKeyTypeInvalid
:
143 l
->append("invalid");
145 case WebIDBKeyTypeNull
:
148 case WebIDBKeyTypeMin
:
156 void ParamTraits
<IndexedDBKeyPath
>::Write(Message
* m
, const param_type
& p
) {
157 WriteParam(m
, static_cast<int>(p
.type()));
159 case WebIDBKeyPathTypeArray
:
160 WriteParam(m
, p
.array());
162 case WebIDBKeyPathTypeString
:
163 WriteParam(m
, p
.string());
165 case WebIDBKeyPathTypeNull
:
173 bool ParamTraits
<IndexedDBKeyPath
>::Read(const Message
* m
,
174 base::PickleIterator
* iter
,
177 if (!ReadParam(m
, iter
, &type
))
181 case WebIDBKeyPathTypeArray
: {
182 std::vector
<base::string16
> array
;
183 if (!ReadParam(m
, iter
, &array
))
185 *r
= IndexedDBKeyPath(array
);
188 case WebIDBKeyPathTypeString
: {
189 base::string16 string
;
190 if (!ReadParam(m
, iter
, &string
))
192 *r
= IndexedDBKeyPath(string
);
195 case WebIDBKeyPathTypeNull
:
196 *r
= IndexedDBKeyPath();
204 void ParamTraits
<IndexedDBKeyPath
>::Log(const param_type
& p
, std::string
* l
) {
205 l
->append("<IndexedDBKeyPath>(");
207 case WebIDBKeyPathTypeArray
: {
208 l
->append("array=[");
210 for (const base::string16
& entry
: p
.array()) {
219 case WebIDBKeyPathTypeString
:
220 l
->append("string=");
221 LogParam(p
.string(), l
);
223 case WebIDBKeyPathTypeNull
:
233 void ParamTraits
<IndexedDBKeyRange
>::Write(Message
* m
, const param_type
& p
) {
234 WriteParam(m
, p
.lower());
235 WriteParam(m
, p
.upper());
236 WriteParam(m
, p
.lower_open());
237 WriteParam(m
, p
.upper_open());
240 bool ParamTraits
<IndexedDBKeyRange
>::Read(const Message
* m
,
241 base::PickleIterator
* iter
,
244 if (!ReadParam(m
, iter
, &lower
))
248 if (!ReadParam(m
, iter
, &upper
))
252 if (!ReadParam(m
, iter
, &lower_open
))
256 if (!ReadParam(m
, iter
, &upper_open
))
259 *r
= IndexedDBKeyRange(lower
, upper
, lower_open
, upper_open
);
263 void ParamTraits
<IndexedDBKeyRange
>::Log(const param_type
& p
, std::string
* l
) {
264 l
->append("<IndexedDBKeyRange>(lower=");
265 LogParam(p
.lower(), l
);
266 l
->append(", upper=");
267 LogParam(p
.upper(), l
);
268 l
->append(", lower_open=");
269 LogParam(p
.lower_open(), l
);
270 l
->append(", upper_open=");
271 LogParam(p
.upper_open(), l
);