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
,
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>(");
112 LogParam(static_cast<int>(p
.type()), l
);
115 std::vector
<IndexedDBKey
>::const_iterator it
= p
.array().begin();
116 while (it
!= p
.array().end()) {
119 if (it
!= p
.array().end())
123 LogParam(p
.binary(), l
);
125 LogParam(p
.string(), l
);
127 LogParam(p
.date(), l
);
129 LogParam(p
.number(), l
);
133 void ParamTraits
<IndexedDBKeyPath
>::Write(Message
* m
, const param_type
& p
) {
134 WriteParam(m
, static_cast<int>(p
.type()));
136 case WebIDBKeyPathTypeArray
:
137 WriteParam(m
, p
.array());
139 case WebIDBKeyPathTypeString
:
140 WriteParam(m
, p
.string());
142 case WebIDBKeyPathTypeNull
:
150 bool ParamTraits
<IndexedDBKeyPath
>::Read(const Message
* m
,
151 PickleIterator
* iter
,
154 if (!ReadParam(m
, iter
, &type
))
158 case WebIDBKeyPathTypeArray
: {
159 std::vector
<base::string16
> array
;
160 if (!ReadParam(m
, iter
, &array
))
162 *r
= IndexedDBKeyPath(array
);
165 case WebIDBKeyPathTypeString
: {
166 base::string16 string
;
167 if (!ReadParam(m
, iter
, &string
))
169 *r
= IndexedDBKeyPath(string
);
172 case WebIDBKeyPathTypeNull
:
173 *r
= IndexedDBKeyPath();
181 void ParamTraits
<IndexedDBKeyPath
>::Log(const param_type
& p
, std::string
* l
) {
182 l
->append("<IndexedDBKeyPath>(");
183 LogParam(static_cast<int>(p
.type()), l
);
185 LogParam(p
.string(), l
);
188 std::vector
<base::string16
>::const_iterator it
= p
.array().begin();
189 while (it
!= p
.array().end()) {
192 if (it
!= p
.array().end())
198 void ParamTraits
<IndexedDBKeyRange
>::Write(Message
* m
, const param_type
& p
) {
199 WriteParam(m
, p
.lower());
200 WriteParam(m
, p
.upper());
201 WriteParam(m
, p
.lower_open());
202 WriteParam(m
, p
.upper_open());
205 bool ParamTraits
<IndexedDBKeyRange
>::Read(const Message
* m
,
206 PickleIterator
* iter
,
209 if (!ReadParam(m
, iter
, &lower
))
213 if (!ReadParam(m
, iter
, &upper
))
217 if (!ReadParam(m
, iter
, &lower_open
))
221 if (!ReadParam(m
, iter
, &upper_open
))
224 *r
= IndexedDBKeyRange(lower
, upper
, lower_open
, upper_open
);
228 void ParamTraits
<IndexedDBKeyRange
>::Log(const param_type
& p
, std::string
* l
) {
229 l
->append("<IndexedDBKeyRange>(lower=");
230 LogParam(p
.lower(), l
);
231 l
->append(", upper=");
232 LogParam(p
.upper(), l
);
233 l
->append(", lower_open=");
234 LogParam(p
.lower_open(), l
);
235 l
->append(", upper_open=");
236 LogParam(p
.upper_open(), l
);