OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 MOJO_PUBLIC_CPP_BINDINGS_INTERFACE_PTR_H_ | 5 #ifndef MOJO_PUBLIC_CPP_BINDINGS_INTERFACE_PTR_H_ |
6 #define MOJO_PUBLIC_CPP_BINDINGS_INTERFACE_PTR_H_ | 6 #define MOJO_PUBLIC_CPP_BINDINGS_INTERFACE_PTR_H_ |
7 | 7 |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <string> | 10 #include <string> |
(...skipping 13 matching lines...) Expand all Loading... |
24 | 24 |
25 // A pointer to a local proxy of a remote Interface implementation. Uses a | 25 // A pointer to a local proxy of a remote Interface implementation. Uses a |
26 // message pipe to communicate with the remote implementation, and automatically | 26 // message pipe to communicate with the remote implementation, and automatically |
27 // closes the pipe and deletes the proxy on destruction. The pointer must be | 27 // closes the pipe and deletes the proxy on destruction. The pointer must be |
28 // bound to a message pipe before the interface methods can be called. | 28 // bound to a message pipe before the interface methods can be called. |
29 // | 29 // |
30 // This class is thread hostile, as is the local proxy it manages, while bound | 30 // This class is thread hostile, as is the local proxy it manages, while bound |
31 // to a message pipe. All calls to this class or the proxy should be from the | 31 // to a message pipe. All calls to this class or the proxy should be from the |
32 // same thread that bound it. If you need to move the proxy to a different | 32 // same thread that bound it. If you need to move the proxy to a different |
33 // thread, extract the InterfacePtrInfo (containing just the message pipe and | 33 // thread, extract the InterfacePtrInfo (containing just the message pipe and |
34 // any version information) using PassInterface(), pass it to a different | 34 // any version information) using PassInterface() on the original thread, pass |
35 // thread, and create and bind a new InterfacePtr from that thread. If an | 35 // it to a different thread, and create and bind a new InterfacePtr from that |
36 // InterfacePtr is not bound to a message pipe, it may be bound or destroyed on | 36 // thread. If an InterfacePtr is not bound to a message pipe, it may be bound or |
37 // any thread. | 37 // destroyed on any thread. |
38 template <typename Interface> | 38 template <typename Interface> |
39 class InterfacePtr { | 39 class InterfacePtr { |
40 public: | 40 public: |
41 using InterfaceType = Interface; | 41 using InterfaceType = Interface; |
42 using PtrInfoType = InterfacePtrInfo<Interface>; | 42 using PtrInfoType = InterfacePtrInfo<Interface>; |
43 | 43 |
44 // Constructs an unbound InterfacePtr. | 44 // Constructs an unbound InterfacePtr. |
45 InterfacePtr() {} | 45 InterfacePtr() {} |
46 InterfacePtr(decltype(nullptr)) {} | 46 InterfacePtr(decltype(nullptr)) {} |
47 | 47 |
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
233 base::ThreadTaskRunnerHandle::Get()) { | 233 base::ThreadTaskRunnerHandle::Get()) { |
234 InterfacePtr<Interface> ptr; | 234 InterfacePtr<Interface> ptr; |
235 if (info.is_valid()) | 235 if (info.is_valid()) |
236 ptr.Bind(std::move(info), std::move(runner)); | 236 ptr.Bind(std::move(info), std::move(runner)); |
237 return std::move(ptr); | 237 return std::move(ptr); |
238 } | 238 } |
239 | 239 |
240 } // namespace mojo | 240 } // namespace mojo |
241 | 241 |
242 #endif // MOJO_PUBLIC_CPP_BINDINGS_INTERFACE_PTR_H_ | 242 #endif // MOJO_PUBLIC_CPP_BINDINGS_INTERFACE_PTR_H_ |
OLD | NEW |