| 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 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| 11 #include "base/callback_forward.h" | |
| 12 #include "base/logging.h" | 11 #include "base/logging.h" |
| 13 #include "base/macros.h" | 12 #include "base/macros.h" |
| 14 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
| 15 #include "base/single_thread_task_runner.h" | 14 #include "base/single_thread_task_runner.h" |
| 16 #include "base/threading/thread_task_runner_handle.h" | 15 #include "base/threading/thread_task_runner_handle.h" |
| 16 #include "mojo/public/cpp/bindings/callback.h" |
| 17 #include "mojo/public/cpp/bindings/interface_ptr_info.h" | 17 #include "mojo/public/cpp/bindings/interface_ptr_info.h" |
| 18 #include "mojo/public/cpp/bindings/lib/interface_ptr_state.h" | 18 #include "mojo/public/cpp/bindings/lib/interface_ptr_state.h" |
| 19 | 19 |
| 20 namespace mojo { | 20 namespace mojo { |
| 21 | 21 |
| 22 class AssociatedGroup; | 22 class AssociatedGroup; |
| 23 | 23 |
| 24 // A pointer to a local proxy of a remote Interface implementation. Uses a | 24 // A pointer to a local proxy of a remote Interface implementation. Uses a |
| 25 // message pipe to communicate with the remote implementation, and automatically | 25 // message pipe to communicate with the remote implementation, and automatically |
| 26 // closes the pipe and deletes the proxy on destruction. The pointer must be | 26 // closes the pipe and deletes the proxy on destruction. The pointer must be |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 92 // Functions like a pointer to Interface. Must already be bound. | 92 // Functions like a pointer to Interface. Must already be bound. |
| 93 Interface* operator->() const { return get(); } | 93 Interface* operator->() const { return get(); } |
| 94 Interface& operator*() const { return *get(); } | 94 Interface& operator*() const { return *get(); } |
| 95 | 95 |
| 96 // Returns the version number of the interface that the remote side supports. | 96 // Returns the version number of the interface that the remote side supports. |
| 97 uint32_t version() const { return internal_state_.version(); } | 97 uint32_t version() const { return internal_state_.version(); } |
| 98 | 98 |
| 99 // Queries the max version that the remote side supports. On completion, the | 99 // Queries the max version that the remote side supports. On completion, the |
| 100 // result will be returned as the input of |callback|. The version number of | 100 // result will be returned as the input of |callback|. The version number of |
| 101 // this interface pointer will also be updated. | 101 // this interface pointer will also be updated. |
| 102 void QueryVersion(const base::Callback<void(uint32_t)>& callback) { | 102 void QueryVersion(const Callback<void(uint32_t)>& callback) { |
| 103 internal_state_.QueryVersion(callback); | 103 internal_state_.QueryVersion(callback); |
| 104 } | 104 } |
| 105 | 105 |
| 106 // If the remote side doesn't support the specified version, it will close its | 106 // If the remote side doesn't support the specified version, it will close its |
| 107 // end of the message pipe asynchronously. This does nothing if it's already | 107 // end of the message pipe asynchronously. This does nothing if it's already |
| 108 // known that the remote side supports the specified version, i.e., if | 108 // known that the remote side supports the specified version, i.e., if |
| 109 // |version <= this->version()|. | 109 // |version <= this->version()|. |
| 110 // | 110 // |
| 111 // After calling RequireVersion() with a version not supported by the remote | 111 // After calling RequireVersion() with a version not supported by the remote |
| 112 // side, all subsequent calls to interface methods will be ignored. | 112 // side, all subsequent calls to interface methods will be ignored. |
| (...skipping 27 matching lines...) Expand all Loading... |
| 140 // Indicates whether the message pipe has encountered an error. If true, | 140 // Indicates whether the message pipe has encountered an error. If true, |
| 141 // method calls made on this interface will be dropped (and may already have | 141 // method calls made on this interface will be dropped (and may already have |
| 142 // been dropped). | 142 // been dropped). |
| 143 bool encountered_error() const { return internal_state_.encountered_error(); } | 143 bool encountered_error() const { return internal_state_.encountered_error(); } |
| 144 | 144 |
| 145 // Registers a handler to receive error notifications. The handler will be | 145 // Registers a handler to receive error notifications. The handler will be |
| 146 // called from the thread that owns this InterfacePtr. | 146 // called from the thread that owns this InterfacePtr. |
| 147 // | 147 // |
| 148 // This method may only be called after the InterfacePtr has been bound to a | 148 // This method may only be called after the InterfacePtr has been bound to a |
| 149 // message pipe. | 149 // message pipe. |
| 150 void set_connection_error_handler(const base::Closure& error_handler) { | 150 void set_connection_error_handler(const Closure& error_handler) { |
| 151 internal_state_.set_connection_error_handler(error_handler); | 151 internal_state_.set_connection_error_handler(error_handler); |
| 152 } | 152 } |
| 153 | 153 |
| 154 // Unbinds the InterfacePtr and returns the information which could be used | 154 // Unbinds the InterfacePtr and returns the information which could be used |
| 155 // to setup an InterfacePtr again. This method may be used to move the proxy | 155 // to setup an InterfacePtr again. This method may be used to move the proxy |
| 156 // to a different thread (see class comments for details). | 156 // to a different thread (see class comments for details). |
| 157 // | 157 // |
| 158 // It is an error to call PassInterface() while: | 158 // It is an error to call PassInterface() while: |
| 159 // - there are pending responses; or | 159 // - there are pending responses; or |
| 160 // TODO: fix this restriction, it's not always obvious when there is a | 160 // TODO: fix this restriction, it's not always obvious when there is a |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 234 base::ThreadTaskRunnerHandle::Get()) { | 234 base::ThreadTaskRunnerHandle::Get()) { |
| 235 InterfacePtr<Interface> ptr; | 235 InterfacePtr<Interface> ptr; |
| 236 if (info.is_valid()) | 236 if (info.is_valid()) |
| 237 ptr.Bind(std::move(info), std::move(runner)); | 237 ptr.Bind(std::move(info), std::move(runner)); |
| 238 return std::move(ptr); | 238 return std::move(ptr); |
| 239 } | 239 } |
| 240 | 240 |
| 241 } // namespace mojo | 241 } // namespace mojo |
| 242 | 242 |
| 243 #endif // MOJO_PUBLIC_CPP_BINDINGS_INTERFACE_PTR_H_ | 243 #endif // MOJO_PUBLIC_CPP_BINDINGS_INTERFACE_PTR_H_ |
| OLD | NEW |