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

Side by Side Diff: ipc/ipc_message_utils.cc

Issue 1154283003: Change most uses of Pickle to base::Pickle (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 6 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
« no previous file with comments | « ipc/ipc_message_utils.h ('k') | ipc/ipc_message_utils_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "ipc/ipc_message_utils.h" 5 #include "ipc/ipc_message_utils.h"
6 6
7 #include "base/files/file_path.h" 7 #include "base/files/file_path.h"
8 #include "base/json/json_writer.h" 8 #include "base/json/json_writer.h"
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "base/strings/nullable_string16.h" 10 #include "base/strings/nullable_string16.h"
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 base::StringPrintf("[%02X]", static_cast<unsigned char>(data[i]))); 47 base::StringPrintf("[%02X]", static_cast<unsigned char>(data[i])));
48 } 48 }
49 if (data.size() > kMaxBytesToLog) { 49 if (data.size() > kMaxBytesToLog) {
50 out->append(base::StringPrintf( 50 out->append(base::StringPrintf(
51 " and %u more bytes", 51 " and %u more bytes",
52 static_cast<unsigned>(data.size() - kMaxBytesToLog))); 52 static_cast<unsigned>(data.size() - kMaxBytesToLog)));
53 } 53 }
54 #endif 54 #endif
55 } 55 }
56 56
57 bool ReadValue(const Message* m, PickleIterator* iter, base::Value** value, 57 bool ReadValue(const Message* m,
58 base::PickleIterator* iter,
59 base::Value** value,
58 int recursion); 60 int recursion);
59 61
60 void WriteValue(Message* m, const base::Value* value, int recursion) { 62 void WriteValue(Message* m, const base::Value* value, int recursion) {
61 bool result; 63 bool result;
62 if (recursion > kMaxRecursionDepth) { 64 if (recursion > kMaxRecursionDepth) {
63 LOG(WARNING) << "Max recursion depth hit in WriteValue."; 65 LOG(WARNING) << "Max recursion depth hit in WriteValue.";
64 return; 66 return;
65 } 67 }
66 68
67 m->WriteInt(value->GetType()); 69 m->WriteInt(value->GetType());
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 it != list->end(); ++it) { 125 it != list->end(); ++it) {
124 WriteValue(m, *it, recursion + 1); 126 WriteValue(m, *it, recursion + 1);
125 } 127 }
126 break; 128 break;
127 } 129 }
128 } 130 }
129 } 131 }
130 132
131 // Helper for ReadValue that reads a DictionaryValue into a pre-allocated 133 // Helper for ReadValue that reads a DictionaryValue into a pre-allocated
132 // object. 134 // object.
133 bool ReadDictionaryValue(const Message* m, PickleIterator* iter, 135 bool ReadDictionaryValue(const Message* m,
134 base::DictionaryValue* value, int recursion) { 136 base::PickleIterator* iter,
137 base::DictionaryValue* value,
138 int recursion) {
135 int size; 139 int size;
136 if (!ReadParam(m, iter, &size)) 140 if (!ReadParam(m, iter, &size))
137 return false; 141 return false;
138 142
139 for (int i = 0; i < size; ++i) { 143 for (int i = 0; i < size; ++i) {
140 std::string key; 144 std::string key;
141 base::Value* subval; 145 base::Value* subval;
142 if (!ReadParam(m, iter, &key) || 146 if (!ReadParam(m, iter, &key) ||
143 !ReadValue(m, iter, &subval, recursion + 1)) 147 !ReadValue(m, iter, &subval, recursion + 1))
144 return false; 148 return false;
145 value->SetWithoutPathExpansion(key, subval); 149 value->SetWithoutPathExpansion(key, subval);
146 } 150 }
147 151
148 return true; 152 return true;
149 } 153 }
150 154
151 // Helper for ReadValue that reads a ReadListValue into a pre-allocated 155 // Helper for ReadValue that reads a ReadListValue into a pre-allocated
152 // object. 156 // object.
153 bool ReadListValue(const Message* m, PickleIterator* iter, 157 bool ReadListValue(const Message* m,
154 base::ListValue* value, int recursion) { 158 base::PickleIterator* iter,
159 base::ListValue* value,
160 int recursion) {
155 int size; 161 int size;
156 if (!ReadParam(m, iter, &size)) 162 if (!ReadParam(m, iter, &size))
157 return false; 163 return false;
158 164
159 for (int i = 0; i < size; ++i) { 165 for (int i = 0; i < size; ++i) {
160 base::Value* subval; 166 base::Value* subval;
161 if (!ReadValue(m, iter, &subval, recursion + 1)) 167 if (!ReadValue(m, iter, &subval, recursion + 1))
162 return false; 168 return false;
163 value->Set(i, subval); 169 value->Set(i, subval);
164 } 170 }
165 171
166 return true; 172 return true;
167 } 173 }
168 174
169 bool ReadValue(const Message* m, PickleIterator* iter, base::Value** value, 175 bool ReadValue(const Message* m,
176 base::PickleIterator* iter,
177 base::Value** value,
170 int recursion) { 178 int recursion) {
171 if (recursion > kMaxRecursionDepth) { 179 if (recursion > kMaxRecursionDepth) {
172 LOG(WARNING) << "Max recursion depth hit in ReadValue."; 180 LOG(WARNING) << "Max recursion depth hit in ReadValue.";
173 return false; 181 return false;
174 } 182 }
175 183
176 int type; 184 int type;
177 if (!ReadParam(m, iter, &type)) 185 if (!ReadParam(m, iter, &type))
178 return false; 186 return false;
179 187
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
254 } 262 }
255 263
256 void ParamTraits<bool>::Log(const param_type& p, std::string* l) { 264 void ParamTraits<bool>::Log(const param_type& p, std::string* l) {
257 l->append(p ? "true" : "false"); 265 l->append(p ? "true" : "false");
258 } 266 }
259 267
260 void ParamTraits<unsigned char>::Write(Message* m, const param_type& p) { 268 void ParamTraits<unsigned char>::Write(Message* m, const param_type& p) {
261 m->WriteBytes(&p, sizeof(param_type)); 269 m->WriteBytes(&p, sizeof(param_type));
262 } 270 }
263 271
264 bool ParamTraits<unsigned char>::Read(const Message* m, PickleIterator* iter, 272 bool ParamTraits<unsigned char>::Read(const Message* m,
265 param_type* r) { 273 base::PickleIterator* iter,
274 param_type* r) {
266 const char* data; 275 const char* data;
267 if (!iter->ReadBytes(&data, sizeof(param_type))) 276 if (!iter->ReadBytes(&data, sizeof(param_type)))
268 return false; 277 return false;
269 memcpy(r, data, sizeof(param_type)); 278 memcpy(r, data, sizeof(param_type));
270 return true; 279 return true;
271 } 280 }
272 281
273 void ParamTraits<unsigned char>::Log(const param_type& p, std::string* l) { 282 void ParamTraits<unsigned char>::Log(const param_type& p, std::string* l) {
274 l->append(base::UintToString(p)); 283 l->append(base::UintToString(p));
275 } 284 }
276 285
277 void ParamTraits<unsigned short>::Write(Message* m, const param_type& p) { 286 void ParamTraits<unsigned short>::Write(Message* m, const param_type& p) {
278 m->WriteBytes(&p, sizeof(param_type)); 287 m->WriteBytes(&p, sizeof(param_type));
279 } 288 }
280 289
281 bool ParamTraits<unsigned short>::Read(const Message* m, PickleIterator* iter, 290 bool ParamTraits<unsigned short>::Read(const Message* m,
291 base::PickleIterator* iter,
282 param_type* r) { 292 param_type* r) {
283 const char* data; 293 const char* data;
284 if (!iter->ReadBytes(&data, sizeof(param_type))) 294 if (!iter->ReadBytes(&data, sizeof(param_type)))
285 return false; 295 return false;
286 memcpy(r, data, sizeof(param_type)); 296 memcpy(r, data, sizeof(param_type));
287 return true; 297 return true;
288 } 298 }
289 299
290 void ParamTraits<unsigned short>::Log(const param_type& p, std::string* l) { 300 void ParamTraits<unsigned short>::Log(const param_type& p, std::string* l) {
291 l->append(base::UintToString(p)); 301 l->append(base::UintToString(p));
(...skipping 24 matching lines...) Expand all
316 } 326 }
317 327
318 void ParamTraits<float>::Log(const param_type& p, std::string* l) { 328 void ParamTraits<float>::Log(const param_type& p, std::string* l) {
319 l->append(base::StringPrintf("%e", p)); 329 l->append(base::StringPrintf("%e", p));
320 } 330 }
321 331
322 void ParamTraits<double>::Write(Message* m, const param_type& p) { 332 void ParamTraits<double>::Write(Message* m, const param_type& p) {
323 m->WriteBytes(reinterpret_cast<const char*>(&p), sizeof(param_type)); 333 m->WriteBytes(reinterpret_cast<const char*>(&p), sizeof(param_type));
324 } 334 }
325 335
326 bool ParamTraits<double>::Read(const Message* m, PickleIterator* iter, 336 bool ParamTraits<double>::Read(const Message* m,
337 base::PickleIterator* iter,
327 param_type* r) { 338 param_type* r) {
328 const char *data; 339 const char *data;
329 if (!iter->ReadBytes(&data, sizeof(*r))) { 340 if (!iter->ReadBytes(&data, sizeof(*r))) {
330 NOTREACHED(); 341 NOTREACHED();
331 return false; 342 return false;
332 } 343 }
333 memcpy(r, data, sizeof(param_type)); 344 memcpy(r, data, sizeof(param_type));
334 return true; 345 return true;
335 } 346 }
336 347
(...skipping 11 matching lines...) Expand all
348 } 359 }
349 360
350 void ParamTraits<std::vector<char> >::Write(Message* m, const param_type& p) { 361 void ParamTraits<std::vector<char> >::Write(Message* m, const param_type& p) {
351 if (p.empty()) { 362 if (p.empty()) {
352 m->WriteData(NULL, 0); 363 m->WriteData(NULL, 0);
353 } else { 364 } else {
354 m->WriteData(&p.front(), static_cast<int>(p.size())); 365 m->WriteData(&p.front(), static_cast<int>(p.size()));
355 } 366 }
356 } 367 }
357 368
358 bool ParamTraits<std::vector<char> >::Read(const Message* m, 369 bool ParamTraits<std::vector<char>>::Read(const Message* m,
359 PickleIterator* iter, 370 base::PickleIterator* iter,
360 param_type* r) { 371 param_type* r) {
361 const char *data; 372 const char *data;
362 int data_size = 0; 373 int data_size = 0;
363 if (!iter->ReadData(&data, &data_size) || data_size < 0) 374 if (!iter->ReadData(&data, &data_size) || data_size < 0)
364 return false; 375 return false;
365 r->resize(data_size); 376 r->resize(data_size);
366 if (data_size) 377 if (data_size)
367 memcpy(&r->front(), data, data_size); 378 memcpy(&r->front(), data, data_size);
368 return true; 379 return true;
369 } 380 }
370 381
371 void ParamTraits<std::vector<char> >::Log(const param_type& p, std::string* l) { 382 void ParamTraits<std::vector<char> >::Log(const param_type& p, std::string* l) {
372 LogBytes(p, l); 383 LogBytes(p, l);
373 } 384 }
374 385
375 void ParamTraits<std::vector<unsigned char> >::Write(Message* m, 386 void ParamTraits<std::vector<unsigned char> >::Write(Message* m,
376 const param_type& p) { 387 const param_type& p) {
377 if (p.empty()) { 388 if (p.empty()) {
378 m->WriteData(NULL, 0); 389 m->WriteData(NULL, 0);
379 } else { 390 } else {
380 m->WriteData(reinterpret_cast<const char*>(&p.front()), 391 m->WriteData(reinterpret_cast<const char*>(&p.front()),
381 static_cast<int>(p.size())); 392 static_cast<int>(p.size()));
382 } 393 }
383 } 394 }
384 395
385 bool ParamTraits<std::vector<unsigned char> >::Read(const Message* m, 396 bool ParamTraits<std::vector<unsigned char>>::Read(const Message* m,
386 PickleIterator* iter, 397 base::PickleIterator* iter,
387 param_type* r) { 398 param_type* r) {
388 const char *data; 399 const char *data;
389 int data_size = 0; 400 int data_size = 0;
390 if (!iter->ReadData(&data, &data_size) || data_size < 0) 401 if (!iter->ReadData(&data, &data_size) || data_size < 0)
391 return false; 402 return false;
392 r->resize(data_size); 403 r->resize(data_size);
393 if (data_size) 404 if (data_size)
394 memcpy(&r->front(), data, data_size); 405 memcpy(&r->front(), data, data_size);
395 return true; 406 return true;
396 } 407 }
397 408
398 void ParamTraits<std::vector<unsigned char> >::Log(const param_type& p, 409 void ParamTraits<std::vector<unsigned char> >::Log(const param_type& p,
399 std::string* l) { 410 std::string* l) {
400 LogBytes(p, l); 411 LogBytes(p, l);
401 } 412 }
402 413
403 void ParamTraits<std::vector<bool> >::Write(Message* m, const param_type& p) { 414 void ParamTraits<std::vector<bool> >::Write(Message* m, const param_type& p) {
404 WriteParam(m, static_cast<int>(p.size())); 415 WriteParam(m, static_cast<int>(p.size()));
405 // Cast to bool below is required because libc++'s 416 // Cast to bool below is required because libc++'s
406 // vector<bool>::const_reference is different from bool, and we want to avoid 417 // vector<bool>::const_reference is different from bool, and we want to avoid
407 // writing an extra specialization of ParamTraits for it. 418 // writing an extra specialization of ParamTraits for it.
408 for (size_t i = 0; i < p.size(); i++) 419 for (size_t i = 0; i < p.size(); i++)
409 WriteParam(m, static_cast<bool>(p[i])); 420 WriteParam(m, static_cast<bool>(p[i]));
410 } 421 }
411 422
412 bool ParamTraits<std::vector<bool> >::Read(const Message* m, 423 bool ParamTraits<std::vector<bool>>::Read(const Message* m,
413 PickleIterator* iter, 424 base::PickleIterator* iter,
414 param_type* r) { 425 param_type* r) {
415 int size; 426 int size;
416 // ReadLength() checks for < 0 itself. 427 // ReadLength() checks for < 0 itself.
417 if (!iter->ReadLength(&size)) 428 if (!iter->ReadLength(&size))
418 return false; 429 return false;
419 r->resize(size); 430 r->resize(size);
420 for (int i = 0; i < size; i++) { 431 for (int i = 0; i < size; i++) {
421 bool value; 432 bool value;
422 if (!ReadParam(m, iter, &value)) 433 if (!ReadParam(m, iter, &value))
423 return false; 434 return false;
424 (*r)[i] = value; 435 (*r)[i] = value;
425 } 436 }
426 return true; 437 return true;
427 } 438 }
428 439
429 void ParamTraits<std::vector<bool> >::Log(const param_type& p, std::string* l) { 440 void ParamTraits<std::vector<bool> >::Log(const param_type& p, std::string* l) {
430 for (size_t i = 0; i < p.size(); ++i) { 441 for (size_t i = 0; i < p.size(); ++i) {
431 if (i != 0) 442 if (i != 0)
432 l->push_back(' '); 443 l->push_back(' ');
433 LogParam(static_cast<bool>(p[i]), l); 444 LogParam(static_cast<bool>(p[i]), l);
434 } 445 }
435 } 446 }
436 447
437 void ParamTraits<base::DictionaryValue>::Write(Message* m, 448 void ParamTraits<base::DictionaryValue>::Write(Message* m,
438 const param_type& p) { 449 const param_type& p) {
439 WriteValue(m, &p, 0); 450 WriteValue(m, &p, 0);
440 } 451 }
441 452
442 bool ParamTraits<base::DictionaryValue>::Read( 453 bool ParamTraits<base::DictionaryValue>::Read(const Message* m,
443 const Message* m, PickleIterator* iter, param_type* r) { 454 base::PickleIterator* iter,
455 param_type* r) {
444 int type; 456 int type;
445 if (!ReadParam(m, iter, &type) || type != base::Value::TYPE_DICTIONARY) 457 if (!ReadParam(m, iter, &type) || type != base::Value::TYPE_DICTIONARY)
446 return false; 458 return false;
447 459
448 return ReadDictionaryValue(m, iter, r, 0); 460 return ReadDictionaryValue(m, iter, r, 0);
449 } 461 }
450 462
451 void ParamTraits<base::DictionaryValue>::Log(const param_type& p, 463 void ParamTraits<base::DictionaryValue>::Log(const param_type& p,
452 std::string* l) { 464 std::string* l) {
453 std::string json; 465 std::string json;
(...skipping 13 matching lines...) Expand all
467 if (!m->WriteAttachment( 479 if (!m->WriteAttachment(
468 new internal::PlatformFileAttachment(base::ScopedFD(p.fd)))) 480 new internal::PlatformFileAttachment(base::ScopedFD(p.fd))))
469 NOTREACHED(); 481 NOTREACHED();
470 } else { 482 } else {
471 if (!m->WriteAttachment(new internal::PlatformFileAttachment(p.fd))) 483 if (!m->WriteAttachment(new internal::PlatformFileAttachment(p.fd)))
472 NOTREACHED(); 484 NOTREACHED();
473 } 485 }
474 } 486 }
475 487
476 bool ParamTraits<base::FileDescriptor>::Read(const Message* m, 488 bool ParamTraits<base::FileDescriptor>::Read(const Message* m,
477 PickleIterator* iter, 489 base::PickleIterator* iter,
478 param_type* r) { 490 param_type* r) {
479 *r = base::FileDescriptor(); 491 *r = base::FileDescriptor();
480 492
481 bool valid; 493 bool valid;
482 if (!ReadParam(m, iter, &valid)) 494 if (!ReadParam(m, iter, &valid))
483 return false; 495 return false;
484 496
485 // TODO(morrita): Seems like this should return false. 497 // TODO(morrita): Seems like this should return false.
486 if (!valid) 498 if (!valid)
487 return true; 499 return true;
(...skipping 14 matching lines...) Expand all
502 l->append(base::StringPrintf("FD(%d)", p.fd)); 514 l->append(base::StringPrintf("FD(%d)", p.fd));
503 } 515 }
504 } 516 }
505 #endif // defined(OS_POSIX) 517 #endif // defined(OS_POSIX)
506 518
507 void ParamTraits<base::FilePath>::Write(Message* m, const param_type& p) { 519 void ParamTraits<base::FilePath>::Write(Message* m, const param_type& p) {
508 p.WriteToPickle(m); 520 p.WriteToPickle(m);
509 } 521 }
510 522
511 bool ParamTraits<base::FilePath>::Read(const Message* m, 523 bool ParamTraits<base::FilePath>::Read(const Message* m,
512 PickleIterator* iter, 524 base::PickleIterator* iter,
513 param_type* r) { 525 param_type* r) {
514 return r->ReadFromPickle(iter); 526 return r->ReadFromPickle(iter);
515 } 527 }
516 528
517 void ParamTraits<base::FilePath>::Log(const param_type& p, std::string* l) { 529 void ParamTraits<base::FilePath>::Log(const param_type& p, std::string* l) {
518 ParamTraits<base::FilePath::StringType>::Log(p.value(), l); 530 ParamTraits<base::FilePath::StringType>::Log(p.value(), l);
519 } 531 }
520 532
521 void ParamTraits<base::ListValue>::Write(Message* m, const param_type& p) { 533 void ParamTraits<base::ListValue>::Write(Message* m, const param_type& p) {
522 WriteValue(m, &p, 0); 534 WriteValue(m, &p, 0);
523 } 535 }
524 536
525 bool ParamTraits<base::ListValue>::Read( 537 bool ParamTraits<base::ListValue>::Read(const Message* m,
526 const Message* m, PickleIterator* iter, param_type* r) { 538 base::PickleIterator* iter,
539 param_type* r) {
527 int type; 540 int type;
528 if (!ReadParam(m, iter, &type) || type != base::Value::TYPE_LIST) 541 if (!ReadParam(m, iter, &type) || type != base::Value::TYPE_LIST)
529 return false; 542 return false;
530 543
531 return ReadListValue(m, iter, r, 0); 544 return ReadListValue(m, iter, r, 0);
532 } 545 }
533 546
534 void ParamTraits<base::ListValue>::Log(const param_type& p, std::string* l) { 547 void ParamTraits<base::ListValue>::Log(const param_type& p, std::string* l) {
535 std::string json; 548 std::string json;
536 base::JSONWriter::Write(p, &json); 549 base::JSONWriter::Write(p, &json);
537 l->append(json); 550 l->append(json);
538 } 551 }
539 552
540 void ParamTraits<base::NullableString16>::Write(Message* m, 553 void ParamTraits<base::NullableString16>::Write(Message* m,
541 const param_type& p) { 554 const param_type& p) {
542 WriteParam(m, p.string()); 555 WriteParam(m, p.string());
543 WriteParam(m, p.is_null()); 556 WriteParam(m, p.is_null());
544 } 557 }
545 558
546 bool ParamTraits<base::NullableString16>::Read(const Message* m, 559 bool ParamTraits<base::NullableString16>::Read(const Message* m,
547 PickleIterator* iter, 560 base::PickleIterator* iter,
548 param_type* r) { 561 param_type* r) {
549 base::string16 string; 562 base::string16 string;
550 if (!ReadParam(m, iter, &string)) 563 if (!ReadParam(m, iter, &string))
551 return false; 564 return false;
552 bool is_null; 565 bool is_null;
553 if (!ReadParam(m, iter, &is_null)) 566 if (!ReadParam(m, iter, &is_null))
554 return false; 567 return false;
555 *r = base::NullableString16(string, is_null); 568 *r = base::NullableString16(string, is_null);
556 return true; 569 return true;
557 } 570 }
(...skipping 10 matching lines...) Expand all
568 void ParamTraits<base::File::Info>::Write(Message* m, 581 void ParamTraits<base::File::Info>::Write(Message* m,
569 const param_type& p) { 582 const param_type& p) {
570 WriteParam(m, p.size); 583 WriteParam(m, p.size);
571 WriteParam(m, p.is_directory); 584 WriteParam(m, p.is_directory);
572 WriteParam(m, p.last_modified.ToDoubleT()); 585 WriteParam(m, p.last_modified.ToDoubleT());
573 WriteParam(m, p.last_accessed.ToDoubleT()); 586 WriteParam(m, p.last_accessed.ToDoubleT());
574 WriteParam(m, p.creation_time.ToDoubleT()); 587 WriteParam(m, p.creation_time.ToDoubleT());
575 } 588 }
576 589
577 bool ParamTraits<base::File::Info>::Read(const Message* m, 590 bool ParamTraits<base::File::Info>::Read(const Message* m,
578 PickleIterator* iter, 591 base::PickleIterator* iter,
579 param_type* p) { 592 param_type* p) {
580 double last_modified, last_accessed, creation_time; 593 double last_modified, last_accessed, creation_time;
581 if (!ReadParam(m, iter, &p->size) || 594 if (!ReadParam(m, iter, &p->size) ||
582 !ReadParam(m, iter, &p->is_directory) || 595 !ReadParam(m, iter, &p->is_directory) ||
583 !ReadParam(m, iter, &last_modified) || 596 !ReadParam(m, iter, &last_modified) ||
584 !ReadParam(m, iter, &last_accessed) || 597 !ReadParam(m, iter, &last_accessed) ||
585 !ReadParam(m, iter, &creation_time)) 598 !ReadParam(m, iter, &creation_time))
586 return false; 599 return false;
587 p->last_modified = base::Time::FromDoubleT(last_modified); 600 p->last_modified = base::Time::FromDoubleT(last_modified);
588 p->last_accessed = base::Time::FromDoubleT(last_accessed); 601 p->last_accessed = base::Time::FromDoubleT(last_accessed);
(...skipping 13 matching lines...) Expand all
602 LogParam(p.last_accessed.ToDoubleT(), l); 615 LogParam(p.last_accessed.ToDoubleT(), l);
603 l->append(","); 616 l->append(",");
604 LogParam(p.creation_time.ToDoubleT(), l); 617 LogParam(p.creation_time.ToDoubleT(), l);
605 l->append(")"); 618 l->append(")");
606 } 619 }
607 620
608 void ParamTraits<base::Time>::Write(Message* m, const param_type& p) { 621 void ParamTraits<base::Time>::Write(Message* m, const param_type& p) {
609 ParamTraits<int64>::Write(m, p.ToInternalValue()); 622 ParamTraits<int64>::Write(m, p.ToInternalValue());
610 } 623 }
611 624
612 bool ParamTraits<base::Time>::Read(const Message* m, PickleIterator* iter, 625 bool ParamTraits<base::Time>::Read(const Message* m,
626 base::PickleIterator* iter,
613 param_type* r) { 627 param_type* r) {
614 int64 value; 628 int64 value;
615 if (!ParamTraits<int64>::Read(m, iter, &value)) 629 if (!ParamTraits<int64>::Read(m, iter, &value))
616 return false; 630 return false;
617 *r = base::Time::FromInternalValue(value); 631 *r = base::Time::FromInternalValue(value);
618 return true; 632 return true;
619 } 633 }
620 634
621 void ParamTraits<base::Time>::Log(const param_type& p, std::string* l) { 635 void ParamTraits<base::Time>::Log(const param_type& p, std::string* l) {
622 ParamTraits<int64>::Log(p.ToInternalValue(), l); 636 ParamTraits<int64>::Log(p.ToInternalValue(), l);
623 } 637 }
624 638
625 void ParamTraits<base::TimeDelta>::Write(Message* m, const param_type& p) { 639 void ParamTraits<base::TimeDelta>::Write(Message* m, const param_type& p) {
626 ParamTraits<int64>::Write(m, p.ToInternalValue()); 640 ParamTraits<int64>::Write(m, p.ToInternalValue());
627 } 641 }
628 642
629 bool ParamTraits<base::TimeDelta>::Read(const Message* m, 643 bool ParamTraits<base::TimeDelta>::Read(const Message* m,
630 PickleIterator* iter, 644 base::PickleIterator* iter,
631 param_type* r) { 645 param_type* r) {
632 int64 value; 646 int64 value;
633 bool ret = ParamTraits<int64>::Read(m, iter, &value); 647 bool ret = ParamTraits<int64>::Read(m, iter, &value);
634 if (ret) 648 if (ret)
635 *r = base::TimeDelta::FromInternalValue(value); 649 *r = base::TimeDelta::FromInternalValue(value);
636 650
637 return ret; 651 return ret;
638 } 652 }
639 653
640 void ParamTraits<base::TimeDelta>::Log(const param_type& p, std::string* l) { 654 void ParamTraits<base::TimeDelta>::Log(const param_type& p, std::string* l) {
641 ParamTraits<int64>::Log(p.ToInternalValue(), l); 655 ParamTraits<int64>::Log(p.ToInternalValue(), l);
642 } 656 }
643 657
644 void ParamTraits<base::TimeTicks>::Write(Message* m, const param_type& p) { 658 void ParamTraits<base::TimeTicks>::Write(Message* m, const param_type& p) {
645 ParamTraits<int64>::Write(m, p.ToInternalValue()); 659 ParamTraits<int64>::Write(m, p.ToInternalValue());
646 } 660 }
647 661
648 bool ParamTraits<base::TimeTicks>::Read(const Message* m, 662 bool ParamTraits<base::TimeTicks>::Read(const Message* m,
649 PickleIterator* iter, 663 base::PickleIterator* iter,
650 param_type* r) { 664 param_type* r) {
651 int64 value; 665 int64 value;
652 bool ret = ParamTraits<int64>::Read(m, iter, &value); 666 bool ret = ParamTraits<int64>::Read(m, iter, &value);
653 if (ret) 667 if (ret)
654 *r = base::TimeTicks::FromInternalValue(value); 668 *r = base::TimeTicks::FromInternalValue(value);
655 669
656 return ret; 670 return ret;
657 } 671 }
658 672
659 void ParamTraits<base::TimeTicks>::Log(const param_type& p, std::string* l) { 673 void ParamTraits<base::TimeTicks>::Log(const param_type& p, std::string* l) {
660 ParamTraits<int64>::Log(p.ToInternalValue(), l); 674 ParamTraits<int64>::Log(p.ToInternalValue(), l);
661 } 675 }
662 676
663 void ParamTraits<base::TraceTicks>::Write(Message* m, const param_type& p) { 677 void ParamTraits<base::TraceTicks>::Write(Message* m, const param_type& p) {
664 ParamTraits<int64>::Write(m, p.ToInternalValue()); 678 ParamTraits<int64>::Write(m, p.ToInternalValue());
665 } 679 }
666 680
667 bool ParamTraits<base::TraceTicks>::Read(const Message* m, 681 bool ParamTraits<base::TraceTicks>::Read(const Message* m,
668 PickleIterator* iter, 682 base::PickleIterator* iter,
669 param_type* r) { 683 param_type* r) {
670 int64 value; 684 int64 value;
671 bool ret = ParamTraits<int64>::Read(m, iter, &value); 685 bool ret = ParamTraits<int64>::Read(m, iter, &value);
672 if (ret) 686 if (ret)
673 *r = base::TraceTicks::FromInternalValue(value); 687 *r = base::TraceTicks::FromInternalValue(value);
674 688
675 return ret; 689 return ret;
676 } 690 }
677 691
678 void ParamTraits<base::TraceTicks>::Log(const param_type& p, std::string* l) { 692 void ParamTraits<base::TraceTicks>::Log(const param_type& p, std::string* l) {
679 ParamTraits<int64>::Log(p.ToInternalValue(), l); 693 ParamTraits<int64>::Log(p.ToInternalValue(), l);
680 } 694 }
681 695
682 void ParamTraits<IPC::ChannelHandle>::Write(Message* m, const param_type& p) { 696 void ParamTraits<IPC::ChannelHandle>::Write(Message* m, const param_type& p) {
683 #if defined(OS_WIN) 697 #if defined(OS_WIN)
684 // On Windows marshalling pipe handle is not supported. 698 // On Windows marshalling pipe handle is not supported.
685 DCHECK(p.pipe.handle == NULL); 699 DCHECK(p.pipe.handle == NULL);
686 #endif // defined (OS_WIN) 700 #endif // defined (OS_WIN)
687 WriteParam(m, p.name); 701 WriteParam(m, p.name);
688 #if defined(OS_POSIX) 702 #if defined(OS_POSIX)
689 WriteParam(m, p.socket); 703 WriteParam(m, p.socket);
690 #endif 704 #endif
691 } 705 }
692 706
693 bool ParamTraits<IPC::ChannelHandle>::Read(const Message* m, 707 bool ParamTraits<IPC::ChannelHandle>::Read(const Message* m,
694 PickleIterator* iter, 708 base::PickleIterator* iter,
695 param_type* r) { 709 param_type* r) {
696 return ReadParam(m, iter, &r->name) 710 return ReadParam(m, iter, &r->name)
697 #if defined(OS_POSIX) 711 #if defined(OS_POSIX)
698 && ReadParam(m, iter, &r->socket) 712 && ReadParam(m, iter, &r->socket)
699 #endif 713 #endif
700 ; 714 ;
701 } 715 }
702 716
703 void ParamTraits<IPC::ChannelHandle>::Log(const param_type& p, 717 void ParamTraits<IPC::ChannelHandle>::Log(const param_type& p,
704 std::string* l) { 718 std::string* l) {
(...skipping 11 matching lines...) Expand all
716 WriteParam(m, p.type); 730 WriteParam(m, p.type);
717 WriteParam(m, p.flags); 731 WriteParam(m, p.flags);
718 WriteParam(m, p.sent); 732 WriteParam(m, p.sent);
719 WriteParam(m, p.receive); 733 WriteParam(m, p.receive);
720 WriteParam(m, p.dispatch); 734 WriteParam(m, p.dispatch);
721 WriteParam(m, p.message_name); 735 WriteParam(m, p.message_name);
722 WriteParam(m, p.params); 736 WriteParam(m, p.params);
723 } 737 }
724 738
725 bool ParamTraits<LogData>::Read(const Message* m, 739 bool ParamTraits<LogData>::Read(const Message* m,
726 PickleIterator* iter, 740 base::PickleIterator* iter,
727 param_type* r) { 741 param_type* r) {
728 return 742 return
729 ReadParam(m, iter, &r->channel) && 743 ReadParam(m, iter, &r->channel) &&
730 ReadParam(m, iter, &r->routing_id) && 744 ReadParam(m, iter, &r->routing_id) &&
731 ReadParam(m, iter, &r->type) && 745 ReadParam(m, iter, &r->type) &&
732 ReadParam(m, iter, &r->flags) && 746 ReadParam(m, iter, &r->flags) &&
733 ReadParam(m, iter, &r->sent) && 747 ReadParam(m, iter, &r->sent) &&
734 ReadParam(m, iter, &r->receive) && 748 ReadParam(m, iter, &r->receive) &&
735 ReadParam(m, iter, &r->dispatch) && 749 ReadParam(m, iter, &r->dispatch) &&
736 ReadParam(m, iter, &r->message_name) && 750 ReadParam(m, iter, &r->message_name) &&
(...skipping 20 matching lines...) Expand all
757 // Be careful also to use only explicitly-sized types. The NaCl environment 771 // Be careful also to use only explicitly-sized types. The NaCl environment
758 // could be 64-bit and the host browser could be 32-bits. The nested message 772 // could be 64-bit and the host browser could be 32-bits. The nested message
759 // may or may not be safe to send between 32-bit and 64-bit systems, but we 773 // may or may not be safe to send between 32-bit and 64-bit systems, but we
760 // leave that up to the code sending the message to ensure. 774 // leave that up to the code sending the message to ensure.
761 m->WriteUInt32(static_cast<uint32>(p.routing_id())); 775 m->WriteUInt32(static_cast<uint32>(p.routing_id()));
762 m->WriteUInt32(p.type()); 776 m->WriteUInt32(p.type());
763 m->WriteUInt32(p.flags()); 777 m->WriteUInt32(p.flags());
764 m->WriteData(p.payload(), static_cast<uint32>(p.payload_size())); 778 m->WriteData(p.payload(), static_cast<uint32>(p.payload_size()));
765 } 779 }
766 780
767 bool ParamTraits<Message>::Read(const Message* m, PickleIterator* iter, 781 bool ParamTraits<Message>::Read(const Message* m,
782 base::PickleIterator* iter,
768 Message* r) { 783 Message* r) {
769 uint32 routing_id, type, flags; 784 uint32 routing_id, type, flags;
770 if (!iter->ReadUInt32(&routing_id) || 785 if (!iter->ReadUInt32(&routing_id) ||
771 !iter->ReadUInt32(&type) || 786 !iter->ReadUInt32(&type) ||
772 !iter->ReadUInt32(&flags)) 787 !iter->ReadUInt32(&flags))
773 return false; 788 return false;
774 789
775 int payload_size; 790 int payload_size;
776 const char* payload; 791 const char* payload;
777 if (!iter->ReadData(&payload, &payload_size)) 792 if (!iter->ReadData(&payload, &payload_size))
778 return false; 793 return false;
779 794
780 r->SetHeaderValues(static_cast<int32>(routing_id), type, flags); 795 r->SetHeaderValues(static_cast<int32>(routing_id), type, flags);
781 return r->WriteBytes(payload, payload_size); 796 return r->WriteBytes(payload, payload_size);
782 } 797 }
783 798
784 void ParamTraits<Message>::Log(const Message& p, std::string* l) { 799 void ParamTraits<Message>::Log(const Message& p, std::string* l) {
785 l->append("<IPC::Message>"); 800 l->append("<IPC::Message>");
786 } 801 }
787 802
788 #if defined(OS_WIN) 803 #if defined(OS_WIN)
789 // Note that HWNDs/HANDLE/HCURSOR/HACCEL etc are always 32 bits, even on 64 804 // Note that HWNDs/HANDLE/HCURSOR/HACCEL etc are always 32 bits, even on 64
790 // bit systems. That's why we use the Windows macros to convert to 32 bits. 805 // bit systems. That's why we use the Windows macros to convert to 32 bits.
791 void ParamTraits<HANDLE>::Write(Message* m, const param_type& p) { 806 void ParamTraits<HANDLE>::Write(Message* m, const param_type& p) {
792 m->WriteInt(HandleToLong(p)); 807 m->WriteInt(HandleToLong(p));
793 } 808 }
794 809
795 bool ParamTraits<HANDLE>::Read(const Message* m, PickleIterator* iter, 810 bool ParamTraits<HANDLE>::Read(const Message* m,
811 base::PickleIterator* iter,
796 param_type* r) { 812 param_type* r) {
797 int32 temp; 813 int32 temp;
798 if (!iter->ReadInt(&temp)) 814 if (!iter->ReadInt(&temp))
799 return false; 815 return false;
800 *r = LongToHandle(temp); 816 *r = LongToHandle(temp);
801 return true; 817 return true;
802 } 818 }
803 819
804 void ParamTraits<HANDLE>::Log(const param_type& p, std::string* l) { 820 void ParamTraits<HANDLE>::Log(const param_type& p, std::string* l) {
805 l->append(base::StringPrintf("0x%X", p)); 821 l->append(base::StringPrintf("0x%X", p));
806 } 822 }
807 823
808 void ParamTraits<LOGFONT>::Write(Message* m, const param_type& p) { 824 void ParamTraits<LOGFONT>::Write(Message* m, const param_type& p) {
809 m->WriteData(reinterpret_cast<const char*>(&p), sizeof(LOGFONT)); 825 m->WriteData(reinterpret_cast<const char*>(&p), sizeof(LOGFONT));
810 } 826 }
811 827
812 bool ParamTraits<LOGFONT>::Read(const Message* m, PickleIterator* iter, 828 bool ParamTraits<LOGFONT>::Read(const Message* m,
829 base::PickleIterator* iter,
813 param_type* r) { 830 param_type* r) {
814 const char *data; 831 const char *data;
815 int data_size = 0; 832 int data_size = 0;
816 if (iter->ReadData(&data, &data_size) && data_size == sizeof(LOGFONT)) { 833 if (iter->ReadData(&data, &data_size) && data_size == sizeof(LOGFONT)) {
817 const LOGFONT *font = reinterpret_cast<LOGFONT*>(const_cast<char*>(data)); 834 const LOGFONT *font = reinterpret_cast<LOGFONT*>(const_cast<char*>(data));
818 if (_tcsnlen(font->lfFaceName, LF_FACESIZE) < LF_FACESIZE) { 835 if (_tcsnlen(font->lfFaceName, LF_FACESIZE) < LF_FACESIZE) {
819 memcpy(r, data, sizeof(LOGFONT)); 836 memcpy(r, data, sizeof(LOGFONT));
820 return true; 837 return true;
821 } 838 }
822 } 839 }
823 840
824 NOTREACHED(); 841 NOTREACHED();
825 return false; 842 return false;
826 } 843 }
827 844
828 void ParamTraits<LOGFONT>::Log(const param_type& p, std::string* l) { 845 void ParamTraits<LOGFONT>::Log(const param_type& p, std::string* l) {
829 l->append(base::StringPrintf("<LOGFONT>")); 846 l->append(base::StringPrintf("<LOGFONT>"));
830 } 847 }
831 848
832 void ParamTraits<MSG>::Write(Message* m, const param_type& p) { 849 void ParamTraits<MSG>::Write(Message* m, const param_type& p) {
833 m->WriteData(reinterpret_cast<const char*>(&p), sizeof(MSG)); 850 m->WriteData(reinterpret_cast<const char*>(&p), sizeof(MSG));
834 } 851 }
835 852
836 bool ParamTraits<MSG>::Read(const Message* m, PickleIterator* iter, 853 bool ParamTraits<MSG>::Read(const Message* m,
854 base::PickleIterator* iter,
837 param_type* r) { 855 param_type* r) {
838 const char *data; 856 const char *data;
839 int data_size = 0; 857 int data_size = 0;
840 bool result = iter->ReadData(&data, &data_size); 858 bool result = iter->ReadData(&data, &data_size);
841 if (result && data_size == sizeof(MSG)) { 859 if (result && data_size == sizeof(MSG)) {
842 memcpy(r, data, sizeof(MSG)); 860 memcpy(r, data, sizeof(MSG));
843 } else { 861 } else {
844 result = false; 862 result = false;
845 NOTREACHED(); 863 NOTREACHED();
846 } 864 }
847 865
848 return result; 866 return result;
849 } 867 }
850 868
851 void ParamTraits<MSG>::Log(const param_type& p, std::string* l) { 869 void ParamTraits<MSG>::Log(const param_type& p, std::string* l) {
852 l->append("<MSG>"); 870 l->append("<MSG>");
853 } 871 }
854 872
855 #endif // OS_WIN 873 #endif // OS_WIN
856 874
857 } // namespace IPC 875 } // namespace IPC
OLDNEW
« no previous file with comments | « ipc/ipc_message_utils.h ('k') | ipc/ipc_message_utils_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698