Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(276)

Side by Side Diff: content/common/indexed_db/indexed_db_param_traits.cc

Issue 2511403003: Send IndexedDB observations through IDBDatabaseCallbacks. (Closed)
Patch Set: Rebased. Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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.
4
5 #include "content/common/indexed_db/indexed_db_param_traits.h"
6
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_range.h"
11 #include "ipc/ipc_message_utils.h"
12
13 using content::IndexedDBKey;
14 using content::IndexedDBKeyRange;
15
16 using blink::WebIDBKeyType;
17 using blink::WebIDBKeyTypeArray;
18 using blink::WebIDBKeyTypeBinary;
19 using blink::WebIDBKeyTypeDate;
20 using blink::WebIDBKeyTypeInvalid;
21 using blink::WebIDBKeyTypeMin;
22 using blink::WebIDBKeyTypeNull;
23 using blink::WebIDBKeyTypeNumber;
24 using blink::WebIDBKeyTypeString;
25
26 namespace IPC {
27
28 void ParamTraits<IndexedDBKey>::GetSize(base::PickleSizer* s,
29 const param_type& p) {
30 GetParamSize(s, static_cast<int>(p.type()));
31 switch (p.type()) {
32 case WebIDBKeyTypeArray:
33 GetParamSize(s, p.array());
34 return;
35 case WebIDBKeyTypeBinary:
36 GetParamSize(s, p.binary());
37 return;
38 case WebIDBKeyTypeString:
39 GetParamSize(s, p.string());
40 return;
41 case WebIDBKeyTypeDate:
42 GetParamSize(s, p.date());
43 return;
44 case WebIDBKeyTypeNumber:
45 GetParamSize(s, p.number());
46 return;
47 case WebIDBKeyTypeInvalid:
48 case WebIDBKeyTypeNull:
49 return;
50 case WebIDBKeyTypeMin:
51 default:
52 NOTREACHED();
53 return;
54 }
55 }
56
57 void ParamTraits<IndexedDBKey>::Write(base::Pickle* m, const param_type& p) {
58 WriteParam(m, static_cast<int>(p.type()));
59 switch (p.type()) {
60 case WebIDBKeyTypeArray:
61 WriteParam(m, p.array());
62 return;
63 case WebIDBKeyTypeBinary:
64 WriteParam(m, p.binary());
65 return;
66 case WebIDBKeyTypeString:
67 WriteParam(m, p.string());
68 return;
69 case WebIDBKeyTypeDate:
70 WriteParam(m, p.date());
71 return;
72 case WebIDBKeyTypeNumber:
73 WriteParam(m, p.number());
74 return;
75 case WebIDBKeyTypeInvalid:
76 case WebIDBKeyTypeNull:
77 return;
78 case WebIDBKeyTypeMin:
79 default:
80 NOTREACHED();
81 return;
82 }
83 }
84
85 bool ParamTraits<IndexedDBKey>::Read(const base::Pickle* m,
86 base::PickleIterator* iter,
87 param_type* r) {
88 int type;
89 if (!ReadParam(m, iter, &type))
90 return false;
91 WebIDBKeyType web_type = static_cast<WebIDBKeyType>(type);
92
93 switch (web_type) {
94 case WebIDBKeyTypeArray: {
95 std::vector<IndexedDBKey> array;
96 if (!ReadParam(m, iter, &array))
97 return false;
98 *r = IndexedDBKey(array);
99 return true;
100 }
101 case WebIDBKeyTypeBinary: {
102 std::string binary;
103 if (!ReadParam(m, iter, &binary))
104 return false;
105 *r = IndexedDBKey(binary);
106 return true;
107 }
108 case WebIDBKeyTypeString: {
109 base::string16 string;
110 if (!ReadParam(m, iter, &string))
111 return false;
112 *r = IndexedDBKey(string);
113 return true;
114 }
115 case WebIDBKeyTypeDate:
116 case WebIDBKeyTypeNumber: {
117 double number;
118 if (!ReadParam(m, iter, &number))
119 return false;
120 *r = IndexedDBKey(number, web_type);
121 return true;
122 }
123 case WebIDBKeyTypeInvalid:
124 case WebIDBKeyTypeNull:
125 *r = IndexedDBKey(web_type);
126 return true;
127 case WebIDBKeyTypeMin:
128 default:
129 NOTREACHED();
130 return false;
131 }
132 }
133
134 void ParamTraits<IndexedDBKey>::Log(const param_type& p, std::string* l) {
135 l->append("<IndexedDBKey>(");
136 switch(p.type()) {
137 case WebIDBKeyTypeArray: {
138 l->append("array=");
139 l->append("[");
140 bool first = true;
141 for (const IndexedDBKey& key : p.array()) {
142 if (!first)
143 l->append(", ");
144 first = false;
145 Log(key, l);
146 }
147 l->append("]");
148 break;
149 }
150 case WebIDBKeyTypeBinary:
151 l->append("binary=");
152 LogParam(p.binary(), l);
153 break;
154 case WebIDBKeyTypeString:
155 l->append("string=");
156 LogParam(p.string(), l);
157 break;
158 case WebIDBKeyTypeDate:
159 l->append("date=");
160 LogParam(p.date(), l);
161 break;
162 case WebIDBKeyTypeNumber:
163 l->append("number=");
164 LogParam(p.number(), l);
165 break;
166 case WebIDBKeyTypeInvalid:
167 l->append("invalid");
168 break;
169 case WebIDBKeyTypeNull:
170 l->append("null");
171 break;
172 case WebIDBKeyTypeMin:
173 default:
174 NOTREACHED();
175 break;
176 }
177 l->append(")");
178 }
179
180 void ParamTraits<IndexedDBKeyRange>::GetSize(base::PickleSizer* s,
181 const param_type& p) {
182 GetParamSize(s, p.lower());
183 GetParamSize(s, p.upper());
184 GetParamSize(s, p.lower_open());
185 GetParamSize(s, p.upper_open());
186 }
187
188 void ParamTraits<IndexedDBKeyRange>::Write(base::Pickle* m,
189 const param_type& p) {
190 WriteParam(m, p.lower());
191 WriteParam(m, p.upper());
192 WriteParam(m, p.lower_open());
193 WriteParam(m, p.upper_open());
194 }
195
196 bool ParamTraits<IndexedDBKeyRange>::Read(const base::Pickle* m,
197 base::PickleIterator* iter,
198 param_type* r) {
199 IndexedDBKey lower;
200 if (!ReadParam(m, iter, &lower))
201 return false;
202
203 IndexedDBKey upper;
204 if (!ReadParam(m, iter, &upper))
205 return false;
206
207 bool lower_open;
208 if (!ReadParam(m, iter, &lower_open))
209 return false;
210
211 bool upper_open;
212 if (!ReadParam(m, iter, &upper_open))
213 return false;
214
215 *r = IndexedDBKeyRange(lower, upper, lower_open, upper_open);
216 return true;
217 }
218
219 void ParamTraits<IndexedDBKeyRange>::Log(const param_type& p, std::string* l) {
220 l->append("<IndexedDBKeyRange>(lower=");
221 LogParam(p.lower(), l);
222 l->append(", upper=");
223 LogParam(p.upper(), l);
224 l->append(", lower_open=");
225 LogParam(p.lower_open(), l);
226 l->append(", upper_open=");
227 LogParam(p.upper_open(), l);
228 l->append(")");
229 }
230
231 } // namespace IPC
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698