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

Unified Diff: ipc/ipc_forwarding_message_filter.cc

Issue 10796057: Add IPC::ForwardingMessageFilter. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: with nits Created 8 years, 5 months 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 | « ipc/ipc_forwarding_message_filter.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ipc/ipc_forwarding_message_filter.cc
diff --git a/ipc/ipc_forwarding_message_filter.cc b/ipc/ipc_forwarding_message_filter.cc
new file mode 100644
index 0000000000000000000000000000000000000000..48f6e5ff810dbd14fa9afe2f98901098bbb3b986
--- /dev/null
+++ b/ipc/ipc_forwarding_message_filter.cc
@@ -0,0 +1,60 @@
+// 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 "ipc/ipc_forwarding_message_filter.h"
+
+#include "base/bind.h"
+#include "base/location.h"
+
+namespace IPC {
+
+ForwardingMessageFilter::ForwardingMessageFilter(
+ const uint32* message_ids_to_filter,
+ size_t num_message_ids_to_filter,
+ base::TaskRunner* target_task_runner,
+ const Handler& handler)
+ : target_task_runner_(target_task_runner),
+ handler_(handler) {
+ DCHECK(target_task_runner_);
+ DCHECK(!handler_.is_null());
+ for (size_t i = 0; i < num_message_ids_to_filter; i++)
+ message_ids_to_filter_.insert(message_ids_to_filter[i]);
+}
+
+void ForwardingMessageFilter::AddRoute(int routing_id) {
+ base::AutoLock locked(routes_lock_);
+ routes_.insert(routing_id);
+}
+
+void ForwardingMessageFilter::RemoveRoute(int routing_id) {
+ base::AutoLock locked(routes_lock_);
+ routes_.erase(routing_id);
+}
+
+bool ForwardingMessageFilter::OnMessageReceived(const Message& message) {
+ if (message_ids_to_filter_.find(message.type()) ==
+ message_ids_to_filter_.end())
+ return false;
+
+ {
+ base::AutoLock locked(routes_lock_);
+ if (routes_.find(message.routing_id()) == routes_.end())
+ return false;
+ }
+
+ target_task_runner_->PostTask(
+ FROM_HERE,
+ base::Bind(&ForwardingMessageFilter::ForwardToHandler, this, message));
+ return true;
+}
+
+ForwardingMessageFilter::~ForwardingMessageFilter() {
+}
+
+void ForwardingMessageFilter::ForwardToHandler(const Message& message) {
+ DCHECK(target_task_runner_->RunsTasksOnCurrentThread());
+ handler_.Run(message);
+}
+
+} // namespace IPC
« no previous file with comments | « ipc/ipc_forwarding_message_filter.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698