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