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

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

Issue 1991403002: [battor agent] Fix the init sequence so it retries inits instead of resets. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Cleaned up and ready for a 2nd review Created 4 years, 6 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
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 <iostream>
8
7 #include "base/bind.h" 9 #include "base/bind.h"
8 #include "base/bind_helpers.h" 10 #include "base/bind_helpers.h"
9 #include "base/command_line.h" 11 #include "base/command_line.h"
10 #include "base/memory/ptr_util.h" 12 #include "base/memory/ptr_util.h"
11 #include "base/strings/stringprintf.h" 13 #include "base/strings/stringprintf.h"
12 #include "base/threading/thread_task_runner_handle.h" 14 #include "base/threading/thread_task_runner_handle.h"
13 #include "device/serial/buffer.h" 15 #include "device/serial/buffer.h"
14 #include "device/serial/serial_io_handler.h" 16 #include "device/serial/serial_io_handler.h"
15 #include "net/base/io_buffer.h" 17 #include "net/base/io_buffer.h"
16 #include "tools/battor_agent/serial_utils.h" 18 #include "tools/battor_agent/serial_utils.h"
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 "the 'already read' buffer had an irrecoverable error with code: %d.", 176 "the 'already read' buffer had an irrecoverable error with code: %d.",
175 parse_message_error)); 177 parse_message_error));
176 EndReadBytes(false, BATTOR_MESSAGE_TYPE_CONTROL, nullptr); 178 EndReadBytes(false, BATTOR_MESSAGE_TYPE_CONTROL, nullptr);
177 return; 179 return;
178 } 180 }
179 181
180 LogSerial("No complete message found in the 'already read' buffer."); 182 LogSerial("No complete message found in the 'already read' buffer.");
181 BeginReadBytes(message_max_bytes - already_read_buffer_.size()); 183 BeginReadBytes(message_max_bytes - already_read_buffer_.size());
182 } 184 }
183 185
186 void BattOrConnectionImpl::CancelReadMessage() {
187 io_handler_->CancelRead(device::serial::ReceiveError::TIMEOUT);
188 }
189
184 void BattOrConnectionImpl::Flush() { 190 void BattOrConnectionImpl::Flush() {
185 io_handler_->Flush(); 191 io_handler_->Flush();
186 already_read_buffer_.clear(); 192 already_read_buffer_.clear();
187 } 193 }
188 194
189 scoped_refptr<device::SerialIoHandler> BattOrConnectionImpl::CreateIoHandler() { 195 scoped_refptr<device::SerialIoHandler> BattOrConnectionImpl::CreateIoHandler() {
190 return device::SerialIoHandler::Create(file_thread_task_runner_, 196 return device::SerialIoHandler::Create(file_thread_task_runner_,
191 ui_thread_task_runner_); 197 ui_thread_task_runner_);
192 } 198 }
193 199
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
340 base::ThreadTaskRunnerHandle::Get()->PostTask( 346 base::ThreadTaskRunnerHandle::Get()->PostTask(
341 FROM_HERE, 347 FROM_HERE,
342 base::Bind(&Listener::OnBytesSent, base::Unretained(listener_), success)); 348 base::Bind(&Listener::OnBytesSent, base::Unretained(listener_), success));
343 } 349 }
344 350
345 void BattOrConnectionImpl::LogSerial(const std::string& str) { 351 void BattOrConnectionImpl::LogSerial(const std::string& str) {
346 serial_log_ << str << std::endl << std::endl; 352 serial_log_ << str << std::endl << std::endl;
347 } 353 }
348 354
349 } // namespace battor 355 } // namespace battor
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698