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

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

Issue 2036623002: Validate map keys in C++ Mojo bindings (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address review comments Created 4 years, 7 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
« no previous file with comments | « mojo/public/cpp/bindings/lib/map_serialization.h ('k') | mojo/public/cpp/bindings/lib/validation_util.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/public/cpp/bindings/lib/validate_params.h
diff --git a/mojo/public/cpp/bindings/lib/validate_params.h b/mojo/public/cpp/bindings/lib/validate_params.h
index 2509b6bb0a6457d227739ff5de14fba3bf0b507f..ee6e1f31e41af0cfc22f0ad209b9d3b4e2307b0c 100644
--- a/mojo/public/cpp/bindings/lib/validate_params.h
+++ b/mojo/public/cpp/bindings/lib/validate_params.h
@@ -14,44 +14,68 @@ namespace internal {
using ValidateEnumFunc = bool (*)(int32_t);
+// TODO(tibell): Rename to ContainerValidateParams.
class ArrayValidateParams {
public:
+ // Validates a map. A map is validated as a pair of arrays, one for the keys
+ // and one for the values. Both arguments must be non-null.
+ //
+ // ArrayValidateParams takes ownership of |in_key_validate params| and
+ // |in_element_validate params|.
+ ArrayValidateParams(ArrayValidateParams* in_key_validate_params,
+ ArrayValidateParams* in_element_validate_params)
+ : key_validate_params(in_key_validate_params),
+ element_validate_params(in_element_validate_params) {
+ DCHECK(in_key_validate_params)
+ << "Map validate params require key validate params";
+ DCHECK(in_element_validate_params)
+ << "Map validate params require element validate params";
+ }
+
+ // Validates an array.
+ //
// ArrayValidateParams takes ownership of |in_element_validate params|.
ArrayValidateParams(uint32_t in_expected_num_elements,
bool in_element_is_nullable,
ArrayValidateParams* in_element_validate_params)
: expected_num_elements(in_expected_num_elements),
element_is_nullable(in_element_is_nullable),
- element_validate_params(in_element_validate_params),
- validate_enum_func(nullptr) {}
+ element_validate_params(in_element_validate_params) {}
// Validates an array of enums.
ArrayValidateParams(uint32_t in_expected_num_elements,
ValidateEnumFunc in_validate_enum_func)
: expected_num_elements(in_expected_num_elements),
- element_is_nullable(false),
- element_validate_params(nullptr),
validate_enum_func(in_validate_enum_func) {}
~ArrayValidateParams() {
if (element_validate_params)
delete element_validate_params;
+ if (key_validate_params)
+ delete key_validate_params;
}
// If |expected_num_elements| is not 0, the array is expected to have exactly
// that number of elements.
- uint32_t expected_num_elements;
+ uint32_t expected_num_elements = 0;
// Whether the elements are nullable.
- bool element_is_nullable;
+ bool element_is_nullable = false;
+
+ // Validation information for the map key array. May contain other
+ // ArrayValidateParams e.g. if the keys are strings.
+ ArrayValidateParams* key_validate_params = nullptr;
- // Validation information for elements. It is either a pointer to another
- // instance of ArrayValidateParams (if elements are arrays or maps), or
- // nullptr. In the case of maps, this is used to validate the value array.
- ArrayValidateParams* element_validate_params;
+ // For arrays: validation information for elements. It is either a pointer to
+ // another instance of ArrayValidateParams (if elements are arrays or maps),
+ // or nullptr.
+ //
+ // For maps: validation information for the whole value array. May contain
+ // other ArrayValidateParams e.g. if the values are arrays or maps.
+ ArrayValidateParams* element_validate_params = nullptr;
// Validation function for enum elements.
- ValidateEnumFunc validate_enum_func;
+ ValidateEnumFunc validate_enum_func = nullptr;
private:
DISALLOW_COPY_AND_ASSIGN(ArrayValidateParams);
« no previous file with comments | « mojo/public/cpp/bindings/lib/map_serialization.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