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

Side by Side Diff: chrome/common/ipc_message_utils.h

Issue 27157: Initial checkin of the out of process worker implementation.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 9 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 | Annotate | Revision Log
« no previous file with comments | « chrome/common/common.vcproj ('k') | chrome/common/render_messages_internal.h » ('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) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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 #ifndef CHROME_COMMON_IPC_MESSAGE_UTILS_H_ 5 #ifndef CHROME_COMMON_IPC_MESSAGE_UTILS_H_
6 #define CHROME_COMMON_IPC_MESSAGE_UTILS_H_ 6 #define CHROME_COMMON_IPC_MESSAGE_UTILS_H_
7 7
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 #include <map> 10 #include <map>
11 11
12 #include "base/file_path.h" 12 #include "base/file_path.h"
13 #include "base/string_util.h" 13 #include "base/string_util.h"
14 #include "base/string16.h"
14 #include "base/tuple.h" 15 #include "base/tuple.h"
15 #if defined(OS_POSIX) 16 #if defined(OS_POSIX)
16 #include "chrome/common/file_descriptor_set_posix.h" 17 #include "chrome/common/file_descriptor_set_posix.h"
17 #endif 18 #endif
18 #include "chrome/common/ipc_maybe.h" 19 #include "chrome/common/ipc_maybe.h"
19 #include "chrome/common/ipc_sync_message.h" 20 #include "chrome/common/ipc_sync_message.h"
20 #include "chrome/common/thumbnail_score.h" 21 #include "chrome/common/thumbnail_score.h"
21 #include "chrome/common/transport_dib.h" 22 #include "chrome/common/transport_dib.h"
22 #include "webkit/glue/cache_manager.h" 23 #include "webkit/glue/cache_manager.h"
23 #include "webkit/glue/console_message_level.h" 24 #include "webkit/glue/console_message_level.h"
(...skipping 25 matching lines...) Expand all
49 ViewMsgStart, 50 ViewMsgStart,
50 ViewHostMsgStart, 51 ViewHostMsgStart,
51 PluginProcessMsgStart, 52 PluginProcessMsgStart,
52 PluginProcessHostMsgStart, 53 PluginProcessHostMsgStart,
53 PluginMsgStart, 54 PluginMsgStart,
54 PluginHostMsgStart, 55 PluginHostMsgStart,
55 NPObjectMsgStart, 56 NPObjectMsgStart,
56 TestMsgStart, 57 TestMsgStart,
57 DevToolsAgentMsgStart, 58 DevToolsAgentMsgStart,
58 DevToolsClientMsgStart, 59 DevToolsClientMsgStart,
60 WorkerProcessMsgStart,
61 WorkerProcessHostMsgStart,
62 WorkerMsgStart,
63 WorkerHostMsgStart,
59 // NOTE: When you add a new message class, also update 64 // NOTE: When you add a new message class, also update
60 // IPCStatusView::IPCStatusView to ensure logging works. 65 // IPCStatusView::IPCStatusView to ensure logging works.
61 // NOTE: this enum is used by IPC_MESSAGE_MACRO to generate a unique message 66 // NOTE: this enum is used by IPC_MESSAGE_MACRO to generate a unique message
62 // id. Only 4 bits are used for the message type, so if this enum needs more 67 // id. Only 4 bits are used for the message type, so if this enum needs more
63 // than 16 entries, that code needs to be updated. 68 // than 16 entries, that code needs to be updated.
64 LastMsgIndex 69 LastMsgIndex
65 }; 70 };
66 71
67 COMPILE_ASSERT(LastMsgIndex <= 16, need_to_update_IPC_MESSAGE_MACRO); 72 COMPILE_ASSERT(LastMsgIndex <= 16, need_to_update_IPC_MESSAGE_MACRO);
68 73
(...skipping 416 matching lines...) Expand 10 before | Expand all | Expand 10 after
485 if (!ReadParam(m, iter, &value)) 490 if (!ReadParam(m, iter, &value))
486 return false; 491 return false;
487 } 492 }
488 return true; 493 return true;
489 } 494 }
490 static void Log(const param_type& p, std::wstring* l) { 495 static void Log(const param_type& p, std::wstring* l) {
491 l->append(L"<std::map>"); 496 l->append(L"<std::map>");
492 } 497 }
493 }; 498 };
494 499
500
495 template <> 501 template <>
496 struct ParamTraits<std::wstring> { 502 struct ParamTraits<std::wstring> {
497 typedef std::wstring param_type; 503 typedef std::wstring param_type;
498 static void Write(Message* m, const param_type& p) { 504 static void Write(Message* m, const param_type& p) {
499 m->WriteWString(p); 505 m->WriteWString(p);
500 } 506 }
501 static bool Read(const Message* m, void** iter, param_type* r) { 507 static bool Read(const Message* m, void** iter, param_type* r) {
502 return m->ReadWString(iter, r); 508 return m->ReadWString(iter, r);
503 } 509 }
504 static void Log(const param_type& p, std::wstring* l) { 510 static void Log(const param_type& p, std::wstring* l) {
505 l->append(p); 511 l->append(p);
506 } 512 }
507 }; 513 };
508 514
515
516 // If WCHAR_T_IS_UTF16 is defined, then string16 is a std::wstring so we don't
517 // need this trait.
518 #if !defined(WCHAR_T_IS_UTF16)
519
520 template <>
521 struct ParamTraits<string16> {
522 typedef string16 param_type;
523 static void Write(Message* m, const param_type& p) {
524 m->WriteData(reinterpret_cast<const char*>(p.data()),
525 static_cast<int>(p.size() * sizeof(char16)));
526 }
527 static bool Read(const Message* m, void** iter, param_type* r) {
528 const char *data;
529 int data_size = 0;
530 if (!m->ReadData(iter, &data, &data_size))
531 return false;
532 r->assign(reinterpret_cast<const char16*>(data),
533 data_size / sizeof(char16));
534 return true;
535 }
536 static void Log(const param_type& p, std::wstring* l) {
537 l->append(UTF16ToWide(p));
538 }
539 };
540
541 #endif
542
509 template <> 543 template <>
510 struct ParamTraits<GURL> { 544 struct ParamTraits<GURL> {
511 typedef GURL param_type; 545 typedef GURL param_type;
512 static void Write(Message* m, const param_type& p); 546 static void Write(Message* m, const param_type& p);
513 static bool Read(const Message* m, void** iter, param_type* p); 547 static bool Read(const Message* m, void** iter, param_type* p);
514 static void Log(const param_type& p, std::wstring* l); 548 static void Log(const param_type& p, std::wstring* l);
515 }; 549 };
516 550
517 // and, a few more useful types... 551 // and, a few more useful types...
518 #if defined(OS_WIN) 552 #if defined(OS_WIN)
(...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after
886 ReadParam(m, iter, &r->dispatch) && 920 ReadParam(m, iter, &r->dispatch) &&
887 ReadParam(m, iter, &r->params); 921 ReadParam(m, iter, &r->params);
888 r->type = static_cast<uint16>(type); 922 r->type = static_cast<uint16>(type);
889 return result; 923 return result;
890 } 924 }
891 static void Log(const param_type& p, std::wstring* l) { 925 static void Log(const param_type& p, std::wstring* l) {
892 // Doesn't make sense to implement this! 926 // Doesn't make sense to implement this!
893 } 927 }
894 }; 928 };
895 929
930
931 template <>
932 struct ParamTraits<webkit_glue::WebApplicationInfo> {
933 typedef webkit_glue::WebApplicationInfo param_type;
934 static void Write(Message* m, const param_type& p);
935 static bool Read(const Message* m, void** iter, param_type* r);
936 static void Log(const param_type& p, std::wstring* l);
937 };
938
939
940 #if defined(OS_WIN)
941 template<>
942 struct ParamTraits<TransportDIB::Id> {
943 typedef TransportDIB::Id param_type;
944 static void Write(Message* m, const param_type& p) {
945 WriteParam(m, p.handle);
946 WriteParam(m, p.sequence_num);
947 }
948 static bool Read(const Message* m, void** iter, param_type* r) {
949 return (ReadParam(m, iter, &r->handle) &&
950 ReadParam(m, iter, &r->sequence_num));
951 }
952 static void Log(const param_type& p, std::wstring* l) {
953 l->append(L"TransportDIB(");
954 LogParam(p.handle, l);
955 l->append(L", ");
956 LogParam(p.sequence_num, l);
957 l->append(L")");
958 }
959 };
960 #endif
961
962 template<typename A>
963 struct ParamTraits<Maybe<A> > {
964 typedef struct Maybe<A> param_type;
965 static void Write(Message* m, const param_type& p) {
966 WriteParam(m, p.valid);
967 if (p.valid)
968 WriteParam(m, p.value);
969 }
970 static bool Read(const Message* m, void** iter, param_type* r) {
971 if (!ReadParam(m, iter, &r->valid))
972 return false;
973
974 if (r->valid)
975 return ReadParam(m, iter, &r->value);
976 return true;
977 }
978 static void Log(const param_type& p, std::wstring* l) {
979 if (p.valid) {
980 l->append(L"Just ");
981 ParamTraits<A>::Log(p.value, l);
982 } else {
983 l->append(L"Nothing");
984 }
985
986 }
987 };
988
989
896 template <> 990 template <>
897 struct ParamTraits<Message> { 991 struct ParamTraits<Message> {
898 static void Write(Message* m, const Message& p) { 992 static void Write(Message* m, const Message& p) {
899 m->WriteInt(p.size()); 993 m->WriteInt(p.size());
900 m->WriteData(reinterpret_cast<const char*>(p.data()), p.size()); 994 m->WriteData(reinterpret_cast<const char*>(p.data()), p.size());
901 } 995 }
902 static bool Read(const Message* m, void** iter, Message* r) { 996 static bool Read(const Message* m, void** iter, Message* r) {
903 int size; 997 int size;
904 if (!m->ReadInt(iter, &size)) 998 if (!m->ReadInt(iter, &size))
905 return false; 999 return false;
906 const char* data; 1000 const char* data;
907 if (!m->ReadData(iter, &data, &size)) 1001 if (!m->ReadData(iter, &data, &size))
908 return false; 1002 return false;
909 *r = Message(data, size); 1003 *r = Message(data, size);
910 return true; 1004 return true;
911 } 1005 }
912 static void Log(const Message& p, std::wstring* l) { 1006 static void Log(const Message& p, std::wstring* l) {
913 l->append(L"<IPC::Message>"); 1007 l->append(L"<IPC::Message>");
914 } 1008 }
915 }; 1009 };
916 1010
1011
917 template <> 1012 template <>
918 struct ParamTraits<Tuple0> { 1013 struct ParamTraits<Tuple0> {
919 typedef Tuple0 param_type; 1014 typedef Tuple0 param_type;
920 static void Write(Message* m, const param_type& p) { 1015 static void Write(Message* m, const param_type& p) {
921 } 1016 }
922 static bool Read(const Message* m, void** iter, param_type* r) { 1017 static bool Read(const Message* m, void** iter, param_type* r) {
923 return true; 1018 return true;
924 } 1019 }
925 static void Log(const param_type& p, std::wstring* l) { 1020 static void Log(const param_type& p, std::wstring* l) {
926 } 1021 }
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
1063 LogParam(p.c, l); 1158 LogParam(p.c, l);
1064 l->append(L", "); 1159 l->append(L", ");
1065 LogParam(p.d, l); 1160 LogParam(p.d, l);
1066 l->append(L", "); 1161 l->append(L", ");
1067 LogParam(p.e, l); 1162 LogParam(p.e, l);
1068 l->append(L", "); 1163 l->append(L", ");
1069 LogParam(p.f, l); 1164 LogParam(p.f, l);
1070 } 1165 }
1071 }; 1166 };
1072 1167
1073 #if defined(OS_WIN)
1074 template<>
1075 struct ParamTraits<TransportDIB::Id> {
1076 typedef TransportDIB::Id param_type;
1077 static void Write(Message* m, const param_type& p) {
1078 WriteParam(m, p.handle);
1079 WriteParam(m, p.sequence_num);
1080 }
1081 static bool Read(const Message* m, void** iter, param_type* r) {
1082 return (ReadParam(m, iter, &r->handle) &&
1083 ReadParam(m, iter, &r->sequence_num));
1084 }
1085 static void Log(const param_type& p, std::wstring* l) {
1086 l->append(L"TransportDIB(");
1087 LogParam(p.handle, l);
1088 l->append(L", ");
1089 LogParam(p.sequence_num, l);
1090 l->append(L")");
1091 }
1092 };
1093 #endif
1094
1095 template<typename A>
1096 struct ParamTraits<Maybe<A> > {
1097 typedef struct Maybe<A> param_type;
1098 static void Write(Message* m, const param_type& p) {
1099 WriteParam(m, p.valid);
1100 if (p.valid)
1101 WriteParam(m, p.value);
1102 }
1103 static bool Read(const Message* m, void** iter, param_type* r) {
1104 if (!ReadParam(m, iter, &r->valid))
1105 return false;
1106
1107 if (r->valid)
1108 return ReadParam(m, iter, &r->value);
1109 return true;
1110 }
1111 static void Log(const param_type& p, std::wstring* l) {
1112 if (p.valid) {
1113 l->append(L"Just ");
1114 ParamTraits<A>::Log(p.value, l);
1115 } else {
1116 l->append(L"Nothing");
1117 }
1118
1119 }
1120 };
1121
1122 template <>
1123 struct ParamTraits<webkit_glue::WebApplicationInfo> {
1124 typedef webkit_glue::WebApplicationInfo param_type;
1125 static void Write(Message* m, const param_type& p);
1126 static bool Read(const Message* m, void** iter, param_type* r);
1127 static void Log(const param_type& p, std::wstring* l);
1128 };
1129 1168
1130 1169
1131 //----------------------------------------------------------------------------- 1170 //-----------------------------------------------------------------------------
1132 // Generic message subclasses 1171 // Generic message subclasses
1133 1172
1134 // Used for asynchronous messages. 1173 // Used for asynchronous messages.
1135 template <class ParamType> 1174 template <class ParamType>
1136 class MessageWithTuple : public Message { 1175 class MessageWithTuple : public Message {
1137 public: 1176 public:
1138 typedef ParamType Param; 1177 typedef ParamType Param;
(...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after
1440 l->append(L"<FindInPageRequest>"); 1479 l->append(L"<FindInPageRequest>");
1441 } 1480 }
1442 }; 1481 };
1443 1482
1444 //----------------------------------------------------------------------------- 1483 //-----------------------------------------------------------------------------
1445 1484
1446 } // namespace IPC 1485 } // namespace IPC
1447 1486
1448 #endif // CHROME_COMMON_IPC_MESSAGE_UTILS_H_ 1487 #endif // CHROME_COMMON_IPC_MESSAGE_UTILS_H_
1449 1488
OLDNEW
« no previous file with comments | « chrome/common/common.vcproj ('k') | chrome/common/render_messages_internal.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698