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 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
108 #ifdef IPC_MESSAGE_LOG_ENABLED | 108 #ifdef IPC_MESSAGE_LOG_ENABLED |
109 if (logger->Enabled()) | 109 if (logger->Enabled()) |
110 logger->OnPostDispatchMessage(message, channel_id_); | 110 logger->OnPostDispatchMessage(message, channel_id_); |
111 #endif | 111 #endif |
112 return true; | 112 return true; |
113 } | 113 } |
114 return false; | 114 return false; |
115 } | 115 } |
116 | 116 |
117 // Called on the IPC::Channel thread | 117 // Called on the IPC::Channel thread |
| 118 void ChannelProxy::Context::PauseChannel() { |
| 119 DCHECK(channel_); |
| 120 channel_->Pause(); |
| 121 } |
| 122 |
| 123 // Called on the IPC::Channel thread |
118 void ChannelProxy::Context::UnpauseChannel(bool flush) { | 124 void ChannelProxy::Context::UnpauseChannel(bool flush) { |
119 DCHECK(channel_); | 125 DCHECK(channel_); |
120 channel_->Unpause(flush); | 126 channel_->Unpause(flush); |
121 } | 127 } |
122 | 128 |
123 // Called on the IPC::Channel thread | 129 // Called on the IPC::Channel thread |
124 void ChannelProxy::Context::FlushChannel() { | 130 void ChannelProxy::Context::FlushChannel() { |
125 DCHECK(channel_); | 131 DCHECK(channel_); |
126 channel_->Flush(); | 132 channel_->Flush(); |
127 } | 133 } |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
164 void ChannelProxy::Context::OnChannelError() { | 170 void ChannelProxy::Context::OnChannelError() { |
165 for (size_t i = 0; i < filters_.size(); ++i) | 171 for (size_t i = 0; i < filters_.size(); ++i) |
166 filters_[i]->OnChannelError(); | 172 filters_[i]->OnChannelError(); |
167 | 173 |
168 // See above comment about using listener_task_runner_ here. | 174 // See above comment about using listener_task_runner_ here. |
169 listener_task_runner_->PostTask( | 175 listener_task_runner_->PostTask( |
170 FROM_HERE, base::Bind(&Context::OnDispatchError, this)); | 176 FROM_HERE, base::Bind(&Context::OnDispatchError, this)); |
171 } | 177 } |
172 | 178 |
173 // Called on the IPC::Channel thread | 179 // Called on the IPC::Channel thread |
174 void ChannelProxy::Context::OnChannelOpened(bool pause) { | 180 void ChannelProxy::Context::OnChannelOpened() { |
175 DCHECK(channel_ != NULL); | 181 DCHECK(channel_ != NULL); |
176 | 182 |
177 // Assume a reference to ourselves on behalf of this thread. This reference | 183 // Assume a reference to ourselves on behalf of this thread. This reference |
178 // will be released when we are closed. | 184 // will be released when we are closed. |
179 AddRef(); | 185 AddRef(); |
180 | 186 |
181 bool success = pause ? channel_->ConnectPaused() : channel_->Connect(); | 187 if (!channel_->Connect()) { |
182 if (!success) { | |
183 OnChannelError(); | 188 OnChannelError(); |
184 return; | 189 return; |
185 } | 190 } |
186 | 191 |
187 for (size_t i = 0; i < filters_.size(); ++i) | 192 for (size_t i = 0; i < filters_.size(); ++i) |
188 filters_[i]->OnFilterAdded(channel_.get()); | 193 filters_[i]->OnFilterAdded(channel_.get()); |
189 } | 194 } |
190 | 195 |
191 // Called on the IPC::Channel thread | 196 // Called on the IPC::Channel thread |
192 void ChannelProxy::Context::OnChannelClosed() { | 197 void ChannelProxy::Context::OnChannelClosed() { |
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
468 } | 473 } |
469 | 474 |
470 ChannelProxy::~ChannelProxy() { | 475 ChannelProxy::~ChannelProxy() { |
471 DCHECK(CalledOnValidThread()); | 476 DCHECK(CalledOnValidThread()); |
472 | 477 |
473 Close(); | 478 Close(); |
474 } | 479 } |
475 | 480 |
476 void ChannelProxy::Init(const IPC::ChannelHandle& channel_handle, | 481 void ChannelProxy::Init(const IPC::ChannelHandle& channel_handle, |
477 Channel::Mode mode, | 482 Channel::Mode mode, |
478 bool create_pipe_now, | 483 bool create_pipe_now) { |
479 bool create_paused) { | |
480 #if defined(OS_POSIX) | 484 #if defined(OS_POSIX) |
481 // When we are creating a server on POSIX, we need its file descriptor | 485 // When we are creating a server on POSIX, we need its file descriptor |
482 // to be created immediately so that it can be accessed and passed | 486 // to be created immediately so that it can be accessed and passed |
483 // to other processes. Forcing it to be created immediately avoids | 487 // to other processes. Forcing it to be created immediately avoids |
484 // race conditions that may otherwise arise. | 488 // race conditions that may otherwise arise. |
485 if (mode & Channel::MODE_SERVER_FLAG) { | 489 if (mode & Channel::MODE_SERVER_FLAG) { |
486 create_pipe_now = true; | 490 create_pipe_now = true; |
487 } | 491 } |
488 #endif // defined(OS_POSIX) | 492 #endif // defined(OS_POSIX) |
489 Init( | 493 Init( |
490 ChannelFactory::Create(channel_handle, mode, context_->ipc_task_runner()), | 494 ChannelFactory::Create(channel_handle, mode, context_->ipc_task_runner()), |
491 create_pipe_now, create_paused); | 495 create_pipe_now); |
492 } | 496 } |
493 | 497 |
494 void ChannelProxy::Init(std::unique_ptr<ChannelFactory> factory, | 498 void ChannelProxy::Init(std::unique_ptr<ChannelFactory> factory, |
495 bool create_pipe_now, | 499 bool create_pipe_now) { |
496 bool create_paused) { | |
497 DCHECK(CalledOnValidThread()); | 500 DCHECK(CalledOnValidThread()); |
498 DCHECK(!did_init_); | 501 DCHECK(!did_init_); |
499 | 502 |
500 if (create_pipe_now) { | 503 if (create_pipe_now) { |
501 // Create the channel immediately. This effectively sets up the | 504 // Create the channel immediately. This effectively sets up the |
502 // low-level pipe so that the client can connect. Without creating | 505 // low-level pipe so that the client can connect. Without creating |
503 // the pipe immediately, it is possible for a listener to attempt | 506 // the pipe immediately, it is possible for a listener to attempt |
504 // to connect and get an error since the pipe doesn't exist yet. | 507 // to connect and get an error since the pipe doesn't exist yet. |
505 context_->CreateChannel(std::move(factory)); | 508 context_->CreateChannel(std::move(factory)); |
506 } else { | 509 } else { |
507 context_->ipc_task_runner()->PostTask( | 510 context_->ipc_task_runner()->PostTask( |
508 FROM_HERE, base::Bind(&Context::CreateChannel, context_, | 511 FROM_HERE, base::Bind(&Context::CreateChannel, context_, |
509 base::Passed(&factory))); | 512 base::Passed(&factory))); |
510 } | 513 } |
511 | 514 |
512 // complete initialization on the background thread | 515 // complete initialization on the background thread |
513 context_->ipc_task_runner()->PostTask( | 516 context_->ipc_task_runner()->PostTask( |
514 FROM_HERE, | 517 FROM_HERE, |
515 base::Bind(&Context::OnChannelOpened, context_, create_paused)); | 518 base::Bind(&Context::OnChannelOpened, context_)); |
516 | 519 |
517 did_init_ = true; | 520 did_init_ = true; |
518 OnChannelInit(); | 521 OnChannelInit(); |
519 } | 522 } |
520 | 523 |
| 524 void ChannelProxy::Pause() { |
| 525 context_->ipc_task_runner()->PostTask( |
| 526 FROM_HERE, base::Bind(&Context::PauseChannel, context_)); |
| 527 } |
| 528 |
521 void ChannelProxy::Unpause(bool flush) { | 529 void ChannelProxy::Unpause(bool flush) { |
522 context_->ipc_task_runner()->PostTask( | 530 context_->ipc_task_runner()->PostTask( |
523 FROM_HERE, base::Bind(&Context::UnpauseChannel, context_, flush)); | 531 FROM_HERE, base::Bind(&Context::UnpauseChannel, context_, flush)); |
524 } | 532 } |
525 | 533 |
526 void ChannelProxy::Flush() { | 534 void ChannelProxy::Flush() { |
527 context_->ipc_task_runner()->PostTask( | 535 context_->ipc_task_runner()->PostTask( |
528 FROM_HERE, base::Bind(&Context::FlushChannel, context_)); | 536 FROM_HERE, base::Bind(&Context::FlushChannel, context_)); |
529 } | 537 } |
530 | 538 |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
640 return channel->TakeClientFileDescriptor(); | 648 return channel->TakeClientFileDescriptor(); |
641 } | 649 } |
642 #endif | 650 #endif |
643 | 651 |
644 void ChannelProxy::OnChannelInit() { | 652 void ChannelProxy::OnChannelInit() { |
645 } | 653 } |
646 | 654 |
647 //----------------------------------------------------------------------------- | 655 //----------------------------------------------------------------------------- |
648 | 656 |
649 } // namespace IPC | 657 } // namespace IPC |
OLD | NEW |