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

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

Issue 10272018: Move IndexedDBKey, IndexedDBKeyRange into content namespace (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Use "using content::*" aliasing for IDB/SSV types Created 8 years, 7 months 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/common/indexed_db/indexed_db_param_traits.h" 5 #include "content/common/indexed_db/indexed_db_param_traits.h"
6 6
7 #include "content/common/indexed_db/indexed_db_key.h" 7 #include "content/common/indexed_db/indexed_db_key.h"
8 #include "content/common/indexed_db/indexed_db_key_path.h" 8 #include "content/common/indexed_db/indexed_db_key_path.h"
9 #include "content/common/indexed_db/indexed_db_key_range.h" 9 #include "content/common/indexed_db/indexed_db_key_range.h"
10 #include "content/public/common/serialized_script_value.h" 10 #include "content/public/common/serialized_script_value.h"
11 #include "ipc/ipc_message_utils.h" 11 #include "ipc/ipc_message_utils.h"
12 12
13 using content::IndexedDBKey;
14 using content::IndexedDBKeyPath;
15 using content::IndexedDBKeyRange;
16 using content::SerializedScriptValue;
17
13 namespace IPC { 18 namespace IPC {
14 19
15 void ParamTraits<content::SerializedScriptValue>::Write(Message* m, 20 void ParamTraits<SerializedScriptValue>::Write(Message* m,
16 const param_type& p) { 21 const param_type& p) {
17 WriteParam(m, p.is_null()); 22 WriteParam(m, p.is_null());
18 WriteParam(m, p.is_invalid()); 23 WriteParam(m, p.is_invalid());
19 WriteParam(m, p.data()); 24 WriteParam(m, p.data());
20 } 25 }
21 26
22 bool ParamTraits<content::SerializedScriptValue>::Read(const Message* m, 27 bool ParamTraits<SerializedScriptValue>::Read(const Message* m,
23 PickleIterator* iter, 28 PickleIterator* iter,
24 param_type* r) { 29 param_type* r) {
25 bool is_null; 30 bool is_null;
26 bool is_invalid; 31 bool is_invalid;
27 string16 data; 32 string16 data;
28 bool ok = 33 bool ok =
29 ReadParam(m, iter, &is_null) && 34 ReadParam(m, iter, &is_null) &&
30 ReadParam(m, iter, &is_invalid) && 35 ReadParam(m, iter, &is_invalid) &&
31 ReadParam(m, iter, &data); 36 ReadParam(m, iter, &data);
32 if (!ok) 37 if (!ok)
33 return false; 38 return false;
34 r->set_is_null(is_null); 39 r->set_is_null(is_null);
35 r->set_is_invalid(is_invalid); 40 r->set_is_invalid(is_invalid);
36 r->set_data(data); 41 r->set_data(data);
37 return true; 42 return true;
38 } 43 }
39 44
40 void ParamTraits<content::SerializedScriptValue>::Log(const param_type& p, 45 void ParamTraits<SerializedScriptValue>::Log(const param_type& p,
41 std::string* l) { 46 std::string* l) {
42 l->append("<SerializedScriptValue>("); 47 l->append("<SerializedScriptValue>(");
43 LogParam(p.is_null(), l); 48 LogParam(p.is_null(), l);
44 l->append(", "); 49 l->append(", ");
45 LogParam(p.is_invalid(), l); 50 LogParam(p.is_invalid(), l);
46 l->append(", "); 51 l->append(", ");
47 LogParam(p.data(), l); 52 LogParam(p.data(), l);
48 l->append(")"); 53 l->append(")");
49 } 54 }
50 55
51 void ParamTraits<IndexedDBKey>::Write(Message* m, const param_type& p) { 56 void ParamTraits<IndexedDBKey>::Write(Message* m,
57 const param_type& p) {
52 WriteParam(m, int(p.type())); 58 WriteParam(m, int(p.type()));
53 switch (p.type()) { 59 switch (p.type()) {
54 case WebKit::WebIDBKey::ArrayType: 60 case WebKit::WebIDBKey::ArrayType:
55 WriteParam(m, p.array()); 61 WriteParam(m, p.array());
56 return; 62 return;
57 case WebKit::WebIDBKey::StringType: 63 case WebKit::WebIDBKey::StringType:
58 WriteParam(m, p.string()); 64 WriteParam(m, p.string());
59 return; 65 return;
60 case WebKit::WebIDBKey::DateType: 66 case WebKit::WebIDBKey::DateType:
61 WriteParam(m, p.date()); 67 WriteParam(m, p.date());
62 return; 68 return;
63 case WebKit::WebIDBKey::NumberType: 69 case WebKit::WebIDBKey::NumberType:
64 WriteParam(m, p.number()); 70 WriteParam(m, p.number());
65 return; 71 return;
66 case WebKit::WebIDBKey::InvalidType: 72 case WebKit::WebIDBKey::InvalidType:
67 case WebKit::WebIDBKey::NullType: 73 case WebKit::WebIDBKey::NullType:
68 return; 74 return;
69 } 75 }
70 NOTREACHED(); 76 NOTREACHED();
71 } 77 }
72 78
73 bool ParamTraits<IndexedDBKey>::Read(const Message* m, 79 bool ParamTraits<IndexedDBKey>::Read(const Message* m,
74 PickleIterator* iter, 80 PickleIterator* iter,
75 param_type* r) { 81 param_type* r) {
76 int type; 82 int type;
77 if (!ReadParam(m, iter, &type)) 83 if (!ReadParam(m, iter, &type))
78 return false; 84 return false;
79 85
80 switch (type) { 86 switch (type) {
81 case WebKit::WebIDBKey::ArrayType: 87 case WebKit::WebIDBKey::ArrayType: {
82 { 88 std::vector<IndexedDBKey> array;
83 std::vector<IndexedDBKey> array; 89 if (!ReadParam(m, iter, &array))
84 if (!ReadParam(m, iter, &array)) 90 return false;
85 return false; 91 r->SetArray(array);
86 r->SetArray(array); 92 return true;
87 return true; 93 }
88 } 94 case WebKit::WebIDBKey::StringType: {
89 case WebKit::WebIDBKey::StringType: 95 string16 string;
90 { 96 if (!ReadParam(m, iter, &string))
91 string16 string; 97 return false;
92 if (!ReadParam(m, iter, &string)) 98 r->SetString(string);
93 return false; 99 return true;
94 r->SetString(string); 100 }
95 return true; 101 case WebKit::WebIDBKey::DateType: {
96 } 102 double date;
97 case WebKit::WebIDBKey::DateType: 103 if (!ReadParam(m, iter, &date))
98 { 104 return false;
99 double date; 105 r->SetDate(date);
100 if (!ReadParam(m, iter, &date)) 106 return true;
101 return false; 107 }
102 r->SetDate(date); 108 case WebKit::WebIDBKey::NumberType: {
103 return true; 109 double number;
104 } 110 if (!ReadParam(m, iter, &number))
105 case WebKit::WebIDBKey::NumberType: 111 return false;
106 { 112 r->SetNumber(number);
107 double number; 113 return true;
108 if (!ReadParam(m, iter, &number)) 114 }
109 return false;
110 r->SetNumber(number);
111 return true;
112 }
113 case WebKit::WebIDBKey::InvalidType: 115 case WebKit::WebIDBKey::InvalidType:
114 r->SetInvalid(); 116 r->SetInvalid();
115 return true; 117 return true;
116 case WebKit::WebIDBKey::NullType: 118 case WebKit::WebIDBKey::NullType:
117 r->SetNull(); 119 r->SetNull();
118 return true; 120 return true;
119 } 121 }
120 NOTREACHED(); 122 NOTREACHED();
121 return false; 123 return false;
122 } 124 }
123 125
124 void ParamTraits<IndexedDBKey>::Log(const param_type& p, std::string* l) { 126 void ParamTraits<IndexedDBKey>::Log(const param_type& p,
127 std::string* l) {
125 l->append("<IndexedDBKey>("); 128 l->append("<IndexedDBKey>(");
126 LogParam(int(p.type()), l); 129 LogParam(int(p.type()), l);
127 l->append(", "); 130 l->append(", ");
128 l->append("["); 131 l->append("[");
129 std::vector<IndexedDBKey>::const_iterator it = p.array().begin(); 132 std::vector<IndexedDBKey>::const_iterator it = p.array().begin();
130 while (it != p.array().end()) { 133 while (it != p.array().end()) {
131 Log(*it, l); 134 Log(*it, l);
132 ++it; 135 ++it;
133 if (it != p.array().end()) 136 if (it != p.array().end())
134 l->append(", "); 137 l->append(", ");
135 } 138 }
136 l->append("], "); 139 l->append("], ");
137 LogParam(p.string(), l); 140 LogParam(p.string(), l);
138 l->append(", "); 141 l->append(", ");
139 LogParam(p.date(), l); 142 LogParam(p.date(), l);
140 l->append(", "); 143 l->append(", ");
141 LogParam(p.number(), l); 144 LogParam(p.number(), l);
142 l->append(")"); 145 l->append(")");
143 } 146 }
144 147
145 void ParamTraits<content::IndexedDBKeyPath>::Write(Message* m, 148 void ParamTraits<IndexedDBKeyPath>::Write(Message* m,
146 const param_type& p) { 149 const param_type& p) {
147 WriteParam(m, int(p.type())); 150 WriteParam(m, int(p.type()));
148 switch (p.type()) { 151 switch (p.type()) {
149 case WebKit::WebIDBKeyPath::ArrayType: 152 case WebKit::WebIDBKeyPath::ArrayType:
150 WriteParam(m, p.array()); 153 WriteParam(m, p.array());
151 return; 154 return;
152 case WebKit::WebIDBKeyPath::StringType: 155 case WebKit::WebIDBKeyPath::StringType:
153 WriteParam(m, p.string()); 156 WriteParam(m, p.string());
154 return; 157 return;
155 case WebKit::WebIDBKeyPath::NullType: 158 case WebKit::WebIDBKeyPath::NullType:
156 return; 159 return;
157 } 160 }
158 NOTREACHED(); 161 NOTREACHED();
159 } 162 }
160 163
161 bool ParamTraits<content::IndexedDBKeyPath>::Read(const Message* m, 164 bool ParamTraits<IndexedDBKeyPath>::Read(const Message* m,
162 PickleIterator* iter, 165 PickleIterator* iter,
163 param_type* r) { 166 param_type* r) {
164 int type; 167 int type;
165 if (!ReadParam(m, iter, &type)) 168 if (!ReadParam(m, iter, &type))
166 return false; 169 return false;
167 170
168 switch (type) { 171 switch (type) {
169 case WebKit::WebIDBKeyPath::ArrayType: { 172 case WebKit::WebIDBKeyPath::ArrayType: {
170 std::vector<string16> array; 173 std::vector<string16> array;
171 if (!ReadParam(m, iter, &array)) 174 if (!ReadParam(m, iter, &array))
172 return false; 175 return false;
173 r->SetArray(array); 176 r->SetArray(array);
174 return true; 177 return true;
175 } 178 }
176 case WebKit::WebIDBKeyPath::StringType: { 179 case WebKit::WebIDBKeyPath::StringType: {
177 string16 string; 180 string16 string;
178 if (!ReadParam(m, iter, &string)) 181 if (!ReadParam(m, iter, &string))
179 return false; 182 return false;
180 r->SetString(string); 183 r->SetString(string);
181 return true; 184 return true;
182 } 185 }
183 case WebKit::WebIDBKeyPath::NullType: 186 case WebKit::WebIDBKeyPath::NullType:
184 r->SetNull(); 187 r->SetNull();
185 return true; 188 return true;
186 } 189 }
187 NOTREACHED(); 190 NOTREACHED();
188 return false; 191 return false;
189 } 192 }
190 193
191 void ParamTraits<content::IndexedDBKeyPath>::Log(const param_type& p, 194 void ParamTraits<IndexedDBKeyPath>::Log(const param_type& p,
192 std::string* l) { 195 std::string* l) {
193 l->append("<IndexedDBKeyPath>("); 196 l->append("<IndexedDBKeyPath>(");
194 LogParam(int(p.type()), l); 197 LogParam(int(p.type()), l);
195 l->append(", "); 198 l->append(", ");
196 LogParam(p.string(), l); 199 LogParam(p.string(), l);
197 l->append(", "); 200 l->append(", ");
198 l->append("["); 201 l->append("[");
199 std::vector<string16>::const_iterator it = p.array().begin(); 202 std::vector<string16>::const_iterator it = p.array().begin();
200 while (it != p.array().end()) { 203 while (it != p.array().end()) {
201 LogParam(*it, l); 204 LogParam(*it, l);
202 ++it; 205 ++it;
203 if (it != p.array().end()) 206 if (it != p.array().end())
204 l->append(", "); 207 l->append(", ");
205 } 208 }
206 l->append("])"); 209 l->append("])");
207 } 210 }
208 211
209 void ParamTraits<IndexedDBKeyRange>::Write(Message* m, const param_type& p) { 212 void ParamTraits<IndexedDBKeyRange>::Write(Message* m,
213 const param_type& p) {
210 WriteParam(m, p.lower()); 214 WriteParam(m, p.lower());
211 WriteParam(m, p.upper()); 215 WriteParam(m, p.upper());
212 WriteParam(m, p.lowerOpen()); 216 WriteParam(m, p.lowerOpen());
213 WriteParam(m, p.upperOpen()); 217 WriteParam(m, p.upperOpen());
214 } 218 }
215 219
216 bool ParamTraits<IndexedDBKeyRange>::Read(const Message* m, 220 bool ParamTraits<IndexedDBKeyRange>::Read(const Message* m,
217 PickleIterator* iter, 221 PickleIterator* iter,
218 param_type* r) { 222 param_type* r) {
219
220 IndexedDBKey lower; 223 IndexedDBKey lower;
221 if (!ReadParam(m, iter, &lower)) 224 if (!ReadParam(m, iter, &lower))
222 return false; 225 return false;
223 226
224 IndexedDBKey upper; 227 IndexedDBKey upper;
225 if (!ReadParam(m, iter, &upper)) 228 if (!ReadParam(m, iter, &upper))
226 return false; 229 return false;
227 230
228 bool lower_open; 231 bool lower_open;
229 if (!ReadParam(m, iter, &lower_open)) 232 if (!ReadParam(m, iter, &lower_open))
230 return false; 233 return false;
231 234
232 bool upper_open; 235 bool upper_open;
233 if (!ReadParam(m, iter, &upper_open)) 236 if (!ReadParam(m, iter, &upper_open))
234 return false; 237 return false;
235 238
236 r->Set(lower, upper, lower_open, upper_open); 239 r->Set(lower, upper, lower_open, upper_open);
237 return true; 240 return true;
238 } 241 }
239 242
240 void ParamTraits<IndexedDBKeyRange>::Log(const param_type& p, std::string* l) { 243 void ParamTraits<IndexedDBKeyRange>::Log(const param_type& p,
244 std::string* l) {
241 l->append("<IndexedDBKeyRange>(lower="); 245 l->append("<IndexedDBKeyRange>(lower=");
242 LogParam(p.lower(), l); 246 LogParam(p.lower(), l);
243 l->append(", upper="); 247 l->append(", upper=");
244 LogParam(p.upper(), l); 248 LogParam(p.upper(), l);
245 l->append(", lower_open="); 249 l->append(", lower_open=");
246 LogParam(p.lowerOpen(), l); 250 LogParam(p.lowerOpen(), l);
247 l->append(", upper_open="); 251 l->append(", upper_open=");
248 LogParam(p.upperOpen(), l); 252 LogParam(p.upperOpen(), l);
249 l->append(")"); 253 l->append(")");
250 } 254 }
251 255
252 } // namespace IPC 256 } // namespace IPC
OLDNEW
« no previous file with comments | « content/common/indexed_db/indexed_db_param_traits.h ('k') | content/common/indexed_db/proxy_webidbcursor_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698