OLD | NEW |
(Empty) | |
| 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_LIB_VALIDATOR_CHAIN_H_ |
| 6 #define MOJO_PUBLIC_CPP_BINDINGS_LIB_VALIDATOR_CHAIN_H_ |
| 7 |
| 8 #include <assert.h> |
| 9 |
| 10 #include <vector> |
| 11 |
| 12 #include "mojo/public/cpp/bindings/lib/message_validator.h" |
| 13 #include "mojo/public/cpp/bindings/message.h" |
| 14 #include "mojo/public/cpp/bindings/no_interface.h" |
| 15 #include "mojo/public/cpp/system/macros.h" |
| 16 |
| 17 namespace mojo { |
| 18 namespace internal { |
| 19 |
| 20 class ValidatorChain { |
| 21 MOJO_MOVE_ONLY_TYPE_FOR_CPP_03(ValidatorChain, RValue) |
| 22 |
| 23 public: |
| 24 // Doesn't take ownership of |sink|. Therefore |sink| has to stay alive while |
| 25 // this object is alive. If |sink| is NULL, set_sink() has to be called to set |
| 26 // a valid sink before this object can be used to validate messages. |
| 27 explicit ValidatorChain(MessageReceiver* sink = NULL); |
| 28 |
| 29 // Move-only constructor and operator=. |
| 30 ValidatorChain(RValue other); |
| 31 ValidatorChain& operator=(RValue other); |
| 32 |
| 33 ~ValidatorChain(); |
| 34 |
| 35 // Takes ownership of |validator|. |
| 36 ValidatorChain& Append(MessageValidator* validator); |
| 37 ValidatorChain& Append(NoValidator* validator); |
| 38 |
| 39 // Doesn't take ownership of |sink|. Therefore |sink| has to stay alive while |
| 40 // this object is alive. |
| 41 void set_sink(MessageReceiver* sink) { |
| 42 assert(!sink_); |
| 43 sink_ = sink; |
| 44 } |
| 45 |
| 46 // Returns a receiver to accept messages for validation. Messages reach |
| 47 // |sink_| only if they pass all the validators in the chain. |
| 48 MessageReceiver* GetHead(); |
| 49 |
| 50 private: |
| 51 // Owned by this object. |
| 52 std::vector<MessageValidator*> validators_; |
| 53 |
| 54 MessageReceiver* sink_; |
| 55 }; |
| 56 |
| 57 } // namespace internal |
| 58 } // namespace mojo |
| 59 |
| 60 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_VALIDATOR_CHAIN_H_ |
OLD | NEW |