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

Side by Side Diff: ipc/ipc_sync_message_filter.h

Issue 2754143005: Use WaitableEvents to wake up sync IPC waiting (Closed)
Patch Set: . Created 3 years, 9 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.h ('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 #include <vector>
10 10
11 #include "base/macros.h" 11 #include "base/macros.h"
12 #include "base/memory/ref_counted.h" 12 #include "base/memory/ref_counted.h"
13 #include "base/memory/weak_ptr.h"
14 #include "base/synchronization/lock.h" 13 #include "base/synchronization/lock.h"
15 #include "base/synchronization/waitable_event_watcher.h"
16 #include "ipc/ipc_sender.h" 14 #include "ipc/ipc_sender.h"
17 #include "ipc/ipc_sync_message.h" 15 #include "ipc/ipc_sync_message.h"
18 #include "ipc/message_filter.h" 16 #include "ipc/message_filter.h"
19 #include "ipc/mojo_event.h"
20 #include "mojo/public/cpp/bindings/associated_interface_ptr.h" 17 #include "mojo/public/cpp/bindings/associated_interface_ptr.h"
21 #include "mojo/public/cpp/bindings/associated_interface_request.h" 18 #include "mojo/public/cpp/bindings/associated_interface_request.h"
22 #include "mojo/public/cpp/bindings/scoped_interface_endpoint_handle.h" 19 #include "mojo/public/cpp/bindings/scoped_interface_endpoint_handle.h"
23 20
24 namespace base { 21 namespace base {
25 class SingleThreadTaskRunner; 22 class SingleThreadTaskRunner;
26 class WaitableEvent; 23 class WaitableEvent;
27 } 24 }
28 25
29 namespace IPC { 26 namespace IPC {
(...skipping 26 matching lines...) Expand all
56 mojo::AssociatedInterfacePtr<Interface>* proxy) { 53 mojo::AssociatedInterfacePtr<Interface>* proxy) {
57 auto request = mojo::MakeRequest(proxy); 54 auto request = mojo::MakeRequest(proxy);
58 GetGenericRemoteAssociatedInterface(Interface::Name_, request.PassHandle()); 55 GetGenericRemoteAssociatedInterface(Interface::Name_, request.PassHandle());
59 } 56 }
60 57
61 protected: 58 protected:
62 explicit SyncMessageFilter(base::WaitableEvent* shutdown_event); 59 explicit SyncMessageFilter(base::WaitableEvent* shutdown_event);
63 ~SyncMessageFilter() override; 60 ~SyncMessageFilter() override;
64 61
65 private: 62 private:
66 class IOMessageLoopObserver;
67
68 friend class SyncChannel; 63 friend class SyncChannel;
69 friend class IOMessageLoopObserver;
70 64
71 void SendOnIOThread(Message* message); 65 void SendOnIOThread(Message* message);
72 // Signal all the pending sends as done, used in an error condition. 66 // Signal all the pending sends as done, used in an error condition.
73 void SignalAllEvents(); 67 void SignalAllEvents();
74 68
75 void OnShutdownEventSignaled(base::WaitableEvent* event);
76 void OnIOMessageLoopDestroyed();
77
78 // NOTE: This must ONLY be called on the Channel's thread. 69 // NOTE: This must ONLY be called on the Channel's thread.
79 void GetGenericRemoteAssociatedInterface( 70 void GetGenericRemoteAssociatedInterface(
80 const std::string& interface_name, 71 const std::string& interface_name,
81 mojo::ScopedInterfaceEndpointHandle handle); 72 mojo::ScopedInterfaceEndpointHandle handle);
82 73
83 // The channel to which this filter was added. 74 // The channel to which this filter was added.
84 Channel* channel_; 75 Channel* channel_;
85 76
86 // The process's main thread. 77 // The process's main thread.
87 scoped_refptr<base::SingleThreadTaskRunner> listener_task_runner_; 78 scoped_refptr<base::SingleThreadTaskRunner> listener_task_runner_;
88 79
89 // The message loop where the Channel lives. 80 // The message loop where the Channel lives.
90 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_; 81 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_;
91 82
92 typedef std::set<PendingSyncMsg*> PendingSyncMessages; 83 typedef std::set<PendingSyncMsg*> PendingSyncMessages;
93 PendingSyncMessages pending_sync_messages_; 84 PendingSyncMessages pending_sync_messages_;
94 85
95 // Messages waiting to be delivered after IO initialization. 86 // Messages waiting to be delivered after IO initialization.
96 std::vector<std::unique_ptr<Message>> pending_messages_; 87 std::vector<std::unique_ptr<Message>> pending_messages_;
97 88
98 // Locks data members above. 89 // Locks data members above.
99 base::Lock lock_; 90 base::Lock lock_;
100 91
101 base::WaitableEvent* const shutdown_event_; 92 base::WaitableEvent* const shutdown_event_;
102 93
103 // Used to asynchronously watch |shutdown_event_| on the IO thread and forward
104 // to |shutdown_mojo_event_| (see below.)
105 base::WaitableEventWatcher shutdown_watcher_;
106
107 // A Mojo event which can be watched for shutdown. Signals are forwarded to
108 // this event asynchronously from |shutdown_event_|.
109 MojoEvent shutdown_mojo_event_;
110
111 scoped_refptr<IOMessageLoopObserver> io_message_loop_observer_;
112
113 base::WeakPtrFactory<SyncMessageFilter> weak_factory_;
114
115 DISALLOW_COPY_AND_ASSIGN(SyncMessageFilter); 94 DISALLOW_COPY_AND_ASSIGN(SyncMessageFilter);
116 }; 95 };
117 96
118 } // namespace IPC 97 } // namespace IPC
119 98
120 #endif // IPC_IPC_SYNC_MESSAGE_FILTER_H_ 99 #endif // IPC_IPC_SYNC_MESSAGE_FILTER_H_
OLDNEW
« no previous file with comments | « ipc/ipc_sync_message.h ('k') | ipc/ipc_sync_message_filter.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698