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

Side by Side Diff: ipc/ipc_message.cc

Issue 1392713004: ipc: Add missing includes for USE_ATTACHMENT_BROKER. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix unit test. Created 5 years, 2 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
« no previous file with comments | « content/common/child_process_host_impl.cc ('k') | ipc/ipc_message_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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_message.h" 5 #include "ipc/ipc_message.h"
6 6
7 #include <limits.h> 7 #include <limits.h>
8 8
9 #include "base/atomic_sequence_num.h" 9 #include "base/atomic_sequence_num.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "build/build_config.h" 11 #include "build/build_config.h"
12 #include "ipc/attachment_broker.h"
12 #include "ipc/ipc_message_attachment.h" 13 #include "ipc/ipc_message_attachment.h"
13 #include "ipc/ipc_message_attachment_set.h" 14 #include "ipc/ipc_message_attachment_set.h"
14 #include "ipc/placeholder_brokerable_attachment.h" 15 #include "ipc/placeholder_brokerable_attachment.h"
15 16
16 #if defined(OS_POSIX) 17 #if defined(OS_POSIX)
17 #include "base/file_descriptor_posix.h" 18 #include "base/file_descriptor_posix.h"
18 #include "ipc/ipc_platform_file_attachment_posix.h" 19 #include "ipc/ipc_platform_file_attachment_posix.h"
19 #endif 20 #endif
20 21
21 namespace { 22 namespace {
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 info->message_size = 0; 172 info->message_size = 0;
172 173
173 size_t pickle_size = 0; 174 size_t pickle_size = 0;
174 if (!base::Pickle::PeekNext(sizeof(Header), 175 if (!base::Pickle::PeekNext(sizeof(Header),
175 range_start, range_end, &pickle_size)) 176 range_start, range_end, &pickle_size))
176 return; 177 return;
177 178
178 bool have_entire_pickle = 179 bool have_entire_pickle =
179 static_cast<size_t>(range_end - range_start) >= pickle_size; 180 static_cast<size_t>(range_end - range_start) >= pickle_size;
180 181
181 #if USE_ATTACHMENT_BROKER 182 #if USE_ATTACHMENT_BROKER && defined(OS_MACOSX) && !defined(OS_IOS)
182 // TODO(dskiba): determine message_size when entire pickle is not available 183 // TODO(dskiba): determine message_size when entire pickle is not available
183 184
184 if (!have_entire_pickle) 185 if (!have_entire_pickle)
185 return; 186 return;
186 187
187 const char* pickle_end = range_start + pickle_size; 188 const char* pickle_end = range_start + pickle_size;
188 189
189 // The data is not copied. 190 // The data is not copied.
190 Message message(range_start, static_cast<int>(pickle_size)); 191 Message message(range_start, static_cast<int>(pickle_size));
191 size_t num_attachments = message.header()->num_brokered_attachments; 192 size_t num_attachments = message.header()->num_brokered_attachments;
192 193
193 // Check for possible overflows. 194 // Check for possible overflows.
194 size_t max_size_t = std::numeric_limits<size_t>::max(); 195 size_t max_size_t = std::numeric_limits<size_t>::max();
195 if (num_attachments >= max_size_t / BrokerableAttachment::kNonceSize) 196 if (num_attachments >= max_size_t / BrokerableAttachment::kNonceSize)
196 return; 197 return;
197 198
198 size_t attachment_length = num_attachments * BrokerableAttachment::kNonceSize; 199 size_t attachment_length = num_attachments * BrokerableAttachment::kNonceSize;
199 if (pickle_size > max_size_t - attachment_length) 200 if (pickle_size > max_size_t - attachment_length)
200 return; 201 return;
201 202
202 // Check whether the range includes the attachments. 203 // Check whether the range includes the attachments.
203 size_t buffer_length = static_cast<size_t>(range_end - range_start); 204 size_t buffer_length = static_cast<size_t>(range_end - range_start);
204 if (buffer_length < attachment_length + pickle_size) 205 if (buffer_length < attachment_length + pickle_size)
205 return; 206 return;
206 207
207 for (int i = 0; i < num_attachments; ++i) { 208 for (size_t i = 0; i < num_attachments; ++i) {
208 const char* attachment_start = 209 const char* attachment_start =
209 pickle_end + i * BrokerableAttachment::kNonceSize; 210 pickle_end + i * BrokerableAttachment::kNonceSize;
210 BrokerableAttachment::AttachmentId id(attachment_start, 211 BrokerableAttachment::AttachmentId id(attachment_start,
211 BrokerableAttachment::kNonceSize); 212 BrokerableAttachment::kNonceSize);
212 info->attachment_ids.push_back(id); 213 info->attachment_ids.push_back(id);
213 } 214 }
214 info->message_end = 215 info->message_end =
215 pickle_end + num_attachments * BrokerableAttachment::kNonceSize; 216 pickle_end + num_attachments * BrokerableAttachment::kNonceSize;
216 info->message_size = info->message_end - range_start; 217 info->message_size = info->message_end - range_start;
217 #else 218 #else
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
265 bool Message::HasMojoHandles() const { 266 bool Message::HasMojoHandles() const {
266 return attachment_set_.get() && attachment_set_->num_mojo_handles() > 0; 267 return attachment_set_.get() && attachment_set_->num_mojo_handles() > 0;
267 } 268 }
268 269
269 bool Message::HasBrokerableAttachments() const { 270 bool Message::HasBrokerableAttachments() const {
270 return attachment_set_.get() && 271 return attachment_set_.get() &&
271 attachment_set_->num_brokerable_attachments() > 0; 272 attachment_set_->num_brokerable_attachments() > 0;
272 } 273 }
273 274
274 } // namespace IPC 275 } // namespace IPC
OLDNEW
« no previous file with comments | « content/common/child_process_host_impl.cc ('k') | ipc/ipc_message_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698