1 // Copyright (c) 2011 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. 4 5 #include "content/common/message_router.h" 6 7 #include "ipc/ipc_message.h" 8 9 namespace content { 10 11 MessageRouter::MessageRouter() { 12 } 13 14 MessageRouter::~MessageRouter() { 15 } 16 17 bool MessageRouter::OnControlMessageReceived(const IPC::Message& msg) { 18 NOTREACHED() << 19 "should override in subclass if you care about control messages"; 20 return false; 21 } 22 23 bool MessageRouter::Send(IPC::Message* msg) { 24 NOTREACHED() << 25 "should override in subclass if you care about sending messages"; 26 return false; 27 } 28 29 bool MessageRouter::AddRoute(int32 routing_id, IPC::Listener* listener) { 30 if (routes_.Lookup(routing_id)) { 31 DLOG(ERROR) << "duplicate routing ID"; 32 return false; 33 } 34 routes_.AddWithID(listener, routing_id); 35 return true; 36 } 37 38 void MessageRouter::RemoveRoute(int32 routing_id) { 39 routes_.Remove(routing_id); 40 } 41 42 bool MessageRouter::OnMessageReceived(const IPC::Message& msg) { 43 if (msg.routing_id() == MSG_ROUTING_CONTROL) 44 return OnControlMessageReceived(msg); 45 46 return RouteMessage(msg); 47 } 48 49 bool MessageRouter::RouteMessage(const IPC::Message& msg) { 50 IPC::Listener* listener = routes_.Lookup(msg.routing_id()); 51 if (!listener) 52 return false; 53 54 listener->OnMessageReceived(msg); 55 return true; 56 } 57 58 } // namespace content 59