Chromium Code Reviews| Index: content/child/cross_thread_message_filter.cc |
| diff --git a/content/child/cross_thread_message_filter.cc b/content/child/cross_thread_message_filter.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..14db21bf56dcc89b361b2dd28d7c2fc2a272cb4b |
| --- /dev/null |
| +++ b/content/child/cross_thread_message_filter.cc |
| @@ -0,0 +1,59 @@ |
| +// 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/cross_thread_message_filter.h" |
| + |
| +#include "base/bind.h" |
| +#include "base/bind_helpers.h" |
| +#include "base/location.h" |
| +#include "base/message_loop/message_loop_proxy.h" |
| +#include "webkit/child/worker_task_runner.h" |
| + |
| +namespace content { |
| + |
| +class CrossThreadMessageFilter::Internal |
| + : public IPC::ChannelProxy::MessageFilter { |
| + public: |
| + explicit Internal(CrossThreadMessageFilter* filter) |
| + : filter_(filter), |
| + main_thread_loop_proxy_(base::MessageLoopProxy::current()) {} |
| + |
| + virtual bool OnMessageReceived(const IPC::Message& msg) OVERRIDE { |
| + int ipc_thread_id = 0; |
| + if (!filter_->OverrideThreadIDForMessage(msg, &ipc_thread_id)) |
| + return filter_->OnMessageReceived(msg); |
| + |
| + base::Closure closure = base::Bind( |
| + base::IgnoreResult(&CrossThreadMessageFilter::OnMessageReceived), |
| + filter_, msg); |
| + if (!ipc_thread_id) { |
|
jam
2013/11/08 19:51:59
we should keep the ipc_thread_id stuff in child cl
michaeln
2013/11/09 01:52:10
+1 using the base::TaskRunner abstraction for this
kinuko
2013/11/15 14:40:36
Done. (If I should separate a CL for adding TaskR
|
| + main_thread_loop_proxy_->PostTask(FROM_HERE, closure); |
| + return true; |
| + } |
| + if (!webkit_glue::WorkerTaskRunner::Instance()->PostTask( |
| + ipc_thread_id, closure)) |
| + filter_->OnStaleMessageReceived(msg); |
| + return true; |
| + } |
| + |
| + private: |
| + virtual ~Internal() {} |
| + scoped_refptr<CrossThreadMessageFilter> filter_; |
| + scoped_refptr<base::MessageLoopProxy> main_thread_loop_proxy_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(Internal); |
| +}; |
| + |
| +CrossThreadMessageFilter::CrossThreadMessageFilter() |
| + : internal_(NULL) {} |
| + |
| +CrossThreadMessageFilter::~CrossThreadMessageFilter() {} |
| + |
| +IPC::ChannelProxy::MessageFilter* CrossThreadMessageFilter::GetFilter() { |
| + if (!internal_) |
| + internal_ = new Internal(this); |
| + return internal_; |
| +} |
| + |
| +} // namespace content |