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

Side by Side Diff: tools/battor_agent/battor_connection_impl.cc

Issue 2254873004: Re-write many calls to WrapUnique() with MakeUnique() (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 4 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 | « no previous file | tools/battor_agent/battor_connection_impl_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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "tools/battor_agent/battor_connection_impl.h" 5 #include "tools/battor_agent/battor_connection_impl.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/memory/ptr_util.h" 10 #include "base/memory/ptr_util.h"
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 } 136 }
137 137
138 data.push_back(bytes[i]); 138 data.push_back(bytes[i]);
139 } 139 }
140 140
141 data.push_back(BATTOR_CONTROL_BYTE_END); 141 data.push_back(BATTOR_CONTROL_BYTE_END);
142 142
143 LogSerial(StringPrintf("Bytes sent: %s.", CharVectorToString(data).c_str())); 143 LogSerial(StringPrintf("Bytes sent: %s.", CharVectorToString(data).c_str()));
144 144
145 pending_write_length_ = data.size(); 145 pending_write_length_ = data.size();
146 io_handler_->Write(base::WrapUnique(new device::SendBuffer( 146 io_handler_->Write(base::MakeUnique<device::SendBuffer>(
147 data, base::Bind(&BattOrConnectionImpl::OnBytesSent, AsWeakPtr())))); 147 data, base::Bind(&BattOrConnectionImpl::OnBytesSent, AsWeakPtr())));
148 } 148 }
149 149
150 void BattOrConnectionImpl::ReadMessage(BattOrMessageType type) { 150 void BattOrConnectionImpl::ReadMessage(BattOrMessageType type) {
151 LogSerial("Read requested."); 151 LogSerial("Read requested.");
152 152
153 pending_read_message_type_ = type; 153 pending_read_message_type_ = type;
154 size_t message_max_bytes = GetMaxBytesForMessageType(type); 154 size_t message_max_bytes = GetMaxBytesForMessageType(type);
155 155
156 LogSerial( 156 LogSerial(
157 "Before doing a serial read, checking to see if we already have a " 157 "Before doing a serial read, checking to see if we already have a "
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 void BattOrConnectionImpl::BeginReadBytes(size_t max_bytes_to_read) { 198 void BattOrConnectionImpl::BeginReadBytes(size_t max_bytes_to_read) {
199 LogSerial( 199 LogSerial(
200 StringPrintf("Starting read of up to %zu bytes.", max_bytes_to_read)); 200 StringPrintf("Starting read of up to %zu bytes.", max_bytes_to_read));
201 201
202 pending_read_buffer_ = 202 pending_read_buffer_ =
203 make_scoped_refptr(new net::IOBuffer(max_bytes_to_read)); 203 make_scoped_refptr(new net::IOBuffer(max_bytes_to_read));
204 204
205 auto on_receive_buffer_filled = 205 auto on_receive_buffer_filled =
206 base::Bind(&BattOrConnectionImpl::OnBytesRead, AsWeakPtr()); 206 base::Bind(&BattOrConnectionImpl::OnBytesRead, AsWeakPtr());
207 207
208 io_handler_->Read(base::WrapUnique(new device::ReceiveBuffer( 208 io_handler_->Read(base::MakeUnique<device::ReceiveBuffer>(
209 pending_read_buffer_, static_cast<uint32_t>(max_bytes_to_read), 209 pending_read_buffer_, static_cast<uint32_t>(max_bytes_to_read),
210 on_receive_buffer_filled))); 210 on_receive_buffer_filled));
211 } 211 }
212 212
213 void BattOrConnectionImpl::OnBytesRead(int bytes_read, 213 void BattOrConnectionImpl::OnBytesRead(int bytes_read,
214 device::serial::ReceiveError error) { 214 device::serial::ReceiveError error) {
215 if (error != device::serial::ReceiveError::NONE) { 215 if (error != device::serial::ReceiveError::NONE) {
216 LogSerial(StringPrintf( 216 LogSerial(StringPrintf(
217 "Read failed due to serial read failure with error code: %d.", 217 "Read failed due to serial read failure with error code: %d.",
218 static_cast<int>(error))); 218 static_cast<int>(error)));
219 EndReadBytes(false, BATTOR_MESSAGE_TYPE_CONTROL, nullptr); 219 EndReadBytes(false, BATTOR_MESSAGE_TYPE_CONTROL, nullptr);
220 return; 220 return;
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
352 base::ThreadTaskRunnerHandle::Get()->PostTask( 352 base::ThreadTaskRunnerHandle::Get()->PostTask(
353 FROM_HERE, 353 FROM_HERE,
354 base::Bind(&Listener::OnBytesSent, base::Unretained(listener_), success)); 354 base::Bind(&Listener::OnBytesSent, base::Unretained(listener_), success));
355 } 355 }
356 356
357 void BattOrConnectionImpl::LogSerial(const std::string& str) { 357 void BattOrConnectionImpl::LogSerial(const std::string& str) {
358 serial_log_ << str << std::endl << std::endl; 358 serial_log_ << str << std::endl << std::endl;
359 } 359 }
360 360
361 } // namespace battor 361 } // namespace battor
OLDNEW
« no previous file with comments | « no previous file | tools/battor_agent/battor_connection_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698