| 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 "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
| 9 #include "base/location.h" | 9 #include "base/location.h" |
| 10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
| (...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 340 if (channel_send_thread_safe_) { | 340 if (channel_send_thread_safe_) { |
| 341 SendFromThisThread(message); | 341 SendFromThisThread(message); |
| 342 return; | 342 return; |
| 343 } | 343 } |
| 344 | 344 |
| 345 ipc_task_runner()->PostTask( | 345 ipc_task_runner()->PostTask( |
| 346 FROM_HERE, base::Bind(&ChannelProxy::Context::OnSendMessage, this, | 346 FROM_HERE, base::Bind(&ChannelProxy::Context::OnSendMessage, this, |
| 347 base::Passed(scoped_ptr<Message>(message)))); | 347 base::Passed(scoped_ptr<Message>(message)))); |
| 348 } | 348 } |
| 349 | 349 |
| 350 | |
| 351 //----------------------------------------------------------------------------- | 350 //----------------------------------------------------------------------------- |
| 352 | 351 |
| 353 // static | 352 // static |
| 354 scoped_ptr<ChannelProxy> ChannelProxy::Create( | 353 scoped_ptr<ChannelProxy> ChannelProxy::Create( |
| 355 const IPC::ChannelHandle& channel_handle, | 354 const IPC::ChannelHandle& channel_handle, |
| 356 Channel::Mode mode, | 355 Channel::Mode mode, |
| 357 Listener* listener, | 356 Listener* listener, |
| 358 const scoped_refptr<base::SingleThreadTaskRunner>& ipc_task_runner) { | 357 const scoped_refptr<base::SingleThreadTaskRunner>& ipc_task_runner, |
| 358 AttachmentBroker* broker) { |
| 359 scoped_ptr<ChannelProxy> channel(new ChannelProxy(listener, ipc_task_runner)); | 359 scoped_ptr<ChannelProxy> channel(new ChannelProxy(listener, ipc_task_runner)); |
| 360 channel->Init(channel_handle, mode, true); | 360 channel->Init(channel_handle, mode, true, broker); |
| 361 return channel.Pass(); | 361 return channel.Pass(); |
| 362 } | 362 } |
| 363 | 363 |
| 364 // static | 364 // static |
| 365 scoped_ptr<ChannelProxy> ChannelProxy::Create( | 365 scoped_ptr<ChannelProxy> ChannelProxy::Create( |
| 366 scoped_ptr<ChannelFactory> factory, | 366 scoped_ptr<ChannelFactory> factory, |
| 367 Listener* listener, | 367 Listener* listener, |
| 368 const scoped_refptr<base::SingleThreadTaskRunner>& ipc_task_runner) { | 368 const scoped_refptr<base::SingleThreadTaskRunner>& ipc_task_runner) { |
| 369 scoped_ptr<ChannelProxy> channel(new ChannelProxy(listener, ipc_task_runner)); | 369 scoped_ptr<ChannelProxy> channel(new ChannelProxy(listener, ipc_task_runner)); |
| 370 channel->Init(factory.Pass(), true); | 370 channel->Init(factory.Pass(), true); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 389 } | 389 } |
| 390 | 390 |
| 391 ChannelProxy::~ChannelProxy() { | 391 ChannelProxy::~ChannelProxy() { |
| 392 DCHECK(CalledOnValidThread()); | 392 DCHECK(CalledOnValidThread()); |
| 393 | 393 |
| 394 Close(); | 394 Close(); |
| 395 } | 395 } |
| 396 | 396 |
| 397 void ChannelProxy::Init(const IPC::ChannelHandle& channel_handle, | 397 void ChannelProxy::Init(const IPC::ChannelHandle& channel_handle, |
| 398 Channel::Mode mode, | 398 Channel::Mode mode, |
| 399 bool create_pipe_now) { | 399 bool create_pipe_now, |
| 400 AttachmentBroker* broker) { |
| 400 #if defined(OS_POSIX) | 401 #if defined(OS_POSIX) |
| 401 // When we are creating a server on POSIX, we need its file descriptor | 402 // When we are creating a server on POSIX, we need its file descriptor |
| 402 // to be created immediately so that it can be accessed and passed | 403 // to be created immediately so that it can be accessed and passed |
| 403 // to other processes. Forcing it to be created immediately avoids | 404 // to other processes. Forcing it to be created immediately avoids |
| 404 // race conditions that may otherwise arise. | 405 // race conditions that may otherwise arise. |
| 405 if (mode & Channel::MODE_SERVER_FLAG) { | 406 if (mode & Channel::MODE_SERVER_FLAG) { |
| 406 create_pipe_now = true; | 407 create_pipe_now = true; |
| 407 } | 408 } |
| 408 #endif // defined(OS_POSIX) | 409 #endif // defined(OS_POSIX) |
| 409 Init(ChannelFactory::Create(channel_handle, mode), | 410 Init(ChannelFactory::Create(channel_handle, mode, broker), create_pipe_now); |
| 410 create_pipe_now); | |
| 411 } | 411 } |
| 412 | 412 |
| 413 void ChannelProxy::Init(scoped_ptr<ChannelFactory> factory, | 413 void ChannelProxy::Init(scoped_ptr<ChannelFactory> factory, |
| 414 bool create_pipe_now) { | 414 bool create_pipe_now) { |
| 415 DCHECK(CalledOnValidThread()); | 415 DCHECK(CalledOnValidThread()); |
| 416 DCHECK(!did_init_); | 416 DCHECK(!did_init_); |
| 417 | 417 |
| 418 if (create_pipe_now) { | 418 if (create_pipe_now) { |
| 419 // Create the channel immediately. This effectively sets up the | 419 // Create the channel immediately. This effectively sets up the |
| 420 // low-level pipe so that the client can connect. Without creating | 420 // low-level pipe so that the client can connect. Without creating |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 515 Channel* channel = context_.get()->channel_.get(); | 515 Channel* channel = context_.get()->channel_.get(); |
| 516 // Channel must have been created first. | 516 // Channel must have been created first. |
| 517 DCHECK(channel) << context_.get()->channel_id_; | 517 DCHECK(channel) << context_.get()->channel_id_; |
| 518 return channel->TakeClientFileDescriptor(); | 518 return channel->TakeClientFileDescriptor(); |
| 519 } | 519 } |
| 520 #endif | 520 #endif |
| 521 | 521 |
| 522 //----------------------------------------------------------------------------- | 522 //----------------------------------------------------------------------------- |
| 523 | 523 |
| 524 } // namespace IPC | 524 } // namespace IPC |
| OLD | NEW |