[content shell] hook up testRunner.dumpEditingCallbacks
[chromium-blink-merge.git] / content / common / indexed_db / indexed_db_param_traits.cc
blob65107ea1891a8ce58074523fdfe74d73d3f8f2ce
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 "content/common/indexed_db/indexed_db_key.h"
8 #include "content/common/indexed_db/indexed_db_key_path.h"
9 #include "content/common/indexed_db/indexed_db_key_range.h"
10 #include "content/public/common/serialized_script_value.h"
11 #include "ipc/ipc_message_utils.h"
13 using content::IndexedDBKey;
14 using content::IndexedDBKeyPath;
15 using content::IndexedDBKeyRange;
16 using content::SerializedScriptValue;
18 namespace IPC {
20 void ParamTraits<SerializedScriptValue>::Write(Message* m,
21 const param_type& p) {
22 WriteParam(m, p.is_null());
23 WriteParam(m, p.is_invalid());
24 WriteParam(m, p.data());
27 bool ParamTraits<SerializedScriptValue>::Read(const Message* m,
28 PickleIterator* iter,
29 param_type* r) {
30 bool is_null;
31 bool is_invalid;
32 string16 data;
33 bool ok =
34 ReadParam(m, iter, &is_null) &&
35 ReadParam(m, iter, &is_invalid) &&
36 ReadParam(m, iter, &data);
37 if (!ok)
38 return false;
39 r->set_is_null(is_null);
40 r->set_is_invalid(is_invalid);
41 r->set_data(data);
42 return true;
45 void ParamTraits<SerializedScriptValue>::Log(const param_type& p,
46 std::string* l) {
47 l->append("<SerializedScriptValue>(");
48 LogParam(p.is_null(), l);
49 l->append(", ");
50 LogParam(p.is_invalid(), l);
51 l->append(", ");
52 LogParam(p.data(), l);
53 l->append(")");
56 void ParamTraits<IndexedDBKey>::Write(Message* m,
57 const param_type& p) {
58 WriteParam(m, int(p.type()));
59 switch (p.type()) {
60 case WebKit::WebIDBKey::ArrayType:
61 WriteParam(m, p.array());
62 return;
63 case WebKit::WebIDBKey::StringType:
64 WriteParam(m, p.string());
65 return;
66 case WebKit::WebIDBKey::DateType:
67 WriteParam(m, p.date());
68 return;
69 case WebKit::WebIDBKey::NumberType:
70 WriteParam(m, p.number());
71 return;
72 case WebKit::WebIDBKey::InvalidType:
73 case WebKit::WebIDBKey::NullType:
74 return;
76 NOTREACHED();
79 bool ParamTraits<IndexedDBKey>::Read(const Message* m,
80 PickleIterator* iter,
81 param_type* r) {
82 int type;
83 if (!ReadParam(m, iter, &type))
84 return false;
86 switch (type) {
87 case WebKit::WebIDBKey::ArrayType: {
88 std::vector<IndexedDBKey> array;
89 if (!ReadParam(m, iter, &array))
90 return false;
91 r->SetArray(array);
92 return true;
94 case WebKit::WebIDBKey::StringType: {
95 string16 string;
96 if (!ReadParam(m, iter, &string))
97 return false;
98 r->SetString(string);
99 return true;
101 case WebKit::WebIDBKey::DateType: {
102 double date;
103 if (!ReadParam(m, iter, &date))
104 return false;
105 r->SetDate(date);
106 return true;
108 case WebKit::WebIDBKey::NumberType: {
109 double number;
110 if (!ReadParam(m, iter, &number))
111 return false;
112 r->SetNumber(number);
113 return true;
115 case WebKit::WebIDBKey::InvalidType:
116 r->SetInvalid();
117 return true;
118 case WebKit::WebIDBKey::NullType:
119 r->SetNull();
120 return true;
122 NOTREACHED();
123 return false;
126 void ParamTraits<IndexedDBKey>::Log(const param_type& p,
127 std::string* l) {
128 l->append("<IndexedDBKey>(");
129 LogParam(int(p.type()), l);
130 l->append(", ");
131 l->append("[");
132 std::vector<IndexedDBKey>::const_iterator it = p.array().begin();
133 while (it != p.array().end()) {
134 Log(*it, l);
135 ++it;
136 if (it != p.array().end())
137 l->append(", ");
139 l->append("], ");
140 LogParam(p.string(), l);
141 l->append(", ");
142 LogParam(p.date(), l);
143 l->append(", ");
144 LogParam(p.number(), l);
145 l->append(")");
148 void ParamTraits<IndexedDBKeyPath>::Write(Message* m,
149 const param_type& p) {
150 WriteParam(m, int(p.type()));
151 switch (p.type()) {
152 case WebKit::WebIDBKeyPath::ArrayType:
153 WriteParam(m, p.array());
154 return;
155 case WebKit::WebIDBKeyPath::StringType:
156 WriteParam(m, p.string());
157 return;
158 case WebKit::WebIDBKeyPath::NullType:
159 return;
161 NOTREACHED();
164 bool ParamTraits<IndexedDBKeyPath>::Read(const Message* m,
165 PickleIterator* iter,
166 param_type* r) {
167 int type;
168 if (!ReadParam(m, iter, &type))
169 return false;
171 switch (type) {
172 case WebKit::WebIDBKeyPath::ArrayType: {
173 std::vector<string16> array;
174 if (!ReadParam(m, iter, &array))
175 return false;
176 r->SetArray(array);
177 return true;
179 case WebKit::WebIDBKeyPath::StringType: {
180 string16 string;
181 if (!ReadParam(m, iter, &string))
182 return false;
183 r->SetString(string);
184 return true;
186 case WebKit::WebIDBKeyPath::NullType:
187 r->SetNull();
188 return true;
190 NOTREACHED();
191 return false;
194 void ParamTraits<IndexedDBKeyPath>::Log(const param_type& p,
195 std::string* l) {
196 l->append("<IndexedDBKeyPath>(");
197 LogParam(int(p.type()), l);
198 l->append(", ");
199 LogParam(p.string(), l);
200 l->append(", ");
201 l->append("[");
202 std::vector<string16>::const_iterator it = p.array().begin();
203 while (it != p.array().end()) {
204 LogParam(*it, l);
205 ++it;
206 if (it != p.array().end())
207 l->append(", ");
209 l->append("])");
212 void ParamTraits<IndexedDBKeyRange>::Write(Message* m,
213 const param_type& p) {
214 WriteParam(m, p.lower());
215 WriteParam(m, p.upper());
216 WriteParam(m, p.lowerOpen());
217 WriteParam(m, p.upperOpen());
220 bool ParamTraits<IndexedDBKeyRange>::Read(const Message* m,
221 PickleIterator* iter,
222 param_type* r) {
223 IndexedDBKey lower;
224 if (!ReadParam(m, iter, &lower))
225 return false;
227 IndexedDBKey upper;
228 if (!ReadParam(m, iter, &upper))
229 return false;
231 bool lower_open;
232 if (!ReadParam(m, iter, &lower_open))
233 return false;
235 bool upper_open;
236 if (!ReadParam(m, iter, &upper_open))
237 return false;
239 r->Set(lower, upper, lower_open, upper_open);
240 return true;
243 void ParamTraits<IndexedDBKeyRange>::Log(const param_type& p,
244 std::string* l) {
245 l->append("<IndexedDBKeyRange>(lower=");
246 LogParam(p.lower(), l);
247 l->append(", upper=");
248 LogParam(p.upper(), l);
249 l->append(", lower_open=");
250 LogParam(p.lowerOpen(), l);
251 l->append(", upper_open=");
252 LogParam(p.upperOpen(), l);
253 l->append(")");
256 } // namespace IPC