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

Unified Diff: ppapi/host/resource_message_filter.cc

Issue 11359097: Refactored the PPB_Flash_File_ModuleLocal/FileRef to the new ppapi resource model (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
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..0e51ad627366d238c60cb15f2ee2c3946bb652a4
--- /dev/null
+++ b/ppapi/host/resource_message_filter.cc
@@ -0,0 +1,77 @@
+// 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()
+ : io_message_loop_proxy_(MessageLoop::current()->message_loop_proxy()),
+ resource_host_(NULL) {
+}
+
+ResourceMessageFilter::ResourceMessageFilter(
+ scoped_refptr<base::MessageLoopProxy> io_message_loop_proxy)
+ : io_message_loop_proxy_(io_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 (!io_message_loop_proxy_->BelongsToCurrentThread()) {
+ io_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

Powered by Google App Engine
This is Rietveld 408576698