Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1054)

Side by Side Diff: mojo/public/cpp/bindings/lib/validation_errors.h

Issue 2064903002: Mojo: Report bindings validation errors via MojoNotifyBadMessage (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 // Message deserialization failure, for example due to rejection by custom
68 // 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
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_
OLDNEW
« no previous file with comments | « mojo/public/cpp/bindings/lib/validation_context.cc ('k') | mojo/public/cpp/bindings/lib/validation_errors.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698