| 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_message.h" | 5 #include "ipc/ipc_sync_message.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <stack> | 9 #include <stack> |
| 10 | 10 |
| 11 #include "base/atomic_sequence_num.h" | 11 #include "base/atomic_sequence_num.h" |
| 12 #include "base/lazy_instance.h" |
| 12 #include "base/logging.h" | 13 #include "base/logging.h" |
| 14 #include "base/synchronization/waitable_event.h" |
| 13 #include "build/build_config.h" | 15 #include "build/build_config.h" |
| 14 | 16 |
| 15 namespace { | 17 namespace { |
| 16 | 18 |
| 19 struct WaitableEventLazyInstanceTraits |
| 20 : public base::DefaultLazyInstanceTraits<base::WaitableEvent> { |
| 21 static base::WaitableEvent* New(void* instance) { |
| 22 // Use placement new to initialize our instance in our preallocated space. |
| 23 return new (instance) |
| 24 base::WaitableEvent(base::WaitableEvent::ResetPolicy::MANUAL, |
| 25 base::WaitableEvent::InitialState::SIGNALED); |
| 26 } |
| 27 }; |
| 28 |
| 29 base::LazyInstance<base::WaitableEvent, WaitableEventLazyInstanceTraits> |
| 30 dummy_event = LAZY_INSTANCE_INITIALIZER; |
| 31 |
| 17 base::StaticAtomicSequenceNumber g_next_id; | 32 base::StaticAtomicSequenceNumber g_next_id; |
| 18 | 33 |
| 19 } // namespace | 34 } // namespace |
| 20 | 35 |
| 21 namespace IPC { | 36 namespace IPC { |
| 22 | 37 |
| 23 #define kSyncMessageHeaderSize 4 | 38 #define kSyncMessageHeaderSize 4 |
| 24 | 39 |
| 25 SyncMessage::SyncMessage(int32_t routing_id, | 40 SyncMessage::SyncMessage(int32_t routing_id, |
| 26 uint32_t type, | 41 uint32_t type, |
| 27 PriorityValue priority, | 42 PriorityValue priority, |
| 28 MessageReplyDeserializer* deserializer) | 43 MessageReplyDeserializer* deserializer) |
| 29 : Message(routing_id, type, priority), | 44 : Message(routing_id, type, priority), |
| 30 deserializer_(deserializer) { | 45 deserializer_(deserializer), |
| 46 pump_messages_event_(NULL) { |
| 31 set_sync(); | 47 set_sync(); |
| 32 set_unblock(true); | 48 set_unblock(true); |
| 33 | 49 |
| 34 // Add synchronous message data before the message payload. | 50 // Add synchronous message data before the message payload. |
| 35 SyncHeader header; | 51 SyncHeader header; |
| 36 header.message_id = g_next_id.GetNext(); | 52 header.message_id = g_next_id.GetNext(); |
| 37 WriteSyncHeader(this, header); | 53 WriteSyncHeader(this, header); |
| 38 } | 54 } |
| 39 | 55 |
| 40 SyncMessage::~SyncMessage() { | 56 SyncMessage::~SyncMessage() { |
| 41 } | 57 } |
| 42 | 58 |
| 43 MessageReplyDeserializer* SyncMessage::GetReplyDeserializer() { | 59 MessageReplyDeserializer* SyncMessage::GetReplyDeserializer() { |
| 44 DCHECK(deserializer_.get()); | 60 DCHECK(deserializer_.get()); |
| 45 return deserializer_.release(); | 61 return deserializer_.release(); |
| 46 } | 62 } |
| 47 | 63 |
| 64 void SyncMessage::EnableMessagePumping() { |
| 65 DCHECK(!pump_messages_event_); |
| 66 set_pump_messages_event(dummy_event.Pointer()); |
| 67 } |
| 68 |
| 48 bool SyncMessage::IsMessageReplyTo(const Message& msg, int request_id) { | 69 bool SyncMessage::IsMessageReplyTo(const Message& msg, int request_id) { |
| 49 if (!msg.is_reply()) | 70 if (!msg.is_reply()) |
| 50 return false; | 71 return false; |
| 51 | 72 |
| 52 return GetMessageId(msg) == request_id; | 73 return GetMessageId(msg) == request_id; |
| 53 } | 74 } |
| 54 | 75 |
| 55 base::PickleIterator SyncMessage::GetDataIterator(const Message* msg) { | 76 base::PickleIterator SyncMessage::GetDataIterator(const Message* msg) { |
| 56 base::PickleIterator iter(*msg); | 77 base::PickleIterator iter(*msg); |
| 57 if (!iter.SkipBytes(kSyncMessageHeaderSize)) | 78 if (!iter.SkipBytes(kSyncMessageHeaderSize)) |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 114 | 135 |
| 115 return true; | 136 return true; |
| 116 } | 137 } |
| 117 | 138 |
| 118 | 139 |
| 119 bool MessageReplyDeserializer::SerializeOutputParameters(const Message& msg) { | 140 bool MessageReplyDeserializer::SerializeOutputParameters(const Message& msg) { |
| 120 return SerializeOutputParameters(msg, SyncMessage::GetDataIterator(&msg)); | 141 return SerializeOutputParameters(msg, SyncMessage::GetDataIterator(&msg)); |
| 121 } | 142 } |
| 122 | 143 |
| 123 } // namespace IPC | 144 } // namespace IPC |
| OLD | NEW |