OLD | NEW |
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 #ifndef IPC_IPC_MESSAGE_UTILS_H_ | 5 #ifndef IPC_IPC_MESSAGE_UTILS_H_ |
6 #define IPC_IPC_MESSAGE_UTILS_H_ | 6 #define IPC_IPC_MESSAGE_UTILS_H_ |
7 | 7 |
8 #include <algorithm> | 8 #include <algorithm> |
9 #include <map> | 9 #include <map> |
10 #include <set> | 10 #include <set> |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 }; | 90 }; |
91 | 91 |
92 template <class P> | 92 template <class P> |
93 static inline void WriteParam(Message* m, const P& p) { | 93 static inline void WriteParam(Message* m, const P& p) { |
94 typedef typename SimilarTypeTraits<P>::Type Type; | 94 typedef typename SimilarTypeTraits<P>::Type Type; |
95 ParamTraits<Type>::Write(m, static_cast<const Type& >(p)); | 95 ParamTraits<Type>::Write(m, static_cast<const Type& >(p)); |
96 } | 96 } |
97 | 97 |
98 template <class P> | 98 template <class P> |
99 static inline bool WARN_UNUSED_RESULT ReadParam(const Message* m, | 99 static inline bool WARN_UNUSED_RESULT ReadParam(const Message* m, |
100 PickleIterator* iter, | 100 base::PickleIterator* iter, |
101 P* p) { | 101 P* p) { |
102 typedef typename SimilarTypeTraits<P>::Type Type; | 102 typedef typename SimilarTypeTraits<P>::Type Type; |
103 return ParamTraits<Type>::Read(m, iter, reinterpret_cast<Type* >(p)); | 103 return ParamTraits<Type>::Read(m, iter, reinterpret_cast<Type* >(p)); |
104 } | 104 } |
105 | 105 |
106 template <class P> | 106 template <class P> |
107 static inline void LogParam(const P& p, std::string* l) { | 107 static inline void LogParam(const P& p, std::string* l) { |
108 typedef typename SimilarTypeTraits<P>::Type Type; | 108 typedef typename SimilarTypeTraits<P>::Type Type; |
109 ParamTraits<Type>::Log(static_cast<const Type& >(p), l); | 109 ParamTraits<Type>::Log(static_cast<const Type& >(p), l); |
110 } | 110 } |
111 | 111 |
112 // Primitive ParamTraits ------------------------------------------------------- | 112 // Primitive ParamTraits ------------------------------------------------------- |
113 | 113 |
114 template <> | 114 template <> |
115 struct ParamTraits<bool> { | 115 struct ParamTraits<bool> { |
116 typedef bool param_type; | 116 typedef bool param_type; |
117 static void Write(Message* m, const param_type& p) { | 117 static void Write(Message* m, const param_type& p) { |
118 m->WriteBool(p); | 118 m->WriteBool(p); |
119 } | 119 } |
120 static bool Read(const Message* m, PickleIterator* iter, param_type* r) { | 120 static bool Read(const Message* m, base::PickleIterator* iter, |
| 121 param_type* r) { |
121 return iter->ReadBool(r); | 122 return iter->ReadBool(r); |
122 } | 123 } |
123 IPC_EXPORT static void Log(const param_type& p, std::string* l); | 124 IPC_EXPORT static void Log(const param_type& p, std::string* l); |
124 }; | 125 }; |
125 | 126 |
126 template <> | 127 template <> |
127 struct IPC_EXPORT ParamTraits<unsigned char> { | 128 struct IPC_EXPORT ParamTraits<unsigned char> { |
128 typedef unsigned char param_type; | 129 typedef unsigned char param_type; |
129 static void Write(Message* m, const param_type& p); | 130 static void Write(Message* m, const param_type& p); |
130 static bool Read(const Message* m, PickleIterator* iter, param_type* r); | 131 static bool Read(const Message* m, PickleIterator* iter, param_type* r); |
131 static void Log(const param_type& p, std::string* l); | 132 static void Log(const param_type& p, std::string* l); |
132 }; | 133 }; |
133 | 134 |
134 template <> | 135 template <> |
135 struct IPC_EXPORT ParamTraits<unsigned short> { | 136 struct IPC_EXPORT ParamTraits<unsigned short> { |
136 typedef unsigned short param_type; | 137 typedef unsigned short param_type; |
137 static void Write(Message* m, const param_type& p); | 138 static void Write(Message* m, const param_type& p); |
138 static bool Read(const Message* m, PickleIterator* iter, param_type* r); | 139 static bool Read(const Message* m, base::PickleIterator* iter, param_type* r); |
139 static void Log(const param_type& p, std::string* l); | 140 static void Log(const param_type& p, std::string* l); |
140 }; | 141 }; |
141 | 142 |
142 template <> | 143 template <> |
143 struct ParamTraits<int> { | 144 struct ParamTraits<int> { |
144 typedef int param_type; | 145 typedef int param_type; |
145 static void Write(Message* m, const param_type& p) { | 146 static void Write(Message* m, const param_type& p) { |
146 m->WriteInt(p); | 147 m->WriteInt(p); |
147 } | 148 } |
148 static bool Read(const Message* m, PickleIterator* iter, param_type* r) { | 149 static bool Read(const Message* m, base::PickleIterator* iter, |
| 150 param_type* r) { |
149 return iter->ReadInt(r); | 151 return iter->ReadInt(r); |
150 } | 152 } |
151 IPC_EXPORT static void Log(const param_type& p, std::string* l); | 153 IPC_EXPORT static void Log(const param_type& p, std::string* l); |
152 }; | 154 }; |
153 | 155 |
154 template <> | 156 template <> |
155 struct ParamTraits<unsigned int> { | 157 struct ParamTraits<unsigned int> { |
156 typedef unsigned int param_type; | 158 typedef unsigned int param_type; |
157 static void Write(Message* m, const param_type& p) { | 159 static void Write(Message* m, const param_type& p) { |
158 m->WriteInt(p); | 160 m->WriteInt(p); |
159 } | 161 } |
160 static bool Read(const Message* m, PickleIterator* iter, param_type* r) { | 162 static bool Read(const Message* m, base::PickleIterator* iter, |
| 163 param_type* r) { |
161 return iter->ReadInt(reinterpret_cast<int*>(r)); | 164 return iter->ReadInt(reinterpret_cast<int*>(r)); |
162 } | 165 } |
163 IPC_EXPORT static void Log(const param_type& p, std::string* l); | 166 IPC_EXPORT static void Log(const param_type& p, std::string* l); |
164 }; | 167 }; |
165 | 168 |
166 template <> | 169 template <> |
167 struct ParamTraits<long> { | 170 struct ParamTraits<long> { |
168 typedef long param_type; | 171 typedef long param_type; |
169 static void Write(Message* m, const param_type& p) { | 172 static void Write(Message* m, const param_type& p) { |
170 m->WriteLongUsingDangerousNonPortableLessPersistableForm(p); | 173 m->WriteLongUsingDangerousNonPortableLessPersistableForm(p); |
171 } | 174 } |
172 static bool Read(const Message* m, PickleIterator* iter, param_type* r) { | 175 static bool Read(const Message* m, base::PickleIterator* iter, |
| 176 param_type* r) { |
173 return iter->ReadLong(r); | 177 return iter->ReadLong(r); |
174 } | 178 } |
175 IPC_EXPORT static void Log(const param_type& p, std::string* l); | 179 IPC_EXPORT static void Log(const param_type& p, std::string* l); |
176 }; | 180 }; |
177 | 181 |
178 template <> | 182 template <> |
179 struct ParamTraits<unsigned long> { | 183 struct ParamTraits<unsigned long> { |
180 typedef unsigned long param_type; | 184 typedef unsigned long param_type; |
181 static void Write(Message* m, const param_type& p) { | 185 static void Write(Message* m, const param_type& p) { |
182 m->WriteLongUsingDangerousNonPortableLessPersistableForm(p); | 186 m->WriteLongUsingDangerousNonPortableLessPersistableForm(p); |
183 } | 187 } |
184 static bool Read(const Message* m, PickleIterator* iter, param_type* r) { | 188 static bool Read(const Message* m, base::PickleIterator* iter, |
| 189 param_type* r) { |
185 return iter->ReadLong(reinterpret_cast<long*>(r)); | 190 return iter->ReadLong(reinterpret_cast<long*>(r)); |
186 } | 191 } |
187 IPC_EXPORT static void Log(const param_type& p, std::string* l); | 192 IPC_EXPORT static void Log(const param_type& p, std::string* l); |
188 }; | 193 }; |
189 | 194 |
190 template <> | 195 template <> |
191 struct ParamTraits<long long> { | 196 struct ParamTraits<long long> { |
192 typedef long long param_type; | 197 typedef long long param_type; |
193 static void Write(Message* m, const param_type& p) { | 198 static void Write(Message* m, const param_type& p) { |
194 m->WriteInt64(static_cast<int64>(p)); | 199 m->WriteInt64(static_cast<int64>(p)); |
195 } | 200 } |
196 static bool Read(const Message* m, PickleIterator* iter, | 201 static bool Read(const Message* m, base::PickleIterator* iter, |
197 param_type* r) { | 202 param_type* r) { |
198 return iter->ReadInt64(reinterpret_cast<int64*>(r)); | 203 return iter->ReadInt64(reinterpret_cast<int64*>(r)); |
199 } | 204 } |
200 IPC_EXPORT static void Log(const param_type& p, std::string* l); | 205 IPC_EXPORT static void Log(const param_type& p, std::string* l); |
201 }; | 206 }; |
202 | 207 |
203 template <> | 208 template <> |
204 struct ParamTraits<unsigned long long> { | 209 struct ParamTraits<unsigned long long> { |
205 typedef unsigned long long param_type; | 210 typedef unsigned long long param_type; |
206 static void Write(Message* m, const param_type& p) { | 211 static void Write(Message* m, const param_type& p) { |
207 m->WriteInt64(p); | 212 m->WriteInt64(p); |
208 } | 213 } |
209 static bool Read(const Message* m, PickleIterator* iter, | 214 static bool Read(const Message* m, base::PickleIterator* iter, |
210 param_type* r) { | 215 param_type* r) { |
211 return iter->ReadInt64(reinterpret_cast<int64*>(r)); | 216 return iter->ReadInt64(reinterpret_cast<int64*>(r)); |
212 } | 217 } |
213 IPC_EXPORT static void Log(const param_type& p, std::string* l); | 218 IPC_EXPORT static void Log(const param_type& p, std::string* l); |
214 }; | 219 }; |
215 | 220 |
216 // Note that the IPC layer doesn't sanitize NaNs and +/- INF values. Clients | 221 // Note that the IPC layer doesn't sanitize NaNs and +/- INF values. Clients |
217 // should be sure to check the sanity of these values after receiving them over | 222 // should be sure to check the sanity of these values after receiving them over |
218 // IPC. | 223 // IPC. |
219 template <> | 224 template <> |
220 struct IPC_EXPORT ParamTraits<float> { | 225 struct IPC_EXPORT ParamTraits<float> { |
221 typedef float param_type; | 226 typedef float param_type; |
222 static void Write(Message* m, const param_type& p) { | 227 static void Write(Message* m, const param_type& p) { |
223 m->WriteFloat(p); | 228 m->WriteFloat(p); |
224 } | 229 } |
225 static bool Read(const Message* m, PickleIterator* iter, param_type* r) { | 230 static bool Read(const Message* m, base::PickleIterator* iter, |
| 231 param_type* r) { |
226 return iter->ReadFloat(r); | 232 return iter->ReadFloat(r); |
227 } | 233 } |
228 static void Log(const param_type& p, std::string* l); | 234 static void Log(const param_type& p, std::string* l); |
229 }; | 235 }; |
230 | 236 |
231 template <> | 237 template <> |
232 struct IPC_EXPORT ParamTraits<double> { | 238 struct IPC_EXPORT ParamTraits<double> { |
233 typedef double param_type; | 239 typedef double param_type; |
234 static void Write(Message* m, const param_type& p); | 240 static void Write(Message* m, const param_type& p); |
235 static bool Read(const Message* m, PickleIterator* iter, param_type* r); | 241 static bool Read(const Message* m, base::PickleIterator* iter, param_type* r); |
236 static void Log(const param_type& p, std::string* l); | 242 static void Log(const param_type& p, std::string* l); |
237 }; | 243 }; |
238 | 244 |
239 // STL ParamTraits ------------------------------------------------------------- | 245 // STL ParamTraits ------------------------------------------------------------- |
240 | 246 |
241 template <> | 247 template <> |
242 struct ParamTraits<std::string> { | 248 struct ParamTraits<std::string> { |
243 typedef std::string param_type; | 249 typedef std::string param_type; |
244 static void Write(Message* m, const param_type& p) { | 250 static void Write(Message* m, const param_type& p) { |
245 m->WriteString(p); | 251 m->WriteString(p); |
246 } | 252 } |
247 static bool Read(const Message* m, PickleIterator* iter, | 253 static bool Read(const Message* m, base::PickleIterator* iter, |
248 param_type* r) { | 254 param_type* r) { |
249 return iter->ReadString(r); | 255 return iter->ReadString(r); |
250 } | 256 } |
251 IPC_EXPORT static void Log(const param_type& p, std::string* l); | 257 IPC_EXPORT static void Log(const param_type& p, std::string* l); |
252 }; | 258 }; |
253 | 259 |
254 template <> | 260 template <> |
255 struct ParamTraits<base::string16> { | 261 struct ParamTraits<base::string16> { |
256 typedef base::string16 param_type; | 262 typedef base::string16 param_type; |
257 static void Write(Message* m, const param_type& p) { | 263 static void Write(Message* m, const param_type& p) { |
258 m->WriteString16(p); | 264 m->WriteString16(p); |
259 } | 265 } |
260 static bool Read(const Message* m, PickleIterator* iter, | 266 static bool Read(const Message* m, base::PickleIterator* iter, |
261 param_type* r) { | 267 param_type* r) { |
262 return iter->ReadString16(r); | 268 return iter->ReadString16(r); |
263 } | 269 } |
264 IPC_EXPORT static void Log(const param_type& p, std::string* l); | 270 IPC_EXPORT static void Log(const param_type& p, std::string* l); |
265 }; | 271 }; |
266 | 272 |
267 template <> | 273 template <> |
268 struct IPC_EXPORT ParamTraits<std::vector<char> > { | 274 struct IPC_EXPORT ParamTraits<std::vector<char> > { |
269 typedef std::vector<char> param_type; | 275 typedef std::vector<char> param_type; |
270 static void Write(Message* m, const param_type& p); | 276 static void Write(Message* m, const param_type& p); |
271 static bool Read(const Message*, PickleIterator* iter, param_type* r); | 277 static bool Read(const Message*, base::PickleIterator* iter, param_type* r); |
272 static void Log(const param_type& p, std::string* l); | 278 static void Log(const param_type& p, std::string* l); |
273 }; | 279 }; |
274 | 280 |
275 template <> | 281 template <> |
276 struct IPC_EXPORT ParamTraits<std::vector<unsigned char> > { | 282 struct IPC_EXPORT ParamTraits<std::vector<unsigned char> > { |
277 typedef std::vector<unsigned char> param_type; | 283 typedef std::vector<unsigned char> param_type; |
278 static void Write(Message* m, const param_type& p); | 284 static void Write(Message* m, const param_type& p); |
279 static bool Read(const Message* m, PickleIterator* iter, param_type* r); | 285 static bool Read(const Message* m, base::PickleIterator* iter, param_type* r); |
280 static void Log(const param_type& p, std::string* l); | 286 static void Log(const param_type& p, std::string* l); |
281 }; | 287 }; |
282 | 288 |
283 template <> | 289 template <> |
284 struct IPC_EXPORT ParamTraits<std::vector<bool> > { | 290 struct IPC_EXPORT ParamTraits<std::vector<bool> > { |
285 typedef std::vector<bool> param_type; | 291 typedef std::vector<bool> param_type; |
286 static void Write(Message* m, const param_type& p); | 292 static void Write(Message* m, const param_type& p); |
287 static bool Read(const Message* m, PickleIterator* iter, param_type* r); | 293 static bool Read(const Message* m, base::PickleIterator* iter, param_type* r); |
288 static void Log(const param_type& p, std::string* l); | 294 static void Log(const param_type& p, std::string* l); |
289 }; | 295 }; |
290 | 296 |
291 template <class P> | 297 template <class P> |
292 struct ParamTraits<std::vector<P> > { | 298 struct ParamTraits<std::vector<P> > { |
293 typedef std::vector<P> param_type; | 299 typedef std::vector<P> param_type; |
294 static void Write(Message* m, const param_type& p) { | 300 static void Write(Message* m, const param_type& p) { |
295 WriteParam(m, static_cast<int>(p.size())); | 301 WriteParam(m, static_cast<int>(p.size())); |
296 for (size_t i = 0; i < p.size(); i++) | 302 for (size_t i = 0; i < p.size(); i++) |
297 WriteParam(m, p[i]); | 303 WriteParam(m, p[i]); |
298 } | 304 } |
299 static bool Read(const Message* m, PickleIterator* iter, | 305 static bool Read(const Message* m, base::PickleIterator* iter, |
300 param_type* r) { | 306 param_type* r) { |
301 int size; | 307 int size; |
302 // ReadLength() checks for < 0 itself. | 308 // ReadLength() checks for < 0 itself. |
303 if (!iter->ReadLength(&size)) | 309 if (!iter->ReadLength(&size)) |
304 return false; | 310 return false; |
305 // Resizing beforehand is not safe, see BUG 1006367 for details. | 311 // Resizing beforehand is not safe, see BUG 1006367 for details. |
306 if (INT_MAX / sizeof(P) <= static_cast<size_t>(size)) | 312 if (INT_MAX / sizeof(P) <= static_cast<size_t>(size)) |
307 return false; | 313 return false; |
308 r->resize(size); | 314 r->resize(size); |
309 for (int i = 0; i < size; i++) { | 315 for (int i = 0; i < size; i++) { |
(...skipping 13 matching lines...) Expand all Loading... |
323 | 329 |
324 template <class P> | 330 template <class P> |
325 struct ParamTraits<std::set<P> > { | 331 struct ParamTraits<std::set<P> > { |
326 typedef std::set<P> param_type; | 332 typedef std::set<P> param_type; |
327 static void Write(Message* m, const param_type& p) { | 333 static void Write(Message* m, const param_type& p) { |
328 WriteParam(m, static_cast<int>(p.size())); | 334 WriteParam(m, static_cast<int>(p.size())); |
329 typename param_type::const_iterator iter; | 335 typename param_type::const_iterator iter; |
330 for (iter = p.begin(); iter != p.end(); ++iter) | 336 for (iter = p.begin(); iter != p.end(); ++iter) |
331 WriteParam(m, *iter); | 337 WriteParam(m, *iter); |
332 } | 338 } |
333 static bool Read(const Message* m, PickleIterator* iter, | 339 static bool Read(const Message* m, base::PickleIterator* iter, |
334 param_type* r) { | 340 param_type* r) { |
335 int size; | 341 int size; |
336 if (!iter->ReadLength(&size)) | 342 if (!iter->ReadLength(&size)) |
337 return false; | 343 return false; |
338 for (int i = 0; i < size; ++i) { | 344 for (int i = 0; i < size; ++i) { |
339 P item; | 345 P item; |
340 if (!ReadParam(m, iter, &item)) | 346 if (!ReadParam(m, iter, &item)) |
341 return false; | 347 return false; |
342 r->insert(item); | 348 r->insert(item); |
343 } | 349 } |
344 return true; | 350 return true; |
345 } | 351 } |
346 static void Log(const param_type& p, std::string* l) { | 352 static void Log(const param_type& p, std::string* l) { |
347 l->append("<std::set>"); | 353 l->append("<std::set>"); |
348 } | 354 } |
349 }; | 355 }; |
350 | 356 |
351 template <class K, class V, class C, class A> | 357 template <class K, class V, class C, class A> |
352 struct ParamTraits<std::map<K, V, C, A> > { | 358 struct ParamTraits<std::map<K, V, C, A> > { |
353 typedef std::map<K, V, C, A> param_type; | 359 typedef std::map<K, V, C, A> param_type; |
354 static void Write(Message* m, const param_type& p) { | 360 static void Write(Message* m, const param_type& p) { |
355 WriteParam(m, static_cast<int>(p.size())); | 361 WriteParam(m, static_cast<int>(p.size())); |
356 typename param_type::const_iterator iter; | 362 typename param_type::const_iterator iter; |
357 for (iter = p.begin(); iter != p.end(); ++iter) { | 363 for (iter = p.begin(); iter != p.end(); ++iter) { |
358 WriteParam(m, iter->first); | 364 WriteParam(m, iter->first); |
359 WriteParam(m, iter->second); | 365 WriteParam(m, iter->second); |
360 } | 366 } |
361 } | 367 } |
362 static bool Read(const Message* m, PickleIterator* iter, | 368 static bool Read(const Message* m, base::PickleIterator* iter, |
363 param_type* r) { | 369 param_type* r) { |
364 int size; | 370 int size; |
365 if (!ReadParam(m, iter, &size) || size < 0) | 371 if (!ReadParam(m, iter, &size) || size < 0) |
366 return false; | 372 return false; |
367 for (int i = 0; i < size; ++i) { | 373 for (int i = 0; i < size; ++i) { |
368 K k; | 374 K k; |
369 if (!ReadParam(m, iter, &k)) | 375 if (!ReadParam(m, iter, &k)) |
370 return false; | 376 return false; |
371 V& value = (*r)[k]; | 377 V& value = (*r)[k]; |
372 if (!ReadParam(m, iter, &value)) | 378 if (!ReadParam(m, iter, &value)) |
373 return false; | 379 return false; |
374 } | 380 } |
375 return true; | 381 return true; |
376 } | 382 } |
377 static void Log(const param_type& p, std::string* l) { | 383 static void Log(const param_type& p, std::string* l) { |
378 l->append("<std::map>"); | 384 l->append("<std::map>"); |
379 } | 385 } |
380 }; | 386 }; |
381 | 387 |
382 template <class A, class B> | 388 template <class A, class B> |
383 struct ParamTraits<std::pair<A, B> > { | 389 struct ParamTraits<std::pair<A, B> > { |
384 typedef std::pair<A, B> param_type; | 390 typedef std::pair<A, B> param_type; |
385 static void Write(Message* m, const param_type& p) { | 391 static void Write(Message* m, const param_type& p) { |
386 WriteParam(m, p.first); | 392 WriteParam(m, p.first); |
387 WriteParam(m, p.second); | 393 WriteParam(m, p.second); |
388 } | 394 } |
389 static bool Read(const Message* m, PickleIterator* iter, | 395 static bool Read(const Message* m, base::PickleIterator* iter, |
390 param_type* r) { | 396 param_type* r) { |
391 return ReadParam(m, iter, &r->first) && ReadParam(m, iter, &r->second); | 397 return ReadParam(m, iter, &r->first) && ReadParam(m, iter, &r->second); |
392 } | 398 } |
393 static void Log(const param_type& p, std::string* l) { | 399 static void Log(const param_type& p, std::string* l) { |
394 l->append("("); | 400 l->append("("); |
395 LogParam(p.first, l); | 401 LogParam(p.first, l); |
396 l->append(", "); | 402 l->append(", "); |
397 LogParam(p.second, l); | 403 LogParam(p.second, l); |
398 l->append(")"); | 404 l->append(")"); |
399 } | 405 } |
400 }; | 406 }; |
401 | 407 |
402 // Base ParamTraits ------------------------------------------------------------ | 408 // Base ParamTraits ------------------------------------------------------------ |
403 | 409 |
404 template <> | 410 template <> |
405 struct IPC_EXPORT ParamTraits<base::DictionaryValue> { | 411 struct IPC_EXPORT ParamTraits<base::DictionaryValue> { |
406 typedef base::DictionaryValue param_type; | 412 typedef base::DictionaryValue param_type; |
407 static void Write(Message* m, const param_type& p); | 413 static void Write(Message* m, const param_type& p); |
408 static bool Read(const Message* m, PickleIterator* iter, param_type* r); | 414 static bool Read(const Message* m, base::PickleIterator* iter, param_type* r); |
409 static void Log(const param_type& p, std::string* l); | 415 static void Log(const param_type& p, std::string* l); |
410 }; | 416 }; |
411 | 417 |
412 #if defined(OS_POSIX) | 418 #if defined(OS_POSIX) |
413 // FileDescriptors may be serialised over IPC channels on POSIX. On the | 419 // FileDescriptors may be serialised over IPC channels on POSIX. On the |
414 // receiving side, the FileDescriptor is a valid duplicate of the file | 420 // receiving side, the FileDescriptor is a valid duplicate of the file |
415 // descriptor which was transmitted: *it is not just a copy of the integer like | 421 // descriptor which was transmitted: *it is not just a copy of the integer like |
416 // HANDLEs on Windows*. The only exception is if the file descriptor is < 0. In | 422 // HANDLEs on Windows*. The only exception is if the file descriptor is < 0. In |
417 // this case, the receiving end will see a value of -1. *Zero is a valid file | 423 // this case, the receiving end will see a value of -1. *Zero is a valid file |
418 // descriptor*. | 424 // descriptor*. |
419 // | 425 // |
420 // The received file descriptor will have the |auto_close| flag set to true. The | 426 // The received file descriptor will have the |auto_close| flag set to true. The |
421 // code which handles the message is responsible for taking ownership of it. | 427 // code which handles the message is responsible for taking ownership of it. |
422 // File descriptors are OS resources and must be closed when no longer needed. | 428 // File descriptors are OS resources and must be closed when no longer needed. |
423 // | 429 // |
424 // When sending a file descriptor, the file descriptor must be valid at the time | 430 // When sending a file descriptor, the file descriptor must be valid at the time |
425 // of transmission. Since transmission is not synchronous, one should consider | 431 // of transmission. Since transmission is not synchronous, one should consider |
426 // dup()ing any file descriptors to be transmitted and setting the |auto_close| | 432 // dup()ing any file descriptors to be transmitted and setting the |auto_close| |
427 // flag, which causes the file descriptor to be closed after writing. | 433 // flag, which causes the file descriptor to be closed after writing. |
428 template<> | 434 template<> |
429 struct IPC_EXPORT ParamTraits<base::FileDescriptor> { | 435 struct IPC_EXPORT ParamTraits<base::FileDescriptor> { |
430 typedef base::FileDescriptor param_type; | 436 typedef base::FileDescriptor param_type; |
431 static void Write(Message* m, const param_type& p); | 437 static void Write(Message* m, const param_type& p); |
432 static bool Read(const Message* m, PickleIterator* iter, param_type* r); | 438 static bool Read(const Message* m, base::PickleIterator* iter, param_type* r); |
433 static void Log(const param_type& p, std::string* l); | 439 static void Log(const param_type& p, std::string* l); |
434 }; | 440 }; |
435 #endif // defined(OS_POSIX) | 441 #endif // defined(OS_POSIX) |
436 | 442 |
437 template <> | 443 template <> |
438 struct IPC_EXPORT ParamTraits<base::FilePath> { | 444 struct IPC_EXPORT ParamTraits<base::FilePath> { |
439 typedef base::FilePath param_type; | 445 typedef base::FilePath param_type; |
440 static void Write(Message* m, const param_type& p); | 446 static void Write(Message* m, const param_type& p); |
441 static bool Read(const Message* m, PickleIterator* iter, param_type* r); | 447 static bool Read(const Message* m, base::PickleIterator* iter, param_type* r); |
442 static void Log(const param_type& p, std::string* l); | 448 static void Log(const param_type& p, std::string* l); |
443 }; | 449 }; |
444 | 450 |
445 template <> | 451 template <> |
446 struct IPC_EXPORT ParamTraits<base::ListValue> { | 452 struct IPC_EXPORT ParamTraits<base::ListValue> { |
447 typedef base::ListValue param_type; | 453 typedef base::ListValue param_type; |
448 static void Write(Message* m, const param_type& p); | 454 static void Write(Message* m, const param_type& p); |
449 static bool Read(const Message* m, PickleIterator* iter, param_type* r); | 455 static bool Read(const Message* m, base::PickleIterator* iter, param_type* r); |
450 static void Log(const param_type& p, std::string* l); | 456 static void Log(const param_type& p, std::string* l); |
451 }; | 457 }; |
452 | 458 |
453 template <> | 459 template <> |
454 struct IPC_EXPORT ParamTraits<base::NullableString16> { | 460 struct IPC_EXPORT ParamTraits<base::NullableString16> { |
455 typedef base::NullableString16 param_type; | 461 typedef base::NullableString16 param_type; |
456 static void Write(Message* m, const param_type& p); | 462 static void Write(Message* m, const param_type& p); |
457 static bool Read(const Message* m, PickleIterator* iter, | 463 static bool Read(const Message* m, base::PickleIterator* iter, |
458 param_type* r); | 464 param_type* r); |
459 static void Log(const param_type& p, std::string* l); | 465 static void Log(const param_type& p, std::string* l); |
460 }; | 466 }; |
461 | 467 |
462 template <> | 468 template <> |
463 struct IPC_EXPORT ParamTraits<base::File::Info> { | 469 struct IPC_EXPORT ParamTraits<base::File::Info> { |
464 typedef base::File::Info param_type; | 470 typedef base::File::Info param_type; |
465 static void Write(Message* m, const param_type& p); | 471 static void Write(Message* m, const param_type& p); |
466 static bool Read(const Message* m, PickleIterator* iter, param_type* r); | 472 static bool Read(const Message* m, base::PickleIterator* iter, param_type* r); |
467 static void Log(const param_type& p, std::string* l); | 473 static void Log(const param_type& p, std::string* l); |
468 }; | 474 }; |
469 | 475 |
470 template <> | 476 template <> |
471 struct SimilarTypeTraits<base::File::Error> { | 477 struct SimilarTypeTraits<base::File::Error> { |
472 typedef int Type; | 478 typedef int Type; |
473 }; | 479 }; |
474 | 480 |
475 #if defined(OS_WIN) | 481 #if defined(OS_WIN) |
476 template <> | 482 template <> |
477 struct SimilarTypeTraits<HWND> { | 483 struct SimilarTypeTraits<HWND> { |
478 typedef HANDLE Type; | 484 typedef HANDLE Type; |
479 }; | 485 }; |
480 #endif // defined(OS_WIN) | 486 #endif // defined(OS_WIN) |
481 | 487 |
482 template <> | 488 template <> |
483 struct IPC_EXPORT ParamTraits<base::Time> { | 489 struct IPC_EXPORT ParamTraits<base::Time> { |
484 typedef base::Time param_type; | 490 typedef base::Time param_type; |
485 static void Write(Message* m, const param_type& p); | 491 static void Write(Message* m, const param_type& p); |
486 static bool Read(const Message* m, PickleIterator* iter, param_type* r); | 492 static bool Read(const Message* m, base::PickleIterator* iter, param_type* r); |
487 static void Log(const param_type& p, std::string* l); | 493 static void Log(const param_type& p, std::string* l); |
488 }; | 494 }; |
489 | 495 |
490 template <> | 496 template <> |
491 struct IPC_EXPORT ParamTraits<base::TimeDelta> { | 497 struct IPC_EXPORT ParamTraits<base::TimeDelta> { |
492 typedef base::TimeDelta param_type; | 498 typedef base::TimeDelta param_type; |
493 static void Write(Message* m, const param_type& p); | 499 static void Write(Message* m, const param_type& p); |
494 static bool Read(const Message* m, PickleIterator* iter, param_type* r); | 500 static bool Read(const Message* m, base::PickleIterator* iter, param_type* r); |
495 static void Log(const param_type& p, std::string* l); | 501 static void Log(const param_type& p, std::string* l); |
496 }; | 502 }; |
497 | 503 |
498 template <> | 504 template <> |
499 struct IPC_EXPORT ParamTraits<base::TimeTicks> { | 505 struct IPC_EXPORT ParamTraits<base::TimeTicks> { |
500 typedef base::TimeTicks param_type; | 506 typedef base::TimeTicks param_type; |
501 static void Write(Message* m, const param_type& p); | 507 static void Write(Message* m, const param_type& p); |
502 static bool Read(const Message* m, PickleIterator* iter, param_type* r); | 508 static bool Read(const Message* m, base::PickleIterator* iter, param_type* r); |
503 static void Log(const param_type& p, std::string* l); | 509 static void Log(const param_type& p, std::string* l); |
504 }; | 510 }; |
505 | 511 |
506 template <> | 512 template <> |
507 struct IPC_EXPORT ParamTraits<base::TraceTicks> { | 513 struct IPC_EXPORT ParamTraits<base::TraceTicks> { |
508 typedef base::TraceTicks param_type; | 514 typedef base::TraceTicks param_type; |
509 static void Write(Message* m, const param_type& p); | 515 static void Write(Message* m, const param_type& p); |
510 static bool Read(const Message* m, PickleIterator* iter, param_type* r); | 516 static bool Read(const Message* m, base::PickleIterator* iter, param_type* r); |
511 static void Log(const param_type& p, std::string* l); | 517 static void Log(const param_type& p, std::string* l); |
512 }; | 518 }; |
513 | 519 |
514 template <> | 520 template <> |
515 struct ParamTraits<base::Tuple<>> { | 521 struct ParamTraits<base::Tuple<>> { |
516 typedef base::Tuple<> param_type; | 522 typedef base::Tuple<> param_type; |
517 static void Write(Message* m, const param_type& p) { | 523 static void Write(Message* m, const param_type& p) { |
518 } | 524 } |
519 static bool Read(const Message* m, PickleIterator* iter, param_type* r) { | 525 static bool Read(const Message* m, base::PickleIterator* iter, |
| 526 param_type* r) { |
520 return true; | 527 return true; |
521 } | 528 } |
522 static void Log(const param_type& p, std::string* l) { | 529 static void Log(const param_type& p, std::string* l) { |
523 } | 530 } |
524 }; | 531 }; |
525 | 532 |
526 template <class A> | 533 template <class A> |
527 struct ParamTraits<base::Tuple<A>> { | 534 struct ParamTraits<base::Tuple<A>> { |
528 typedef base::Tuple<A> param_type; | 535 typedef base::Tuple<A> param_type; |
529 static void Write(Message* m, const param_type& p) { | 536 static void Write(Message* m, const param_type& p) { |
530 WriteParam(m, base::get<0>(p)); | 537 WriteParam(m, base::get<0>(p)); |
531 } | 538 } |
532 static bool Read(const Message* m, PickleIterator* iter, param_type* r) { | 539 static bool Read(const Message* m, base::PickleIterator* iter, |
| 540 param_type* r) { |
533 return ReadParam(m, iter, &base::get<0>(*r)); | 541 return ReadParam(m, iter, &base::get<0>(*r)); |
534 } | 542 } |
535 static void Log(const param_type& p, std::string* l) { | 543 static void Log(const param_type& p, std::string* l) { |
536 LogParam(base::get<0>(p), l); | 544 LogParam(base::get<0>(p), l); |
537 } | 545 } |
538 }; | 546 }; |
539 | 547 |
540 template <class A, class B> | 548 template <class A, class B> |
541 struct ParamTraits<base::Tuple<A, B>> { | 549 struct ParamTraits<base::Tuple<A, B>> { |
542 typedef base::Tuple<A, B> param_type; | 550 typedef base::Tuple<A, B> param_type; |
543 static void Write(Message* m, const param_type& p) { | 551 static void Write(Message* m, const param_type& p) { |
544 WriteParam(m, base::get<0>(p)); | 552 WriteParam(m, base::get<0>(p)); |
545 WriteParam(m, base::get<1>(p)); | 553 WriteParam(m, base::get<1>(p)); |
546 } | 554 } |
547 static bool Read(const Message* m, PickleIterator* iter, param_type* r) { | 555 static bool Read(const Message* m, base::PickleIterator* iter, |
| 556 param_type* r) { |
548 return (ReadParam(m, iter, &base::get<0>(*r)) && | 557 return (ReadParam(m, iter, &base::get<0>(*r)) && |
549 ReadParam(m, iter, &base::get<1>(*r))); | 558 ReadParam(m, iter, &base::get<1>(*r))); |
550 } | 559 } |
551 static void Log(const param_type& p, std::string* l) { | 560 static void Log(const param_type& p, std::string* l) { |
552 LogParam(base::get<0>(p), l); | 561 LogParam(base::get<0>(p), l); |
553 l->append(", "); | 562 l->append(", "); |
554 LogParam(base::get<1>(p), l); | 563 LogParam(base::get<1>(p), l); |
555 } | 564 } |
556 }; | 565 }; |
557 | 566 |
558 template <class A, class B, class C> | 567 template <class A, class B, class C> |
559 struct ParamTraits<base::Tuple<A, B, C>> { | 568 struct ParamTraits<base::Tuple<A, B, C>> { |
560 typedef base::Tuple<A, B, C> param_type; | 569 typedef base::Tuple<A, B, C> param_type; |
561 static void Write(Message* m, const param_type& p) { | 570 static void Write(Message* m, const param_type& p) { |
562 WriteParam(m, base::get<0>(p)); | 571 WriteParam(m, base::get<0>(p)); |
563 WriteParam(m, base::get<1>(p)); | 572 WriteParam(m, base::get<1>(p)); |
564 WriteParam(m, base::get<2>(p)); | 573 WriteParam(m, base::get<2>(p)); |
565 } | 574 } |
566 static bool Read(const Message* m, PickleIterator* iter, param_type* r) { | 575 static bool Read(const Message* m, base::PickleIterator* iter, |
| 576 param_type* r) { |
567 return (ReadParam(m, iter, &base::get<0>(*r)) && | 577 return (ReadParam(m, iter, &base::get<0>(*r)) && |
568 ReadParam(m, iter, &base::get<1>(*r)) && | 578 ReadParam(m, iter, &base::get<1>(*r)) && |
569 ReadParam(m, iter, &base::get<2>(*r))); | 579 ReadParam(m, iter, &base::get<2>(*r))); |
570 } | 580 } |
571 static void Log(const param_type& p, std::string* l) { | 581 static void Log(const param_type& p, std::string* l) { |
572 LogParam(base::get<0>(p), l); | 582 LogParam(base::get<0>(p), l); |
573 l->append(", "); | 583 l->append(", "); |
574 LogParam(base::get<1>(p), l); | 584 LogParam(base::get<1>(p), l); |
575 l->append(", "); | 585 l->append(", "); |
576 LogParam(base::get<2>(p), l); | 586 LogParam(base::get<2>(p), l); |
577 } | 587 } |
578 }; | 588 }; |
579 | 589 |
580 template <class A, class B, class C, class D> | 590 template <class A, class B, class C, class D> |
581 struct ParamTraits<base::Tuple<A, B, C, D>> { | 591 struct ParamTraits<base::Tuple<A, B, C, D>> { |
582 typedef base::Tuple<A, B, C, D> param_type; | 592 typedef base::Tuple<A, B, C, D> param_type; |
583 static void Write(Message* m, const param_type& p) { | 593 static void Write(Message* m, const param_type& p) { |
584 WriteParam(m, base::get<0>(p)); | 594 WriteParam(m, base::get<0>(p)); |
585 WriteParam(m, base::get<1>(p)); | 595 WriteParam(m, base::get<1>(p)); |
586 WriteParam(m, base::get<2>(p)); | 596 WriteParam(m, base::get<2>(p)); |
587 WriteParam(m, base::get<3>(p)); | 597 WriteParam(m, base::get<3>(p)); |
588 } | 598 } |
589 static bool Read(const Message* m, PickleIterator* iter, param_type* r) { | 599 static bool Read(const Message* m, base::PickleIterator* iter, |
| 600 param_type* r) { |
590 return (ReadParam(m, iter, &base::get<0>(*r)) && | 601 return (ReadParam(m, iter, &base::get<0>(*r)) && |
591 ReadParam(m, iter, &base::get<1>(*r)) && | 602 ReadParam(m, iter, &base::get<1>(*r)) && |
592 ReadParam(m, iter, &base::get<2>(*r)) && | 603 ReadParam(m, iter, &base::get<2>(*r)) && |
593 ReadParam(m, iter, &base::get<3>(*r))); | 604 ReadParam(m, iter, &base::get<3>(*r))); |
594 } | 605 } |
595 static void Log(const param_type& p, std::string* l) { | 606 static void Log(const param_type& p, std::string* l) { |
596 LogParam(base::get<0>(p), l); | 607 LogParam(base::get<0>(p), l); |
597 l->append(", "); | 608 l->append(", "); |
598 LogParam(base::get<1>(p), l); | 609 LogParam(base::get<1>(p), l); |
599 l->append(", "); | 610 l->append(", "); |
600 LogParam(base::get<2>(p), l); | 611 LogParam(base::get<2>(p), l); |
601 l->append(", "); | 612 l->append(", "); |
602 LogParam(base::get<3>(p), l); | 613 LogParam(base::get<3>(p), l); |
603 } | 614 } |
604 }; | 615 }; |
605 | 616 |
606 template <class A, class B, class C, class D, class E> | 617 template <class A, class B, class C, class D, class E> |
607 struct ParamTraits<base::Tuple<A, B, C, D, E>> { | 618 struct ParamTraits<base::Tuple<A, B, C, D, E>> { |
608 typedef base::Tuple<A, B, C, D, E> param_type; | 619 typedef base::Tuple<A, B, C, D, E> param_type; |
609 static void Write(Message* m, const param_type& p) { | 620 static void Write(Message* m, const param_type& p) { |
610 WriteParam(m, base::get<0>(p)); | 621 WriteParam(m, base::get<0>(p)); |
611 WriteParam(m, base::get<1>(p)); | 622 WriteParam(m, base::get<1>(p)); |
612 WriteParam(m, base::get<2>(p)); | 623 WriteParam(m, base::get<2>(p)); |
613 WriteParam(m, base::get<3>(p)); | 624 WriteParam(m, base::get<3>(p)); |
614 WriteParam(m, base::get<4>(p)); | 625 WriteParam(m, base::get<4>(p)); |
615 } | 626 } |
616 static bool Read(const Message* m, PickleIterator* iter, param_type* r) { | 627 static bool Read(const Message* m, base::PickleIterator* iter, |
| 628 param_type* r) { |
617 return (ReadParam(m, iter, &base::get<0>(*r)) && | 629 return (ReadParam(m, iter, &base::get<0>(*r)) && |
618 ReadParam(m, iter, &base::get<1>(*r)) && | 630 ReadParam(m, iter, &base::get<1>(*r)) && |
619 ReadParam(m, iter, &base::get<2>(*r)) && | 631 ReadParam(m, iter, &base::get<2>(*r)) && |
620 ReadParam(m, iter, &base::get<3>(*r)) && | 632 ReadParam(m, iter, &base::get<3>(*r)) && |
621 ReadParam(m, iter, &base::get<4>(*r))); | 633 ReadParam(m, iter, &base::get<4>(*r))); |
622 } | 634 } |
623 static void Log(const param_type& p, std::string* l) { | 635 static void Log(const param_type& p, std::string* l) { |
624 LogParam(base::get<0>(p), l); | 636 LogParam(base::get<0>(p), l); |
625 l->append(", "); | 637 l->append(", "); |
626 LogParam(base::get<1>(p), l); | 638 LogParam(base::get<1>(p), l); |
627 l->append(", "); | 639 l->append(", "); |
628 LogParam(base::get<2>(p), l); | 640 LogParam(base::get<2>(p), l); |
629 l->append(", "); | 641 l->append(", "); |
630 LogParam(base::get<3>(p), l); | 642 LogParam(base::get<3>(p), l); |
631 l->append(", "); | 643 l->append(", "); |
632 LogParam(base::get<4>(p), l); | 644 LogParam(base::get<4>(p), l); |
633 } | 645 } |
634 }; | 646 }; |
635 | 647 |
636 template<class P> | 648 template<class P> |
637 struct ParamTraits<ScopedVector<P> > { | 649 struct ParamTraits<ScopedVector<P> > { |
638 typedef ScopedVector<P> param_type; | 650 typedef ScopedVector<P> param_type; |
639 static void Write(Message* m, const param_type& p) { | 651 static void Write(Message* m, const param_type& p) { |
640 WriteParam(m, static_cast<int>(p.size())); | 652 WriteParam(m, static_cast<int>(p.size())); |
641 for (size_t i = 0; i < p.size(); i++) | 653 for (size_t i = 0; i < p.size(); i++) |
642 WriteParam(m, *p[i]); | 654 WriteParam(m, *p[i]); |
643 } | 655 } |
644 static bool Read(const Message* m, PickleIterator* iter, param_type* r) { | 656 static bool Read(const Message* m, base::PickleIterator* iter, |
| 657 param_type* r) { |
645 int size = 0; | 658 int size = 0; |
646 if (!iter->ReadLength(&size)) | 659 if (!iter->ReadLength(&size)) |
647 return false; | 660 return false; |
648 if (INT_MAX/sizeof(P) <= static_cast<size_t>(size)) | 661 if (INT_MAX/sizeof(P) <= static_cast<size_t>(size)) |
649 return false; | 662 return false; |
650 r->resize(size); | 663 r->resize(size); |
651 for (int i = 0; i < size; i++) { | 664 for (int i = 0; i < size; i++) { |
652 (*r)[i] = new P(); | 665 (*r)[i] = new P(); |
653 if (!ReadParam(m, iter, (*r)[i])) | 666 if (!ReadParam(m, iter, (*r)[i])) |
654 return false; | 667 return false; |
(...skipping 18 matching lines...) Expand all Loading... |
673 typedef typename param_type::key_type K; | 686 typedef typename param_type::key_type K; |
674 typedef typename param_type::data_type V; | 687 typedef typename param_type::data_type V; |
675 static void Write(Message* m, const param_type& p) { | 688 static void Write(Message* m, const param_type& p) { |
676 WriteParam(m, static_cast<int>(p.size())); | 689 WriteParam(m, static_cast<int>(p.size())); |
677 typename param_type::const_iterator iter; | 690 typename param_type::const_iterator iter; |
678 for (iter = p.begin(); iter != p.end(); ++iter) { | 691 for (iter = p.begin(); iter != p.end(); ++iter) { |
679 WriteParam(m, iter->first); | 692 WriteParam(m, iter->first); |
680 WriteParam(m, iter->second); | 693 WriteParam(m, iter->second); |
681 } | 694 } |
682 } | 695 } |
683 static bool Read(const Message* m, PickleIterator* iter, param_type* r) { | 696 static bool Read(const Message* m, base::PickleIterator* iter, |
| 697 param_type* r) { |
684 int size; | 698 int size; |
685 if (!iter->ReadLength(&size)) | 699 if (!iter->ReadLength(&size)) |
686 return false; | 700 return false; |
687 for (int i = 0; i < size; ++i) { | 701 for (int i = 0; i < size; ++i) { |
688 K key; | 702 K key; |
689 if (!ReadParam(m, iter, &key)) | 703 if (!ReadParam(m, iter, &key)) |
690 return false; | 704 return false; |
691 V& value = (*r)[key]; | 705 V& value = (*r)[key]; |
692 if (!ReadParam(m, iter, &value)) | 706 if (!ReadParam(m, iter, &value)) |
693 return false; | 707 return false; |
694 } | 708 } |
695 return true; | 709 return true; |
696 } | 710 } |
697 static void Log(const param_type& p, std::string* l) { | 711 static void Log(const param_type& p, std::string* l) { |
698 l->append("<base::SmallMap>"); | 712 l->append("<base::SmallMap>"); |
699 } | 713 } |
700 }; | 714 }; |
701 | 715 |
702 template <class P> | 716 template <class P> |
703 struct ParamTraits<scoped_ptr<P> > { | 717 struct ParamTraits<scoped_ptr<P> > { |
704 typedef scoped_ptr<P> param_type; | 718 typedef scoped_ptr<P> param_type; |
705 static void Write(Message* m, const param_type& p) { | 719 static void Write(Message* m, const param_type& p) { |
706 bool valid = !!p; | 720 bool valid = !!p; |
707 WriteParam(m, valid); | 721 WriteParam(m, valid); |
708 if (valid) | 722 if (valid) |
709 WriteParam(m, *p); | 723 WriteParam(m, *p); |
710 } | 724 } |
711 static bool Read(const Message* m, PickleIterator* iter, param_type* r) { | 725 static bool Read(const Message* m, base::PickleIterator* iter, |
| 726 param_type* r) { |
712 bool valid = false; | 727 bool valid = false; |
713 if (!ReadParam(m, iter, &valid)) | 728 if (!ReadParam(m, iter, &valid)) |
714 return false; | 729 return false; |
715 | 730 |
716 if (!valid) { | 731 if (!valid) { |
717 r->reset(); | 732 r->reset(); |
718 return true; | 733 return true; |
719 } | 734 } |
720 | 735 |
721 param_type temp(new P()); | 736 param_type temp(new P()); |
(...skipping 13 matching lines...) Expand all Loading... |
735 | 750 |
736 // IPC types ParamTraits ------------------------------------------------------- | 751 // IPC types ParamTraits ------------------------------------------------------- |
737 | 752 |
738 // A ChannelHandle is basically a platform-inspecific wrapper around the | 753 // A ChannelHandle is basically a platform-inspecific wrapper around the |
739 // fact that IPC endpoints are handled specially on POSIX. See above comments | 754 // fact that IPC endpoints are handled specially on POSIX. See above comments |
740 // on FileDescriptor for more background. | 755 // on FileDescriptor for more background. |
741 template<> | 756 template<> |
742 struct IPC_EXPORT ParamTraits<IPC::ChannelHandle> { | 757 struct IPC_EXPORT ParamTraits<IPC::ChannelHandle> { |
743 typedef ChannelHandle param_type; | 758 typedef ChannelHandle param_type; |
744 static void Write(Message* m, const param_type& p); | 759 static void Write(Message* m, const param_type& p); |
745 static bool Read(const Message* m, PickleIterator* iter, param_type* r); | 760 static bool Read(const Message* m, base::PickleIterator* iter, param_type* r); |
746 static void Log(const param_type& p, std::string* l); | 761 static void Log(const param_type& p, std::string* l); |
747 }; | 762 }; |
748 | 763 |
749 template <> | 764 template <> |
750 struct IPC_EXPORT ParamTraits<LogData> { | 765 struct IPC_EXPORT ParamTraits<LogData> { |
751 typedef LogData param_type; | 766 typedef LogData param_type; |
752 static void Write(Message* m, const param_type& p); | 767 static void Write(Message* m, const param_type& p); |
753 static bool Read(const Message* m, PickleIterator* iter, param_type* r); | 768 static bool Read(const Message* m, base::PickleIterator* iter, param_type* r); |
754 static void Log(const param_type& p, std::string* l); | 769 static void Log(const param_type& p, std::string* l); |
755 }; | 770 }; |
756 | 771 |
757 template <> | 772 template <> |
758 struct IPC_EXPORT ParamTraits<Message> { | 773 struct IPC_EXPORT ParamTraits<Message> { |
759 static void Write(Message* m, const Message& p); | 774 static void Write(Message* m, const Message& p); |
760 static bool Read(const Message* m, PickleIterator* iter, Message* r); | 775 static bool Read(const Message* m, base::PickleIterator* iter, Message* r); |
761 static void Log(const Message& p, std::string* l); | 776 static void Log(const Message& p, std::string* l); |
762 }; | 777 }; |
763 | 778 |
764 // Windows ParamTraits --------------------------------------------------------- | 779 // Windows ParamTraits --------------------------------------------------------- |
765 | 780 |
766 #if defined(OS_WIN) | 781 #if defined(OS_WIN) |
767 template <> | 782 template <> |
768 struct IPC_EXPORT ParamTraits<HANDLE> { | 783 struct IPC_EXPORT ParamTraits<HANDLE> { |
769 typedef HANDLE param_type; | 784 typedef HANDLE param_type; |
770 static void Write(Message* m, const param_type& p); | 785 static void Write(Message* m, const param_type& p); |
771 static bool Read(const Message* m, PickleIterator* iter, param_type* r); | 786 static bool Read(const Message* m, base::PickleIterator* iter, param_type* r); |
772 static void Log(const param_type& p, std::string* l); | 787 static void Log(const param_type& p, std::string* l); |
773 }; | 788 }; |
774 | 789 |
775 template <> | 790 template <> |
776 struct IPC_EXPORT ParamTraits<LOGFONT> { | 791 struct IPC_EXPORT ParamTraits<LOGFONT> { |
777 typedef LOGFONT param_type; | 792 typedef LOGFONT param_type; |
778 static void Write(Message* m, const param_type& p); | 793 static void Write(Message* m, const param_type& p); |
779 static bool Read(const Message* m, PickleIterator* iter, param_type* r); | 794 static bool Read(const Message* m, base::PickleIterator* iter, param_type* r); |
780 static void Log(const param_type& p, std::string* l); | 795 static void Log(const param_type& p, std::string* l); |
781 }; | 796 }; |
782 | 797 |
783 template <> | 798 template <> |
784 struct IPC_EXPORT ParamTraits<MSG> { | 799 struct IPC_EXPORT ParamTraits<MSG> { |
785 typedef MSG param_type; | 800 typedef MSG param_type; |
786 static void Write(Message* m, const param_type& p); | 801 static void Write(Message* m, const param_type& p); |
787 static bool Read(const Message* m, PickleIterator* iter, param_type* r); | 802 static bool Read(const Message* m, base::PickleIterator* iter, param_type* r); |
788 static void Log(const param_type& p, std::string* l); | 803 static void Log(const param_type& p, std::string* l); |
789 }; | 804 }; |
790 #endif // defined(OS_WIN) | 805 #endif // defined(OS_WIN) |
791 | 806 |
792 //----------------------------------------------------------------------------- | 807 //----------------------------------------------------------------------------- |
793 // Generic message subclasses | 808 // Generic message subclasses |
794 | 809 |
795 // Used for asynchronous messages. | 810 // Used for asynchronous messages. |
796 template <class ParamType> | 811 template <class ParamType> |
797 class MessageSchema { | 812 class MessageSchema { |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
851 | 866 |
852 // This class assumes that its template argument is a RefTuple (a Tuple with | 867 // This class assumes that its template argument is a RefTuple (a Tuple with |
853 // reference elements). This would go into ipc_message_utils_impl.h, but it is | 868 // reference elements). This would go into ipc_message_utils_impl.h, but it is |
854 // also used by chrome_frame. | 869 // also used by chrome_frame. |
855 template <class RefTuple> | 870 template <class RefTuple> |
856 class ParamDeserializer : public MessageReplyDeserializer { | 871 class ParamDeserializer : public MessageReplyDeserializer { |
857 public: | 872 public: |
858 explicit ParamDeserializer(const RefTuple& out) : out_(out) { } | 873 explicit ParamDeserializer(const RefTuple& out) : out_(out) { } |
859 | 874 |
860 bool SerializeOutputParameters(const IPC::Message& msg, | 875 bool SerializeOutputParameters(const IPC::Message& msg, |
861 PickleIterator iter) override { | 876 base::PickleIterator iter) override { |
862 return ReadParam(&msg, &iter, &out_); | 877 return ReadParam(&msg, &iter, &out_); |
863 } | 878 } |
864 | 879 |
865 RefTuple out_; | 880 RefTuple out_; |
866 }; | 881 }; |
867 | 882 |
868 // Used for synchronous messages. | 883 // Used for synchronous messages. |
869 template <class SendParamType, class ReplyParamType> | 884 template <class SendParamType, class ReplyParamType> |
870 class SyncMessageSchema { | 885 class SyncMessageSchema { |
871 public: | 886 public: |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
918 template <typename... Ts> | 933 template <typename... Ts> |
919 static void WriteReplyParams(Message* reply, Ts... args) { | 934 static void WriteReplyParams(Message* reply, Ts... args) { |
920 ReplyParam p(args...); | 935 ReplyParam p(args...); |
921 WriteParam(reply, p); | 936 WriteParam(reply, p); |
922 } | 937 } |
923 }; | 938 }; |
924 | 939 |
925 } // namespace IPC | 940 } // namespace IPC |
926 | 941 |
927 #endif // IPC_IPC_MESSAGE_UTILS_H_ | 942 #endif // IPC_IPC_MESSAGE_UTILS_H_ |
OLD | NEW |