| 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 328 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 339 ScopedInterfaceEndpointHandle* local_endpoint, | 339 ScopedInterfaceEndpointHandle* local_endpoint, |
| 340 ScopedInterfaceEndpointHandle* remote_endpoint) { | 340 ScopedInterfaceEndpointHandle* remote_endpoint) { |
| 341 base::AutoLock locker(lock_); | 341 base::AutoLock locker(lock_); |
| 342 uint32_t id = 0; | 342 uint32_t id = 0; |
| 343 do { | 343 do { |
| 344 if (next_interface_id_value_ >= kInterfaceIdNamespaceMask) | 344 if (next_interface_id_value_ >= kInterfaceIdNamespaceMask) |
| 345 next_interface_id_value_ = 1; | 345 next_interface_id_value_ = 1; |
| 346 id = next_interface_id_value_++; | 346 id = next_interface_id_value_++; |
| 347 if (set_interface_id_namespace_bit_) | 347 if (set_interface_id_namespace_bit_) |
| 348 id |= kInterfaceIdNamespaceMask; | 348 id |= kInterfaceIdNamespaceMask; |
| 349 } while (ContainsKey(endpoints_, id)); | 349 } while (base::ContainsKey(endpoints_, id)); |
| 350 | 350 |
| 351 InterfaceEndpoint* endpoint = new InterfaceEndpoint(this, id); | 351 InterfaceEndpoint* endpoint = new InterfaceEndpoint(this, id); |
| 352 endpoints_[id] = endpoint; | 352 endpoints_[id] = endpoint; |
| 353 if (encountered_error_) | 353 if (encountered_error_) |
| 354 UpdateEndpointStateMayRemove(endpoint, PEER_ENDPOINT_CLOSED); | 354 UpdateEndpointStateMayRemove(endpoint, PEER_ENDPOINT_CLOSED); |
| 355 | 355 |
| 356 *local_endpoint = CreateScopedInterfaceEndpointHandle(id, true); | 356 *local_endpoint = CreateScopedInterfaceEndpointHandle(id, true); |
| 357 *remote_endpoint = CreateScopedInterfaceEndpointHandle(id, false); | 357 *remote_endpoint = CreateScopedInterfaceEndpointHandle(id, false); |
| 358 } | 358 } |
| 359 | 359 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 377 return CreateScopedInterfaceEndpointHandle(id, true); | 377 return CreateScopedInterfaceEndpointHandle(id, true); |
| 378 } | 378 } |
| 379 | 379 |
| 380 void MultiplexRouter::CloseEndpointHandle(InterfaceId id, bool is_local) { | 380 void MultiplexRouter::CloseEndpointHandle(InterfaceId id, bool is_local) { |
| 381 if (!IsValidInterfaceId(id)) | 381 if (!IsValidInterfaceId(id)) |
| 382 return; | 382 return; |
| 383 | 383 |
| 384 base::AutoLock locker(lock_); | 384 base::AutoLock locker(lock_); |
| 385 | 385 |
| 386 if (!is_local) { | 386 if (!is_local) { |
| 387 DCHECK(ContainsKey(endpoints_, id)); | 387 DCHECK(base::ContainsKey(endpoints_, id)); |
| 388 DCHECK(!IsMasterInterfaceId(id)); | 388 DCHECK(!IsMasterInterfaceId(id)); |
| 389 | 389 |
| 390 // We will receive a NotifyPeerEndpointClosed message from the other side. | 390 // We will receive a NotifyPeerEndpointClosed message from the other side. |
| 391 control_message_proxy_.NotifyEndpointClosedBeforeSent(id); | 391 control_message_proxy_.NotifyEndpointClosedBeforeSent(id); |
| 392 | 392 |
| 393 return; | 393 return; |
| 394 } | 394 } |
| 395 | 395 |
| 396 DCHECK(ContainsKey(endpoints_, id)); | 396 DCHECK(base::ContainsKey(endpoints_, id)); |
| 397 InterfaceEndpoint* endpoint = endpoints_[id].get(); | 397 InterfaceEndpoint* endpoint = endpoints_[id].get(); |
| 398 DCHECK(!endpoint->client()); | 398 DCHECK(!endpoint->client()); |
| 399 DCHECK(!endpoint->closed()); | 399 DCHECK(!endpoint->closed()); |
| 400 UpdateEndpointStateMayRemove(endpoint, ENDPOINT_CLOSED); | 400 UpdateEndpointStateMayRemove(endpoint, ENDPOINT_CLOSED); |
| 401 | 401 |
| 402 if (!IsMasterInterfaceId(id)) | 402 if (!IsMasterInterfaceId(id)) |
| 403 control_message_proxy_.NotifyPeerEndpointClosed(id); | 403 control_message_proxy_.NotifyPeerEndpointClosed(id); |
| 404 | 404 |
| 405 ProcessTasks(NO_DIRECT_CLIENT_CALLS, nullptr); | 405 ProcessTasks(NO_DIRECT_CLIENT_CALLS, nullptr); |
| 406 } | 406 } |
| 407 | 407 |
| 408 InterfaceEndpointController* MultiplexRouter::AttachEndpointClient( | 408 InterfaceEndpointController* MultiplexRouter::AttachEndpointClient( |
| 409 const ScopedInterfaceEndpointHandle& handle, | 409 const ScopedInterfaceEndpointHandle& handle, |
| 410 InterfaceEndpointClient* client, | 410 InterfaceEndpointClient* client, |
| 411 scoped_refptr<base::SingleThreadTaskRunner> runner) { | 411 scoped_refptr<base::SingleThreadTaskRunner> runner) { |
| 412 const InterfaceId id = handle.id(); | 412 const InterfaceId id = handle.id(); |
| 413 | 413 |
| 414 DCHECK(IsValidInterfaceId(id)); | 414 DCHECK(IsValidInterfaceId(id)); |
| 415 DCHECK(client); | 415 DCHECK(client); |
| 416 | 416 |
| 417 base::AutoLock locker(lock_); | 417 base::AutoLock locker(lock_); |
| 418 DCHECK(ContainsKey(endpoints_, id)); | 418 DCHECK(base::ContainsKey(endpoints_, id)); |
| 419 | 419 |
| 420 InterfaceEndpoint* endpoint = endpoints_[id].get(); | 420 InterfaceEndpoint* endpoint = endpoints_[id].get(); |
| 421 endpoint->AttachClient(client, std::move(runner)); | 421 endpoint->AttachClient(client, std::move(runner)); |
| 422 | 422 |
| 423 if (endpoint->peer_closed()) | 423 if (endpoint->peer_closed()) |
| 424 tasks_.push_back(Task::CreateNotifyErrorTask(endpoint)); | 424 tasks_.push_back(Task::CreateNotifyErrorTask(endpoint)); |
| 425 ProcessTasks(NO_DIRECT_CLIENT_CALLS, nullptr); | 425 ProcessTasks(NO_DIRECT_CLIENT_CALLS, nullptr); |
| 426 | 426 |
| 427 return endpoint; | 427 return endpoint; |
| 428 } | 428 } |
| 429 | 429 |
| 430 void MultiplexRouter::DetachEndpointClient( | 430 void MultiplexRouter::DetachEndpointClient( |
| 431 const ScopedInterfaceEndpointHandle& handle) { | 431 const ScopedInterfaceEndpointHandle& handle) { |
| 432 const InterfaceId id = handle.id(); | 432 const InterfaceId id = handle.id(); |
| 433 | 433 |
| 434 DCHECK(IsValidInterfaceId(id)); | 434 DCHECK(IsValidInterfaceId(id)); |
| 435 | 435 |
| 436 base::AutoLock locker(lock_); | 436 base::AutoLock locker(lock_); |
| 437 DCHECK(ContainsKey(endpoints_, id)); | 437 DCHECK(base::ContainsKey(endpoints_, id)); |
| 438 | 438 |
| 439 InterfaceEndpoint* endpoint = endpoints_[id].get(); | 439 InterfaceEndpoint* endpoint = endpoints_[id].get(); |
| 440 endpoint->DetachClient(); | 440 endpoint->DetachClient(); |
| 441 } | 441 } |
| 442 | 442 |
| 443 void MultiplexRouter::RaiseError() { | 443 void MultiplexRouter::RaiseError() { |
| 444 if (task_runner_->BelongsToCurrentThread()) { | 444 if (task_runner_->BelongsToCurrentThread()) { |
| 445 connector_.RaiseError(); | 445 connector_.RaiseError(); |
| 446 } else { | 446 } else { |
| 447 task_runner_->PostTask(FROM_HERE, | 447 task_runner_->PostTask(FROM_HERE, |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 487 | 487 |
| 488 bool MultiplexRouter::HasAssociatedEndpoints() const { | 488 bool MultiplexRouter::HasAssociatedEndpoints() const { |
| 489 DCHECK(thread_checker_.CalledOnValidThread()); | 489 DCHECK(thread_checker_.CalledOnValidThread()); |
| 490 base::AutoLock locker(lock_); | 490 base::AutoLock locker(lock_); |
| 491 | 491 |
| 492 if (endpoints_.size() > 1) | 492 if (endpoints_.size() > 1) |
| 493 return true; | 493 return true; |
| 494 if (endpoints_.size() == 0) | 494 if (endpoints_.size() == 0) |
| 495 return false; | 495 return false; |
| 496 | 496 |
| 497 return !ContainsKey(endpoints_, kMasterInterfaceId); | 497 return !base::ContainsKey(endpoints_, kMasterInterfaceId); |
| 498 } | 498 } |
| 499 | 499 |
| 500 void MultiplexRouter::EnableTestingMode() { | 500 void MultiplexRouter::EnableTestingMode() { |
| 501 DCHECK(thread_checker_.CalledOnValidThread()); | 501 DCHECK(thread_checker_.CalledOnValidThread()); |
| 502 base::AutoLock locker(lock_); | 502 base::AutoLock locker(lock_); |
| 503 | 503 |
| 504 testing_mode_ = true; | 504 testing_mode_ = true; |
| 505 connector_.set_enforce_errors_from_incoming_receiver(false); | 505 connector_.set_enforce_errors_from_incoming_receiver(false); |
| 506 } | 506 } |
| 507 | 507 |
| (...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 877 *inserted = true; | 877 *inserted = true; |
| 878 } else { | 878 } else { |
| 879 endpoint = iter->second.get(); | 879 endpoint = iter->second.get(); |
| 880 } | 880 } |
| 881 | 881 |
| 882 return endpoint; | 882 return endpoint; |
| 883 } | 883 } |
| 884 | 884 |
| 885 } // namespace internal | 885 } // namespace internal |
| 886 } // namespace mojo | 886 } // namespace mojo |
| OLD | NEW |