Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(454)

Side by Side Diff: ipc/ipc_channel_reader.cc

Issue 1308613006: ipc: Update Message::FindNext to parse brokered attachments. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Really disable tests. Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 input_overflow_buf_.clear(); 77 input_overflow_buf_.clear();
78 LOG(ERROR) << "IPC message is too big"; 78 LOG(ERROR) << "IPC message is too big";
79 return false; 79 return false;
80 } 80 }
81 input_overflow_buf_.append(input_data, input_data_len); 81 input_overflow_buf_.append(input_data, input_data_len);
82 p = input_overflow_buf_.data(); 82 p = input_overflow_buf_.data();
83 end = p + input_overflow_buf_.size(); 83 end = p + input_overflow_buf_.size();
84 } 84 }
85 85
86 // Dispatch all complete messages in the data buffer. 86 // Dispatch all complete messages in the data buffer.
87 bool unrecoverable_parsing_error = false;
87 while (p < end) { 88 while (p < end) {
88 const char* message_tail = Message::FindNext(p, end); 89 Message::NextMessageInfo info = Message::FindNext(p, end);
89 if (message_tail) { 90 if (info.message_found) {
90 int len = static_cast<int>(message_tail - p); 91 int pickle_len = static_cast<int>(info.pickle_end - p);
92 Message translated_message(p, pickle_len);
91 93
92 Message translated_message(p, len); 94 // TODO(erikchen): Make attachments for info.attachment_ids.
95 // http://crbug.com/493414.
96
93 if (!GetNonBrokeredAttachments(&translated_message)) 97 if (!GetNonBrokeredAttachments(&translated_message))
94 return false; 98 return false;
95 99
96 // If there are no queued messages, attempt to immediately dispatch the 100 // If there are no queued messages, attempt to immediately dispatch the
97 // newly translated message. 101 // newly translated message.
98 if (queued_messages_.empty()) { 102 if (queued_messages_.empty()) {
99 DCHECK(blocked_ids_.empty()); 103 DCHECK(blocked_ids_.empty());
100 AttachmentIdSet blocked_ids = 104 AttachmentIdSet blocked_ids =
101 GetBrokeredAttachments(&translated_message); 105 GetBrokeredAttachments(&translated_message);
102 106
103 if (blocked_ids.empty()) { 107 if (blocked_ids.empty()) {
104 // Dispatch the message and continue the loop. 108 // Dispatch the message and continue the loop.
105 DispatchMessage(&translated_message); 109 DispatchMessage(&translated_message);
106 p = message_tail; 110 p = info.message_end;
107 continue; 111 continue;
108 } 112 }
109 113
110 blocked_ids_.swap(blocked_ids); 114 blocked_ids_.swap(blocked_ids);
111 StartObservingAttachmentBroker(); 115 StartObservingAttachmentBroker();
112 } 116 }
113 117
114 // Make a deep copy of |translated_message| to add to the queue. 118 // Make a deep copy of |translated_message| to add to the queue.
115 scoped_ptr<Message> m(new Message(translated_message)); 119 scoped_ptr<Message> m(new Message(translated_message));
116 queued_messages_.push_back(m.release()); 120 queued_messages_.push_back(m.release());
117 p = message_tail; 121 p = info.message_end;
118 } else { 122 } else {
119 // Last message is partial. 123 // Last message is partial.
124 unrecoverable_parsing_error = info.parsing_error;
120 break; 125 break;
121 } 126 }
122 } 127 }
123 128
124 // Save any partial data in the overflow buffer. 129 // Save any partial data in the overflow buffer.
125 input_overflow_buf_.assign(p, end - p); 130 input_overflow_buf_.assign(p, end - p);
126 131
127 if (input_overflow_buf_.empty() && !DidEmptyInputBuffers()) 132 if (input_overflow_buf_.empty() && !DidEmptyInputBuffers())
128 return false; 133 return false;
134 if (unrecoverable_parsing_error)
135 return false;
129 return true; 136 return true;
130 } 137 }
131 138
132 ChannelReader::DispatchState ChannelReader::DispatchMessages() { 139 ChannelReader::DispatchState ChannelReader::DispatchMessages() {
133 while (!queued_messages_.empty()) { 140 while (!queued_messages_.empty()) {
134 if (!blocked_ids_.empty()) 141 if (!blocked_ids_.empty())
135 return DISPATCH_WAITING_ON_BROKER; 142 return DISPATCH_WAITING_ON_BROKER;
136 143
137 Message* m = queued_messages_.front(); 144 Message* m = queued_messages_.front();
138 145
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
233 } 240 }
234 241
235 void ChannelReader::StopObservingAttachmentBroker() { 242 void ChannelReader::StopObservingAttachmentBroker() {
236 #if USE_ATTACHMENT_BROKER 243 #if USE_ATTACHMENT_BROKER
237 GetAttachmentBroker()->RemoveObserver(this); 244 GetAttachmentBroker()->RemoveObserver(this);
238 #endif // USE_ATTACHMENT_BROKER 245 #endif // USE_ATTACHMENT_BROKER
239 } 246 }
240 247
241 } // namespace internal 248 } // namespace internal
242 } // namespace IPC 249 } // namespace IPC
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698