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

Unified Diff: mojo/public/cpp/bindings/lib/filter_chain.h

Issue 291583005: Change FilterChain::Append() to a template method. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 7 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 | « no previous file | mojo/public/cpp/bindings/lib/filter_chain.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/public/cpp/bindings/lib/filter_chain.h
diff --git a/mojo/public/cpp/bindings/lib/filter_chain.h b/mojo/public/cpp/bindings/lib/filter_chain.h
index df681356f41d1955e1d2e94abbbe4cb51b20762d..8680f41aaee7216d1aed1f4e00eb863ef423466a 100644
--- a/mojo/public/cpp/bindings/lib/filter_chain.h
+++ b/mojo/public/cpp/bindings/lib/filter_chain.h
@@ -5,8 +5,6 @@
#ifndef MOJO_PUBLIC_CPP_BINDINGS_LIB_FILTER_CHAIN_H_
#define MOJO_PUBLIC_CPP_BINDINGS_LIB_FILTER_CHAIN_H_
-#include <assert.h>
-
#include <vector>
#include "mojo/public/cpp/bindings/message.h"
@@ -30,20 +28,17 @@ class FilterChain {
~FilterChain();
- // Takes ownership of |filter|.
- FilterChain& Append(MessageFilter* filter);
- FilterChain& Append(PassThroughFilter* filter);
+ template <typename FilterType>
+ inline void Append();
// Doesn't take ownership of |sink|. Therefore |sink| has to stay alive while
// this object is alive.
- void set_sink(MessageReceiver* sink) {
- assert(!sink_);
- sink_ = sink;
- }
+ void SetSink(MessageReceiver* sink);
// Returns a receiver to accept messages. Messages flow through all filters in
// the same order as they were appended to the chain. If all filters allow a
// message to pass, it will be forwarded to |sink_|.
+ // The returned value is invalidated when this object goes away.
MessageReceiver* GetHead();
private:
@@ -53,6 +48,18 @@ class FilterChain {
MessageReceiver* sink_;
};
+template <typename FilterType>
+inline void FilterChain::Append() {
+ FilterType* filter = new FilterType(sink_);
+ if (!filters_.empty())
+ filters_.back()->set_sink(filter);
+ filters_.push_back(filter);
+}
+
+template <>
+inline void FilterChain::Append<PassThroughFilter>() {
+}
+
} // namespace internal
} // namespace mojo
« no previous file with comments | « no previous file | mojo/public/cpp/bindings/lib/filter_chain.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698