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/callback.h" | 8 #include "base/callback.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/macros.h" | 10 #include "base/macros.h" |
11 #include "mojo/public/cpp/bindings/lib/validation_context.h" | 11 #include "mojo/public/cpp/bindings/lib/validation_context.h" |
12 | 12 |
13 namespace mojo { | 13 namespace mojo { |
14 | |
15 class Message; | |
16 | |
14 namespace internal { | 17 namespace internal { |
15 | 18 |
16 enum ValidationError { | 19 enum ValidationError { |
17 // There is no validation error. | 20 // There is no validation error. |
18 VALIDATION_ERROR_NONE, | 21 VALIDATION_ERROR_NONE, |
19 // An object (struct or array) is not 8-byte aligned. | 22 // An object (struct or array) is not 8-byte aligned. |
20 VALIDATION_ERROR_MISALIGNED_OBJECT, | 23 VALIDATION_ERROR_MISALIGNED_OBJECT, |
21 // 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 |
22 // objects. | 25 // objects. |
23 VALIDATION_ERROR_ILLEGAL_MEMORY_RANGE, | 26 VALIDATION_ERROR_ILLEGAL_MEMORY_RANGE, |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
68 // validation logic. | 71 // validation logic. |
69 VALIDATION_ERROR_DESERIALIZATION_FAILED, | 72 VALIDATION_ERROR_DESERIALIZATION_FAILED, |
70 }; | 73 }; |
71 | 74 |
72 const char* ValidationErrorToString(ValidationError error); | 75 const char* ValidationErrorToString(ValidationError error); |
73 | 76 |
74 void ReportValidationError(ValidationContext* context, | 77 void ReportValidationError(ValidationContext* context, |
75 ValidationError error, | 78 ValidationError error, |
76 const char* description = nullptr); | 79 const char* description = nullptr); |
77 | 80 |
81 void ReportValidationErrorForMessage( | |
82 mojo::Message* message, | |
83 ValidationError error, | |
84 const base::StringPiece& description = ""); | |
yzshen1
2016/07/31 07:16:32
nit: does it make sense to use the same type for |
tibell
2016/07/31 23:50:29
Done.
| |
85 | |
78 // Only used by validation tests and when there is only one thread doing message | 86 // Only used by validation tests and when there is only one thread doing message |
79 // validation. | 87 // validation. |
80 class ValidationErrorObserverForTesting { | 88 class ValidationErrorObserverForTesting { |
81 public: | 89 public: |
82 explicit ValidationErrorObserverForTesting(const base::Closure& callback); | 90 explicit ValidationErrorObserverForTesting(const base::Closure& callback); |
83 ~ValidationErrorObserverForTesting(); | 91 ~ValidationErrorObserverForTesting(); |
84 | 92 |
85 ValidationError last_error() const { return last_error_; } | 93 ValidationError last_error() const { return last_error_; } |
86 void set_last_error(ValidationError error) { | 94 void set_last_error(ValidationError error) { |
87 last_error_ = error; | 95 last_error_ = error; |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
130 // | 138 // |
131 // In non-debug build, does nothing (not even compiling |condition|). | 139 // In non-debug build, does nothing (not even compiling |condition|). |
132 #define MOJO_INTERNAL_DLOG_SERIALIZATION_WARNING(condition, error, \ | 140 #define MOJO_INTERNAL_DLOG_SERIALIZATION_WARNING(condition, error, \ |
133 description) \ | 141 description) \ |
134 DLOG_IF(FATAL, (condition) && !ReportSerializationWarning(error)) \ | 142 DLOG_IF(FATAL, (condition) && !ReportSerializationWarning(error)) \ |
135 << "The outgoing message will trigger " \ | 143 << "The outgoing message will trigger " \ |
136 << ValidationErrorToString(error) << " at the receiving side (" \ | 144 << ValidationErrorToString(error) << " at the receiving side (" \ |
137 << description << ")."; | 145 << description << ")."; |
138 | 146 |
139 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_VALIDATION_ERRORS_H_ | 147 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_VALIDATION_ERRORS_H_ |
OLD | NEW |