Skip to content

Commit

Permalink
Decouple IPC::MessageFilter from IPC::Channel
Browse files Browse the repository at this point in the history
This change gets rid of Channel dependency from MessageFilter
so that it depends only on IPC::Sender.

TEST=none
BUG=377980
R=jam@chromium.org, darin@chromium.org

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@276939 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
morrita@chromium.org committed Jun 13, 2014
1 parent 12a63da commit d1549b8
Show file tree
Hide file tree
Showing 51 changed files with 192 additions and 197 deletions.
12 changes: 6 additions & 6 deletions chrome/renderer/media/cast_ipc_dispatcher.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ CastIPCDispatcher* CastIPCDispatcher::global_instance_ = NULL;

CastIPCDispatcher::CastIPCDispatcher(
const scoped_refptr<base::MessageLoopProxy>& io_message_loop)
: channel_(NULL),
: sender_(NULL),
io_message_loop_(io_message_loop) {
DCHECK(io_message_loop_);
DCHECK(!global_instance_);
Expand All @@ -29,8 +29,8 @@ CastIPCDispatcher* CastIPCDispatcher::Get() {

void CastIPCDispatcher::Send(IPC::Message* message) {
DCHECK(io_message_loop_->BelongsToCurrentThread());
if (channel_) {
channel_->Send(message);
if (sender_) {
sender_->Send(message);
} else {
delete message;
}
Expand All @@ -56,18 +56,18 @@ bool CastIPCDispatcher::OnMessageReceived(const IPC::Message& message) {
return handled;
}

void CastIPCDispatcher::OnFilterAdded(IPC::Channel* channel) {
void CastIPCDispatcher::OnFilterAdded(IPC::Sender* sender) {
DCHECK(io_message_loop_->BelongsToCurrentThread());
DCHECK(!global_instance_);
global_instance_ = this;
channel_ = channel;
sender_ = sender;
}

void CastIPCDispatcher::OnFilterRemoved() {
DCHECK(io_message_loop_->BelongsToCurrentThread());
DCHECK_EQ(this, global_instance_);
global_instance_ = NULL;
channel_ = NULL;
sender_ = NULL;
}

void CastIPCDispatcher::OnChannelClosing() {
Expand Down
6 changes: 3 additions & 3 deletions chrome/renderer/media/cast_ipc_dispatcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class CastIPCDispatcher : public IPC::MessageFilter {

// IPC::MessageFilter implementation
virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
virtual void OnFilterAdded(IPC::Channel* channel) OVERRIDE;
virtual void OnFilterAdded(IPC::Sender* sender) OVERRIDE;
virtual void OnFilterRemoved() OVERRIDE;
virtual void OnChannelClosing() OVERRIDE;

Expand All @@ -52,8 +52,8 @@ class CastIPCDispatcher : public IPC::MessageFilter {

static CastIPCDispatcher* global_instance_;

// IPC channel for Send(); must only be accesed on |io_message_loop_|.
IPC::Channel* channel_;
// For IPC Send(); must only be accesed on |io_message_loop_|.
IPC::Sender* sender_;

// Message loop on which IPC calls are driven.
const scoped_refptr<base::MessageLoopProxy> io_message_loop_;
Expand Down
16 changes: 8 additions & 8 deletions chrome/renderer/media/webrtc_logging_message_filter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ WebRtcLoggingMessageFilter::WebRtcLoggingMessageFilter(
const scoped_refptr<base::MessageLoopProxy>& io_message_loop)
: io_message_loop_(io_message_loop),
log_message_delegate_(NULL),
channel_(NULL) {
sender_(NULL) {
// May be null in a browsertest using MockRenderThread.
if (io_message_loop_) {
io_message_loop_->PostTask(
Expand All @@ -39,20 +39,20 @@ bool WebRtcLoggingMessageFilter::OnMessageReceived(
return handled;
}

void WebRtcLoggingMessageFilter::OnFilterAdded(IPC::Channel* channel) {
void WebRtcLoggingMessageFilter::OnFilterAdded(IPC::Sender* sender) {
DCHECK(!io_message_loop_ || io_message_loop_->BelongsToCurrentThread());
channel_ = channel;
sender_ = sender;
}

void WebRtcLoggingMessageFilter::OnFilterRemoved() {
DCHECK(!io_message_loop_ || io_message_loop_->BelongsToCurrentThread());
channel_ = NULL;
sender_ = NULL;
log_message_delegate_->OnFilterRemoved();
}

void WebRtcLoggingMessageFilter::OnChannelClosing() {
DCHECK(!io_message_loop_ || io_message_loop_->BelongsToCurrentThread());
channel_ = NULL;
sender_ = NULL;
log_message_delegate_->OnFilterRemoved();
}

Expand Down Expand Up @@ -85,10 +85,10 @@ void WebRtcLoggingMessageFilter::OnStopLogging() {

void WebRtcLoggingMessageFilter::Send(IPC::Message* message) {
DCHECK(!io_message_loop_ || io_message_loop_->BelongsToCurrentThread());
if (!channel_) {
DLOG(ERROR) << "IPC channel not available.";
if (!sender_) {
DLOG(ERROR) << "IPC sender not available.";
delete message;
} else {
channel_->Send(message);
sender_->Send(message);
}
}
4 changes: 2 additions & 2 deletions chrome/renderer/media/webrtc_logging_message_filter.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class WebRtcLoggingMessageFilter : public IPC::MessageFilter {
private:
// IPC::MessageFilter implementation.
virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
virtual void OnFilterAdded(IPC::Channel* channel) OVERRIDE;
virtual void OnFilterAdded(IPC::Sender* sender) OVERRIDE;
virtual void OnFilterRemoved() OVERRIDE;
virtual void OnChannelClosing() OVERRIDE;

Expand All @@ -58,7 +58,7 @@ class WebRtcLoggingMessageFilter : public IPC::MessageFilter {
void OnStopLogging();
void Send(IPC::Message* message);

IPC::Channel* channel_;
IPC::Sender* sender_;

DISALLOW_COPY_AND_ASSIGN(WebRtcLoggingMessageFilter);
};
Expand Down
22 changes: 11 additions & 11 deletions components/nacl/renderer/pnacl_translation_resource_host.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,26 +21,26 @@ PnaclTranslationResourceHost::CacheRequestInfo::~CacheRequestInfo() {}

PnaclTranslationResourceHost::PnaclTranslationResourceHost(
const scoped_refptr<base::MessageLoopProxy>& io_message_loop)
: io_message_loop_(io_message_loop), channel_(NULL) {}
: io_message_loop_(io_message_loop), sender_(NULL) {}

PnaclTranslationResourceHost::~PnaclTranslationResourceHost() {
DCHECK(io_message_loop_->BelongsToCurrentThread());
CleanupCacheRequests();
}

void PnaclTranslationResourceHost::OnFilterAdded(IPC::Channel* channel) {
void PnaclTranslationResourceHost::OnFilterAdded(IPC::Sender* sender) {
DCHECK(io_message_loop_->BelongsToCurrentThread());
channel_ = channel;
sender_ = sender;
}

void PnaclTranslationResourceHost::OnFilterRemoved() {
DCHECK(io_message_loop_->BelongsToCurrentThread());
channel_ = NULL;
sender_ = NULL;
}

void PnaclTranslationResourceHost::OnChannelClosing() {
DCHECK(io_message_loop_->BelongsToCurrentThread());
channel_ = NULL;
sender_ = NULL;
}

bool PnaclTranslationResourceHost::OnMessageReceived(
Expand Down Expand Up @@ -84,8 +84,8 @@ void PnaclTranslationResourceHost::SendRequestNexeFd(
PP_FileHandle* file_handle,
scoped_refptr<TrackedCallback> callback) {
DCHECK(io_message_loop_->BelongsToCurrentThread());
if (!channel_ || !channel_->Send(new NaClHostMsg_NexeTempFileRequest(
render_view_id, instance, cache_info))) {
if (!sender_ || !sender_->Send(new NaClHostMsg_NexeTempFileRequest(
render_view_id, instance, cache_info))) {
PpapiGlobals::Get()->GetMainThreadMessageLoop()
->PostTask(FROM_HERE,
base::Bind(&TrackedCallback::Run,
Expand Down Expand Up @@ -115,13 +115,13 @@ void PnaclTranslationResourceHost::SendReportTranslationFinished(
PP_Instance instance,
PP_Bool success) {
DCHECK(io_message_loop_->BelongsToCurrentThread());
// If the channel is closed or we have been detached, we are probably shutting
// If the sender is closed or we have been detached, we are probably shutting
// down, so just don't send anything.
if (!channel_)
if (!sender_)
return;
DCHECK(pending_cache_requests_.count(instance) == 0);
channel_->Send(new NaClHostMsg_ReportTranslationFinished(instance,
PP_ToBool(success)));
sender_->Send(new NaClHostMsg_ReportTranslationFinished(instance,
PP_ToBool(success)));
}

void PnaclTranslationResourceHost::OnNexeTempFileReply(
Expand Down
4 changes: 2 additions & 2 deletions components/nacl/renderer/pnacl_translation_resource_host.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class PnaclTranslationResourceHost : public IPC::MessageFilter {
typedef std::map<PP_Instance, CacheRequestInfo> CacheRequestInfoMap;
// IPC::MessageFilter implementation.
virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
virtual void OnFilterAdded(IPC::Channel* channel) OVERRIDE;
virtual void OnFilterAdded(IPC::Sender* sender) OVERRIDE;
virtual void OnFilterRemoved() OVERRIDE;
virtual void OnChannelClosing() OVERRIDE;

Expand All @@ -76,7 +76,7 @@ class PnaclTranslationResourceHost : public IPC::MessageFilter {
scoped_refptr<base::MessageLoopProxy> io_message_loop_;

// Should be accessed on the io thread.
IPC::Channel* channel_;
IPC::Sender* sender_;
CacheRequestInfoMap pending_cache_requests_;
DISALLOW_COPY_AND_ASSIGN(PnaclTranslationResourceHost);
};
Expand Down
22 changes: 11 additions & 11 deletions components/tracing/child_trace_message_filter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@ namespace tracing {

ChildTraceMessageFilter::ChildTraceMessageFilter(
base::MessageLoopProxy* ipc_message_loop)
: channel_(NULL),
: sender_(NULL),
ipc_message_loop_(ipc_message_loop) {}

void ChildTraceMessageFilter::OnFilterAdded(IPC::Channel* channel) {
channel_ = channel;
channel_->Send(new TracingHostMsg_ChildSupportsTracing());
void ChildTraceMessageFilter::OnFilterAdded(IPC::Sender* sender) {
sender_ = sender;
sender_->Send(new TracingHostMsg_ChildSupportsTracing());
}

void ChildTraceMessageFilter::OnFilterRemoved() {
channel_ = NULL;
sender_ = NULL;
}

bool ChildTraceMessageFilter::OnMessageReceived(const IPC::Message& message) {
Expand Down Expand Up @@ -105,7 +105,7 @@ void ChildTraceMessageFilter::OnCaptureMonitoringSnapshot() {
void ChildTraceMessageFilter::OnGetTraceBufferPercentFull() {
float bpf = TraceLog::GetInstance()->GetBufferPercentFull();

channel_->Send(new TracingHostMsg_TraceBufferPercentFullReply(bpf));
sender_->Send(new TracingHostMsg_TraceBufferPercentFullReply(bpf));
}

void ChildTraceMessageFilter::OnSetWatchEvent(const std::string& category_name,
Expand All @@ -125,7 +125,7 @@ void ChildTraceMessageFilter::OnWatchEventMatched() {
base::Bind(&ChildTraceMessageFilter::OnWatchEventMatched, this));
return;
}
channel_->Send(new TracingHostMsg_WatchEventMatched);
sender_->Send(new TracingHostMsg_WatchEventMatched);
}

void ChildTraceMessageFilter::OnTraceDataCollected(
Expand All @@ -138,13 +138,13 @@ void ChildTraceMessageFilter::OnTraceDataCollected(
return;
}
if (events_str_ptr->data().size()) {
channel_->Send(new TracingHostMsg_TraceDataCollected(
sender_->Send(new TracingHostMsg_TraceDataCollected(
events_str_ptr->data()));
}
if (!has_more_events) {
std::vector<std::string> category_groups;
TraceLog::GetInstance()->GetKnownCategoryGroups(&category_groups);
channel_->Send(new TracingHostMsg_EndTracingAck(category_groups));
sender_->Send(new TracingHostMsg_EndTracingAck(category_groups));
}
}

Expand All @@ -160,11 +160,11 @@ void ChildTraceMessageFilter::OnMonitoringTraceDataCollected(
has_more_events));
return;
}
channel_->Send(new TracingHostMsg_MonitoringTraceDataCollected(
sender_->Send(new TracingHostMsg_MonitoringTraceDataCollected(
events_str_ptr->data()));

if (!has_more_events)
channel_->Send(new TracingHostMsg_CaptureMonitoringSnapshotAck());
sender_->Send(new TracingHostMsg_CaptureMonitoringSnapshotAck());
}

} // namespace tracing
4 changes: 2 additions & 2 deletions components/tracing/child_trace_message_filter.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class ChildTraceMessageFilter : public IPC::MessageFilter {
explicit ChildTraceMessageFilter(base::MessageLoopProxy* ipc_message_loop);

// IPC::MessageFilter implementation.
virtual void OnFilterAdded(IPC::Channel* channel) OVERRIDE;
virtual void OnFilterAdded(IPC::Sender* sender) OVERRIDE;
virtual void OnFilterRemoved() OVERRIDE;
virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;

Expand Down Expand Up @@ -54,7 +54,7 @@ class ChildTraceMessageFilter : public IPC::MessageFilter {
const scoped_refptr<base::RefCountedString>& events_str_ptr,
bool has_more_events);

IPC::Channel* channel_;
IPC::Sender* sender_;
base::MessageLoopProxy* ipc_message_loop_;

DISALLOW_COPY_AND_ASSIGN(ChildTraceMessageFilter);
Expand Down
2 changes: 1 addition & 1 deletion content/browser/dom_storage/dom_storage_message_filter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ void DOMStorageMessageFilter::UninitializeInSequence() {
host_.reset();
}

void DOMStorageMessageFilter::OnFilterAdded(IPC::Channel* channel) {
void DOMStorageMessageFilter::OnFilterAdded(IPC::Sender* sender) {
context_->task_runner()->PostShutdownBlockingTask(
FROM_HERE,
DOMStorageTaskRunner::PRIMARY_SEQUENCE,
Expand Down
2 changes: 1 addition & 1 deletion content/browser/dom_storage/dom_storage_message_filter.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class DOMStorageMessageFilter
void UninitializeInSequence();

// BrowserMessageFilter implementation
virtual void OnFilterAdded(IPC::Channel* channel) OVERRIDE;
virtual void OnFilterAdded(IPC::Sender* sender) OVERRIDE;
virtual void OnFilterRemoved() OVERRIDE;
virtual base::TaskRunner* OverrideTaskRunnerForMessage(
const IPC::Message& message) OVERRIDE;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ AudioInputRendererHost::~AudioInputRendererHost() {
}

void AudioInputRendererHost::OnChannelClosing() {
// Since the IPC channel is gone, close all requested audio streams.
// Since the IPC sender is gone, close all requested audio streams.
DeleteEntries();
}

Expand Down
2 changes: 1 addition & 1 deletion content/browser/renderer_host/media/audio_renderer_host.cc
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ void AudioRendererHost::GetOutputControllers(
}

void AudioRendererHost::OnChannelClosing() {
// Since the IPC channel is gone, close all requested audio streams.
// Since the IPC sender is gone, close all requested audio streams.
while (!audio_entries_.empty()) {
// Note: OnCloseStream() removes the entries from audio_entries_.
OnCloseStream(audio_entries_.begin()->first);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ bool MediaStreamDispatcherHost::OnMessageReceived(const IPC::Message& message) {
void MediaStreamDispatcherHost::OnChannelClosing() {
DVLOG(1) << "MediaStreamDispatcherHost::OnChannelClosing";

// Since the IPC channel is gone, close all requesting/requested streams.
// Since the IPC sender is gone, close all requesting/requested streams.
media_stream_manager_->CancelAllRequests(render_process_id_);
}

Expand Down
2 changes: 1 addition & 1 deletion content/browser/renderer_host/media/video_capture_host.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ VideoCaptureHost::VideoCaptureHost(MediaStreamManager* media_stream_manager)
VideoCaptureHost::~VideoCaptureHost() {}

void VideoCaptureHost::OnChannelClosing() {
// Since the IPC channel is gone, close all requested VideoCaptureDevices.
// Since the IPC sender is gone, close all requested VideoCaptureDevices.
for (EntryMap::iterator it = entries_.begin(); it != entries_.end(); ) {
const base::WeakPtr<VideoCaptureController>& controller = it->second;
if (controller) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ class VideoCaptureHostTest : public testing::Test {

CloseSession();

// Simulate closing the IPC channel.
// Simulate closing the IPC sender.
host_->OnChannelClosing();

// Release the reference to the mock object. The object will be destructed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ P2PSocketDispatcherHost::P2PSocketDispatcherHost(
}

void P2PSocketDispatcherHost::OnChannelClosing() {
// Since the IPC channel is gone, close pending connections.
// Since the IPC sender is gone, close pending connections.
STLDeleteContainerPairSecondPointers(sockets_.begin(), sockets_.end());
sockets_.clear();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ void ServiceWorkerDispatcherHost::Init(
render_process_id_, this);
}

void ServiceWorkerDispatcherHost::OnFilterAdded(IPC::Channel* channel) {
BrowserMessageFilter::OnFilterAdded(channel);
void ServiceWorkerDispatcherHost::OnFilterAdded(IPC::Sender* sender) {
BrowserMessageFilter::OnFilterAdded(sender);
channel_ready_ = true;
std::vector<IPC::Message*> messages;
pending_messages_.release(&messages);
Expand Down
Loading

0 comments on commit d1549b8

Please sign in to comment.