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 "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/macros.h" | 9 #include "base/macros.h" |
10 #include "mojo/public/cpp/bindings/callback.h" | 10 #include "mojo/public/cpp/bindings/callback.h" |
(...skipping 11 matching lines...) Expand all Loading... |
22 // bound to a message pipe before the interface methods can be called. | 22 // bound to a message pipe before the interface methods can be called. |
23 // | 23 // |
24 // This class is thread hostile, as is the local proxy it manages. All calls to | 24 // This class is thread hostile, as is the local proxy it manages. All calls to |
25 // this class or the proxy should be from the same thread that created it. If | 25 // this class or the proxy should be from the same thread that created it. If |
26 // you need to move the proxy to a different thread, extract the | 26 // you need to move the proxy to a different thread, extract the |
27 // InterfacePtrInfo (containing just the message pipe and any version | 27 // InterfacePtrInfo (containing just the message pipe and any version |
28 // information) using PassInterface(), pass it to a different thread, and | 28 // information) using PassInterface(), pass it to a different thread, and |
29 // create and bind a new InterfacePtr from that thread. | 29 // create and bind a new InterfacePtr from that thread. |
30 template <typename Interface> | 30 template <typename Interface> |
31 class InterfacePtr { | 31 class InterfacePtr { |
32 MOVE_ONLY_TYPE_WITH_MOVE_CONSTRUCTOR_FOR_CPP_03(InterfacePtr) | 32 DISALLOW_COPY_AND_ASSIGN_WITH_MOVE_FOR_BIND(InterfacePtr) |
33 | 33 |
34 public: | 34 public: |
35 // Constructs an unbound InterfacePtr. | 35 // Constructs an unbound InterfacePtr. |
36 InterfacePtr() {} | 36 InterfacePtr() {} |
37 InterfacePtr(decltype(nullptr)) {} | 37 InterfacePtr(decltype(nullptr)) {} |
38 | 38 |
39 // Takes over the binding of another InterfacePtr. | 39 // Takes over the binding of another InterfacePtr. |
40 InterfacePtr(InterfacePtr&& other) { | 40 InterfacePtr(InterfacePtr&& other) { |
41 internal_state_.Swap(&other.internal_state_); | 41 internal_state_.Swap(&other.internal_state_); |
42 } | 42 } |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
205 const MojoAsyncWaiter* waiter = Environment::GetDefaultAsyncWaiter()) { | 205 const MojoAsyncWaiter* waiter = Environment::GetDefaultAsyncWaiter()) { |
206 InterfacePtr<Interface> ptr; | 206 InterfacePtr<Interface> ptr; |
207 if (info.is_valid()) | 207 if (info.is_valid()) |
208 ptr.Bind(info.Pass(), waiter); | 208 ptr.Bind(info.Pass(), waiter); |
209 return ptr.Pass(); | 209 return ptr.Pass(); |
210 } | 210 } |
211 | 211 |
212 } // namespace mojo | 212 } // namespace mojo |
213 | 213 |
214 #endif // MOJO_PUBLIC_CPP_BINDINGS_INTERFACE_PTR_H_ | 214 #endif // MOJO_PUBLIC_CPP_BINDINGS_INTERFACE_PTR_H_ |
OLD | NEW |