ipc/chromium/src/chrome/common/message_router.h

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
michael@0 2 // Use of this source code is governed by a BSD-style license that can be
michael@0 3 // found in the LICENSE file.
michael@0 4
michael@0 5 #ifndef CHROME_COMMON_MESSAGE_ROUTER_H__
michael@0 6 #define CHROME_COMMON_MESSAGE_ROUTER_H__
michael@0 7
michael@0 8 #include "base/id_map.h"
michael@0 9 #include "chrome/common/ipc_channel.h"
michael@0 10
michael@0 11 // The MessageRouter handles all incoming messages sent to it by routing them
michael@0 12 // to the correct listener. Routing is based on the Message's routing ID.
michael@0 13 // Since routing IDs are typically assigned asynchronously by the browser
michael@0 14 // process, the MessageRouter has the notion of pending IDs for listeners that
michael@0 15 // have not yet been assigned a routing ID.
michael@0 16 //
michael@0 17 // When a message arrives, the routing ID is used to index the set of routes to
michael@0 18 // find a listener. If a listener is found, then the message is passed to it.
michael@0 19 // Otherwise, the message is ignored if its routing ID is not equal to
michael@0 20 // MSG_ROUTING_CONTROL.
michael@0 21 //
michael@0 22 // The MessageRouter supports the IPC::Message::Sender interface for outgoing
michael@0 23 // messages, but does not define a meaningful implementation of it. The
michael@0 24 // subclass of MessageRouter is intended to provide that if appropriate.
michael@0 25 //
michael@0 26 // The MessageRouter can be used as a concrete class provided its Send method
michael@0 27 // is not called and it does not receive any control messages.
michael@0 28
michael@0 29 class MessageRouter : public IPC::Channel::Listener,
michael@0 30 public IPC::Message::Sender {
michael@0 31 public:
michael@0 32 MessageRouter() {}
michael@0 33 virtual ~MessageRouter() {}
michael@0 34
michael@0 35 // Implemented by subclasses to handle control messages
michael@0 36 virtual void OnControlMessageReceived(const IPC::Message& msg);
michael@0 37
michael@0 38 // IPC::Channel::Listener implementation:
michael@0 39 virtual void OnMessageReceived(const IPC::Message& msg);
michael@0 40
michael@0 41 // Like OnMessageReceived, except it only handles routed messages. Returns
michael@0 42 // true if the message was dispatched, or false if there was no listener for
michael@0 43 // that route id.
michael@0 44 virtual bool RouteMessage(const IPC::Message& msg);
michael@0 45
michael@0 46 // IPC::Message::Sender implementation:
michael@0 47 virtual bool Send(IPC::Message* msg);
michael@0 48
michael@0 49 // Called to add/remove a listener for a particular message routing ID.
michael@0 50 void AddRoute(int32_t routing_id, IPC::Channel::Listener* listener);
michael@0 51 void RemoveRoute(int32_t routing_id);
michael@0 52
michael@0 53 private:
michael@0 54 // A list of all listeners with assigned routing IDs.
michael@0 55 IDMap<IPC::Channel::Listener> routes_;
michael@0 56
michael@0 57 DISALLOW_EVIL_CONSTRUCTORS(MessageRouter);
michael@0 58 };
michael@0 59
michael@0 60 #endif // CHROME_COMMON_MESSAGE_ROUTER_H__

mercurial