| 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 #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 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 183 | 183 |
| 184 void set_top_send_done_watcher(base::WaitableEventWatcher* watcher) { | 184 void set_top_send_done_watcher(base::WaitableEventWatcher* watcher) { |
| 185 top_send_done_watcher_ = watcher; | 185 top_send_done_watcher_ = watcher; |
| 186 } | 186 } |
| 187 | 187 |
| 188 private: | 188 private: |
| 189 friend class base::RefCountedThreadSafe<ReceivedSyncMsgQueue>; | 189 friend class base::RefCountedThreadSafe<ReceivedSyncMsgQueue>; |
| 190 | 190 |
| 191 // See the comment in SyncChannel::SyncChannel for why this event is created | 191 // See the comment in SyncChannel::SyncChannel for why this event is created |
| 192 // as manual reset. | 192 // as manual reset. |
| 193 ReceivedSyncMsgQueue() : | 193 ReceivedSyncMsgQueue() |
| 194 message_queue_version_(0), | 194 : message_queue_version_(0), |
| 195 dispatch_event_(true, false), | 195 dispatch_event_(base::WaitableEvent::ResetPolicy::MANUAL, |
| 196 listener_task_runner_(base::ThreadTaskRunnerHandle::Get()), | 196 base::WaitableEvent::InitialState::NOT_SIGNALED), |
| 197 task_pending_(false), | 197 listener_task_runner_(base::ThreadTaskRunnerHandle::Get()), |
| 198 listener_count_(0), | 198 task_pending_(false), |
| 199 top_send_done_watcher_(NULL) { | 199 listener_count_(0), |
| 200 } | 200 top_send_done_watcher_(NULL) {} |
| 201 | 201 |
| 202 ~ReceivedSyncMsgQueue() {} | 202 ~ReceivedSyncMsgQueue() {} |
| 203 | 203 |
| 204 // Holds information about a queued synchronous message or reply. | 204 // Holds information about a queued synchronous message or reply. |
| 205 struct QueuedMessage { | 205 struct QueuedMessage { |
| 206 QueuedMessage(Message* m, SyncContext* c) : message(m), context(c) { } | 206 QueuedMessage(Message* m, SyncContext* c) : message(m), context(c) { } |
| 207 Message* message; | 207 Message* message; |
| 208 scoped_refptr<SyncChannel::SyncContext> context; | 208 scoped_refptr<SyncChannel::SyncContext> context; |
| 209 }; | 209 }; |
| 210 | 210 |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 253 // the reply has arrived. | 253 // the reply has arrived. |
| 254 void SyncChannel::SyncContext::Push(SyncMessage* sync_msg) { | 254 void SyncChannel::SyncContext::Push(SyncMessage* sync_msg) { |
| 255 // Create the tracking information for this message. This object is stored | 255 // Create the tracking information for this message. This object is stored |
| 256 // by value since all members are pointers that are cheap to copy. These | 256 // by value since all members are pointers that are cheap to copy. These |
| 257 // pointers are cleaned up in the Pop() function. | 257 // pointers are cleaned up in the Pop() function. |
| 258 // | 258 // |
| 259 // The event is created as manual reset because in between Signal and | 259 // The event is created as manual reset because in between Signal and |
| 260 // OnObjectSignalled, another Send can happen which would stop the watcher | 260 // OnObjectSignalled, another Send can happen which would stop the watcher |
| 261 // from being called. The event would get watched later, when the nested | 261 // from being called. The event would get watched later, when the nested |
| 262 // Send completes, so the event will need to remain set. | 262 // Send completes, so the event will need to remain set. |
| 263 PendingSyncMsg pending(SyncMessage::GetMessageId(*sync_msg), | 263 PendingSyncMsg pending( |
| 264 sync_msg->GetReplyDeserializer(), | 264 SyncMessage::GetMessageId(*sync_msg), sync_msg->GetReplyDeserializer(), |
| 265 new WaitableEvent(true, false)); | 265 new WaitableEvent(base::WaitableEvent::ResetPolicy::MANUAL, |
| 266 base::WaitableEvent::InitialState::NOT_SIGNALED)); |
| 266 base::AutoLock auto_lock(deserializers_lock_); | 267 base::AutoLock auto_lock(deserializers_lock_); |
| 267 deserializers_.push_back(pending); | 268 deserializers_.push_back(pending); |
| 268 } | 269 } |
| 269 | 270 |
| 270 bool SyncChannel::SyncContext::Pop() { | 271 bool SyncChannel::SyncContext::Pop() { |
| 271 bool result; | 272 bool result; |
| 272 { | 273 { |
| 273 base::AutoLock auto_lock(deserializers_lock_); | 274 base::AutoLock auto_lock(deserializers_lock_); |
| 274 PendingSyncMsg msg = deserializers_.back(); | 275 PendingSyncMsg msg = deserializers_.back(); |
| 275 delete msg.deserializer; | 276 delete msg.deserializer; |
| (...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 631 TRACE_EVENT2("ipc", "SyncChannel::SendOnIPCThread", | 632 TRACE_EVENT2("ipc", "SyncChannel::SendOnIPCThread", |
| 632 "class", IPC_MESSAGE_ID_CLASS(message->type()), | 633 "class", IPC_MESSAGE_ID_CLASS(message->type()), |
| 633 "line", IPC_MESSAGE_ID_LINE(message->type())); | 634 "line", IPC_MESSAGE_ID_LINE(message->type())); |
| 634 #endif | 635 #endif |
| 635 if (!message->is_sync()) | 636 if (!message->is_sync()) |
| 636 return ChannelProxy::SendOnIPCThread(std::move(message)); | 637 return ChannelProxy::SendOnIPCThread(std::move(message)); |
| 637 return Send(message.release()); | 638 return Send(message.release()); |
| 638 } | 639 } |
| 639 | 640 |
| 640 } // namespace IPC | 641 } // namespace IPC |
| OLD | NEW |