OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 #include "mojo/public/cpp/bindings/lib/binding_state.h" | 5 #include "mojo/public/cpp/bindings/lib/binding_state.h" |
6 | 6 |
7 #include "mojo/public/cpp/bindings/lib/control_message_proxy.h" | 7 #include "mojo/public/cpp/bindings/lib/control_message_proxy.h" |
8 | 8 |
9 namespace mojo { | 9 namespace mojo { |
10 namespace internal { | 10 namespace internal { |
(...skipping 22 matching lines...) Expand all Loading... |
33 } | 33 } |
34 | 34 |
35 void SimpleBindingState::Close() { | 35 void SimpleBindingState::Close() { |
36 if (!router_) | 36 if (!router_) |
37 return; | 37 return; |
38 | 38 |
39 router_->CloseMessagePipe(); | 39 router_->CloseMessagePipe(); |
40 DestroyRouter(); | 40 DestroyRouter(); |
41 } | 41 } |
42 | 42 |
| 43 void SimpleBindingState::CloseWithReason(uint32_t custom_reason, |
| 44 const std::string& description) { |
| 45 if (router_) |
| 46 router_->control_message_proxy()->SendDisconnectReason(custom_reason, |
| 47 description); |
| 48 Close(); |
| 49 } |
| 50 |
43 void SimpleBindingState::FlushForTesting() { | 51 void SimpleBindingState::FlushForTesting() { |
44 router_->control_message_proxy()->FlushForTesting(); | 52 router_->control_message_proxy()->FlushForTesting(); |
45 } | 53 } |
46 | 54 |
47 void SimpleBindingState::EnableTestingMode() { | 55 void SimpleBindingState::EnableTestingMode() { |
48 DCHECK(is_bound()); | 56 DCHECK(is_bound()); |
49 router_->EnableTestingMode(); | 57 router_->EnableTestingMode(); |
50 } | 58 } |
51 | 59 |
52 void SimpleBindingState::BindInternal( | 60 void SimpleBindingState::BindInternal( |
53 ScopedMessagePipeHandle handle, | 61 ScopedMessagePipeHandle handle, |
54 scoped_refptr<base::SingleThreadTaskRunner> runner, | 62 scoped_refptr<base::SingleThreadTaskRunner> runner, |
55 const char* interface_name, | 63 const char* interface_name, |
56 std::unique_ptr<MessageReceiver> request_validator, | 64 std::unique_ptr<MessageReceiver> request_validator, |
57 bool has_sync_methods, | 65 bool has_sync_methods, |
58 MessageReceiverWithResponderStatus* stub, | 66 MessageReceiverWithResponderStatus* stub, |
59 uint32_t interface_version) { | 67 uint32_t interface_version) { |
60 FilterChain filters; | 68 FilterChain filters; |
61 filters.Append<MessageHeaderValidator>(interface_name); | 69 filters.Append<MessageHeaderValidator>(interface_name); |
62 filters.Append(std::move(request_validator)); | 70 filters.Append(std::move(request_validator)); |
63 | 71 |
64 router_ = new internal::Router(std::move(handle), std::move(filters), | 72 router_ = new internal::Router(std::move(handle), std::move(filters), |
65 has_sync_methods, std::move(runner), | 73 has_sync_methods, std::move(runner), |
66 interface_version); | 74 interface_version); |
67 router_->set_incoming_receiver(stub); | 75 router_->set_incoming_receiver(stub); |
68 router_->set_connection_error_handler(base::Bind( | |
69 &SimpleBindingState::RunConnectionErrorHandler, base::Unretained(this))); | |
70 } | 76 } |
71 | 77 |
72 void SimpleBindingState::DestroyRouter() { | 78 void SimpleBindingState::DestroyRouter() { |
73 router_->set_connection_error_handler(base::Closure()); | |
74 delete router_; | 79 delete router_; |
75 router_ = nullptr; | 80 router_ = nullptr; |
76 connection_error_handler_.Reset(); | |
77 } | |
78 | |
79 void SimpleBindingState::RunConnectionErrorHandler() { | |
80 if (!connection_error_handler_.is_null()) | |
81 connection_error_handler_.Run(); | |
82 } | 81 } |
83 | 82 |
84 // ----------------------------------------------------------------------------- | 83 // ----------------------------------------------------------------------------- |
85 | 84 |
86 MultiplexedBindingState::MultiplexedBindingState() = default; | 85 MultiplexedBindingState::MultiplexedBindingState() = default; |
87 | 86 |
88 MultiplexedBindingState::~MultiplexedBindingState() = default; | 87 MultiplexedBindingState::~MultiplexedBindingState() = default; |
89 | 88 |
90 void MultiplexedBindingState::AddFilter( | 89 void MultiplexedBindingState::AddFilter( |
91 std::unique_ptr<MessageReceiver> filter) { | 90 std::unique_ptr<MessageReceiver> filter) { |
(...skipping 19 matching lines...) Expand all Loading... |
111 return router_->WaitForIncomingMessage(deadline); | 110 return router_->WaitForIncomingMessage(deadline); |
112 } | 111 } |
113 | 112 |
114 void MultiplexedBindingState::Close() { | 113 void MultiplexedBindingState::Close() { |
115 if (!router_) | 114 if (!router_) |
116 return; | 115 return; |
117 | 116 |
118 endpoint_client_.reset(); | 117 endpoint_client_.reset(); |
119 router_->CloseMessagePipe(); | 118 router_->CloseMessagePipe(); |
120 router_ = nullptr; | 119 router_ = nullptr; |
121 connection_error_handler_.Reset(); | 120 } |
| 121 |
| 122 void MultiplexedBindingState::CloseWithReason(uint32_t custom_reason, |
| 123 const std::string& description) { |
| 124 if (endpoint_client_) |
| 125 endpoint_client_->control_message_proxy()->SendDisconnectReason( |
| 126 custom_reason, description); |
| 127 Close(); |
122 } | 128 } |
123 | 129 |
124 void MultiplexedBindingState::FlushForTesting() { | 130 void MultiplexedBindingState::FlushForTesting() { |
125 endpoint_client_->control_message_proxy()->FlushForTesting(); | 131 endpoint_client_->control_message_proxy()->FlushForTesting(); |
126 } | 132 } |
127 | 133 |
128 void MultiplexedBindingState::EnableTestingMode() { | 134 void MultiplexedBindingState::EnableTestingMode() { |
129 DCHECK(is_bound()); | 135 DCHECK(is_bound()); |
130 router_->EnableTestingMode(); | 136 router_->EnableTestingMode(); |
131 } | 137 } |
132 | 138 |
133 void MultiplexedBindingState::BindInternal( | 139 void MultiplexedBindingState::BindInternal( |
134 ScopedMessagePipeHandle handle, | 140 ScopedMessagePipeHandle handle, |
135 scoped_refptr<base::SingleThreadTaskRunner> runner, | 141 scoped_refptr<base::SingleThreadTaskRunner> runner, |
136 const char* interface_name, | 142 const char* interface_name, |
137 std::unique_ptr<MessageReceiver> request_validator, | 143 std::unique_ptr<MessageReceiver> request_validator, |
138 bool has_sync_methods, | 144 bool has_sync_methods, |
139 MessageReceiverWithResponderStatus* stub, | 145 MessageReceiverWithResponderStatus* stub, |
140 uint32_t interface_version) { | 146 uint32_t interface_version) { |
141 DCHECK(!router_); | 147 DCHECK(!router_); |
142 | 148 |
143 router_ = new internal::MultiplexRouter(false, std::move(handle), runner); | 149 router_ = new internal::MultiplexRouter(false, std::move(handle), runner); |
144 router_->SetMasterInterfaceName(interface_name); | 150 router_->SetMasterInterfaceName(interface_name); |
145 | 151 |
146 endpoint_client_.reset(new InterfaceEndpointClient( | 152 endpoint_client_.reset(new InterfaceEndpointClient( |
147 router_->CreateLocalEndpointHandle(kMasterInterfaceId), stub, | 153 router_->CreateLocalEndpointHandle(kMasterInterfaceId), stub, |
148 std::move(request_validator), has_sync_methods, std::move(runner), | 154 std::move(request_validator), has_sync_methods, std::move(runner), |
149 interface_version)); | 155 interface_version)); |
150 | |
151 endpoint_client_->set_connection_error_handler( | |
152 base::Bind(&MultiplexedBindingState::RunConnectionErrorHandler, | |
153 base::Unretained(this))); | |
154 } | |
155 | |
156 void MultiplexedBindingState::RunConnectionErrorHandler() { | |
157 if (!connection_error_handler_.is_null()) | |
158 connection_error_handler_.Run(); | |
159 } | 156 } |
160 | 157 |
161 } // namesapce internal | 158 } // namesapce internal |
162 } // namespace mojo | 159 } // namespace mojo |
OLD | NEW |