| 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 "mojo/public/cpp/system/macros.h" | 8 #include "mojo/public/cpp/system/macros.h" |
| 9 | 9 |
| 10 namespace mojo { | 10 namespace mojo { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 // A struct header doesn't make sense, for example: | 21 // A struct header doesn't make sense, for example: |
| 22 // - |num_bytes| is smaller than the size of the oldest version that we | 22 // - |num_bytes| is smaller than the size of the oldest version that we |
| 23 // support. | 23 // support. |
| 24 // - |num_fields| is smaller than the field number of the oldest version that | 24 // - |num_fields| is smaller than the field number of the oldest version that |
| 25 // we support. | 25 // we support. |
| 26 // - |num_bytes| and |num_fields| don't match. | 26 // - |num_bytes| and |num_fields| don't match. |
| 27 VALIDATION_ERROR_UNEXPECTED_STRUCT_HEADER, | 27 VALIDATION_ERROR_UNEXPECTED_STRUCT_HEADER, |
| 28 // An array header doesn't make sense, for example: | 28 // An array header doesn't make sense, for example: |
| 29 // - |num_bytes| is smaller than the size of the header plus the size required | 29 // - |num_bytes| is smaller than the size of the header plus the size required |
| 30 // to store |num_elements| elements. | 30 // to store |num_elements| elements. |
| 31 // - For fixed-size arrays, |num_elements| is different than the specified |
| 32 // size. |
| 31 VALIDATION_ERROR_UNEXPECTED_ARRAY_HEADER, | 33 VALIDATION_ERROR_UNEXPECTED_ARRAY_HEADER, |
| 32 // An encoded handle is illegal. | 34 // An encoded handle is illegal. |
| 33 VALIDATION_ERROR_ILLEGAL_HANDLE, | 35 VALIDATION_ERROR_ILLEGAL_HANDLE, |
| 36 // A non-nullable handle field is set to invalid handle. |
| 37 VALIDATION_ERROR_UNEXPECTED_INVALID_HANDLE, |
| 34 // An encoded pointer is illegal. | 38 // An encoded pointer is illegal. |
| 35 VALIDATION_ERROR_ILLEGAL_POINTER, | 39 VALIDATION_ERROR_ILLEGAL_POINTER, |
| 40 // A non-nullable pointer field is set to null. |
| 41 VALIDATION_ERROR_UNEXPECTED_NULL_POINTER, |
| 36 // |flags| in the message header is an invalid flag combination. | 42 // |flags| in the message header is an invalid flag combination. |
| 37 VALIDATION_ERROR_MESSAGE_HEADER_INVALID_FLAG_COMBINATION, | 43 VALIDATION_ERROR_MESSAGE_HEADER_INVALID_FLAG_COMBINATION, |
| 38 // |flags| in the message header indicates that a request ID is required but | 44 // |flags| in the message header indicates that a request ID is required but |
| 39 // there isn't one. | 45 // there isn't one. |
| 40 VALIDATION_ERROR_MESSAGE_HEADER_MISSING_REQUEST_ID, | 46 VALIDATION_ERROR_MESSAGE_HEADER_MISSING_REQUEST_ID, |
| 41 }; | 47 }; |
| 42 | 48 |
| 43 const char* ValidationErrorToString(ValidationError error); | 49 const char* ValidationErrorToString(ValidationError error); |
| 44 | 50 |
| 45 void ReportValidationError(ValidationError error); | 51 void ReportValidationError(ValidationError error); |
| 46 | 52 |
| 47 // Only used by validation tests and when there is only one thread doing message | 53 // Only used by validation tests and when there is only one thread doing message |
| 48 // validation. | 54 // validation. |
| 49 class ValidationErrorObserverForTesting { | 55 class ValidationErrorObserverForTesting { |
| 50 public: | 56 public: |
| 51 ValidationErrorObserverForTesting(); | 57 ValidationErrorObserverForTesting(); |
| 52 ~ValidationErrorObserverForTesting(); | 58 ~ValidationErrorObserverForTesting(); |
| 53 | 59 |
| 54 ValidationError last_error() const { return last_error_; } | 60 ValidationError last_error() const { return last_error_; } |
| 55 void set_last_error(ValidationError error) { last_error_ = error; } | 61 void set_last_error(ValidationError error) { last_error_ = error; } |
| 56 | 62 |
| 57 private: | 63 private: |
| 58 ValidationError last_error_; | 64 ValidationError last_error_; |
| 59 | 65 |
| 60 MOJO_DISALLOW_COPY_AND_ASSIGN(ValidationErrorObserverForTesting); | 66 MOJO_DISALLOW_COPY_AND_ASSIGN(ValidationErrorObserverForTesting); |
| 61 }; | 67 }; |
| 62 | 68 |
| 69 // Currently it only returns true when there is a |
| 70 // ValidationErrorObserverForTesting object alive. In other words, non-nullable |
| 71 // validation is only turned on during validation tests. |
| 72 // |
| 73 // TODO(yzshen): Remove this function and enable non-nullable validation by |
| 74 // default. |
| 75 bool IsNonNullableValidationEnabled(); |
| 76 |
| 63 } // namespace internal | 77 } // namespace internal |
| 64 } // namespace mojo | 78 } // namespace mojo |
| 65 | 79 |
| 66 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_VALIDATION_ERRORS_H_ | 80 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_VALIDATION_ERRORS_H_ |
| OLD | NEW |