Skip to content

Commit

Permalink
Refactor content/common/message_router to ipc/message_router
Browse files Browse the repository at this point in the history
BUG=586366

Review URL: https://codereview.chromium.org/1710973002

Cr-Commit-Position: refs/heads/master@{#376326}
  • Loading branch information
mdittmer authored and Commit bot committed Feb 19, 2016
1 parent 3d6b5d3 commit 638a149
Show file tree
Hide file tree
Showing 17 changed files with 53 additions and 49 deletions.
2 changes: 1 addition & 1 deletion content/browser/gpu/gpu_process_host_ui_shim.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@
#include "base/threading/non_thread_safe.h"
#include "build/build_config.h"
#include "content/common/content_export.h"
#include "content/common/message_router.h"
#include "content/public/common/gpu_memory_stats.h"
#include "gpu/config/gpu_info.h"
#include "ipc/ipc_listener.h"
#include "ipc/ipc_sender.h"
#include "ipc/message_router.h"

#if defined(OS_MACOSX)
struct GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params;
Expand Down
4 changes: 2 additions & 2 deletions content/child/child_thread_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ bool ChildThreadImpl::ChildThreadMessageRouter::Send(IPC::Message* msg) {

bool ChildThreadImpl::ChildThreadMessageRouter::RouteMessage(
const IPC::Message& msg) {
bool handled = MessageRouter::RouteMessage(msg);
bool handled = IPC::MessageRouter::RouteMessage(msg);
#if defined(OS_ANDROID)
if (!handled && msg.is_sync()) {
IPC::Message* reply = IPC::SyncMessage::GenerateReply(&msg);
Expand Down Expand Up @@ -551,7 +551,7 @@ void ChildThreadImpl::ReleaseCachedFonts() {
}
#endif

MessageRouter* ChildThreadImpl::GetRouter() {
IPC::MessageRouter* ChildThreadImpl::GetRouter() {
DCHECK(base::MessageLoop::current() == message_loop());
return &router_;
}
Expand Down
6 changes: 3 additions & 3 deletions content/child/child_thread_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@
#include "build/build_config.h"
#include "content/child/mojo/mojo_application.h"
#include "content/common/content_export.h"
#include "content/common/message_router.h"
#include "content/common/mojo/channel_init.h"
#include "content/public/child/child_thread.h"
#include "ipc/ipc_message.h" // For IPC_MESSAGE_LOG_ENABLED.
#include "ipc/ipc_platform_file.h"
#include "ipc/message_router.h"

namespace base {
class MessageLoop;
Expand Down Expand Up @@ -92,7 +92,7 @@ class CONTENT_EXPORT ChildThreadImpl

IPC::SyncChannel* channel() { return channel_.get(); }

MessageRouter* GetRouter();
IPC::MessageRouter* GetRouter();

// Allocates a block of shared memory of the given size. Returns NULL on
// failure.
Expand Down Expand Up @@ -203,7 +203,7 @@ class CONTENT_EXPORT ChildThreadImpl
scoped_refptr<base::SequencedTaskRunner> GetIOTaskRunner();

private:
class ChildThreadMessageRouter : public MessageRouter {
class ChildThreadMessageRouter : public IPC::MessageRouter {
public:
// |sender| must outlive this object.
explicit ChildThreadMessageRouter(IPC::Sender* sender);
Expand Down
4 changes: 2 additions & 2 deletions content/child/npapi/np_channel_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
#include "base/memory/scoped_ptr.h"
#include "base/process/process.h"
#include "content/child/npapi/npobject_base.h"
#include "content/common/message_router.h"
#include "ipc/ipc_channel_handle.h"
#include "ipc/ipc_sync_channel.h"
#include "ipc/message_router.h"

namespace base {
class SingleThreadTaskRunner;
Expand Down Expand Up @@ -170,7 +170,7 @@ class NPChannelBase : public IPC::Listener,

// Used to implement message routing functionality to WebPlugin[Delegate]
// objects
MessageRouter router_;
IPC::MessageRouter router_;

// A channel is invalid if it is disconnected as a result of a channel
// error. This flag is used to indicate the same.
Expand Down
2 changes: 1 addition & 1 deletion content/common/gpu/client/gpu_channel_host.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@
#include "content/common/content_export.h"
#include "content/common/gpu/gpu_process_launch_causes.h"
#include "content/common/gpu/gpu_stream_priority.h"
#include "content/common/message_router.h"
#include "gpu/config/gpu_info.h"
#include "ipc/ipc_channel_handle.h"
#include "ipc/ipc_sync_channel.h"
#include "ipc/message_filter.h"
#include "ipc/message_router.h"
#include "media/video/jpeg_decode_accelerator.h"
#include "ui/events/latency_info.h"
#include "ui/gfx/geometry/size.h"
Expand Down
4 changes: 2 additions & 2 deletions content/common/gpu/gpu_channel.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
#include "content/common/gpu/gpu_command_buffer_stub.h"
#include "content/common/gpu/gpu_memory_manager.h"
#include "content/common/gpu/gpu_stream_priority.h"
#include "content/common/message_router.h"
#include "gpu/command_buffer/service/valuebuffer_manager.h"
#include "ipc/ipc_sync_channel.h"
#include "ipc/message_router.h"
#include "ui/gfx/geometry/size.h"
#include "ui/gfx/native_widget_types.h"
#include "ui/gl/gl_share_group.h"
Expand Down Expand Up @@ -254,7 +254,7 @@ class CONTENT_EXPORT GpuChannel
std::string channel_id_;

// Used to implement message routing functionality to CommandBuffer objects
MessageRouter router_;
IPC::MessageRouter router_;

// Whether the processing of IPCs on this channel is stalled and we should
// preempt other GpuChannels.
Expand Down
2 changes: 1 addition & 1 deletion content/common/gpu/gpu_channel_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
#include "content/common/gpu/gpu_memory_buffer_factory.h"
#include "content/common/gpu/gpu_memory_manager.h"
#include "content/common/gpu/gpu_messages.h"
#include "content/common/message_router.h"
#include "content/public/common/content_switches.h"
#include "gpu/command_buffer/common/value_state.h"
#include "gpu/command_buffer/service/feature_info.h"
Expand All @@ -27,6 +26,7 @@
#include "gpu/command_buffer/service/shader_translator_cache.h"
#include "gpu/command_buffer/service/sync_point_manager.h"
#include "ipc/message_filter.h"
#include "ipc/message_router.h"
#include "ui/gl/gl_bindings.h"
#include "ui/gl/gl_share_group.h"

Expand Down
4 changes: 2 additions & 2 deletions content/common/gpu/gpu_channel_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
#include "content/common/content_export.h"
#include "content/common/content_param_traits.h"
#include "content/common/gpu/gpu_memory_manager.h"
#include "content/common/message_router.h"
#include "ipc/ipc_listener.h"
#include "ipc/ipc_sender.h"
#include "ipc/message_router.h"
#include "ui/gfx/gpu_memory_buffer.h"
#include "ui/gfx/native_widget_types.h"
#include "ui/gl/gl_surface.h"
Expand Down Expand Up @@ -173,7 +173,7 @@ class CONTENT_EXPORT GpuChannelManager : public IPC::Listener,

// Used to send and receive IPC messages from the browser process.
IPC::SyncChannel* const channel_;
MessageRouter router_;
IPC::MessageRouter router_;

GpuWatchdog* watchdog_;

Expand Down
1 change: 1 addition & 0 deletions content/content_child.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
'../components/mime_util/mime_util.gyp:mime_util',
'../components/tracing.gyp:tracing',
'../components/webcrypto/webcrypto.gyp:webcrypto',
'../ipc/ipc.gyp:ipc',
'../mojo/mojo_base.gyp:mojo_environment_chromium',
'../mojo/mojo_base.gyp:mojo_common_lib',
'../mojo/mojo_base.gyp:mojo_message_pump_lib',
Expand Down
3 changes: 1 addition & 2 deletions content/content_common.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
'../base/base.gyp:base',
'../components/tracing.gyp:tracing',
'../gpu/command_buffer/command_buffer.gyp:gles2_utils',
'../ipc/ipc.gyp:ipc',
'../net/net.gyp:net',
'../skia/skia.gyp:skia',
'../third_party/WebKit/public/blink_headers.gyp:blink_headers',
Expand Down Expand Up @@ -451,8 +452,6 @@
'common/media/webrtc_identity_messages.h',
'common/memory_messages.h',
'common/message_port_messages.h',
'common/message_router.cc',
'common/message_router.h',
'common/mime_registry_messages.h',
'common/mojo/channel_init.cc',
'common/mojo/channel_init.h',
Expand Down
1 change: 1 addition & 0 deletions content/content_renderer.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
'../device/vibration/vibration.gyp:device_vibration_mojo_bindings',
'../gin/gin.gyp:gin',
'../gpu/gpu.gyp:gpu',
'../ipc/ipc.gyp:ipc',
'../jingle/jingle.gyp:jingle_glue',
'../media/blink/media_blink.gyp:media_blink',
'../media/media.gyp:media',
Expand Down
4 changes: 2 additions & 2 deletions content/renderer/websharedworker_proxy.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@
#include <stddef.h>

#include "content/child/webmessageportchannel_impl.h"
#include "content/common/message_router.h"
#include "content/common/view_messages.h"
#include "content/common/worker_messages.h"
#include "ipc/message_router.h"
#include "third_party/WebKit/public/platform/WebURL.h"
#include "third_party/WebKit/public/web/WebSharedWorkerClient.h"

namespace content {

WebSharedWorkerProxy::WebSharedWorkerProxy(MessageRouter* router,
WebSharedWorkerProxy::WebSharedWorkerProxy(IPC::MessageRouter* router,
int route_id)
: route_id_(route_id),
router_(router),
Expand Down
11 changes: 6 additions & 5 deletions content/renderer/websharedworker_proxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@
#include "third_party/WebKit/public/web/WebSharedWorkerConnector.h"
#include "url/gurl.h"

namespace content {

namespace IPC {
class MessageRouter;
}

namespace content {

// Implementation of the WebSharedWorker APIs. This object is intended to only
// live long enough to allow the caller to send a "connect" event to the worker
Expand All @@ -27,8 +29,7 @@ class WebSharedWorkerProxy : public blink::WebSharedWorkerConnector,
private IPC::Listener {
public:
// If the worker not loaded yet, route_id == MSG_ROUTING_NONE
WebSharedWorkerProxy(MessageRouter* router,
int route_id);
WebSharedWorkerProxy(IPC::MessageRouter* router, int route_id);
~WebSharedWorkerProxy() override;

// Implementations of WebSharedWorkerConnector APIs
Expand Down Expand Up @@ -62,7 +63,7 @@ class WebSharedWorkerProxy : public blink::WebSharedWorkerConnector,
// routing ids).
int route_id_;

MessageRouter* const router_;
IPC::MessageRouter* const router_;

// Stores messages that were sent before the StartWorkerContext message.
std::vector<IPC::Message*> queued_messages_;
Expand Down
2 changes: 2 additions & 0 deletions ipc/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ component("ipc") {
"message_filter.h",
"message_filter_router.cc",
"message_filter_router.h",
"message_router.cc",
"message_router.h",
"param_traits_log_macros.h",
"param_traits_macros.h",
"param_traits_read_macros.h",
Expand Down
2 changes: 2 additions & 0 deletions ipc/ipc.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@
'message_filter.h',
'message_filter_router.cc',
'message_filter_router.h',
'message_router.cc',
'message_router.h',
'param_traits_log_macros.h',
'param_traits_macros.h',
'param_traits_read_macros.h',
Expand Down
20 changes: 9 additions & 11 deletions content/common/message_router.cc → ipc/message_router.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,25 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "content/common/message_router.h"
#include "ipc/message_router.h"

#include "ipc/ipc_message.h"

namespace content {
namespace IPC {

MessageRouter::MessageRouter() {
}
MessageRouter::MessageRouter() {}

MessageRouter::~MessageRouter() {
}
MessageRouter::~MessageRouter() {}

bool MessageRouter::OnControlMessageReceived(const IPC::Message& msg) {
NOTREACHED() <<
"should override in subclass if you care about control messages";
NOTREACHED()
<< "should override in subclass if you care about control messages";
return false;
}

bool MessageRouter::Send(IPC::Message* msg) {
NOTREACHED() <<
"should override in subclass if you care about sending messages";
NOTREACHED()
<< "should override in subclass if you care about sending messages";
return false;
}

Expand Down Expand Up @@ -54,4 +52,4 @@ bool MessageRouter::RouteMessage(const IPC::Message& msg) {
return listener->OnMessageReceived(msg);
}

} // namespace content
} // namespace IPC
30 changes: 15 additions & 15 deletions content/common/message_router.h → ipc/message_router.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CONTENT_COMMON_MESSAGE_ROUTER_H_
#define CONTENT_COMMON_MESSAGE_ROUTER_H_
#ifndef IPC_MESSAGE_ROUTER_H_
#define IPC_MESSAGE_ROUTER_H_

#include <stdint.h>

#include "base/id_map.h"
#include "base/macros.h"
#include "content/common/content_export.h"
#include "ipc/ipc_export.h"
#include "ipc/ipc_listener.h"
#include "ipc/ipc_sender.h"

Expand All @@ -31,41 +31,41 @@
// The MessageRouter can be used as a concrete class provided its Send method
// is not called and it does not receive any control messages.

namespace content {
namespace IPC {

class CONTENT_EXPORT MessageRouter : public IPC::Listener, public IPC::Sender {
class IPC_EXPORT MessageRouter : public Listener, public Sender {
public:
MessageRouter();
~MessageRouter() override;

// Implemented by subclasses to handle control messages
virtual bool OnControlMessageReceived(const IPC::Message& msg);
virtual bool OnControlMessageReceived(const Message& msg);

// IPC::Listener implementation:
bool OnMessageReceived(const IPC::Message& msg) override;
// Listener implementation:
bool OnMessageReceived(const Message& msg) override;

// 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);
virtual bool RouteMessage(const Message& msg);

// IPC::Sender implementation:
bool Send(IPC::Message* msg) override;
// Sender implementation:
bool Send(Message* msg) override;

// Called to add a listener for a particular message routing ID.
// Returns true if succeeded.
bool AddRoute(int32_t routing_id, IPC::Listener* listener);
bool AddRoute(int32_t routing_id, Listener* listener);

// Called to remove a listener for a particular message routing ID.
void RemoveRoute(int32_t routing_id);

private:
// A list of all listeners with assigned routing IDs.
IDMap<IPC::Listener> routes_;
IDMap<Listener> routes_;

DISALLOW_COPY_AND_ASSIGN(MessageRouter);
};

} // namespace content
} // namespace IPC

#endif // CONTENT_COMMON_MESSAGE_ROUTER_H_
#endif // IPC_MESSAGE_ROUTER_H_

0 comments on commit 638a149

Please sign in to comment.