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

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

Issue 2250183003: Make the fuchsia mojo/public repo the source of truth. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 4 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « mojo/public/cpp/bindings/lib/iterator_util.h ('k') | mojo/public/cpp/bindings/lib/map_internal.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/public/cpp/bindings/lib/map_data_internal.h
diff --git a/mojo/public/cpp/bindings/lib/map_data_internal.h b/mojo/public/cpp/bindings/lib/map_data_internal.h
deleted file mode 100644
index d8eefd7a933e41c8a9ec7a37f09e89de19e2db94..0000000000000000000000000000000000000000
--- a/mojo/public/cpp/bindings/lib/map_data_internal.h
+++ /dev/null
@@ -1,154 +0,0 @@
-// Copyright 2014 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef MOJO_PUBLIC_CPP_BINDINGS_LIB_MAP_DATA_INTERNAL_H_
-#define MOJO_PUBLIC_CPP_BINDINGS_LIB_MAP_DATA_INTERNAL_H_
-
-#include <string>
-#include <vector>
-
-#include "mojo/public/cpp/bindings/lib/array_internal.h"
-#include "mojo/public/cpp/bindings/lib/validate_params.h"
-#include "mojo/public/cpp/bindings/lib/validation_errors.h"
-#include "mojo/public/cpp/bindings/lib/validation_util.h"
-
-namespace mojo {
-namespace internal {
-
-inline const ArrayValidateParams* GetMapKeyValidateParamsDefault() {
- // The memory allocated here never gets released to not cause an exit time
- // destructor.
- static const ArrayValidateParams* validate_params =
- new ArrayValidateParams(0, false, nullptr);
- return validate_params;
-}
-
-inline const ArrayValidateParams* GetMapKeyValidateParamsForStrings() {
- // The memory allocated here never gets released to not cause an exit time
- // destructor.
- static const ArrayValidateParams* validate_params = new ArrayValidateParams(
- 0, false, new ArrayValidateParams(0, false, nullptr));
- return validate_params;
-}
-
-template <typename MapKey>
-struct MapKeyValidateParamsFactory {
- static const ArrayValidateParams* Get() {
- return GetMapKeyValidateParamsDefault();
- }
-};
-
-// For non-nullable strings only. (Which is OK; map keys can't be null.)
-template <>
-struct MapKeyValidateParamsFactory<mojo::internal::Array_Data<char>*> {
- static const ArrayValidateParams* Get() {
- return GetMapKeyValidateParamsForStrings();
- }
-};
-
-// Map serializes into a struct which has two arrays as struct fields, the keys
-// and the values.
-// TODO(vardhan): Fill out the missing validation error messages.
-template <typename Key, typename Value>
-class Map_Data {
- public:
- static Map_Data* New(Buffer* buf) {
- return new (buf->Allocate(sizeof(Map_Data))) Map_Data();
- }
-
- static ValidationError Validate(
- const void* data,
- BoundsChecker* bounds_checker,
- const ArrayValidateParams* value_validate_params,
- std::string* err) {
- if (!data)
- return ValidationError::NONE;
-
- ValidationError retval =
- ValidateStructHeaderAndClaimMemory(data, bounds_checker, err);
- if (retval != ValidationError::NONE)
- return retval;
-
- const Map_Data* object = static_cast<const Map_Data*>(data);
- if (object->header_.num_bytes != sizeof(Map_Data) ||
- object->header_.version != 0) {
- MOJO_INTERNAL_DEBUG_SET_ERROR_MSG(err) << "";
- return ValidationError::UNEXPECTED_STRUCT_HEADER;
- }
-
- if (!ValidateEncodedPointer(&object->keys.offset)) {
- MOJO_INTERNAL_DEBUG_SET_ERROR_MSG(err) << "";
- return ValidationError::ILLEGAL_POINTER;
- }
-
- if (!object->keys.offset) {
- MOJO_INTERNAL_DEBUG_SET_ERROR_MSG(err) << "null key array in map struct";
- return ValidationError::UNEXPECTED_NULL_POINTER;
- }
-
- const ArrayValidateParams* key_validate_params =
- MapKeyValidateParamsFactory<Key>::Get();
- retval =
- Array_Data<Key>::Validate(DecodePointerRaw(&object->keys.offset),
- bounds_checker, key_validate_params, err);
- if (retval != ValidationError::NONE)
- return retval;
-
- if (!ValidateEncodedPointer(&object->values.offset)) {
- MOJO_INTERNAL_DEBUG_SET_ERROR_MSG(err) << "";
- return ValidationError::ILLEGAL_POINTER;
- }
-
- if (!object->values.offset) {
- MOJO_INTERNAL_DEBUG_SET_ERROR_MSG(err)
- << "null value array in map struct";
- return ValidationError::UNEXPECTED_NULL_POINTER;
- }
-
- retval =
- Array_Data<Value>::Validate(DecodePointerRaw(&object->values.offset),
- bounds_checker, value_validate_params, err);
- if (retval != ValidationError::NONE)
- return retval;
-
- const ArrayHeader* key_header =
- static_cast<const ArrayHeader*>(DecodePointerRaw(&object->keys.offset));
- const ArrayHeader* value_header = static_cast<const ArrayHeader*>(
- DecodePointerRaw(&object->values.offset));
- if (key_header->num_elements != value_header->num_elements) {
- MOJO_INTERNAL_DEBUG_SET_ERROR_MSG(err) << "";
- return ValidationError::DIFFERENT_SIZED_ARRAYS_IN_MAP;
- }
-
- return ValidationError::NONE;
- }
-
- StructHeader header_;
-
- ArrayPointer<Key> keys;
- ArrayPointer<Value> values;
-
- void EncodePointersAndHandles(std::vector<mojo::Handle>* handles) {
- Encode(&keys, handles);
- Encode(&values, handles);
- }
-
- void DecodePointersAndHandles(std::vector<mojo::Handle>* handles) {
- Decode(&keys, handles);
- Decode(&values, handles);
- }
-
- private:
- Map_Data() {
- header_.num_bytes = sizeof(*this);
- header_.version = 0;
- }
- ~Map_Data() = delete;
-};
-static_assert(sizeof(Map_Data<char, char>) == 24, "Bad sizeof(Map_Data)");
-
-} // namespace internal
-} // namespace mojo
-
-#endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_MAP_DATA_INTERNAL_H_
« no previous file with comments | « mojo/public/cpp/bindings/lib/iterator_util.h ('k') | mojo/public/cpp/bindings/lib/map_internal.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698