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 #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 444 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
455 std::string json; | 455 std::string json; |
456 base::JSONWriter::Write(&p, &json); | 456 base::JSONWriter::Write(&p, &json); |
457 l->append(json); | 457 l->append(json); |
458 } | 458 } |
459 | 459 |
460 #if defined(OS_POSIX) | 460 #if defined(OS_POSIX) |
461 void ParamTraits<base::FileDescriptor>::Write(Message* m, const param_type& p) { | 461 void ParamTraits<base::FileDescriptor>::Write(Message* m, const param_type& p) { |
462 const bool valid = p.fd >= 0; | 462 const bool valid = p.fd >= 0; |
463 WriteParam(m, valid); | 463 WriteParam(m, valid); |
464 | 464 |
465 if (valid) { | 465 if (!valid) |
466 if (!m->WriteFileDescriptor(p)) | 466 return; |
| 467 |
| 468 if (p.auto_close) { |
| 469 if (!m->WriteFile(base::ScopedFD(p.fd))) |
| 470 NOTREACHED(); |
| 471 } else { |
| 472 if (!m->WriteBorrowingFile(p.fd)) |
467 NOTREACHED(); | 473 NOTREACHED(); |
468 } | 474 } |
469 } | 475 } |
470 | 476 |
471 bool ParamTraits<base::FileDescriptor>::Read(const Message* m, | 477 bool ParamTraits<base::FileDescriptor>::Read(const Message* m, |
472 PickleIterator* iter, | 478 PickleIterator* iter, |
473 param_type* r) { | 479 param_type* r) { |
| 480 *r = base::FileDescriptor(); |
| 481 |
474 bool valid; | 482 bool valid; |
475 if (!ReadParam(m, iter, &valid)) | 483 if (!ReadParam(m, iter, &valid)) |
476 return false; | 484 return false; |
477 | 485 |
478 if (!valid) { | 486 // TODO(morrita): Seems like this should return false. |
479 r->fd = -1; | 487 if (!valid) |
480 r->auto_close = false; | |
481 return true; | 488 return true; |
482 } | |
483 | 489 |
484 return m->ReadFileDescriptor(iter, r); | 490 base::ScopedFD fd; |
| 491 if (!m->ReadFile(iter, &fd)) |
| 492 return false; |
| 493 |
| 494 *r = base::FileDescriptor(fd.release(), true); |
| 495 return true; |
485 } | 496 } |
486 | 497 |
487 void ParamTraits<base::FileDescriptor>::Log(const param_type& p, | 498 void ParamTraits<base::FileDescriptor>::Log(const param_type& p, |
488 std::string* l) { | 499 std::string* l) { |
489 if (p.auto_close) { | 500 if (p.auto_close) { |
490 l->append(base::StringPrintf("FD(%d auto-close)", p.fd)); | 501 l->append(base::StringPrintf("FD(%d auto-close)", p.fd)); |
491 } else { | 502 } else { |
492 l->append(base::StringPrintf("FD(%d)", p.fd)); | 503 l->append(base::StringPrintf("FD(%d)", p.fd)); |
493 } | 504 } |
494 } | 505 } |
(...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
819 return result; | 830 return result; |
820 } | 831 } |
821 | 832 |
822 void ParamTraits<MSG>::Log(const param_type& p, std::string* l) { | 833 void ParamTraits<MSG>::Log(const param_type& p, std::string* l) { |
823 l->append("<MSG>"); | 834 l->append("<MSG>"); |
824 } | 835 } |
825 | 836 |
826 #endif // OS_WIN | 837 #endif // OS_WIN |
827 | 838 |
828 } // namespace IPC | 839 } // namespace IPC |
OLD | NEW |