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 <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
11 #include "base/json/json_writer.h" | 11 #include "base/json/json_writer.h" |
12 #include "base/memory/ptr_util.h" | |
12 #include "base/strings/nullable_string16.h" | 13 #include "base/strings/nullable_string16.h" |
13 #include "base/strings/string_number_conversions.h" | 14 #include "base/strings/string_number_conversions.h" |
14 #include "base/strings/utf_string_conversions.h" | 15 #include "base/strings/utf_string_conversions.h" |
15 #include "base/time/time.h" | 16 #include "base/time/time.h" |
16 #include "base/unguessable_token.h" | 17 #include "base/unguessable_token.h" |
17 #include "base/values.h" | 18 #include "base/values.h" |
18 #include "build/build_config.h" | 19 #include "build/build_config.h" |
19 #include "ipc/ipc_channel_handle.h" | 20 #include "ipc/ipc_channel_handle.h" |
20 #include "ipc/ipc_message_attachment.h" | 21 #include "ipc/ipc_message_attachment.h" |
21 #include "ipc/ipc_message_attachment_set.h" | 22 #include "ipc/ipc_message_attachment_set.h" |
(...skipping 607 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
629 return ReadDictionaryValue(m, iter, r, 0); | 630 return ReadDictionaryValue(m, iter, r, 0); |
630 } | 631 } |
631 | 632 |
632 void ParamTraits<base::DictionaryValue>::Log(const param_type& p, | 633 void ParamTraits<base::DictionaryValue>::Log(const param_type& p, |
633 std::string* l) { | 634 std::string* l) { |
634 std::string json; | 635 std::string json; |
635 base::JSONWriter::Write(p, &json); | 636 base::JSONWriter::Write(p, &json); |
636 l->append(json); | 637 l->append(json); |
637 } | 638 } |
638 | 639 |
640 void ParamTraits<std::unique_ptr<base::Value>>::GetSize( | |
641 base::PickleSizer* sizer, | |
642 const param_type& p) { | |
643 bool valid = !!p; | |
644 GetParamSize(sizer, valid); | |
645 if (valid) | |
646 GetValueSize(sizer, p.get(), 0); | |
647 } | |
648 | |
649 void ParamTraits<std::unique_ptr<base::Value>>::Write(base::Pickle* m, | |
650 const param_type& p) { | |
651 bool valid = !!p; | |
652 WriteParam(m, valid); | |
653 if (valid) | |
654 WriteValue(m, p.get(), 0); | |
655 } | |
656 | |
657 bool ParamTraits<std::unique_ptr<base::Value>>::Read(const base::Pickle* m, | |
658 base::PickleIterator* iter, | |
659 param_type* r) { | |
660 bool valid = false; | |
661 if (!ReadParam(m, iter, &valid)) | |
662 return false; | |
663 | |
664 if (!valid) { | |
665 r->reset(); | |
666 return true; | |
667 } | |
668 | |
669 base::Value* temp = nullptr; | |
670 if (!ReadValue(m, iter, &temp, 0)) | |
671 return false; | |
672 | |
673 *r = base::WrapUnique(temp); | |
674 return true; | |
675 } | |
676 | |
677 void ParamTraits<std::unique_ptr<base::Value>>::Log(const param_type& p, | |
678 std::string* l) { | |
679 std::string json = "nullptr"; | |
yzshen1
2016/11/03 21:59:24
nit: maybe default to empty and only set "nullptr"
| |
680 if (p.get()) | |
681 base::JSONWriter::Write(*p, &json); | |
682 l->append(json); | |
683 } | |
684 | |
639 #if defined(OS_POSIX) | 685 #if defined(OS_POSIX) |
640 void ParamTraits<base::FileDescriptor>::GetSize(base::PickleSizer* sizer, | 686 void ParamTraits<base::FileDescriptor>::GetSize(base::PickleSizer* sizer, |
641 const param_type& p) { | 687 const param_type& p) { |
642 GetParamSize(sizer, p.fd >= 0); | 688 GetParamSize(sizer, p.fd >= 0); |
643 if (p.fd >= 0) | 689 if (p.fd >= 0) |
644 sizer->AddAttachment(); | 690 sizer->AddAttachment(); |
645 } | 691 } |
646 | 692 |
647 void ParamTraits<base::FileDescriptor>::Write(base::Pickle* m, | 693 void ParamTraits<base::FileDescriptor>::Write(base::Pickle* m, |
648 const param_type& p) { | 694 const param_type& p) { |
(...skipping 602 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1251 return result; | 1297 return result; |
1252 } | 1298 } |
1253 | 1299 |
1254 void ParamTraits<MSG>::Log(const param_type& p, std::string* l) { | 1300 void ParamTraits<MSG>::Log(const param_type& p, std::string* l) { |
1255 l->append("<MSG>"); | 1301 l->append("<MSG>"); |
1256 } | 1302 } |
1257 | 1303 |
1258 #endif // OS_WIN | 1304 #endif // OS_WIN |
1259 | 1305 |
1260 } // namespace IPC | 1306 } // namespace IPC |
OLD | NEW |