Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1073)

Unified Diff: mojo/public/cpp/bindings/associated_binding.h

Issue 2318793002: Mojo C++ bindings: support disconnect with a reason. (Closed)
Patch Set: . Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « mojo/public/cpp/bindings/BUILD.gn ('k') | mojo/public/cpp/bindings/associated_interface_ptr.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/public/cpp/bindings/associated_binding.h
diff --git a/mojo/public/cpp/bindings/associated_binding.h b/mojo/public/cpp/bindings/associated_binding.h
index 3f991290171cf0a3d1ef5e4588f6ee2064a39d66..a7a7c822869b414eb33fd63bde32f5a3e1f89de8 100644
--- a/mojo/public/cpp/bindings/associated_binding.h
+++ b/mojo/public/cpp/bindings/associated_binding.h
@@ -6,6 +6,7 @@
#define MOJO_PUBLIC_CPP_BINDINGS_ASSOCIATED_BINDING_H_
#include <memory>
+#include <string>
#include <utility>
#include "base/bind.h"
@@ -18,6 +19,7 @@
#include "mojo/public/cpp/bindings/associated_group.h"
#include "mojo/public/cpp/bindings/associated_group_controller.h"
#include "mojo/public/cpp/bindings/associated_interface_request.h"
+#include "mojo/public/cpp/bindings/connection_error_callback.h"
#include "mojo/public/cpp/bindings/interface_endpoint_client.h"
#include "mojo/public/cpp/bindings/lib/control_message_proxy.h"
#include "mojo/public/cpp/bindings/scoped_interface_endpoint_handle.h"
@@ -105,9 +107,6 @@ class AssociatedBinding {
std::move(handle), &stub_,
base::WrapUnique(new typename Interface::RequestValidator_()),
Interface::HasSyncMethods_, std::move(runner), Interface::Version_));
- endpoint_client_->set_connection_error_handler(
- base::Bind(&AssociatedBinding::RunConnectionErrorHandler,
- base::Unretained(this)));
stub_.serialization_context()->group_controller =
endpoint_client_->group_controller();
@@ -126,7 +125,14 @@ class AssociatedBinding {
void Close() {
DCHECK(endpoint_client_);
endpoint_client_.reset();
- connection_error_handler_.Reset();
+ }
+
+ // Similar to the method above, but also specifies a disconnect reason.
+ void CloseWithReason(uint32_t custom_reason, const std::string& description) {
+ DCHECK(endpoint_client_);
+ endpoint_client_->control_message_proxy()->SendDisconnectReason(
+ custom_reason, description);
+ Close();
}
// Unbinds and returns the associated interface request so it can be
@@ -139,7 +145,6 @@ class AssociatedBinding {
request.Bind(endpoint_client_->PassHandle());
endpoint_client_.reset();
- connection_error_handler_.Reset();
return request;
}
@@ -151,7 +156,13 @@ class AssociatedBinding {
// AssociatedBinding is unbound or closed.
void set_connection_error_handler(const base::Closure& error_handler) {
DCHECK(is_bound());
- connection_error_handler_ = error_handler;
+ endpoint_client_->set_connection_error_handler(error_handler);
+ }
+
+ void set_connection_error_with_reason_handler(
+ const ConnectionErrorWithReasonCallback& error_handler) {
+ DCHECK(is_bound());
+ endpoint_client_->set_connection_error_with_reason_handler(error_handler);
}
// Returns the interface implementation that was previously specified.
@@ -175,16 +186,10 @@ class AssociatedBinding {
}
private:
- void RunConnectionErrorHandler() {
- if (!connection_error_handler_.is_null())
- connection_error_handler_.Run();
- }
-
std::unique_ptr<InterfaceEndpointClient> endpoint_client_;
typename Interface::Stub_ stub_;
Interface* impl_;
- base::Closure connection_error_handler_;
DISALLOW_COPY_AND_ASSIGN(AssociatedBinding);
};
« no previous file with comments | « mojo/public/cpp/bindings/BUILD.gn ('k') | mojo/public/cpp/bindings/associated_interface_ptr.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698