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 BindForMojo_h | 5 #ifndef BindForMojo_h |
6 #define BindForMojo_h | 6 #define BindForMojo_h |
7 | 7 |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "mojo/public/cpp/bindings/callback.h" | 9 #include "mojo/public/cpp/bindings/callback.h" |
10 | 10 |
11 // This file provides limited access to base::Bind() function. base::Bind() | 11 // This file provides limited access to base::Bind() function. base::Bind() |
12 // could be dangerous if it's used across threads, so we don't want to allow | 12 // could be dangerous if it's used across threads, so we don't want to allow |
13 // general use of base::Bind(). | 13 // general use of base::Bind(). |
14 // See also "platform/ThreadSafeFunctional.h". | 14 // See also "platform/ThreadSafeFunctional.h". |
15 | 15 |
16 namespace blink { | 16 namespace blink { |
17 | 17 |
18 // Binds an instance of a class to its member function. Does not bind anything | 18 // Binds an instance of a class to its member function. Does not bind anything |
19 // else. | 19 // else. |
20 template <typename Class, typename ReturnType, typename... Args> | 20 template <typename Class, typename ReturnType, typename... Args> |
21 mojo::Callback<ReturnType(Args...)> | 21 mojo::Callback<ReturnType(Args...)> |
22 sameThreadBindForMojo(ReturnType (Class::*method)(Args...), Class* instance) | 22 sameThreadBindForMojo(ReturnType (Class::*method)(Args...), Class* instance) |
23 { | 23 { |
24 return base::Bind(method, base::Unretained(instance)); | 24 return base::Bind(method, base::Unretained(instance)); |
25 } | 25 } |
26 | 26 |
27 template <typename Class, typename ReturnType, typename BoundArgs, typename... A rgs> | |
28 mojo::Callback<ReturnType(Args...)> | |
29 sameThreadBindForMojoWithBoundArgs(ReturnType (Class::*method)(BoundArgs*, Args. ..), Class* instance, BoundArgs* bound) | |
30 { | |
31 return base::Bind(method, base::Unretained(instance), base::Unretained(bound )); | |
Yuki
2016/03/22 07:15:03
In general, this is not a good idea because it's n
RaviKasibhatla
2016/03/23 15:20:50
In GetDevices, the original Web callback is being
Yuki
2016/03/25 09:49:04
I'm talking about not only VRGetDevicesRequest's c
haraken
2016/03/25 09:56:36
Dcheng and Dana are working on it (https://bugs.ch
| |
32 } | |
33 | |
27 } // namespace blink | 34 } // namespace blink |
28 | 35 |
29 #endif // BindForMojo_h | 36 #endif // BindForMojo_h |
OLD | NEW |