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

Side by Side Diff: ipc/ipc_sync_channel.cc

Issue 9384024: Prefer ScopedNestableTaskAllower over manual save/restore (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rename back to "allow". Created 8 years, 10 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 | « content/renderer/devtools_agent.cc ('k') | net/base/file_stream_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/lazy_instance.h" 8 #include "base/lazy_instance.h"
9 #include "base/location.h" 9 #include "base/location.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 488 matching lines...) Expand 10 before | Expand all | Expand 10 after
499 // outermost call completes first, etc. 499 // outermost call completes first, etc.
500 if (old_send_done_event_watcher) { 500 if (old_send_done_event_watcher) {
501 old_delegate = old_send_done_event_watcher->delegate(); 501 old_delegate = old_send_done_event_watcher->delegate();
502 old_event = old_send_done_event_watcher->GetWatchedEvent(); 502 old_event = old_send_done_event_watcher->GetWatchedEvent();
503 old_send_done_event_watcher->StopWatching(); 503 old_send_done_event_watcher->StopWatching();
504 } 504 }
505 505
506 sync_msg_queue->set_top_send_done_watcher(&send_done_watcher); 506 sync_msg_queue->set_top_send_done_watcher(&send_done_watcher);
507 507
508 send_done_watcher.StartWatching(context->GetSendDoneEvent(), context); 508 send_done_watcher.StartWatching(context->GetSendDoneEvent(), context);
509 bool old_state = MessageLoop::current()->NestableTasksAllowed();
510 509
511 MessageLoop::current()->SetNestableTasksAllowed(true); 510 {
512 MessageLoop::current()->Run(); 511 MessageLoop::ScopedNestableTaskAllower allow(MessageLoop::current());
513 MessageLoop::current()->SetNestableTasksAllowed(old_state); 512 MessageLoop::current()->Run();
513 }
514 514
515 sync_msg_queue->set_top_send_done_watcher(old_send_done_event_watcher); 515 sync_msg_queue->set_top_send_done_watcher(old_send_done_event_watcher);
516 if (old_send_done_event_watcher && old_event) { 516 if (old_send_done_event_watcher && old_event) {
517 old_send_done_event_watcher->StartWatching(old_event, old_delegate); 517 old_send_done_event_watcher->StartWatching(old_event, old_delegate);
518 } 518 }
519 } 519 }
520 520
521 void SyncChannel::OnWaitableEventSignaled(WaitableEvent* event) { 521 void SyncChannel::OnWaitableEventSignaled(WaitableEvent* event) {
522 DCHECK(event == sync_context()->GetDispatchEvent()); 522 DCHECK(event == sync_context()->GetDispatchEvent());
523 // The call to DispatchMessages might delete this object, so reregister 523 // The call to DispatchMessages might delete this object, so reregister
524 // the object watcher first. 524 // the object watcher first.
525 event->Reset(); 525 event->Reset();
526 dispatch_watcher_.StartWatching(event, this); 526 dispatch_watcher_.StartWatching(event, this);
527 sync_context()->DispatchMessages(); 527 sync_context()->DispatchMessages();
528 } 528 }
529 529
530 void SyncChannel::StartWatching() { 530 void SyncChannel::StartWatching() {
531 // Ideally we only want to watch this object when running a nested message 531 // Ideally we only want to watch this object when running a nested message
532 // loop. However, we don't know when it exits if there's another nested 532 // loop. However, we don't know when it exits if there's another nested
533 // message loop running under it or not, so we wouldn't know whether to 533 // message loop running under it or not, so we wouldn't know whether to
534 // stop or keep watching. So we always watch it, and create the event as 534 // stop or keep watching. So we always watch it, and create the event as
535 // manual reset since the object watcher might otherwise reset the event 535 // manual reset since the object watcher might otherwise reset the event
536 // when we're doing a WaitMany. 536 // when we're doing a WaitMany.
537 dispatch_watcher_.StartWatching(sync_context()->GetDispatchEvent(), this); 537 dispatch_watcher_.StartWatching(sync_context()->GetDispatchEvent(), this);
538 } 538 }
539 539
540 } // namespace IPC 540 } // namespace IPC
OLDNEW
« no previous file with comments | « content/renderer/devtools_agent.cc ('k') | net/base/file_stream_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698