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

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

Issue 469393004: Mojo: Add warning of invalid serialization results (in debug build). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 4 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 | Annotate | Revision Log
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 "mojo/public/cpp/system/macros.h" 8 #include "mojo/public/cpp/system/macros.h"
9 9
10 namespace mojo { 10 namespace mojo {
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 59
60 ValidationError last_error() const { return last_error_; } 60 ValidationError last_error() const { return last_error_; }
61 void set_last_error(ValidationError error) { last_error_ = error; } 61 void set_last_error(ValidationError error) { last_error_ = error; }
62 62
63 private: 63 private:
64 ValidationError last_error_; 64 ValidationError last_error_;
65 65
66 MOJO_DISALLOW_COPY_AND_ASSIGN(ValidationErrorObserverForTesting); 66 MOJO_DISALLOW_COPY_AND_ASSIGN(ValidationErrorObserverForTesting);
67 }; 67 };
68 68
69 // Currently it only returns true when there is a 69 // Used only by MOJO_INTERNAL_DLOG_SERIALIZATION_WARNING. Don't use it directly.
70 // ValidationErrorObserverForTesting object alive. In other words, non-nullable 70 //
71 // validation is only turned on during validation tests. 71 // The function returns true if the error is recorded (by a
72 // SerializationWarningObserverForTesting object), false otherwise.
73 bool ReportSerializationWarning(ValidationError error);
74
75 // Only used by serialization tests and when there is only one thread doing
76 // message serialization.
77 class SerializationWarningObserverForTesting {
78 public:
79 SerializationWarningObserverForTesting();
80 ~SerializationWarningObserverForTesting();
81
82 ValidationError last_warning() const { return last_warning_; }
83 void set_last_warning(ValidationError error) { last_warning_ = error; }
84
85 private:
86 ValidationError last_warning_;
87
88 MOJO_DISALLOW_COPY_AND_ASSIGN(SerializationWarningObserverForTesting);
89 };
90
91 // Currently it only returns true during validation and serialization tests.
72 // 92 //
73 // TODO(yzshen): Remove this function and enable non-nullable validation by 93 // TODO(yzshen): Remove this function and enable non-nullable validation by
74 // default. 94 // default.
75 bool IsNonNullableValidationEnabled(); 95 bool IsNonNullableValidationEnabled();
76 96
77 } // namespace internal 97 } // namespace internal
78 } // namespace mojo 98 } // namespace mojo
79 99
100 // In debug build, logs a serialization warning if |condition| evaluates to
101 // true:
102 // - if there is a SerializationWarningObserverForTesting object alive,
103 // records |error| in it;
104 // - otherwise, logs a fatal-level message.
105 // |error| is the validation error that will be triggered by the receiver
106 // of the serialzation result.
107 //
108 // In non-debug build, does nothing (not even compiling |condition|).
109 #define MOJO_INTERNAL_DLOG_SERIALIZATION_WARNING(condition, error) \
110 MOJO_DLOG_IF(FATAL, (condition) && !ReportSerializationWarning(error)) \
111 << "The outgoing message will trigger " \
112 << ValidationErrorToString(error) << " at the receiving side.";
113
80 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_VALIDATION_ERRORS_H_ 114 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_VALIDATION_ERRORS_H_
OLDNEW
« no previous file with comments | « mojo/public/cpp/bindings/lib/array_serialization.h ('k') | mojo/public/cpp/bindings/lib/validation_errors.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698