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

Side by Side Diff: mojo/system/message_in_transit.cc

Issue 190973008: Mojo: Remove implicit scoped_refptr<T> -> T* conversions in mojo/. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 9 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 | Annotate | Revision Log
« no previous file with comments | « mojo/common/handle_watcher.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "mojo/system/message_in_transit.h" 5 #include "mojo/system/message_in_transit.h"
6 6
7 #include <string.h> 7 #include <string.h>
8 8
9 #include <new> 9 #include <new>
10 10
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
168 dispatchers_.get() ? dispatchers_->size() : static_cast<size_t>(0)); 168 dispatchers_.get() ? dispatchers_->size() : static_cast<size_t>(0));
169 169
170 if (!num_handles()) 170 if (!num_handles())
171 return; 171 return;
172 172
173 size_t handle_table_size = num_handles() * sizeof(HandleTableEntry); 173 size_t handle_table_size = num_handles() * sizeof(HandleTableEntry);
174 // The size of the secondary buffer. We'll start with the size of the handle 174 // The size of the secondary buffer. We'll start with the size of the handle
175 // table, and add to it as we go along. 175 // table, and add to it as we go along.
176 size_t size = handle_table_size; 176 size_t size = handle_table_size;
177 for (size_t i = 0; i < dispatchers_->size(); i++) { 177 for (size_t i = 0; i < dispatchers_->size(); i++) {
178 if (Dispatcher* dispatcher = (*dispatchers_)[i]) { 178 if (Dispatcher* dispatcher = (*dispatchers_)[i].get()) {
179 size += RoundUpMessageAlignment( 179 size += RoundUpMessageAlignment(
180 Dispatcher::MessageInTransitAccess::GetMaximumSerializedSize( 180 Dispatcher::MessageInTransitAccess::GetMaximumSerializedSize(
181 dispatcher, channel)); 181 dispatcher, channel));
182 // TODO(vtl): Check for overflow? 182 // TODO(vtl): Check for overflow?
183 } 183 }
184 } 184 }
185 185
186 secondary_buffer_ = base::AlignedAlloc(size, kMessageAlignment); 186 secondary_buffer_ = base::AlignedAlloc(size, kMessageAlignment);
187 // TODO(vtl): Check for overflow? 187 // TODO(vtl): Check for overflow?
188 secondary_buffer_size_ = static_cast<uint32_t>(size); 188 secondary_buffer_size_ = static_cast<uint32_t>(size);
189 // Entirely clear out the secondary buffer, since then we won't have to worry 189 // Entirely clear out the secondary buffer, since then we won't have to worry
190 // about clearing padding or unused space (e.g., if a dispatcher fails to 190 // about clearing padding or unused space (e.g., if a dispatcher fails to
191 // serialize). 191 // serialize).
192 memset(secondary_buffer_, 0, size); 192 memset(secondary_buffer_, 0, size);
193 193
194 HandleTableEntry* handle_table = 194 HandleTableEntry* handle_table =
195 static_cast<HandleTableEntry*>(secondary_buffer_); 195 static_cast<HandleTableEntry*>(secondary_buffer_);
196 size_t current_offset = handle_table_size; 196 size_t current_offset = handle_table_size;
197 for (size_t i = 0; i < dispatchers_->size(); i++) { 197 for (size_t i = 0; i < dispatchers_->size(); i++) {
198 Dispatcher* dispatcher = (*dispatchers_)[i]; 198 Dispatcher* dispatcher = (*dispatchers_)[i].get();
199 if (!dispatcher) { 199 if (!dispatcher) {
200 COMPILE_ASSERT(Dispatcher::kTypeUnknown == 0, 200 COMPILE_ASSERT(Dispatcher::kTypeUnknown == 0,
201 need_Dispatcher_kTypeUnknown_to_be_zero); 201 value_of_Dispatcher_kTypeUnknown_must_be_zero);
202 continue; 202 continue;
203 } 203 }
204 204
205 void* destination = static_cast<char*>(secondary_buffer_) + current_offset; 205 void* destination = static_cast<char*>(secondary_buffer_) + current_offset;
206 size_t actual_size = 0; 206 size_t actual_size = 0;
207 if (Dispatcher::MessageInTransitAccess::SerializeAndClose( 207 if (Dispatcher::MessageInTransitAccess::SerializeAndClose(
208 dispatcher, channel, destination, &actual_size)) { 208 dispatcher, channel, destination, &actual_size)) {
209 handle_table[i].type = static_cast<int32_t>(dispatcher->GetType()); 209 handle_table[i].type = static_cast<int32_t>(dispatcher->GetType());
210 handle_table[i].offset = static_cast<uint32_t>(current_offset); 210 handle_table[i].offset = static_cast<uint32_t>(current_offset);
211 handle_table[i].size = static_cast<uint32_t>(actual_size); 211 handle_table[i].size = static_cast<uint32_t>(actual_size);
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
263 263
264 void MessageInTransit::UpdateTotalSize() { 264 void MessageInTransit::UpdateTotalSize() {
265 DCHECK_EQ(main_buffer_size_ % kMessageAlignment, 0u); 265 DCHECK_EQ(main_buffer_size_ % kMessageAlignment, 0u);
266 DCHECK_EQ(secondary_buffer_size_ % kMessageAlignment, 0u); 266 DCHECK_EQ(secondary_buffer_size_ % kMessageAlignment, 0u);
267 header()->total_size = 267 header()->total_size =
268 static_cast<uint32_t>(main_buffer_size_ + secondary_buffer_size_); 268 static_cast<uint32_t>(main_buffer_size_ + secondary_buffer_size_);
269 } 269 }
270 270
271 } // namespace system 271 } // namespace system
272 } // namespace mojo 272 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/common/handle_watcher.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698