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

Side by Side Diff: chrome/common/ipc_sync_channel.cc

Issue 18324: POSIX: Get IPCSyncChannel unittests working (Closed)
Patch Set: Addressing comments Created 11 years, 11 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
« no previous file with comments | « chrome/common/common.scons ('k') | chrome/common/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) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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 "chrome/common/ipc_sync_channel.h" 5 #include "chrome/common/ipc_sync_channel.h"
6 6
7 #include "base/lazy_instance.h" 7 #include "base/lazy_instance.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/thread_local.h" 9 #include "base/thread_local.h"
10 #include "base/message_loop.h" 10 #include "base/message_loop.h"
11 #include "base/waitable_event.h" 11 #include "base/waitable_event.h"
12 #include "base/waitable_event_watcher.h" 12 #include "base/waitable_event_watcher.h"
13 #include "chrome/common/ipc_logging.h" 13 #include "chrome/common/ipc_logging.h"
14 #include "chrome/common/ipc_sync_message.h" 14 #include "chrome/common/ipc_sync_message.h"
15 15
16 #if !defined(OS_WIN)
17 #define INFINITE -1
18 #endif
19
20 using base::TimeDelta; 16 using base::TimeDelta;
21 using base::TimeTicks; 17 using base::TimeTicks;
22 using base::WaitableEvent; 18 using base::WaitableEvent;
23 19
24 namespace IPC { 20 namespace IPC {
25 // When we're blocked in a Send(), we need to process incoming synchronous 21 // When we're blocked in a Send(), we need to process incoming synchronous
26 // messages right away because it could be blocking our reply (either 22 // messages right away because it could be blocking our reply (either
27 // directly from the same object we're calling, or indirectly through one or 23 // directly from the same object we're calling, or indirectly through one or
28 // more other channels). That means that in SyncContext's OnMessageReceived, 24 // more other channels). That means that in SyncContext's OnMessageReceived,
29 // we need to process sync message right away if we're blocked. However a 25 // we need to process sync message right away if we're blocked. However a
(...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after
368 // stop or keep watching. So we always watch it, and create the event as 364 // stop or keep watching. So we always watch it, and create the event as
369 // manual reset since the object watcher might otherwise reset the event 365 // manual reset since the object watcher might otherwise reset the event
370 // when we're doing a WaitMany. 366 // when we're doing a WaitMany.
371 dispatch_watcher_.StartWatching(sync_context()->GetDispatchEvent(), this); 367 dispatch_watcher_.StartWatching(sync_context()->GetDispatchEvent(), this);
372 } 368 }
373 369
374 SyncChannel::~SyncChannel() { 370 SyncChannel::~SyncChannel() {
375 } 371 }
376 372
377 bool SyncChannel::Send(Message* message) { 373 bool SyncChannel::Send(Message* message) {
378 return SendWithTimeout(message, INFINITE); 374 return SendWithTimeout(message, base::kNoTimeout);
379 } 375 }
380 376
381 bool SyncChannel::SendWithTimeout(Message* message, int timeout_ms) { 377 bool SyncChannel::SendWithTimeout(Message* message, int timeout_ms) {
382 if (!message->is_sync()) { 378 if (!message->is_sync()) {
383 ChannelProxy::Send(message); 379 ChannelProxy::Send(message);
384 return true; 380 return true;
385 } 381 }
386 382
387 // *this* might get deleted in WaitForReply. 383 // *this* might get deleted in WaitForReply.
388 scoped_refptr<SyncContext> context(sync_context()); 384 scoped_refptr<SyncContext> context(sync_context());
389 if (context->shutdown_event()->IsSignaled()) { 385 if (context->shutdown_event()->IsSignaled()) {
390 delete message; 386 delete message;
391 return false; 387 return false;
392 } 388 }
393 389
394 DCHECK(sync_messages_with_no_timeout_allowed_ || timeout_ms != INFINITE); 390 DCHECK(sync_messages_with_no_timeout_allowed_ || timeout_ms != base::kNoTimeou t);
jam 2009/01/17 02:12:37 80 characters
395 SyncMessage* sync_msg = static_cast<SyncMessage*>(message); 391 SyncMessage* sync_msg = static_cast<SyncMessage*>(message);
396 context->Push(sync_msg); 392 context->Push(sync_msg);
397 int message_id = SyncMessage::GetMessageId(*sync_msg); 393 int message_id = SyncMessage::GetMessageId(*sync_msg);
398 WaitableEvent* pump_messages_event = sync_msg->pump_messages_event(); 394 WaitableEvent* pump_messages_event = sync_msg->pump_messages_event();
399 395
400 ChannelProxy::Send(message); 396 ChannelProxy::Send(message);
401 397
402 if (timeout_ms != INFINITE) { 398 if (timeout_ms != base::kNoTimeout) {
403 // We use the sync message id so that when a message times out, we don't 399 // We use the sync message id so that when a message times out, we don't
404 // confuse it with another send that is either above/below this Send in 400 // confuse it with another send that is either above/below this Send in
405 // the call stack. 401 // the call stack.
406 context->ipc_message_loop()->PostDelayedTask(FROM_HERE, 402 context->ipc_message_loop()->PostDelayedTask(FROM_HERE,
407 NewRunnableMethod(context.get(), 403 NewRunnableMethod(context.get(),
408 &SyncContext::OnSendTimeout, message_id), timeout_ms); 404 &SyncContext::OnSendTimeout, message_id), timeout_ms);
409 } 405 }
410 406
411 // Wait for reply, or for any other incoming synchronous messages. 407 // Wait for reply, or for any other incoming synchronous messages.
412 WaitForReply(pump_messages_event); 408 WaitForReply(pump_messages_event);
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
460 dispatch_watcher_.StartWatching(dispatch_event, this); 456 dispatch_watcher_.StartWatching(dispatch_event, this);
461 sync_context()->DispatchMessages(); 457 sync_context()->DispatchMessages();
462 } else { 458 } else {
463 // We got the reply, timed out or the process shutdown. 459 // We got the reply, timed out or the process shutdown.
464 DCHECK(event == sync_context()->GetSendDoneEvent()); 460 DCHECK(event == sync_context()->GetSendDoneEvent());
465 MessageLoop::current()->Quit(); 461 MessageLoop::current()->Quit();
466 } 462 }
467 } 463 }
468 464
469 } // namespace IPC 465 } // namespace IPC
OLDNEW
« no previous file with comments | « chrome/common/common.scons ('k') | chrome/common/ipc_sync_channel_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698