From c2f93e23d00e8a5ef74e9dcb5249ddbd7873e044 Mon Sep 17 00:00:00 2001 From: sky Date: Fri, 18 Sep 2015 15:12:55 -0700 Subject: [PATCH] Adds comment for InterfacePtr::PassInterface() as well as DCHECK The DCHECK will help catch errors early. BUG=533107 TEST=none R=yzshen@chromium.org Review URL: https://codereview.chromium.org/1355713002 Cr-Commit-Position: refs/heads/master@{#349781} --- third_party/mojo/src/mojo/public/cpp/bindings/interface_ptr.h | 5 +++++ .../mojo/src/mojo/public/cpp/bindings/lib/interface_ptr_internal.h | 5 +++++ third_party/mojo/src/mojo/public/cpp/bindings/lib/router.cc | 7 ++----- third_party/mojo/src/mojo/public/cpp/bindings/lib/router.h | 5 +++++ 4 files changed, 17 insertions(+), 5 deletions(-) diff --git a/third_party/mojo/src/mojo/public/cpp/bindings/interface_ptr.h b/third_party/mojo/src/mojo/public/cpp/bindings/interface_ptr.h index 00514ddb5427..7908ca8b3d80 100644 --- a/third_party/mojo/src/mojo/public/cpp/bindings/interface_ptr.h +++ b/third_party/mojo/src/mojo/public/cpp/bindings/interface_ptr.h @@ -139,7 +139,12 @@ class InterfacePtr { // Unbinds the InterfacePtr and returns the information which could be used // to setup an InterfacePtr again. This method may be used to move the proxy // to a different thread (see class comments for details). + // + // It is an error to call PassInterface() while there are pending responses. + // TODO: fix this restriction, it's not always obvious when there is a + // pending response. InterfacePtrInfo PassInterface() { + MOJO_DCHECK(!internal_state_.has_pending_callbacks()); State state; internal_state_.Swap(&state); diff --git a/third_party/mojo/src/mojo/public/cpp/bindings/lib/interface_ptr_internal.h b/third_party/mojo/src/mojo/public/cpp/bindings/lib/interface_ptr_internal.h index 5ef6742847b4..1c2cad85845e 100644 --- a/third_party/mojo/src/mojo/public/cpp/bindings/lib/interface_ptr_internal.h +++ b/third_party/mojo/src/mojo/public/cpp/bindings/lib/interface_ptr_internal.h @@ -119,6 +119,11 @@ class InterfacePtrState { router_->set_connection_error_handler(error_handler); } + // Returns true if bound and awaiting a response to a message. + bool has_pending_callbacks() const { + return router_ && router_->has_pending_responders(); + } + Router* router_for_testing() { ConfigureProxyIfNecessary(); return router_; diff --git a/third_party/mojo/src/mojo/public/cpp/bindings/lib/router.cc b/third_party/mojo/src/mojo/public/cpp/bindings/lib/router.cc index e64f1fa0a122..5a7c7e2f9743 100644 --- a/third_party/mojo/src/mojo/public/cpp/bindings/lib/router.cc +++ b/third_party/mojo/src/mojo/public/cpp/bindings/lib/router.cc @@ -87,11 +87,8 @@ Router::Router(ScopedMessagePipeHandle message_pipe, Router::~Router() { weak_self_.set_value(nullptr); - for (ResponderMap::const_iterator i = responders_.begin(); - i != responders_.end(); - ++i) { - delete i->second; - } + for (auto& pair : responders_) + delete pair.second; } bool Router::Accept(Message* message) { diff --git a/third_party/mojo/src/mojo/public/cpp/bindings/lib/router.h b/third_party/mojo/src/mojo/public/cpp/bindings/lib/router.h index dcca1f5a293e..d7e5a68d6e25 100644 --- a/third_party/mojo/src/mojo/public/cpp/bindings/lib/router.h +++ b/third_party/mojo/src/mojo/public/cpp/bindings/lib/router.h @@ -76,6 +76,9 @@ class Router : public MessageReceiverWithResponder { MessagePipeHandle handle() const { return connector_.handle(); } + // Returns true if this Router has any pending callbacks. + bool has_pending_responders() const { return !responders_.empty(); } + private: typedef std::map ResponderMap; @@ -98,6 +101,8 @@ class Router : public MessageReceiverWithResponder { Connector connector_; SharedData weak_self_; MessageReceiverWithResponderStatus* incoming_receiver_; + // Maps from the id of a response to the MessageReceiver that handles the + // response. ResponderMap responders_; uint64_t next_request_id_; bool testing_mode_; -- 2.11.4.GIT