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

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

Issue 1387993002: mojo::Serialize*_() calls now propogate/return validation errors. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Fixed MOJO_DCHECK issues, removed SerializationWarningObserver & addressing trung's CL comments Created 5 years, 2 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 "mojo/public/cpp/system/macros.h" 8 #include "mojo/public/cpp/system/macros.h"
9 9
10 namespace mojo { 10 namespace mojo {
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 71
72 ValidationError last_error() const { return last_error_; } 72 ValidationError last_error() const { return last_error_; }
73 void set_last_error(ValidationError error) { last_error_ = error; } 73 void set_last_error(ValidationError error) { last_error_ = error; }
74 74
75 private: 75 private:
76 ValidationError last_error_; 76 ValidationError last_error_;
77 77
78 MOJO_DISALLOW_COPY_AND_ASSIGN(ValidationErrorObserverForTesting); 78 MOJO_DISALLOW_COPY_AND_ASSIGN(ValidationErrorObserverForTesting);
79 }; 79 };
80 80
81 // Used only by MOJO_INTERNAL_DLOG_SERIALIZATION_WARNING. Don't use it directly.
82 //
83 // The function returns true if the error is recorded (by a
84 // SerializationWarningObserverForTesting object), false otherwise.
85 bool ReportSerializationWarning(ValidationError error);
86
87 // Only used by serialization tests and when there is only one thread doing
88 // message serialization.
89 class SerializationWarningObserverForTesting {
90 public:
91 SerializationWarningObserverForTesting();
92 ~SerializationWarningObserverForTesting();
93
94 ValidationError last_warning() const { return last_warning_; }
95 void set_last_warning(ValidationError error) { last_warning_ = error; }
96
97 private:
98 ValidationError last_warning_;
99
100 MOJO_DISALLOW_COPY_AND_ASSIGN(SerializationWarningObserverForTesting);
101 };
102
103 } // namespace internal 81 } // namespace internal
104 } // namespace mojo 82 } // namespace mojo
105 83
106 // In debug build, logs a serialization warning if |condition| evaluates to 84 // In a debug build, logs a serialization warning.
107 // true: 85 #define MOJO_INTERNAL_DLOG_SERIALIZATION_WARNING(error, description) \
108 // - if there is a SerializationWarningObserverForTesting object alive, 86 MOJO_DLOG(WARNING) << "The outgoing message will trigger " \
109 // records |error| in it; 87 << ValidationErrorToString(error) \
110 // - otherwise, logs a fatal-level message. 88 << " at the receiving side (" << description << ")."
111 // |error| is the validation error that will be triggered by the receiver
112 // of the serialzation result.
113 //
114 // In non-debug build, does nothing (not even compiling |condition|).
115 #define MOJO_INTERNAL_DLOG_SERIALIZATION_WARNING( \
116 condition, error, description) \
117 MOJO_DLOG_IF(FATAL, (condition) && !ReportSerializationWarning(error)) \
118 << "The outgoing message will trigger " \
119 << ValidationErrorToString(error) << " at the receiving side (" \
120 << description << ").";
121 89
122 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_VALIDATION_ERRORS_H_ 90 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_VALIDATION_ERRORS_H_
OLDNEW
« no previous file with comments | « mojo/public/cpp/bindings/lib/map_serialization_forward.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