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 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
159 const char* pickle_end = range_start + pickle_size; | 159 const char* pickle_end = range_start + pickle_size; |
160 | 160 |
161 info->message_end = pickle_end; | 161 info->message_end = pickle_end; |
162 | 162 |
163 info->pickle_end = pickle_end; | 163 info->pickle_end = pickle_end; |
164 info->message_found = true; | 164 info->message_found = true; |
165 } | 165 } |
166 | 166 |
167 bool Message::WriteAttachment( | 167 bool Message::WriteAttachment( |
168 scoped_refptr<base::Pickle::Attachment> attachment) { | 168 scoped_refptr<base::Pickle::Attachment> attachment) { |
169 bool brokerable; | |
170 size_t index; | 169 size_t index; |
171 bool success = attachment_set()->AddAttachment( | 170 bool success = attachment_set()->AddAttachment( |
172 make_scoped_refptr(static_cast<MessageAttachment*>(attachment.get())), | 171 make_scoped_refptr(static_cast<MessageAttachment*>(attachment.get())), |
173 &index, &brokerable); | 172 &index); |
174 DCHECK(success); | 173 DCHECK(success); |
175 | 174 |
176 // NOTE: If you add more data to the pickle, make sure to update | 175 // NOTE: If you add more data to the pickle, make sure to update |
177 // PickleSizer::AddAttachment. | 176 // PickleSizer::AddAttachment. |
178 | 177 |
179 // Write the type of descriptor. | |
180 WriteBool(brokerable); | |
181 | |
182 // Write the index of the descriptor so that we don't have to | 178 // Write the index of the descriptor so that we don't have to |
183 // keep the current descriptor as extra decoding state when deserialising. | 179 // keep the current descriptor as extra decoding state when deserialising. |
184 WriteInt(static_cast<int>(index)); | 180 WriteInt(static_cast<int>(index)); |
185 | 181 |
186 return success; | 182 return success; |
187 } | 183 } |
188 | 184 |
189 bool Message::ReadAttachment( | 185 bool Message::ReadAttachment( |
190 base::PickleIterator* iter, | 186 base::PickleIterator* iter, |
191 scoped_refptr<base::Pickle::Attachment>* attachment) const { | 187 scoped_refptr<base::Pickle::Attachment>* attachment) const { |
192 bool brokerable; | |
193 if (!iter->ReadBool(&brokerable)) | |
194 return false; | |
195 | |
196 int index; | 188 int index; |
197 if (!iter->ReadInt(&index)) | 189 if (!iter->ReadInt(&index)) |
198 return false; | 190 return false; |
199 | 191 |
200 MessageAttachmentSet* attachment_set = attachment_set_.get(); | 192 MessageAttachmentSet* attachment_set = attachment_set_.get(); |
201 if (!attachment_set) | 193 if (!attachment_set) |
202 return false; | 194 return false; |
203 | 195 |
204 *attachment = brokerable | 196 *attachment = attachment_set->GetAttachmentAt(index); |
205 ? attachment_set->GetBrokerableAttachmentAt(index) | |
206 : attachment_set->GetNonBrokerableAttachmentAt(index); | |
207 | 197 |
208 return nullptr != attachment->get(); | 198 return nullptr != attachment->get(); |
209 } | 199 } |
210 | 200 |
211 bool Message::HasAttachments() const { | 201 bool Message::HasAttachments() const { |
212 return attachment_set_.get() && !attachment_set_->empty(); | 202 return attachment_set_.get() && !attachment_set_->empty(); |
213 } | 203 } |
214 | 204 |
215 bool Message::HasMojoHandles() const { | |
216 return attachment_set_.get() && attachment_set_->num_mojo_handles() > 0; | |
217 } | |
218 | |
219 bool Message::HasBrokerableAttachments() const { | |
220 return attachment_set_.get() && | |
221 attachment_set_->num_brokerable_attachments() > 0; | |
222 } | |
223 | |
224 } // namespace IPC | 205 } // namespace IPC |
OLD | NEW |