| 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_LIB_INTERFACE_PTR_STATE_H_ | 5 #ifndef MOJO_PUBLIC_CPP_BINDINGS_LIB_INTERFACE_PTR_STATE_H_ |
| 6 #define MOJO_PUBLIC_CPP_BINDINGS_LIB_INTERFACE_PTR_STATE_H_ | 6 #define MOJO_PUBLIC_CPP_BINDINGS_LIB_INTERFACE_PTR_STATE_H_ |
| 7 | 7 |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <algorithm> // For |std::swap()|. | 10 #include <algorithm> // For |std::swap()|. |
| 11 #include <memory> | 11 #include <memory> |
| 12 #include <string> |
| 12 #include <utility> | 13 #include <utility> |
| 13 | 14 |
| 14 #include "base/bind.h" | 15 #include "base/bind.h" |
| 15 #include "base/callback_forward.h" | 16 #include "base/callback_forward.h" |
| 16 #include "base/logging.h" | 17 #include "base/logging.h" |
| 17 #include "base/macros.h" | 18 #include "base/macros.h" |
| 18 #include "base/memory/ptr_util.h" | 19 #include "base/memory/ptr_util.h" |
| 19 #include "base/memory/ref_counted.h" | 20 #include "base/memory/ref_counted.h" |
| 20 #include "base/single_thread_task_runner.h" | 21 #include "base/single_thread_task_runner.h" |
| 21 #include "mojo/public/cpp/bindings/associated_group.h" | 22 #include "mojo/public/cpp/bindings/associated_group.h" |
| 23 #include "mojo/public/cpp/bindings/connection_error_callback.h" |
| 22 #include "mojo/public/cpp/bindings/filter_chain.h" | 24 #include "mojo/public/cpp/bindings/filter_chain.h" |
| 23 #include "mojo/public/cpp/bindings/interface_endpoint_client.h" | 25 #include "mojo/public/cpp/bindings/interface_endpoint_client.h" |
| 24 #include "mojo/public/cpp/bindings/interface_id.h" | 26 #include "mojo/public/cpp/bindings/interface_id.h" |
| 25 #include "mojo/public/cpp/bindings/interface_ptr_info.h" | 27 #include "mojo/public/cpp/bindings/interface_ptr_info.h" |
| 26 #include "mojo/public/cpp/bindings/lib/control_message_handler.h" | 28 #include "mojo/public/cpp/bindings/lib/control_message_handler.h" |
| 27 #include "mojo/public/cpp/bindings/lib/control_message_proxy.h" | 29 #include "mojo/public/cpp/bindings/lib/control_message_proxy.h" |
| 28 #include "mojo/public/cpp/bindings/lib/multiplex_router.h" | 30 #include "mojo/public/cpp/bindings/lib/multiplex_router.h" |
| 29 #include "mojo/public/cpp/bindings/lib/router.h" | 31 #include "mojo/public/cpp/bindings/lib/router.h" |
| 30 #include "mojo/public/cpp/bindings/message_header_validator.h" | 32 #include "mojo/public/cpp/bindings/message_header_validator.h" |
| 31 #include "mojo/public/cpp/bindings/scoped_interface_endpoint_handle.h" | 33 #include "mojo/public/cpp/bindings/scoped_interface_endpoint_handle.h" |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 79 | 81 |
| 80 version_ = version; | 82 version_ = version; |
| 81 router_->control_message_proxy()->RequireVersion(version); | 83 router_->control_message_proxy()->RequireVersion(version); |
| 82 } | 84 } |
| 83 | 85 |
| 84 void FlushForTesting() { | 86 void FlushForTesting() { |
| 85 ConfigureProxyIfNecessary(); | 87 ConfigureProxyIfNecessary(); |
| 86 router_->control_message_proxy()->FlushForTesting(); | 88 router_->control_message_proxy()->FlushForTesting(); |
| 87 } | 89 } |
| 88 | 90 |
| 91 void SendDisconnectReason(uint32_t custom_reason, |
| 92 const std::string& description) { |
| 93 ConfigureProxyIfNecessary(); |
| 94 router_->control_message_proxy()->SendDisconnectReason(custom_reason, |
| 95 description); |
| 96 } |
| 97 |
| 89 void Swap(InterfacePtrState* other) { | 98 void Swap(InterfacePtrState* other) { |
| 90 using std::swap; | 99 using std::swap; |
| 91 swap(other->proxy_, proxy_); | 100 swap(other->proxy_, proxy_); |
| 92 swap(other->router_, router_); | 101 swap(other->router_, router_); |
| 93 handle_.swap(other->handle_); | 102 handle_.swap(other->handle_); |
| 94 runner_.swap(other->runner_); | 103 runner_.swap(other->runner_); |
| 95 swap(other->version_, version_); | 104 swap(other->version_, version_); |
| 96 } | 105 } |
| 97 | 106 |
| 98 void Bind(InterfacePtrInfo<Interface> info, | 107 void Bind(InterfacePtrInfo<Interface> info, |
| (...skipping 24 matching lines...) Expand all Loading... |
| 123 return router_ ? router_->encountered_error() : false; | 132 return router_ ? router_->encountered_error() : false; |
| 124 } | 133 } |
| 125 | 134 |
| 126 void set_connection_error_handler(const base::Closure& error_handler) { | 135 void set_connection_error_handler(const base::Closure& error_handler) { |
| 127 ConfigureProxyIfNecessary(); | 136 ConfigureProxyIfNecessary(); |
| 128 | 137 |
| 129 DCHECK(router_); | 138 DCHECK(router_); |
| 130 router_->set_connection_error_handler(error_handler); | 139 router_->set_connection_error_handler(error_handler); |
| 131 } | 140 } |
| 132 | 141 |
| 142 void set_connection_error_with_reason_handler( |
| 143 const ConnectionErrorWithReasonCallback& error_handler) { |
| 144 ConfigureProxyIfNecessary(); |
| 145 |
| 146 DCHECK(router_); |
| 147 router_->set_connection_error_with_reason_handler(error_handler); |
| 148 } |
| 149 |
| 133 // Returns true if bound and awaiting a response to a message. | 150 // Returns true if bound and awaiting a response to a message. |
| 134 bool has_pending_callbacks() const { | 151 bool has_pending_callbacks() const { |
| 135 return router_ && router_->has_pending_responders(); | 152 return router_ && router_->has_pending_responders(); |
| 136 } | 153 } |
| 137 | 154 |
| 138 AssociatedGroup* associated_group() { return nullptr; } | 155 AssociatedGroup* associated_group() { return nullptr; } |
| 139 | 156 |
| 140 void EnableTestingMode() { | 157 void EnableTestingMode() { |
| 141 ConfigureProxyIfNecessary(); | 158 ConfigureProxyIfNecessary(); |
| 142 router_->EnableTestingMode(); | 159 router_->EnableTestingMode(); |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 227 | 244 |
| 228 version_ = version; | 245 version_ = version; |
| 229 endpoint_client_->control_message_proxy()->RequireVersion(version); | 246 endpoint_client_->control_message_proxy()->RequireVersion(version); |
| 230 } | 247 } |
| 231 | 248 |
| 232 void FlushForTesting() { | 249 void FlushForTesting() { |
| 233 ConfigureProxyIfNecessary(); | 250 ConfigureProxyIfNecessary(); |
| 234 endpoint_client_->control_message_proxy()->FlushForTesting(); | 251 endpoint_client_->control_message_proxy()->FlushForTesting(); |
| 235 } | 252 } |
| 236 | 253 |
| 254 void SendDisconnectReason(uint32_t custom_reason, |
| 255 const std::string& description) { |
| 256 ConfigureProxyIfNecessary(); |
| 257 endpoint_client_->control_message_proxy()->SendDisconnectReason( |
| 258 custom_reason, description); |
| 259 } |
| 260 |
| 237 void Swap(InterfacePtrState* other) { | 261 void Swap(InterfacePtrState* other) { |
| 238 using std::swap; | 262 using std::swap; |
| 239 swap(other->router_, router_); | 263 swap(other->router_, router_); |
| 240 swap(other->endpoint_client_, endpoint_client_); | 264 swap(other->endpoint_client_, endpoint_client_); |
| 241 swap(other->proxy_, proxy_); | 265 swap(other->proxy_, proxy_); |
| 242 handle_.swap(other->handle_); | 266 handle_.swap(other->handle_); |
| 243 runner_.swap(other->runner_); | 267 runner_.swap(other->runner_); |
| 244 swap(other->version_, version_); | 268 swap(other->version_, version_); |
| 245 } | 269 } |
| 246 | 270 |
| (...skipping 30 matching lines...) Expand all Loading... |
| 277 return endpoint_client_ ? endpoint_client_->encountered_error() : false; | 301 return endpoint_client_ ? endpoint_client_->encountered_error() : false; |
| 278 } | 302 } |
| 279 | 303 |
| 280 void set_connection_error_handler(const base::Closure& error_handler) { | 304 void set_connection_error_handler(const base::Closure& error_handler) { |
| 281 ConfigureProxyIfNecessary(); | 305 ConfigureProxyIfNecessary(); |
| 282 | 306 |
| 283 DCHECK(endpoint_client_); | 307 DCHECK(endpoint_client_); |
| 284 endpoint_client_->set_connection_error_handler(error_handler); | 308 endpoint_client_->set_connection_error_handler(error_handler); |
| 285 } | 309 } |
| 286 | 310 |
| 311 void set_connection_error_with_reason_handler( |
| 312 const ConnectionErrorWithReasonCallback& error_handler) { |
| 313 ConfigureProxyIfNecessary(); |
| 314 |
| 315 DCHECK(endpoint_client_); |
| 316 endpoint_client_->set_connection_error_with_reason_handler(error_handler); |
| 317 } |
| 318 |
| 287 // Returns true if bound and awaiting a response to a message. | 319 // Returns true if bound and awaiting a response to a message. |
| 288 bool has_pending_callbacks() const { | 320 bool has_pending_callbacks() const { |
| 289 return endpoint_client_ && endpoint_client_->has_pending_responders(); | 321 return endpoint_client_ && endpoint_client_->has_pending_responders(); |
| 290 } | 322 } |
| 291 | 323 |
| 292 AssociatedGroup* associated_group() { | 324 AssociatedGroup* associated_group() { |
| 293 ConfigureProxyIfNecessary(); | 325 ConfigureProxyIfNecessary(); |
| 294 return endpoint_client_->associated_group(); | 326 return endpoint_client_->associated_group(); |
| 295 } | 327 } |
| 296 | 328 |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 346 | 378 |
| 347 uint32_t version_; | 379 uint32_t version_; |
| 348 | 380 |
| 349 DISALLOW_COPY_AND_ASSIGN(InterfacePtrState); | 381 DISALLOW_COPY_AND_ASSIGN(InterfacePtrState); |
| 350 }; | 382 }; |
| 351 | 383 |
| 352 } // namespace internal | 384 } // namespace internal |
| 353 } // namespace mojo | 385 } // namespace mojo |
| 354 | 386 |
| 355 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_INTERFACE_PTR_STATE_H_ | 387 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_INTERFACE_PTR_STATE_H_ |
| OLD | NEW |