| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "ipc/ipc_channel_proxy.h" | 5 #include "ipc/ipc_channel_proxy.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <utility> | 10 #include <utility> |
| 11 | 11 |
| 12 #include "base/bind.h" | 12 #include "base/bind.h" |
| 13 #include "base/compiler_specific.h" | 13 #include "base/compiler_specific.h" |
| 14 #include "base/location.h" | 14 #include "base/location.h" |
| 15 #include "base/memory/ptr_util.h" | 15 #include "base/memory/ptr_util.h" |
| 16 #include "base/memory/ref_counted.h" | 16 #include "base/memory/ref_counted.h" |
| 17 #include "base/profiler/scoped_tracker.h" | 17 #include "base/profiler/scoped_tracker.h" |
| 18 #include "base/single_thread_task_runner.h" | 18 #include "base/single_thread_task_runner.h" |
| 19 #include "base/threading/thread_task_runner_handle.h" | 19 #include "base/threading/thread_task_runner_handle.h" |
| 20 #include "build/build_config.h" | 20 #include "build/build_config.h" |
| 21 #include "ipc/ipc_channel_factory.h" | 21 #include "ipc/ipc_channel_factory.h" |
| 22 #include "ipc/ipc_listener.h" | 22 #include "ipc/ipc_listener.h" |
| 23 #include "ipc/ipc_logging.h" | 23 #include "ipc/ipc_logging.h" |
| 24 #include "ipc/ipc_message_macros.h" | 24 #include "ipc/ipc_message_macros.h" |
| 25 #include "ipc/message_filter.h" | 25 #include "ipc/message_filter.h" |
| 26 #include "ipc/message_filter_router.h" | 26 #include "ipc/message_filter_router.h" |
| 27 | 27 |
| 28 namespace IPC { | 28 namespace IPC { |
| 29 | 29 |
| 30 namespace { | |
| 31 | |
| 32 void BindAssociatedInterfaceOnTaskRunner( | |
| 33 scoped_refptr<base::SingleThreadTaskRunner> task_runner, | |
| 34 const ChannelProxy::GenericAssociatedInterfaceFactory& factory, | |
| 35 mojo::ScopedInterfaceEndpointHandle handle) { | |
| 36 task_runner->PostTask(FROM_HERE, base::Bind(factory, base::Passed(&handle))); | |
| 37 } | |
| 38 | |
| 39 } // namespace | |
| 40 | |
| 41 //------------------------------------------------------------------------------ | 30 //------------------------------------------------------------------------------ |
| 42 | 31 |
| 43 ChannelProxy::Context::Context( | 32 ChannelProxy::Context::Context( |
| 44 Listener* listener, | 33 Listener* listener, |
| 45 const scoped_refptr<base::SingleThreadTaskRunner>& ipc_task_runner) | 34 const scoped_refptr<base::SingleThreadTaskRunner>& ipc_task_runner) |
| 46 : listener_task_runner_(base::ThreadTaskRunnerHandle::Get()), | 35 : listener_task_runner_(base::ThreadTaskRunnerHandle::Get()), |
| 47 listener_(listener), | 36 listener_(listener), |
| 48 ipc_task_runner_(ipc_task_runner), | 37 ipc_task_runner_(ipc_task_runner), |
| 49 channel_connected_called_(false), | 38 channel_connected_called_(false), |
| 50 message_filter_router_(new MessageFilterRouter()), | 39 message_filter_router_(new MessageFilterRouter()), |
| (...skipping 23 matching lines...) Expand all Loading... |
| 74 DCHECK(!channel_); | 63 DCHECK(!channel_); |
| 75 DCHECK_EQ(factory->GetIPCTaskRunner(), ipc_task_runner_); | 64 DCHECK_EQ(factory->GetIPCTaskRunner(), ipc_task_runner_); |
| 76 channel_ = factory->BuildChannel(this); | 65 channel_ = factory->BuildChannel(this); |
| 77 | 66 |
| 78 Channel::AssociatedInterfaceSupport* support = | 67 Channel::AssociatedInterfaceSupport* support = |
| 79 channel_->GetAssociatedInterfaceSupport(); | 68 channel_->GetAssociatedInterfaceSupport(); |
| 80 if (support) { | 69 if (support) { |
| 81 associated_group_ = *support->GetAssociatedGroup(); | 70 associated_group_ = *support->GetAssociatedGroup(); |
| 82 | 71 |
| 83 base::AutoLock l(pending_filters_lock_); | 72 base::AutoLock l(pending_filters_lock_); |
| 84 for (auto& entry : pending_interfaces_) | 73 for (auto& entry : pending_io_thread_interfaces_) |
| 85 support->AddGenericAssociatedInterface(entry.first, entry.second); | 74 support->AddGenericAssociatedInterface(entry.first, entry.second); |
| 86 pending_interfaces_.clear(); | 75 pending_io_thread_interfaces_.clear(); |
| 87 } | 76 } |
| 88 } | 77 } |
| 89 | 78 |
| 90 bool ChannelProxy::Context::TryFilters(const Message& message) { | 79 bool ChannelProxy::Context::TryFilters(const Message& message) { |
| 91 DCHECK(message_filter_router_); | 80 DCHECK(message_filter_router_); |
| 92 #ifdef IPC_MESSAGE_LOG_ENABLED | 81 #ifdef IPC_MESSAGE_LOG_ENABLED |
| 93 Logging* logger = Logging::GetInstance(); | 82 Logging* logger = Logging::GetInstance(); |
| 94 if (logger->Enabled()) | 83 if (logger->Enabled()) |
| 95 logger->OnPreDispatchMessage(message); | 84 logger->OnPreDispatchMessage(message); |
| 96 #endif | 85 #endif |
| (...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 381 if (listener_) | 370 if (listener_) |
| 382 listener_->OnAssociatedInterfaceRequest(interface_name, std::move(handle)); | 371 listener_->OnAssociatedInterfaceRequest(interface_name, std::move(handle)); |
| 383 } | 372 } |
| 384 | 373 |
| 385 void ChannelProxy::Context::ClearChannel() { | 374 void ChannelProxy::Context::ClearChannel() { |
| 386 base::AutoLock l(channel_lifetime_lock_); | 375 base::AutoLock l(channel_lifetime_lock_); |
| 387 channel_.reset(); | 376 channel_.reset(); |
| 388 associated_group_ = mojo::AssociatedGroup(); | 377 associated_group_ = mojo::AssociatedGroup(); |
| 389 } | 378 } |
| 390 | 379 |
| 391 void ChannelProxy::Context::AddGenericAssociatedInterface( | |
| 392 const std::string& name, | |
| 393 const GenericAssociatedInterfaceFactory& factory) { | |
| 394 AddGenericAssociatedInterfaceForIOThread( | |
| 395 name, base::Bind(&BindAssociatedInterfaceOnTaskRunner, | |
| 396 listener_task_runner_, factory)); | |
| 397 } | |
| 398 | |
| 399 void ChannelProxy::Context::AddGenericAssociatedInterfaceForIOThread( | 380 void ChannelProxy::Context::AddGenericAssociatedInterfaceForIOThread( |
| 400 const std::string& name, | 381 const std::string& name, |
| 401 const GenericAssociatedInterfaceFactory& factory) { | 382 const GenericAssociatedInterfaceFactory& factory) { |
| 402 base::AutoLock l(channel_lifetime_lock_); | 383 base::AutoLock l(channel_lifetime_lock_); |
| 403 if (!channel_) { | 384 if (!channel_) { |
| 404 base::AutoLock l(pending_filters_lock_); | 385 base::AutoLock l(pending_filters_lock_); |
| 405 pending_interfaces_.emplace_back(name, factory); | 386 pending_io_thread_interfaces_.emplace_back(name, factory); |
| 406 return; | 387 return; |
| 407 } | 388 } |
| 408 Channel::AssociatedInterfaceSupport* support = | 389 Channel::AssociatedInterfaceSupport* support = |
| 409 channel_->GetAssociatedInterfaceSupport(); | 390 channel_->GetAssociatedInterfaceSupport(); |
| 410 if (support) | 391 if (support) |
| 411 support->AddGenericAssociatedInterface(name, factory); | 392 support->AddGenericAssociatedInterface(name, factory); |
| 412 } | 393 } |
| 413 | 394 |
| 414 void ChannelProxy::Context::Send(Message* message) { | 395 void ChannelProxy::Context::Send(Message* message) { |
| 415 ipc_task_runner()->PostTask( | 396 ipc_task_runner()->PostTask( |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 578 } | 559 } |
| 579 | 560 |
| 580 void ChannelProxy::RemoveFilter(MessageFilter* filter) { | 561 void ChannelProxy::RemoveFilter(MessageFilter* filter) { |
| 581 DCHECK(CalledOnValidThread()); | 562 DCHECK(CalledOnValidThread()); |
| 582 | 563 |
| 583 context_->ipc_task_runner()->PostTask( | 564 context_->ipc_task_runner()->PostTask( |
| 584 FROM_HERE, base::Bind(&Context::OnRemoveFilter, context_, | 565 FROM_HERE, base::Bind(&Context::OnRemoveFilter, context_, |
| 585 base::RetainedRef(filter))); | 566 base::RetainedRef(filter))); |
| 586 } | 567 } |
| 587 | 568 |
| 588 void ChannelProxy::AddGenericAssociatedInterface( | |
| 589 const std::string& name, | |
| 590 const GenericAssociatedInterfaceFactory& factory) { | |
| 591 context()->AddGenericAssociatedInterface(name, factory); | |
| 592 } | |
| 593 | |
| 594 void ChannelProxy::AddGenericAssociatedInterfaceForIOThread( | 569 void ChannelProxy::AddGenericAssociatedInterfaceForIOThread( |
| 595 const std::string& name, | 570 const std::string& name, |
| 596 const GenericAssociatedInterfaceFactory& factory) { | 571 const GenericAssociatedInterfaceFactory& factory) { |
| 597 context()->AddGenericAssociatedInterfaceForIOThread(name, factory); | 572 context()->AddGenericAssociatedInterfaceForIOThread(name, factory); |
| 598 } | 573 } |
| 599 | 574 |
| 600 mojo::AssociatedGroup* ChannelProxy::GetAssociatedGroup() { | 575 mojo::AssociatedGroup* ChannelProxy::GetAssociatedGroup() { |
| 601 return context()->associated_group(); | 576 return context()->associated_group(); |
| 602 } | 577 } |
| 603 | 578 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 615 | 590 |
| 616 context()->ClearIPCTaskRunner(); | 591 context()->ClearIPCTaskRunner(); |
| 617 } | 592 } |
| 618 | 593 |
| 619 void ChannelProxy::OnChannelInit() { | 594 void ChannelProxy::OnChannelInit() { |
| 620 } | 595 } |
| 621 | 596 |
| 622 //----------------------------------------------------------------------------- | 597 //----------------------------------------------------------------------------- |
| 623 | 598 |
| 624 } // namespace IPC | 599 } // namespace IPC |
| OLD | NEW |