| 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_message.h" | 5 #include "ipc/ipc_message.h" |
| 6 | 6 |
| 7 #include "base/atomic_sequence_num.h" | 7 #include "base/atomic_sequence_num.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "build/build_config.h" | 9 #include "build/build_config.h" |
| 10 #include "ipc/ipc_message_attachment.h" | 10 #include "ipc/ipc_message_attachment.h" |
| (...skipping 25 matching lines...) Expand all Loading... |
| 36 | 36 |
| 37 } // namespace | 37 } // namespace |
| 38 | 38 |
| 39 namespace IPC { | 39 namespace IPC { |
| 40 | 40 |
| 41 //------------------------------------------------------------------------------ | 41 //------------------------------------------------------------------------------ |
| 42 | 42 |
| 43 Message::~Message() { | 43 Message::~Message() { |
| 44 } | 44 } |
| 45 | 45 |
| 46 Message::Message() | 46 Message::Message() : base::Pickle(sizeof(Header)) { |
| 47 : Pickle(sizeof(Header)) { | |
| 48 header()->routing = header()->type = 0; | 47 header()->routing = header()->type = 0; |
| 49 header()->flags = GetRefNumUpper24(); | 48 header()->flags = GetRefNumUpper24(); |
| 50 #if defined(OS_POSIX) | 49 #if defined(OS_POSIX) |
| 51 header()->num_fds = 0; | 50 header()->num_fds = 0; |
| 52 header()->pad = 0; | 51 header()->pad = 0; |
| 53 #endif | 52 #endif |
| 54 Init(); | 53 Init(); |
| 55 } | 54 } |
| 56 | 55 |
| 57 Message::Message(int32 routing_id, uint32 type, PriorityValue priority) | 56 Message::Message(int32 routing_id, uint32 type, PriorityValue priority) |
| 58 : Pickle(sizeof(Header)) { | 57 : base::Pickle(sizeof(Header)) { |
| 59 header()->routing = routing_id; | 58 header()->routing = routing_id; |
| 60 header()->type = type; | 59 header()->type = type; |
| 61 DCHECK((priority & 0xffffff00) == 0); | 60 DCHECK((priority & 0xffffff00) == 0); |
| 62 header()->flags = priority | GetRefNumUpper24(); | 61 header()->flags = priority | GetRefNumUpper24(); |
| 63 #if defined(OS_POSIX) | 62 #if defined(OS_POSIX) |
| 64 header()->num_fds = 0; | 63 header()->num_fds = 0; |
| 65 header()->pad = 0; | 64 header()->pad = 0; |
| 66 #endif | 65 #endif |
| 67 Init(); | 66 Init(); |
| 68 } | 67 } |
| 69 | 68 |
| 70 Message::Message(const char* data, int data_len) : Pickle(data, data_len) { | 69 Message::Message(const char* data, int data_len) |
| 70 : base::Pickle(data, data_len) { |
| 71 Init(); | 71 Init(); |
| 72 } | 72 } |
| 73 | 73 |
| 74 Message::Message(const Message& other) : Pickle(other) { | 74 Message::Message(const Message& other) : base::Pickle(other) { |
| 75 Init(); | 75 Init(); |
| 76 #if defined(OS_POSIX) | 76 #if defined(OS_POSIX) |
| 77 attachment_set_ = other.attachment_set_; | 77 attachment_set_ = other.attachment_set_; |
| 78 #endif | 78 #endif |
| 79 } | 79 } |
| 80 | 80 |
| 81 void Message::Init() { | 81 void Message::Init() { |
| 82 dispatch_error_ = false; | 82 dispatch_error_ = false; |
| 83 #ifdef IPC_MESSAGE_LOG_ENABLED | 83 #ifdef IPC_MESSAGE_LOG_ENABLED |
| 84 received_time_ = 0; | 84 received_time_ = 0; |
| 85 dont_log_ = false; | 85 dont_log_ = false; |
| 86 log_data_ = NULL; | 86 log_data_ = NULL; |
| 87 #endif | 87 #endif |
| 88 } | 88 } |
| 89 | 89 |
| 90 Message& Message::operator=(const Message& other) { | 90 Message& Message::operator=(const Message& other) { |
| 91 *static_cast<Pickle*>(this) = other; | 91 *static_cast<base::Pickle*>(this) = other; |
| 92 #if defined(OS_POSIX) | 92 #if defined(OS_POSIX) |
| 93 attachment_set_ = other.attachment_set_; | 93 attachment_set_ = other.attachment_set_; |
| 94 #endif | 94 #endif |
| 95 return *this; | 95 return *this; |
| 96 } | 96 } |
| 97 | 97 |
| 98 void Message::SetHeaderValues(int32 routing, uint32 type, uint32 flags) { | 98 void Message::SetHeaderValues(int32 routing, uint32 type, uint32 flags) { |
| 99 // This should only be called when the message is already empty. | 99 // This should only be called when the message is already empty. |
| 100 DCHECK(payload_size() == 0); | 100 DCHECK(payload_size() == 0); |
| 101 | 101 |
| (...skipping 29 matching lines...) Expand all Loading... |
| 131 #endif | 131 #endif |
| 132 | 132 |
| 133 bool Message::WriteAttachment(scoped_refptr<MessageAttachment> attachment) { | 133 bool Message::WriteAttachment(scoped_refptr<MessageAttachment> attachment) { |
| 134 // We write the index of the descriptor so that we don't have to | 134 // We write the index of the descriptor so that we don't have to |
| 135 // keep the current descriptor as extra decoding state when deserialising. | 135 // keep the current descriptor as extra decoding state when deserialising. |
| 136 WriteInt(attachment_set()->size()); | 136 WriteInt(attachment_set()->size()); |
| 137 return attachment_set()->AddAttachment(attachment); | 137 return attachment_set()->AddAttachment(attachment); |
| 138 } | 138 } |
| 139 | 139 |
| 140 bool Message::ReadAttachment( | 140 bool Message::ReadAttachment( |
| 141 PickleIterator* iter, | 141 base::PickleIterator* iter, |
| 142 scoped_refptr<MessageAttachment>* attachment) const { | 142 scoped_refptr<MessageAttachment>* attachment) const { |
| 143 int descriptor_index; | 143 int descriptor_index; |
| 144 if (!iter->ReadInt(&descriptor_index)) | 144 if (!iter->ReadInt(&descriptor_index)) |
| 145 return false; | 145 return false; |
| 146 | 146 |
| 147 MessageAttachmentSet* attachment_set = attachment_set_.get(); | 147 MessageAttachmentSet* attachment_set = attachment_set_.get(); |
| 148 if (!attachment_set) | 148 if (!attachment_set) |
| 149 return false; | 149 return false; |
| 150 | 150 |
| 151 *attachment = attachment_set->GetAttachmentAt(descriptor_index); | 151 *attachment = attachment_set->GetAttachmentAt(descriptor_index); |
| 152 return nullptr != attachment->get(); | 152 return nullptr != attachment->get(); |
| 153 } | 153 } |
| 154 | 154 |
| 155 bool Message::HasAttachments() const { | 155 bool Message::HasAttachments() const { |
| 156 return attachment_set_.get() && !attachment_set_->empty(); | 156 return attachment_set_.get() && !attachment_set_->empty(); |
| 157 } | 157 } |
| 158 | 158 |
| 159 bool Message::HasMojoHandles() const { | 159 bool Message::HasMojoHandles() const { |
| 160 return attachment_set_.get() && 0 < attachment_set_->num_mojo_handles(); | 160 return attachment_set_.get() && 0 < attachment_set_->num_mojo_handles(); |
| 161 } | 161 } |
| 162 | 162 |
| 163 } // namespace IPC | 163 } // namespace IPC |
| OLD | NEW |