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

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

Issue 293983026: Mojo cpp bindings: remove redundant validation in Decode*(). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | mojo/public/cpp/bindings/lib/array_internal.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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_ARRAY_INTERNAL_H_ 5 #ifndef MOJO_PUBLIC_CPP_BINDINGS_LIB_ARRAY_INTERNAL_H_
6 #define MOJO_PUBLIC_CPP_BINDINGS_LIB_ARRAY_INTERNAL_H_ 6 #define MOJO_PUBLIC_CPP_BINDINGS_LIB_ARRAY_INTERNAL_H_
7 7
8 #include <new> 8 #include <new>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 99
100 template <typename T> 100 template <typename T>
101 struct ArraySerializationHelper<T, false> { 101 struct ArraySerializationHelper<T, false> {
102 typedef typename ArrayDataTraits<T>::StorageType ElementType; 102 typedef typename ArrayDataTraits<T>::StorageType ElementType;
103 103
104 static void EncodePointersAndHandles(const ArrayHeader* header, 104 static void EncodePointersAndHandles(const ArrayHeader* header,
105 ElementType* elements, 105 ElementType* elements,
106 std::vector<Handle>* handles) { 106 std::vector<Handle>* handles) {
107 } 107 }
108 108
109 static bool DecodePointersAndHandles(const ArrayHeader* header, 109 static void DecodePointersAndHandles(const ArrayHeader* header,
110 ElementType* elements, 110 ElementType* elements,
111 Message* message) { 111 std::vector<Handle>* handles) {
112 return true;
113 } 112 }
114 113
115 static bool ValidateElements(const ArrayHeader* header, 114 static bool ValidateElements(const ArrayHeader* header,
116 const ElementType* elements, 115 const ElementType* elements,
117 BoundsChecker* bounds_checker) { 116 BoundsChecker* bounds_checker) {
118 return true; 117 return true;
119 } 118 }
120 }; 119 };
121 120
122 template <> 121 template <>
123 struct ArraySerializationHelper<Handle, true> { 122 struct ArraySerializationHelper<Handle, true> {
124 typedef ArrayDataTraits<Handle>::StorageType ElementType; 123 typedef ArrayDataTraits<Handle>::StorageType ElementType;
125 124
126 static void EncodePointersAndHandles(const ArrayHeader* header, 125 static void EncodePointersAndHandles(const ArrayHeader* header,
127 ElementType* elements, 126 ElementType* elements,
128 std::vector<Handle>* handles); 127 std::vector<Handle>* handles);
129 128
130 static bool DecodePointersAndHandles(const ArrayHeader* header, 129 static void DecodePointersAndHandles(const ArrayHeader* header,
131 ElementType* elements, 130 ElementType* elements,
132 Message* message); 131 std::vector<Handle>* handles);
133 132
134 static bool ValidateElements(const ArrayHeader* header, 133 static bool ValidateElements(const ArrayHeader* header,
135 const ElementType* elements, 134 const ElementType* elements,
136 BoundsChecker* bounds_checker); 135 BoundsChecker* bounds_checker);
137 }; 136 };
138 137
139 template <typename H> 138 template <typename H>
140 struct ArraySerializationHelper<H, true> { 139 struct ArraySerializationHelper<H, true> {
141 typedef typename ArrayDataTraits<H>::StorageType ElementType; 140 typedef typename ArrayDataTraits<H>::StorageType ElementType;
142 141
143 static void EncodePointersAndHandles(const ArrayHeader* header, 142 static void EncodePointersAndHandles(const ArrayHeader* header,
144 ElementType* elements, 143 ElementType* elements,
145 std::vector<Handle>* handles) { 144 std::vector<Handle>* handles) {
146 ArraySerializationHelper<Handle, true>::EncodePointersAndHandles( 145 ArraySerializationHelper<Handle, true>::EncodePointersAndHandles(
147 header, elements, handles); 146 header, elements, handles);
148 } 147 }
149 148
150 static bool DecodePointersAndHandles(const ArrayHeader* header, 149 static void DecodePointersAndHandles(const ArrayHeader* header,
151 ElementType* elements, 150 ElementType* elements,
152 Message* message) { 151 std::vector<Handle>* handles) {
153 return ArraySerializationHelper<Handle, true>::DecodePointersAndHandles( 152 ArraySerializationHelper<Handle, true>::DecodePointersAndHandles(
154 header, elements, message); 153 header, elements, handles);
155 } 154 }
156 155
157 static bool ValidateElements(const ArrayHeader* header, 156 static bool ValidateElements(const ArrayHeader* header,
158 const ElementType* elements, 157 const ElementType* elements,
159 BoundsChecker* bounds_checker) { 158 BoundsChecker* bounds_checker) {
160 return ArraySerializationHelper<Handle, true>::ValidateElements( 159 return ArraySerializationHelper<Handle, true>::ValidateElements(
161 header, elements, bounds_checker); 160 header, elements, bounds_checker);
162 } 161 }
163 }; 162 };
164 163
165 template <typename P> 164 template <typename P>
166 struct ArraySerializationHelper<P*, false> { 165 struct ArraySerializationHelper<P*, false> {
167 typedef typename ArrayDataTraits<P*>::StorageType ElementType; 166 typedef typename ArrayDataTraits<P*>::StorageType ElementType;
168 167
169 static void EncodePointersAndHandles(const ArrayHeader* header, 168 static void EncodePointersAndHandles(const ArrayHeader* header,
170 ElementType* elements, 169 ElementType* elements,
171 std::vector<Handle>* handles) { 170 std::vector<Handle>* handles) {
172 for (uint32_t i = 0; i < header->num_elements; ++i) 171 for (uint32_t i = 0; i < header->num_elements; ++i)
173 Encode(&elements[i], handles); 172 Encode(&elements[i], handles);
174 } 173 }
175 174
176 static bool DecodePointersAndHandles(const ArrayHeader* header, 175 static void DecodePointersAndHandles(const ArrayHeader* header,
177 ElementType* elements, 176 ElementType* elements,
178 Message* message) { 177 std::vector<Handle>* handles) {
179 for (uint32_t i = 0; i < header->num_elements; ++i) { 178 for (uint32_t i = 0; i < header->num_elements; ++i)
180 if (!Decode(&elements[i], message)) 179 Decode(&elements[i], handles);
181 return false;
182 }
183 return true;
184 } 180 }
185 181
186 static bool ValidateElements(const ArrayHeader* header, 182 static bool ValidateElements(const ArrayHeader* header,
187 const ElementType* elements, 183 const ElementType* elements,
188 BoundsChecker* bounds_checker) { 184 BoundsChecker* bounds_checker) {
189 for (uint32_t i = 0; i < header->num_elements; ++i) { 185 for (uint32_t i = 0; i < header->num_elements; ++i) {
190 if (!ValidateEncodedPointer(&elements[i].offset) || 186 if (!ValidateEncodedPointer(&elements[i].offset) ||
191 !P::Validate(DecodePointerRaw(&elements[i].offset), bounds_checker)) { 187 !P::Validate(DecodePointerRaw(&elements[i].offset), bounds_checker)) {
192 return false; 188 return false;
193 } 189 }
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
251 247
252 const StorageType* storage() const { 248 const StorageType* storage() const {
253 return reinterpret_cast<const StorageType*>( 249 return reinterpret_cast<const StorageType*>(
254 reinterpret_cast<const char*>(this) + sizeof(*this)); 250 reinterpret_cast<const char*>(this) + sizeof(*this));
255 } 251 }
256 252
257 void EncodePointersAndHandles(std::vector<Handle>* handles) { 253 void EncodePointersAndHandles(std::vector<Handle>* handles) {
258 Helper::EncodePointersAndHandles(&header_, storage(), handles); 254 Helper::EncodePointersAndHandles(&header_, storage(), handles);
259 } 255 }
260 256
261 bool DecodePointersAndHandles(Message* message) { 257 void DecodePointersAndHandles(std::vector<Handle>* handles) {
262 return Helper::DecodePointersAndHandles(&header_, storage(), message); 258 Helper::DecodePointersAndHandles(&header_, storage(), handles);
263 } 259 }
264 260
265 private: 261 private:
266 Array_Data(size_t num_bytes, size_t num_elements) { 262 Array_Data(size_t num_bytes, size_t num_elements) {
267 header_.num_bytes = static_cast<uint32_t>(num_bytes); 263 header_.num_bytes = static_cast<uint32_t>(num_bytes);
268 header_.num_elements = static_cast<uint32_t>(num_elements); 264 header_.num_elements = static_cast<uint32_t>(num_elements);
269 } 265 }
270 ~Array_Data() {} 266 ~Array_Data() {}
271 267
272 internal::ArrayHeader header_; 268 internal::ArrayHeader header_;
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
320 }; 316 };
321 317
322 template <> struct WrapperTraits<String, false> { 318 template <> struct WrapperTraits<String, false> {
323 typedef String_Data* DataType; 319 typedef String_Data* DataType;
324 }; 320 };
325 321
326 } // namespace internal 322 } // namespace internal
327 } // namespace mojo 323 } // namespace mojo
328 324
329 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_ARRAY_INTERNAL_H_ 325 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_ARRAY_INTERNAL_H_
OLDNEW
« no previous file with comments | « no previous file | mojo/public/cpp/bindings/lib/array_internal.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698