| 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 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 67 Reset(); | 67 Reset(); |
| 68 if (adapter_.get()) { | 68 if (adapter_.get()) { |
| 69 if (adapter_->IsDiscoverable()) { | 69 if (adapter_->IsDiscoverable()) { |
| 70 adapter_->SetDiscoverable(false, base::Closure(), base::Closure()); | 70 adapter_->SetDiscoverable(false, base::Closure(), base::Closure()); |
| 71 } | 71 } |
| 72 adapter_->RemoveObserver(this); | 72 adapter_->RemoveObserver(this); |
| 73 adapter_ = NULL; | 73 adapter_ = NULL; |
| 74 } | 74 } |
| 75 } | 75 } |
| 76 | 76 |
| 77 void BluetoothHostPairingController::ChangeStage(Stage new_stage) { | |
| 78 if (current_stage_ == new_stage) | |
| 79 return; | |
| 80 VLOG(1) << "ChangeStage " << new_stage; | |
| 81 current_stage_ = new_stage; | |
| 82 FOR_EACH_OBSERVER(Observer, observers_, PairingStageChanged(new_stage)); | |
| 83 } | |
| 84 | |
| 85 void BluetoothHostPairingController::SendHostStatus() { | 77 void BluetoothHostPairingController::SendHostStatus() { |
| 86 pairing_api::HostStatus host_status; | 78 pairing_api::HostStatus host_status; |
| 87 | 79 |
| 88 host_status.set_api_version(kPairingAPIVersion); | 80 host_status.set_api_version(kPairingAPIVersion); |
| 89 if (!enrollment_domain_.empty()) | 81 if (!enrollment_domain_.empty()) |
| 90 host_status.mutable_parameters()->set_domain(enrollment_domain_); | 82 host_status.mutable_parameters()->set_domain(enrollment_domain_); |
| 91 if (!permanent_id_.empty()) | 83 if (!permanent_id_.empty()) |
| 92 host_status.mutable_parameters()->set_permanent_id(permanent_id_); | 84 host_status.mutable_parameters()->set_permanent_id(permanent_id_); |
| 93 | 85 |
| 94 // TODO(zork): Get these values from the UI. (http://crbug.com/405744) | 86 // TODO(zork): Get these values from the UI. (http://crbug.com/405744) |
| (...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 302 LOG(ERROR) << reason << ", " << error_message; | 294 LOG(ERROR) << reason << ", " << error_message; |
| 303 } | 295 } |
| 304 | 296 |
| 305 void BluetoothHostPairingController::OnHostStatusMessage( | 297 void BluetoothHostPairingController::OnHostStatusMessage( |
| 306 const pairing_api::HostStatus& message) { | 298 const pairing_api::HostStatus& message) { |
| 307 NOTREACHED(); | 299 NOTREACHED(); |
| 308 } | 300 } |
| 309 | 301 |
| 310 void BluetoothHostPairingController::OnConfigureHostMessage( | 302 void BluetoothHostPairingController::OnConfigureHostMessage( |
| 311 const pairing_api::ConfigureHost& message) { | 303 const pairing_api::ConfigureHost& message) { |
| 304 ChangeStage(STAGE_SETUP_BASIC_CONFIGURATION); |
| 312 FOR_EACH_OBSERVER(Observer, observers_, | 305 FOR_EACH_OBSERVER(Observer, observers_, |
| 313 ConfigureHostRequested( | 306 ConfigureHostRequested( |
| 314 message.parameters().accepted_eula(), | 307 message.parameters().accepted_eula(), |
| 315 message.parameters().lang(), | 308 message.parameters().lang(), |
| 316 message.parameters().timezone(), | 309 message.parameters().timezone(), |
| 317 message.parameters().send_reports(), | 310 message.parameters().send_reports(), |
| 318 message.parameters().keyboard_layout())); | 311 message.parameters().keyboard_layout())); |
| 319 } | 312 } |
| 320 | 313 |
| 321 void BluetoothHostPairingController::OnPairDevicesMessage( | 314 void BluetoothHostPairingController::OnPairDevicesMessage( |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 367 } | 360 } |
| 368 | 361 |
| 369 void BluetoothHostPairingController::RemoveObserver(Observer* observer) { | 362 void BluetoothHostPairingController::RemoveObserver(Observer* observer) { |
| 370 observers_.RemoveObserver(observer); | 363 observers_.RemoveObserver(observer); |
| 371 } | 364 } |
| 372 | 365 |
| 373 HostPairingController::Stage BluetoothHostPairingController::GetCurrentStage() { | 366 HostPairingController::Stage BluetoothHostPairingController::GetCurrentStage() { |
| 374 return current_stage_; | 367 return current_stage_; |
| 375 } | 368 } |
| 376 | 369 |
| 370 void BluetoothHostPairingController::ChangeStage(Stage new_stage) { |
| 371 if (current_stage_ == new_stage) |
| 372 return; |
| 373 VLOG(1) << "ChangeStage " << new_stage; |
| 374 current_stage_ = new_stage; |
| 375 FOR_EACH_OBSERVER(Observer, observers_, PairingStageChanged(new_stage)); |
| 376 } |
| 377 |
| 377 void BluetoothHostPairingController::StartPairing() { | 378 void BluetoothHostPairingController::StartPairing() { |
| 378 DCHECK_EQ(current_stage_, STAGE_NONE); | 379 DCHECK_EQ(current_stage_, STAGE_NONE); |
| 379 bool bluetooth_available = | 380 bool bluetooth_available = |
| 380 device::BluetoothAdapterFactory::IsBluetoothAdapterAvailable(); | 381 device::BluetoothAdapterFactory::IsBluetoothAdapterAvailable(); |
| 381 if (!bluetooth_available) { | 382 if (!bluetooth_available) { |
| 382 ChangeStage(STAGE_INITIALIZATION_ERROR); | 383 ChangeStage(STAGE_INITIALIZATION_ERROR); |
| 383 return; | 384 return; |
| 384 } | 385 } |
| 385 | 386 |
| 386 device::BluetoothAdapterFactory::GetAdapter( | 387 device::BluetoothAdapterFactory::GetAdapter( |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 476 ChangeStage(STAGE_WAITING_FOR_CODE_CONFIRMATION); | 477 ChangeStage(STAGE_WAITING_FOR_CODE_CONFIRMATION); |
| 477 } | 478 } |
| 478 | 479 |
| 479 void BluetoothHostPairingController::AuthorizePairing( | 480 void BluetoothHostPairingController::AuthorizePairing( |
| 480 device::BluetoothDevice* device) { | 481 device::BluetoothDevice* device) { |
| 481 // Disallow unknown device. | 482 // Disallow unknown device. |
| 482 device->RejectPairing(); | 483 device->RejectPairing(); |
| 483 } | 484 } |
| 484 | 485 |
| 485 } // namespace pairing_chromeos | 486 } // namespace pairing_chromeos |
| OLD | NEW |