| 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> |
| (...skipping 472 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 483 DCHECK(!did_init_); | 483 DCHECK(!did_init_); |
| 484 | 484 |
| 485 if (create_pipe_now) { | 485 if (create_pipe_now) { |
| 486 // Create the channel immediately. This effectively sets up the | 486 // Create the channel immediately. This effectively sets up the |
| 487 // low-level pipe so that the client can connect. Without creating | 487 // low-level pipe so that the client can connect. Without creating |
| 488 // the pipe immediately, it is possible for a listener to attempt | 488 // the pipe immediately, it is possible for a listener to attempt |
| 489 // to connect and get an error since the pipe doesn't exist yet. | 489 // to connect and get an error since the pipe doesn't exist yet. |
| 490 context_->CreateChannel(std::move(factory)); | 490 context_->CreateChannel(std::move(factory)); |
| 491 } else { | 491 } else { |
| 492 context_->ipc_task_runner()->PostTask( | 492 context_->ipc_task_runner()->PostTask( |
| 493 FROM_HERE, base::Bind(&Context::CreateChannel, context_.get(), | 493 FROM_HERE, base::Bind(&Context::CreateChannel, context_, |
| 494 base::Passed(&factory))); | 494 base::Passed(&factory))); |
| 495 } | 495 } |
| 496 | 496 |
| 497 // complete initialization on the background thread | 497 // complete initialization on the background thread |
| 498 context_->ipc_task_runner()->PostTask( | 498 context_->ipc_task_runner()->PostTask( |
| 499 FROM_HERE, base::Bind(&Context::OnChannelOpened, context_.get())); | 499 FROM_HERE, base::Bind(&Context::OnChannelOpened, context_)); |
| 500 | 500 |
| 501 did_init_ = true; | 501 did_init_ = true; |
| 502 OnChannelInit(); | 502 OnChannelInit(); |
| 503 } | 503 } |
| 504 | 504 |
| 505 void ChannelProxy::Close() { | 505 void ChannelProxy::Close() { |
| 506 DCHECK(CalledOnValidThread()); | 506 DCHECK(CalledOnValidThread()); |
| 507 | 507 |
| 508 // Clear the backpointer to the listener so that any pending calls to | 508 // Clear the backpointer to the listener so that any pending calls to |
| 509 // Context::OnDispatchMessage or OnDispatchError will be ignored. It is | 509 // Context::OnDispatchMessage or OnDispatchError will be ignored. It is |
| 510 // possible that the channel could be closed while it is receiving messages! | 510 // possible that the channel could be closed while it is receiving messages! |
| 511 context_->Clear(); | 511 context_->Clear(); |
| 512 | 512 |
| 513 if (context_->ipc_task_runner()) { | 513 if (context_->ipc_task_runner()) { |
| 514 context_->ipc_task_runner()->PostTask( | 514 context_->ipc_task_runner()->PostTask( |
| 515 FROM_HERE, base::Bind(&Context::OnChannelClosed, context_.get())); | 515 FROM_HERE, base::Bind(&Context::OnChannelClosed, context_)); |
| 516 } | 516 } |
| 517 } | 517 } |
| 518 | 518 |
| 519 bool ChannelProxy::Send(Message* message) { | 519 bool ChannelProxy::Send(Message* message) { |
| 520 DCHECK(did_init_); | 520 DCHECK(did_init_); |
| 521 | 521 |
| 522 // TODO(alexeypa): add DCHECK(CalledOnValidThread()) here. Currently there are | 522 // TODO(alexeypa): add DCHECK(CalledOnValidThread()) here. Currently there are |
| 523 // tests that call Send() from a wrong thread. See http://crbug.com/163523. | 523 // tests that call Send() from a wrong thread. See http://crbug.com/163523. |
| 524 | 524 |
| 525 #ifdef ENABLE_IPC_FUZZER | 525 #ifdef ENABLE_IPC_FUZZER |
| (...skipping 15 matching lines...) Expand all Loading... |
| 541 void ChannelProxy::AddFilter(MessageFilter* filter) { | 541 void ChannelProxy::AddFilter(MessageFilter* filter) { |
| 542 DCHECK(CalledOnValidThread()); | 542 DCHECK(CalledOnValidThread()); |
| 543 | 543 |
| 544 context_->AddFilter(filter); | 544 context_->AddFilter(filter); |
| 545 } | 545 } |
| 546 | 546 |
| 547 void ChannelProxy::RemoveFilter(MessageFilter* filter) { | 547 void ChannelProxy::RemoveFilter(MessageFilter* filter) { |
| 548 DCHECK(CalledOnValidThread()); | 548 DCHECK(CalledOnValidThread()); |
| 549 | 549 |
| 550 context_->ipc_task_runner()->PostTask( | 550 context_->ipc_task_runner()->PostTask( |
| 551 FROM_HERE, base::Bind(&Context::OnRemoveFilter, context_.get(), | 551 FROM_HERE, base::Bind(&Context::OnRemoveFilter, context_, |
| 552 base::RetainedRef(filter))); | 552 base::RetainedRef(filter))); |
| 553 } | 553 } |
| 554 | 554 |
| 555 void ChannelProxy::AddGenericAssociatedInterface( | 555 void ChannelProxy::AddGenericAssociatedInterface( |
| 556 const std::string& name, | 556 const std::string& name, |
| 557 const GenericAssociatedInterfaceFactory& factory) { | 557 const GenericAssociatedInterfaceFactory& factory) { |
| 558 context()->AddGenericAssociatedInterface(name, factory); | 558 context()->AddGenericAssociatedInterface(name, factory); |
| 559 } | 559 } |
| 560 | 560 |
| 561 void ChannelProxy::AddGenericAssociatedInterfaceForIOThread( | 561 void ChannelProxy::AddGenericAssociatedInterfaceForIOThread( |
| 562 const std::string& name, | 562 const std::string& name, |
| 563 const GenericAssociatedInterfaceFactory& factory) { | 563 const GenericAssociatedInterfaceFactory& factory) { |
| 564 context()->AddGenericAssociatedInterfaceForIOThread(name, factory); | 564 context()->AddGenericAssociatedInterfaceForIOThread(name, factory); |
| 565 } | 565 } |
| 566 | 566 |
| 567 mojo::AssociatedGroup* ChannelProxy::GetAssociatedGroup() { | 567 mojo::AssociatedGroup* ChannelProxy::GetAssociatedGroup() { |
| 568 return context()->associated_group(); | 568 return context()->associated_group(); |
| 569 } | 569 } |
| 570 | 570 |
| 571 void ChannelProxy::GetGenericRemoteAssociatedInterface( | 571 void ChannelProxy::GetGenericRemoteAssociatedInterface( |
| 572 const std::string& name, | 572 const std::string& name, |
| 573 mojo::ScopedInterfaceEndpointHandle handle) { | 573 mojo::ScopedInterfaceEndpointHandle handle) { |
| 574 DCHECK(did_init_); | 574 DCHECK(did_init_); |
| 575 context_->ipc_task_runner()->PostTask( | 575 context_->ipc_task_runner()->PostTask( |
| 576 FROM_HERE, base::Bind(&Context::GetRemoteAssociatedInterface, | 576 FROM_HERE, base::Bind(&Context::GetRemoteAssociatedInterface, |
| 577 context_.get(), name, base::Passed(&handle))); | 577 context_, name, base::Passed(&handle))); |
| 578 } | 578 } |
| 579 | 579 |
| 580 void ChannelProxy::ClearIPCTaskRunner() { | 580 void ChannelProxy::ClearIPCTaskRunner() { |
| 581 DCHECK(CalledOnValidThread()); | 581 DCHECK(CalledOnValidThread()); |
| 582 | 582 |
| 583 context()->ClearIPCTaskRunner(); | 583 context()->ClearIPCTaskRunner(); |
| 584 } | 584 } |
| 585 | 585 |
| 586 base::ProcessId ChannelProxy::GetPeerPID() const { | 586 base::ProcessId ChannelProxy::GetPeerPID() const { |
| 587 base::AutoLock l(context_->peer_pid_lock_); | 587 base::AutoLock l(context_->peer_pid_lock_); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 614 return channel->TakeClientFileDescriptor(); | 614 return channel->TakeClientFileDescriptor(); |
| 615 } | 615 } |
| 616 #endif | 616 #endif |
| 617 | 617 |
| 618 void ChannelProxy::OnChannelInit() { | 618 void ChannelProxy::OnChannelInit() { |
| 619 } | 619 } |
| 620 | 620 |
| 621 //----------------------------------------------------------------------------- | 621 //----------------------------------------------------------------------------- |
| 622 | 622 |
| 623 } // namespace IPC | 623 } // namespace IPC |
| OLD | NEW |