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

Unified Diff: chromeos/components/tether/keep_alive_operation.cc

Issue 2918863002: [CrOS Tether] Update the KeepAliveTickle code to receive DeviceStatus updates. (Closed)
Patch Set: Rebased. Created 3 years, 7 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 side-by-side diff with in-line comments
Download patch
Index: chromeos/components/tether/keep_alive_operation.cc
diff --git a/chromeos/components/tether/keep_alive_operation.cc b/chromeos/components/tether/keep_alive_operation.cc
index dc9d54acbab17bcddeb39cb8650590ecfab240c6..15816e0bba454b78ec8cd9ab90f178a05d622c5a 100644
--- a/chromeos/components/tether/keep_alive_operation.cc
+++ b/chromeos/components/tether/keep_alive_operation.cc
@@ -44,7 +44,8 @@ KeepAliveOperation::KeepAliveOperation(
BleConnectionManager* connection_manager)
: MessageTransferOperation(
std::vector<cryptauth::RemoteDevice>{device_to_connect},
- connection_manager) {}
+ connection_manager),
+ remote_device_(device_to_connect) {}
KeepAliveOperation::~KeepAliveOperation() {}
@@ -62,12 +63,38 @@ void KeepAliveOperation::OnDeviceAuthenticated(
SendMessageToDevice(remote_device,
base::MakeUnique<MessageWrapper>(KeepAliveTickle()));
+}
+
+void KeepAliveOperation::OnMessageReceived(
+ std::unique_ptr<MessageWrapper> message_wrapper,
+ const cryptauth::RemoteDevice& remote_device) {
+ if (message_wrapper->GetMessageType() !=
+ MessageType::KEEP_ALIVE_TICKLE_RESPONSE) {
+ // If another type of message has been received, ignore it.
+ return;
+ }
+
+ if (!(remote_device == remote_device_)) {
+ // If the message came from another device, ignore it.
+ return;
+ }
+
+ KeepAliveTickleResponse* response =
+ static_cast<KeepAliveTickleResponse*>(message_wrapper->GetProto().get());
+ device_status_ = base::MakeUnique<DeviceStatus>(response->device_status());
+
+ // Now that a response has been received, the device can be unregistered.
UnregisterDevice(remote_device);
}
void KeepAliveOperation::OnOperationFinished() {
for (auto& observer : observer_list_) {
- observer.OnOperationFinished();
+ // Note: If the operation did not complete successfully, |device_status_|
+ // will still be null.
+ observer.OnOperationFinished(
+ remote_device_, device_status_
+ ? base::MakeUnique<DeviceStatus>(*device_status_)
+ : nullptr);
}
}

Powered by Google App Engine
This is Rietveld 408576698