| 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/bind.h" | 8 #include "base/bind.h" |
| 9 #include "mojo/public/cpp/bindings/wtf_array.h" | 9 #include "mojo/public/cpp/bindings/wtf_array.h" |
| 10 #include "platform/heap/HeapAllocator.h" | 10 #include "platform/heap/HeapAllocator.h" |
| 11 #include <utility> | 11 #include <utility> |
| 12 | 12 |
| 13 namespace blink { | 13 namespace blink { |
| 14 | 14 |
| 15 namespace internal { | 15 namespace internal { |
| 16 | 16 |
| 17 template <typename R, typename... Args> | 17 template <typename R, typename... Args> |
| 18 R CallWTFFunction(Function<R(Args...)>* functor, Args... args) | 18 R CallWTFFunction(Function<R(Args...)>* functor, Args... args) |
| 19 { | 19 { |
| 20 return (*functor)(std::forward<Args>(args)...); | 20 return (*functor)(std::forward<Args>(args)...); |
| 21 } | 21 } |
| 22 | 22 |
| 23 } | 23 } |
| 24 | 24 |
| 25 template <typename R, typename... Args> | 25 template <typename R, typename... Args> |
| 26 base::Callback<R(Args...)> createBaseCallback(PassOwnPtr<Function<R(Args...)>> f
unctor) |
| 27 { |
| 28 return base::Bind(&internal::CallWTFFunction<R, Args...>, base::Owned(functo
r.leakPtr())); |
| 29 } |
| 30 |
| 31 template <typename R, typename... Args> |
| 26 base::Callback<R(Args...)> createBaseCallback(std::unique_ptr<Function<R(Args...
)>> functor) | 32 base::Callback<R(Args...)> createBaseCallback(std::unique_ptr<Function<R(Args...
)>> functor) |
| 27 { | 33 { |
| 28 return base::Bind(&internal::CallWTFFunction<R, Args...>, base::Owned(functo
r.release())); | 34 return base::Bind(&internal::CallWTFFunction<R, Args...>, base::Owned(functo
r.release())); |
| 29 } | 35 } |
| 30 | 36 |
| 31 } // namespace blink | 37 } // namespace blink |
| 32 | 38 |
| 33 namespace mojo { | 39 namespace mojo { |
| 34 | 40 |
| 35 // A |TypeConverter| that will create a |WTFArray<T>| containing a copy of the | 41 // A |TypeConverter| that will create a |WTFArray<T>| containing a copy of the |
| 36 // contents of a |blink::HeapVector<E>|, using |TypeConverter<T, E>| to copy | 42 // contents of a |blink::HeapVector<E>|, using |TypeConverter<T, E>| to copy |
| 37 // each element. The returned array will always be non-null. | 43 // each element. The returned array will always be non-null. |
| 38 template <typename T, typename E> | 44 template <typename T, typename E> |
| 39 struct TypeConverter<WTFArray<T>, blink::HeapVector<E>> { | 45 struct TypeConverter<WTFArray<T>, blink::HeapVector<E>> { |
| 40 static WTFArray<T> Convert(const blink::HeapVector<E>& input) | 46 static WTFArray<T> Convert(const blink::HeapVector<E>& input) |
| 41 { | 47 { |
| 42 WTFArray<T> result(input.size()); | 48 WTFArray<T> result(input.size()); |
| 43 for (size_t i = 0; i < input.size(); ++i) | 49 for (size_t i = 0; i < input.size(); ++i) |
| 44 result[i] = TypeConverter<T, E>::Convert(input[i]); | 50 result[i] = TypeConverter<T, E>::Convert(input[i]); |
| 45 return std::move(result); | 51 return std::move(result); |
| 46 } | 52 } |
| 47 }; | 53 }; |
| 48 | 54 |
| 49 } // namespace mojo | 55 } // namespace mojo |
| 50 | 56 |
| 51 #endif // MojoHelper_h | 57 #endif // MojoHelper_h |
| OLD | NEW |