1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "content/child/child_message_filter.h"
8 #include "base/bind_helpers.h"
9 #include "base/location.h"
10 #include "base/task_runner.h"
11 #include "content/child/child_thread.h"
12 #include "content/child/thread_safe_sender.h"
16 class ChildMessageFilter::Internal
: public IPC::ChannelProxy::MessageFilter
{
18 explicit Internal(ChildMessageFilter
* filter
) : filter_(filter
) {}
20 virtual bool OnMessageReceived(const IPC::Message
& msg
) OVERRIDE
{
21 scoped_refptr
<base::TaskRunner
> runner
=
22 filter_
->OverrideTaskRunnerForMessage(msg
);
23 if (runner
&& !runner
->RunsTasksOnCurrentThread()) {
24 if (!runner
->PostTask(
27 base::IgnoreResult(&ChildMessageFilter::OnMessageReceived
),
29 filter_
->OnStaleMessageReceived(msg
);
33 return filter_
->OnMessageReceived(msg
);
37 virtual ~Internal() {}
38 scoped_refptr
<ChildMessageFilter
> filter_
;
40 DISALLOW_COPY_AND_ASSIGN(Internal
);
43 bool ChildMessageFilter::Send(IPC::Message
* message
) {
44 return thread_safe_sender_
->Send(message
);
47 base::TaskRunner
* ChildMessageFilter::OverrideTaskRunnerForMessage(
48 const IPC::Message
& msg
) {
52 ChildMessageFilter::ChildMessageFilter()
54 thread_safe_sender_(ChildThread::current()->thread_safe_sender()) {}
56 ChildMessageFilter::~ChildMessageFilter() {}
58 IPC::ChannelProxy::MessageFilter
* ChildMessageFilter::GetFilter() {
60 internal_
= new Internal(this);
64 } // namespace content