Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(136)

Unified Diff: ppapi/host/resource_message_filter.cc

Issue 11410029: Added a ResourceMessageFilter for handling resource messages on another thread. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 8 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ppapi/host/resource_message_filter.h ('k') | ppapi/host/resource_message_filter_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ppapi/host/resource_message_filter.cc
diff --git a/ppapi/host/resource_message_filter.cc b/ppapi/host/resource_message_filter.cc
new file mode 100644
index 0000000000000000000000000000000000000000..887c184f66ba8e50e17680caea5983e1d46c8e11
--- /dev/null
+++ b/ppapi/host/resource_message_filter.cc
@@ -0,0 +1,78 @@
+// Copyright (c) 2012 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 "ppapi/host/resource_message_filter.h"
+
+#include "base/message_loop.h"
+#include "base/message_loop_proxy.h"
+#include "base/task_runner.h"
+#include "ipc/ipc_message.h"
+#include "ppapi/c/pp_errors.h"
+#include "ppapi/host/ppapi_host.h"
+#include "ppapi/host/resource_host.h"
+
+namespace ppapi {
+namespace host {
+
+ResourceMessageFilter::ResourceMessageFilter()
+ : reply_thread_message_loop_proxy_(
+ MessageLoop::current()->message_loop_proxy()),
+ resource_host_(NULL) {
+}
+
+ResourceMessageFilter::ResourceMessageFilter(
+ scoped_refptr<base::MessageLoopProxy> reply_thread_message_loop_proxy)
+ : reply_thread_message_loop_proxy_(reply_thread_message_loop_proxy),
+ resource_host_(NULL) {
+}
+
+ResourceMessageFilter::~ResourceMessageFilter() {
+}
+
+void ResourceMessageFilter::OnFilterAdded(ResourceHost* resource_host) {
+ resource_host_ = resource_host;
+}
+
+void ResourceMessageFilter::OnFilterDestroyed() {
+ resource_host_ = NULL;
+}
+
+bool ResourceMessageFilter::HandleMessage(const IPC::Message& msg,
+ HostMessageContext* context) {
+ scoped_refptr<base::TaskRunner> runner = OverrideTaskRunnerForMessage(msg);
+ if (runner) {
+ // TODO(raymes): We need to make a copy so the context can be used on other
+ // threads. It would be better to have a thread-safe refcounted context.
+ HostMessageContext context_copy = *context;
+ runner->PostTask(FROM_HERE, base::Bind(
+ &ResourceMessageFilter::DispatchMessage, this, msg, context_copy));
+ return true;
+ }
+
+ return false;
+}
+
+void ResourceMessageFilter::SendReply(const ReplyMessageContext& context,
+ const IPC::Message& msg) {
+ if (!reply_thread_message_loop_proxy_->BelongsToCurrentThread()) {
+ reply_thread_message_loop_proxy_->PostTask(FROM_HERE,
+ base::Bind(&ResourceMessageFilter::SendReply, this, context, msg));
+ return;
+ }
+ if (resource_host_)
+ resource_host_->SendReply(context, msg);
+}
+
+scoped_refptr<base::TaskRunner>
+ResourceMessageFilter::OverrideTaskRunnerForMessage(const IPC::Message& msg) {
+ return NULL;
+}
+
+void ResourceMessageFilter::DispatchMessage(const IPC::Message& msg,
+ HostMessageContext context) {
+ RunMessageHandlerAndReply(msg, &context);
+}
+
+} // namespace host
+} // namespace ppapi
« no previous file with comments | « ppapi/host/resource_message_filter.h ('k') | ppapi/host/resource_message_filter_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698