OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CONTENT_COMMON_MESSAGE_ROUTER_H_ | 5 #ifndef CONTENT_COMMON_MESSAGE_ROUTER_H_ |
6 #define CONTENT_COMMON_MESSAGE_ROUTER_H_ | 6 #define CONTENT_COMMON_MESSAGE_ROUTER_H_ |
7 | 7 |
8 #include "base/id_map.h" | 8 #include "base/id_map.h" |
9 #include "ipc/ipc_listener.h" | 9 #include "ipc/ipc_listener.h" |
10 #include "ipc/ipc_sender.h" | 10 #include "ipc/ipc_sender.h" |
11 | 11 |
12 // The MessageRouter handles all incoming messages sent to it by routing them | 12 // The MessageRouter handles all incoming messages sent to it by routing them |
13 // to the correct listener. Routing is based on the Message's routing ID. | 13 // to the correct listener. Routing is based on the Message's routing ID. |
14 // Since routing IDs are typically assigned asynchronously by the browser | 14 // Since routing IDs are typically assigned asynchronously by the browser |
15 // process, the MessageRouter has the notion of pending IDs for listeners that | 15 // process, the MessageRouter has the notion of pending IDs for listeners that |
16 // have not yet been assigned a routing ID. | 16 // have not yet been assigned a routing ID. |
17 // | 17 // |
18 // When a message arrives, the routing ID is used to index the set of routes to | 18 // When a message arrives, the routing ID is used to index the set of routes to |
19 // find a listener. If a listener is found, then the message is passed to it. | 19 // find a listener. If a listener is found, then the message is passed to it. |
20 // Otherwise, the message is ignored if its routing ID is not equal to | 20 // Otherwise, the message is ignored if its routing ID is not equal to |
21 // MSG_ROUTING_CONTROL. | 21 // MSG_ROUTING_CONTROL. |
22 // | 22 // |
23 // The MessageRouter supports the IPC::Sender interface for outgoing messages, | 23 // The MessageRouter supports the IPC::Sender interface for outgoing messages, |
24 // but does not define a meaningful implementation of it. The subclass of | 24 // but does not define a meaningful implementation of it. The subclass of |
25 // MessageRouter is intended to provide that if appropriate. | 25 // MessageRouter is intended to provide that if appropriate. |
26 // | 26 // |
27 // The MessageRouter can be used as a concrete class provided its Send method | 27 // The MessageRouter can be used as a concrete class provided its Send method |
28 // is not called and it does not receive any control messages. | 28 // is not called and it does not receive any control messages. |
29 | 29 |
| 30 namespace content { |
| 31 |
30 class MessageRouter : public IPC::Listener, public IPC::Sender { | 32 class MessageRouter : public IPC::Listener, public IPC::Sender { |
31 public: | 33 public: |
32 MessageRouter(); | 34 MessageRouter(); |
33 virtual ~MessageRouter(); | 35 virtual ~MessageRouter(); |
34 | 36 |
35 // Implemented by subclasses to handle control messages | 37 // Implemented by subclasses to handle control messages |
36 virtual bool OnControlMessageReceived(const IPC::Message& msg); | 38 virtual bool OnControlMessageReceived(const IPC::Message& msg); |
37 | 39 |
38 // IPC::Listener implementation: | 40 // IPC::Listener implementation: |
39 virtual bool OnMessageReceived(const IPC::Message& msg) OVERRIDE; | 41 virtual bool OnMessageReceived(const IPC::Message& msg) OVERRIDE; |
(...skipping 12 matching lines...) Expand all Loading... |
52 | 54 |
53 IPC::Listener* ResolveRoute(int32 routing_id); | 55 IPC::Listener* ResolveRoute(int32 routing_id); |
54 | 56 |
55 private: | 57 private: |
56 // A list of all listeners with assigned routing IDs. | 58 // A list of all listeners with assigned routing IDs. |
57 IDMap<IPC::Listener> routes_; | 59 IDMap<IPC::Listener> routes_; |
58 | 60 |
59 DISALLOW_COPY_AND_ASSIGN(MessageRouter); | 61 DISALLOW_COPY_AND_ASSIGN(MessageRouter); |
60 }; | 62 }; |
61 | 63 |
| 64 } // namespace content |
| 65 |
62 #endif // CONTENT_COMMON_MESSAGE_ROUTER_H_ | 66 #endif // CONTENT_COMMON_MESSAGE_ROUTER_H_ |
OLD | NEW |