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

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

Issue 2358133002: Turn //mojo/public/cpp/bindings and //mojo/public/cpp/system into components (Closed)
Patch Set: Fix wording Created 4 years, 3 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/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/bindings_export.h"
11 #include "mojo/public/cpp/bindings/lib/validation_context.h" 12 #include "mojo/public/cpp/bindings/lib/validation_context.h"
12 13
13 namespace mojo { 14 namespace mojo {
14 15
15 class Message; 16 class Message;
16 17
17 namespace internal { 18 namespace internal {
18 19
19 enum ValidationError { 20 enum ValidationError {
20 // There is no validation error. 21 // There is no validation error.
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 // A value of a non-extensible enum type is unknown. 69 // A value of a non-extensible enum type is unknown.
69 VALIDATION_ERROR_UNKNOWN_ENUM_VALUE, 70 VALIDATION_ERROR_UNKNOWN_ENUM_VALUE,
70 // Message deserialization failure, for example due to rejection by custom 71 // Message deserialization failure, for example due to rejection by custom
71 // validation logic. 72 // validation logic.
72 VALIDATION_ERROR_DESERIALIZATION_FAILED, 73 VALIDATION_ERROR_DESERIALIZATION_FAILED,
73 // The message contains a too deeply nested value, for example a recursively 74 // The message contains a too deeply nested value, for example a recursively
74 // defined field which runtime value is too large. 75 // defined field which runtime value is too large.
75 VALIDATION_ERROR_MAX_RECURSION_DEPTH, 76 VALIDATION_ERROR_MAX_RECURSION_DEPTH,
76 }; 77 };
77 78
78 const char* ValidationErrorToString(ValidationError error); 79 MOJO_CPP_BINDINGS_EXPORT const char* ValidationErrorToString(
80 ValidationError error);
79 81
80 void ReportValidationError(ValidationContext* context, 82 MOJO_CPP_BINDINGS_EXPORT void ReportValidationError(
81 ValidationError error, 83 ValidationContext* context,
82 const char* description = nullptr); 84 ValidationError error,
85 const char* description = nullptr);
83 86
84 void ReportValidationErrorForMessage( 87 MOJO_CPP_BINDINGS_EXPORT void ReportValidationErrorForMessage(
85 mojo::Message* message, 88 mojo::Message* message,
86 ValidationError error, 89 ValidationError error,
87 const char* description = nullptr); 90 const char* description = nullptr);
88 91
89 // Only used by validation tests and when there is only one thread doing message 92 // Only used by validation tests and when there is only one thread doing message
90 // validation. 93 // validation.
91 class ValidationErrorObserverForTesting { 94 class MOJO_CPP_BINDINGS_EXPORT ValidationErrorObserverForTesting {
92 public: 95 public:
93 explicit ValidationErrorObserverForTesting(const base::Closure& callback); 96 explicit ValidationErrorObserverForTesting(const base::Closure& callback);
94 ~ValidationErrorObserverForTesting(); 97 ~ValidationErrorObserverForTesting();
95 98
96 ValidationError last_error() const { return last_error_; } 99 ValidationError last_error() const { return last_error_; }
97 void set_last_error(ValidationError error) { 100 void set_last_error(ValidationError error) {
98 last_error_ = error; 101 last_error_ = error;
99 callback_.Run(); 102 callback_.Run();
100 } 103 }
101 104
102 private: 105 private:
103 ValidationError last_error_; 106 ValidationError last_error_;
104 base::Closure callback_; 107 base::Closure callback_;
105 108
106 DISALLOW_COPY_AND_ASSIGN(ValidationErrorObserverForTesting); 109 DISALLOW_COPY_AND_ASSIGN(ValidationErrorObserverForTesting);
107 }; 110 };
108 111
109 // Used only by MOJO_INTERNAL_DLOG_SERIALIZATION_WARNING. Don't use it directly. 112 // Used only by MOJO_INTERNAL_DLOG_SERIALIZATION_WARNING. Don't use it directly.
110 // 113 //
111 // The function returns true if the error is recorded (by a 114 // The function returns true if the error is recorded (by a
112 // SerializationWarningObserverForTesting object), false otherwise. 115 // SerializationWarningObserverForTesting object), false otherwise.
113 bool ReportSerializationWarning(ValidationError error); 116 MOJO_CPP_BINDINGS_EXPORT bool ReportSerializationWarning(ValidationError error);
114 117
115 // Only used by serialization tests and when there is only one thread doing 118 // Only used by serialization tests and when there is only one thread doing
116 // message serialization. 119 // message serialization.
117 class SerializationWarningObserverForTesting { 120 class MOJO_CPP_BINDINGS_EXPORT SerializationWarningObserverForTesting {
118 public: 121 public:
119 SerializationWarningObserverForTesting(); 122 SerializationWarningObserverForTesting();
120 ~SerializationWarningObserverForTesting(); 123 ~SerializationWarningObserverForTesting();
121 124
122 ValidationError last_warning() const { return last_warning_; } 125 ValidationError last_warning() const { return last_warning_; }
123 void set_last_warning(ValidationError error) { last_warning_ = error; } 126 void set_last_warning(ValidationError error) { last_warning_ = error; }
124 127
125 private: 128 private:
126 ValidationError last_warning_; 129 ValidationError last_warning_;
127 130
(...skipping 13 matching lines...) Expand all
141 // 144 //
142 // In non-debug build, does nothing (not even compiling |condition|). 145 // In non-debug build, does nothing (not even compiling |condition|).
143 #define MOJO_INTERNAL_DLOG_SERIALIZATION_WARNING(condition, error, \ 146 #define MOJO_INTERNAL_DLOG_SERIALIZATION_WARNING(condition, error, \
144 description) \ 147 description) \
145 DLOG_IF(FATAL, (condition) && !ReportSerializationWarning(error)) \ 148 DLOG_IF(FATAL, (condition) && !ReportSerializationWarning(error)) \
146 << "The outgoing message will trigger " \ 149 << "The outgoing message will trigger " \
147 << ValidationErrorToString(error) << " at the receiving side (" \ 150 << ValidationErrorToString(error) << " at the receiving side (" \
148 << description << ")."; 151 << description << ").";
149 152
150 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_VALIDATION_ERRORS_H_ 153 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_VALIDATION_ERRORS_H_
OLDNEW
« no previous file with comments | « mojo/public/cpp/bindings/lib/validation_context.h ('k') | mojo/public/cpp/bindings/lib/validation_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698