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

Side by Side Diff: chromeos/components/tether/keep_alive_operation.cc

Issue 2918863002: [CrOS Tether] Update the KeepAliveTickle code to receive DeviceStatus updates. (Closed)
Patch Set: hansberry@ comments. Created 3 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 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 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 "chromeos/components/tether/keep_alive_operation.h" 5 #include "chromeos/components/tether/keep_alive_operation.h"
6 6
7 #include "chromeos/components/tether/message_wrapper.h" 7 #include "chromeos/components/tether/message_wrapper.h"
8 #include "chromeos/components/tether/proto/tether.pb.h" 8 #include "chromeos/components/tether/proto/tether.pb.h"
9 #include "components/proximity_auth/logging/logging.h" 9 #include "components/proximity_auth/logging/logging.h"
10 10
(...skipping 26 matching lines...) Expand all
37 BleConnectionManager* connection_manager) { 37 BleConnectionManager* connection_manager) {
38 return base::MakeUnique<KeepAliveOperation>(device_to_connect, 38 return base::MakeUnique<KeepAliveOperation>(device_to_connect,
39 connection_manager); 39 connection_manager);
40 } 40 }
41 41
42 KeepAliveOperation::KeepAliveOperation( 42 KeepAliveOperation::KeepAliveOperation(
43 const cryptauth::RemoteDevice& device_to_connect, 43 const cryptauth::RemoteDevice& device_to_connect,
44 BleConnectionManager* connection_manager) 44 BleConnectionManager* connection_manager)
45 : MessageTransferOperation( 45 : MessageTransferOperation(
46 std::vector<cryptauth::RemoteDevice>{device_to_connect}, 46 std::vector<cryptauth::RemoteDevice>{device_to_connect},
47 connection_manager) {} 47 connection_manager),
48 remote_device_(device_to_connect) {}
48 49
49 KeepAliveOperation::~KeepAliveOperation() {} 50 KeepAliveOperation::~KeepAliveOperation() {}
50 51
51 void KeepAliveOperation::AddObserver(Observer* observer) { 52 void KeepAliveOperation::AddObserver(Observer* observer) {
52 observer_list_.AddObserver(observer); 53 observer_list_.AddObserver(observer);
53 } 54 }
54 55
55 void KeepAliveOperation::RemoveObserver(Observer* observer) { 56 void KeepAliveOperation::RemoveObserver(Observer* observer) {
56 observer_list_.RemoveObserver(observer); 57 observer_list_.RemoveObserver(observer);
57 } 58 }
58 59
59 void KeepAliveOperation::OnDeviceAuthenticated( 60 void KeepAliveOperation::OnDeviceAuthenticated(
60 const cryptauth::RemoteDevice& remote_device) { 61 const cryptauth::RemoteDevice& remote_device) {
61 DCHECK(remote_devices().size() == 1u && remote_devices()[0] == remote_device); 62 DCHECK(remote_devices().size() == 1u && remote_devices()[0] == remote_device);
62 63
63 SendMessageToDevice(remote_device, 64 SendMessageToDevice(remote_device,
64 base::MakeUnique<MessageWrapper>(KeepAliveTickle())); 65 base::MakeUnique<MessageWrapper>(KeepAliveTickle()));
66 }
67
68 void KeepAliveOperation::OnMessageReceived(
69 std::unique_ptr<MessageWrapper> message_wrapper,
70 const cryptauth::RemoteDevice& remote_device) {
71 if (message_wrapper->GetMessageType() !=
72 MessageType::KEEP_ALIVE_TICKLE_RESPONSE) {
73 // If another type of message has been received, ignore it.
74 return;
75 }
76
77 if (!(remote_device == remote_device_)) {
78 // If the message came from another device, ignore it.
79 return;
80 }
81
82 KeepAliveTickleResponse* response =
83 static_cast<KeepAliveTickleResponse*>(message_wrapper->GetProto().get());
84 device_status_ = base::MakeUnique<DeviceStatus>(response->device_status());
85
86 // Now that a response has been received, the device can be unregistered.
65 UnregisterDevice(remote_device); 87 UnregisterDevice(remote_device);
66 } 88 }
67 89
68 void KeepAliveOperation::OnOperationFinished() { 90 void KeepAliveOperation::OnOperationFinished() {
69 for (auto& observer : observer_list_) { 91 for (auto& observer : observer_list_) {
70 observer.OnOperationFinished(); 92 // Note: If the operation did not complete successfully, |device_status_|
93 // will still be null.
94 observer.OnOperationFinished(
95 remote_device_, device_status_
96 ? base::MakeUnique<DeviceStatus>(*device_status_)
97 : nullptr);
71 } 98 }
72 } 99 }
73 100
74 MessageType KeepAliveOperation::GetMessageTypeForConnection() { 101 MessageType KeepAliveOperation::GetMessageTypeForConnection() {
75 return MessageType::KEEP_ALIVE_TICKLE; 102 return MessageType::KEEP_ALIVE_TICKLE;
76 } 103 }
77 104
78 } // namespace tether 105 } // namespace tether
79 106
80 } // namespace chromeos 107 } // namespace chromeos
OLDNEW
« no previous file with comments | « chromeos/components/tether/keep_alive_operation.h ('k') | chromeos/components/tether/keep_alive_operation_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698