| OLD | NEW |
| 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> | |
| 10 | 9 |
| 11 #include "base/macros.h" | 10 #include "base/macros.h" |
| 12 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
| 13 #include "base/memory/weak_ptr.h" | 12 #include "base/memory/scoped_vector.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 | 17 |
| 21 namespace base { | 18 namespace base { |
| 22 class SingleThreadTaskRunner; | 19 class SingleThreadTaskRunner; |
| 23 class WaitableEvent; | 20 class WaitableEvent; |
| 24 } | 21 } |
| 25 | 22 |
| 26 namespace IPC { | 23 namespace IPC { |
| 27 class SyncChannel; | 24 class SyncChannel; |
| 28 | 25 |
| 29 // This MessageFilter allows sending synchronous IPC messages from a thread | 26 // This MessageFilter allows sending synchronous IPC messages from a thread |
| (...skipping 12 matching lines...) Expand all Loading... |
| 42 void OnChannelClosing() override; | 39 void OnChannelClosing() override; |
| 43 bool OnMessageReceived(const Message& message) override; | 40 bool OnMessageReceived(const Message& message) override; |
| 44 | 41 |
| 45 protected: | 42 protected: |
| 46 SyncMessageFilter(base::WaitableEvent* shutdown_event, | 43 SyncMessageFilter(base::WaitableEvent* shutdown_event, |
| 47 bool is_channel_send_thread_safe); | 44 bool is_channel_send_thread_safe); |
| 48 | 45 |
| 49 ~SyncMessageFilter() override; | 46 ~SyncMessageFilter() override; |
| 50 | 47 |
| 51 private: | 48 private: |
| 52 class IOMessageLoopObserver; | |
| 53 | |
| 54 friend class SyncChannel; | 49 friend class SyncChannel; |
| 55 friend class IOMessageLoopObserver; | |
| 56 | 50 |
| 57 void set_is_channel_send_thread_safe(bool is_channel_send_thread_safe) { | 51 void set_is_channel_send_thread_safe(bool is_channel_send_thread_safe) { |
| 58 is_channel_send_thread_safe_ = is_channel_send_thread_safe; | 52 is_channel_send_thread_safe_ = is_channel_send_thread_safe; |
| 59 } | 53 } |
| 60 | 54 |
| 61 void SendOnIOThread(Message* message); | 55 void SendOnIOThread(Message* message); |
| 62 // Signal all the pending sends as done, used in an error condition. | 56 // Signal all the pending sends as done, used in an error condition. |
| 63 void SignalAllEvents(); | 57 void SignalAllEvents(); |
| 64 | 58 |
| 65 void OnShutdownEventSignaled(base::WaitableEvent* event); | |
| 66 void OnIOMessageLoopDestroyed(); | |
| 67 | |
| 68 // The channel to which this filter was added. | 59 // The channel to which this filter was added. |
| 69 Sender* sender_; | 60 Sender* sender_; |
| 70 | 61 |
| 71 // Indicates if |sender_|'s Send method is thread-safe. | 62 // Indicates if |sender_|'s Send method is thread-safe. |
| 72 bool is_channel_send_thread_safe_; | 63 bool is_channel_send_thread_safe_; |
| 73 | 64 |
| 74 // The process's main thread. | 65 // The process's main thread. |
| 75 scoped_refptr<base::SingleThreadTaskRunner> listener_task_runner_; | 66 scoped_refptr<base::SingleThreadTaskRunner> listener_task_runner_; |
| 76 | 67 |
| 77 // The message loop where the Channel lives. | 68 // The message loop where the Channel lives. |
| 78 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_; | 69 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_; |
| 79 | 70 |
| 80 typedef std::set<PendingSyncMsg*> PendingSyncMessages; | 71 typedef std::set<PendingSyncMsg*> PendingSyncMessages; |
| 81 PendingSyncMessages pending_sync_messages_; | 72 PendingSyncMessages pending_sync_messages_; |
| 82 | 73 |
| 83 // Messages waiting to be delivered after IO initialization. | 74 // Messages waiting to be delivered after IO initialization. |
| 84 std::vector<std::unique_ptr<Message>> pending_messages_; | 75 ScopedVector<Message> pending_messages_; |
| 85 | 76 |
| 86 // Locks data members above. | 77 // Locks data members above. |
| 87 base::Lock lock_; | 78 base::Lock lock_; |
| 88 | 79 |
| 89 base::WaitableEvent* const shutdown_event_; | 80 base::WaitableEvent* 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_; | |
| 102 | 81 |
| 103 DISALLOW_COPY_AND_ASSIGN(SyncMessageFilter); | 82 DISALLOW_COPY_AND_ASSIGN(SyncMessageFilter); |
| 104 }; | 83 }; |
| 105 | 84 |
| 106 } // namespace IPC | 85 } // namespace IPC |
| 107 | 86 |
| 108 #endif // IPC_IPC_SYNC_MESSAGE_FILTER_H_ | 87 #endif // IPC_IPC_SYNC_MESSAGE_FILTER_H_ |
| OLD | NEW |