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

Unified Diff: ppapi/host/background_thread_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
Index: ppapi/host/background_thread_message_filter.cc
diff --git a/ppapi/host/background_thread_message_filter.cc b/ppapi/host/background_thread_message_filter.cc
new file mode 100644
index 0000000000000000000000000000000000000000..18e436817509b457a70c76777ea8efe3a1e6fc7f
--- /dev/null
+++ b/ppapi/host/background_thread_message_filter.cc
@@ -0,0 +1,102 @@
+// 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/background_thread_message_filter.h"
+
+#include "base/task_runner.h"
+#include "content/public/browser/browser_ppapi_host.h"
+#include "ipc/ipc_message.h"
+#include "ppapi/c/pp_errors.h"
+#include "ppapi/host/host_message_context.h"
+#include "ppapi/host/ppapi_host.h"
+#include "ppapi/host/resource_host.h"
+
+namespace ppapi {
+namespace host {
+
+BackgroundThreadMessageFilter::BackgroundThreadMessageFilter()
+ : resource_host_(NULL) {
+}
+
+BackgroundThreadMessageFilter::~BackgroundThreadMessageFilter() {
+}
+
+void BackgroundThreadMessageFilter::OnFilterAdded(ResourceHost* resource_host) {
+ resource_host_ = resource_host;
+}
+
+void BackgroundThreadMessageFilter::OnFilterDestroyed() {
+ resource_host_ = NULL;
+}
+
+bool BackgroundThreadMessageFilter::HandleMessage(
+ const IPC::Message& msg,
+ HostMessageContext* context) {
+ HostMessageContext context_copy = *context;
+
+ content::BrowserThread::ID thread = content::BrowserThread::IO;
+ bool overridden_for_thread = OverrideThreadForMessage(msg, &thread);
+ scoped_refptr<base::TaskRunner> runner =
+ OverrideTaskRunnerForMessage(msg);
+ // The message should not be overridden for both a thread and a task runner.
+ DCHECK(!(overridden_for_thread && runner));
+
+ if (overridden_for_thread) {
+ content::BrowserThread::PostTask(
+ thread, FROM_HERE,
+ base::Bind(&BackgroundThreadMessageFilter::DispatchMessage,
+ this, msg, context_copy));
+ return true;
+ } else if (runner) {
+ runner->PostTask(FROM_HERE, base::Bind(
+ &BackgroundThreadMessageFilter::DispatchMessage, this, msg,
+ context_copy));
+ return true;
+ }
+
+ return false;
+}
+
+void BackgroundThreadMessageFilter::SendReply(
+ const ReplyMessageContext& context,
+ const IPC::Message& msg) {
+ if (!content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)) {
+ content::BrowserThread::PostTask(content::BrowserThread::IO, FROM_HERE,
+ base::Bind(&BackgroundThreadMessageFilter::SendReply, this, context,
+ msg));
+ }
+ if (resource_host_)
+ resource_host_->SendReply(context, msg);
+}
+
+void BackgroundThreadMessageFilter::DispatchMessage(
+ const IPC::Message& msg,
+ HostMessageContext context) {
+ RunMessageHandlerAndReply(msg, &context);
+}
+
+bool BackgroundThreadMessageFilter::OverrideThreadForMessage(
+ const IPC::Message& message,
+ content::BrowserThread::ID* thread) {
+ return false;
+}
+
+base::TaskRunner* BackgroundThreadMessageFilter::OverrideTaskRunnerForMessage(
+ const IPC::Message& msg) {
+ return NULL;
+}
+
+RenderViewHostMessageFilter::RenderViewHostMessageFilter(
+ content::BrowserPpapiHost* host,
+ PP_Instance instance) {
+ host->GetRenderViewIDsForInstance(instance, &render_process_id_,
+ &render_view_id_);
+}
+
+content::RenderViewHost* RenderViewHostMessageFilter::GetRenderViewHost() {
+ return content::RenderViewHost::FromID(render_process_id_, render_view_id_);
+}
+
+} // namespace host
+} // namespace ppapi

Powered by Google App Engine
This is Rietveld 408576698