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

Unified 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, 9 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/wtf_array.h
diff --git a/mojo/public/cpp/bindings/wtf_array.h b/mojo/public/cpp/bindings/wtf_array.h
index b5d1a30c36304ace290d60d6735919ec408083fd..d693ad9e1eed684bd35351640c713fef14c6f9eb 100644
--- a/mojo/public/cpp/bindings/wtf_array.h
+++ b/mojo/public/cpp/bindings/wtf_array.h
@@ -16,6 +16,10 @@
#include "mojo/public/cpp/bindings/type_converter.h"
#include "third_party/WebKit/Source/wtf/Vector.h"
+namespace blink {
+class HeapAllocator;
+}
+
namespace mojo {
// Represents an array backed by WTF::Vector. Comparing with WTF::Vector,
@@ -230,6 +234,21 @@ class WTFArray {
bool is_null_;
};
+// A |TypeConverter| that will create a |WTFArray<T>| containing a copy of the
+// contents of a |WTF::Vector<E, 0, blink::HeapAllocator>|, using
+// |TypeConverter<T, E>| to copy each element. The returned array will always be
+// non-null.
+template <typename T, typename E>
+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.
+ static WTFArray<T> Convert(
+ const WTF::Vector<E, 0, blink::HeapAllocator>& input) {
+ WTFArray<T> result(input.size());
+ for (size_t i = 0; i < input.size(); ++i)
+ result[i] = TypeConverter<T, E>::Convert(input[i]);
+ return std::move(result);
+ }
+};
+
} // namespace mojo
#endif // MOJO_PUBLIC_CPP_BINDINGS_WTF_ARRAY_H_

Powered by Google App Engine
This is Rietveld 408576698