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

Side by Side Diff: ipc/ipc_sync_message_filter.h

Issue 2101163002: Reland Mojo-based waiting for IPC::SyncChannel (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 years, 5 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 | « ipc/ipc_sync_message.cc ('k') | ipc/ipc_sync_message_filter.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 #ifndef IPC_IPC_SYNC_MESSAGE_FILTER_H_ 5 #ifndef IPC_IPC_SYNC_MESSAGE_FILTER_H_
6 #define IPC_IPC_SYNC_MESSAGE_FILTER_H_ 6 #define IPC_IPC_SYNC_MESSAGE_FILTER_H_
7 7
8 #include <set> 8 #include <set>
9 #include <vector>
9 10
10 #include "base/macros.h" 11 #include "base/macros.h"
11 #include "base/memory/ref_counted.h" 12 #include "base/memory/ref_counted.h"
12 #include "base/memory/scoped_vector.h" 13 #include "base/memory/weak_ptr.h"
13 #include "base/synchronization/lock.h" 14 #include "base/synchronization/lock.h"
15 #include "base/synchronization/waitable_event_watcher.h"
14 #include "ipc/ipc_sender.h" 16 #include "ipc/ipc_sender.h"
15 #include "ipc/ipc_sync_message.h" 17 #include "ipc/ipc_sync_message.h"
16 #include "ipc/message_filter.h" 18 #include "ipc/message_filter.h"
19 #include "ipc/mojo_event.h"
17 20
18 namespace base { 21 namespace base {
19 class SingleThreadTaskRunner; 22 class SingleThreadTaskRunner;
20 class WaitableEvent; 23 class WaitableEvent;
21 } 24 }
22 25
23 namespace IPC { 26 namespace IPC {
24 class SyncChannel; 27 class SyncChannel;
25 28
26 // This MessageFilter allows sending synchronous IPC messages from a thread 29 // This MessageFilter allows sending synchronous IPC messages from a thread
(...skipping 12 matching lines...) Expand all
39 void OnChannelClosing() override; 42 void OnChannelClosing() override;
40 bool OnMessageReceived(const Message& message) override; 43 bool OnMessageReceived(const Message& message) override;
41 44
42 protected: 45 protected:
43 SyncMessageFilter(base::WaitableEvent* shutdown_event, 46 SyncMessageFilter(base::WaitableEvent* shutdown_event,
44 bool is_channel_send_thread_safe); 47 bool is_channel_send_thread_safe);
45 48
46 ~SyncMessageFilter() override; 49 ~SyncMessageFilter() override;
47 50
48 private: 51 private:
52 class IOMessageLoopObserver;
53
49 friend class SyncChannel; 54 friend class SyncChannel;
55 friend class IOMessageLoopObserver;
50 56
51 void set_is_channel_send_thread_safe(bool is_channel_send_thread_safe) { 57 void set_is_channel_send_thread_safe(bool is_channel_send_thread_safe) {
52 is_channel_send_thread_safe_ = is_channel_send_thread_safe; 58 is_channel_send_thread_safe_ = is_channel_send_thread_safe;
53 } 59 }
54 60
55 void SendOnIOThread(Message* message); 61 void SendOnIOThread(Message* message);
56 // Signal all the pending sends as done, used in an error condition. 62 // Signal all the pending sends as done, used in an error condition.
57 void SignalAllEvents(); 63 void SignalAllEvents();
58 64
65 void OnShutdownEventSignaled(base::WaitableEvent* event);
66 void OnIOMessageLoopDestroyed();
67
59 // The channel to which this filter was added. 68 // The channel to which this filter was added.
60 Sender* sender_; 69 Sender* sender_;
61 70
62 // Indicates if |sender_|'s Send method is thread-safe. 71 // Indicates if |sender_|'s Send method is thread-safe.
63 bool is_channel_send_thread_safe_; 72 bool is_channel_send_thread_safe_;
64 73
65 // The process's main thread. 74 // The process's main thread.
66 scoped_refptr<base::SingleThreadTaskRunner> listener_task_runner_; 75 scoped_refptr<base::SingleThreadTaskRunner> listener_task_runner_;
67 76
68 // The message loop where the Channel lives. 77 // The message loop where the Channel lives.
69 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_; 78 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_;
70 79
71 typedef std::set<PendingSyncMsg*> PendingSyncMessages; 80 typedef std::set<PendingSyncMsg*> PendingSyncMessages;
72 PendingSyncMessages pending_sync_messages_; 81 PendingSyncMessages pending_sync_messages_;
73 82
74 // Messages waiting to be delivered after IO initialization. 83 // Messages waiting to be delivered after IO initialization.
75 ScopedVector<Message> pending_messages_; 84 std::vector<std::unique_ptr<Message>> pending_messages_;
76 85
77 // Locks data members above. 86 // Locks data members above.
78 base::Lock lock_; 87 base::Lock lock_;
79 88
80 base::WaitableEvent* shutdown_event_; 89 base::WaitableEvent* const shutdown_event_;
90
91 // Used to asynchronously watch |shutdown_event_| on the IO thread and forward
92 // to |shutdown_mojo_event_| (see below.)
93 base::WaitableEventWatcher shutdown_watcher_;
94
95 // A Mojo event which can be watched for shutdown. Signals are forwarded to
96 // this event asynchronously from |shutdown_event_|.
97 MojoEvent shutdown_mojo_event_;
98
99 scoped_refptr<IOMessageLoopObserver> io_message_loop_observer_;
100
101 base::WeakPtrFactory<SyncMessageFilter> weak_factory_;
81 102
82 DISALLOW_COPY_AND_ASSIGN(SyncMessageFilter); 103 DISALLOW_COPY_AND_ASSIGN(SyncMessageFilter);
83 }; 104 };
84 105
85 } // namespace IPC 106 } // namespace IPC
86 107
87 #endif // IPC_IPC_SYNC_MESSAGE_FILTER_H_ 108 #endif // IPC_IPC_SYNC_MESSAGE_FILTER_H_
OLDNEW
« no previous file with comments | « ipc/ipc_sync_message.cc ('k') | ipc/ipc_sync_message_filter.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698