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"
13 #include "ipc/message_filter.h"
17 class ChildMessageFilter::Internal
: public IPC::MessageFilter
{
19 explicit Internal(ChildMessageFilter
* filter
) : filter_(filter
) {}
21 bool OnMessageReceived(const IPC::Message
& msg
) override
{
22 scoped_refptr
<base::TaskRunner
> runner
=
23 filter_
->OverrideTaskRunnerForMessage(msg
);
24 if (runner
.get() && !runner
->RunsTasksOnCurrentThread()) {
25 if (!runner
->PostTask(
28 base::IgnoreResult(&ChildMessageFilter::OnMessageReceived
),
30 filter_
->OnStaleMessageReceived(msg
);
34 return filter_
->OnMessageReceived(msg
);
38 ~Internal() override
{}
39 scoped_refptr
<ChildMessageFilter
> filter_
;
41 DISALLOW_COPY_AND_ASSIGN(Internal
);
44 bool ChildMessageFilter::Send(IPC::Message
* message
) {
45 return thread_safe_sender_
->Send(message
);
48 base::TaskRunner
* ChildMessageFilter::OverrideTaskRunnerForMessage(
49 const IPC::Message
& msg
) {
53 ChildMessageFilter::ChildMessageFilter()
55 thread_safe_sender_(ChildThread::current()->thread_safe_sender()) {}
57 ChildMessageFilter::~ChildMessageFilter() {}
59 IPC::MessageFilter
* ChildMessageFilter::GetFilter() {
61 internal_
= new Internal(this);
65 } // namespace content