We started redesigning GpuMemoryBuffer interface to handle multiple buffers [0].
[chromium-blink-merge.git] / content / common / indexed_db / indexed_db_param_traits.cc
blob8e714087a8dd9821c976902ad4f0568c8db309d9
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"
7 #include <string>
8 #include <vector>
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;
31 namespace IPC {
33 void ParamTraits<IndexedDBKey>::Write(Message* m, const param_type& p) {
34 WriteParam(m, static_cast<int>(p.type()));
35 switch (p.type()) {
36 case WebIDBKeyTypeArray:
37 WriteParam(m, p.array());
38 return;
39 case WebIDBKeyTypeBinary:
40 WriteParam(m, p.binary());
41 return;
42 case WebIDBKeyTypeString:
43 WriteParam(m, p.string());
44 return;
45 case WebIDBKeyTypeDate:
46 WriteParam(m, p.date());
47 return;
48 case WebIDBKeyTypeNumber:
49 WriteParam(m, p.number());
50 return;
51 case WebIDBKeyTypeInvalid:
52 case WebIDBKeyTypeNull:
53 return;
54 case WebIDBKeyTypeMin:
55 default:
56 NOTREACHED();
57 return;
61 bool ParamTraits<IndexedDBKey>::Read(const Message* m,
62 PickleIterator* iter,
63 param_type* r) {
64 int type;
65 if (!ReadParam(m, iter, &type))
66 return false;
67 WebIDBKeyType web_type = static_cast<WebIDBKeyType>(type);
69 switch (web_type) {
70 case WebIDBKeyTypeArray: {
71 std::vector<IndexedDBKey> array;
72 if (!ReadParam(m, iter, &array))
73 return false;
74 *r = IndexedDBKey(array);
75 return true;
77 case WebIDBKeyTypeBinary: {
78 std::string binary;
79 if (!ReadParam(m, iter, &binary))
80 return false;
81 *r = IndexedDBKey(binary);
82 return true;
84 case WebIDBKeyTypeString: {
85 base::string16 string;
86 if (!ReadParam(m, iter, &string))
87 return false;
88 *r = IndexedDBKey(string);
89 return true;
91 case WebIDBKeyTypeDate:
92 case WebIDBKeyTypeNumber: {
93 double number;
94 if (!ReadParam(m, iter, &number))
95 return false;
96 *r = IndexedDBKey(number, web_type);
97 return true;
99 case WebIDBKeyTypeInvalid:
100 case WebIDBKeyTypeNull:
101 *r = IndexedDBKey(web_type);
102 return true;
103 case WebIDBKeyTypeMin:
104 default:
105 NOTREACHED();
106 return false;
110 void ParamTraits<IndexedDBKey>::Log(const param_type& p, std::string* l) {
111 l->append("<IndexedDBKey>(");
112 LogParam(static_cast<int>(p.type()), l);
113 l->append(", ");
114 l->append("[");
115 std::vector<IndexedDBKey>::const_iterator it = p.array().begin();
116 while (it != p.array().end()) {
117 Log(*it, l);
118 ++it;
119 if (it != p.array().end())
120 l->append(", ");
122 l->append("], ");
123 LogParam(p.binary(), l);
124 l->append(", ");
125 LogParam(p.string(), l);
126 l->append(", ");
127 LogParam(p.date(), l);
128 l->append(", ");
129 LogParam(p.number(), l);
130 l->append(")");
133 void ParamTraits<IndexedDBKeyPath>::Write(Message* m, const param_type& p) {
134 WriteParam(m, static_cast<int>(p.type()));
135 switch (p.type()) {
136 case WebIDBKeyPathTypeArray:
137 WriteParam(m, p.array());
138 return;
139 case WebIDBKeyPathTypeString:
140 WriteParam(m, p.string());
141 return;
142 case WebIDBKeyPathTypeNull:
143 return;
144 default:
145 NOTREACHED();
146 return;
150 bool ParamTraits<IndexedDBKeyPath>::Read(const Message* m,
151 PickleIterator* iter,
152 param_type* r) {
153 int type;
154 if (!ReadParam(m, iter, &type))
155 return false;
157 switch (type) {
158 case WebIDBKeyPathTypeArray: {
159 std::vector<base::string16> array;
160 if (!ReadParam(m, iter, &array))
161 return false;
162 *r = IndexedDBKeyPath(array);
163 return true;
165 case WebIDBKeyPathTypeString: {
166 base::string16 string;
167 if (!ReadParam(m, iter, &string))
168 return false;
169 *r = IndexedDBKeyPath(string);
170 return true;
172 case WebIDBKeyPathTypeNull:
173 *r = IndexedDBKeyPath();
174 return true;
175 default:
176 NOTREACHED();
177 return false;
181 void ParamTraits<IndexedDBKeyPath>::Log(const param_type& p, std::string* l) {
182 l->append("<IndexedDBKeyPath>(");
183 LogParam(static_cast<int>(p.type()), l);
184 l->append(", ");
185 LogParam(p.string(), l);
186 l->append(", ");
187 l->append("[");
188 std::vector<base::string16>::const_iterator it = p.array().begin();
189 while (it != p.array().end()) {
190 LogParam(*it, l);
191 ++it;
192 if (it != p.array().end())
193 l->append(", ");
195 l->append("])");
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,
207 param_type* r) {
208 IndexedDBKey lower;
209 if (!ReadParam(m, iter, &lower))
210 return false;
212 IndexedDBKey upper;
213 if (!ReadParam(m, iter, &upper))
214 return false;
216 bool lower_open;
217 if (!ReadParam(m, iter, &lower_open))
218 return false;
220 bool upper_open;
221 if (!ReadParam(m, iter, &upper_open))
222 return false;
224 *r = IndexedDBKeyRange(lower, upper, lower_open, upper_open);
225 return true;
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);
237 l->append(")");
240 } // namespace IPC