Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(8)

Side by Side Diff: ipc/ipc_sync_channel.cc

Issue 310853003: Add IPC::ChannelProxy::Create() and IPC::SyncChannel::Create() (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Landing Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ipc/ipc_sync_channel.h ('k') | ipc/ipc_sync_channel_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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_sync_channel.h" 5 #include "ipc/ipc_sync_channel.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/debug/trace_event.h" 8 #include "base/debug/trace_event.h"
9 #include "base/lazy_instance.h" 9 #include "base/lazy_instance.h"
10 #include "base/location.h" 10 #include "base/location.h"
(...skipping 386 matching lines...) Expand 10 before | Expand all | Expand 10 after
397 DCHECK_EQ(GetSendDoneEvent(), event); 397 DCHECK_EQ(GetSendDoneEvent(), event);
398 base::MessageLoop::current()->QuitNow(); 398 base::MessageLoop::current()->QuitNow();
399 } 399 }
400 } 400 }
401 401
402 base::WaitableEventWatcher::EventCallback 402 base::WaitableEventWatcher::EventCallback
403 SyncChannel::SyncContext::MakeWaitableEventCallback() { 403 SyncChannel::SyncContext::MakeWaitableEventCallback() {
404 return base::Bind(&SyncChannel::SyncContext::OnWaitableEventSignaled, this); 404 return base::Bind(&SyncChannel::SyncContext::OnWaitableEventSignaled, this);
405 } 405 }
406 406
407 SyncChannel::SyncChannel( 407 // static
408 scoped_ptr<SyncChannel> SyncChannel::Create(
408 const IPC::ChannelHandle& channel_handle, 409 const IPC::ChannelHandle& channel_handle,
409 Channel::Mode mode, 410 Channel::Mode mode,
410 Listener* listener, 411 Listener* listener,
411 base::SingleThreadTaskRunner* ipc_task_runner, 412 base::SingleThreadTaskRunner* ipc_task_runner,
412 bool create_pipe_now, 413 bool create_pipe_now,
413 WaitableEvent* shutdown_event) 414 base::WaitableEvent* shutdown_event) {
414 : ChannelProxy(new SyncContext(listener, ipc_task_runner, shutdown_event)) { 415 scoped_ptr<SyncChannel> channel =
415 // The current (listener) thread must be distinct from the IPC thread, or else 416 Create(listener, ipc_task_runner, shutdown_event);
416 // sending synchronous messages will deadlock. 417 channel->Init(channel_handle, mode, create_pipe_now);
417 DCHECK_NE(ipc_task_runner, base::ThreadTaskRunnerHandle::Get()); 418 return channel.Pass();
418 ChannelProxy::Init(channel_handle, mode, create_pipe_now); 419 }
419 StartWatching(); 420
421 // static
422 scoped_ptr<SyncChannel> SyncChannel::Create(
423 Listener* listener,
424 base::SingleThreadTaskRunner* ipc_task_runner,
425 WaitableEvent* shutdown_event) {
426 return make_scoped_ptr(
427 new SyncChannel(listener, ipc_task_runner, shutdown_event));
420 } 428 }
421 429
422 SyncChannel::SyncChannel( 430 SyncChannel::SyncChannel(
423 Listener* listener, 431 Listener* listener,
424 base::SingleThreadTaskRunner* ipc_task_runner, 432 base::SingleThreadTaskRunner* ipc_task_runner,
425 WaitableEvent* shutdown_event) 433 WaitableEvent* shutdown_event)
426 : ChannelProxy(new SyncContext(listener, ipc_task_runner, shutdown_event)) { 434 : ChannelProxy(new SyncContext(listener, ipc_task_runner, shutdown_event)) {
427 // The current (listener) thread must be distinct from the IPC thread, or else 435 // The current (listener) thread must be distinct from the IPC thread, or else
428 // sending synchronous messages will deadlock. 436 // sending synchronous messages will deadlock.
429 DCHECK_NE(ipc_task_runner, base::ThreadTaskRunnerHandle::Get()); 437 DCHECK_NE(ipc_task_runner, base::ThreadTaskRunnerHandle::Get());
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
556 // manual reset since the object watcher might otherwise reset the event 564 // manual reset since the object watcher might otherwise reset the event
557 // when we're doing a WaitMany. 565 // when we're doing a WaitMany.
558 dispatch_watcher_callback_ = 566 dispatch_watcher_callback_ =
559 base::Bind(&SyncChannel::OnWaitableEventSignaled, 567 base::Bind(&SyncChannel::OnWaitableEventSignaled,
560 base::Unretained(this)); 568 base::Unretained(this));
561 dispatch_watcher_.StartWatching(sync_context()->GetDispatchEvent(), 569 dispatch_watcher_.StartWatching(sync_context()->GetDispatchEvent(),
562 dispatch_watcher_callback_); 570 dispatch_watcher_callback_);
563 } 571 }
564 572
565 } // namespace IPC 573 } // namespace IPC
OLDNEW
« no previous file with comments | « ipc/ipc_sync_channel.h ('k') | ipc/ipc_sync_channel_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698