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 <algorithm> | 8 #include <algorithm> |
9 | 9 |
| 10 #include "mojo/public/cpp/bindings/callback.h" |
10 #include "mojo/public/cpp/bindings/error_handler.h" | 11 #include "mojo/public/cpp/bindings/error_handler.h" |
11 #include "mojo/public/cpp/bindings/interface_ptr_info.h" | 12 #include "mojo/public/cpp/bindings/interface_ptr_info.h" |
12 #include "mojo/public/cpp/bindings/lib/interface_ptr_internal.h" | 13 #include "mojo/public/cpp/bindings/lib/interface_ptr_internal.h" |
13 #include "mojo/public/cpp/environment/environment.h" | 14 #include "mojo/public/cpp/environment/environment.h" |
14 #include "mojo/public/cpp/system/macros.h" | 15 #include "mojo/public/cpp/system/macros.h" |
15 | 16 |
16 namespace mojo { | 17 namespace mojo { |
17 class ErrorHandler; | |
18 | 18 |
19 // A pointer to a local proxy of a remote Interface implementation. Uses a | 19 // A pointer to a local proxy of a remote Interface implementation. Uses a |
20 // message pipe to communicate with the remote implementation, and automatically | 20 // message pipe to communicate with the remote implementation, and automatically |
21 // closes the pipe and deletes the proxy on destruction. The pointer must be | 21 // closes the pipe and deletes the proxy on destruction. The pointer must be |
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 |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
123 // Indicates whether the message pipe has encountered an error. If true, | 123 // Indicates whether the message pipe has encountered an error. If true, |
124 // method calls made on this interface will be dropped (and may already have | 124 // method calls made on this interface will be dropped (and may already have |
125 // been dropped). | 125 // been dropped). |
126 bool encountered_error() const { return internal_state_.encountered_error(); } | 126 bool encountered_error() const { return internal_state_.encountered_error(); } |
127 | 127 |
128 // Registers a handler to receive error notifications. The handler will be | 128 // Registers a handler to receive error notifications. The handler will be |
129 // called from the thread that owns this InterfacePtr. | 129 // called from the thread that owns this InterfacePtr. |
130 // | 130 // |
131 // This method may only be called after the InterfacePtr has been bound to a | 131 // This method may only be called after the InterfacePtr has been bound to a |
132 // message pipe. | 132 // message pipe. |
| 133 void set_connection_error_handler(const Closure& error_handler) { |
| 134 internal_state_.set_connection_error_handler(error_handler); |
| 135 } |
| 136 |
| 137 // Similar to the method above but uses the ErrorHandler interface instead of |
| 138 // a callback. |
| 139 // NOTE: Deprecated. Please use the method above. |
| 140 // TODO(yzshen): Remove this method once all callsites are converted. |
133 void set_error_handler(ErrorHandler* error_handler) { | 141 void set_error_handler(ErrorHandler* error_handler) { |
134 internal_state_.set_error_handler(error_handler); | 142 set_connection_error_handler( |
| 143 [error_handler]() { error_handler->OnConnectionError(); }); |
135 } | 144 } |
136 | 145 |
137 // Unbinds the InterfacePtr and returns the information which could be used | 146 // Unbinds the InterfacePtr and returns the information which could be used |
138 // to setup an InterfacePtr again. This method may be used to move the proxy | 147 // to setup an InterfacePtr again. This method may be used to move the proxy |
139 // to a different thread (see class comments for details). | 148 // to a different thread (see class comments for details). |
140 InterfacePtrInfo<Interface> PassInterface() { | 149 InterfacePtrInfo<Interface> PassInterface() { |
141 State state; | 150 State state; |
142 internal_state_.Swap(&state); | 151 internal_state_.Swap(&state); |
143 | 152 |
144 return state.PassInterface(); | 153 return state.PassInterface(); |
(...skipping 29 matching lines...) Expand all Loading... |
174 const MojoAsyncWaiter* waiter = Environment::GetDefaultAsyncWaiter()) { | 183 const MojoAsyncWaiter* waiter = Environment::GetDefaultAsyncWaiter()) { |
175 InterfacePtr<Interface> ptr; | 184 InterfacePtr<Interface> ptr; |
176 if (info.is_valid()) | 185 if (info.is_valid()) |
177 ptr.Bind(info.Pass(), waiter); | 186 ptr.Bind(info.Pass(), waiter); |
178 return ptr.Pass(); | 187 return ptr.Pass(); |
179 } | 188 } |
180 | 189 |
181 } // namespace mojo | 190 } // namespace mojo |
182 | 191 |
183 #endif // MOJO_PUBLIC_CPP_BINDINGS_INTERFACE_PTR_H_ | 192 #endif // MOJO_PUBLIC_CPP_BINDINGS_INTERFACE_PTR_H_ |
OLD | NEW |