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/message_loop/message_loop.h" | |
8 #include "mojo/public/cpp/bindings/wtf_array.h" | 9 #include "mojo/public/cpp/bindings/wtf_array.h" |
9 #include "platform/heap/HeapAllocator.h" | 10 #include "platform/heap/HeapAllocator.h" |
10 #include <utility> | 11 #include <utility> |
11 | 12 |
12 namespace mojo { | 13 namespace mojo { |
13 | 14 |
14 // A |TypeConverter| that will create a |WTFArray<T>| containing a copy of the | 15 // A |TypeConverter| that will create a |WTFArray<T>| containing a copy of the |
15 // contents of a |blink::HeapVector<E>|, using |TypeConverter<T, E>| to copy | 16 // contents of a |blink::HeapVector<E>|, using |TypeConverter<T, E>| to copy |
16 // each element. The returned array will always be non-null. | 17 // each element. The returned array will always be non-null. |
17 template <typename T, typename E> | 18 template <typename T, typename E> |
18 struct TypeConverter<WTFArray<T>, blink::HeapVector<E>> { | 19 struct TypeConverter<WTFArray<T>, blink::HeapVector<E>> { |
19 static WTFArray<T> Convert(const blink::HeapVector<E>& input) { | 20 static WTFArray<T> Convert(const blink::HeapVector<E>& input) { |
20 WTFArray<T> result(input.size()); | 21 WTFArray<T> result(input.size()); |
21 for (size_t i = 0; i < input.size(); ++i) | 22 for (size_t i = 0; i < input.size(); ++i) |
22 result[i] = TypeConverter<T, E>::Convert(input[i]); | 23 result[i] = TypeConverter<T, E>::Convert(input[i]); |
23 return std::move(result); | 24 return std::move(result); |
24 } | 25 } |
25 }; | 26 }; |
26 | 27 |
27 } // namespace mojo | 28 } // namespace mojo |
28 | 29 |
30 namespace blink { | |
31 | |
32 // Used to get whether message loop is ready for current thread, to help | |
33 // blink::initialize() determining whether can initialize mojo stuff or not. | |
34 // TODO(leonhsl): http://crbug.com/660274 Remove this API by ensuring | |
35 // a message loop before calling blink::initialize(). | |
36 inline bool canInitializeMojo() { | |
37 return base::MessageLoop::current(); | |
38 } | |
39 } | |
kinuko
2016/11/08 11:35:12
nit: // namespace blink
leonhsl(Using Gerrit)
2016/11/08 12:22:39
Done.
| |
40 | |
29 #endif // MojoHelper_h | 41 #endif // MojoHelper_h |
OLD | NEW |