blob: c325632235fecf5cb3de94c3b131f7d08a1641a7 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
// Copyright 2013 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 "content/child/child_message_filter.h"
#include "base/bind.h"
#include "base/bind_helpers.h"
#include "base/location.h"
#include "base/task_runner.h"
#include "content/child/child_thread.h"
#include "content/child/thread_safe_sender.h"
namespace content {
class ChildMessageFilter::Internal : public IPC::ChannelProxy::MessageFilter {
public:
explicit Internal(ChildMessageFilter* filter) : filter_(filter) {}
virtual bool OnMessageReceived(const IPC::Message& msg) OVERRIDE {
scoped_refptr<base::TaskRunner> runner =
filter_->OverrideTaskRunnerForMessage(msg);
if (runner && !runner->RunsTasksOnCurrentThread()) {
if (!runner->PostTask(
FROM_HERE,
base::Bind(
base::IgnoreResult(&ChildMessageFilter::OnMessageReceived),
filter_, msg)))
filter_->OnStaleMessageReceived(msg);
return true;
}
return filter_->OnMessageReceived(msg);
}
private:
virtual ~Internal() {}
scoped_refptr<ChildMessageFilter> filter_;
DISALLOW_COPY_AND_ASSIGN(Internal);
};
bool ChildMessageFilter::Send(IPC::Message* message) {
return thread_safe_sender_->Send(message);
}
base::TaskRunner* ChildMessageFilter::OverrideTaskRunnerForMessage(
const IPC::Message& msg) {
return NULL;
}
ChildMessageFilter::ChildMessageFilter()
: internal_(NULL),
thread_safe_sender_(ChildThread::current()->thread_safe_sender()) {}
ChildMessageFilter::~ChildMessageFilter() {}
IPC::ChannelProxy::MessageFilter* ChildMessageFilter::GetFilter() {
if (!internal_)
internal_ = new Internal(this);
return internal_;
}
} // namespace content
|