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

Unified Diff: mojo/public/cpp/bindings/lib/validation_util.h

Issue 2112093002: Mojo C++ bindings: Merge EncodePointers/DecodePointers into Serialize/Deserialize, respectively. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@61_array_fix
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 side-by-side diff with in-line comments
Download patch
Index: mojo/public/cpp/bindings/lib/validation_util.h
diff --git a/mojo/public/cpp/bindings/lib/validation_util.h b/mojo/public/cpp/bindings/lib/validation_util.h
index 7f861018661c1ba18668fe63c01cacbbdaf7aead..c883392ebc13fae00fd7e629644a5bca880556ae 100644
--- a/mojo/public/cpp/bindings/lib/validation_util.h
+++ b/mojo/public/cpp/bindings/lib/validation_util.h
@@ -21,6 +21,16 @@ namespace internal {
// smaller than |offset|.
bool ValidateEncodedPointer(const uint64_t* offset);
+template <typename T>
+bool ValidatePointer(const Pointer<T>& input,
+ ValidationContext* validation_context) {
+ bool result = ValidateEncodedPointer(&input.offset);
+ if (!result)
+ ReportValidationError(validation_context, VALIDATION_ERROR_ILLEGAL_POINTER);
+
+ return result;
+}
+
// Validates that |data| contains a valid struct header, in terms of alignment
// and size (i.e., the |num_bytes| field of the header is sufficient for storing
// the header itself). Besides, it checks that the memory range
@@ -118,40 +128,18 @@ bool ValidateHandleOrInterfaceNonNullable(
ValidationContext* validation_context);
template <typename T>
-bool ValidateArray(const Pointer<Array_Data<T>>& input,
- ValidationContext* validation_context,
- const ContainerValidateParams* validate_params) {
- if (!ValidateEncodedPointer(&input.offset)) {
- ReportValidationError(validation_context, VALIDATION_ERROR_ILLEGAL_POINTER);
- return false;
- }
-
- return Array_Data<T>::Validate(DecodePointerRaw(&input.offset),
- validation_context, validate_params);
-}
-
-template <typename T>
-bool ValidateMap(const Pointer<T>& input,
- ValidationContext* validation_context,
- const ContainerValidateParams* validate_params) {
- if (!ValidateEncodedPointer(&input.offset)) {
- ReportValidationError(validation_context, VALIDATION_ERROR_ILLEGAL_POINTER);
- return false;
- }
-
- return T::Validate(DecodePointerRaw(&input.offset), validation_context,
- validate_params);
+bool ValidateContainer(const Pointer<T>& input,
+ ValidationContext* validation_context,
+ const ContainerValidateParams* validate_params) {
+ return ValidatePointer(input, validation_context) &&
+ T::Validate(input.Get(), validation_context, validate_params);
}
template <typename T>
bool ValidateStruct(const Pointer<T>& input,
ValidationContext* validation_context) {
- if (!ValidateEncodedPointer(&input.offset)) {
- ReportValidationError(validation_context, VALIDATION_ERROR_ILLEGAL_POINTER);
- return false;
- }
-
- return T::Validate(DecodePointerRaw(&input.offset), validation_context);
+ return ValidatePointer(input, validation_context) &&
+ T::Validate(input.Get(), validation_context);
}
template <typename T>
@@ -163,13 +151,8 @@ bool ValidateInlinedUnion(const T& input,
template <typename T>
bool ValidateNonInlinedUnion(const Pointer<T>& input,
ValidationContext* validation_context) {
- if (!ValidateEncodedPointer(&input.offset)) {
- ReportValidationError(validation_context, VALIDATION_ERROR_ILLEGAL_POINTER);
- return false;
- }
-
- return T::Validate(DecodePointerRaw(&input.offset), validation_context,
- false);
+ return ValidatePointer(input, validation_context) &&
+ T::Validate(input.Get(), validation_context, false);
}
bool ValidateHandleOrInterface(const AssociatedInterface_Data& input,
« no previous file with comments | « mojo/public/cpp/bindings/lib/serialization_util.cc ('k') | mojo/public/cpp/bindings/tests/array_common_test.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698