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

Side by Side Diff: mojo/public/cpp/bindings/wtf_array.h

Issue 1753543002: PaymentRequest Mojo bindings. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@interface
Patch Set: Rebase Created 4 years, 8 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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_WTF_ARRAY_H_ 5 #ifndef MOJO_PUBLIC_CPP_BINDINGS_WTF_ARRAY_H_
6 #define MOJO_PUBLIC_CPP_BINDINGS_WTF_ARRAY_H_ 6 #define MOJO_PUBLIC_CPP_BINDINGS_WTF_ARRAY_H_
7 7
8 #include <stddef.h> 8 #include <stddef.h>
9 #include <utility> 9 #include <utility>
10 10
11 #include "base/move.h" 11 #include "base/move.h"
12 #include "mojo/public/cpp/bindings/lib/array_internal.h" 12 #include "mojo/public/cpp/bindings/lib/array_internal.h"
13 #include "mojo/public/cpp/bindings/lib/bindings_internal.h" 13 #include "mojo/public/cpp/bindings/lib/bindings_internal.h"
14 #include "mojo/public/cpp/bindings/lib/template_util.h" 14 #include "mojo/public/cpp/bindings/lib/template_util.h"
15 #include "mojo/public/cpp/bindings/lib/value_traits.h" 15 #include "mojo/public/cpp/bindings/lib/value_traits.h"
16 #include "mojo/public/cpp/bindings/type_converter.h" 16 #include "mojo/public/cpp/bindings/type_converter.h"
17 #include "third_party/WebKit/Source/wtf/Vector.h" 17 #include "third_party/WebKit/Source/wtf/Vector.h"
18 18
19 namespace blink {
20 class HeapAllocator;
21 }
22
19 namespace mojo { 23 namespace mojo {
20 24
21 // Represents an array backed by WTF::Vector. Comparing with WTF::Vector, 25 // Represents an array backed by WTF::Vector. Comparing with WTF::Vector,
22 // mojo::WTFArray is move-only and can be null. 26 // mojo::WTFArray is move-only and can be null.
23 // It is easy to convert between WTF::Vector<T> and mojo::WTFArray<T>: 27 // It is easy to convert between WTF::Vector<T> and mojo::WTFArray<T>:
24 // - constructor WTFArray(WTF::Vector<T>&&) takes the contents of a 28 // - constructor WTFArray(WTF::Vector<T>&&) takes the contents of a
25 // WTF::Vector<T>; 29 // WTF::Vector<T>;
26 // - method PassStorage() passes the underlying WTF::Vector. 30 // - method PassStorage() passes the underlying WTF::Vector.
27 template <typename T> 31 template <typename T>
28 class WTFArray { 32 class WTFArray {
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
223 227
224 void Take(WTFArray* other) { 228 void Take(WTFArray* other) {
225 operator=(nullptr); 229 operator=(nullptr);
226 Swap(other); 230 Swap(other);
227 } 231 }
228 232
229 WTF::Vector<T> vec_; 233 WTF::Vector<T> vec_;
230 bool is_null_; 234 bool is_null_;
231 }; 235 };
232 236
237 // A |TypeConverter| that will create a |WTFArray<T>| containing a copy of the
238 // contents of a |WTF::Vector<E, 0, blink::HeapAllocator>|, using
239 // |TypeConverter<T, E>| to copy each element. The returned array will always be
240 // non-null.
241 template <typename T, typename E>
242 struct TypeConverter<WTFArray<T>, WTF::Vector<E, 0, blink::HeapAllocator>> {
yzshen1 2016/03/29 22:49:31 Is it a common operation to use a non-default allo
please use gerrit instead 2016/03/29 23:08:11 The blink::HeapAllocator is used in blink::HeapVec
yzshen1 2016/03/29 23:20:15 I mean, this TypeConverter is a deep copy.
243 static WTFArray<T> Convert(
244 const WTF::Vector<E, 0, blink::HeapAllocator>& input) {
245 WTFArray<T> result(input.size());
246 for (size_t i = 0; i < input.size(); ++i)
247 result[i] = TypeConverter<T, E>::Convert(input[i]);
248 return std::move(result);
249 }
250 };
251
233 } // namespace mojo 252 } // namespace mojo
234 253
235 #endif // MOJO_PUBLIC_CPP_BINDINGS_WTF_ARRAY_H_ 254 #endif // MOJO_PUBLIC_CPP_BINDINGS_WTF_ARRAY_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698