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

Side by Side Diff: device/serial/serial_io_handler.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/serial_io_handler.h ('k') | device/serial/serial_io_handler_win.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 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/serial_io_handler.h" 5 #include "device/serial/serial_io_handler.h"
6 6
7 #include <memory>
7 #include <utility> 8 #include <utility>
8 9
9 #include "base/bind.h" 10 #include "base/bind.h"
10 #include "base/files/file_path.h" 11 #include "base/files/file_path.h"
11 #include "base/message_loop/message_loop.h" 12 #include "base/message_loop/message_loop.h"
12 #include "base/strings/string_util.h" 13 #include "base/strings/string_util.h"
13 #include "build/build_config.h" 14 #include "build/build_config.h"
14 15
15 #if defined(OS_CHROMEOS) 16 #if defined(OS_CHROMEOS)
16 #include "chromeos/dbus/dbus_thread_manager.h" 17 #include "chromeos/dbus/dbus_thread_manager.h"
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
191 FROM_HERE, 192 FROM_HERE,
192 base::Bind(&SerialIoHandler::DoClose, Passed(std::move(file_)))); 193 base::Bind(&SerialIoHandler::DoClose, Passed(std::move(file_))));
193 } 194 }
194 } 195 }
195 196
196 // static 197 // static
197 void SerialIoHandler::DoClose(base::File port) { 198 void SerialIoHandler::DoClose(base::File port) {
198 // port closed by destructor. 199 // port closed by destructor.
199 } 200 }
200 201
201 void SerialIoHandler::Read(scoped_ptr<WritableBuffer> buffer) { 202 void SerialIoHandler::Read(std::unique_ptr<WritableBuffer> buffer) {
202 DCHECK(CalledOnValidThread()); 203 DCHECK(CalledOnValidThread());
203 DCHECK(!IsReadPending()); 204 DCHECK(!IsReadPending());
204 pending_read_buffer_ = std::move(buffer); 205 pending_read_buffer_ = std::move(buffer);
205 read_canceled_ = false; 206 read_canceled_ = false;
206 AddRef(); 207 AddRef();
207 ReadImpl(); 208 ReadImpl();
208 } 209 }
209 210
210 void SerialIoHandler::Write(scoped_ptr<ReadOnlyBuffer> buffer) { 211 void SerialIoHandler::Write(std::unique_ptr<ReadOnlyBuffer> buffer) {
211 DCHECK(CalledOnValidThread()); 212 DCHECK(CalledOnValidThread());
212 DCHECK(!IsWritePending()); 213 DCHECK(!IsWritePending());
213 pending_write_buffer_ = std::move(buffer); 214 pending_write_buffer_ = std::move(buffer);
214 write_canceled_ = false; 215 write_canceled_ = false;
215 AddRef(); 216 AddRef();
216 WriteImpl(); 217 WriteImpl();
217 } 218 }
218 219
219 void SerialIoHandler::ReadCompleted(int bytes_read, 220 void SerialIoHandler::ReadCompleted(int bytes_read,
220 serial::ReceiveError error) { 221 serial::ReceiveError error) {
221 DCHECK(CalledOnValidThread()); 222 DCHECK(CalledOnValidThread());
222 DCHECK(IsReadPending()); 223 DCHECK(IsReadPending());
223 scoped_ptr<WritableBuffer> pending_read_buffer = 224 std::unique_ptr<WritableBuffer> pending_read_buffer =
224 std::move(pending_read_buffer_); 225 std::move(pending_read_buffer_);
225 if (error == serial::ReceiveError::NONE) { 226 if (error == serial::ReceiveError::NONE) {
226 pending_read_buffer->Done(bytes_read); 227 pending_read_buffer->Done(bytes_read);
227 } else { 228 } else {
228 pending_read_buffer->DoneWithError(bytes_read, static_cast<int32_t>(error)); 229 pending_read_buffer->DoneWithError(bytes_read, static_cast<int32_t>(error));
229 } 230 }
230 Release(); 231 Release();
231 } 232 }
232 233
233 void SerialIoHandler::WriteCompleted(int bytes_written, 234 void SerialIoHandler::WriteCompleted(int bytes_written,
234 serial::SendError error) { 235 serial::SendError error) {
235 DCHECK(CalledOnValidThread()); 236 DCHECK(CalledOnValidThread());
236 DCHECK(IsWritePending()); 237 DCHECK(IsWritePending());
237 scoped_ptr<ReadOnlyBuffer> pending_write_buffer = 238 std::unique_ptr<ReadOnlyBuffer> pending_write_buffer =
238 std::move(pending_write_buffer_); 239 std::move(pending_write_buffer_);
239 if (error == serial::SendError::NONE) { 240 if (error == serial::SendError::NONE) {
240 pending_write_buffer->Done(bytes_written); 241 pending_write_buffer->Done(bytes_written);
241 } else { 242 } else {
242 pending_write_buffer->DoneWithError(bytes_written, 243 pending_write_buffer->DoneWithError(bytes_written,
243 static_cast<int32_t>(error)); 244 static_cast<int32_t>(error));
244 } 245 }
245 Release(); 246 Release();
246 } 247 }
247 248
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
286 } 287 }
287 288
288 void SerialIoHandler::QueueWriteCompleted(int bytes_written, 289 void SerialIoHandler::QueueWriteCompleted(int bytes_written,
289 serial::SendError error) { 290 serial::SendError error) {
290 base::MessageLoop::current()->PostTask( 291 base::MessageLoop::current()->PostTask(
291 FROM_HERE, 292 FROM_HERE,
292 base::Bind(&SerialIoHandler::WriteCompleted, this, bytes_written, error)); 293 base::Bind(&SerialIoHandler::WriteCompleted, this, bytes_written, error));
293 } 294 }
294 295
295 } // namespace device 296 } // namespace device
OLDNEW
« no previous file with comments | « device/serial/serial_io_handler.h ('k') | device/serial/serial_io_handler_win.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698