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

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

Issue 2844973002: [CrOS Tether] Create TetherHostResponseRecorder, which records ConnectTetheringResponses and Tether… (Closed)
Patch Set: Changed "Connectable" wording to "Connected". 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 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/host_scanner_operation.h" 5 #include "chromeos/components/tether/host_scanner_operation.h"
6 6
7 #include "chromeos/components/tether/host_scan_device_prioritizer.h" 7 #include "chromeos/components/tether/host_scan_device_prioritizer.h"
8 #include "chromeos/components/tether/message_wrapper.h" 8 #include "chromeos/components/tether/message_wrapper.h"
9 #include "chromeos/components/tether/proto/tether.pb.h" 9 #include "chromeos/components/tether/proto/tether.pb.h"
10 #include "chromeos/components/tether/tether_host_response_recorder.h"
10 #include "components/proximity_auth/logging/logging.h" 11 #include "components/proximity_auth/logging/logging.h"
11 12
12 namespace chromeos { 13 namespace chromeos {
13 14
14 namespace tether { 15 namespace tether {
15 16
16 namespace { 17 namespace {
17 18
18 std::vector<cryptauth::RemoteDevice> PrioritizeDevices( 19 std::vector<cryptauth::RemoteDevice> PrioritizeDevices(
19 const std::vector<cryptauth::RemoteDevice>& devices_to_connect, 20 const std::vector<cryptauth::RemoteDevice>& devices_to_connect,
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 58
58 // static 59 // static
59 HostScannerOperation::Factory* 60 HostScannerOperation::Factory*
60 HostScannerOperation::Factory::factory_instance_ = nullptr; 61 HostScannerOperation::Factory::factory_instance_ = nullptr;
61 62
62 // static 63 // static
63 std::unique_ptr<HostScannerOperation> 64 std::unique_ptr<HostScannerOperation>
64 HostScannerOperation::Factory::NewInstance( 65 HostScannerOperation::Factory::NewInstance(
65 const std::vector<cryptauth::RemoteDevice>& devices_to_connect, 66 const std::vector<cryptauth::RemoteDevice>& devices_to_connect,
66 BleConnectionManager* connection_manager, 67 BleConnectionManager* connection_manager,
67 HostScanDevicePrioritizer* host_scan_device_prioritizer) { 68 HostScanDevicePrioritizer* host_scan_device_prioritizer,
69 TetherHostResponseRecorder* tether_host_response_recorder) {
68 if (!factory_instance_) { 70 if (!factory_instance_) {
69 factory_instance_ = new Factory(); 71 factory_instance_ = new Factory();
70 } 72 }
71 return factory_instance_->BuildInstance( 73 return factory_instance_->BuildInstance(
72 devices_to_connect, connection_manager, host_scan_device_prioritizer); 74 devices_to_connect, connection_manager, host_scan_device_prioritizer,
75 tether_host_response_recorder);
73 } 76 }
74 77
75 // static 78 // static
76 void HostScannerOperation::Factory::SetInstanceForTesting(Factory* factory) { 79 void HostScannerOperation::Factory::SetInstanceForTesting(Factory* factory) {
77 factory_instance_ = factory; 80 factory_instance_ = factory;
78 } 81 }
79 82
80 std::unique_ptr<HostScannerOperation> 83 std::unique_ptr<HostScannerOperation>
81 HostScannerOperation::Factory::BuildInstance( 84 HostScannerOperation::Factory::BuildInstance(
82 const std::vector<cryptauth::RemoteDevice>& devices_to_connect, 85 const std::vector<cryptauth::RemoteDevice>& devices_to_connect,
83 BleConnectionManager* connection_manager, 86 BleConnectionManager* connection_manager,
84 HostScanDevicePrioritizer* host_scan_device_prioritizer) { 87 HostScanDevicePrioritizer* host_scan_device_prioritizer,
88 TetherHostResponseRecorder* tether_host_response_recorder) {
85 return base::MakeUnique<HostScannerOperation>( 89 return base::MakeUnique<HostScannerOperation>(
86 devices_to_connect, connection_manager, host_scan_device_prioritizer); 90 devices_to_connect, connection_manager, host_scan_device_prioritizer,
91 tether_host_response_recorder);
87 } 92 }
88 93
89 HostScannerOperation::ScannedDeviceInfo::ScannedDeviceInfo( 94 HostScannerOperation::ScannedDeviceInfo::ScannedDeviceInfo(
90 const cryptauth::RemoteDevice& remote_device, 95 const cryptauth::RemoteDevice& remote_device,
91 const DeviceStatus& device_status, 96 const DeviceStatus& device_status,
92 bool set_up_required) 97 bool set_up_required)
93 : remote_device(remote_device), 98 : remote_device(remote_device),
94 device_status(device_status), 99 device_status(device_status),
95 set_up_required(set_up_required) {} 100 set_up_required(set_up_required) {}
96 101
97 HostScannerOperation::ScannedDeviceInfo::~ScannedDeviceInfo() {} 102 HostScannerOperation::ScannedDeviceInfo::~ScannedDeviceInfo() {}
98 103
99 bool operator==(const HostScannerOperation::ScannedDeviceInfo& first, 104 bool operator==(const HostScannerOperation::ScannedDeviceInfo& first,
100 const HostScannerOperation::ScannedDeviceInfo& second) { 105 const HostScannerOperation::ScannedDeviceInfo& second) {
101 return first.remote_device == second.remote_device && 106 return first.remote_device == second.remote_device &&
102 first.device_status.SerializeAsString() == 107 first.device_status.SerializeAsString() ==
103 second.device_status.SerializeAsString() && 108 second.device_status.SerializeAsString() &&
104 first.set_up_required == second.set_up_required; 109 first.set_up_required == second.set_up_required;
105 } 110 }
106 111
107 HostScannerOperation::HostScannerOperation( 112 HostScannerOperation::HostScannerOperation(
108 const std::vector<cryptauth::RemoteDevice>& devices_to_connect, 113 const std::vector<cryptauth::RemoteDevice>& devices_to_connect,
109 BleConnectionManager* connection_manager, 114 BleConnectionManager* connection_manager,
110 HostScanDevicePrioritizer* host_scan_device_prioritizer) 115 HostScanDevicePrioritizer* host_scan_device_prioritizer,
116 TetherHostResponseRecorder* tether_host_response_recorder)
111 : MessageTransferOperation( 117 : MessageTransferOperation(
112 PrioritizeDevices(devices_to_connect, host_scan_device_prioritizer), 118 PrioritizeDevices(devices_to_connect, host_scan_device_prioritizer),
113 connection_manager), 119 connection_manager),
114 host_scan_device_prioritizer_(host_scan_device_prioritizer) {} 120 tether_host_response_recorder_(tether_host_response_recorder) {}
115 121
116 HostScannerOperation::~HostScannerOperation() {} 122 HostScannerOperation::~HostScannerOperation() {}
117 123
118 void HostScannerOperation::AddObserver(Observer* observer) { 124 void HostScannerOperation::AddObserver(Observer* observer) {
119 observer_list_.AddObserver(observer); 125 observer_list_.AddObserver(observer);
120 } 126 }
121 127
122 void HostScannerOperation::RemoveObserver(Observer* observer) { 128 void HostScannerOperation::RemoveObserver(Observer* observer) {
123 observer_list_.RemoveObserver(observer); 129 observer_list_.RemoveObserver(observer);
124 } 130 }
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 bool set_up_required = 165 bool set_up_required =
160 response->response_code() == 166 response->response_code() ==
161 TetherAvailabilityResponse_ResponseCode:: 167 TetherAvailabilityResponse_ResponseCode::
162 TetherAvailabilityResponse_ResponseCode_SETUP_NEEDED; 168 TetherAvailabilityResponse_ResponseCode_SETUP_NEEDED;
163 169
164 PA_LOG(INFO) << "Received TetherAvailabilityResponse from device with ID " 170 PA_LOG(INFO) << "Received TetherAvailabilityResponse from device with ID "
165 << remote_device.GetTruncatedDeviceIdForLogs() << " which " 171 << remote_device.GetTruncatedDeviceIdForLogs() << " which "
166 << "indicates that tethering is available. set_up_required = " 172 << "indicates that tethering is available. set_up_required = "
167 << set_up_required; 173 << set_up_required;
168 174
169 host_scan_device_prioritizer_->RecordSuccessfulTetherAvailabilityResponse( 175 tether_host_response_recorder_->RecordSuccessfulTetherAvailabilityResponse(
170 remote_device); 176 remote_device);
171 177
172 scanned_device_list_so_far_.push_back(ScannedDeviceInfo( 178 scanned_device_list_so_far_.push_back(ScannedDeviceInfo(
173 remote_device, response->device_status(), set_up_required)); 179 remote_device, response->device_status(), set_up_required));
174 NotifyObserversOfScannedDeviceList(false /* is_final_scan_result */); 180 NotifyObserversOfScannedDeviceList(false /* is_final_scan_result */);
175 } 181 }
176 182
177 // Unregister the device after a TetherAvailabilityResponse has been received. 183 // Unregister the device after a TetherAvailabilityResponse has been received.
178 UnregisterDevice(remote_device); 184 UnregisterDevice(remote_device);
179 } 185 }
(...skipping 10 matching lines...) Expand all
190 NotifyObserversOfScannedDeviceList(true /* is_final_scan_result */); 196 NotifyObserversOfScannedDeviceList(true /* is_final_scan_result */);
191 } 197 }
192 198
193 MessageType HostScannerOperation::GetMessageTypeForConnection() { 199 MessageType HostScannerOperation::GetMessageTypeForConnection() {
194 return MessageType::TETHER_AVAILABILITY_REQUEST; 200 return MessageType::TETHER_AVAILABILITY_REQUEST;
195 } 201 }
196 202
197 } // namespace tether 203 } // namespace tether
198 204
199 } // namespace chromeos 205 } // namespace chromeos
OLDNEW
« no previous file with comments | « chromeos/components/tether/host_scanner_operation.h ('k') | chromeos/components/tether/host_scanner_operation_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698