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

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

Issue 2332353004: Mojo C++ bindings: support closing [Associated]InterfaceRequest with 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 | « no previous file | mojo/public/cpp/bindings/interface_request.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/public/cpp/bindings/associated_interface_request.h
diff --git a/mojo/public/cpp/bindings/associated_interface_request.h b/mojo/public/cpp/bindings/associated_interface_request.h
index 30fcd16ec14496d30ae318aa240ed46cedb0b75a..361b301d38957d8eed565d4364d87e2e94920f01 100644
--- a/mojo/public/cpp/bindings/associated_interface_request.h
+++ b/mojo/public/cpp/bindings/associated_interface_request.h
@@ -5,9 +5,15 @@
#ifndef MOJO_PUBLIC_CPP_BINDINGS_ASSOCIATED_INTERFACE_REQUEST_H_
#define MOJO_PUBLIC_CPP_BINDINGS_ASSOCIATED_INTERFACE_REQUEST_H_
+#include <string>
#include <utility>
#include "base/macros.h"
+#include "base/memory/ptr_util.h"
+#include "base/threading/thread_task_runner_handle.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/message.h"
#include "mojo/public/cpp/bindings/scoped_interface_endpoint_handle.h"
namespace mojo {
@@ -64,6 +70,28 @@ class AssociatedInterfaceRequest {
return !is_pending() && !other.is_pending();
}
+ void ResetWithReason(uint32_t custom_reason, const std::string& description) {
+ if (!handle_.is_valid())
+ return;
+
+ if (!handle_.is_local()) {
+ // This handle is supposed to be sent to the other end of the message
+ // pipe and used there.
+ NOTREACHED();
+ handle_.reset();
+ return;
+ }
+
+ InterfaceEndpointClient client(std::move(handle_), nullptr,
+ base::MakeUnique<PassThroughFilter>(), false,
+ base::ThreadTaskRunnerHandle::Get(), 0u);
+ Message message =
+ internal::ControlMessageProxy::ConstructDisconnectReasonMessage(
+ custom_reason, description);
+ bool result = client.Accept(&message);
+ DCHECK(result);
+ }
+
private:
ScopedInterfaceEndpointHandle handle_;
« no previous file with comments | « no previous file | mojo/public/cpp/bindings/interface_request.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698