| 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_controller_pairing_controller.h" | 5 #include "components/pairing/bluetooth_controller_pairing_controller.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
| 10 #include "base/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
| 11 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.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 "device/bluetooth/bluetooth_adapter_factory.h" | 14 #include "device/bluetooth/bluetooth_adapter_factory.h" |
| 15 #include "device/bluetooth/bluetooth_discovery_session.h" | 15 #include "device/bluetooth/bluetooth_discovery_session.h" |
| 16 #include "net/base/io_buffer.h" | 16 #include "net/base/io_buffer.h" |
| 17 | 17 |
| 18 namespace { | 18 namespace { |
| 19 const char* kFakeEnrollmentDomain = "http://fake.com"; | |
| 20 const int kReceiveSize = 16384; | 19 const int kReceiveSize = 16384; |
| 21 } | 20 } |
| 22 | 21 |
| 23 namespace pairing_chromeos { | 22 namespace pairing_chromeos { |
| 24 | 23 |
| 25 BluetoothControllerPairingController::BluetoothControllerPairingController() | 24 BluetoothControllerPairingController::BluetoothControllerPairingController() |
| 26 : current_stage_(STAGE_NONE), | 25 : current_stage_(STAGE_NONE), |
| 27 got_initial_status_(false), | 26 got_initial_status_(false), |
| 28 proto_decoder_(new ProtoDecoder(this)), | 27 proto_decoder_(new ProtoDecoder(this)), |
| 29 ptr_factory_(this) { | 28 ptr_factory_(this) { |
| (...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 297 device->ConfirmPairing(); | 296 device->ConfirmPairing(); |
| 298 // Once pairing is confirmed, the connection will either be successful, or | 297 // Once pairing is confirmed, the connection will either be successful, or |
| 299 // fail. Either case is acceptable as long as the devices are paired. | 298 // fail. Either case is acceptable as long as the devices are paired. |
| 300 } else { | 299 } else { |
| 301 device->RejectPairing(); | 300 device->RejectPairing(); |
| 302 controller_device_id_.clear(); | 301 controller_device_id_.clear(); |
| 303 RepeatDiscovery(); | 302 RepeatDiscovery(); |
| 304 } | 303 } |
| 305 } | 304 } |
| 306 | 305 |
| 306 void BluetoothControllerPairingController::SetHostConfiguration( |
| 307 bool accepted_eula, |
| 308 const std::string& lang, |
| 309 const std::string& timezone, |
| 310 bool send_reports, |
| 311 const std::string& keyboard_layout) { |
| 312 // TODO(zork): Get configuration from UI and send to Host. |
| 313 // (http://crbug.com/405744) |
| 314 } |
| 315 |
| 307 void BluetoothControllerPairingController::OnAuthenticationDone( | 316 void BluetoothControllerPairingController::OnAuthenticationDone( |
| 308 const chromeos::UserContext& user_context, | 317 const std::string& domain, |
| 309 content::BrowserContext* browser_context) { | 318 const std::string& auth_token) { |
| 310 DCHECK_EQ(current_stage_, STAGE_WAITING_FOR_CREDENTIALS); | 319 DCHECK_EQ(current_stage_, STAGE_WAITING_FOR_CREDENTIALS); |
| 311 | 320 |
| 312 // TODO(zork): Get configuration from UI and send to Host. | |
| 313 // (http://crbug.com/405744) | |
| 314 | |
| 315 // TODO(zork): Get proper credentials. (http://crbug.com/405744) | |
| 316 // For now, send a fake domain. | |
| 317 pairing_api::PairDevices pair_devices; | 321 pairing_api::PairDevices pair_devices; |
| 318 pair_devices.set_api_version(kPairingAPIVersion); | 322 pair_devices.set_api_version(kPairingAPIVersion); |
| 319 pair_devices.mutable_parameters()->set_admin_access_token( | 323 pair_devices.mutable_parameters()->set_admin_access_token(auth_token); |
| 320 kFakeEnrollmentDomain); | |
| 321 | 324 |
| 322 int size = 0; | 325 int size = 0; |
| 323 scoped_refptr<net::IOBuffer> io_buffer( | 326 scoped_refptr<net::IOBuffer> io_buffer( |
| 324 ProtoDecoder::SendPairDevices(pair_devices, &size)); | 327 ProtoDecoder::SendPairDevices(pair_devices, &size)); |
| 325 | 328 |
| 326 socket_->Send( | 329 socket_->Send( |
| 327 io_buffer, size, | 330 io_buffer, size, |
| 328 base::Bind(&BluetoothControllerPairingController::OnSendComplete, | 331 base::Bind(&BluetoothControllerPairingController::OnSendComplete, |
| 329 ptr_factory_.GetWeakPtr()), | 332 ptr_factory_.GetWeakPtr()), |
| 330 base::Bind(&BluetoothControllerPairingController::OnErrorWithMessage, | 333 base::Bind(&BluetoothControllerPairingController::OnErrorWithMessage, |
| 331 ptr_factory_.GetWeakPtr())); | 334 ptr_factory_.GetWeakPtr())); |
| 332 ChangeStage(STAGE_HOST_ENROLLMENT_IN_PROGRESS); | 335 ChangeStage(STAGE_HOST_ENROLLMENT_IN_PROGRESS); |
| 333 } | 336 } |
| 334 | 337 |
| 335 void BluetoothControllerPairingController::StartSession() { | 338 void BluetoothControllerPairingController::StartSession() { |
| 336 DCHECK_EQ(current_stage_, STAGE_PAIRING_DONE); | 339 DCHECK_EQ(current_stage_, STAGE_PAIRING_DONE); |
| 337 ChangeStage(STAGE_FINISHED); | 340 ChangeStage(STAGE_FINISHED); |
| 338 } | 341 } |
| 339 | 342 |
| 340 // ProtoDecoder::Observer: | 343 // ProtoDecoder::Observer: |
| 341 void BluetoothControllerPairingController::OnHostStatusMessage( | 344 void BluetoothControllerPairingController::OnHostStatusMessage( |
| 342 const pairing_api::HostStatus& message) { | 345 const pairing_api::HostStatus& message) { |
| 343 if (got_initial_status_) { | 346 if (got_initial_status_) { |
| 344 if (message.parameters().has_domain()) { | 347 // TODO(zork): Check that the domain matches. (http://crbug.com/405761) |
| 345 // TODO(zork): Remove this if we don't actually need the domain for UI. | 348 // TODO(zork): Handling updating stages (http://crbug.com/405754). |
| 346 // (http://crbug.com/405761) | 349 pairing_api::CompleteSetup complete_setup; |
| 347 if (message.parameters().domain() == kFakeEnrollmentDomain) { | 350 complete_setup.set_api_version(kPairingAPIVersion); |
| 348 pairing_api::CompleteSetup complete_setup; | 351 // TODO(zork): Get AddAnother from UI (http://crbug.com/405757) |
| 349 complete_setup.set_api_version(kPairingAPIVersion); | 352 complete_setup.mutable_parameters()->set_add_another(false); |
| 350 // TODO(zork): Get AddAnother from UI (http://crbug.com/405757) | |
| 351 complete_setup.mutable_parameters()->set_add_another(false); | |
| 352 | 353 |
| 353 int size = 0; | 354 int size = 0; |
| 354 scoped_refptr<net::IOBuffer> io_buffer( | 355 scoped_refptr<net::IOBuffer> io_buffer( |
| 355 ProtoDecoder::SendCompleteSetup(complete_setup, &size)); | 356 ProtoDecoder::SendCompleteSetup(complete_setup, &size)); |
| 356 | 357 |
| 357 socket_->Send( | 358 socket_->Send( |
| 358 io_buffer, size, | 359 io_buffer, size, |
| 359 base::Bind(&BluetoothControllerPairingController::OnSendComplete, | 360 base::Bind(&BluetoothControllerPairingController::OnSendComplete, |
| 360 ptr_factory_.GetWeakPtr()), | 361 ptr_factory_.GetWeakPtr()), |
| 361 base::Bind( | 362 base::Bind( |
| 362 &BluetoothControllerPairingController::OnErrorWithMessage, | 363 &BluetoothControllerPairingController::OnErrorWithMessage, |
| 363 ptr_factory_.GetWeakPtr())); | 364 ptr_factory_.GetWeakPtr())); |
| 364 ChangeStage(STAGE_PAIRING_DONE); | 365 ChangeStage(STAGE_PAIRING_DONE); |
| 365 } else { | |
| 366 ChangeStage(STAGE_HOST_ENROLLMENT_ERROR); | |
| 367 } | |
| 368 } else { | |
| 369 ChangeStage(STAGE_HOST_ENROLLMENT_ERROR); | |
| 370 } | |
| 371 } else { | 366 } else { |
| 372 got_initial_status_ = true; | 367 got_initial_status_ = true; |
| 373 | 368 |
| 374 // TODO(zork): Check domain. (http://crbug.com/405761) | 369 // TODO(zork): Check domain. (http://crbug.com/405761) |
| 375 | |
| 376 // TODO(zork): Handling updating stages (http://crbug.com/405754). | |
| 377 ChangeStage(STAGE_WAITING_FOR_CREDENTIALS); | 370 ChangeStage(STAGE_WAITING_FOR_CREDENTIALS); |
| 378 } | 371 } |
| 379 } | 372 } |
| 380 | 373 |
| 381 void BluetoothControllerPairingController::OnConfigureHostMessage( | 374 void BluetoothControllerPairingController::OnConfigureHostMessage( |
| 382 const pairing_api::ConfigureHost& message) { | 375 const pairing_api::ConfigureHost& message) { |
| 383 NOTREACHED(); | 376 NOTREACHED(); |
| 384 } | 377 } |
| 385 | 378 |
| 386 void BluetoothControllerPairingController::OnPairDevicesMessage( | 379 void BluetoothControllerPairingController::OnPairDevicesMessage( |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 454 ChangeStage(STAGE_WAITING_FOR_CODE_CONFIRMATION); | 447 ChangeStage(STAGE_WAITING_FOR_CODE_CONFIRMATION); |
| 455 } | 448 } |
| 456 | 449 |
| 457 void BluetoothControllerPairingController::AuthorizePairing( | 450 void BluetoothControllerPairingController::AuthorizePairing( |
| 458 device::BluetoothDevice* device) { | 451 device::BluetoothDevice* device) { |
| 459 // Disallow unknown device. | 452 // Disallow unknown device. |
| 460 device->RejectPairing(); | 453 device->RejectPairing(); |
| 461 } | 454 } |
| 462 | 455 |
| 463 } // namespace pairing_chromeos | 456 } // namespace pairing_chromeos |
| OLD | NEW |