blob: 48616d24b686c5460ccd026c9a83263c7a14fd66 [file] [log] [blame]
Avi Drissmanea1be232022-09-14 23:29:061// Copyright 2011 The Chromium Authors
license.botbf09a502008-08-24 00:55:552// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
initial.commit09911bf2008-07-26 23:55:294
markdittmer638a1492016-02-19 01:11:505#include "ipc/message_router.h"
initial.commit09911bf2008-07-26 23:55:296
Hans Wennborg24397592020-06-17 16:58:507#include "base/logging.h"
[email protected]d84effeb2012-06-25 17:03:108#include "ipc/ipc_message.h"
9
markdittmer638a1492016-02-19 01:11:5010namespace IPC {
[email protected]130757672012-10-24 00:26:1911
Chris Watkins2d879af2017-11-30 02:11:5912MessageRouter::MessageRouter() = default;
[email protected]d4799a32010-09-28 22:54:5813
Chris Watkins2d879af2017-11-30 02:11:5914MessageRouter::~MessageRouter() = default;
[email protected]d4799a32010-09-28 22:54:5815
[email protected]a95986a82010-12-24 06:19:2816bool MessageRouter::OnControlMessageReceived(const IPC::Message& msg) {
Peter Boströmb7e3e08242024-09-24 22:38:1017 NOTREACHED()
markdittmer638a1492016-02-19 01:11:5018 << "should override in subclass if you care about control messages";
initial.commit09911bf2008-07-26 23:55:2919}
20
21bool MessageRouter::Send(IPC::Message* msg) {
Peter Boströmb7e3e08242024-09-24 22:38:1022 NOTREACHED()
markdittmer638a1492016-02-19 01:11:5023 << "should override in subclass if you care about sending messages";
initial.commit09911bf2008-07-26 23:55:2924}
25
avia9aa7a82015-12-25 03:06:3126bool MessageRouter::AddRoute(int32_t routing_id, IPC::Listener* listener) {
[email protected]0d78ec0e2014-04-08 23:35:2327 if (routes_.Lookup(routing_id)) {
28 DLOG(ERROR) << "duplicate routing ID";
29 return false;
30 }
initial.commit09911bf2008-07-26 23:55:2931 routes_.AddWithID(listener, routing_id);
[email protected]0d78ec0e2014-04-08 23:35:2332 return true;
initial.commit09911bf2008-07-26 23:55:2933}
34
avia9aa7a82015-12-25 03:06:3135void MessageRouter::RemoveRoute(int32_t routing_id) {
initial.commit09911bf2008-07-26 23:55:2936 routes_.Remove(routing_id);
37}
38
rockotf62002a2016-09-15 00:08:5939Listener* MessageRouter::GetRoute(int32_t routing_id) {
40 return routes_.Lookup(routing_id);
41}
42
[email protected]a95986a82010-12-24 06:19:2843bool MessageRouter::OnMessageReceived(const IPC::Message& msg) {
44 if (msg.routing_id() == MSG_ROUTING_CONTROL)
45 return OnControlMessageReceived(msg);
46
47 return RouteMessage(msg);
initial.commit09911bf2008-07-26 23:55:2948}
49
50bool MessageRouter::RouteMessage(const IPC::Message& msg) {
[email protected]bae061f72013-04-26 16:22:2951 IPC::Listener* listener = routes_.Lookup(msg.routing_id());
initial.commit09911bf2008-07-26 23:55:2952 if (!listener)
53 return false;
54
boliu60df2072015-10-26 22:55:1955 return listener->OnMessageReceived(msg);
initial.commit09911bf2008-07-26 23:55:2956}
[email protected]c1f50aa2010-02-18 03:46:5757
markdittmer638a1492016-02-19 01:11:5058} // namespace IPC