Commit b6153be7 authored by David Bokan's avatar David Bokan Committed by Chromium LUCI CQ

Make serial api timeout callbacks to OnceCallback

These callbacks are only called from PostDelayedTask which calls them
once. They're always reset to a new callback before posting a new task.

Bug: 1152268
Change-Id: I5a04f6227d963982ad2f368eb9d9591668e49f35
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2600031Reviewed-by: default avatarKaran Bhatia <karandeepb@chromium.org>
Commit-Queue: David Bokan <bokan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#839120}
parent 6a822e69
...@@ -416,7 +416,7 @@ bool SerialConnection::Send(const std::vector<uint8_t>& data, ...@@ -416,7 +416,7 @@ bool SerialConnection::Send(const std::vector<uint8_t>& data,
send_timeout_task_.Cancel(); send_timeout_task_.Cancel();
if (send_timeout_ > 0) { if (send_timeout_ > 0) {
send_timeout_task_.Reset(base::Bind(&SerialConnection::OnSendTimeout, send_timeout_task_.Reset(base::BindOnce(&SerialConnection::OnSendTimeout,
weak_factory_.GetWeakPtr())); weak_factory_.GetWeakPtr()));
base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
FROM_HERE, send_timeout_task_.callback(), FROM_HERE, send_timeout_task_.callback(),
...@@ -527,8 +527,8 @@ void SerialConnection::InitSerialPortForTesting() { ...@@ -527,8 +527,8 @@ void SerialConnection::InitSerialPortForTesting() {
void SerialConnection::SetTimeoutCallback() { void SerialConnection::SetTimeoutCallback() {
if (receive_timeout_ > 0) { if (receive_timeout_ > 0) {
receive_timeout_task_.Reset(base::Bind(&SerialConnection::OnReceiveTimeout, receive_timeout_task_.Reset(base::BindOnce(
weak_factory_.GetWeakPtr())); &SerialConnection::OnReceiveTimeout, weak_factory_.GetWeakPtr()));
base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
FROM_HERE, receive_timeout_task_.callback(), FROM_HERE, receive_timeout_task_.callback(),
base::TimeDelta::FromMilliseconds(receive_timeout_)); base::TimeDelta::FromMilliseconds(receive_timeout_));
......
...@@ -225,11 +225,11 @@ class SerialConnection : public ApiResource, ...@@ -225,11 +225,11 @@ class SerialConnection : public ApiResource,
// Closure which will trigger a receive timeout unless cancelled. Reset on // Closure which will trigger a receive timeout unless cancelled. Reset on
// initialization and after every successful Receive(). // initialization and after every successful Receive().
base::CancelableClosure receive_timeout_task_; base::CancelableOnceClosure receive_timeout_task_;
// Write timeout closure. Reset on initialization and after every successful // Write timeout closure. Reset on initialization and after every successful
// Send(). // Send().
base::CancelableClosure send_timeout_task_; base::CancelableOnceClosure send_timeout_task_;
// Mojo interface remote corresponding with remote asynchronous I/O handler. // Mojo interface remote corresponding with remote asynchronous I/O handler.
mojo::Remote<device::mojom::SerialPort> serial_port_; mojo::Remote<device::mojom::SerialPort> serial_port_;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment