Chromium Code Reviews| Index: ipc/ipc_channel_reader.cc |
| diff --git a/ipc/ipc_channel_reader.cc b/ipc/ipc_channel_reader.cc |
| index 30f03a1f2decbb2fd74b690baf5cc22eeb392ef5..d021b3fc9c36f99efe9e8722419c6da8ebe0b9c6 100644 |
| --- a/ipc/ipc_channel_reader.cc |
| +++ b/ipc/ipc_channel_reader.cc |
| @@ -20,8 +20,7 @@ ChannelReader::ChannelReader(Listener* listener) : listener_(listener) { |
| } |
| ChannelReader::~ChannelReader() { |
| - if (!blocked_ids_.empty()) |
| - StopObservingAttachmentBroker(); |
| + DCHECK(blocked_ids_.empty()); |
| } |
| ChannelReader::DispatchState ChannelReader::ProcessIncomingMessages() { |
| @@ -85,11 +84,14 @@ bool ChannelReader::TranslateInputData(const char* input_data, |
| // Dispatch all complete messages in the data buffer. |
| while (p < end) { |
| - const char* message_tail = Message::FindNext(p, end); |
| - if (message_tail) { |
| - int len = static_cast<int>(message_tail - p); |
| + Message::NextMessageInfo info = Message::FindNext(p, end); |
| + if (info.message_found) { |
| + int pickle_len = static_cast<int>(info.pickle_end - p); |
| + Message translated_message(p, pickle_len); |
| + |
| + for (BrokerableAttachment::AttachmentId id : info.attachment_ids) |
|
Tom Sepez
2015/08/17 18:29:39
nit: maybe auto makes this simpler, also do you wa
erikchen
2015/08/18 05:59:46
Done.
|
| + translated_message.AddPlaceholderBrokerableAttachmentWithId(id); |
| - Message translated_message(p, len); |
| if (!GetNonBrokeredAttachments(&translated_message)) |
| return false; |
| @@ -103,7 +105,7 @@ bool ChannelReader::TranslateInputData(const char* input_data, |
| if (blocked_ids.empty()) { |
| // Dispatch the message and continue the loop. |
| DispatchMessage(&translated_message); |
| - p = message_tail; |
| + p = info.message_end; |
| continue; |
| } |
| @@ -114,7 +116,7 @@ bool ChannelReader::TranslateInputData(const char* input_data, |
| // Make a deep copy of |translated_message| to add to the queue. |
| scoped_ptr<Message> m(new Message(translated_message)); |
| queued_messages_.push_back(m.release()); |
| - p = message_tail; |
| + p = info.message_end; |
| } else { |
| // Last message is partial. |
| break; |
| @@ -149,6 +151,13 @@ ChannelReader::DispatchState ChannelReader::DispatchMessages() { |
| return DISPATCH_FINISHED; |
| } |
| +void ChannelReader::CleanUp() { |
| + if (!blocked_ids_.empty()) { |
| + StopObservingAttachmentBroker(); |
| + blocked_ids_.clear(); |
| + } |
| +} |
| + |
| void ChannelReader::DispatchMessage(Message* m) { |
| m->set_sender_pid(GetSenderPID()); |
| @@ -186,8 +195,9 @@ ChannelReader::AttachmentIdSet ChannelReader::GetBrokeredAttachments( |
| #if USE_ATTACHMENT_BROKER |
| MessageAttachmentSet* set = msg->attachment_set(); |
| - for (const scoped_refptr<BrokerableAttachment>& attachment : |
| - set->GetBrokerableAttachmentsForUpdating()) { |
| + std::vector<const BrokerableAttachment*> brokerable_attachments_copy = |
| + set->PeekBrokerableAttachments(); |
| + for (const BrokerableAttachment* attachment : brokerable_attachments_copy) { |
| if (attachment->NeedsBrokering()) { |
| AttachmentBroker* broker = GetAttachmentBroker(); |
| scoped_refptr<BrokerableAttachment> brokered_attachment; |
| @@ -198,7 +208,7 @@ ChannelReader::AttachmentIdSet ChannelReader::GetBrokeredAttachments( |
| continue; |
| } |
| - attachment->PopulateWithAttachment(brokered_attachment.get()); |
| + set->ReplacePlaceholderWithAttachment(brokered_attachment); |
| } |
| } |
| #endif // USE_ATTACHMENT_BROKER |