OLD | NEW |
---|---|
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 IPC_IPC_MESSAGE_UTILS_H_ | 5 #ifndef IPC_IPC_MESSAGE_UTILS_H_ |
6 #define IPC_IPC_MESSAGE_UTILS_H_ | 6 #define IPC_IPC_MESSAGE_UTILS_H_ |
7 | 7 |
8 #include <algorithm> | 8 #include <algorithm> |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
11 #include <map> | 11 #include <map> |
12 #include <set> | |
12 | 13 |
13 #include "base/file_path.h" | 14 #include "base/file_path.h" |
14 #include "base/format_macros.h" | 15 #include "base/format_macros.h" |
15 #include "base/nullable_string16.h" | 16 #include "base/nullable_string16.h" |
16 #include "base/string16.h" | 17 #include "base/string16.h" |
17 #include "base/string_util.h" | 18 #include "base/string_util.h" |
18 #include "base/utf_string_conversions.h" | 19 #include "base/utf_string_conversions.h" |
19 #include "base/time.h" | 20 #include "base/time.h" |
20 #include "base/tuple.h" | 21 #include "base/tuple.h" |
21 #include "base/values.h" | 22 #include "base/values.h" |
22 #if defined(OS_POSIX) | 23 #if defined(OS_POSIX) |
23 #include "ipc/file_descriptor_set_posix.h" | 24 #include "ipc/file_descriptor_set_posix.h" |
24 #endif | 25 #endif |
25 #include "ipc/ipc_channel_handle.h" | 26 #include "ipc/ipc_channel_handle.h" |
26 #include "ipc/ipc_sync_message.h" | 27 #include "ipc/ipc_sync_message.h" |
27 | 28 |
28 // Used by IPC_BEGIN_MESSAGES so that each message class starts from a unique | 29 // Used by IPC_BEGIN_MESSAGES so that each message class starts from a unique |
29 // base. Messages have unique IDs across channels in order for the IPC logging | 30 // base. Messages have unique IDs across channels in order for the IPC logging |
30 // code to figure out the message class from its ID. | 31 // code to figure out the message class from its ID. |
31 enum IPCMessageStart { | 32 enum IPCMessageStart { |
32 // By using a start value of 0 for automation messages, we keep backward | 33 // By using a start value of 0 for automation messages, we keep backward |
33 // compatibility with old builds. | 34 // compatibility with old builds. |
34 AutomationMsgStart = 0, | 35 AutomationMsgStart = 0, |
35 ViewMsgStart, | 36 ViewMsgStart, |
36 ViewHostMsgStart, | 37 ViewHostMsgStart, |
37 PluginProcessMsgStart, | 38 PluginProcessMsgStart, |
38 PluginProcessHostMsgStart, | 39 PluginProcessHostMsgStart, |
39 PluginMsgStart, | 40 PluginMsgStart, |
40 PluginHostMsgStart, | 41 PluginHostMsgStart, |
42 ProfileImportProcessMsgStart, | |
43 ProfileImportProcessHostMsgStart, | |
41 NPObjectMsgStart, | 44 NPObjectMsgStart, |
42 TestMsgStart, | 45 TestMsgStart, |
43 DevToolsAgentMsgStart, | 46 DevToolsAgentMsgStart, |
44 DevToolsClientMsgStart, | 47 DevToolsClientMsgStart, |
45 WorkerProcessMsgStart, | 48 WorkerProcessMsgStart, |
46 WorkerProcessHostMsgStart, | 49 WorkerProcessHostMsgStart, |
47 WorkerMsgStart, | 50 WorkerMsgStart, |
48 WorkerHostMsgStart, | 51 WorkerHostMsgStart, |
49 NaClProcessMsgStart, | 52 NaClProcessMsgStart, |
50 GpuCommandBufferMsgStart, | 53 GpuCommandBufferMsgStart, |
(...skipping 409 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
460 for (int i = 0; i < size; i++) { | 463 for (int i = 0; i < size; i++) { |
461 if (!ReadParam(m, iter, &(*r)[i])) | 464 if (!ReadParam(m, iter, &(*r)[i])) |
462 return false; | 465 return false; |
463 } | 466 } |
464 return true; | 467 return true; |
465 } | 468 } |
466 static void Log(const param_type& p, std::wstring* l) { | 469 static void Log(const param_type& p, std::wstring* l) { |
467 for (size_t i = 0; i < p.size(); ++i) { | 470 for (size_t i = 0; i < p.size(); ++i) { |
468 if (i != 0) | 471 if (i != 0) |
469 l->append(L" "); | 472 l->append(L" "); |
470 | |
471 LogParam((p[i]), l); | 473 LogParam((p[i]), l); |
472 } | 474 } |
473 } | 475 } |
474 }; | 476 }; |
475 | 477 |
478 template <class P> | |
479 struct ParamTraits<std::set<P> > { | |
480 typedef std::set<P> param_type; | |
481 static void Write(Message* m, const param_type& p) { | |
482 WriteParam(m, static_cast<int>(p.size())); | |
483 typename param_type::const_iterator iter; | |
484 for (iter = p.begin(); iter != p.end(); ++iter) | |
485 WriteParam(m, *iter); | |
486 } | |
487 static bool Read(const Message* m, void** iter, param_type* r) { | |
488 int size; | |
489 if (!m->ReadLength(iter, &size)) | |
490 return false; | |
491 for (int i = 0; i < size; ++i) { | |
492 P item; | |
493 if (!ReadParam(m, iter, &item)) | |
494 return false; | |
495 r->insert(item); | |
496 } | |
497 return true; | |
498 } | |
499 static void Log(const param_type& p, std::wstring* l) { | |
500 l->append(L"<std::set>"); | |
jeremy
2010/05/13 21:01:59
Should LogParam() all items in the set (see std::v
| |
501 } | |
502 }; | |
503 | |
504 | |
476 template <class K, class V> | 505 template <class K, class V> |
477 struct ParamTraits<std::map<K, V> > { | 506 struct ParamTraits<std::map<K, V> > { |
478 typedef std::map<K, V> param_type; | 507 typedef std::map<K, V> param_type; |
479 static void Write(Message* m, const param_type& p) { | 508 static void Write(Message* m, const param_type& p) { |
480 WriteParam(m, static_cast<int>(p.size())); | 509 WriteParam(m, static_cast<int>(p.size())); |
481 typename param_type::const_iterator iter; | 510 typename param_type::const_iterator iter; |
482 for (iter = p.begin(); iter != p.end(); ++iter) { | 511 for (iter = p.begin(); iter != p.end(); ++iter) { |
483 WriteParam(m, iter->first); | 512 WriteParam(m, iter->first); |
484 WriteParam(m, iter->second); | 513 WriteParam(m, iter->second); |
485 } | 514 } |
(...skipping 767 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1253 ReplyParam p(a, b, c, d, e); | 1282 ReplyParam p(a, b, c, d, e); |
1254 WriteParam(reply, p); | 1283 WriteParam(reply, p); |
1255 } | 1284 } |
1256 }; | 1285 }; |
1257 | 1286 |
1258 //----------------------------------------------------------------------------- | 1287 //----------------------------------------------------------------------------- |
1259 | 1288 |
1260 } // namespace IPC | 1289 } // namespace IPC |
1261 | 1290 |
1262 #endif // IPC_IPC_MESSAGE_UTILS_H_ | 1291 #endif // IPC_IPC_MESSAGE_UTILS_H_ |
OLD | NEW |