| OLD | NEW |
| (Empty) |
| 1 // Copyright 2016 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_VALIDATOR_H_ | |
| 6 #define MOJO_PUBLIC_CPP_BINDINGS_MESSAGE_VALIDATOR_H_ | |
| 7 | |
| 8 #include <string> | |
| 9 #include <vector> | |
| 10 | |
| 11 #include "mojo/public/cpp/bindings/lib/validation_errors.h" | |
| 12 #include "mojo/public/cpp/bindings/message.h" | |
| 13 #include "mojo/public/cpp/system/macros.h" | |
| 14 | |
| 15 namespace mojo { | |
| 16 namespace internal { | |
| 17 | |
| 18 // This class is the base class for message validators. Subclasses should | |
| 19 // implement the pure virtual method Validate() to validate messages. | |
| 20 class MessageValidator { | |
| 21 public: | |
| 22 virtual ~MessageValidator() {} | |
| 23 // Validates the message and returns ValidationError::NONE if valid. | |
| 24 // Otherwise returns a different value, and sets the |err| string if it is not | |
| 25 // null. | |
| 26 virtual ValidationError Validate(const Message* message, | |
| 27 std::string* err) = 0; | |
| 28 }; | |
| 29 | |
| 30 // A message validator that does nothing, and always returns a non-error. | |
| 31 class PassThroughValidator final : public MessageValidator { | |
| 32 public: | |
| 33 ValidationError Validate(const Message* message, std::string* err) override; | |
| 34 }; | |
| 35 | |
| 36 using MessageValidatorList = std::vector<std::unique_ptr<MessageValidator>>; | |
| 37 | |
| 38 // Iterates through |validators| and tries to validate the given |message| until | |
| 39 // a validator fails. If a validator fails, a |ValidationError| is returned and | |
| 40 // the supplied |err| is set if it is not null. |ValidationError::NONE| is | |
| 41 // returned if the supplied |message| passes all the |validators|. | |
| 42 ValidationError RunValidatorsOnMessage(const MessageValidatorList& validators, | |
| 43 const Message* message, | |
| 44 std::string* err); | |
| 45 | |
| 46 } // namespace internal | |
| 47 } // namespace mojo | |
| 48 | |
| 49 #endif // MOJO_PUBLIC_CPP_BINDINGS_MESSAGE_VALIDATOR_H_ | |
| OLD | NEW |