OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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_ASSOCIATED_INTERFACE_REQUEST_H_ | 5 #ifndef MOJO_PUBLIC_CPP_BINDINGS_ASSOCIATED_INTERFACE_REQUEST_H_ |
6 #define MOJO_PUBLIC_CPP_BINDINGS_ASSOCIATED_INTERFACE_REQUEST_H_ | 6 #define MOJO_PUBLIC_CPP_BINDINGS_ASSOCIATED_INTERFACE_REQUEST_H_ |
7 | 7 |
| 8 #include <string> |
8 #include <utility> | 9 #include <utility> |
9 | 10 |
10 #include "base/macros.h" | 11 #include "base/macros.h" |
| 12 #include "base/memory/ptr_util.h" |
| 13 #include "base/threading/thread_task_runner_handle.h" |
| 14 #include "mojo/public/cpp/bindings/interface_endpoint_client.h" |
| 15 #include "mojo/public/cpp/bindings/lib/control_message_proxy.h" |
| 16 #include "mojo/public/cpp/bindings/message.h" |
11 #include "mojo/public/cpp/bindings/scoped_interface_endpoint_handle.h" | 17 #include "mojo/public/cpp/bindings/scoped_interface_endpoint_handle.h" |
12 | 18 |
13 namespace mojo { | 19 namespace mojo { |
14 | 20 |
15 // AssociatedInterfaceRequest represents an associated interface request. It is | 21 // AssociatedInterfaceRequest represents an associated interface request. It is |
16 // similar to InterfaceRequest except that it doesn't own a message pipe handle. | 22 // similar to InterfaceRequest except that it doesn't own a message pipe handle. |
17 template <typename Interface> | 23 template <typename Interface> |
18 class AssociatedInterfaceRequest { | 24 class AssociatedInterfaceRequest { |
19 public: | 25 public: |
20 // Constructs an empty AssociatedInterfaceRequest, representing that the | 26 // Constructs an empty AssociatedInterfaceRequest, representing that the |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 | 63 |
58 bool Equals(const AssociatedInterfaceRequest& other) const { | 64 bool Equals(const AssociatedInterfaceRequest& other) const { |
59 if (this == &other) | 65 if (this == &other) |
60 return true; | 66 return true; |
61 | 67 |
62 // Now that the two refer to different objects, they are equivalent if | 68 // Now that the two refer to different objects, they are equivalent if |
63 // and only if they are both invalid. | 69 // and only if they are both invalid. |
64 return !is_pending() && !other.is_pending(); | 70 return !is_pending() && !other.is_pending(); |
65 } | 71 } |
66 | 72 |
| 73 void ResetWithReason(uint32_t custom_reason, const std::string& description) { |
| 74 if (!handle_.is_valid()) |
| 75 return; |
| 76 |
| 77 if (!handle_.is_local()) { |
| 78 // This handle is supposed to be sent to the other end of the message |
| 79 // pipe and used there. |
| 80 NOTREACHED(); |
| 81 handle_.reset(); |
| 82 return; |
| 83 } |
| 84 |
| 85 InterfaceEndpointClient client(std::move(handle_), nullptr, |
| 86 base::MakeUnique<PassThroughFilter>(), false, |
| 87 base::ThreadTaskRunnerHandle::Get(), 0u); |
| 88 Message message = |
| 89 internal::ControlMessageProxy::ConstructDisconnectReasonMessage( |
| 90 custom_reason, description); |
| 91 bool result = client.Accept(&message); |
| 92 DCHECK(result); |
| 93 } |
| 94 |
67 private: | 95 private: |
68 ScopedInterfaceEndpointHandle handle_; | 96 ScopedInterfaceEndpointHandle handle_; |
69 | 97 |
70 DISALLOW_COPY_AND_ASSIGN(AssociatedInterfaceRequest); | 98 DISALLOW_COPY_AND_ASSIGN(AssociatedInterfaceRequest); |
71 }; | 99 }; |
72 | 100 |
73 // Makes an AssociatedInterfaceRequest bound to the specified associated | 101 // Makes an AssociatedInterfaceRequest bound to the specified associated |
74 // endpoint. | 102 // endpoint. |
75 template <typename Interface> | 103 template <typename Interface> |
76 AssociatedInterfaceRequest<Interface> MakeAssociatedRequest( | 104 AssociatedInterfaceRequest<Interface> MakeAssociatedRequest( |
77 ScopedInterfaceEndpointHandle handle) { | 105 ScopedInterfaceEndpointHandle handle) { |
78 AssociatedInterfaceRequest<Interface> request; | 106 AssociatedInterfaceRequest<Interface> request; |
79 request.Bind(std::move(handle)); | 107 request.Bind(std::move(handle)); |
80 return request; | 108 return request; |
81 } | 109 } |
82 | 110 |
83 } // namespace mojo | 111 } // namespace mojo |
84 | 112 |
85 #endif // MOJO_PUBLIC_CPP_BINDINGS_ASSOCIATED_INTERFACE_REQUEST_H_ | 113 #endif // MOJO_PUBLIC_CPP_BINDINGS_ASSOCIATED_INTERFACE_REQUEST_H_ |
OLD | NEW |