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

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/ipc/chromium/src/chrome/common/message_router.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,60 @@
     1.4 +// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
     1.5 +// Use of this source code is governed by a BSD-style license that can be
     1.6 +// found in the LICENSE file.
     1.7 +
     1.8 +#ifndef CHROME_COMMON_MESSAGE_ROUTER_H__
     1.9 +#define CHROME_COMMON_MESSAGE_ROUTER_H__
    1.10 +
    1.11 +#include "base/id_map.h"
    1.12 +#include "chrome/common/ipc_channel.h"
    1.13 +
    1.14 +// The MessageRouter handles all incoming messages sent to it by routing them
    1.15 +// to the correct listener.  Routing is based on the Message's routing ID.
    1.16 +// Since routing IDs are typically assigned asynchronously by the browser
    1.17 +// process, the MessageRouter has the notion of pending IDs for listeners that
    1.18 +// have not yet been assigned a routing ID.
    1.19 +//
    1.20 +// When a message arrives, the routing ID is used to index the set of routes to
    1.21 +// find a listener.  If a listener is found, then the message is passed to it.
    1.22 +// Otherwise, the message is ignored if its routing ID is not equal to
    1.23 +// MSG_ROUTING_CONTROL.
    1.24 +//
    1.25 +// The MessageRouter supports the IPC::Message::Sender interface for outgoing
    1.26 +// messages, but does not define a meaningful implementation of it.  The
    1.27 +// subclass of MessageRouter is intended to provide that if appropriate.
    1.28 +//
    1.29 +// The MessageRouter can be used as a concrete class provided its Send method
    1.30 +// is not called and it does not receive any control messages.
    1.31 +
    1.32 +class MessageRouter : public IPC::Channel::Listener,
    1.33 +                      public IPC::Message::Sender {
    1.34 + public:
    1.35 +  MessageRouter() {}
    1.36 +  virtual ~MessageRouter() {}
    1.37 +
    1.38 +  // Implemented by subclasses to handle control messages
    1.39 +  virtual void OnControlMessageReceived(const IPC::Message& msg);
    1.40 +
    1.41 +  // IPC::Channel::Listener implementation:
    1.42 +  virtual void OnMessageReceived(const IPC::Message& msg);
    1.43 +
    1.44 +  // Like OnMessageReceived, except it only handles routed messages.  Returns
    1.45 +  // true if the message was dispatched, or false if there was no listener for
    1.46 +  // that route id.
    1.47 +  virtual bool RouteMessage(const IPC::Message& msg);
    1.48 +
    1.49 +  // IPC::Message::Sender implementation:
    1.50 +  virtual bool Send(IPC::Message* msg);
    1.51 +
    1.52 +  // Called to add/remove a listener for a particular message routing ID.
    1.53 +  void AddRoute(int32_t routing_id, IPC::Channel::Listener* listener);
    1.54 +  void RemoveRoute(int32_t routing_id);
    1.55 +
    1.56 + private:
    1.57 +  // A list of all listeners with assigned routing IDs.
    1.58 +  IDMap<IPC::Channel::Listener> routes_;
    1.59 +
    1.60 +  DISALLOW_EVIL_CONSTRUCTORS(MessageRouter);
    1.61 +};
    1.62 +
    1.63 +#endif  // CHROME_COMMON_MESSAGE_ROUTER_H__

mercurial