| 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/sequenced_task_runner.h" |
| 18 #include "base/threading/thread_task_runner_handle.h" | 18 #include "base/threading/sequenced_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; | 25 class AssociatedGroup; |
| 26 | 26 |
| 27 // A pointer to a local proxy of a remote Interface implementation. Uses a | 27 // A pointer to a local proxy of a remote Interface implementation. Uses a |
| 28 // message pipe to communicate with the remote implementation, and automatically | 28 // message pipe to communicate with the remote implementation, and automatically |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 71 // | 71 // |
| 72 // Calling with an invalid |info| (containing an invalid message pipe handle) | 72 // Calling with an invalid |info| (containing an invalid message pipe handle) |
| 73 // has the same effect as reset(). In this case, the InterfacePtr is not | 73 // has the same effect as reset(). In this case, the InterfacePtr is not |
| 74 // considered as bound. | 74 // considered as bound. |
| 75 // | 75 // |
| 76 // |runner| must belong to the same thread. It will be used to dispatch all | 76 // |runner| must belong to the same thread. It will be used to dispatch all |
| 77 // callbacks and connection error notification. It is useful when you attach | 77 // callbacks and connection error notification. It is useful when you attach |
| 78 // multiple task runners to a single thread for the purposes of task | 78 // multiple task runners to a single thread for the purposes of task |
| 79 // scheduling. | 79 // scheduling. |
| 80 void Bind(InterfacePtrInfo<Interface> info, | 80 void Bind(InterfacePtrInfo<Interface> info, |
| 81 scoped_refptr<base::SingleThreadTaskRunner> runner = | 81 scoped_refptr<base::SequencedTaskRunner> runner = |
| 82 base::ThreadTaskRunnerHandle::Get()) { | 82 base::SequencedTaskRunnerHandle::Get()) { |
| 83 reset(); | 83 reset(); |
| 84 if (info.is_valid()) | 84 if (info.is_valid()) |
| 85 internal_state_.Bind(std::move(info), std::move(runner)); | 85 internal_state_.Bind(std::move(info), std::move(runner)); |
| 86 } | 86 } |
| 87 | 87 |
| 88 // Returns whether or not this InterfacePtr is bound to a message pipe. | 88 // Returns whether or not this InterfacePtr is bound to a message pipe. |
| 89 bool is_bound() const { return internal_state_.is_bound(); } | 89 bool is_bound() const { return internal_state_.is_bound(); } |
| 90 | 90 |
| 91 // Returns a raw pointer to the local proxy. Caller does not take ownership. | 91 // Returns a raw pointer to the local proxy. Caller does not take ownership. |
| 92 // Note that the local proxy is thread hostile, as stated above. | 92 // Note that the local proxy is thread hostile, as stated above. |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 229 mutable State internal_state_; | 229 mutable State internal_state_; |
| 230 | 230 |
| 231 DISALLOW_COPY_AND_ASSIGN(InterfacePtr); | 231 DISALLOW_COPY_AND_ASSIGN(InterfacePtr); |
| 232 }; | 232 }; |
| 233 | 233 |
| 234 // If |info| is valid (containing a valid message pipe handle), returns an | 234 // If |info| is valid (containing a valid message pipe handle), returns an |
| 235 // InterfacePtr bound to it. Otherwise, returns an unbound InterfacePtr. | 235 // InterfacePtr bound to it. Otherwise, returns an unbound InterfacePtr. |
| 236 template <typename Interface> | 236 template <typename Interface> |
| 237 InterfacePtr<Interface> MakeProxy( | 237 InterfacePtr<Interface> MakeProxy( |
| 238 InterfacePtrInfo<Interface> info, | 238 InterfacePtrInfo<Interface> info, |
| 239 scoped_refptr<base::SingleThreadTaskRunner> runner = | 239 scoped_refptr<base::SequencedTaskRunner> runner = |
| 240 base::ThreadTaskRunnerHandle::Get()) { | 240 base::SequencedTaskRunnerHandle::Get()) { |
| 241 InterfacePtr<Interface> ptr; | 241 InterfacePtr<Interface> ptr; |
| 242 if (info.is_valid()) | 242 if (info.is_valid()) |
| 243 ptr.Bind(std::move(info), std::move(runner)); | 243 ptr.Bind(std::move(info), std::move(runner)); |
| 244 return std::move(ptr); | 244 return std::move(ptr); |
| 245 } | 245 } |
| 246 | 246 |
| 247 } // namespace mojo | 247 } // namespace mojo |
| 248 | 248 |
| 249 #endif // MOJO_PUBLIC_CPP_BINDINGS_INTERFACE_PTR_H_ | 249 #endif // MOJO_PUBLIC_CPP_BINDINGS_INTERFACE_PTR_H_ |
| OLD | NEW |