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

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

Issue 20015: Make it easier to create new IPC channel types (i.e. renderer/plugin). Inste... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 10 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/ipc_message_unittest.cc ('k') | chrome/common/ipc_message_utils.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) 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>
(...skipping 16 matching lines...) Expand all
27 namespace gfx { 27 namespace gfx {
28 class Point; 28 class Point;
29 class Rect; 29 class Rect;
30 class Size; 30 class Size;
31 } // namespace gfx 31 } // namespace gfx
32 32
33 namespace webkit_glue { 33 namespace webkit_glue {
34 struct WebApplicationInfo; 34 struct WebApplicationInfo;
35 } // namespace webkit_glue 35 } // namespace webkit_glue
36 36
37 namespace IPC { 37 // Used by IPC_BEGIN_MESSAGES so that each message class starts from a unique
38 // base. Messages have unique IDs across channels in order for the IPC logging
39 // code to figure out the message class from its ID.
40 enum IPCMessageStart {
41 // By using a start value of 0 for automation messages, we keep backward
42 // compatibility with old builds.
43 AutomationMsgStart = 0,
44 ViewMsgStart,
45 ViewHostMsgStart,
46 PluginProcessMsgStart,
47 PluginProcessHostMsgStart,
48 PluginMsgStart,
49 PluginHostMsgStart,
50 NPObjectMsgStart,
51 TestMsgStart,
52 // NOTE: When you add a new message class, also update
53 // IPCStatusView::IPCStatusView to ensure logging works.
54 // NOTE: this enum is used by IPC_MESSAGE_MACRO to generate a unique message
55 // id. Only 4 bits are used for the message type, so if this enum needs more
56 // than 16 entries, that code needs to be updated.
57 LastMsgIndex
58 };
38 59
39 // Used by the message macros to register a logging function based on the 60 COMPILE_ASSERT(LastMsgIndex <= 16, need_to_update_IPC_MESSAGE_MACRO);
40 // message class.
41 typedef void (LogFunction)(uint16 type,
42 std::wstring* name,
43 const IPC::Message* msg,
44 std::wstring* params);
45 void RegisterMessageLogger(int msg_start, LogFunction* func);
46
47
48 //-----------------------------------------------------------------------------
49 // An iterator class for reading the fields contained within a Message.
50
51 class MessageIterator {
52 public:
53 explicit MessageIterator(const Message& m) : msg_(m), iter_(NULL) {
54 }
55 int NextInt() const {
56 int val;
57 if (!msg_.ReadInt(&iter_, &val))
58 NOTREACHED();
59 return val;
60 }
61 intptr_t NextIntPtr() const {
62 intptr_t val;
63 if (!msg_.ReadIntPtr(&iter_, &val))
64 NOTREACHED();
65 return val;
66 }
67 const std::string NextString() const {
68 std::string val;
69 if (!msg_.ReadString(&iter_, &val))
70 NOTREACHED();
71 return val;
72 }
73 const std::wstring NextWString() const {
74 std::wstring val;
75 if (!msg_.ReadWString(&iter_, &val))
76 NOTREACHED();
77 return val;
78 }
79 const void NextData(const char** data, int* length) const {
80 if (!msg_.ReadData(&iter_, data, length)) {
81 NOTREACHED();
82 }
83 }
84 private:
85 const Message& msg_;
86 mutable void* iter_;
87 };
88 61
89 //----------------------------------------------------------------------------- 62 //-----------------------------------------------------------------------------
90 // ParamTraits specializations, etc. 63 // ParamTraits specializations, etc.
91 64
92 template <class P> struct ParamTraits {}; 65 template <class P> struct ParamTraits {};
93 66
94 template <class P> 67 template <class P>
95 static inline void WriteParam(Message* m, const P& p) { 68 static inline void WriteParam(IPC::Message* m, const P& p) {
96 ParamTraits<P>::Write(m, p); 69 ParamTraits<P>::Write(m, p);
97 } 70 }
98 71
99 template <class P> 72 template <class P>
100 static inline bool ReadParam(const Message* m, void** iter, P* p) { 73 static inline bool ReadParam(const IPC::Message* m, void** iter, P* p) {
101 return ParamTraits<P>::Read(m, iter, p); 74 return ParamTraits<P>::Read(m, iter, p);
102 } 75 }
103 76
104 template <class P> 77 template <class P>
105 static inline void LogParam(const P& p, std::wstring* l) { 78 static inline void LogParam(const P& p, std::wstring* l) {
106 ParamTraits<P>::Log(p, l); 79 ParamTraits<P>::Log(p, l);
107 } 80 }
108 81
109 template <> 82 template <>
110 struct ParamTraits<bool> { 83 struct ParamTraits<bool> {
111 typedef bool param_type; 84 typedef bool param_type;
112 static void Write(Message* m, const param_type& p) { 85 static void Write(IPC::Message* m, const param_type& p) {
113 m->WriteBool(p); 86 m->WriteBool(p);
114 } 87 }
115 static bool Read(const Message* m, void** iter, param_type* r) { 88 static bool Read(const IPC::Message* m, void** iter, param_type* r) {
116 return m->ReadBool(iter, r); 89 return m->ReadBool(iter, r);
117 } 90 }
118 static void Log(const param_type& p, std::wstring* l) { 91 static void Log(const param_type& p, std::wstring* l) {
119 l->append(p ? L"true" : L"false"); 92 l->append(p ? L"true" : L"false");
120 } 93 }
121 }; 94 };
122 95
123 template <> 96 template <>
124 struct ParamTraits<int> { 97 struct ParamTraits<int> {
125 typedef int param_type; 98 typedef int param_type;
126 static void Write(Message* m, const param_type& p) { 99 static void Write(IPC::Message* m, const param_type& p) {
127 m->WriteInt(p); 100 m->WriteInt(p);
128 } 101 }
129 static bool Read(const Message* m, void** iter, param_type* r) { 102 static bool Read(const IPC::Message* m, void** iter, param_type* r) {
130 return m->ReadInt(iter, r); 103 return m->ReadInt(iter, r);
131 } 104 }
132 static void Log(const param_type& p, std::wstring* l) { 105 static void Log(const param_type& p, std::wstring* l) {
133 l->append(StringPrintf(L"%d", p)); 106 l->append(StringPrintf(L"%d", p));
134 } 107 }
135 }; 108 };
136 109
137 template <> 110 template <>
138 struct ParamTraits<long> { 111 struct ParamTraits<long> {
139 typedef long param_type; 112 typedef long param_type;
140 static void Write(Message* m, const param_type& p) { 113 static void Write(IPC::Message* m, const param_type& p) {
141 m->WriteLong(p); 114 m->WriteLong(p);
142 } 115 }
143 static bool Read(const Message* m, void** iter, param_type* r) { 116 static bool Read(const IPC::Message* m, void** iter, param_type* r) {
144 return m->ReadLong(iter, r); 117 return m->ReadLong(iter, r);
145 } 118 }
146 static void Log(const param_type& p, std::wstring* l) { 119 static void Log(const param_type& p, std::wstring* l) {
147 l->append(StringPrintf(L"%l", p)); 120 l->append(StringPrintf(L"%l", p));
148 } 121 }
149 }; 122 };
150 123
151 template <> 124 template <>
152 struct ParamTraits<size_t> { 125 struct ParamTraits<size_t> {
153 typedef size_t param_type; 126 typedef size_t param_type;
154 static void Write(Message* m, const param_type& p) { 127 static void Write(IPC::Message* m, const param_type& p) {
155 m->WriteSize(p); 128 m->WriteSize(p);
156 } 129 }
157 static bool Read(const Message* m, void** iter, param_type* r) { 130 static bool Read(const IPC::Message* m, void** iter, param_type* r) {
158 return m->ReadSize(iter, r); 131 return m->ReadSize(iter, r);
159 } 132 }
160 static void Log(const param_type& p, std::wstring* l) { 133 static void Log(const param_type& p, std::wstring* l) {
161 l->append(StringPrintf(L"%u", p)); 134 l->append(StringPrintf(L"%u", p));
162 } 135 }
163 }; 136 };
164 137
165 #if defined(OS_MACOSX) 138 #if defined(OS_MACOSX)
166 // On Linux size_t & uint32 can be the same type. 139 // On Linux size_t & uint32 can be the same type.
167 // TODO(playmobil): Fix compilation if this is not the case. 140 // TODO(playmobil): Fix compilation if this is not the case.
168 template <> 141 template <>
169 struct ParamTraits<uint32> { 142 struct ParamTraits<uint32> {
170 typedef uint32 param_type; 143 typedef uint32 param_type;
171 static void Write(Message* m, const param_type& p) { 144 static void Write(IPC::Message* m, const param_type& p) {
172 m->WriteUInt32(p); 145 m->WriteUInt32(p);
173 } 146 }
174 static bool Read(const Message* m, void** iter, param_type* r) { 147 static bool Read(const IPC::Message* m, void** iter, param_type* r) {
175 return m->ReadUInt32(iter, r); 148 return m->ReadUInt32(iter, r);
176 } 149 }
177 static void Log(const param_type& p, std::wstring* l) { 150 static void Log(const param_type& p, std::wstring* l) {
178 l->append(StringPrintf(L"%u", p)); 151 l->append(StringPrintf(L"%u", p));
179 } 152 }
180 }; 153 };
181 #endif // defined(OS_MACOSX) 154 #endif // defined(OS_MACOSX)
182 155
183 template <> 156 template <>
184 struct ParamTraits<int64> { 157 struct ParamTraits<int64> {
185 typedef int64 param_type; 158 typedef int64 param_type;
186 static void Write(Message* m, const param_type& p) { 159 static void Write(IPC::Message* m, const param_type& p) {
187 m->WriteInt64(p); 160 m->WriteInt64(p);
188 } 161 }
189 static bool Read(const Message* m, void** iter, param_type* r) { 162 static bool Read(const IPC::Message* m, void** iter, param_type* r) {
190 return m->ReadInt64(iter, r); 163 return m->ReadInt64(iter, r);
191 } 164 }
192 static void Log(const param_type& p, std::wstring* l) { 165 static void Log(const param_type& p, std::wstring* l) {
193 l->append(StringPrintf(L"%I64d", p)); 166 l->append(StringPrintf(L"%I64d", p));
194 } 167 }
195 }; 168 };
196 169
197 template <> 170 template <>
198 struct ParamTraits<uint64> { 171 struct ParamTraits<uint64> {
199 typedef uint64 param_type; 172 typedef uint64 param_type;
200 static void Write(Message* m, const param_type& p) { 173 static void Write(IPC::Message* m, const param_type& p) {
201 m->WriteInt64(static_cast<int64>(p)); 174 m->WriteInt64(static_cast<int64>(p));
202 } 175 }
203 static bool Read(const Message* m, void** iter, param_type* r) { 176 static bool Read(const IPC::Message* m, void** iter, param_type* r) {
204 return m->ReadInt64(iter, reinterpret_cast<int64*>(r)); 177 return m->ReadInt64(iter, reinterpret_cast<int64*>(r));
205 } 178 }
206 static void Log(const param_type& p, std::wstring* l) { 179 static void Log(const param_type& p, std::wstring* l) {
207 l->append(StringPrintf(L"%I64u", p)); 180 l->append(StringPrintf(L"%I64u", p));
208 } 181 }
209 }; 182 };
210 183
211 template <> 184 template <>
212 struct ParamTraits<double> { 185 struct ParamTraits<double> {
213 typedef double param_type; 186 typedef double param_type;
214 static void Write(Message* m, const param_type& p) { 187 static void Write(IPC::Message* m, const param_type& p) {
215 m->WriteData(reinterpret_cast<const char*>(&p), sizeof(param_type)); 188 m->WriteData(reinterpret_cast<const char*>(&p), sizeof(param_type));
216 } 189 }
217 static bool Read(const Message* m, void** iter, param_type* r) { 190 static bool Read(const IPC::Message* m, void** iter, param_type* r) {
218 const char *data; 191 const char *data;
219 int data_size = 0; 192 int data_size = 0;
220 bool result = m->ReadData(iter, &data, &data_size); 193 bool result = m->ReadData(iter, &data, &data_size);
221 if (result && data_size == sizeof(param_type)) { 194 if (result && data_size == sizeof(param_type)) {
222 memcpy(r, data, sizeof(param_type)); 195 memcpy(r, data, sizeof(param_type));
223 } else { 196 } else {
224 result = false; 197 result = false;
225 NOTREACHED(); 198 NOTREACHED();
226 } 199 }
227 200
228 return result; 201 return result;
229 } 202 }
230 static void Log(const param_type& p, std::wstring* l) { 203 static void Log(const param_type& p, std::wstring* l) {
231 l->append(StringPrintf(L"e", p)); 204 l->append(StringPrintf(L"e", p));
232 } 205 }
233 }; 206 };
234 207
235 template <> 208 template <>
236 struct ParamTraits<wchar_t> { 209 struct ParamTraits<wchar_t> {
237 typedef wchar_t param_type; 210 typedef wchar_t param_type;
238 static void Write(Message* m, const param_type& p) { 211 static void Write(IPC::Message* m, const param_type& p) {
239 m->WriteData(reinterpret_cast<const char*>(&p), sizeof(param_type)); 212 m->WriteData(reinterpret_cast<const char*>(&p), sizeof(param_type));
240 } 213 }
241 static bool Read(const Message* m, void** iter, param_type* r) { 214 static bool Read(const IPC::Message* m, void** iter, param_type* r) {
242 const char *data; 215 const char *data;
243 int data_size = 0; 216 int data_size = 0;
244 bool result = m->ReadData(iter, &data, &data_size); 217 bool result = m->ReadData(iter, &data, &data_size);
245 if (result && data_size == sizeof(param_type)) { 218 if (result && data_size == sizeof(param_type)) {
246 memcpy(r, data, sizeof(param_type)); 219 memcpy(r, data, sizeof(param_type));
247 } else { 220 } else {
248 result = false; 221 result = false;
249 NOTREACHED(); 222 NOTREACHED();
250 } 223 }
251 224
252 return result; 225 return result;
253 } 226 }
254 static void Log(const param_type& p, std::wstring* l) { 227 static void Log(const param_type& p, std::wstring* l) {
255 l->append(StringPrintf(L"%lc", p)); 228 l->append(StringPrintf(L"%lc", p));
256 } 229 }
257 }; 230 };
258 231
259 template <> 232 template <>
260 struct ParamTraits<base::Time> { 233 struct ParamTraits<base::Time> {
261 typedef base::Time param_type; 234 typedef base::Time param_type;
262 static void Write(Message* m, const param_type& p) { 235 static void Write(IPC::Message* m, const param_type& p) {
263 ParamTraits<int64>::Write(m, p.ToInternalValue()); 236 ParamTraits<int64>::Write(m, p.ToInternalValue());
264 } 237 }
265 static bool Read(const Message* m, void** iter, param_type* r) { 238 static bool Read(const IPC::Message* m, void** iter, param_type* r) {
266 int64 value; 239 int64 value;
267 if (!ParamTraits<int64>::Read(m, iter, &value)) 240 if (!ParamTraits<int64>::Read(m, iter, &value))
268 return false; 241 return false;
269 *r = base::Time::FromInternalValue(value); 242 *r = base::Time::FromInternalValue(value);
270 return true; 243 return true;
271 } 244 }
272 static void Log(const param_type& p, std::wstring* l) { 245 static void Log(const param_type& p, std::wstring* l) {
273 ParamTraits<int64>::Log(p.ToInternalValue(), l); 246 ParamTraits<int64>::Log(p.ToInternalValue(), l);
274 } 247 }
275 }; 248 };
276 249
277 #if defined(OS_WIN) 250 #if defined(OS_WIN)
278 template <> 251 template <>
279 struct ParamTraits<LOGFONT> { 252 struct ParamTraits<LOGFONT> {
280 typedef LOGFONT param_type; 253 typedef LOGFONT param_type;
281 static void Write(Message* m, const param_type& p) { 254 static void Write(IPC::Message* m, const param_type& p) {
282 m->WriteData(reinterpret_cast<const char*>(&p), sizeof(LOGFONT)); 255 m->WriteData(reinterpret_cast<const char*>(&p), sizeof(LOGFONT));
283 } 256 }
284 static bool Read(const Message* m, void** iter, param_type* r) { 257 static bool Read(const IPC::Message* m, void** iter, param_type* r) {
285 const char *data; 258 const char *data;
286 int data_size = 0; 259 int data_size = 0;
287 bool result = m->ReadData(iter, &data, &data_size); 260 bool result = m->ReadData(iter, &data, &data_size);
288 if (result && data_size == sizeof(LOGFONT)) { 261 if (result && data_size == sizeof(LOGFONT)) {
289 memcpy(r, data, sizeof(LOGFONT)); 262 memcpy(r, data, sizeof(LOGFONT));
290 } else { 263 } else {
291 result = false; 264 result = false;
292 NOTREACHED(); 265 NOTREACHED();
293 } 266 }
294 267
295 return result; 268 return result;
296 } 269 }
297 static void Log(const param_type& p, std::wstring* l) { 270 static void Log(const param_type& p, std::wstring* l) {
298 l->append(StringPrintf(L"<LOGFONT>")); 271 l->append(StringPrintf(L"<LOGFONT>"));
299 } 272 }
300 }; 273 };
301 274
302 template <> 275 template <>
303 struct ParamTraits<MSG> { 276 struct ParamTraits<MSG> {
304 typedef MSG param_type; 277 typedef MSG param_type;
305 static void Write(Message* m, const param_type& p) { 278 static void Write(IPC::Message* m, const param_type& p) {
306 m->WriteData(reinterpret_cast<const char*>(&p), sizeof(MSG)); 279 m->WriteData(reinterpret_cast<const char*>(&p), sizeof(MSG));
307 } 280 }
308 static bool Read(const Message* m, void** iter, param_type* r) { 281 static bool Read(const IPC::Message* m, void** iter, param_type* r) {
309 const char *data; 282 const char *data;
310 int data_size = 0; 283 int data_size = 0;
311 bool result = m->ReadData(iter, &data, &data_size); 284 bool result = m->ReadData(iter, &data, &data_size);
312 if (result && data_size == sizeof(MSG)) { 285 if (result && data_size == sizeof(MSG)) {
313 memcpy(r, data, sizeof(MSG)); 286 memcpy(r, data, sizeof(MSG));
314 } else { 287 } else {
315 result = false; 288 result = false;
316 NOTREACHED(); 289 NOTREACHED();
317 } 290 }
318 291
319 return result; 292 return result;
320 } 293 }
321 }; 294 };
322 #endif // defined(OS_WIN) 295 #endif // defined(OS_WIN)
323 296
324 template <> 297 template <>
325 struct ParamTraits<SkBitmap> { 298 struct ParamTraits<SkBitmap> {
326 typedef SkBitmap param_type; 299 typedef SkBitmap param_type;
327 static void Write(Message* m, const param_type& p); 300 static void Write(IPC::Message* m, const param_type& p);
328 301
329 // Note: This function expects parameter |r| to be of type &SkBitmap since 302 // Note: This function expects parameter |r| to be of type &SkBitmap since
330 // r->SetConfig() and r->SetPixels() are called. 303 // r->SetConfig() and r->SetPixels() are called.
331 static bool Read(const Message* m, void** iter, param_type* r); 304 static bool Read(const IPC::Message* m, void** iter, param_type* r);
332 305
333 static void Log(const param_type& p, std::wstring* l); 306 static void Log(const param_type& p, std::wstring* l);
334 }; 307 };
335 308
336 template <> 309 template <>
337 struct ParamTraits<std::string> { 310 struct ParamTraits<std::string> {
338 typedef std::string param_type; 311 typedef std::string param_type;
339 static void Write(Message* m, const param_type& p) { 312 static void Write(IPC::Message* m, const param_type& p) {
340 m->WriteString(p); 313 m->WriteString(p);
341 } 314 }
342 static bool Read(const Message* m, void** iter, param_type* r) { 315 static bool Read(const IPC::Message* m, void** iter, param_type* r) {
343 return m->ReadString(iter, r); 316 return m->ReadString(iter, r);
344 } 317 }
345 static void Log(const param_type& p, std::wstring* l) { 318 static void Log(const param_type& p, std::wstring* l) {
346 l->append(UTF8ToWide(p)); 319 l->append(UTF8ToWide(p));
347 } 320 }
348 }; 321 };
349 322
350 template <> 323 template <>
351 struct ParamTraits<std::vector<unsigned char> > { 324 struct ParamTraits<std::vector<unsigned char> > {
352 typedef std::vector<unsigned char> param_type; 325 typedef std::vector<unsigned char> param_type;
353 static void Write(Message* m, const param_type& p) { 326 static void Write(IPC::Message* m, const param_type& p) {
354 if (p.size() == 0) { 327 if (p.size() == 0) {
355 m->WriteData(NULL, 0); 328 m->WriteData(NULL, 0);
356 } else { 329 } else {
357 m->WriteData(reinterpret_cast<const char*>(&p.front()), 330 m->WriteData(reinterpret_cast<const char*>(&p.front()),
358 static_cast<int>(p.size())); 331 static_cast<int>(p.size()));
359 } 332 }
360 } 333 }
361 static bool Read(const Message* m, void** iter, param_type* r) { 334 static bool Read(const IPC::Message* m, void** iter, param_type* r) {
362 const char *data; 335 const char *data;
363 int data_size = 0; 336 int data_size = 0;
364 if (!m->ReadData(iter, &data, &data_size) || data_size < 0) 337 if (!m->ReadData(iter, &data, &data_size) || data_size < 0)
365 return false; 338 return false;
366 r->resize(data_size); 339 r->resize(data_size);
367 if (data_size) 340 if (data_size)
368 memcpy(&r->front(), data, data_size); 341 memcpy(&r->front(), data, data_size);
369 return true; 342 return true;
370 } 343 }
371 static void Log(const param_type& p, std::wstring* l) { 344 static void Log(const param_type& p, std::wstring* l) {
372 for (size_t i = 0; i < p.size(); ++i) 345 for (size_t i = 0; i < p.size(); ++i)
373 l->push_back(p[i]); 346 l->push_back(p[i]);
374 } 347 }
375 }; 348 };
376 349
377 template <> 350 template <>
378 struct ParamTraits<std::vector<char> > { 351 struct ParamTraits<std::vector<char> > {
379 typedef std::vector<char> param_type; 352 typedef std::vector<char> param_type;
380 static void Write(Message* m, const param_type& p) { 353 static void Write(IPC::Message* m, const param_type& p) {
381 if (p.size() == 0) { 354 if (p.size() == 0) {
382 m->WriteData(NULL, 0); 355 m->WriteData(NULL, 0);
383 } else { 356 } else {
384 m->WriteData(&p.front(), static_cast<int>(p.size())); 357 m->WriteData(&p.front(), static_cast<int>(p.size()));
385 } 358 }
386 } 359 }
387 static bool Read(const Message* m, void** iter, param_type* r) { 360 static bool Read(const IPC::Message* m, void** iter, param_type* r) {
388 const char *data; 361 const char *data;
389 int data_size = 0; 362 int data_size = 0;
390 if (!m->ReadData(iter, &data, &data_size) || data_size < 0) 363 if (!m->ReadData(iter, &data, &data_size) || data_size < 0)
391 return false; 364 return false;
392 r->resize(data_size); 365 r->resize(data_size);
393 if (data_size) 366 if (data_size)
394 memcpy(&r->front(), data, data_size); 367 memcpy(&r->front(), data, data_size);
395 return true; 368 return true;
396 } 369 }
397 static void Log(const param_type& p, std::wstring* l) { 370 static void Log(const param_type& p, std::wstring* l) {
398 for (size_t i = 0; i < p.size(); ++i) 371 for (size_t i = 0; i < p.size(); ++i)
399 l->push_back(p[i]); 372 l->push_back(p[i]);
400 } 373 }
401 }; 374 };
402 375
403 template <class P> 376 template <class P>
404 struct ParamTraits<std::vector<P> > { 377 struct ParamTraits<std::vector<P> > {
405 typedef std::vector<P> param_type; 378 typedef std::vector<P> param_type;
406 static void Write(Message* m, const param_type& p) { 379 static void Write(IPC::Message* m, const param_type& p) {
407 WriteParam(m, static_cast<int>(p.size())); 380 WriteParam(m, static_cast<int>(p.size()));
408 for (size_t i = 0; i < p.size(); i++) 381 for (size_t i = 0; i < p.size(); i++)
409 WriteParam(m, p[i]); 382 WriteParam(m, p[i]);
410 } 383 }
411 static bool Read(const Message* m, void** iter, param_type* r) { 384 static bool Read(const IPC::Message* m, void** iter, param_type* r) {
412 int size; 385 int size;
413 if (!m->ReadLength(iter, &size)) 386 if (!m->ReadLength(iter, &size))
414 return false; 387 return false;
415 // Resizing beforehand is not safe, see BUG 1006367 for details. 388 // Resizing beforehand is not safe, see BUG 1006367 for details.
416 if (m->IteratorHasRoomFor(*iter, size * sizeof(P))) { 389 if (m->IteratorHasRoomFor(*iter, size * sizeof(P))) {
417 r->resize(size); 390 r->resize(size);
418 for (int i = 0; i < size; i++) { 391 for (int i = 0; i < size; i++) {
419 if (!ReadParam(m, iter, &(*r)[i])) 392 if (!ReadParam(m, iter, &(*r)[i]))
420 return false; 393 return false;
421 } 394 }
(...skipping 13 matching lines...) Expand all
435 l->append(L" "); 408 l->append(L" ");
436 409
437 LogParam((p[i]), l); 410 LogParam((p[i]), l);
438 } 411 }
439 } 412 }
440 }; 413 };
441 414
442 template <class K, class V> 415 template <class K, class V>
443 struct ParamTraits<std::map<K, V> > { 416 struct ParamTraits<std::map<K, V> > {
444 typedef std::map<K, V> param_type; 417 typedef std::map<K, V> param_type;
445 static void Write(Message* m, const param_type& p) { 418 static void Write(IPC::Message* m, const param_type& p) {
446 WriteParam(m, static_cast<int>(p.size())); 419 WriteParam(m, static_cast<int>(p.size()));
447 typename param_type::const_iterator iter; 420 typename param_type::const_iterator iter;
448 for (iter = p.begin(); iter != p.end(); ++iter) { 421 for (iter = p.begin(); iter != p.end(); ++iter) {
449 WriteParam(m, iter->first); 422 WriteParam(m, iter->first);
450 WriteParam(m, iter->second); 423 WriteParam(m, iter->second);
451 } 424 }
452 } 425 }
453 static bool Read(const Message* m, void** iter, param_type* r) { 426 static bool Read(const IPC::Message* m, void** iter, param_type* r) {
454 int size; 427 int size;
455 if (!ReadParam(m, iter, &size) || size < 0) 428 if (!ReadParam(m, iter, &size) || size < 0)
456 return false; 429 return false;
457 for (int i = 0; i < size; ++i) { 430 for (int i = 0; i < size; ++i) {
458 K k; 431 K k;
459 if (!ReadParam(m, iter, &k)) 432 if (!ReadParam(m, iter, &k))
460 return false; 433 return false;
461 V& value = (*r)[k]; 434 V& value = (*r)[k];
462 if (!ReadParam(m, iter, &value)) 435 if (!ReadParam(m, iter, &value))
463 return false; 436 return false;
464 } 437 }
465 return true; 438 return true;
466 } 439 }
467 static void Log(const param_type& p, std::wstring* l) { 440 static void Log(const param_type& p, std::wstring* l) {
468 l->append(L"<std::map>"); 441 l->append(L"<std::map>");
469 } 442 }
470 }; 443 };
471 444
472 template <> 445 template <>
473 struct ParamTraits<std::wstring> { 446 struct ParamTraits<std::wstring> {
474 typedef std::wstring param_type; 447 typedef std::wstring param_type;
475 static void Write(Message* m, const param_type& p) { 448 static void Write(IPC::Message* m, const param_type& p) {
476 m->WriteWString(p); 449 m->WriteWString(p);
477 } 450 }
478 static bool Read(const Message* m, void** iter, param_type* r) { 451 static bool Read(const IPC::Message* m, void** iter, param_type* r) {
479 return m->ReadWString(iter, r); 452 return m->ReadWString(iter, r);
480 } 453 }
481 static void Log(const param_type& p, std::wstring* l) { 454 static void Log(const param_type& p, std::wstring* l) {
482 l->append(p); 455 l->append(p);
483 } 456 }
484 }; 457 };
485 458
486 template <> 459 template <>
487 struct ParamTraits<GURL> { 460 struct ParamTraits<GURL> {
488 typedef GURL param_type; 461 typedef GURL param_type;
489 static void Write(Message* m, const param_type& p); 462 static void Write(IPC::Message* m, const param_type& p);
490 static bool Read(const Message* m, void** iter, param_type* p); 463 static bool Read(const IPC::Message* m, void** iter, param_type* p);
491 static void Log(const param_type& p, std::wstring* l); 464 static void Log(const param_type& p, std::wstring* l);
492 }; 465 };
493 466
494 // and, a few more useful types... 467 // and, a few more useful types...
495 #if defined(OS_WIN) 468 #if defined(OS_WIN)
496 template <> 469 template <>
497 struct ParamTraits<HANDLE> { 470 struct ParamTraits<HANDLE> {
498 typedef HANDLE param_type; 471 typedef HANDLE param_type;
499 static void Write(Message* m, const param_type& p) { 472 static void Write(IPC::Message* m, const param_type& p) {
500 m->WriteIntPtr(reinterpret_cast<intptr_t>(p)); 473 m->WriteIntPtr(reinterpret_cast<intptr_t>(p));
501 } 474 }
502 static bool Read(const Message* m, void** iter, param_type* r) { 475 static bool Read(const IPC::Message* m, void** iter, param_type* r) {
503 DCHECK_EQ(sizeof(param_type), sizeof(intptr_t)); 476 DCHECK_EQ(sizeof(param_type), sizeof(intptr_t));
504 return m->ReadIntPtr(iter, reinterpret_cast<intptr_t*>(r)); 477 return m->ReadIntPtr(iter, reinterpret_cast<intptr_t*>(r));
505 } 478 }
506 static void Log(const param_type& p, std::wstring* l) { 479 static void Log(const param_type& p, std::wstring* l) {
507 l->append(StringPrintf(L"0x%X", p)); 480 l->append(StringPrintf(L"0x%X", p));
508 } 481 }
509 }; 482 };
510 483
511 template <> 484 template <>
512 struct ParamTraits<HCURSOR> { 485 struct ParamTraits<HCURSOR> {
513 typedef HCURSOR param_type; 486 typedef HCURSOR param_type;
514 static void Write(Message* m, const param_type& p) { 487 static void Write(IPC::Message* m, const param_type& p) {
515 m->WriteIntPtr(reinterpret_cast<intptr_t>(p)); 488 m->WriteIntPtr(reinterpret_cast<intptr_t>(p));
516 } 489 }
517 static bool Read(const Message* m, void** iter, param_type* r) { 490 static bool Read(const IPC::Message* m, void** iter, param_type* r) {
518 DCHECK_EQ(sizeof(param_type), sizeof(intptr_t)); 491 DCHECK_EQ(sizeof(param_type), sizeof(intptr_t));
519 return m->ReadIntPtr(iter, reinterpret_cast<intptr_t*>(r)); 492 return m->ReadIntPtr(iter, reinterpret_cast<intptr_t*>(r));
520 } 493 }
521 static void Log(const param_type& p, std::wstring* l) { 494 static void Log(const param_type& p, std::wstring* l) {
522 l->append(StringPrintf(L"0x%X", p)); 495 l->append(StringPrintf(L"0x%X", p));
523 } 496 }
524 }; 497 };
525 498
526 template <> 499 template <>
527 struct ParamTraits<HWND> { 500 struct ParamTraits<HWND> {
528 typedef HWND param_type; 501 typedef HWND param_type;
529 static void Write(Message* m, const param_type& p) { 502 static void Write(IPC::Message* m, const param_type& p) {
530 m->WriteIntPtr(reinterpret_cast<intptr_t>(p)); 503 m->WriteIntPtr(reinterpret_cast<intptr_t>(p));
531 } 504 }
532 static bool Read(const Message* m, void** iter, param_type* r) { 505 static bool Read(const IPC::Message* m, void** iter, param_type* r) {
533 DCHECK_EQ(sizeof(param_type), sizeof(intptr_t)); 506 DCHECK_EQ(sizeof(param_type), sizeof(intptr_t));
534 return m->ReadIntPtr(iter, reinterpret_cast<intptr_t*>(r)); 507 return m->ReadIntPtr(iter, reinterpret_cast<intptr_t*>(r));
535 } 508 }
536 static void Log(const param_type& p, std::wstring* l) { 509 static void Log(const param_type& p, std::wstring* l) {
537 l->append(StringPrintf(L"0x%X", p)); 510 l->append(StringPrintf(L"0x%X", p));
538 } 511 }
539 }; 512 };
540 513
541 template <> 514 template <>
542 struct ParamTraits<HRGN> { 515 struct ParamTraits<HRGN> {
543 typedef HRGN param_type; 516 typedef HRGN param_type;
544 static void Write(Message* m, const param_type& p) { 517 static void Write(IPC::Message* m, const param_type& p) {
545 int data_size = GetRegionData(p, 0, NULL); 518 int data_size = GetRegionData(p, 0, NULL);
546 if (data_size) { 519 if (data_size) {
547 char* bytes = new char[data_size]; 520 char* bytes = new char[data_size];
548 GetRegionData(p, data_size, reinterpret_cast<LPRGNDATA>(bytes)); 521 GetRegionData(p, data_size, reinterpret_cast<LPRGNDATA>(bytes));
549 m->WriteData(reinterpret_cast<const char*>(bytes), data_size); 522 m->WriteData(reinterpret_cast<const char*>(bytes), data_size);
550 delete [] bytes; 523 delete [] bytes;
551 } else { 524 } else {
552 m->WriteData(NULL, 0); 525 m->WriteData(NULL, 0);
553 } 526 }
554 } 527 }
555 static bool Read(const Message* m, void** iter, param_type* r) { 528 static bool Read(const IPC::Message* m, void** iter, param_type* r) {
556 bool res = FALSE; 529 bool res = FALSE;
557 const char *data; 530 const char *data;
558 int data_size = 0; 531 int data_size = 0;
559 res = m->ReadData(iter, &data, &data_size); 532 res = m->ReadData(iter, &data, &data_size);
560 if (data_size) { 533 if (data_size) {
561 *r = ExtCreateRegion(NULL, data_size, 534 *r = ExtCreateRegion(NULL, data_size,
562 reinterpret_cast<CONST RGNDATA*>(data)); 535 reinterpret_cast<CONST RGNDATA*>(data));
563 } else { 536 } else {
564 res = TRUE; 537 res = TRUE;
565 *r = CreateRectRgn(0, 0, 0, 0); 538 *r = CreateRectRgn(0, 0, 0, 0);
566 } 539 }
567 return res; 540 return res;
568 } 541 }
569 static void Log(const param_type& p, std::wstring* l) { 542 static void Log(const param_type& p, std::wstring* l) {
570 l->append(StringPrintf(L"0x%X", p)); 543 l->append(StringPrintf(L"0x%X", p));
571 } 544 }
572 }; 545 };
573 546
574 template <> 547 template <>
575 struct ParamTraits<HACCEL> { 548 struct ParamTraits<HACCEL> {
576 typedef HACCEL param_type; 549 typedef HACCEL param_type;
577 static void Write(Message* m, const param_type& p) { 550 static void Write(IPC::Message* m, const param_type& p) {
578 m->WriteIntPtr(reinterpret_cast<intptr_t>(p)); 551 m->WriteIntPtr(reinterpret_cast<intptr_t>(p));
579 } 552 }
580 static bool Read(const Message* m, void** iter, param_type* r) { 553 static bool Read(const IPC::Message* m, void** iter, param_type* r) {
581 DCHECK_EQ(sizeof(param_type), sizeof(intptr_t)); 554 DCHECK_EQ(sizeof(param_type), sizeof(intptr_t));
582 return m->ReadIntPtr(iter, reinterpret_cast<intptr_t*>(r)); 555 return m->ReadIntPtr(iter, reinterpret_cast<intptr_t*>(r));
583 } 556 }
584 }; 557 };
585 558
586 template <> 559 template <>
587 struct ParamTraits<POINT> { 560 struct ParamTraits<POINT> {
588 typedef POINT param_type; 561 typedef POINT param_type;
589 static void Write(Message* m, const param_type& p) { 562 static void Write(IPC::Message* m, const param_type& p) {
590 m->WriteInt(p.x); 563 m->WriteInt(p.x);
591 m->WriteInt(p.y); 564 m->WriteInt(p.y);
592 } 565 }
593 static bool Read(const Message* m, void** iter, param_type* r) { 566 static bool Read(const IPC::Message* m, void** iter, param_type* r) {
594 int x, y; 567 int x, y;
595 if (!m->ReadInt(iter, &x) || !m->ReadInt(iter, &y)) 568 if (!m->ReadInt(iter, &x) || !m->ReadInt(iter, &y))
596 return false; 569 return false;
597 r->x = x; 570 r->x = x;
598 r->y = y; 571 r->y = y;
599 return true; 572 return true;
600 } 573 }
601 static void Log(const param_type& p, std::wstring* l) { 574 static void Log(const param_type& p, std::wstring* l) {
602 l->append(StringPrintf(L"(%d, %d)", p.x, p.y)); 575 l->append(StringPrintf(L"(%d, %d)", p.x, p.y));
603 } 576 }
604 }; 577 };
605 #endif // defined(OS_WIN) 578 #endif // defined(OS_WIN)
606 579
607 template <> 580 template <>
608 struct ParamTraits<FilePath> { 581 struct ParamTraits<FilePath> {
609 typedef FilePath param_type; 582 typedef FilePath param_type;
610 static void Write(Message* m, const param_type& p) { 583 static void Write(IPC::Message* m, const param_type& p) {
611 ParamTraits<FilePath::StringType>::Write(m, p.value()); 584 ParamTraits<FilePath::StringType>::Write(m, p.value());
612 } 585 }
613 static bool Read(const Message* m, void** iter, param_type* r) { 586 static bool Read(const IPC::Message* m, void** iter, param_type* r) {
614 FilePath::StringType value; 587 FilePath::StringType value;
615 if (!ParamTraits<FilePath::StringType>::Read(m, iter, &value)) 588 if (!ParamTraits<FilePath::StringType>::Read(m, iter, &value))
616 return false; 589 return false;
617 *r = FilePath(value); 590 *r = FilePath(value);
618 return true; 591 return true;
619 } 592 }
620 static void Log(const param_type& p, std::wstring* l) { 593 static void Log(const param_type& p, std::wstring* l) {
621 ParamTraits<FilePath::StringType>::Log(p.value(), l); 594 ParamTraits<FilePath::StringType>::Log(p.value(), l);
622 } 595 }
623 }; 596 };
624 597
625 template <> 598 template <>
626 struct ParamTraits<gfx::Point> { 599 struct ParamTraits<gfx::Point> {
627 typedef gfx::Point param_type; 600 typedef gfx::Point param_type;
628 static void Write(Message* m, const param_type& p); 601 static void Write(IPC::Message* m, const param_type& p);
629 static bool Read(const Message* m, void** iter, param_type* r); 602 static bool Read(const IPC::Message* m, void** iter, param_type* r);
630 static void Log(const param_type& p, std::wstring* l); 603 static void Log(const param_type& p, std::wstring* l);
631 }; 604 };
632 605
633 template <> 606 template <>
634 struct ParamTraits<gfx::Rect> { 607 struct ParamTraits<gfx::Rect> {
635 typedef gfx::Rect param_type; 608 typedef gfx::Rect param_type;
636 static void Write(Message* m, const param_type& p); 609 static void Write(IPC::Message* m, const param_type& p);
637 static bool Read(const Message* m, void** iter, param_type* r); 610 static bool Read(const IPC::Message* m, void** iter, param_type* r);
638 static void Log(const param_type& p, std::wstring* l); 611 static void Log(const param_type& p, std::wstring* l);
639 }; 612 };
640 613
641 template <> 614 template <>
642 struct ParamTraits<gfx::Size> { 615 struct ParamTraits<gfx::Size> {
643 typedef gfx::Size param_type; 616 typedef gfx::Size param_type;
644 static void Write(Message* m, const param_type& p); 617 static void Write(IPC::Message* m, const param_type& p);
645 static bool Read(const Message* m, void** iter, param_type* r); 618 static bool Read(const IPC::Message* m, void** iter, param_type* r);
646 static void Log(const param_type& p, std::wstring* l); 619 static void Log(const param_type& p, std::wstring* l);
647 }; 620 };
648 621
649 template<> 622 template<>
650 struct ParamTraits<ThumbnailScore> { 623 struct ParamTraits<ThumbnailScore> {
651 typedef ThumbnailScore param_type; 624 typedef ThumbnailScore param_type;
652 static void Write(Message* m, const param_type& p) { 625 static void Write(IPC::Message* m, const param_type& p) {
653 IPC::ParamTraits<double>::Write(m, p.boring_score); 626 ParamTraits<double>::Write(m, p.boring_score);
654 IPC::ParamTraits<bool>::Write(m, p.good_clipping); 627 ParamTraits<bool>::Write(m, p.good_clipping);
655 IPC::ParamTraits<bool>::Write(m, p.at_top); 628 ParamTraits<bool>::Write(m, p.at_top);
656 IPC::ParamTraits<base::Time>::Write(m, p.time_at_snapshot); 629 ParamTraits<base::Time>::Write(m, p.time_at_snapshot);
657 } 630 }
658 static bool Read(const Message* m, void** iter, param_type* r) { 631 static bool Read(const IPC::Message* m, void** iter, param_type* r) {
659 double boring_score; 632 double boring_score;
660 bool good_clipping, at_top; 633 bool good_clipping, at_top;
661 base::Time time_at_snapshot; 634 base::Time time_at_snapshot;
662 if (!IPC::ParamTraits<double>::Read(m, iter, &boring_score) || 635 if (!ParamTraits<double>::Read(m, iter, &boring_score) ||
663 !IPC::ParamTraits<bool>::Read(m, iter, &good_clipping) || 636 !ParamTraits<bool>::Read(m, iter, &good_clipping) ||
664 !IPC::ParamTraits<bool>::Read(m, iter, &at_top) || 637 !ParamTraits<bool>::Read(m, iter, &at_top) ||
665 !IPC::ParamTraits<base::Time>::Read(m, iter, &time_at_snapshot)) 638 !ParamTraits<base::Time>::Read(m, iter, &time_at_snapshot))
666 return false; 639 return false;
667 640
668 r->boring_score = boring_score; 641 r->boring_score = boring_score;
669 r->good_clipping = good_clipping; 642 r->good_clipping = good_clipping;
670 r->at_top = at_top; 643 r->at_top = at_top;
671 r->time_at_snapshot = time_at_snapshot; 644 r->time_at_snapshot = time_at_snapshot;
672 return true; 645 return true;
673 } 646 }
674 static void Log(const param_type& p, std::wstring* l) { 647 static void Log(const param_type& p, std::wstring* l) {
675 l->append(StringPrintf(L"(%f, %d, %d)", 648 l->append(StringPrintf(L"(%f, %d, %d)",
676 p.boring_score, p.good_clipping, p.at_top)); 649 p.boring_score, p.good_clipping, p.at_top));
677 } 650 }
678 }; 651 };
679 652
680 template <> 653 template <>
681 struct ParamTraits<WindowOpenDisposition> { 654 struct ParamTraits<WindowOpenDisposition> {
682 typedef WindowOpenDisposition param_type; 655 typedef WindowOpenDisposition param_type;
683 static void Write(Message* m, const param_type& p) { 656 static void Write(IPC::Message* m, const param_type& p) {
684 m->WriteInt(p); 657 m->WriteInt(p);
685 } 658 }
686 static bool Read(const Message* m, void** iter, param_type* r) { 659 static bool Read(const IPC::Message* m, void** iter, param_type* r) {
687 int temp; 660 int temp;
688 bool res = m->ReadInt(iter, &temp); 661 bool res = m->ReadInt(iter, &temp);
689 *r = static_cast<WindowOpenDisposition>(temp); 662 *r = static_cast<WindowOpenDisposition>(temp);
690 return res; 663 return res;
691 } 664 }
692 static void Log(const param_type& p, std::wstring* l) { 665 static void Log(const param_type& p, std::wstring* l) {
693 l->append(StringPrintf(L"%d", p)); 666 l->append(StringPrintf(L"%d", p));
694 } 667 }
695 }; 668 };
696 669
697 template <> 670 template <>
698 struct ParamTraits<ConsoleMessageLevel> { 671 struct ParamTraits<ConsoleMessageLevel> {
699 typedef ConsoleMessageLevel param_type; 672 typedef ConsoleMessageLevel param_type;
700 static void Write(Message* m, const param_type& p) { 673 static void Write(IPC::Message* m, const param_type& p) {
701 m->WriteInt(p); 674 m->WriteInt(p);
702 } 675 }
703 static bool Read(const Message* m, void** iter, param_type* r) { 676 static bool Read(const IPC::Message* m, void** iter, param_type* r) {
704 int temp; 677 int temp;
705 bool res = m->ReadInt(iter, &temp); 678 bool res = m->ReadInt(iter, &temp);
706 *r = static_cast<ConsoleMessageLevel>(temp); 679 *r = static_cast<ConsoleMessageLevel>(temp);
707 return res; 680 return res;
708 } 681 }
709 static void Log(const param_type& p, std::wstring* l) { 682 static void Log(const param_type& p, std::wstring* l) {
710 l->append(StringPrintf(L"%d", p)); 683 l->append(StringPrintf(L"%d", p));
711 } 684 }
712 }; 685 };
713 686
714 template <> 687 template <>
715 struct ParamTraits<CacheManager::ResourceTypeStat> { 688 struct ParamTraits<CacheManager::ResourceTypeStat> {
716 typedef CacheManager::ResourceTypeStat param_type; 689 typedef CacheManager::ResourceTypeStat param_type;
717 static void Write(Message* m, const param_type& p) { 690 static void Write(IPC::Message* m, const param_type& p) {
718 WriteParam(m, p.count); 691 WriteParam(m, p.count);
719 WriteParam(m, p.size); 692 WriteParam(m, p.size);
720 WriteParam(m, p.live_size); 693 WriteParam(m, p.live_size);
721 WriteParam(m, p.decoded_size); 694 WriteParam(m, p.decoded_size);
722 } 695 }
723 static bool Read(const Message* m, void** iter, param_type* r) { 696 static bool Read(const IPC::Message* m, void** iter, param_type* r) {
724 bool result = 697 bool result =
725 ReadParam(m, iter, &r->count) && 698 ReadParam(m, iter, &r->count) &&
726 ReadParam(m, iter, &r->size) && 699 ReadParam(m, iter, &r->size) &&
727 ReadParam(m, iter, &r->live_size) && 700 ReadParam(m, iter, &r->live_size) &&
728 ReadParam(m, iter, &r->decoded_size); 701 ReadParam(m, iter, &r->decoded_size);
729 return result; 702 return result;
730 } 703 }
731 static void Log(const param_type& p, std::wstring* l) { 704 static void Log(const param_type& p, std::wstring* l) {
732 l->append(StringPrintf(L"%d %d %d %d", p.count, p.size, p.live_size, 705 l->append(StringPrintf(L"%d %d %d %d", p.count, p.size, p.live_size,
733 p.decoded_size)); 706 p.decoded_size));
734 } 707 }
735 }; 708 };
736 709
737 template <> 710 template <>
738 struct ParamTraits<CacheManager::ResourceTypeStats> { 711 struct ParamTraits<CacheManager::ResourceTypeStats> {
739 typedef CacheManager::ResourceTypeStats param_type; 712 typedef CacheManager::ResourceTypeStats param_type;
740 static void Write(Message* m, const param_type& p) { 713 static void Write(IPC::Message* m, const param_type& p) {
741 WriteParam(m, p.images); 714 WriteParam(m, p.images);
742 WriteParam(m, p.css_stylesheets); 715 WriteParam(m, p.css_stylesheets);
743 WriteParam(m, p.scripts); 716 WriteParam(m, p.scripts);
744 WriteParam(m, p.xsl_stylesheets); 717 WriteParam(m, p.xsl_stylesheets);
745 WriteParam(m, p.fonts); 718 WriteParam(m, p.fonts);
746 } 719 }
747 static bool Read(const Message* m, void** iter, param_type* r) { 720 static bool Read(const IPC::Message* m, void** iter, param_type* r) {
748 bool result = 721 bool result =
749 ReadParam(m, iter, &r->images) && 722 ReadParam(m, iter, &r->images) &&
750 ReadParam(m, iter, &r->css_stylesheets) && 723 ReadParam(m, iter, &r->css_stylesheets) &&
751 ReadParam(m, iter, &r->scripts) && 724 ReadParam(m, iter, &r->scripts) &&
752 ReadParam(m, iter, &r->xsl_stylesheets) && 725 ReadParam(m, iter, &r->xsl_stylesheets) &&
753 ReadParam(m, iter, &r->fonts); 726 ReadParam(m, iter, &r->fonts);
754 return result; 727 return result;
755 } 728 }
756 static void Log(const param_type& p, std::wstring* l) { 729 static void Log(const param_type& p, std::wstring* l) {
757 l->append(L"<WebCoreStats>"); 730 l->append(L"<WebCoreStats>");
758 LogParam(p.images, l); 731 LogParam(p.images, l);
759 LogParam(p.css_stylesheets, l); 732 LogParam(p.css_stylesheets, l);
760 LogParam(p.scripts, l); 733 LogParam(p.scripts, l);
761 LogParam(p.xsl_stylesheets, l); 734 LogParam(p.xsl_stylesheets, l);
762 LogParam(p.fonts, l); 735 LogParam(p.fonts, l);
763 l->append(L"</WebCoreStats>"); 736 l->append(L"</WebCoreStats>");
764 } 737 }
765 }; 738 };
766 739
767 #if defined(OS_WIN) 740 #if defined(OS_WIN)
768 template <> 741 template <>
769 struct ParamTraits<XFORM> { 742 struct ParamTraits<XFORM> {
770 typedef XFORM param_type; 743 typedef XFORM param_type;
771 static void Write(Message* m, const param_type& p) { 744 static void Write(IPC::Message* m, const param_type& p) {
772 m->WriteData(reinterpret_cast<const char*>(&p), sizeof(XFORM)); 745 m->WriteData(reinterpret_cast<const char*>(&p), sizeof(XFORM));
773 } 746 }
774 static bool Read(const Message* m, void** iter, param_type* r) { 747 static bool Read(const IPC::Message* m, void** iter, param_type* r) {
775 const char *data; 748 const char *data;
776 int data_size = 0; 749 int data_size = 0;
777 bool result = m->ReadData(iter, &data, &data_size); 750 bool result = m->ReadData(iter, &data, &data_size);
778 if (result && data_size == sizeof(XFORM)) { 751 if (result && data_size == sizeof(XFORM)) {
779 memcpy(r, data, sizeof(XFORM)); 752 memcpy(r, data, sizeof(XFORM));
780 } else { 753 } else {
781 result = false; 754 result = false;
782 NOTREACHED(); 755 NOTREACHED();
783 } 756 }
784 757
785 return result; 758 return result;
786 } 759 }
787 static void Log(const param_type& p, std::wstring* l) { 760 static void Log(const param_type& p, std::wstring* l) {
788 l->append(L"<XFORM>"); 761 l->append(L"<XFORM>");
789 } 762 }
790 }; 763 };
791 #endif // defined(OS_WIN) 764 #endif // defined(OS_WIN)
792 765
793 template <> 766 template <>
794 struct ParamTraits<WebCursor> { 767 struct ParamTraits<WebCursor> {
795 typedef WebCursor param_type; 768 typedef WebCursor param_type;
796 static void Write(Message* m, const param_type& p) { 769 static void Write(IPC::Message* m, const param_type& p) {
797 p.Serialize(m); 770 p.Serialize(m);
798 } 771 }
799 static bool Read(const Message* m, void** iter, param_type* r) { 772 static bool Read(const IPC::Message* m, void** iter, param_type* r) {
800 return r->Deserialize(m, iter); 773 return r->Deserialize(m, iter);
801 } 774 }
802 static void Log(const param_type& p, std::wstring* l) { 775 static void Log(const param_type& p, std::wstring* l) {
803 l->append(L"<WebCursor>"); 776 l->append(L"<WebCursor>");
804 } 777 }
805 }; 778 };
806 779
780 namespace IPC {
781
807 struct LogData { 782 struct LogData {
808 std::wstring channel; 783 std::wstring channel;
809 uint16 type; 784 uint16 type;
810 std::wstring flags; 785 std::wstring flags;
811 int64 sent; // Time that the message was sent (i.e. at Send()). 786 int64 sent; // Time that the message was sent (i.e. at Send()).
812 int64 receive; // Time before it was dispatched (i.e. before calling 787 int64 receive; // Time before it was dispatched (i.e. before calling
813 // OnMessageReceived). 788 // OnMessageReceived).
814 int64 dispatch; // Time after it was dispatched (i.e. after calling 789 int64 dispatch; // Time after it was dispatched (i.e. after calling
815 // OnMessageReceived). 790 // OnMessageReceived).
816 std::wstring params; 791 std::wstring params;
817 }; 792 };
818 793
794 }
795
819 template <> 796 template <>
820 struct ParamTraits<LogData> { 797 struct ParamTraits<IPC::LogData> {
821 typedef LogData param_type; 798 typedef IPC::LogData param_type;
822 static void Write(Message* m, const param_type& p) { 799 static void Write(IPC::Message* m, const param_type& p) {
823 WriteParam(m, p.channel); 800 WriteParam(m, p.channel);
824 WriteParam(m, static_cast<int>(p.type)); 801 WriteParam(m, static_cast<int>(p.type));
825 WriteParam(m, p.flags); 802 WriteParam(m, p.flags);
826 WriteParam(m, p.sent); 803 WriteParam(m, p.sent);
827 WriteParam(m, p.receive); 804 WriteParam(m, p.receive);
828 WriteParam(m, p.dispatch); 805 WriteParam(m, p.dispatch);
829 WriteParam(m, p.params); 806 WriteParam(m, p.params);
830 } 807 }
831 static bool Read(const Message* m, void** iter, param_type* r) { 808 static bool Read(const IPC::Message* m, void** iter, param_type* r) {
832 int type; 809 int type;
833 bool result = 810 bool result =
834 ReadParam(m, iter, &r->channel) && 811 ReadParam(m, iter, &r->channel) &&
835 ReadParam(m, iter, &type) && 812 ReadParam(m, iter, &type) &&
836 ReadParam(m, iter, &r->flags) && 813 ReadParam(m, iter, &r->flags) &&
837 ReadParam(m, iter, &r->sent) && 814 ReadParam(m, iter, &r->sent) &&
838 ReadParam(m, iter, &r->receive) && 815 ReadParam(m, iter, &r->receive) &&
839 ReadParam(m, iter, &r->dispatch) && 816 ReadParam(m, iter, &r->dispatch) &&
840 ReadParam(m, iter, &r->params); 817 ReadParam(m, iter, &r->params);
841 r->type = static_cast<uint16>(type); 818 r->type = static_cast<uint16>(type);
842 return result; 819 return result;
843 } 820 }
844 static void Log(const param_type& p, std::wstring* l) { 821 static void Log(const param_type& p, std::wstring* l) {
845 // Doesn't make sense to implement this! 822 // Doesn't make sense to implement this!
846 } 823 }
847 }; 824 };
848 825
849 template <> 826 template <>
850 struct ParamTraits<Tuple0> { 827 struct ParamTraits<Tuple0> {
851 typedef Tuple0 param_type; 828 typedef Tuple0 param_type;
852 static void Write(Message* m, const param_type& p) { 829 static void Write(IPC::Message* m, const param_type& p) {
853 } 830 }
854 static bool Read(const Message* m, void** iter, param_type* r) { 831 static bool Read(const IPC::Message* m, void** iter, param_type* r) {
855 return true; 832 return true;
856 } 833 }
857 static void Log(const param_type& p, std::wstring* l) { 834 static void Log(const param_type& p, std::wstring* l) {
858 } 835 }
859 }; 836 };
860 837
861 template <class A> 838 template <class A>
862 struct ParamTraits< Tuple1<A> > { 839 struct ParamTraits< Tuple1<A> > {
863 typedef Tuple1<A> param_type; 840 typedef Tuple1<A> param_type;
864 static void Write(Message* m, const param_type& p) { 841 static void Write(IPC::Message* m, const param_type& p) {
865 WriteParam(m, p.a); 842 WriteParam(m, p.a);
866 } 843 }
867 static bool Read(const Message* m, void** iter, param_type* r) { 844 static bool Read(const IPC::Message* m, void** iter, param_type* r) {
868 return ReadParam(m, iter, &r->a); 845 return ReadParam(m, iter, &r->a);
869 } 846 }
870 static void Log(const param_type& p, std::wstring* l) { 847 static void Log(const param_type& p, std::wstring* l) {
871 LogParam(p.a, l); 848 LogParam(p.a, l);
872 } 849 }
873 }; 850 };
874 851
875 template <class A, class B> 852 template <class A, class B>
876 struct ParamTraits< Tuple2<A, B> > { 853 struct ParamTraits< Tuple2<A, B> > {
877 typedef Tuple2<A, B> param_type; 854 typedef Tuple2<A, B> param_type;
878 static void Write(Message* m, const param_type& p) { 855 static void Write(IPC::Message* m, const param_type& p) {
879 WriteParam(m, p.a); 856 WriteParam(m, p.a);
880 WriteParam(m, p.b); 857 WriteParam(m, p.b);
881 } 858 }
882 static bool Read(const Message* m, void** iter, param_type* r) { 859 static bool Read(const IPC::Message* m, void** iter, param_type* r) {
883 return (ReadParam(m, iter, &r->a) && 860 return (ReadParam(m, iter, &r->a) &&
884 ReadParam(m, iter, &r->b)); 861 ReadParam(m, iter, &r->b));
885 } 862 }
886 static void Log(const param_type& p, std::wstring* l) { 863 static void Log(const param_type& p, std::wstring* l) {
887 LogParam(p.a, l); 864 LogParam(p.a, l);
888 l->append(L", "); 865 l->append(L", ");
889 LogParam(p.b, l); 866 LogParam(p.b, l);
890 } 867 }
891 }; 868 };
892 869
893 template <class A, class B, class C> 870 template <class A, class B, class C>
894 struct ParamTraits< Tuple3<A, B, C> > { 871 struct ParamTraits< Tuple3<A, B, C> > {
895 typedef Tuple3<A, B, C> param_type; 872 typedef Tuple3<A, B, C> param_type;
896 static void Write(Message* m, const param_type& p) { 873 static void Write(IPC::Message* m, const param_type& p) {
897 WriteParam(m, p.a); 874 WriteParam(m, p.a);
898 WriteParam(m, p.b); 875 WriteParam(m, p.b);
899 WriteParam(m, p.c); 876 WriteParam(m, p.c);
900 } 877 }
901 static bool Read(const Message* m, void** iter, param_type* r) { 878 static bool Read(const IPC::Message* m, void** iter, param_type* r) {
902 return (ReadParam(m, iter, &r->a) && 879 return (ReadParam(m, iter, &r->a) &&
903 ReadParam(m, iter, &r->b) && 880 ReadParam(m, iter, &r->b) &&
904 ReadParam(m, iter, &r->c)); 881 ReadParam(m, iter, &r->c));
905 } 882 }
906 static void Log(const param_type& p, std::wstring* l) { 883 static void Log(const param_type& p, std::wstring* l) {
907 LogParam(p.a, l); 884 LogParam(p.a, l);
908 l->append(L", "); 885 l->append(L", ");
909 LogParam(p.b, l); 886 LogParam(p.b, l);
910 l->append(L", "); 887 l->append(L", ");
911 LogParam(p.c, l); 888 LogParam(p.c, l);
912 } 889 }
913 }; 890 };
914 891
915 template <class A, class B, class C, class D> 892 template <class A, class B, class C, class D>
916 struct ParamTraits< Tuple4<A, B, C, D> > { 893 struct ParamTraits< Tuple4<A, B, C, D> > {
917 typedef Tuple4<A, B, C, D> param_type; 894 typedef Tuple4<A, B, C, D> param_type;
918 static void Write(Message* m, const param_type& p) { 895 static void Write(IPC::Message* m, const param_type& p) {
919 WriteParam(m, p.a); 896 WriteParam(m, p.a);
920 WriteParam(m, p.b); 897 WriteParam(m, p.b);
921 WriteParam(m, p.c); 898 WriteParam(m, p.c);
922 WriteParam(m, p.d); 899 WriteParam(m, p.d);
923 } 900 }
924 static bool Read(const Message* m, void** iter, param_type* r) { 901 static bool Read(const IPC::Message* m, void** iter, param_type* r) {
925 return (ReadParam(m, iter, &r->a) && 902 return (ReadParam(m, iter, &r->a) &&
926 ReadParam(m, iter, &r->b) && 903 ReadParam(m, iter, &r->b) &&
927 ReadParam(m, iter, &r->c) && 904 ReadParam(m, iter, &r->c) &&
928 ReadParam(m, iter, &r->d)); 905 ReadParam(m, iter, &r->d));
929 } 906 }
930 static void Log(const param_type& p, std::wstring* l) { 907 static void Log(const param_type& p, std::wstring* l) {
931 LogParam(p.a, l); 908 LogParam(p.a, l);
932 l->append(L", "); 909 l->append(L", ");
933 LogParam(p.b, l); 910 LogParam(p.b, l);
934 l->append(L", "); 911 l->append(L", ");
935 LogParam(p.c, l); 912 LogParam(p.c, l);
936 l->append(L", "); 913 l->append(L", ");
937 LogParam(p.d, l); 914 LogParam(p.d, l);
938 } 915 }
939 }; 916 };
940 917
941 template <class A, class B, class C, class D, class E> 918 template <class A, class B, class C, class D, class E>
942 struct ParamTraits< Tuple5<A, B, C, D, E> > { 919 struct ParamTraits< Tuple5<A, B, C, D, E> > {
943 typedef Tuple5<A, B, C, D, E> param_type; 920 typedef Tuple5<A, B, C, D, E> param_type;
944 static void Write(Message* m, const param_type& p) { 921 static void Write(IPC::Message* m, const param_type& p) {
945 WriteParam(m, p.a); 922 WriteParam(m, p.a);
946 WriteParam(m, p.b); 923 WriteParam(m, p.b);
947 WriteParam(m, p.c); 924 WriteParam(m, p.c);
948 WriteParam(m, p.d); 925 WriteParam(m, p.d);
949 WriteParam(m, p.e); 926 WriteParam(m, p.e);
950 } 927 }
951 static bool Read(const Message* m, void** iter, param_type* r) { 928 static bool Read(const IPC::Message* m, void** iter, param_type* r) {
952 return (ReadParam(m, iter, &r->a) && 929 return (ReadParam(m, iter, &r->a) &&
953 ReadParam(m, iter, &r->b) && 930 ReadParam(m, iter, &r->b) &&
954 ReadParam(m, iter, &r->c) && 931 ReadParam(m, iter, &r->c) &&
955 ReadParam(m, iter, &r->d) && 932 ReadParam(m, iter, &r->d) &&
956 ReadParam(m, iter, &r->e)); 933 ReadParam(m, iter, &r->e));
957 } 934 }
958 static void Log(const param_type& p, std::wstring* l) { 935 static void Log(const param_type& p, std::wstring* l) {
959 LogParam(p.a, l); 936 LogParam(p.a, l);
960 l->append(L", "); 937 l->append(L", ");
961 LogParam(p.b, l); 938 LogParam(p.b, l);
962 l->append(L", "); 939 l->append(L", ");
963 LogParam(p.c, l); 940 LogParam(p.c, l);
964 l->append(L", "); 941 l->append(L", ");
965 LogParam(p.d, l); 942 LogParam(p.d, l);
966 l->append(L", "); 943 l->append(L", ");
967 LogParam(p.e, l); 944 LogParam(p.e, l);
968 } 945 }
969 }; 946 };
970 947
971 template <class A, class B, class C, class D, class E, class F> 948 template <class A, class B, class C, class D, class E, class F>
972 struct ParamTraits< Tuple6<A, B, C, D, E, F> > { 949 struct ParamTraits< Tuple6<A, B, C, D, E, F> > {
973 typedef Tuple6<A, B, C, D, E, F> param_type; 950 typedef Tuple6<A, B, C, D, E, F> param_type;
974 static void Write(Message* m, const param_type& p) { 951 static void Write(IPC::Message* m, const param_type& p) {
975 WriteParam(m, p.a); 952 WriteParam(m, p.a);
976 WriteParam(m, p.b); 953 WriteParam(m, p.b);
977 WriteParam(m, p.c); 954 WriteParam(m, p.c);
978 WriteParam(m, p.d); 955 WriteParam(m, p.d);
979 WriteParam(m, p.e); 956 WriteParam(m, p.e);
980 WriteParam(m, p.f); 957 WriteParam(m, p.f);
981 } 958 }
982 static bool Read(const Message* m, void** iter, param_type* r) { 959 static bool Read(const IPC::Message* m, void** iter, param_type* r) {
983 return (ReadParam(m, iter, &r->a) && 960 return (ReadParam(m, iter, &r->a) &&
984 ReadParam(m, iter, &r->b) && 961 ReadParam(m, iter, &r->b) &&
985 ReadParam(m, iter, &r->c) && 962 ReadParam(m, iter, &r->c) &&
986 ReadParam(m, iter, &r->d) && 963 ReadParam(m, iter, &r->d) &&
987 ReadParam(m, iter, &r->e) && 964 ReadParam(m, iter, &r->e) &&
988 ReadParam(m, iter, &r->f)); 965 ReadParam(m, iter, &r->f));
989 } 966 }
990 static void Log(const param_type& p, std::wstring* l) { 967 static void Log(const param_type& p, std::wstring* l) {
991 LogParam(p.a, l); 968 LogParam(p.a, l);
992 l->append(L", "); 969 l->append(L", ");
993 LogParam(p.b, l); 970 LogParam(p.b, l);
994 l->append(L", "); 971 l->append(L", ");
995 LogParam(p.c, l); 972 LogParam(p.c, l);
996 l->append(L", "); 973 l->append(L", ");
997 LogParam(p.d, l); 974 LogParam(p.d, l);
998 l->append(L", "); 975 l->append(L", ");
999 LogParam(p.e, l); 976 LogParam(p.e, l);
1000 l->append(L", "); 977 l->append(L", ");
1001 LogParam(p.f, l); 978 LogParam(p.f, l);
1002 } 979 }
1003 }; 980 };
1004 981
1005 template <> 982 template <>
1006 struct ParamTraits<webkit_glue::WebApplicationInfo> { 983 struct ParamTraits<webkit_glue::WebApplicationInfo> {
1007 typedef webkit_glue::WebApplicationInfo param_type; 984 typedef webkit_glue::WebApplicationInfo param_type;
1008 static void Write(Message* m, const param_type& p); 985 static void Write(IPC::Message* m, const param_type& p);
1009 static bool Read(const Message* m, void** iter, param_type* r); 986 static bool Read(const IPC::Message* m, void** iter, param_type* r);
1010 static void Log(const param_type& p, std::wstring* l); 987 static void Log(const param_type& p, std::wstring* l);
1011 }; 988 };
1012 989
990 // Traits for ViewMsg_FindInPageMsg_Request structure to pack/unpack.
991 template <>
992 struct ParamTraits<FindInPageRequest> {
993 typedef FindInPageRequest param_type;
994 static void Write(IPC::Message* m, const param_type& p) {
995 WriteParam(m, p.request_id);
996 WriteParam(m, p.search_string);
997 WriteParam(m, p.forward);
998 WriteParam(m, p.match_case);
999 WriteParam(m, p.find_next);
1000 }
1001 static bool Read(const IPC::Message* m, void** iter, param_type* p) {
1002 return
1003 ReadParam(m, iter, &p->request_id) &&
1004 ReadParam(m, iter, &p->search_string) &&
1005 ReadParam(m, iter, &p->forward) &&
1006 ReadParam(m, iter, &p->match_case) &&
1007 ReadParam(m, iter, &p->find_next);
1008 }
1009 static void Log(const param_type& p, std::wstring* l) {
1010 l->append(L"<FindInPageRequest>");
1011 }
1012 };
1013
1014 namespace IPC {
1015
1016 //-----------------------------------------------------------------------------
1017 // An iterator class for reading the fields contained within a Message.
1018
1019 class MessageIterator {
1020 public:
1021 explicit MessageIterator(const Message& m) : msg_(m), iter_(NULL) {
1022 }
1023 int NextInt() const {
1024 int val;
1025 if (!msg_.ReadInt(&iter_, &val))
1026 NOTREACHED();
1027 return val;
1028 }
1029 intptr_t NextIntPtr() const {
1030 intptr_t val;
1031 if (!msg_.ReadIntPtr(&iter_, &val))
1032 NOTREACHED();
1033 return val;
1034 }
1035 const std::string NextString() const {
1036 std::string val;
1037 if (!msg_.ReadString(&iter_, &val))
1038 NOTREACHED();
1039 return val;
1040 }
1041 const std::wstring NextWString() const {
1042 std::wstring val;
1043 if (!msg_.ReadWString(&iter_, &val))
1044 NOTREACHED();
1045 return val;
1046 }
1047 const void NextData(const char** data, int* length) const {
1048 if (!msg_.ReadData(&iter_, data, length)) {
1049 NOTREACHED();
1050 }
1051 }
1052 private:
1053 const Message& msg_;
1054 mutable void* iter_;
1055 };
1013 1056
1014 //----------------------------------------------------------------------------- 1057 //-----------------------------------------------------------------------------
1015 // Generic message subclasses 1058 // Generic message subclasses
1016 1059
1017 // Used for asynchronous messages. 1060 // Used for asynchronous messages.
1018 template <class ParamType> 1061 template <class ParamType>
1019 class MessageWithTuple : public Message { 1062 class MessageWithTuple : public Message {
1020 public: 1063 public:
1021 typedef ParamType Param; 1064 typedef ParamType Param;
1022 1065
1023 MessageWithTuple(int32 routing_id, uint16 type, const Param& p) 1066 MessageWithTuple(int32 routing_id, uint16 type, const Param& p)
1024 : Message(routing_id, type, PRIORITY_NORMAL) { 1067 : Message(routing_id, type, PRIORITY_NORMAL) {
1025 WriteParam(this, p); 1068 WriteParam(this, p);
1026 } 1069 }
1027 1070
1028 static bool Read(const Message* msg, Param* p) { 1071 static bool Read(const IPC::Message* msg, Param* p) {
1029 void* iter = NULL; 1072 void* iter = NULL;
1030 bool rv = ReadParam(msg, &iter, p); 1073 bool rv = ReadParam(msg, &iter, p);
1031 DCHECK(rv) << "Error deserializing message " << msg->type(); 1074 DCHECK(rv) << "Error deserializing message " << msg->type();
1032 return rv; 1075 return rv;
1033 } 1076 }
1034 1077
1035 // Generic dispatcher. Should cover most cases. 1078 // Generic dispatcher. Should cover most cases.
1036 template<class T, class Method> 1079 template<class T, class Method>
1037 static bool Dispatch(const Message* msg, T* obj, Method func) { 1080 static bool Dispatch(const IPC::Message* msg, T* obj, Method func) {
1038 Param p; 1081 Param p;
1039 if (Read(msg, &p)) { 1082 if (Read(msg, &p)) {
1040 DispatchToMethod(obj, func, p); 1083 DispatchToMethod(obj, func, p);
1041 return true; 1084 return true;
1042 } 1085 }
1043 return false; 1086 return false;
1044 } 1087 }
1045 1088
1046 // The following dispatchers exist for the case where the callback function 1089 // The following dispatchers exist for the case where the callback function
1047 // needs the message as well. They assume that "Param" is a type of Tuple 1090 // needs the message as well. They assume that "Param" is a type of Tuple
1048 // (except the one arg case, as there is no Tuple1). 1091 // (except the one arg case, as there is no Tuple1).
1049 template<class T, typename TA> 1092 template<class T, typename TA>
1050 static bool Dispatch(const Message* msg, T* obj, 1093 static bool Dispatch(const IPC::Message* msg, T* obj,
1051 void (T::*func)(const Message&, TA)) { 1094 void (T::*func)(const Message&, TA)) {
1052 Param p; 1095 Param p;
1053 if (Read(msg, &p)) { 1096 if (Read(msg, &p)) {
1054 (obj->*func)(*msg, p); 1097 (obj->*func)(*msg, p);
1055 return true; 1098 return true;
1056 } 1099 }
1057 return false; 1100 return false;
1058 } 1101 }
1059 1102
1060 template<class T, typename TA, typename TB> 1103 template<class T, typename TA, typename TB>
1061 static bool Dispatch(const Message* msg, T* obj, 1104 static bool Dispatch(const IPC::Message* msg, T* obj,
1062 void (T::*func)(const Message&, TA, TB)) { 1105 void (T::*func)(const Message&, TA, TB)) {
1063 Param p; 1106 Param p;
1064 if (Read(msg, &p)) { 1107 if (Read(msg, &p)) {
1065 (obj->*func)(*msg, p.a, p.b); 1108 (obj->*func)(*msg, p.a, p.b);
1066 return true; 1109 return true;
1067 } 1110 }
1068 return false; 1111 return false;
1069 } 1112 }
1070 1113
1071 template<class T, typename TA, typename TB, typename TC> 1114 template<class T, typename TA, typename TB, typename TC>
1072 static bool Dispatch(const Message* msg, T* obj, 1115 static bool Dispatch(const IPC::Message* msg, T* obj,
1073 void (T::*func)(const Message&, TA, TB, TC)) { 1116 void (T::*func)(const Message&, TA, TB, TC)) {
1074 Param p; 1117 Param p;
1075 if (Read(msg, &p)) { 1118 if (Read(msg, &p)) {
1076 (obj->*func)(*msg, p.a, p.b, p.c); 1119 (obj->*func)(*msg, p.a, p.b, p.c);
1077 return true; 1120 return true;
1078 } 1121 }
1079 return false; 1122 return false;
1080 } 1123 }
1081 1124
1082 template<class T, typename TA, typename TB, typename TC, typename TD> 1125 template<class T, typename TA, typename TB, typename TC, typename TD>
1083 static bool Dispatch(const Message* msg, T* obj, 1126 static bool Dispatch(const IPC::Message* msg, T* obj,
1084 void (T::*func)(const Message&, TA, TB, TC, TD)) { 1127 void (T::*func)(const Message&, TA, TB, TC, TD)) {
1085 Param p; 1128 Param p;
1086 if (Read(msg, &p)) { 1129 if (Read(msg, &p)) {
1087 (obj->*func)(*msg, p.a, p.b, p.c, p.d); 1130 (obj->*func)(*msg, p.a, p.b, p.c, p.d);
1088 return true; 1131 return true;
1089 } 1132 }
1090 return false; 1133 return false;
1091 } 1134 }
1092 1135
1093 template<class T, typename TA, typename TB, typename TC, typename TD, 1136 template<class T, typename TA, typename TB, typename TC, typename TD,
1094 typename TE> 1137 typename TE>
1095 static bool Dispatch(const Message* msg, T* obj, 1138 static bool Dispatch(const IPC::Message* msg, T* obj,
1096 void (T::*func)(const Message&, TA, TB, TC, TD, TE)) { 1139 void (T::*func)(const Message&, TA, TB, TC, TD, TE)) {
1097 Param p; 1140 Param p;
1098 if (Read(msg, &p)) { 1141 if (Read(msg, &p)) {
1099 (obj->*func)(*msg, p.a, p.b, p.c, p.d, p.e); 1142 (obj->*func)(*msg, p.a, p.b, p.c, p.d, p.e);
1100 return true; 1143 return true;
1101 } 1144 }
1102 return false; 1145 return false;
1103 } 1146 }
1104 1147
1105 static void Log(const Message* msg, std::wstring* l) { 1148 static void Log(const IPC::Message* msg, std::wstring* l) {
1106 Param p; 1149 Param p;
1107 if (Read(msg, &p)) 1150 if (Read(msg, &p))
1108 LogParam(p, l); 1151 LogParam(p, l);
1109 } 1152 }
1153
1154 // Functions used to do manual unpacking. Only used by the automation code,
1155 // these should go away once that code uses SyncChannel.
1156 template<typename TA, typename TB>
1157 static bool Read(const IPC::Message* msg, TA* a, TB* b) {
1158 ParamType params;
1159 if (!Read(msg, &params))
1160 return false;
1161 *a = params.a;
1162 *b = params.b;
1163 return true;
1164 }
1165
1166 template<typename TA, typename TB, typename TC>
1167 static bool Read(const IPC::Message* msg, TA* a, TB* b, TC* c) {
1168 ParamType params;
1169 if (!Read(msg, &params))
1170 return false;
1171 *a = params.a;
1172 *b = params.b;
1173 *c = params.c;
1174 return true;
1175 }
1176
1177 template<typename TA, typename TB, typename TC, typename TD>
1178 static bool Read(const IPC::Message* msg, TA* a, TB* b, TC* c, TD* d) {
1179 ParamType params;
1180 if (!Read(msg, &params))
1181 return false;
1182 *a = params.a;
1183 *b = params.b;
1184 *c = params.c;
1185 *d = params.d;
1186 return true;
1187 }
1188
1189 template<typename TA, typename TB, typename TC, typename TD, typename TE>
1190 static bool Read(const IPC::Message* msg, TA* a, TB* b, TC* c, TD* d, TE* e) {
1191 ParamType params;
1192 if (!Read(msg, &params))
1193 return false;
1194 *a = params.a;
1195 *b = params.b;
1196 *c = params.c;
1197 *d = params.d;
1198 *e = params.e;
1199 return true;
1200 }
1110 }; 1201 };
1111 1202
1112 // This class assumes that its template argument is a RefTuple (a Tuple with 1203 // This class assumes that its template argument is a RefTuple (a Tuple with
1113 // reference elements). 1204 // reference elements).
1114 template <class RefTuple> 1205 template <class RefTuple>
1115 class ParamDeserializer : public MessageReplyDeserializer { 1206 class ParamDeserializer : public MessageReplyDeserializer {
1116 public: 1207 public:
1117 explicit ParamDeserializer(const RefTuple& out) : out_(out) { } 1208 explicit ParamDeserializer(const RefTuple& out) : out_(out) { }
1118 1209
1119 bool SerializeOutputParameters(const IPC::Message& msg, void* iter) { 1210 bool SerializeOutputParameters(const IPC::Message& msg, void* iter) {
(...skipping 11 matching lines...) Expand all
1131 template <class SendParam, class ReplyParam> 1222 template <class SendParam, class ReplyParam>
1132 class MessageWithReply : public SyncMessage { 1223 class MessageWithReply : public SyncMessage {
1133 public: 1224 public:
1134 MessageWithReply(int32 routing_id, uint16 type, 1225 MessageWithReply(int32 routing_id, uint16 type,
1135 const SendParam& send, const ReplyParam& reply) 1226 const SendParam& send, const ReplyParam& reply)
1136 : SyncMessage(routing_id, type, PRIORITY_NORMAL, 1227 : SyncMessage(routing_id, type, PRIORITY_NORMAL,
1137 new ParamDeserializer<ReplyParam>(reply)) { 1228 new ParamDeserializer<ReplyParam>(reply)) {
1138 WriteParam(this, send); 1229 WriteParam(this, send);
1139 } 1230 }
1140 1231
1141 static void Log(const Message* msg, std::wstring* l) { 1232 static void Log(const IPC::Message* msg, std::wstring* l) {
1142 if (msg->is_sync()) { 1233 if (msg->is_sync()) {
1143 SendParam p; 1234 SendParam p;
1144 void* iter = SyncMessage::GetDataIterator(msg); 1235 void* iter = SyncMessage::GetDataIterator(msg);
1145 ReadParam(msg, &iter, &p); 1236 ReadParam(msg, &iter, &p);
1146 LogParam(p, l); 1237 LogParam(p, l);
1147 1238
1148 #if defined(IPC_MESSAGE_LOG_ENABLED) 1239 #if defined(IPC_MESSAGE_LOG_ENABLED)
1149 const std::wstring& output_params = msg->output_params(); 1240 const std::wstring& output_params = msg->output_params();
1150 if (!l->empty() && !output_params.empty()) 1241 if (!l->empty() && !output_params.empty())
1151 l->append(L", "); 1242 l->append(L", ");
1152 1243
1153 l->append(output_params); 1244 l->append(output_params);
1154 #endif 1245 #endif
1155 } else { 1246 } else {
1156 // This is an outgoing reply. Now that we have the output parameters, we 1247 // This is an outgoing reply. Now that we have the output parameters, we
1157 // can finally log the message. 1248 // can finally log the message.
1158 typename ReplyParam::ValueTuple p; 1249 typename ReplyParam::ValueTuple p;
1159 void* iter = SyncMessage::GetDataIterator(msg); 1250 void* iter = SyncMessage::GetDataIterator(msg);
1160 ReadParam(msg, &iter, &p); 1251 ReadParam(msg, &iter, &p);
1161 LogParam(p, l); 1252 LogParam(p, l);
1162 } 1253 }
1163 } 1254 }
1164 1255
1165 template<class T, class Method> 1256 template<class T, class Method>
1166 static bool Dispatch(const Message* msg, T* obj, Method func) { 1257 static bool Dispatch(const IPC::Message* msg, T* obj, Method func) {
1167 SendParam send_params; 1258 SendParam send_params;
1168 void* iter = GetDataIterator(msg); 1259 void* iter = GetDataIterator(msg);
1169 Message* reply = GenerateReply(msg); 1260 Message* reply = GenerateReply(msg);
1170 bool error; 1261 bool error;
1171 if (ReadParam(msg, &iter, &send_params)) { 1262 if (ReadParam(msg, &iter, &send_params)) {
1172 typename ReplyParam::ValueTuple reply_params; 1263 typename ReplyParam::ValueTuple reply_params;
1173 DispatchToMethod(obj, func, send_params, &reply_params); 1264 DispatchToMethod(obj, func, send_params, &reply_params);
1174 WriteParam(reply, reply_params); 1265 WriteParam(reply, reply_params);
1175 error = false; 1266 error = false;
1176 #ifdef IPC_MESSAGE_LOG_ENABLED 1267 #ifdef IPC_MESSAGE_LOG_ENABLED
1177 if (msg->received_time() != 0) { 1268 if (msg->received_time() != 0) {
1178 std::wstring output_params; 1269 std::wstring output_params;
1179 LogParam(reply_params, &output_params); 1270 LogParam(reply_params, &output_params);
1180 msg->set_output_params(output_params); 1271 msg->set_output_params(output_params);
1181 } 1272 }
1182 #endif 1273 #endif
1183 } else { 1274 } else {
1184 NOTREACHED() << "Error deserializing message " << msg->type(); 1275 NOTREACHED() << "Error deserializing message " << msg->type();
1185 reply->set_reply_error(); 1276 reply->set_reply_error();
1186 error = true; 1277 error = true;
1187 } 1278 }
1188 1279
1189 obj->Send(reply); 1280 obj->Send(reply);
1190 return !error; 1281 return !error;
1191 } 1282 }
1192 1283
1193 template<class T, class Method> 1284 template<class T, class Method>
1194 static bool DispatchDelayReply(const Message* msg, T* obj, Method func) { 1285 static bool DispatchDelayReply(const IPC::Message* msg, T* obj, Method func) {
1195 SendParam send_params; 1286 SendParam send_params;
1196 void* iter = GetDataIterator(msg); 1287 void* iter = GetDataIterator(msg);
1197 Message* reply = GenerateReply(msg); 1288 Message* reply = GenerateReply(msg);
1198 bool error; 1289 bool error;
1199 if (ReadParam(msg, &iter, &send_params)) { 1290 if (ReadParam(msg, &iter, &send_params)) {
1200 Tuple1<Message&> t = MakeRefTuple(*reply); 1291 Tuple1<Message&> t = MakeRefTuple(*reply);
1201 1292
1202 #ifdef IPC_MESSAGE_LOG_ENABLED 1293 #ifdef IPC_MESSAGE_LOG_ENABLED
1203 if (msg->sent_time()) { 1294 if (msg->sent_time()) {
1204 // Don't log the sync message after dispatch, as we don't have the 1295 // Don't log the sync message after dispatch, as we don't have the
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
1245 WriteParam(reply, p); 1336 WriteParam(reply, p);
1246 } 1337 }
1247 1338
1248 template<typename TA, typename TB, typename TC, typename TD, typename TE> 1339 template<typename TA, typename TB, typename TC, typename TD, typename TE>
1249 static void WriteReplyParams(Message* reply, TA a, TB b, TC c, TD d, TE e) { 1340 static void WriteReplyParams(Message* reply, TA a, TB b, TC c, TD d, TE e) {
1250 ReplyParam p(a, b, c, d, e); 1341 ReplyParam p(a, b, c, d, e);
1251 WriteParam(reply, p); 1342 WriteParam(reply, p);
1252 } 1343 }
1253 }; 1344 };
1254 1345
1255 // Traits for ViewMsg_FindInPageMsg_Request structure to pack/unpack.
1256 template <>
1257 struct ParamTraits<FindInPageRequest> {
1258 typedef FindInPageRequest param_type;
1259 static void Write(Message* m, const param_type& p) {
1260 WriteParam(m, p.request_id);
1261 WriteParam(m, p.search_string);
1262 WriteParam(m, p.forward);
1263 WriteParam(m, p.match_case);
1264 WriteParam(m, p.find_next);
1265 }
1266 static bool Read(const Message* m, void** iter, param_type* p) {
1267 return
1268 ReadParam(m, iter, &p->request_id) &&
1269 ReadParam(m, iter, &p->search_string) &&
1270 ReadParam(m, iter, &p->forward) &&
1271 ReadParam(m, iter, &p->match_case) &&
1272 ReadParam(m, iter, &p->find_next);
1273 }
1274 static void Log(const param_type& p, std::wstring* l) {
1275 l->append(L"<FindInPageRequest>");
1276 }
1277 };
1278
1279 //-----------------------------------------------------------------------------
1280
1281 } // namespace IPC 1346 } // namespace IPC
1282 1347
1283 #endif // CHROME_COMMON_IPC_MESSAGE_UTILS_H_ 1348 #endif // CHROME_COMMON_IPC_MESSAGE_UTILS_H_
1284 1349
OLDNEW
« no previous file with comments | « chrome/common/ipc_message_unittest.cc ('k') | chrome/common/ipc_message_utils.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698