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/bindings/callback.h" |
8 #include "mojo/public/cpp/system/macros.h" | 9 #include "mojo/public/cpp/system/macros.h" |
| 10 #if defined(OS_WIN) |
| 11 // To avoid a compile failure on Windows because it defines ERROR, which is also |
| 12 // used by the logs. Similar to change in base. |
| 13 #undef ERROR |
| 14 #endif |
9 | 15 |
10 namespace mojo { | 16 namespace mojo { |
11 namespace internal { | 17 namespace internal { |
12 | 18 |
13 enum ValidationError { | 19 enum ValidationError { |
14 // There is no validation error. | 20 // There is no validation error. |
15 VALIDATION_ERROR_NONE, | 21 VALIDATION_ERROR_NONE, |
16 // An object (struct or array) is not 8-byte aligned. | 22 // An object (struct or array) is not 8-byte aligned. |
17 VALIDATION_ERROR_MISALIGNED_OBJECT, | 23 VALIDATION_ERROR_MISALIGNED_OBJECT, |
18 // An object is not contained inside the message data, or it overlaps other | 24 // An object is not contained inside the message data, or it overlaps other |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
63 | 69 |
64 const char* ValidationErrorToString(ValidationError error); | 70 const char* ValidationErrorToString(ValidationError error); |
65 | 71 |
66 void ReportValidationError(ValidationError error, | 72 void ReportValidationError(ValidationError error, |
67 const char* description = nullptr); | 73 const char* description = nullptr); |
68 | 74 |
69 // Only used by validation tests and when there is only one thread doing message | 75 // Only used by validation tests and when there is only one thread doing message |
70 // validation. | 76 // validation. |
71 class ValidationErrorObserverForTesting { | 77 class ValidationErrorObserverForTesting { |
72 public: | 78 public: |
73 ValidationErrorObserverForTesting(); | 79 explicit ValidationErrorObserverForTesting(const Callback<void()>& callback); |
74 ~ValidationErrorObserverForTesting(); | 80 ~ValidationErrorObserverForTesting(); |
75 | 81 |
76 ValidationError last_error() const { return last_error_; } | 82 ValidationError last_error() const { return last_error_; } |
77 void set_last_error(ValidationError error) { last_error_ = error; } | 83 void set_last_error(ValidationError error) { |
| 84 last_error_ = error; |
| 85 callback_.Run(); |
| 86 } |
78 | 87 |
79 private: | 88 private: |
80 ValidationError last_error_; | 89 ValidationError last_error_; |
| 90 Callback<void()> callback_; |
81 | 91 |
82 MOJO_DISALLOW_COPY_AND_ASSIGN(ValidationErrorObserverForTesting); | 92 MOJO_DISALLOW_COPY_AND_ASSIGN(ValidationErrorObserverForTesting); |
83 }; | 93 }; |
84 | 94 |
85 // Used only by MOJO_INTERNAL_DLOG_SERIALIZATION_WARNING. Don't use it directly. | 95 // Used only by MOJO_INTERNAL_DLOG_SERIALIZATION_WARNING. Don't use it directly. |
86 // | 96 // |
87 // The function returns true if the error is recorded (by a | 97 // The function returns true if the error is recorded (by a |
88 // SerializationWarningObserverForTesting object), false otherwise. | 98 // SerializationWarningObserverForTesting object), false otherwise. |
89 bool ReportSerializationWarning(ValidationError error); | 99 bool ReportSerializationWarning(ValidationError error); |
90 | 100 |
(...skipping 26 matching lines...) Expand all Loading... |
117 // | 127 // |
118 // In non-debug build, does nothing (not even compiling |condition|). | 128 // In non-debug build, does nothing (not even compiling |condition|). |
119 #define MOJO_INTERNAL_DLOG_SERIALIZATION_WARNING( \ | 129 #define MOJO_INTERNAL_DLOG_SERIALIZATION_WARNING( \ |
120 condition, error, description) \ | 130 condition, error, description) \ |
121 MOJO_DLOG_IF(FATAL, (condition) && !ReportSerializationWarning(error)) \ | 131 MOJO_DLOG_IF(FATAL, (condition) && !ReportSerializationWarning(error)) \ |
122 << "The outgoing message will trigger " \ | 132 << "The outgoing message will trigger " \ |
123 << ValidationErrorToString(error) << " at the receiving side (" \ | 133 << ValidationErrorToString(error) << " at the receiving side (" \ |
124 << description << ")."; | 134 << description << ")."; |
125 | 135 |
126 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_VALIDATION_ERRORS_H_ | 136 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_VALIDATION_ERRORS_H_ |
OLD | NEW |