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

Side by Side Diff: ipc/ipc_sync_channel.cc

Issue 2480153004: Revert of Remove MessageLoop destruction observer from mojo::Watcher. (Closed)
Patch Set: Created 4 years, 1 month 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 | « no previous file | mojo/public/cpp/system/tests/watcher_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 <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <utility> 10 #include <utility>
(...skipping 27 matching lines...) Expand all
38 // to true. Also sets |*error| to true in case of an error. 38 // to true. Also sets |*error| to true in case of an error.
39 void OnSyncHandleReady(bool* signal, bool* error, MojoResult result) { 39 void OnSyncHandleReady(bool* signal, bool* error, MojoResult result) {
40 *signal = true; 40 *signal = true;
41 *error = result != MOJO_RESULT_OK; 41 *error = result != MOJO_RESULT_OK;
42 } 42 }
43 43
44 // A ReadyCallback for use with mojo::Watcher. Ignores the result (DCHECKs, but 44 // A ReadyCallback for use with mojo::Watcher. Ignores the result (DCHECKs, but
45 // is only used in cases where failure should be impossible) and runs 45 // is only used in cases where failure should be impossible) and runs
46 // |callback|. 46 // |callback|.
47 void RunOnHandleReady(const base::Closure& callback, MojoResult result) { 47 void RunOnHandleReady(const base::Closure& callback, MojoResult result) {
48 DCHECK_EQ(result, MOJO_RESULT_OK); 48 DCHECK(result == MOJO_RESULT_OK || result == MOJO_RESULT_ABORTED);
49 callback.Run(); 49 if (result == MOJO_RESULT_OK)
50 callback.Run();
50 } 51 }
51 52
52 class PumpMessagesEvent { 53 class PumpMessagesEvent {
53 public: 54 public:
54 PumpMessagesEvent() { event_.Signal(); } 55 PumpMessagesEvent() { event_.Signal(); }
55 ~PumpMessagesEvent() {} 56 ~PumpMessagesEvent() {}
56 57
57 const MojoEvent* event() const { return &event_; } 58 const MojoEvent* event() const { return &event_; }
58 59
59 private: 60 private:
(...skipping 611 matching lines...) Expand 10 before | Expand all | Expand 10 after
671 nested_loop.Run(); 672 nested_loop.Run();
672 send_done_watcher.Cancel(); 673 send_done_watcher.Cancel();
673 } 674 }
674 675
675 sync_msg_queue->set_top_send_done_watcher(old_watcher); 676 sync_msg_queue->set_top_send_done_watcher(old_watcher);
676 if (old_watcher) 677 if (old_watcher)
677 old_watcher->Start(old_handle, MOJO_HANDLE_SIGNAL_READABLE, old_callback); 678 old_watcher->Start(old_handle, MOJO_HANDLE_SIGNAL_READABLE, old_callback);
678 } 679 }
679 680
680 void SyncChannel::OnDispatchHandleReady(MojoResult result) { 681 void SyncChannel::OnDispatchHandleReady(MojoResult result) {
681 DCHECK_EQ(result, MOJO_RESULT_OK); 682 DCHECK(result == MOJO_RESULT_OK || result == MOJO_RESULT_ABORTED);
682 sync_context()->GetDispatchEvent()->Reset(); 683 if (result == MOJO_RESULT_OK) {
683 sync_context()->DispatchMessages(); 684 sync_context()->GetDispatchEvent()->Reset();
685 sync_context()->DispatchMessages();
686 }
684 } 687 }
685 688
686 void SyncChannel::StartWatching() { 689 void SyncChannel::StartWatching() {
687 // |dispatch_watcher_| watches the event asynchronously, only dispatching 690 // |dispatch_watcher_| watches the event asynchronously, only dispatching
688 // messages once the listener thread is unblocked and pumping its task queue. 691 // messages once the listener thread is unblocked and pumping its task queue.
689 // The ReceivedSyncMsgQueue also watches this event and may dispatch 692 // The ReceivedSyncMsgQueue also watches this event and may dispatch
690 // immediately if woken up by a message which it's allowed to dispatch. 693 // immediately if woken up by a message which it's allowed to dispatch.
691 dispatch_watcher_.Start(sync_context()->GetDispatchEvent()->GetHandle(), 694 dispatch_watcher_.Start(sync_context()->GetDispatchEvent()->GetHandle(),
692 MOJO_HANDLE_SIGNAL_READABLE, 695 MOJO_HANDLE_SIGNAL_READABLE,
693 base::Bind(&SyncChannel::OnDispatchHandleReady, 696 base::Bind(&SyncChannel::OnDispatchHandleReady,
694 base::Unretained(this))); 697 base::Unretained(this)));
695 } 698 }
696 699
697 void SyncChannel::OnChannelInit() { 700 void SyncChannel::OnChannelInit() {
698 pre_init_sync_message_filters_.clear(); 701 pre_init_sync_message_filters_.clear();
699 } 702 }
700 703
701 } // namespace IPC 704 } // namespace IPC
OLDNEW
« no previous file with comments | « no previous file | mojo/public/cpp/system/tests/watcher_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698