OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "components/pairing/bluetooth_host_pairing_controller.h" | 5 #include "components/pairing/bluetooth_host_pairing_controller.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/hash.h" | 8 #include "base/hash.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
11 #include "chromeos/system/devicetype.h" | 11 #include "chromeos/system/devicetype.h" |
12 #include "components/pairing/bluetooth_pairing_constants.h" | 12 #include "components/pairing/bluetooth_pairing_constants.h" |
13 #include "components/pairing/pairing_api.pb.h" | 13 #include "components/pairing/pairing_api.pb.h" |
14 #include "components/pairing/proto_decoder.h" | 14 #include "components/pairing/proto_decoder.h" |
15 #include "content/public/browser/browser_thread.h" | |
15 #include "device/bluetooth/bluetooth_adapter_factory.h" | 16 #include "device/bluetooth/bluetooth_adapter_factory.h" |
16 #include "net/base/io_buffer.h" | 17 #include "net/base/io_buffer.h" |
17 | 18 |
18 namespace pairing_chromeos { | 19 namespace pairing_chromeos { |
19 | 20 |
20 namespace { | 21 namespace { |
21 const int kReceiveSize = 16384; | 22 const int kReceiveSize = 16384; |
22 | 23 |
23 std::string GetChromeOSDeviceType() { | 24 std::string GetChromeOSDeviceType() { |
24 switch (chromeos::GetDeviceType()) { | 25 switch (chromeos::GetDeviceType()) { |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
81 case HostPairingController::ENROLLMENT_STATUS_FAILURE: | 82 case HostPairingController::ENROLLMENT_STATUS_FAILURE: |
82 return pairing_api::HostStatusParameters::ENROLLMENT_STATUS_FAILURE; | 83 return pairing_api::HostStatusParameters::ENROLLMENT_STATUS_FAILURE; |
83 case HostPairingController::ENROLLMENT_STATUS_SUCCESS: | 84 case HostPairingController::ENROLLMENT_STATUS_SUCCESS: |
84 return pairing_api::HostStatusParameters::ENROLLMENT_STATUS_SUCCESS; | 85 return pairing_api::HostStatusParameters::ENROLLMENT_STATUS_SUCCESS; |
85 default: | 86 default: |
86 NOTREACHED(); | 87 NOTREACHED(); |
87 return pairing_api::HostStatusParameters::ENROLLMENT_STATUS_UNKNOWN; | 88 return pairing_api::HostStatusParameters::ENROLLMENT_STATUS_UNKNOWN; |
88 } | 89 } |
89 } | 90 } |
90 | 91 |
92 std::vector<BluetoothHostPairingController::InputDeviceInfo> GetDevices() { | |
93 std::vector<BluetoothHostPairingController::InputDeviceInfo> devices; | |
94 if (device::InputServiceLinux::HasInstance()) | |
95 device::InputServiceLinux::GetInstance()->GetDevices(&devices); | |
96 return devices; | |
97 } | |
98 | |
91 } // namespace | 99 } // namespace |
92 | 100 |
93 BluetoothHostPairingController::BluetoothHostPairingController() | 101 BluetoothHostPairingController::BluetoothHostPairingController() |
94 : current_stage_(STAGE_NONE), | 102 : current_stage_(STAGE_NONE), |
95 connectivity_status_(CONNECTIVITY_UNTESTED), | 103 connectivity_status_(CONNECTIVITY_UNTESTED), |
96 update_status_(UPDATE_STATUS_UNKNOWN), | 104 update_status_(UPDATE_STATUS_UNKNOWN), |
97 enrollment_status_(ENROLLMENT_STATUS_UNKNOWN), | 105 enrollment_status_(ENROLLMENT_STATUS_UNKNOWN), |
98 proto_decoder_(new ProtoDecoder(this)), | 106 proto_decoder_(new ProtoDecoder(this)), |
99 ptr_factory_(this) {} | 107 ptr_factory_(this) {} |
100 | 108 |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
151 if (service_socket_.get()) { | 159 if (service_socket_.get()) { |
152 service_socket_->Close(); | 160 service_socket_->Close(); |
153 service_socket_ = NULL; | 161 service_socket_ = NULL; |
154 } | 162 } |
155 | 163 |
156 if (adapter_.get()) { | 164 if (adapter_.get()) { |
157 if (adapter_->IsDiscoverable()) { | 165 if (adapter_->IsDiscoverable()) { |
158 adapter_->SetDiscoverable(false, base::Bind(&base::DoNothing), | 166 adapter_->SetDiscoverable(false, base::Bind(&base::DoNothing), |
159 base::Bind(&base::DoNothing)); | 167 base::Bind(&base::DoNothing)); |
160 } | 168 } |
161 if (!was_powered_) { | 169 |
162 adapter_->SetPowered(false, base::Bind(&base::DoNothing), | 170 content::BrowserThread::PostTaskAndReplyWithResult( |
163 base::Bind(&base::DoNothing)); | 171 content::BrowserThread::FILE, FROM_HERE, base::Bind(&GetDevices), |
achuithb
2016/05/02 23:02:40
BrowserThread::FILE is deprecated, please use Bloc
xdai1
2016/05/03 00:30:26
I'm not sure I should do that.. In https://code.go
| |
164 } | 172 base::Bind(&BluetoothHostPairingController::PowerOffAdapterIfApplicable, |
165 adapter_->RemoveObserver(this); | 173 ptr_factory_.GetWeakPtr())); |
166 adapter_ = NULL; | |
167 } | 174 } |
168 ChangeStage(STAGE_NONE); | 175 ChangeStage(STAGE_NONE); |
169 } | 176 } |
170 | 177 |
171 void BluetoothHostPairingController::OnGetAdapter( | 178 void BluetoothHostPairingController::OnGetAdapter( |
172 scoped_refptr<device::BluetoothAdapter> adapter) { | 179 scoped_refptr<device::BluetoothAdapter> adapter) { |
173 DCHECK(thread_checker_.CalledOnValidThread()); | 180 DCHECK(thread_checker_.CalledOnValidThread()); |
174 DCHECK(!adapter_.get()); | 181 DCHECK(!adapter_.get()); |
175 adapter_ = adapter; | 182 adapter_ = adapter; |
176 | 183 |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
315 | 322 |
316 void BluetoothHostPairingController::OnSendError( | 323 void BluetoothHostPairingController::OnSendError( |
317 const std::string& error_message) { | 324 const std::string& error_message) { |
318 LOG(ERROR) << error_message; | 325 LOG(ERROR) << error_message; |
319 if (enrollment_status_ != ENROLLMENT_STATUS_ENROLLING && | 326 if (enrollment_status_ != ENROLLMENT_STATUS_ENROLLING && |
320 enrollment_status_ != ENROLLMENT_STATUS_SUCCESS) { | 327 enrollment_status_ != ENROLLMENT_STATUS_SUCCESS) { |
321 ChangeStage(STAGE_CONTROLLER_CONNECTION_ERROR); | 328 ChangeStage(STAGE_CONTROLLER_CONNECTION_ERROR); |
322 } | 329 } |
323 } | 330 } |
324 | 331 |
332 void BluetoothHostPairingController::PowerOffAdapterIfApplicable( | |
333 const std::vector<InputDeviceInfo>& devices) { | |
334 bool use_bluetooth = false; | |
335 for (auto& iter : devices) { | |
achuithb
2016/05/02 23:02:40
const auto& device
The iterator should be const,
xdai1
2016/05/03 00:30:26
Done.
| |
336 if (iter.type == InputDeviceInfo::TYPE_BLUETOOTH) { | |
337 use_bluetooth = true; | |
338 break; | |
339 } | |
340 } | |
341 if (!was_powered_ && !use_bluetooth) { | |
342 adapter_->SetPowered(false, base::Bind(&base::DoNothing), | |
343 base::Bind(&base::DoNothing)); | |
344 } | |
345 adapter_->RemoveObserver(this); | |
346 adapter_ = NULL; | |
achuithb
2016/05/02 23:02:40
nullptr here and everywhere in this file please
xdai1
2016/05/03 00:30:26
Done.
| |
347 } | |
348 | |
325 void BluetoothHostPairingController::OnReceiveError( | 349 void BluetoothHostPairingController::OnReceiveError( |
326 device::BluetoothSocket::ErrorReason reason, | 350 device::BluetoothSocket::ErrorReason reason, |
327 const std::string& error_message) { | 351 const std::string& error_message) { |
328 LOG(ERROR) << reason << ", " << error_message; | 352 LOG(ERROR) << reason << ", " << error_message; |
329 ChangeStage(STAGE_CONTROLLER_CONNECTION_ERROR); | 353 ChangeStage(STAGE_CONTROLLER_CONNECTION_ERROR); |
330 } | 354 } |
331 | 355 |
332 void BluetoothHostPairingController::OnHostStatusMessage( | 356 void BluetoothHostPairingController::OnHostStatusMessage( |
333 const pairing_api::HostStatus& message) { | 357 const pairing_api::HostStatus& message) { |
334 NOTREACHED(); | 358 NOTREACHED(); |
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
510 ChangeStage(STAGE_WAITING_FOR_CODE_CONFIRMATION); | 534 ChangeStage(STAGE_WAITING_FOR_CODE_CONFIRMATION); |
511 } | 535 } |
512 | 536 |
513 void BluetoothHostPairingController::AuthorizePairing( | 537 void BluetoothHostPairingController::AuthorizePairing( |
514 device::BluetoothDevice* device) { | 538 device::BluetoothDevice* device) { |
515 // Disallow unknown device. | 539 // Disallow unknown device. |
516 device->RejectPairing(); | 540 device->RejectPairing(); |
517 } | 541 } |
518 | 542 |
519 } // namespace pairing_chromeos | 543 } // namespace pairing_chromeos |
OLD | NEW |