Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
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
3 // found in the LICENSE file.
5 #ifndef CHROME_COMMON_MESSAGE_ROUTER_H__
6 #define CHROME_COMMON_MESSAGE_ROUTER_H__
8 #include "base/id_map.h"
9 #include "chrome/common/ipc_channel.h"
11 // The MessageRouter handles all incoming messages sent to it by routing them
12 // to the correct listener. Routing is based on the Message's routing ID.
13 // Since routing IDs are typically assigned asynchronously by the browser
14 // process, the MessageRouter has the notion of pending IDs for listeners that
15 // have not yet been assigned a routing ID.
16 //
17 // When a message arrives, the routing ID is used to index the set of routes to
18 // find a listener. If a listener is found, then the message is passed to it.
19 // Otherwise, the message is ignored if its routing ID is not equal to
20 // MSG_ROUTING_CONTROL.
21 //
22 // The MessageRouter supports the IPC::Message::Sender interface for outgoing
23 // messages, but does not define a meaningful implementation of it. The
24 // subclass of MessageRouter is intended to provide that if appropriate.
25 //
26 // The MessageRouter can be used as a concrete class provided its Send method
27 // is not called and it does not receive any control messages.
29 class MessageRouter : public IPC::Channel::Listener,
30 public IPC::Message::Sender {
31 public:
32 MessageRouter() {}
33 virtual ~MessageRouter() {}
35 // Implemented by subclasses to handle control messages
36 virtual void OnControlMessageReceived(const IPC::Message& msg);
38 // IPC::Channel::Listener implementation:
39 virtual void OnMessageReceived(const IPC::Message& msg);
41 // Like OnMessageReceived, except it only handles routed messages. Returns
42 // true if the message was dispatched, or false if there was no listener for
43 // that route id.
44 virtual bool RouteMessage(const IPC::Message& msg);
46 // IPC::Message::Sender implementation:
47 virtual bool Send(IPC::Message* msg);
49 // Called to add/remove a listener for a particular message routing ID.
50 void AddRoute(int32_t routing_id, IPC::Channel::Listener* listener);
51 void RemoveRoute(int32_t routing_id);
53 private:
54 // A list of all listeners with assigned routing IDs.
55 IDMap<IPC::Channel::Listener> routes_;
57 DISALLOW_EVIL_CONSTRUCTORS(MessageRouter);
58 };
60 #endif // CHROME_COMMON_MESSAGE_ROUTER_H__