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

Side by Side Diff: ipc/ipc_sync_channel.cc

Issue 2540903002: Remove MessageLoop destruction observer from mojo::Watcher. (Closed)
Patch Set: . Created 4 years 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/android/system/watcher_impl.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(result == MOJO_RESULT_OK || result == MOJO_RESULT_ABORTED); 48 DCHECK_EQ(result, MOJO_RESULT_OK);
49 if (result == MOJO_RESULT_OK) 49 callback.Run();
50 callback.Run();
51 } 50 }
52 51
53 class PumpMessagesEvent { 52 class PumpMessagesEvent {
54 public: 53 public:
55 PumpMessagesEvent() { event_.Signal(); } 54 PumpMessagesEvent() { event_.Signal(); }
56 ~PumpMessagesEvent() {} 55 ~PumpMessagesEvent() {}
57 56
58 const MojoEvent* event() const { return &event_; } 57 const MojoEvent* event() const { return &event_; }
59 58
60 private: 59 private:
(...skipping 611 matching lines...) Expand 10 before | Expand all | Expand 10 after
672 nested_loop.Run(); 671 nested_loop.Run();
673 send_done_watcher.Cancel(); 672 send_done_watcher.Cancel();
674 } 673 }
675 674
676 sync_msg_queue->set_top_send_done_watcher(old_watcher); 675 sync_msg_queue->set_top_send_done_watcher(old_watcher);
677 if (old_watcher) 676 if (old_watcher)
678 old_watcher->Start(old_handle, MOJO_HANDLE_SIGNAL_READABLE, old_callback); 677 old_watcher->Start(old_handle, MOJO_HANDLE_SIGNAL_READABLE, old_callback);
679 } 678 }
680 679
681 void SyncChannel::OnDispatchHandleReady(MojoResult result) { 680 void SyncChannel::OnDispatchHandleReady(MojoResult result) {
682 DCHECK(result == MOJO_RESULT_OK || result == MOJO_RESULT_ABORTED); 681 DCHECK_EQ(result, MOJO_RESULT_OK);
683 if (result == MOJO_RESULT_OK) { 682 sync_context()->GetDispatchEvent()->Reset();
684 sync_context()->GetDispatchEvent()->Reset(); 683 sync_context()->DispatchMessages();
685 sync_context()->DispatchMessages();
686 }
687 } 684 }
688 685
689 void SyncChannel::StartWatching() { 686 void SyncChannel::StartWatching() {
690 // |dispatch_watcher_| watches the event asynchronously, only dispatching 687 // |dispatch_watcher_| watches the event asynchronously, only dispatching
691 // messages once the listener thread is unblocked and pumping its task queue. 688 // messages once the listener thread is unblocked and pumping its task queue.
692 // The ReceivedSyncMsgQueue also watches this event and may dispatch 689 // The ReceivedSyncMsgQueue also watches this event and may dispatch
693 // immediately if woken up by a message which it's allowed to dispatch. 690 // immediately if woken up by a message which it's allowed to dispatch.
694 dispatch_watcher_.Start(sync_context()->GetDispatchEvent()->GetHandle(), 691 dispatch_watcher_.Start(sync_context()->GetDispatchEvent()->GetHandle(),
695 MOJO_HANDLE_SIGNAL_READABLE, 692 MOJO_HANDLE_SIGNAL_READABLE,
696 base::Bind(&SyncChannel::OnDispatchHandleReady, 693 base::Bind(&SyncChannel::OnDispatchHandleReady,
697 base::Unretained(this))); 694 base::Unretained(this)));
698 } 695 }
699 696
700 void SyncChannel::OnChannelInit() { 697 void SyncChannel::OnChannelInit() {
701 pre_init_sync_message_filters_.clear(); 698 pre_init_sync_message_filters_.clear();
702 } 699 }
703 700
704 } // namespace IPC 701 } // namespace IPC
OLDNEW
« no previous file with comments | « no previous file | mojo/android/system/watcher_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698