| 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 <limits.h> | 7 #include <limits.h> |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 #include <stdint.h> | 9 #include <stdint.h> |
| 10 | 10 |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 Init(); | 75 Init(); |
| 76 } | 76 } |
| 77 | 77 |
| 78 Message::Message(const Message& other) : base::Pickle(other) { | 78 Message::Message(const Message& other) : base::Pickle(other) { |
| 79 Init(); | 79 Init(); |
| 80 attachment_set_ = other.attachment_set_; | 80 attachment_set_ = other.attachment_set_; |
| 81 } | 81 } |
| 82 | 82 |
| 83 void Message::Init() { | 83 void Message::Init() { |
| 84 dispatch_error_ = false; | 84 dispatch_error_ = false; |
| 85 #ifdef IPC_MESSAGE_LOG_ENABLED | 85 #if BUILDFLAG(IPC_MESSAGE_LOG_ENABLED) |
| 86 received_time_ = 0; | 86 received_time_ = 0; |
| 87 dont_log_ = false; | 87 dont_log_ = false; |
| 88 log_data_ = NULL; | 88 log_data_ = NULL; |
| 89 #endif | 89 #endif |
| 90 } | 90 } |
| 91 | 91 |
| 92 Message& Message::operator=(const Message& other) { | 92 Message& Message::operator=(const Message& other) { |
| 93 *static_cast<base::Pickle*>(this) = other; | 93 *static_cast<base::Pickle*>(this) = other; |
| 94 attachment_set_ = other.attachment_set_; | 94 attachment_set_ = other.attachment_set_; |
| 95 return *this; | 95 return *this; |
| 96 } | 96 } |
| 97 | 97 |
| 98 void Message::SetHeaderValues(int32_t routing, uint32_t type, uint32_t flags) { | 98 void Message::SetHeaderValues(int32_t routing, uint32_t type, uint32_t 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 |
| 102 header()->routing = routing; | 102 header()->routing = routing; |
| 103 header()->type = type; | 103 header()->type = type; |
| 104 header()->flags = flags; | 104 header()->flags = flags; |
| 105 } | 105 } |
| 106 | 106 |
| 107 void Message::EnsureMessageAttachmentSet() { | 107 void Message::EnsureMessageAttachmentSet() { |
| 108 if (attachment_set_.get() == NULL) | 108 if (attachment_set_.get() == NULL) |
| 109 attachment_set_ = new MessageAttachmentSet; | 109 attachment_set_ = new MessageAttachmentSet; |
| 110 } | 110 } |
| 111 | 111 |
| 112 #ifdef IPC_MESSAGE_LOG_ENABLED | 112 #if BUILDFLAG(IPC_MESSAGE_LOG_ENABLED) |
| 113 void Message::set_sent_time(int64_t time) { | 113 void Message::set_sent_time(int64_t time) { |
| 114 DCHECK((header()->flags & HAS_SENT_TIME_BIT) == 0); | 114 DCHECK((header()->flags & HAS_SENT_TIME_BIT) == 0); |
| 115 header()->flags |= HAS_SENT_TIME_BIT; | 115 header()->flags |= HAS_SENT_TIME_BIT; |
| 116 WriteInt64(time); | 116 WriteInt64(time); |
| 117 } | 117 } |
| 118 | 118 |
| 119 int64_t Message::sent_time() const { | 119 int64_t Message::sent_time() const { |
| 120 if ((header()->flags & HAS_SENT_TIME_BIT) == 0) | 120 if ((header()->flags & HAS_SENT_TIME_BIT) == 0) |
| 121 return 0; | 121 return 0; |
| 122 | 122 |
| 123 const char* data = end_of_payload(); | 123 const char* data = end_of_payload(); |
| 124 data -= sizeof(int64_t); | 124 data -= sizeof(int64_t); |
| 125 return *(reinterpret_cast<const int64_t*>(data)); | 125 return *(reinterpret_cast<const int64_t*>(data)); |
| 126 } | 126 } |
| 127 | 127 |
| 128 void Message::set_received_time(int64_t time) const { | 128 void Message::set_received_time(int64_t time) const { |
| 129 received_time_ = time; | 129 received_time_ = time; |
| 130 } | 130 } |
| 131 #endif | 131 #endif // BUILDFLAG(IPC_MESSAGE_LOG_ENABLED) |
| 132 | 132 |
| 133 Message::NextMessageInfo::NextMessageInfo() | 133 Message::NextMessageInfo::NextMessageInfo() |
| 134 : message_size(0), message_found(false), pickle_end(nullptr), | 134 : message_size(0), message_found(false), pickle_end(nullptr), |
| 135 message_end(nullptr) {} | 135 message_end(nullptr) {} |
| 136 Message::NextMessageInfo::~NextMessageInfo() {} | 136 Message::NextMessageInfo::~NextMessageInfo() {} |
| 137 | 137 |
| 138 // static | 138 // static |
| 139 void Message::FindNext(const char* range_start, | 139 void Message::FindNext(const char* range_start, |
| 140 const char* range_end, | 140 const char* range_end, |
| 141 NextMessageInfo* info) { | 141 NextMessageInfo* info) { |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 196 *attachment = attachment_set->GetAttachmentAt(index); | 196 *attachment = attachment_set->GetAttachmentAt(index); |
| 197 | 197 |
| 198 return nullptr != attachment->get(); | 198 return nullptr != attachment->get(); |
| 199 } | 199 } |
| 200 | 200 |
| 201 bool Message::HasAttachments() const { | 201 bool Message::HasAttachments() const { |
| 202 return attachment_set_.get() && !attachment_set_->empty(); | 202 return attachment_set_.get() && !attachment_set_->empty(); |
| 203 } | 203 } |
| 204 | 204 |
| 205 } // namespace IPC | 205 } // namespace IPC |
| OLD | NEW |