| OLD | NEW |
| 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 MojoHelper_h | 5 #ifndef MojoHelper_h |
| 6 #define MojoHelper_h | 6 #define MojoHelper_h |
| 7 | 7 |
| 8 #include "base/callback.h" | |
| 9 #include "mojo/public/cpp/bindings/wtf_array.h" | 8 #include "mojo/public/cpp/bindings/wtf_array.h" |
| 10 #include "platform/heap/HeapAllocator.h" | 9 #include "platform/heap/HeapAllocator.h" |
| 11 #include "wtf/Functional.h" | |
| 12 #include <utility> | 10 #include <utility> |
| 13 | 11 |
| 14 namespace blink { | |
| 15 | |
| 16 template <typename R, typename... Args> | |
| 17 base::Callback<R(Args...)> createBaseCallback(std::unique_ptr<Function<R(Args...
)>> functor) | |
| 18 { | |
| 19 return static_cast<base::Callback<R(Args...)>>(*functor); | |
| 20 } | |
| 21 | |
| 22 } // namespace blink | |
| 23 | |
| 24 namespace mojo { | 12 namespace mojo { |
| 25 | 13 |
| 26 // A |TypeConverter| that will create a |WTFArray<T>| containing a copy of the | 14 // A |TypeConverter| that will create a |WTFArray<T>| containing a copy of the |
| 27 // contents of a |blink::HeapVector<E>|, using |TypeConverter<T, E>| to copy | 15 // contents of a |blink::HeapVector<E>|, using |TypeConverter<T, E>| to copy |
| 28 // each element. The returned array will always be non-null. | 16 // each element. The returned array will always be non-null. |
| 29 template <typename T, typename E> | 17 template <typename T, typename E> |
| 30 struct TypeConverter<WTFArray<T>, blink::HeapVector<E>> { | 18 struct TypeConverter<WTFArray<T>, blink::HeapVector<E>> { |
| 31 static WTFArray<T> Convert(const blink::HeapVector<E>& input) | 19 static WTFArray<T> Convert(const blink::HeapVector<E>& input) |
| 32 { | 20 { |
| 33 WTFArray<T> result(input.size()); | 21 WTFArray<T> result(input.size()); |
| 34 for (size_t i = 0; i < input.size(); ++i) | 22 for (size_t i = 0; i < input.size(); ++i) |
| 35 result[i] = TypeConverter<T, E>::Convert(input[i]); | 23 result[i] = TypeConverter<T, E>::Convert(input[i]); |
| 36 return std::move(result); | 24 return std::move(result); |
| 37 } | 25 } |
| 38 }; | 26 }; |
| 39 | 27 |
| 40 } // namespace mojo | 28 } // namespace mojo |
| 41 | 29 |
| 42 #endif // MojoHelper_h | 30 #endif // MojoHelper_h |
| OLD | NEW |