diff options
author | zork <zork@chromium.org> | 2014-09-18 18:04:54 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2014-09-19 01:05:27 +0000 |
commit | 32ac1c8de6b465d1638085b86008f546fb672a96 (patch) | |
tree | b1179adc3780b32697c91c7010ebc642f5bbd7f6 /components | |
parent | 2d952ff029c1cf6927c9569be7a47eeb11d8fba1 (diff) | |
download | chromium_src-32ac1c8de6b465d1638085b86008f546fb672a96.zip chromium_src-32ac1c8de6b465d1638085b86008f546fb672a96.tar.gz chromium_src-32ac1c8de6b465d1638085b86008f546fb672a96.tar.bz2 |
Clean up protocol for Bluetooth Pairing.
- Add helper buffer for sending IOBuffer
- Add initialization error states.
- Make the device name more human-readable.
BUG=405744,405774
Review URL: https://codereview.chromium.org/575273002
Cr-Commit-Position: refs/heads/master@{#295629}
Diffstat (limited to 'components')
3 files changed, 46 insertions, 29 deletions
diff --git a/components/pairing/bluetooth_controller_pairing_controller.cc b/components/pairing/bluetooth_controller_pairing_controller.cc index cce1d67..05285c8 100644 --- a/components/pairing/bluetooth_controller_pairing_controller.cc +++ b/components/pairing/bluetooth_controller_pairing_controller.cc @@ -92,6 +92,16 @@ void BluetoothControllerPairingController::DeviceLost( } } +void BluetoothControllerPairingController::SendBuffer( + scoped_refptr<net::IOBuffer> io_buffer, int size) { + socket_->Send( + io_buffer, size, + base::Bind(&BluetoothControllerPairingController::OnSendComplete, + ptr_factory_.GetWeakPtr()), + base::Bind(&BluetoothControllerPairingController::OnErrorWithMessage, + ptr_factory_.GetWeakPtr())); +} + void BluetoothControllerPairingController::OnSetPowered() { DCHECK(thread_checker_.CalledOnValidThread()); adapter_->StartDiscoverySession( @@ -175,15 +185,15 @@ void BluetoothControllerPairingController::OnReceiveComplete( } void BluetoothControllerPairingController::OnError() { - // TODO(zork): Add a stage for initialization error. (http://crbug.com/405744) LOG(ERROR) << "Pairing initialization failed"; + ChangeStage(STAGE_INITIALIZATION_ERROR); Reset(); } void BluetoothControllerPairingController::OnErrorWithMessage( const std::string& message) { - // TODO(zork): Add a stage for initialization error. (http://crbug.com/405744) LOG(ERROR) << message; + ChangeStage(STAGE_INITIALIZATION_ERROR); Reset(); } @@ -228,9 +238,8 @@ void BluetoothControllerPairingController::StartPairing() { current_stage_ == STAGE_DEVICE_NOT_FOUND || current_stage_ == STAGE_ESTABLISHING_CONNECTION_ERROR || current_stage_ == STAGE_HOST_ENROLLMENT_ERROR); - // TODO(zork): Add a stage for no bluetooth. (http://crbug.com/405744) if (!device::BluetoothAdapterFactory::IsBluetoothAdapterAvailable()) { - ChangeStage(STAGE_DEVICE_NOT_FOUND); + ChangeStage(STAGE_INITIALIZATION_ERROR); return; } @@ -309,8 +318,20 @@ void BluetoothControllerPairingController::SetHostConfiguration( const std::string& timezone, bool send_reports, const std::string& keyboard_layout) { - // TODO(zork): Get configuration from UI and send to Host. - // (http://crbug.com/405744) + + pairing_api::ConfigureHost host_config; + host_config.set_api_version(kPairingAPIVersion); + host_config.mutable_parameters()->set_accepted_eula(accepted_eula); + host_config.mutable_parameters()->set_lang(lang); + host_config.mutable_parameters()->set_timezone(timezone); + host_config.mutable_parameters()->set_send_reports(send_reports); + host_config.mutable_parameters()->set_keyboard_layout(keyboard_layout); + + int size = 0; + scoped_refptr<net::IOBuffer> io_buffer( + ProtoDecoder::SendConfigureHost(host_config, &size)); + + SendBuffer(io_buffer, size); } void BluetoothControllerPairingController::OnAuthenticationDone( @@ -326,12 +347,7 @@ void BluetoothControllerPairingController::OnAuthenticationDone( scoped_refptr<net::IOBuffer> io_buffer( ProtoDecoder::SendPairDevices(pair_devices, &size)); - socket_->Send( - io_buffer, size, - base::Bind(&BluetoothControllerPairingController::OnSendComplete, - ptr_factory_.GetWeakPtr()), - base::Bind(&BluetoothControllerPairingController::OnErrorWithMessage, - ptr_factory_.GetWeakPtr())); + SendBuffer(io_buffer, size); ChangeStage(STAGE_HOST_ENROLLMENT_IN_PROGRESS); } @@ -355,13 +371,7 @@ void BluetoothControllerPairingController::OnHostStatusMessage( scoped_refptr<net::IOBuffer> io_buffer( ProtoDecoder::SendCompleteSetup(complete_setup, &size)); - socket_->Send( - io_buffer, size, - base::Bind(&BluetoothControllerPairingController::OnSendComplete, - ptr_factory_.GetWeakPtr()), - base::Bind( - &BluetoothControllerPairingController::OnErrorWithMessage, - ptr_factory_.GetWeakPtr())); + SendBuffer(io_buffer, size); ChangeStage(STAGE_PAIRING_DONE); } else { got_initial_status_ = true; diff --git a/components/pairing/bluetooth_controller_pairing_controller.h b/components/pairing/bluetooth_controller_pairing_controller.h index 7458154..cbc5cd8 100644 --- a/components/pairing/bluetooth_controller_pairing_controller.h +++ b/components/pairing/bluetooth_controller_pairing_controller.h @@ -38,6 +38,7 @@ class BluetoothControllerPairingController void Reset(); void DeviceFound(device::BluetoothDevice* device); void DeviceLost(device::BluetoothDevice* device); + void SendBuffer(scoped_refptr<net::IOBuffer> io_buffer, int size); void OnSetPowered(); void OnGetAdapter(scoped_refptr<device::BluetoothAdapter> adapter); diff --git a/components/pairing/bluetooth_host_pairing_controller.cc b/components/pairing/bluetooth_host_pairing_controller.cc index 3d62c3ac..f30c3ec 100644 --- a/components/pairing/bluetooth_host_pairing_controller.cc +++ b/components/pairing/bluetooth_host_pairing_controller.cc @@ -5,6 +5,7 @@ #include "components/pairing/bluetooth_host_pairing_controller.h" #include "base/bind.h" +#include "base/hash.h" #include "base/logging.h" #include "base/strings/stringprintf.h" #include "components/pairing/bluetooth_pairing_constants.h" @@ -118,9 +119,10 @@ void BluetoothHostPairingController::OnGetAdapter( } void BluetoothHostPairingController::SetName() { - // TODO(zork): Make the device name prettier. (http://crbug.com/405774) - device_name_ = base::StringPrintf("%s%s", kDeviceNamePrefix, - adapter_->GetAddress().c_str()); + // Hash the bluetooth address and take the lower 2 bytes to create a human + // readable device name. + const uint32 device_id = base::Hash(adapter_->GetAddress()) & 0xFFFF; + device_name_ = base::StringPrintf("%s%04X", kDeviceNamePrefix, device_id); adapter_->SetName( device_name_, @@ -232,14 +234,12 @@ void BluetoothHostPairingController::OnReceiveComplete( void BluetoothHostPairingController::OnCreateServiceError( const std::string& message) { LOG(ERROR) << message; - // TODO(zork): Add a stage for initialization error. (http://crbug.com/405744) - ChangeStage(STAGE_NONE); + ChangeStage(STAGE_INITIALIZATION_ERROR); } void BluetoothHostPairingController::OnSetError() { adapter_->RemovePairingDelegate(this); - // TODO(zork): Add a stage for initialization error. (http://crbug.com/405744) - ChangeStage(STAGE_NONE); + ChangeStage(STAGE_INITIALIZATION_ERROR); } void BluetoothHostPairingController::OnAcceptError( @@ -267,7 +267,12 @@ void BluetoothHostPairingController::OnHostStatusMessage( void BluetoothHostPairingController::OnConfigureHostMessage( const pairing_api::ConfigureHost& message) { - // TODO(zork): Add event to API to handle this case. (http://crbug.com/405744) + FOR_EACH_OBSERVER(Observer, observers_, + ConfigureHost(message.parameters().accepted_eula(), + message.parameters().lang(), + message.parameters().timezone(), + message.parameters().send_reports(), + message.parameters().keyboard_layout())); } void BluetoothHostPairingController::OnPairDevicesMessage( @@ -337,9 +342,10 @@ void BluetoothHostPairingController::StartPairing() { DCHECK_EQ(current_stage_, STAGE_NONE); bool bluetooth_available = device::BluetoothAdapterFactory::IsBluetoothAdapterAvailable(); - // TODO(zork): Add a stage for initialization error. (http://crbug.com/405744) - if (!bluetooth_available) + if (!bluetooth_available) { + ChangeStage(STAGE_INITIALIZATION_ERROR); return; + } device::BluetoothAdapterFactory::GetAdapter( base::Bind(&BluetoothHostPairingController::OnGetAdapter, |