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 #include "mojo/public/cpp/bindings/lib/multiplex_router.h" | 5 #include "mojo/public/cpp/bindings/lib/multiplex_router.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
279 private: | 279 private: |
280 explicit Task(Type in_type) : type(in_type) {} | 280 explicit Task(Type in_type) : type(in_type) {} |
281 }; | 281 }; |
282 | 282 |
283 MultiplexRouter::MultiplexRouter( | 283 MultiplexRouter::MultiplexRouter( |
284 bool set_interface_id_namesapce_bit, | 284 bool set_interface_id_namesapce_bit, |
285 ScopedMessagePipeHandle message_pipe, | 285 ScopedMessagePipeHandle message_pipe, |
286 scoped_refptr<base::SingleThreadTaskRunner> runner) | 286 scoped_refptr<base::SingleThreadTaskRunner> runner) |
287 : set_interface_id_namespace_bit_(set_interface_id_namesapce_bit), | 287 : set_interface_id_namespace_bit_(set_interface_id_namesapce_bit), |
288 task_runner_(runner), | 288 task_runner_(runner), |
289 header_validator_(this), | 289 header_validator_(nullptr), |
| 290 filters_(this), |
290 connector_(std::move(message_pipe), | 291 connector_(std::move(message_pipe), |
291 Connector::MULTI_THREADED_SEND, | 292 Connector::MULTI_THREADED_SEND, |
292 std::move(runner)), | 293 std::move(runner)), |
293 control_message_handler_(this), | 294 control_message_handler_(this), |
294 control_message_proxy_(&connector_), | 295 control_message_proxy_(&connector_), |
295 next_interface_id_value_(1), | 296 next_interface_id_value_(1), |
296 posted_to_process_tasks_(false), | 297 posted_to_process_tasks_(false), |
297 encountered_error_(false), | 298 encountered_error_(false), |
298 paused_(false), | 299 paused_(false), |
299 testing_mode_(false) { | 300 testing_mode_(false) { |
300 DCHECK(task_runner_->BelongsToCurrentThread()); | 301 DCHECK(task_runner_->BelongsToCurrentThread()); |
301 // Always participate in sync handle watching, because even if it doesn't | 302 // Always participate in sync handle watching, because even if it doesn't |
302 // expect sync requests during sync handle watching, it may still need to | 303 // expect sync requests during sync handle watching, it may still need to |
303 // dispatch messages to associated endpoints on a different thread. | 304 // dispatch messages to associated endpoints on a different thread. |
304 connector_.AllowWokenUpBySyncWatchOnSameThread(); | 305 connector_.AllowWokenUpBySyncWatchOnSameThread(); |
305 connector_.set_incoming_receiver(&header_validator_); | 306 connector_.set_incoming_receiver(&filters_); |
306 connector_.set_connection_error_handler( | 307 connector_.set_connection_error_handler( |
307 base::Bind(&MultiplexRouter::OnPipeConnectionError, | 308 base::Bind(&MultiplexRouter::OnPipeConnectionError, |
308 base::Unretained(this))); | 309 base::Unretained(this))); |
| 310 |
| 311 std::unique_ptr<MessageHeaderValidator> header_validator = |
| 312 base::MakeUnique<MessageHeaderValidator>(); |
| 313 header_validator_ = header_validator.get(); |
| 314 filters_.Append(std::move(header_validator)); |
309 } | 315 } |
310 | 316 |
311 MultiplexRouter::~MultiplexRouter() { | 317 MultiplexRouter::~MultiplexRouter() { |
312 base::AutoLock locker(lock_); | 318 base::AutoLock locker(lock_); |
313 | 319 |
314 sync_message_tasks_.clear(); | 320 sync_message_tasks_.clear(); |
315 tasks_.clear(); | 321 tasks_.clear(); |
316 | 322 |
317 for (auto iter = endpoints_.begin(); iter != endpoints_.end();) { | 323 for (auto iter = endpoints_.begin(); iter != endpoints_.end();) { |
318 InterfaceEndpoint* endpoint = iter->second.get(); | 324 InterfaceEndpoint* endpoint = iter->second.get(); |
319 // Increment the iterator before calling UpdateEndpointStateMayRemove() | 325 // Increment the iterator before calling UpdateEndpointStateMayRemove() |
320 // because it may remove the corresponding value from the map. | 326 // because it may remove the corresponding value from the map. |
321 ++iter; | 327 ++iter; |
322 | 328 |
323 DCHECK(endpoint->closed()); | 329 DCHECK(endpoint->closed()); |
324 UpdateEndpointStateMayRemove(endpoint, PEER_ENDPOINT_CLOSED); | 330 UpdateEndpointStateMayRemove(endpoint, PEER_ENDPOINT_CLOSED); |
325 } | 331 } |
326 | 332 |
327 DCHECK(endpoints_.empty()); | 333 DCHECK(endpoints_.empty()); |
328 } | 334 } |
329 | 335 |
330 void MultiplexRouter::SetMasterInterfaceName(const std::string& name) { | 336 void MultiplexRouter::SetMasterInterfaceName(const std::string& name) { |
331 DCHECK(thread_checker_.CalledOnValidThread()); | 337 DCHECK(thread_checker_.CalledOnValidThread()); |
332 header_validator_.SetDescription(name + " [master] MessageHeaderValidator"); | 338 header_validator_->SetDescription(name + " [master] MessageHeaderValidator"); |
333 control_message_handler_.SetDescription( | 339 control_message_handler_.SetDescription( |
334 name + " [master] PipeControlMessageHandler"); | 340 name + " [master] PipeControlMessageHandler"); |
335 } | 341 } |
336 | 342 |
337 void MultiplexRouter::CreateEndpointHandlePair( | 343 void MultiplexRouter::CreateEndpointHandlePair( |
338 ScopedInterfaceEndpointHandle* local_endpoint, | 344 ScopedInterfaceEndpointHandle* local_endpoint, |
339 ScopedInterfaceEndpointHandle* remote_endpoint) { | 345 ScopedInterfaceEndpointHandle* remote_endpoint) { |
340 base::AutoLock locker(lock_); | 346 base::AutoLock locker(lock_); |
341 uint32_t id = 0; | 347 uint32_t id = 0; |
342 do { | 348 do { |
(...skipping 534 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
877 *inserted = true; | 883 *inserted = true; |
878 } else { | 884 } else { |
879 endpoint = iter->second.get(); | 885 endpoint = iter->second.get(); |
880 } | 886 } |
881 | 887 |
882 return endpoint; | 888 return endpoint; |
883 } | 889 } |
884 | 890 |
885 } // namespace internal | 891 } // namespace internal |
886 } // namespace mojo | 892 } // namespace mojo |
OLD | NEW |