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

Side by Side Diff: device/serial/data_source_sender.cc

Issue 1874313002: Convert device to std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 4 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
« no previous file with comments | « device/serial/data_source_sender.h ('k') | device/serial/data_source_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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "device/serial/data_source_sender.h" 5 #include "device/serial/data_source_sender.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <limits> 8 #include <limits>
9 #include <memory>
9 #include <utility> 10 #include <utility>
10 11
11 #include "base/bind.h" 12 #include "base/bind.h"
12 #include "base/message_loop/message_loop.h" 13 #include "base/message_loop/message_loop.h"
13 14
14 namespace device { 15 namespace device {
15 16
16 // Represents a send that is not yet fulfilled. 17 // Represents a send that is not yet fulfilled.
17 class DataSourceSender::PendingSend { 18 class DataSourceSender::PendingSend {
18 public: 19 public:
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 DataSourceSender::PendingSend::PendingSend(DataSourceSender* sender, 180 DataSourceSender::PendingSend::PendingSend(DataSourceSender* sender,
180 const ReadyCallback& callback) 181 const ReadyCallback& callback)
181 : sender_(sender), callback_(callback), buffer_in_use_(false) { 182 : sender_(sender), callback_(callback), buffer_in_use_(false) {
182 } 183 }
183 184
184 void DataSourceSender::PendingSend::GetData(uint32_t num_bytes) { 185 void DataSourceSender::PendingSend::GetData(uint32_t num_bytes) {
185 DCHECK(num_bytes); 186 DCHECK(num_bytes);
186 DCHECK(!buffer_in_use_); 187 DCHECK(!buffer_in_use_);
187 buffer_in_use_ = true; 188 buffer_in_use_ = true;
188 data_.resize(num_bytes); 189 data_.resize(num_bytes);
189 callback_.Run(scoped_ptr<WritableBuffer>( 190 callback_.Run(std::unique_ptr<WritableBuffer>(
190 new Buffer(sender_, this, &data_[0], num_bytes))); 191 new Buffer(sender_, this, &data_[0], num_bytes)));
191 } 192 }
192 193
193 void DataSourceSender::PendingSend::Done(uint32_t bytes_written) { 194 void DataSourceSender::PendingSend::Done(uint32_t bytes_written) {
194 DCHECK(buffer_in_use_); 195 DCHECK(buffer_in_use_);
195 DCHECK_LE(bytes_written, data_.size()); 196 DCHECK_LE(bytes_written, data_.size());
196 buffer_in_use_ = false; 197 buffer_in_use_ = false;
197 data_.resize(bytes_written); 198 data_.resize(bytes_written);
198 sender_->Done(data_); 199 sender_->Done(data_);
199 } 200 }
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
243 uint32_t bytes_written, 244 uint32_t bytes_written,
244 int32_t error) { 245 int32_t error) {
245 DCHECK(sender_.get()); 246 DCHECK(sender_.get());
246 PendingSend* send = pending_send_; 247 PendingSend* send = pending_send_;
247 pending_send_ = nullptr; 248 pending_send_ = nullptr;
248 send->DoneWithError(bytes_written, error); 249 send->DoneWithError(bytes_written, error);
249 sender_ = nullptr; 250 sender_ = nullptr;
250 } 251 }
251 252
252 } // namespace device 253 } // namespace device
OLDNEW
« no previous file with comments | « device/serial/data_source_sender.h ('k') | device/serial/data_source_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698