Chromium Code Reviews| Index: mojo/public/cpp/bindings/message_filter.h |
| diff --git a/mojo/public/cpp/bindings/message_filter.h b/mojo/public/cpp/bindings/message_filter.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..5d9eba2e005206e7a48a606f7da8affbd22d558c |
| --- /dev/null |
| +++ b/mojo/public/cpp/bindings/message_filter.h |
| @@ -0,0 +1,44 @@ |
| +// Copyright 2014 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. |
| + |
| +#ifndef MOJO_PUBLIC_CPP_BINDINGS_MESSAGE_FILTER_H_ |
| +#define MOJO_PUBLIC_CPP_BINDINGS_MESSAGE_FILTER_H_ |
| + |
| +#include "mojo/public/cpp/bindings/message.h" |
| +#include "mojo/public/cpp/system/macros.h" |
| + |
| +namespace mojo { |
| + |
| +// This class is the base class for message filters. Subclasses should |
| +// implement the pure virtual method Accept() inherited from MessageReceiver to |
| +// process messages and/or forward them to |next_|. |
| +class MessageFilter : public MessageReceiver { |
| + public: |
| + // Doesn't take ownership of |next|. Therefore |next| has to stay alive while |
| + // this object is alive. |
| + explicit MessageFilter(MessageReceiver* next = NULL); |
| + virtual ~MessageFilter(); |
| + |
| + void set_next(MessageReceiver* next) { next_ = next; } |
|
darin (slow to review)
2014/05/14 06:51:51
it might make sense to rename "next" to "sink" bec
yzshen1
2014/05/14 08:14:03
Done.
|
| + |
| + protected: |
| + MessageReceiver* next_; |
| + |
| + private: |
| + // MessageReceiver method that shouldn't be reached. |
| + virtual bool AcceptWithResponder(Message* message, |
| + MessageReceiver* responder) MOJO_OVERRIDE; |
| +}; |
| + |
| +// A trivial filter that simply forwards every message it receives to |next_|. |
|
darin (slow to review)
2014/05/14 06:51:51
nit: maybe call this class MessageForwarder? At fi
yzshen1
2014/05/14 08:14:03
Done. I changed it to PassThroughFilter.
|
| +class NullFilter : public MessageFilter { |
| + public: |
| + explicit NullFilter(MessageReceiver* next = NULL); |
| + |
| + virtual bool Accept(Message* message) MOJO_OVERRIDE; |
| +}; |
| + |
| +} // namespace mojo |
| + |
| +#endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_MESSAGE_FILTER_H_ |