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

Side by Side Diff: mojo/edk/system/local_data_pipe_impl.cc

Issue 1350503004: Some easy conversions of scoped_ptr -> std::unique_ptr in the EDK. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: 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
« no previous file with comments | « mojo/edk/system/local_data_pipe_impl.h ('k') | mojo/edk/system/memory.h » ('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
11 #include "mojo/edk/system/local_data_pipe_impl.h" 11 #include "mojo/edk/system/local_data_pipe_impl.h"
12 12
13 #include <string.h> 13 #include <string.h>
14 14
15 #include <algorithm> 15 #include <algorithm>
16 #include <utility>
16 17
17 #include "base/logging.h" 18 #include "base/logging.h"
18 #include "base/memory/scoped_ptr.h" 19 #include "base/memory/scoped_ptr.h"
19 #include "mojo/edk/system/channel.h" 20 #include "mojo/edk/system/channel.h"
20 #include "mojo/edk/system/configuration.h" 21 #include "mojo/edk/system/configuration.h"
21 #include "mojo/edk/system/data_pipe.h" 22 #include "mojo/edk/system/data_pipe.h"
22 #include "mojo/edk/system/message_in_transit.h" 23 #include "mojo/edk/system/message_in_transit.h"
23 #include "mojo/edk/system/message_in_transit_queue.h" 24 #include "mojo/edk/system/message_in_transit_queue.h"
24 #include "mojo/edk/system/remote_consumer_data_pipe_impl.h" 25 #include "mojo/edk/system/remote_consumer_data_pipe_impl.h"
25 #include "mojo/edk/system/remote_producer_data_pipe_impl.h" 26 #include "mojo/edk/system/remote_producer_data_pipe_impl.h"
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 // |RemoteProducerDataPipeImpl|. 187 // |RemoteProducerDataPipeImpl|.
187 188
188 s->consumer_num_bytes = current_num_bytes_; 189 s->consumer_num_bytes = current_num_bytes_;
189 // Note: We don't use |port|. 190 // Note: We don't use |port|.
190 scoped_refptr<ChannelEndpoint> channel_endpoint = 191 scoped_refptr<ChannelEndpoint> channel_endpoint =
191 channel->SerializeEndpointWithLocalPeer(destination_for_endpoint, nullptr, 192 channel->SerializeEndpointWithLocalPeer(destination_for_endpoint, nullptr,
192 channel_endpoint_client(), 0); 193 channel_endpoint_client(), 0);
193 // Note: Keep |*this| alive until the end of this method, to make things 194 // Note: Keep |*this| alive until the end of this method, to make things
194 // slightly easier on ourselves. 195 // slightly easier on ourselves.
195 scoped_ptr<DataPipeImpl> self(ReplaceImpl(make_scoped_ptr( 196 scoped_ptr<DataPipeImpl> self(ReplaceImpl(make_scoped_ptr(
196 new RemoteProducerDataPipeImpl(channel_endpoint.get(), buffer_.Pass(), 197 new RemoteProducerDataPipeImpl(channel_endpoint.get(), std::move(buffer_),
197 start_index_, current_num_bytes_)))); 198 start_index_, current_num_bytes_))));
198 199
199 *actual_size = sizeof(SerializedDataPipeProducerDispatcher) + 200 *actual_size = sizeof(SerializedDataPipeProducerDispatcher) +
200 channel->GetSerializedEndpointSize(); 201 channel->GetSerializedEndpointSize();
201 return true; 202 return true;
202 } 203 }
203 204
204 void LocalDataPipeImpl::ConsumerClose() { 205 void LocalDataPipeImpl::ConsumerClose() {
205 // If the producer is around and in a two-phase write, we have to keep the 206 // If the producer is around and in a two-phase write, we have to keep the
206 // buffer around. (We then don't free it until the producer is closed. This 207 // buffer around. (We then don't free it until the producer is closed. This
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after
436 437
437 void LocalDataPipeImpl::MarkDataAsConsumed(size_t num_bytes) { 438 void LocalDataPipeImpl::MarkDataAsConsumed(size_t num_bytes) {
438 DCHECK_LE(num_bytes, current_num_bytes_); 439 DCHECK_LE(num_bytes, current_num_bytes_);
439 start_index_ += num_bytes; 440 start_index_ += num_bytes;
440 start_index_ %= capacity_num_bytes(); 441 start_index_ %= capacity_num_bytes();
441 current_num_bytes_ -= num_bytes; 442 current_num_bytes_ -= num_bytes;
442 } 443 }
443 444
444 } // namespace system 445 } // namespace system
445 } // namespace mojo 446 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/edk/system/local_data_pipe_impl.h ('k') | mojo/edk/system/memory.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698