| 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> |
| 11 #include <utility> | 11 #include <utility> |
| 12 | 12 |
| 13 #include "base/callback_forward.h" | 13 #include "base/callback_forward.h" |
| 14 #include "base/logging.h" | 14 #include "base/logging.h" |
| 15 #include "base/macros.h" | 15 #include "base/macros.h" |
| 16 #include "base/memory/ref_counted.h" | 16 #include "base/memory/ref_counted.h" |
| 17 #include "base/single_thread_task_runner.h" | 17 #include "base/single_thread_task_runner.h" |
| 18 #include "base/threading/thread_task_runner_handle.h" | 18 #include "base/threading/thread_task_runner_handle.h" |
| 19 #include "mojo/public/cpp/bindings/connection_error_callback.h" | 19 #include "mojo/public/cpp/bindings/connection_error_callback.h" |
| 20 #include "mojo/public/cpp/bindings/interface_ptr_info.h" | 20 #include "mojo/public/cpp/bindings/interface_ptr_info.h" |
| 21 #include "mojo/public/cpp/bindings/lib/interface_ptr_state.h" | 21 #include "mojo/public/cpp/bindings/lib/interface_ptr_state.h" |
| 22 | 22 |
| 23 namespace mojo { | 23 namespace mojo { |
| 24 | 24 |
| 25 class AssociatedGroup; | |
| 26 | |
| 27 // 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 |
| 28 // message pipe to communicate with the remote implementation, and automatically | 26 // message pipe to communicate with the remote implementation, and automatically |
| 29 // 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 |
| 30 // 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. |
| 31 // | 29 // |
| 32 // 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 |
| 33 // 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 |
| 34 // 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 |
| 35 // thread, extract the InterfacePtrInfo (containing just the message pipe and | 33 // thread, extract the InterfacePtrInfo (containing just the message pipe and |
| 36 // any version information) using PassInterface(), pass it to a different | 34 // any version information) using PassInterface(), pass it to a different |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 179 // invalidate associated interface endpoint handles. | 177 // invalidate associated interface endpoint handles. |
| 180 InterfacePtrInfo<Interface> PassInterface() { | 178 InterfacePtrInfo<Interface> PassInterface() { |
| 181 CHECK(!HasAssociatedInterfaces()); | 179 CHECK(!HasAssociatedInterfaces()); |
| 182 CHECK(!internal_state_.has_pending_callbacks()); | 180 CHECK(!internal_state_.has_pending_callbacks()); |
| 183 State state; | 181 State state; |
| 184 internal_state_.Swap(&state); | 182 internal_state_.Swap(&state); |
| 185 | 183 |
| 186 return state.PassInterface(); | 184 return state.PassInterface(); |
| 187 } | 185 } |
| 188 | 186 |
| 189 // Returns the associated group that this object belongs to. Returns null if: | |
| 190 // - this object is not bound; or | |
| 191 // - the interface doesn't have methods to pass associated interface | |
| 192 // pointers or requests. | |
| 193 AssociatedGroup* associated_group() { | |
| 194 return internal_state_.associated_group(); | |
| 195 } | |
| 196 | |
| 197 bool Equals(const InterfacePtr& other) const { | 187 bool Equals(const InterfacePtr& other) const { |
| 198 if (this == &other) | 188 if (this == &other) |
| 199 return true; | 189 return true; |
| 200 | 190 |
| 201 // Now that the two refer to different objects, they are equivalent if | 191 // Now that the two refer to different objects, they are equivalent if |
| 202 // and only if they are both null. | 192 // and only if they are both null. |
| 203 return !(*this) && !other; | 193 return !(*this) && !other; |
| 204 } | 194 } |
| 205 | 195 |
| 206 // DO NOT USE. Exposed only for internal use and for testing. | 196 // DO NOT USE. Exposed only for internal use and for testing. |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 243 base::ThreadTaskRunnerHandle::Get()) { | 233 base::ThreadTaskRunnerHandle::Get()) { |
| 244 InterfacePtr<Interface> ptr; | 234 InterfacePtr<Interface> ptr; |
| 245 if (info.is_valid()) | 235 if (info.is_valid()) |
| 246 ptr.Bind(std::move(info), std::move(runner)); | 236 ptr.Bind(std::move(info), std::move(runner)); |
| 247 return std::move(ptr); | 237 return std::move(ptr); |
| 248 } | 238 } |
| 249 | 239 |
| 250 } // namespace mojo | 240 } // namespace mojo |
| 251 | 241 |
| 252 #endif // MOJO_PUBLIC_CPP_BINDINGS_INTERFACE_PTR_H_ | 242 #endif // MOJO_PUBLIC_CPP_BINDINGS_INTERFACE_PTR_H_ |
| OLD | NEW |