Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef MOJO_PUBLIC_CPP_BINDINGS_LIB_VALIDATION_ERRORS_H_ | 5 #ifndef MOJO_PUBLIC_CPP_BINDINGS_LIB_VALIDATION_ERRORS_H_ |
| 6 #define MOJO_PUBLIC_CPP_BINDINGS_LIB_VALIDATION_ERRORS_H_ | 6 #define MOJO_PUBLIC_CPP_BINDINGS_LIB_VALIDATION_ERRORS_H_ |
| 7 | 7 |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "mojo/public/cpp/bindings/callback.h" | 10 #include "mojo/public/cpp/bindings/callback.h" |
| 11 #include "mojo/public/cpp/bindings/lib/validation_context.h" | |
| 11 | 12 |
| 12 namespace mojo { | 13 namespace mojo { |
| 13 namespace internal { | 14 namespace internal { |
| 14 | 15 |
| 15 enum ValidationError { | 16 enum ValidationError { |
| 16 // There is no validation error. | 17 // There is no validation error. |
| 17 VALIDATION_ERROR_NONE, | 18 VALIDATION_ERROR_NONE, |
| 18 // An object (struct or array) is not 8-byte aligned. | 19 // An object (struct or array) is not 8-byte aligned. |
| 19 VALIDATION_ERROR_MISALIGNED_OBJECT, | 20 VALIDATION_ERROR_MISALIGNED_OBJECT, |
| 20 // An object is not contained inside the message data, or it overlaps other | 21 // An object is not contained inside the message data, or it overlaps other |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 55 // there isn't one. | 56 // there isn't one. |
| 56 VALIDATION_ERROR_MESSAGE_HEADER_MISSING_REQUEST_ID, | 57 VALIDATION_ERROR_MESSAGE_HEADER_MISSING_REQUEST_ID, |
| 57 // The |name| field in a message header contains an unexpected value. | 58 // The |name| field in a message header contains an unexpected value. |
| 58 VALIDATION_ERROR_MESSAGE_HEADER_UNKNOWN_METHOD, | 59 VALIDATION_ERROR_MESSAGE_HEADER_UNKNOWN_METHOD, |
| 59 // Two parallel arrays which are supposed to represent a map have different | 60 // Two parallel arrays which are supposed to represent a map have different |
| 60 // lengths. | 61 // lengths. |
| 61 VALIDATION_ERROR_DIFFERENT_SIZED_ARRAYS_IN_MAP, | 62 VALIDATION_ERROR_DIFFERENT_SIZED_ARRAYS_IN_MAP, |
| 62 // Attempted to deserialize a tagged union with an unknown tag. | 63 // Attempted to deserialize a tagged union with an unknown tag. |
| 63 VALIDATION_ERROR_UNKNOWN_UNION_TAG, | 64 VALIDATION_ERROR_UNKNOWN_UNION_TAG, |
| 64 // A value of a non-extensible enum type is unknown. | 65 // A value of a non-extensible enum type is unknown. |
| 65 VALIDATION_ERROR_UNKNOWN_ENUM_VALUE | 66 VALIDATION_ERROR_UNKNOWN_ENUM_VALUE, |
| 67 // Deserialization of some message parameter or struct field failed, for | |
|
yzshen1
2016/06/15 22:20:09
nit: maybe simply say "Message deserialization fai
Ken Rockot(use gerrit already)
2016/06/15 22:38:23
Done
| |
| 68 // example due to rejection by custom validation logic. | |
| 69 VALIDATION_ERROR_DESERIALIZATION_FAILED, | |
| 66 }; | 70 }; |
| 67 | 71 |
| 68 const char* ValidationErrorToString(ValidationError error); | 72 const char* ValidationErrorToString(ValidationError error); |
| 69 | 73 |
| 70 void ReportValidationError(ValidationError error, | 74 void ReportValidationError(ValidationContext* context, |
| 75 ValidationError error, | |
| 71 const char* description = nullptr); | 76 const char* description = nullptr); |
| 72 | 77 |
| 73 // Only used by validation tests and when there is only one thread doing message | 78 // Only used by validation tests and when there is only one thread doing message |
| 74 // validation. | 79 // validation. |
| 75 class ValidationErrorObserverForTesting { | 80 class ValidationErrorObserverForTesting { |
| 76 public: | 81 public: |
| 77 explicit ValidationErrorObserverForTesting(const Callback<void()>& callback); | 82 explicit ValidationErrorObserverForTesting(const Callback<void()>& callback); |
| 78 ~ValidationErrorObserverForTesting(); | 83 ~ValidationErrorObserverForTesting(); |
| 79 | 84 |
| 80 ValidationError last_error() const { return last_error_; } | 85 ValidationError last_error() const { return last_error_; } |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 125 // | 130 // |
| 126 // In non-debug build, does nothing (not even compiling |condition|). | 131 // In non-debug build, does nothing (not even compiling |condition|). |
| 127 #define MOJO_INTERNAL_DLOG_SERIALIZATION_WARNING(condition, error, \ | 132 #define MOJO_INTERNAL_DLOG_SERIALIZATION_WARNING(condition, error, \ |
| 128 description) \ | 133 description) \ |
| 129 DLOG_IF(FATAL, (condition) && !ReportSerializationWarning(error)) \ | 134 DLOG_IF(FATAL, (condition) && !ReportSerializationWarning(error)) \ |
| 130 << "The outgoing message will trigger " \ | 135 << "The outgoing message will trigger " \ |
| 131 << ValidationErrorToString(error) << " at the receiving side (" \ | 136 << ValidationErrorToString(error) << " at the receiving side (" \ |
| 132 << description << ")."; | 137 << description << ")."; |
| 133 | 138 |
| 134 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_VALIDATION_ERRORS_H_ | 139 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_VALIDATION_ERRORS_H_ |
| OLD | NEW |