mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-14 13:55:43 +00:00
Bug 1253123 - Remove message_router (r=jld)
This commit is contained in:
parent
6dd58aa726
commit
5ef16752e3
@ -35,7 +35,6 @@ UNIFIED_SOURCES += [
|
||||
'src/chrome/common/chrome_switches.cc',
|
||||
'src/chrome/common/ipc_channel.cc',
|
||||
'src/chrome/common/ipc_message.cc',
|
||||
'src/chrome/common/message_router.cc',
|
||||
'src/chrome/common/notification_service.cc',
|
||||
]
|
||||
|
||||
|
@ -62,23 +62,9 @@ bool ChildThread::Send(IPC::Message* msg) {
|
||||
return channel_->Send(msg);
|
||||
}
|
||||
|
||||
void ChildThread::AddRoute(int32_t routing_id, IPC::Channel::Listener* listener) {
|
||||
DCHECK(MessageLoop::current() == message_loop());
|
||||
|
||||
router_.AddRoute(routing_id, listener);
|
||||
}
|
||||
|
||||
void ChildThread::RemoveRoute(int32_t routing_id) {
|
||||
DCHECK(MessageLoop::current() == message_loop());
|
||||
|
||||
router_.RemoveRoute(routing_id);
|
||||
}
|
||||
|
||||
void ChildThread::OnMessageReceived(const IPC::Message& msg) {
|
||||
if (msg.routing_id() == MSG_ROUTING_CONTROL) {
|
||||
OnControlMessageReceived(msg);
|
||||
} else {
|
||||
router_.OnMessageReceived(msg);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -6,7 +6,7 @@
|
||||
#define CHROME_COMMON_CHILD_THREAD_H_
|
||||
|
||||
#include "base/thread.h"
|
||||
#include "chrome/common/message_router.h"
|
||||
#include "chrome/common/ipc_channel.h"
|
||||
#include "mozilla/UniquePtr.h"
|
||||
|
||||
class ResourceDispatcher;
|
||||
@ -71,10 +71,6 @@ class ChildThread : public IPC::Channel::Listener,
|
||||
std::wstring channel_name_;
|
||||
mozilla::UniquePtr<IPC::Channel> channel_;
|
||||
|
||||
// Used only on the background render thread to implement message routing
|
||||
// functionality to the consumers of the ChildThread.
|
||||
MessageRouter router_;
|
||||
|
||||
Thread::Options options_;
|
||||
|
||||
// If true, checks with the browser process before shutdown. This avoids race
|
||||
|
@ -1,42 +0,0 @@
|
||||
// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include "chrome/common/message_router.h"
|
||||
|
||||
void MessageRouter::OnControlMessageReceived(const IPC::Message& msg) {
|
||||
NOTREACHED() <<
|
||||
"should override in subclass if you care about control messages";
|
||||
}
|
||||
|
||||
bool MessageRouter::Send(IPC::Message* msg) {
|
||||
NOTREACHED() <<
|
||||
"should override in subclass if you care about sending messages";
|
||||
return false;
|
||||
}
|
||||
|
||||
void MessageRouter::AddRoute(int32_t routing_id,
|
||||
IPC::Channel::Listener* listener) {
|
||||
routes_.AddWithID(listener, routing_id);
|
||||
}
|
||||
|
||||
void MessageRouter::RemoveRoute(int32_t routing_id) {
|
||||
routes_.Remove(routing_id);
|
||||
}
|
||||
|
||||
void MessageRouter::OnMessageReceived(const IPC::Message& msg) {
|
||||
if (msg.routing_id() == MSG_ROUTING_CONTROL) {
|
||||
OnControlMessageReceived(msg);
|
||||
} else {
|
||||
RouteMessage(msg);
|
||||
}
|
||||
}
|
||||
|
||||
bool MessageRouter::RouteMessage(const IPC::Message& msg) {
|
||||
IPC::Channel::Listener* listener = routes_.Lookup(msg.routing_id());
|
||||
if (!listener)
|
||||
return false;
|
||||
|
||||
listener->OnMessageReceived(msg);
|
||||
return true;
|
||||
}
|
@ -1,60 +0,0 @@
|
||||
// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#ifndef CHROME_COMMON_MESSAGE_ROUTER_H__
|
||||
#define CHROME_COMMON_MESSAGE_ROUTER_H__
|
||||
|
||||
#include "base/id_map.h"
|
||||
#include "chrome/common/ipc_channel.h"
|
||||
|
||||
// The MessageRouter handles all incoming messages sent to it by routing them
|
||||
// to the correct listener. Routing is based on the Message's routing ID.
|
||||
// Since routing IDs are typically assigned asynchronously by the browser
|
||||
// process, the MessageRouter has the notion of pending IDs for listeners that
|
||||
// have not yet been assigned a routing ID.
|
||||
//
|
||||
// When a message arrives, the routing ID is used to index the set of routes to
|
||||
// find a listener. If a listener is found, then the message is passed to it.
|
||||
// Otherwise, the message is ignored if its routing ID is not equal to
|
||||
// MSG_ROUTING_CONTROL.
|
||||
//
|
||||
// The MessageRouter supports the IPC::Message::Sender interface for outgoing
|
||||
// messages, but does not define a meaningful implementation of it. The
|
||||
// subclass of MessageRouter is intended to provide that if appropriate.
|
||||
//
|
||||
// The MessageRouter can be used as a concrete class provided its Send method
|
||||
// is not called and it does not receive any control messages.
|
||||
|
||||
class MessageRouter : public IPC::Channel::Listener,
|
||||
public IPC::Message::Sender {
|
||||
public:
|
||||
MessageRouter() {}
|
||||
virtual ~MessageRouter() {}
|
||||
|
||||
// Implemented by subclasses to handle control messages
|
||||
virtual void OnControlMessageReceived(const IPC::Message& msg);
|
||||
|
||||
// IPC::Channel::Listener implementation:
|
||||
virtual void OnMessageReceived(const IPC::Message& msg);
|
||||
|
||||
// Like OnMessageReceived, except it only handles routed messages. Returns
|
||||
// true if the message was dispatched, or false if there was no listener for
|
||||
// that route id.
|
||||
virtual bool RouteMessage(const IPC::Message& msg);
|
||||
|
||||
// IPC::Message::Sender implementation:
|
||||
virtual bool Send(IPC::Message* msg);
|
||||
|
||||
// Called to add/remove a listener for a particular message routing ID.
|
||||
void AddRoute(int32_t routing_id, IPC::Channel::Listener* listener);
|
||||
void RemoveRoute(int32_t routing_id);
|
||||
|
||||
private:
|
||||
// A list of all listeners with assigned routing IDs.
|
||||
IDMap<IPC::Channel::Listener> routes_;
|
||||
|
||||
DISALLOW_EVIL_CONSTRUCTORS(MessageRouter);
|
||||
};
|
||||
|
||||
#endif // CHROME_COMMON_MESSAGE_ROUTER_H__
|
Loading…
Reference in New Issue
Block a user