summaryrefslogtreecommitdiffstats
path: root/ipc/ipc_channel_reader.cc
diff options
context:
space:
mode:
authorerikchen <erikchen@chromium.org>2015-08-19 17:59:13 -0700
committerCommit bot <commit-bot@chromium.org>2015-08-20 01:00:01 +0000
commite8e4f4fa67ee9db6c2910020ef49318e5df68481 (patch)
treec55abb9c58bab8564cb20c36e2c4887e0c5d095b /ipc/ipc_channel_reader.cc
parent0e70552cb63a7f64d4badcf70e3e25d256b31f24 (diff)
downloadchromium_src-e8e4f4fa67ee9db6c2910020ef49318e5df68481.zip
chromium_src-e8e4f4fa67ee9db6c2910020ef49318e5df68481.tar.gz
chromium_src-e8e4f4fa67ee9db6c2910020ef49318e5df68481.tar.bz2
IPC: Add attachment brokering support to the message header.
Message dispatch happens before message translation, and message dispatch requires that all brokered attachments have been received. This means that attachment brokering needs to function without message translation. This is accomplished by modifying the message header to include a new field num_brokered_attachments, and writing the attachment ids into the IPC Channel immediately following the pickled message itself. AttachmentBrokerPrivilegedWinUnittest was expanded to test ChannelReader in the receiving process. It is now a fully functional end-to-end test of attachment brokering. BUG=493414 Review URL: https://codereview.chromium.org/1286253002 Cr-Commit-Position: refs/heads/master@{#344389}
Diffstat (limited to 'ipc/ipc_channel_reader.cc')
-rw-r--r--ipc/ipc_channel_reader.cc32
1 files changed, 21 insertions, 11 deletions
diff --git a/ipc/ipc_channel_reader.cc b/ipc/ipc_channel_reader.cc
index a76b7e6..c47d2bc 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 (const auto& id : info.attachment_ids)
+ 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());
@@ -191,8 +200,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;
@@ -203,7 +213,7 @@ ChannelReader::AttachmentIdSet ChannelReader::GetBrokeredAttachments(
continue;
}
- attachment->PopulateWithAttachment(brokered_attachment.get());
+ set->ReplacePlaceholderWithAttachment(brokered_attachment);
}
}
#endif // USE_ATTACHMENT_BROKER