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_INTERFACE_REQUEST_H_ | 5 #ifndef MOJO_PUBLIC_CPP_BINDINGS_INTERFACE_REQUEST_H_ |
6 #define MOJO_PUBLIC_CPP_BINDINGS_INTERFACE_REQUEST_H_ | 6 #define MOJO_PUBLIC_CPP_BINDINGS_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" |
11 #include "base/single_thread_task_runner.h" | 12 #include "base/single_thread_task_runner.h" |
12 #include "base/threading/thread_task_runner_handle.h" | 13 #include "base/threading/thread_task_runner_handle.h" |
13 #include "mojo/public/cpp/bindings/interface_ptr.h" | 14 #include "mojo/public/cpp/bindings/interface_ptr.h" |
| 15 #include "mojo/public/cpp/bindings/lib/control_message_proxy.h" |
| 16 #include "mojo/public/cpp/system/message_pipe.h" |
14 | 17 |
15 namespace mojo { | 18 namespace mojo { |
16 | 19 |
17 // Represents a request from a remote client for an implementation of Interface | 20 // Represents a request from a remote client for an implementation of Interface |
18 // over a specified message pipe. The implementor of the interface should | 21 // over a specified message pipe. The implementor of the interface should |
19 // remove the message pipe by calling PassMessagePipe() and bind it to the | 22 // remove the message pipe by calling PassMessagePipe() and bind it to the |
20 // implementation. If this is not done, the InterfaceRequest will automatically | 23 // implementation. If this is not done, the InterfaceRequest will automatically |
21 // close the pipe on destruction. Can also represent the absence of a request | 24 // close the pipe on destruction. Can also represent the absence of a request |
22 // if the client did not provide a message pipe. | 25 // if the client did not provide a message pipe. |
23 template <typename Interface> | 26 template <typename Interface> |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 | 60 |
58 bool Equals(const InterfaceRequest& other) const { | 61 bool Equals(const InterfaceRequest& other) const { |
59 if (this == &other) | 62 if (this == &other) |
60 return true; | 63 return true; |
61 | 64 |
62 // Now that the two refer to different objects, they are equivalent if | 65 // Now that the two refer to different objects, they are equivalent if |
63 // and only if they are both invalid. | 66 // and only if they are both invalid. |
64 return !is_pending() && !other.is_pending(); | 67 return !is_pending() && !other.is_pending(); |
65 } | 68 } |
66 | 69 |
| 70 void ResetWithReason(uint32_t custom_reason, const std::string& description) { |
| 71 if (!handle_.is_valid()) |
| 72 return; |
| 73 |
| 74 Message message = |
| 75 internal::ControlMessageProxy::ConstructDisconnectReasonMessage( |
| 76 custom_reason, description); |
| 77 MojoResult result = WriteMessageNew( |
| 78 handle_.get(), message.TakeMojoMessage(), MOJO_WRITE_MESSAGE_FLAG_NONE); |
| 79 DCHECK_EQ(MOJO_RESULT_OK, result); |
| 80 |
| 81 handle_.reset(); |
| 82 } |
| 83 |
67 private: | 84 private: |
68 ScopedMessagePipeHandle handle_; | 85 ScopedMessagePipeHandle handle_; |
69 | 86 |
70 DISALLOW_COPY_AND_ASSIGN(InterfaceRequest); | 87 DISALLOW_COPY_AND_ASSIGN(InterfaceRequest); |
71 }; | 88 }; |
72 | 89 |
73 // Makes an InterfaceRequest bound to the specified message pipe. If |handle| | 90 // Makes an InterfaceRequest bound to the specified message pipe. If |handle| |
74 // is empty or invalid, the resulting InterfaceRequest will represent the | 91 // is empty or invalid, the resulting InterfaceRequest will represent the |
75 // absence of a request. | 92 // absence of a request. |
76 template <typename Interface> | 93 template <typename Interface> |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
140 bool FuseInterface(InterfaceRequest<Interface> request, | 157 bool FuseInterface(InterfaceRequest<Interface> request, |
141 InterfacePtrInfo<Interface> proxy_info) { | 158 InterfacePtrInfo<Interface> proxy_info) { |
142 MojoResult result = FuseMessagePipes(request.PassMessagePipe(), | 159 MojoResult result = FuseMessagePipes(request.PassMessagePipe(), |
143 proxy_info.PassHandle()); | 160 proxy_info.PassHandle()); |
144 return result == MOJO_RESULT_OK; | 161 return result == MOJO_RESULT_OK; |
145 } | 162 } |
146 | 163 |
147 } // namespace mojo | 164 } // namespace mojo |
148 | 165 |
149 #endif // MOJO_PUBLIC_CPP_BINDINGS_INTERFACE_REQUEST_H_ | 166 #endif // MOJO_PUBLIC_CPP_BINDINGS_INTERFACE_REQUEST_H_ |
OLD | NEW |