Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / mojo / public / cpp / bindings / message_filter.h
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef MOJO_PUBLIC_CPP_BINDINGS_MESSAGE_FILTER_H_
6 #define MOJO_PUBLIC_CPP_BINDINGS_MESSAGE_FILTER_H_
7
8 #include "mojo/public/cpp/bindings/message.h"
9 #include "mojo/public/cpp/system/macros.h"
10
11 namespace mojo {
12
13 // This class is the base class for message filters. Subclasses should
14 // implement the pure virtual method Accept() inherited from MessageReceiver to
15 // process messages and/or forward them to |sink_|.
16 class MessageFilter : public MessageReceiver {
17  public:
18   // Doesn't take ownership of |sink|. Therefore |sink| has to stay alive while
19   // this object is alive.
20   explicit MessageFilter(MessageReceiver* sink = nullptr);
21   ~MessageFilter() override;
22
23   void set_sink(MessageReceiver* sink) { sink_ = sink; }
24
25  protected:
26   MessageReceiver* sink_;
27 };
28
29 // A trivial filter that simply forwards every message it receives to |sink_|.
30 class PassThroughFilter : public MessageFilter {
31  public:
32   explicit PassThroughFilter(MessageReceiver* sink = nullptr);
33
34   bool Accept(Message* message) override;
35 };
36
37 }  // namespace mojo
38
39 #endif  // MOJO_PUBLIC_CPP_BINDINGS_LIB_MESSAGE_FILTER_H_