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

Unified Diff: content/child/child_message_filter.cc

Issue 63843002: Add ChildMessageFilter, a base class for renderer/worker cross-thread MessageFilter (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: RemoveFilter fix Created 7 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 | « content/child/child_message_filter.h ('k') | content/child/child_thread.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/child/child_message_filter.cc
diff --git a/content/child/child_message_filter.cc b/content/child/child_message_filter.cc
new file mode 100644
index 0000000000000000000000000000000000000000..c325632235fecf5cb3de94c3b131f7d08a1641a7
--- /dev/null
+++ b/content/child/child_message_filter.cc
@@ -0,0 +1,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
« no previous file with comments | « content/child/child_message_filter.h ('k') | content/child/child_thread.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698