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