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

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

Issue 405653003: mojo: Make InterfacePtr<> testable in if() statements without .get(). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Move to is_bound() Created 6 years, 5 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/spy/spy.cc ('k') | mojo/views/native_widget_view_manager.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 // TODO(vtl): I currently potentially overflow in doing index calculations. 5 // TODO(vtl): I currently potentially overflow in doing index calculations.
6 // E.g., |start_index_| and |current_num_bytes_| fit into a |uint32_t|, but 6 // E.g., |start_index_| and |current_num_bytes_| fit into a |uint32_t|, but
7 // their sum may not. This is bad and poses a security risk. (We're currently 7 // their sum may not. This is bad and poses a security risk. (We're currently
8 // saved by the limit on capacity -- the maximum size of the buffer, checked in 8 // saved by the limit on capacity -- the maximum size of the buffer, checked in
9 // |DataPipe::ValidateOptions()|, is currently sufficiently small. 9 // |DataPipe::ValidateOptions()|, is currently sufficiently small.
10 10
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after
280 rv.satisfied_signals |= MOJO_HANDLE_SIGNAL_READABLE; 280 rv.satisfied_signals |= MOJO_HANDLE_SIGNAL_READABLE;
281 rv.satisfiable_signals |= MOJO_HANDLE_SIGNAL_READABLE; 281 rv.satisfiable_signals |= MOJO_HANDLE_SIGNAL_READABLE;
282 } else if (producer_open_no_lock()) { 282 } else if (producer_open_no_lock()) {
283 rv.satisfiable_signals |= MOJO_HANDLE_SIGNAL_READABLE; 283 rv.satisfiable_signals |= MOJO_HANDLE_SIGNAL_READABLE;
284 } 284 }
285 return rv; 285 return rv;
286 } 286 }
287 287
288 void LocalDataPipe::EnsureBufferNoLock() { 288 void LocalDataPipe::EnsureBufferNoLock() {
289 DCHECK(producer_open_no_lock()); 289 DCHECK(producer_open_no_lock());
290 if (buffer_.get()) 290 if (buffer_)
291 return; 291 return;
292 buffer_.reset(static_cast<char*>( 292 buffer_.reset(static_cast<char*>(
293 base::AlignedAlloc(capacity_num_bytes(), kDataPipeBufferAlignmentBytes))); 293 base::AlignedAlloc(capacity_num_bytes(), kDataPipeBufferAlignmentBytes)));
294 } 294 }
295 295
296 void LocalDataPipe::DestroyBufferNoLock() { 296 void LocalDataPipe::DestroyBufferNoLock() {
297 #ifndef NDEBUG 297 #ifndef NDEBUG
298 // Scribble on the buffer to help detect use-after-frees. (This also helps the 298 // Scribble on the buffer to help detect use-after-frees. (This also helps the
299 // unit test detect certain bugs without needing ASAN or similar.) 299 // unit test detect certain bugs without needing ASAN or similar.)
300 if (buffer_.get()) 300 if (buffer_)
301 memset(buffer_.get(), 0xcd, capacity_num_bytes()); 301 memset(buffer_.get(), 0xcd, capacity_num_bytes());
302 #endif 302 #endif
303 buffer_.reset(); 303 buffer_.reset();
304 } 304 }
305 305
306 size_t LocalDataPipe::GetMaxNumBytesToWriteNoLock() { 306 size_t LocalDataPipe::GetMaxNumBytesToWriteNoLock() {
307 size_t next_index = start_index_ + current_num_bytes_; 307 size_t next_index = start_index_ + current_num_bytes_;
308 if (next_index >= capacity_num_bytes()) { 308 if (next_index >= capacity_num_bytes()) {
309 next_index %= capacity_num_bytes(); 309 next_index %= capacity_num_bytes();
310 DCHECK_GE(start_index_, next_index); 310 DCHECK_GE(start_index_, next_index);
(...skipping 12 matching lines...) Expand all
323 323
324 void LocalDataPipe::MarkDataAsConsumedNoLock(size_t num_bytes) { 324 void LocalDataPipe::MarkDataAsConsumedNoLock(size_t num_bytes) {
325 DCHECK_LE(num_bytes, current_num_bytes_); 325 DCHECK_LE(num_bytes, current_num_bytes_);
326 start_index_ += num_bytes; 326 start_index_ += num_bytes;
327 start_index_ %= capacity_num_bytes(); 327 start_index_ %= capacity_num_bytes();
328 current_num_bytes_ -= num_bytes; 328 current_num_bytes_ -= num_bytes;
329 } 329 }
330 330
331 } // namespace system 331 } // namespace system
332 } // namespace mojo 332 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/spy/spy.cc ('k') | mojo/views/native_widget_view_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698