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

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

Issue 226203003: Mojo: Add the ability to attach PlatformHandles to MessageInTransits. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 8 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/system/message_in_transit.h ('k') | mojo/system/raw_channel.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 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 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 memcpy(secondary_buffer_, message_view.secondary_buffer(), 141 memcpy(secondary_buffer_, message_view.secondary_buffer(),
142 secondary_buffer_size_); 142 secondary_buffer_size_);
143 143
144 DCHECK_EQ(main_buffer_size_, 144 DCHECK_EQ(main_buffer_size_,
145 RoundUpMessageAlignment(sizeof(Header) + num_bytes())); 145 RoundUpMessageAlignment(sizeof(Header) + num_bytes()));
146 } 146 }
147 147
148 MessageInTransit::~MessageInTransit() { 148 MessageInTransit::~MessageInTransit() {
149 base::AlignedFree(main_buffer_); 149 base::AlignedFree(main_buffer_);
150 base::AlignedFree(secondary_buffer_); // Okay if null. 150 base::AlignedFree(secondary_buffer_); // Okay if null.
151 #ifndef NDEBUG
152 main_buffer_size_ = 0;
153 main_buffer_ = NULL;
154 secondary_buffer_size_ = 0;
155 secondary_buffer_ = NULL;
156 #endif
157 151
158 if (dispatchers_.get()) { 152 if (dispatchers_) {
159 for (size_t i = 0; i < dispatchers_->size(); i++) { 153 for (size_t i = 0; i < dispatchers_->size(); i++) {
160 if (!(*dispatchers_)[i]) 154 if (!(*dispatchers_)[i])
161 continue; 155 continue;
162 156
163 DCHECK((*dispatchers_)[i]->HasOneRef()); 157 DCHECK((*dispatchers_)[i]->HasOneRef());
164 (*dispatchers_)[i]->Close(); 158 (*dispatchers_)[i]->Close();
165 } 159 }
166 dispatchers_.reset();
167 } 160 }
161
162 if (platform_handles_) {
163 for (size_t i = 0; i < platform_handles_->size(); i++)
164 (*platform_handles_)[i].CloseIfNecessary();
165 }
166
167 #ifndef NDEBUG
168 main_buffer_size_ = 0;
169 main_buffer_ = NULL;
170 secondary_buffer_size_ = 0;
171 secondary_buffer_ = NULL;
172 dispatchers_.reset();
173 platform_handles_.reset();
174 #endif
168 } 175 }
169 176
170 // static 177 // static
171 bool MessageInTransit::GetNextMessageSize(const void* buffer, 178 bool MessageInTransit::GetNextMessageSize(const void* buffer,
172 size_t buffer_size, 179 size_t buffer_size,
173 size_t* next_message_size) { 180 size_t* next_message_size) {
174 DCHECK(next_message_size); 181 DCHECK(next_message_size);
175 if (!buffer_size) 182 if (!buffer_size)
176 return false; 183 return false;
177 DCHECK(buffer); 184 DCHECK(buffer);
178 DCHECK_EQ(reinterpret_cast<uintptr_t>(buffer) % 185 DCHECK_EQ(reinterpret_cast<uintptr_t>(buffer) %
179 MessageInTransit::kMessageAlignment, 0u); 186 MessageInTransit::kMessageAlignment, 0u);
180 187
181 if (buffer_size < sizeof(Header)) 188 if (buffer_size < sizeof(Header))
182 return false; 189 return false;
183 190
184 const Header* header = static_cast<const Header*>(buffer); 191 const Header* header = static_cast<const Header*>(buffer);
185 *next_message_size = header->total_size; 192 *next_message_size = header->total_size;
186 DCHECK_EQ(*next_message_size % kMessageAlignment, 0u); 193 DCHECK_EQ(*next_message_size % kMessageAlignment, 0u);
187 return true; 194 return true;
188 } 195 }
189 196
190 void MessageInTransit::SetDispatchers( 197 void MessageInTransit::SetDispatchers(
191 scoped_ptr<std::vector<scoped_refptr<Dispatcher> > > dispatchers) { 198 scoped_ptr<std::vector<scoped_refptr<Dispatcher> > > dispatchers) {
192 DCHECK(dispatchers.get()); 199 DCHECK(dispatchers);
193 DCHECK(!dispatchers_.get()); 200 DCHECK(!dispatchers_);
194 201
195 dispatchers_ = dispatchers.Pass(); 202 dispatchers_ = dispatchers.Pass();
196 #ifndef NDEBUG 203 #ifndef NDEBUG
197 for (size_t i = 0; i < dispatchers_->size(); i++) 204 for (size_t i = 0; i < dispatchers_->size(); i++)
198 DCHECK(!(*dispatchers_)[i] || (*dispatchers_)[i]->HasOneRef()); 205 DCHECK(!(*dispatchers_)[i] || (*dispatchers_)[i]->HasOneRef());
199 #endif 206 #endif
200 } 207 }
201 208
202 void MessageInTransit::SerializeAndCloseDispatchers(Channel* channel) { 209 void MessageInTransit::SerializeAndCloseDispatchers(Channel* channel) {
203 DCHECK(channel); 210 DCHECK(channel);
204 DCHECK(!secondary_buffer_); 211 DCHECK(!secondary_buffer_);
205 CHECK_EQ(num_handles(), 212 CHECK_EQ(num_handles(),
206 dispatchers_.get() ? dispatchers_->size() : static_cast<size_t>(0)); 213 dispatchers_ ? dispatchers_->size() : static_cast<size_t>(0));
207 214
208 if (!num_handles()) 215 if (!num_handles())
209 return; 216 return;
210 217
211 size_t handle_table_size = num_handles() * sizeof(HandleTableEntry); 218 size_t handle_table_size = num_handles() * sizeof(HandleTableEntry);
212 // The size of the secondary buffer. We'll start with the size of the handle 219 // The size of the secondary buffer. We'll start with the size of the handle
213 // table, and add to it as we go along. 220 // table, and add to it as we go along.
214 size_t size = handle_table_size; 221 size_t size = handle_table_size;
215 for (size_t i = 0; i < dispatchers_->size(); i++) { 222 for (size_t i = 0; i < dispatchers_->size(); i++) {
216 if (Dispatcher* dispatcher = (*dispatchers_)[i].get()) { 223 if (Dispatcher* dispatcher = (*dispatchers_)[i].get()) {
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
256 } 263 }
257 264
258 current_offset += RoundUpMessageAlignment(actual_size); 265 current_offset += RoundUpMessageAlignment(actual_size);
259 DCHECK_LE(current_offset, size); 266 DCHECK_LE(current_offset, size);
260 } 267 }
261 268
262 UpdateTotalSize(); 269 UpdateTotalSize();
263 } 270 }
264 271
265 void MessageInTransit::DeserializeDispatchers(Channel* channel) { 272 void MessageInTransit::DeserializeDispatchers(Channel* channel) {
266 DCHECK(!dispatchers_.get()); 273 DCHECK(!dispatchers_);
267 274
268 // This should have been checked by calling |IsValid()| on the |View| first. 275 // This should have been checked by calling |IsValid()| on the |View| first.
269 DCHECK_LE(num_handles(), kMaxMessageNumHandles); 276 DCHECK_LE(num_handles(), kMaxMessageNumHandles);
270 277
271 if (!num_handles()) 278 if (!num_handles())
272 return; 279 return;
273 280
274 dispatchers_.reset( 281 dispatchers_.reset(
275 new std::vector<scoped_refptr<Dispatcher> >(num_handles())); 282 new std::vector<scoped_refptr<Dispatcher> >(num_handles()));
276 283
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
346 353
347 void MessageInTransit::UpdateTotalSize() { 354 void MessageInTransit::UpdateTotalSize() {
348 DCHECK_EQ(main_buffer_size_ % kMessageAlignment, 0u); 355 DCHECK_EQ(main_buffer_size_ % kMessageAlignment, 0u);
349 DCHECK_EQ(secondary_buffer_size_ % kMessageAlignment, 0u); 356 DCHECK_EQ(secondary_buffer_size_ % kMessageAlignment, 0u);
350 header()->total_size = 357 header()->total_size =
351 static_cast<uint32_t>(main_buffer_size_ + secondary_buffer_size_); 358 static_cast<uint32_t>(main_buffer_size_ + secondary_buffer_size_);
352 } 359 }
353 360
354 } // namespace system 361 } // namespace system
355 } // namespace mojo 362 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/system/message_in_transit.h ('k') | mojo/system/raw_channel.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698