| 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 421 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 432 ChannelProxy::ChannelProxy( | 432 ChannelProxy::ChannelProxy( |
| 433 Listener* listener, | 433 Listener* listener, |
| 434 const scoped_refptr<base::SingleThreadTaskRunner>& ipc_task_runner) | 434 const scoped_refptr<base::SingleThreadTaskRunner>& ipc_task_runner) |
| 435 : context_(new Context(listener, ipc_task_runner)), did_init_(false) { | 435 : context_(new Context(listener, ipc_task_runner)), did_init_(false) { |
| 436 #if defined(ENABLE_IPC_FUZZER) | 436 #if defined(ENABLE_IPC_FUZZER) |
| 437 outgoing_message_filter_ = NULL; | 437 outgoing_message_filter_ = NULL; |
| 438 #endif | 438 #endif |
| 439 } | 439 } |
| 440 | 440 |
| 441 ChannelProxy::~ChannelProxy() { | 441 ChannelProxy::~ChannelProxy() { |
| 442 DCHECK(CalledOnValidThread()); | 442 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
| 443 | 443 |
| 444 Close(); | 444 Close(); |
| 445 } | 445 } |
| 446 | 446 |
| 447 void ChannelProxy::Init(const IPC::ChannelHandle& channel_handle, | 447 void ChannelProxy::Init(const IPC::ChannelHandle& channel_handle, |
| 448 Channel::Mode mode, | 448 Channel::Mode mode, |
| 449 bool create_pipe_now) { | 449 bool create_pipe_now) { |
| 450 #if defined(OS_POSIX) | 450 #if defined(OS_POSIX) |
| 451 // When we are creating a server on POSIX, we need its file descriptor | 451 // When we are creating a server on POSIX, we need its file descriptor |
| 452 // to be created immediately so that it can be accessed and passed | 452 // to be created immediately so that it can be accessed and passed |
| 453 // to other processes. Forcing it to be created immediately avoids | 453 // to other processes. Forcing it to be created immediately avoids |
| 454 // race conditions that may otherwise arise. | 454 // race conditions that may otherwise arise. |
| 455 if (mode & Channel::MODE_SERVER_FLAG) { | 455 if (mode & Channel::MODE_SERVER_FLAG) { |
| 456 create_pipe_now = true; | 456 create_pipe_now = true; |
| 457 } | 457 } |
| 458 #endif // defined(OS_POSIX) | 458 #endif // defined(OS_POSIX) |
| 459 Init( | 459 Init( |
| 460 ChannelFactory::Create(channel_handle, mode, context_->ipc_task_runner()), | 460 ChannelFactory::Create(channel_handle, mode, context_->ipc_task_runner()), |
| 461 create_pipe_now); | 461 create_pipe_now); |
| 462 } | 462 } |
| 463 | 463 |
| 464 void ChannelProxy::Init(std::unique_ptr<ChannelFactory> factory, | 464 void ChannelProxy::Init(std::unique_ptr<ChannelFactory> factory, |
| 465 bool create_pipe_now) { | 465 bool create_pipe_now) { |
| 466 DCHECK(CalledOnValidThread()); | 466 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
| 467 DCHECK(!did_init_); | 467 DCHECK(!did_init_); |
| 468 | 468 |
| 469 if (create_pipe_now) { | 469 if (create_pipe_now) { |
| 470 // Create the channel immediately. This effectively sets up the | 470 // Create the channel immediately. This effectively sets up the |
| 471 // low-level pipe so that the client can connect. Without creating | 471 // low-level pipe so that the client can connect. Without creating |
| 472 // the pipe immediately, it is possible for a listener to attempt | 472 // the pipe immediately, it is possible for a listener to attempt |
| 473 // to connect and get an error since the pipe doesn't exist yet. | 473 // to connect and get an error since the pipe doesn't exist yet. |
| 474 context_->CreateChannel(std::move(factory)); | 474 context_->CreateChannel(std::move(factory)); |
| 475 } else { | 475 } else { |
| 476 context_->ipc_task_runner()->PostTask( | 476 context_->ipc_task_runner()->PostTask( |
| (...skipping 19 matching lines...) Expand all Loading... |
| 496 context_->ipc_task_runner()->PostTask( | 496 context_->ipc_task_runner()->PostTask( |
| 497 FROM_HERE, base::Bind(&Context::UnpauseChannel, context_, flush)); | 497 FROM_HERE, base::Bind(&Context::UnpauseChannel, context_, flush)); |
| 498 } | 498 } |
| 499 | 499 |
| 500 void ChannelProxy::Flush() { | 500 void ChannelProxy::Flush() { |
| 501 context_->ipc_task_runner()->PostTask( | 501 context_->ipc_task_runner()->PostTask( |
| 502 FROM_HERE, base::Bind(&Context::FlushChannel, context_)); | 502 FROM_HERE, base::Bind(&Context::FlushChannel, context_)); |
| 503 } | 503 } |
| 504 | 504 |
| 505 void ChannelProxy::Close() { | 505 void ChannelProxy::Close() { |
| 506 DCHECK(CalledOnValidThread()); | 506 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
| 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_)); | 515 FROM_HERE, base::Bind(&Context::OnChannelClosed, context_)); |
| 516 } | 516 } |
| (...skipping 15 matching lines...) Expand all Loading... |
| 532 | 532 |
| 533 #if BUILDFLAG(IPC_MESSAGE_LOG_ENABLED) | 533 #if BUILDFLAG(IPC_MESSAGE_LOG_ENABLED) |
| 534 Logging::GetInstance()->OnSendMessage(message); | 534 Logging::GetInstance()->OnSendMessage(message); |
| 535 #endif | 535 #endif |
| 536 | 536 |
| 537 context_->Send(message); | 537 context_->Send(message); |
| 538 return true; | 538 return true; |
| 539 } | 539 } |
| 540 | 540 |
| 541 void ChannelProxy::AddFilter(MessageFilter* filter) { | 541 void ChannelProxy::AddFilter(MessageFilter* filter) { |
| 542 DCHECK(CalledOnValidThread()); | 542 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
| 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_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
| 549 | 549 |
| 550 context_->ipc_task_runner()->PostTask( | 550 context_->ipc_task_runner()->PostTask( |
| 551 FROM_HERE, base::Bind(&Context::OnRemoveFilter, context_, | 551 FROM_HERE, base::Bind(&Context::OnRemoveFilter, context_, |
| 552 base::RetainedRef(filter))); | 552 base::RetainedRef(filter))); |
| 553 } | 553 } |
| 554 | 554 |
| 555 void ChannelProxy::AddGenericAssociatedInterfaceForIOThread( | 555 void ChannelProxy::AddGenericAssociatedInterfaceForIOThread( |
| 556 const std::string& name, | 556 const std::string& name, |
| 557 const GenericAssociatedInterfaceFactory& factory) { | 557 const GenericAssociatedInterfaceFactory& factory) { |
| 558 context()->AddGenericAssociatedInterfaceForIOThread(name, factory); | 558 context()->AddGenericAssociatedInterfaceForIOThread(name, factory); |
| 559 } | 559 } |
| 560 | 560 |
| 561 void ChannelProxy::GetGenericRemoteAssociatedInterface( | 561 void ChannelProxy::GetGenericRemoteAssociatedInterface( |
| 562 const std::string& name, | 562 const std::string& name, |
| 563 mojo::ScopedInterfaceEndpointHandle handle) { | 563 mojo::ScopedInterfaceEndpointHandle handle) { |
| 564 DCHECK(did_init_); | 564 DCHECK(did_init_); |
| 565 context()->thread_safe_channel().GetAssociatedInterface( | 565 context()->thread_safe_channel().GetAssociatedInterface( |
| 566 name, mojom::GenericInterfaceAssociatedRequest(std::move(handle))); | 566 name, mojom::GenericInterfaceAssociatedRequest(std::move(handle))); |
| 567 } | 567 } |
| 568 | 568 |
| 569 void ChannelProxy::ClearIPCTaskRunner() { | 569 void ChannelProxy::ClearIPCTaskRunner() { |
| 570 DCHECK(CalledOnValidThread()); | 570 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
| 571 context()->ClearIPCTaskRunner(); | 571 context()->ClearIPCTaskRunner(); |
| 572 } | 572 } |
| 573 | 573 |
| 574 void ChannelProxy::OnChannelInit() { | 574 void ChannelProxy::OnChannelInit() { |
| 575 } | 575 } |
| 576 | 576 |
| 577 //----------------------------------------------------------------------------- | 577 //----------------------------------------------------------------------------- |
| 578 | 578 |
| 579 } // namespace IPC | 579 } // namespace IPC |
| OLD | NEW |