| 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" |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 93 BluetoothHostPairingController::BluetoothHostPairingController() | 93 BluetoothHostPairingController::BluetoothHostPairingController() |
| 94 : current_stage_(STAGE_NONE), | 94 : current_stage_(STAGE_NONE), |
| 95 connectivity_status_(CONNECTIVITY_UNTESTED), | 95 connectivity_status_(CONNECTIVITY_UNTESTED), |
| 96 update_status_(UPDATE_STATUS_UNKNOWN), | 96 update_status_(UPDATE_STATUS_UNKNOWN), |
| 97 enrollment_status_(ENROLLMENT_STATUS_UNKNOWN), | 97 enrollment_status_(ENROLLMENT_STATUS_UNKNOWN), |
| 98 proto_decoder_(new ProtoDecoder(this)), | 98 proto_decoder_(new ProtoDecoder(this)), |
| 99 ptr_factory_(this) {} | 99 ptr_factory_(this) {} |
| 100 | 100 |
| 101 BluetoothHostPairingController::~BluetoothHostPairingController() { | 101 BluetoothHostPairingController::~BluetoothHostPairingController() { |
| 102 Reset(); | 102 Reset(); |
| 103 if (adapter_.get()) { |
| 104 if (adapter_->IsDiscoverable()) { |
| 105 adapter_->SetDiscoverable(false, base::Closure(), base::Closure()); |
| 106 } |
| 107 adapter_->RemoveObserver(this); |
| 108 adapter_ = NULL; |
| 109 } |
| 103 } | 110 } |
| 104 | 111 |
| 105 void BluetoothHostPairingController::ChangeStage(Stage new_stage) { | 112 void BluetoothHostPairingController::ChangeStage(Stage new_stage) { |
| 106 if (current_stage_ == new_stage) | 113 if (current_stage_ == new_stage) |
| 107 return; | 114 return; |
| 108 VLOG(1) << "ChangeStage " << new_stage; | 115 VLOG(1) << "ChangeStage " << new_stage; |
| 109 current_stage_ = new_stage; | 116 current_stage_ = new_stage; |
| 110 FOR_EACH_OBSERVER(Observer, observers_, PairingStageChanged(new_stage)); | 117 FOR_EACH_OBSERVER(Observer, observers_, PairingStageChanged(new_stage)); |
| 111 } | 118 } |
| 112 | 119 |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 145 void BluetoothHostPairingController::Reset() { | 152 void BluetoothHostPairingController::Reset() { |
| 146 if (controller_socket_.get()) { | 153 if (controller_socket_.get()) { |
| 147 controller_socket_->Close(); | 154 controller_socket_->Close(); |
| 148 controller_socket_ = NULL; | 155 controller_socket_ = NULL; |
| 149 } | 156 } |
| 150 | 157 |
| 151 if (service_socket_.get()) { | 158 if (service_socket_.get()) { |
| 152 service_socket_->Close(); | 159 service_socket_->Close(); |
| 153 service_socket_ = NULL; | 160 service_socket_ = NULL; |
| 154 } | 161 } |
| 155 | |
| 156 if (adapter_.get()) { | |
| 157 if (adapter_->IsDiscoverable()) { | |
| 158 adapter_->SetDiscoverable(false, base::Bind(&base::DoNothing), | |
| 159 base::Bind(&base::DoNothing)); | |
| 160 } | |
| 161 if (!was_powered_) { | |
| 162 adapter_->SetPowered(false, base::Bind(&base::DoNothing), | |
| 163 base::Bind(&base::DoNothing)); | |
| 164 } | |
| 165 adapter_->RemoveObserver(this); | |
| 166 adapter_ = NULL; | |
| 167 } | |
| 168 ChangeStage(STAGE_NONE); | 162 ChangeStage(STAGE_NONE); |
| 169 } | 163 } |
| 170 | 164 |
| 171 void BluetoothHostPairingController::OnGetAdapter( | 165 void BluetoothHostPairingController::OnGetAdapter( |
| 172 scoped_refptr<device::BluetoothAdapter> adapter) { | 166 scoped_refptr<device::BluetoothAdapter> adapter) { |
| 173 DCHECK(thread_checker_.CalledOnValidThread()); | 167 DCHECK(thread_checker_.CalledOnValidThread()); |
| 174 DCHECK(!adapter_.get()); | 168 DCHECK(!adapter_.get()); |
| 175 adapter_ = adapter; | 169 adapter_ = adapter; |
| 176 | 170 |
| 177 if (adapter_->IsPresent()) { | 171 if (adapter_->IsPresent()) { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 193 device_name_, | 187 device_name_, |
| 194 base::Bind(&BluetoothHostPairingController::OnSetName, | 188 base::Bind(&BluetoothHostPairingController::OnSetName, |
| 195 ptr_factory_.GetWeakPtr()), | 189 ptr_factory_.GetWeakPtr()), |
| 196 base::Bind(&BluetoothHostPairingController::OnSetError, | 190 base::Bind(&BluetoothHostPairingController::OnSetError, |
| 197 ptr_factory_.GetWeakPtr())); | 191 ptr_factory_.GetWeakPtr())); |
| 198 } | 192 } |
| 199 | 193 |
| 200 void BluetoothHostPairingController::OnSetName() { | 194 void BluetoothHostPairingController::OnSetName() { |
| 201 DCHECK(thread_checker_.CalledOnValidThread()); | 195 DCHECK(thread_checker_.CalledOnValidThread()); |
| 202 if (adapter_->IsPowered()) { | 196 if (adapter_->IsPowered()) { |
| 203 was_powered_ = true; | |
| 204 OnSetPowered(); | 197 OnSetPowered(); |
| 205 } else { | 198 } else { |
| 206 adapter_->SetPowered( | 199 adapter_->SetPowered( |
| 207 true, | 200 true, |
| 208 base::Bind(&BluetoothHostPairingController::OnSetPowered, | 201 base::Bind(&BluetoothHostPairingController::OnSetPowered, |
| 209 ptr_factory_.GetWeakPtr()), | 202 ptr_factory_.GetWeakPtr()), |
| 210 base::Bind(&BluetoothHostPairingController::OnSetError, | 203 base::Bind(&BluetoothHostPairingController::OnSetError, |
| 211 ptr_factory_.GetWeakPtr())); | 204 ptr_factory_.GetWeakPtr())); |
| 212 } | 205 } |
| 213 } | 206 } |
| (...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 510 ChangeStage(STAGE_WAITING_FOR_CODE_CONFIRMATION); | 503 ChangeStage(STAGE_WAITING_FOR_CODE_CONFIRMATION); |
| 511 } | 504 } |
| 512 | 505 |
| 513 void BluetoothHostPairingController::AuthorizePairing( | 506 void BluetoothHostPairingController::AuthorizePairing( |
| 514 device::BluetoothDevice* device) { | 507 device::BluetoothDevice* device) { |
| 515 // Disallow unknown device. | 508 // Disallow unknown device. |
| 516 device->RejectPairing(); | 509 device->RejectPairing(); |
| 517 } | 510 } |
| 518 | 511 |
| 519 } // namespace pairing_chromeos | 512 } // namespace pairing_chromeos |
| OLD | NEW |