Chromium Code Reviews| 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::File(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 if (!valid) |
|
agl
2014/09/18 01:17:26
One hopes this change is correct, but it looks rea
Hajime Morrita
2014/09/18 01:29:08
Well, I'll preserve existing code for now and chan
| |
| 479 r->fd = -1; | 487 return false; |
| 480 r->auto_close = false; | |
| 481 return true; | |
| 482 } | |
| 483 | 488 |
| 484 return m->ReadFileDescriptor(iter, r); | 489 base::File fd; |
| 490 if (!m->ReadFile(iter, &fd)) | |
| 491 return false; | |
| 492 | |
| 493 *r = base::FileDescriptor(fd.Pass()); | |
| 494 return true; | |
| 485 } | 495 } |
| 486 | 496 |
| 487 void ParamTraits<base::FileDescriptor>::Log(const param_type& p, | 497 void ParamTraits<base::FileDescriptor>::Log(const param_type& p, |
| 488 std::string* l) { | 498 std::string* l) { |
| 489 if (p.auto_close) { | 499 if (p.auto_close) { |
| 490 l->append(base::StringPrintf("FD(%d auto-close)", p.fd)); | 500 l->append(base::StringPrintf("FD(%d auto-close)", p.fd)); |
| 491 } else { | 501 } else { |
| 492 l->append(base::StringPrintf("FD(%d)", p.fd)); | 502 l->append(base::StringPrintf("FD(%d)", p.fd)); |
| 493 } | 503 } |
| 494 } | 504 } |
| (...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 819 return result; | 829 return result; |
| 820 } | 830 } |
| 821 | 831 |
| 822 void ParamTraits<MSG>::Log(const param_type& p, std::string* l) { | 832 void ParamTraits<MSG>::Log(const param_type& p, std::string* l) { |
| 823 l->append("<MSG>"); | 833 l->append("<MSG>"); |
| 824 } | 834 } |
| 825 | 835 |
| 826 #endif // OS_WIN | 836 #endif // OS_WIN |
| 827 | 837 |
| 828 } // namespace IPC | 838 } // namespace IPC |
| OLD | NEW |