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

Side by Side Diff: ipc/ipc_message_utils.cc

Issue 1322253003: ipc: Convert int types from basictypes.h to the ones from stdint.h (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: REBASE Created 5 years, 3 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 296 matching lines...) Expand 10 before | Expand all | Expand 10 after
307 307
308 void ParamTraits<int>::Log(const param_type& p, std::string* l) { 308 void ParamTraits<int>::Log(const param_type& p, std::string* l) {
309 l->append(base::IntToString(p)); 309 l->append(base::IntToString(p));
310 } 310 }
311 311
312 void ParamTraits<unsigned int>::Log(const param_type& p, std::string* l) { 312 void ParamTraits<unsigned int>::Log(const param_type& p, std::string* l) {
313 l->append(base::UintToString(p)); 313 l->append(base::UintToString(p));
314 } 314 }
315 315
316 void ParamTraits<long>::Log(const param_type& p, std::string* l) { 316 void ParamTraits<long>::Log(const param_type& p, std::string* l) {
317 l->append(base::Int64ToString(static_cast<int64>(p))); 317 l->append(base::Int64ToString(static_cast<int64_t>(p)));
318 } 318 }
319 319
320 void ParamTraits<unsigned long>::Log(const param_type& p, std::string* l) { 320 void ParamTraits<unsigned long>::Log(const param_type& p, std::string* l) {
321 l->append(base::Uint64ToString(static_cast<uint64>(p))); 321 l->append(base::Uint64ToString(static_cast<uint64_t>(p)));
322 } 322 }
323 323
324 void ParamTraits<long long>::Log(const param_type& p, std::string* l) { 324 void ParamTraits<long long>::Log(const param_type& p, std::string* l) {
325 l->append(base::Int64ToString(static_cast<int64>(p))); 325 l->append(base::Int64ToString(static_cast<int64_t>(p)));
326 } 326 }
327 327
328 void ParamTraits<unsigned long long>::Log(const param_type& p, std::string* l) { 328 void ParamTraits<unsigned long long>::Log(const param_type& p, std::string* l) {
329 l->append(base::Uint64ToString(p)); 329 l->append(base::Uint64ToString(p));
330 } 330 }
331 331
332 void ParamTraits<float>::Log(const param_type& p, std::string* l) { 332 void ParamTraits<float>::Log(const param_type& p, std::string* l) {
333 l->append(base::StringPrintf("%e", p)); 333 l->append(base::StringPrintf("%e", p));
334 } 334 }
335 335
(...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after
690 l->append(","); 690 l->append(",");
691 LogParam(p.last_modified.ToDoubleT(), l); 691 LogParam(p.last_modified.ToDoubleT(), l);
692 l->append(","); 692 l->append(",");
693 LogParam(p.last_accessed.ToDoubleT(), l); 693 LogParam(p.last_accessed.ToDoubleT(), l);
694 l->append(","); 694 l->append(",");
695 LogParam(p.creation_time.ToDoubleT(), l); 695 LogParam(p.creation_time.ToDoubleT(), l);
696 l->append(")"); 696 l->append(")");
697 } 697 }
698 698
699 void ParamTraits<base::Time>::Write(Message* m, const param_type& p) { 699 void ParamTraits<base::Time>::Write(Message* m, const param_type& p) {
700 ParamTraits<int64>::Write(m, p.ToInternalValue()); 700 ParamTraits<int64_t>::Write(m, p.ToInternalValue());
701 } 701 }
702 702
703 bool ParamTraits<base::Time>::Read(const Message* m, 703 bool ParamTraits<base::Time>::Read(const Message* m,
704 base::PickleIterator* iter, 704 base::PickleIterator* iter,
705 param_type* r) { 705 param_type* r) {
706 int64 value; 706 int64_t value;
707 if (!ParamTraits<int64>::Read(m, iter, &value)) 707 if (!ParamTraits<int64_t>::Read(m, iter, &value))
708 return false; 708 return false;
709 *r = base::Time::FromInternalValue(value); 709 *r = base::Time::FromInternalValue(value);
710 return true; 710 return true;
711 } 711 }
712 712
713 void ParamTraits<base::Time>::Log(const param_type& p, std::string* l) { 713 void ParamTraits<base::Time>::Log(const param_type& p, std::string* l) {
714 ParamTraits<int64>::Log(p.ToInternalValue(), l); 714 ParamTraits<int64_t>::Log(p.ToInternalValue(), l);
715 } 715 }
716 716
717 void ParamTraits<base::TimeDelta>::Write(Message* m, const param_type& p) { 717 void ParamTraits<base::TimeDelta>::Write(Message* m, const param_type& p) {
718 ParamTraits<int64>::Write(m, p.ToInternalValue()); 718 ParamTraits<int64_t>::Write(m, p.ToInternalValue());
719 } 719 }
720 720
721 bool ParamTraits<base::TimeDelta>::Read(const Message* m, 721 bool ParamTraits<base::TimeDelta>::Read(const Message* m,
722 base::PickleIterator* iter, 722 base::PickleIterator* iter,
723 param_type* r) { 723 param_type* r) {
724 int64 value; 724 int64_t value;
725 bool ret = ParamTraits<int64>::Read(m, iter, &value); 725 bool ret = ParamTraits<int64_t>::Read(m, iter, &value);
726 if (ret) 726 if (ret)
727 *r = base::TimeDelta::FromInternalValue(value); 727 *r = base::TimeDelta::FromInternalValue(value);
728 728
729 return ret; 729 return ret;
730 } 730 }
731 731
732 void ParamTraits<base::TimeDelta>::Log(const param_type& p, std::string* l) { 732 void ParamTraits<base::TimeDelta>::Log(const param_type& p, std::string* l) {
733 ParamTraits<int64>::Log(p.ToInternalValue(), l); 733 ParamTraits<int64_t>::Log(p.ToInternalValue(), l);
734 } 734 }
735 735
736 void ParamTraits<base::TimeTicks>::Write(Message* m, const param_type& p) { 736 void ParamTraits<base::TimeTicks>::Write(Message* m, const param_type& p) {
737 ParamTraits<int64>::Write(m, p.ToInternalValue()); 737 ParamTraits<int64_t>::Write(m, p.ToInternalValue());
738 } 738 }
739 739
740 bool ParamTraits<base::TimeTicks>::Read(const Message* m, 740 bool ParamTraits<base::TimeTicks>::Read(const Message* m,
741 base::PickleIterator* iter, 741 base::PickleIterator* iter,
742 param_type* r) { 742 param_type* r) {
743 int64 value; 743 int64_t value;
744 bool ret = ParamTraits<int64>::Read(m, iter, &value); 744 bool ret = ParamTraits<int64_t>::Read(m, iter, &value);
745 if (ret) 745 if (ret)
746 *r = base::TimeTicks::FromInternalValue(value); 746 *r = base::TimeTicks::FromInternalValue(value);
747 747
748 return ret; 748 return ret;
749 } 749 }
750 750
751 void ParamTraits<base::TimeTicks>::Log(const param_type& p, std::string* l) { 751 void ParamTraits<base::TimeTicks>::Log(const param_type& p, std::string* l) {
752 ParamTraits<int64>::Log(p.ToInternalValue(), l); 752 ParamTraits<int64_t>::Log(p.ToInternalValue(), l);
753 } 753 }
754 754
755 void ParamTraits<base::TraceTicks>::Write(Message* m, const param_type& p) { 755 void ParamTraits<base::TraceTicks>::Write(Message* m, const param_type& p) {
756 ParamTraits<int64>::Write(m, p.ToInternalValue()); 756 ParamTraits<int64_t>::Write(m, p.ToInternalValue());
757 } 757 }
758 758
759 bool ParamTraits<base::TraceTicks>::Read(const Message* m, 759 bool ParamTraits<base::TraceTicks>::Read(const Message* m,
760 base::PickleIterator* iter, 760 base::PickleIterator* iter,
761 param_type* r) { 761 param_type* r) {
762 int64 value; 762 int64_t value;
763 bool ret = ParamTraits<int64>::Read(m, iter, &value); 763 bool ret = ParamTraits<int64_t>::Read(m, iter, &value);
764 if (ret) 764 if (ret)
765 *r = base::TraceTicks::FromInternalValue(value); 765 *r = base::TraceTicks::FromInternalValue(value);
766 766
767 return ret; 767 return ret;
768 } 768 }
769 769
770 void ParamTraits<base::TraceTicks>::Log(const param_type& p, std::string* l) { 770 void ParamTraits<base::TraceTicks>::Log(const param_type& p, std::string* l) {
771 ParamTraits<int64>::Log(p.ToInternalValue(), l); 771 ParamTraits<int64_t>::Log(p.ToInternalValue(), l);
772 } 772 }
773 773
774 void ParamTraits<IPC::ChannelHandle>::Write(Message* m, const param_type& p) { 774 void ParamTraits<IPC::ChannelHandle>::Write(Message* m, const param_type& p) {
775 #if defined(OS_WIN) 775 #if defined(OS_WIN)
776 // On Windows marshalling pipe handle is not supported. 776 // On Windows marshalling pipe handle is not supported.
777 DCHECK(p.pipe.handle == NULL); 777 DCHECK(p.pipe.handle == NULL);
778 #endif // defined (OS_WIN) 778 #endif // defined (OS_WIN)
779 WriteParam(m, p.name); 779 WriteParam(m, p.name);
780 #if defined(OS_POSIX) 780 #if defined(OS_POSIX)
781 WriteParam(m, p.socket); 781 WriteParam(m, p.socket);
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
843 // Don't just write out the message. This is used to send messages between 843 // Don't just write out the message. This is used to send messages between
844 // NaCl (Posix environment) and the browser (could be on Windows). The message 844 // NaCl (Posix environment) and the browser (could be on Windows). The message
845 // header formats differ between these systems (so does handle sharing, but 845 // header formats differ between these systems (so does handle sharing, but
846 // we already asserted we don't have any handles). So just write out the 846 // we already asserted we don't have any handles). So just write out the
847 // parts of the header we use. 847 // parts of the header we use.
848 // 848 //
849 // Be careful also to use only explicitly-sized types. The NaCl environment 849 // Be careful also to use only explicitly-sized types. The NaCl environment
850 // could be 64-bit and the host browser could be 32-bits. The nested message 850 // could be 64-bit and the host browser could be 32-bits. The nested message
851 // may or may not be safe to send between 32-bit and 64-bit systems, but we 851 // may or may not be safe to send between 32-bit and 64-bit systems, but we
852 // leave that up to the code sending the message to ensure. 852 // leave that up to the code sending the message to ensure.
853 m->WriteUInt32(static_cast<uint32>(p.routing_id())); 853 m->WriteUInt32(static_cast<uint32_t>(p.routing_id()));
854 m->WriteUInt32(p.type()); 854 m->WriteUInt32(p.type());
855 m->WriteUInt32(p.flags()); 855 m->WriteUInt32(p.flags());
856 m->WriteData(p.payload(), static_cast<uint32>(p.payload_size())); 856 m->WriteData(p.payload(), static_cast<uint32_t>(p.payload_size()));
857 } 857 }
858 858
859 bool ParamTraits<Message>::Read(const Message* m, 859 bool ParamTraits<Message>::Read(const Message* m,
860 base::PickleIterator* iter, 860 base::PickleIterator* iter,
861 Message* r) { 861 Message* r) {
862 uint32 routing_id, type, flags; 862 uint32_t routing_id, type, flags;
863 if (!iter->ReadUInt32(&routing_id) || 863 if (!iter->ReadUInt32(&routing_id) ||
864 !iter->ReadUInt32(&type) || 864 !iter->ReadUInt32(&type) ||
865 !iter->ReadUInt32(&flags)) 865 !iter->ReadUInt32(&flags))
866 return false; 866 return false;
867 867
868 int payload_size; 868 int payload_size;
869 const char* payload; 869 const char* payload;
870 if (!iter->ReadData(&payload, &payload_size)) 870 if (!iter->ReadData(&payload, &payload_size))
871 return false; 871 return false;
872 872
873 r->SetHeaderValues(static_cast<int32>(routing_id), type, flags); 873 r->SetHeaderValues(static_cast<int32_t>(routing_id), type, flags);
874 return r->WriteBytes(payload, payload_size); 874 return r->WriteBytes(payload, payload_size);
875 } 875 }
876 876
877 void ParamTraits<Message>::Log(const Message& p, std::string* l) { 877 void ParamTraits<Message>::Log(const Message& p, std::string* l) {
878 l->append("<IPC::Message>"); 878 l->append("<IPC::Message>");
879 } 879 }
880 880
881 #if defined(OS_WIN) 881 #if defined(OS_WIN)
882 // Note that HWNDs/HANDLE/HCURSOR/HACCEL etc are always 32 bits, even on 64 882 // Note that HWNDs/HANDLE/HCURSOR/HACCEL etc are always 32 bits, even on 64
883 // bit systems. That's why we use the Windows macros to convert to 32 bits. 883 // bit systems. That's why we use the Windows macros to convert to 32 bits.
884 void ParamTraits<HANDLE>::Write(Message* m, const param_type& p) { 884 void ParamTraits<HANDLE>::Write(Message* m, const param_type& p) {
885 m->WriteInt(HandleToLong(p)); 885 m->WriteInt(HandleToLong(p));
886 } 886 }
887 887
888 bool ParamTraits<HANDLE>::Read(const Message* m, 888 bool ParamTraits<HANDLE>::Read(const Message* m,
889 base::PickleIterator* iter, 889 base::PickleIterator* iter,
890 param_type* r) { 890 param_type* r) {
891 int32 temp; 891 int32_t temp;
892 if (!iter->ReadInt(&temp)) 892 if (!iter->ReadInt(&temp))
893 return false; 893 return false;
894 *r = LongToHandle(temp); 894 *r = LongToHandle(temp);
895 return true; 895 return true;
896 } 896 }
897 897
898 void ParamTraits<HANDLE>::Log(const param_type& p, std::string* l) { 898 void ParamTraits<HANDLE>::Log(const param_type& p, std::string* l) {
899 l->append(base::StringPrintf("0x%X", p)); 899 l->append(base::StringPrintf("0x%X", p));
900 } 900 }
901 901
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
944 return result; 944 return result;
945 } 945 }
946 946
947 void ParamTraits<MSG>::Log(const param_type& p, std::string* l) { 947 void ParamTraits<MSG>::Log(const param_type& p, std::string* l) {
948 l->append("<MSG>"); 948 l->append("<MSG>");
949 } 949 }
950 950
951 #endif // OS_WIN 951 #endif // OS_WIN
952 952
953 } // namespace IPC 953 } // 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