| 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_channel_reader.h" | 5 #include "ipc/ipc_channel_reader.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "ipc/ipc_listener.h" | 9 #include "ipc/ipc_listener.h" |
| 10 #include "ipc/ipc_logging.h" | 10 #include "ipc/ipc_logging.h" |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 90 } | 90 } |
| 91 | 91 |
| 92 // Dispatch all complete messages in the data buffer. | 92 // Dispatch all complete messages in the data buffer. |
| 93 while (p < end) { | 93 while (p < end) { |
| 94 Message::NextMessageInfo info; | 94 Message::NextMessageInfo info; |
| 95 Message::FindNext(p, end, &info); | 95 Message::FindNext(p, end, &info); |
| 96 if (info.message_found) { | 96 if (info.message_found) { |
| 97 int pickle_len = static_cast<int>(info.pickle_end - p); | 97 int pickle_len = static_cast<int>(info.pickle_end - p); |
| 98 Message translated_message(p, pickle_len); | 98 Message translated_message(p, pickle_len); |
| 99 | 99 |
| 100 // TODO(erikchen): Make attachments for info.attachment_ids. | 100 for (const auto& id : info.attachment_ids) |
| 101 // http://crbug.com/493414. | 101 translated_message.AddPlaceholderBrokerableAttachmentWithId(id); |
| 102 | 102 |
| 103 if (!GetNonBrokeredAttachments(&translated_message)) | 103 if (!GetNonBrokeredAttachments(&translated_message)) |
| 104 return false; | 104 return false; |
| 105 | 105 |
| 106 // If there are no queued messages, attempt to immediately dispatch the | 106 // If there are no queued messages, attempt to immediately dispatch the |
| 107 // newly translated message. | 107 // newly translated message. |
| 108 if (queued_messages_.empty()) { | 108 if (queued_messages_.empty()) { |
| 109 DCHECK(blocked_ids_.empty()); | 109 DCHECK(blocked_ids_.empty()); |
| 110 AttachmentIdSet blocked_ids = | 110 AttachmentIdSet blocked_ids = |
| 111 GetBrokeredAttachments(&translated_message); | 111 GetBrokeredAttachments(&translated_message); |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 194 if (m->dispatch_error()) | 194 if (m->dispatch_error()) |
| 195 listener_->OnBadMessageReceived(*m); | 195 listener_->OnBadMessageReceived(*m); |
| 196 } | 196 } |
| 197 | 197 |
| 198 ChannelReader::AttachmentIdSet ChannelReader::GetBrokeredAttachments( | 198 ChannelReader::AttachmentIdSet ChannelReader::GetBrokeredAttachments( |
| 199 Message* msg) { | 199 Message* msg) { |
| 200 std::set<BrokerableAttachment::AttachmentId> blocked_ids; | 200 std::set<BrokerableAttachment::AttachmentId> blocked_ids; |
| 201 | 201 |
| 202 #if USE_ATTACHMENT_BROKER | 202 #if USE_ATTACHMENT_BROKER |
| 203 MessageAttachmentSet* set = msg->attachment_set(); | 203 MessageAttachmentSet* set = msg->attachment_set(); |
| 204 for (const scoped_refptr<BrokerableAttachment>& attachment : | 204 std::vector<const BrokerableAttachment*> brokerable_attachments_copy = |
| 205 set->GetBrokerableAttachmentsForUpdating()) { | 205 set->PeekBrokerableAttachments(); |
| 206 for (const BrokerableAttachment* attachment : brokerable_attachments_copy) { |
| 206 if (attachment->NeedsBrokering()) { | 207 if (attachment->NeedsBrokering()) { |
| 207 AttachmentBroker* broker = GetAttachmentBroker(); | 208 AttachmentBroker* broker = GetAttachmentBroker(); |
| 208 scoped_refptr<BrokerableAttachment> brokered_attachment; | 209 scoped_refptr<BrokerableAttachment> brokered_attachment; |
| 209 bool result = broker->GetAttachmentWithId(attachment->GetIdentifier(), | 210 bool result = broker->GetAttachmentWithId(attachment->GetIdentifier(), |
| 210 &brokered_attachment); | 211 &brokered_attachment); |
| 211 if (!result) { | 212 if (!result) { |
| 212 blocked_ids.insert(attachment->GetIdentifier()); | 213 blocked_ids.insert(attachment->GetIdentifier()); |
| 213 continue; | 214 continue; |
| 214 } | 215 } |
| 215 | 216 |
| 216 attachment->PopulateWithAttachment(brokered_attachment.get()); | 217 set->ReplacePlaceholderWithAttachment(brokered_attachment); |
| 217 } | 218 } |
| 218 } | 219 } |
| 219 #endif // USE_ATTACHMENT_BROKER | 220 #endif // USE_ATTACHMENT_BROKER |
| 220 | 221 |
| 221 return blocked_ids; | 222 return blocked_ids; |
| 222 } | 223 } |
| 223 | 224 |
| 224 void ChannelReader::ReceivedBrokerableAttachmentWithId( | 225 void ChannelReader::ReceivedBrokerableAttachmentWithId( |
| 225 const BrokerableAttachment::AttachmentId& id) { | 226 const BrokerableAttachment::AttachmentId& id) { |
| 226 if (blocked_ids_.empty()) | 227 if (blocked_ids_.empty()) |
| (...skipping 16 matching lines...) Expand all Loading... |
| 243 } | 244 } |
| 244 | 245 |
| 245 void ChannelReader::StopObservingAttachmentBroker() { | 246 void ChannelReader::StopObservingAttachmentBroker() { |
| 246 #if USE_ATTACHMENT_BROKER | 247 #if USE_ATTACHMENT_BROKER |
| 247 GetAttachmentBroker()->RemoveObserver(this); | 248 GetAttachmentBroker()->RemoveObserver(this); |
| 248 #endif // USE_ATTACHMENT_BROKER | 249 #endif // USE_ATTACHMENT_BROKER |
| 249 } | 250 } |
| 250 | 251 |
| 251 } // namespace internal | 252 } // namespace internal |
| 252 } // namespace IPC | 253 } // namespace IPC |
| OLD | NEW |