| 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/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/strings/stringprintf.h" | 9 #include "base/strings/stringprintf.h" |
| 10 #include "components/pairing/bluetooth_pairing_constants.h" | 10 #include "components/pairing/bluetooth_pairing_constants.h" |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 59 io_buffer, size, | 59 io_buffer, size, |
| 60 base::Bind(&BluetoothHostPairingController::OnSendComplete, | 60 base::Bind(&BluetoothHostPairingController::OnSendComplete, |
| 61 ptr_factory_.GetWeakPtr()), | 61 ptr_factory_.GetWeakPtr()), |
| 62 base::Bind(&BluetoothHostPairingController::OnSendError, | 62 base::Bind(&BluetoothHostPairingController::OnSendError, |
| 63 ptr_factory_.GetWeakPtr())); | 63 ptr_factory_.GetWeakPtr())); |
| 64 } | 64 } |
| 65 | 65 |
| 66 void BluetoothHostPairingController::AbortWithError( | 66 void BluetoothHostPairingController::AbortWithError( |
| 67 int code, | 67 int code, |
| 68 const std::string& message) { | 68 const std::string& message) { |
| 69 if (controller_socket_) { | 69 if (controller_socket_.get()) { |
| 70 pairing_api::Error error; | 70 pairing_api::Error error; |
| 71 | 71 |
| 72 error.set_api_version(kPairingAPIVersion); | 72 error.set_api_version(kPairingAPIVersion); |
| 73 error.mutable_parameters()->set_code(PAIRING_ERROR_PAIRING_OR_ENROLLMENT); | 73 error.mutable_parameters()->set_code(PAIRING_ERROR_PAIRING_OR_ENROLLMENT); |
| 74 error.mutable_parameters()->set_description(message); | 74 error.mutable_parameters()->set_description(message); |
| 75 | 75 |
| 76 int size = 0; | 76 int size = 0; |
| 77 scoped_refptr<net::IOBuffer> io_buffer( | 77 scoped_refptr<net::IOBuffer> io_buffer( |
| 78 ProtoDecoder::SendError(error, &size)); | 78 ProtoDecoder::SendError(error, &size)); |
| 79 | 79 |
| 80 controller_socket_->Send( | 80 controller_socket_->Send( |
| 81 io_buffer, size, | 81 io_buffer, size, |
| 82 base::Bind(&BluetoothHostPairingController::OnSendComplete, | 82 base::Bind(&BluetoothHostPairingController::OnSendComplete, |
| 83 ptr_factory_.GetWeakPtr()), | 83 ptr_factory_.GetWeakPtr()), |
| 84 base::Bind(&BluetoothHostPairingController::OnSendError, | 84 base::Bind(&BluetoothHostPairingController::OnSendError, |
| 85 ptr_factory_.GetWeakPtr())); | 85 ptr_factory_.GetWeakPtr())); |
| 86 } | 86 } |
| 87 Reset(); | 87 Reset(); |
| 88 } | 88 } |
| 89 | 89 |
| 90 void BluetoothHostPairingController::Reset() { | 90 void BluetoothHostPairingController::Reset() { |
| 91 if (controller_socket_) { | 91 if (controller_socket_.get()) { |
| 92 controller_socket_->Close(); | 92 controller_socket_->Close(); |
| 93 controller_socket_ = NULL; | 93 controller_socket_ = NULL; |
| 94 } | 94 } |
| 95 | 95 |
| 96 if (service_socket_) { | 96 if (service_socket_.get()) { |
| 97 service_socket_->Close(); | 97 service_socket_->Close(); |
| 98 service_socket_ = NULL; | 98 service_socket_ = NULL; |
| 99 } | 99 } |
| 100 ChangeStage(STAGE_NONE); | 100 ChangeStage(STAGE_NONE); |
| 101 } | 101 } |
| 102 | 102 |
| 103 void BluetoothHostPairingController::OnGetAdapter( | 103 void BluetoothHostPairingController::OnGetAdapter( |
| 104 scoped_refptr<device::BluetoothAdapter> adapter) { | 104 scoped_refptr<device::BluetoothAdapter> adapter) { |
| 105 DCHECK(thread_checker_.CalledOnValidThread()); | 105 DCHECK(thread_checker_.CalledOnValidThread()); |
| 106 DCHECK(!adapter_); | 106 DCHECK(!adapter_.get()); |
| 107 adapter_ = adapter; | 107 adapter_ = adapter; |
| 108 | 108 |
| 109 // TODO(zork): Make the device name prettier. (http://crbug.com/405774) | 109 // TODO(zork): Make the device name prettier. (http://crbug.com/405774) |
| 110 device_name_ = base::StringPrintf("%s%s", kDeviceNamePrefix, | 110 device_name_ = base::StringPrintf("%s%s", kDeviceNamePrefix, |
| 111 adapter_->GetAddress().c_str()); | 111 adapter_->GetAddress().c_str()); |
| 112 adapter_->SetName( | 112 adapter_->SetName( |
| 113 device_name_, | 113 device_name_, |
| 114 base::Bind(&BluetoothHostPairingController::OnSetName, | 114 base::Bind(&BluetoothHostPairingController::OnSetName, |
| 115 ptr_factory_.GetWeakPtr()), | 115 ptr_factory_.GetWeakPtr()), |
| 116 base::Bind(&BluetoothHostPairingController::OnSetError, | 116 base::Bind(&BluetoothHostPairingController::OnSetError, |
| (...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 382 ChangeStage(STAGE_WAITING_FOR_CODE_CONFIRMATION); | 382 ChangeStage(STAGE_WAITING_FOR_CODE_CONFIRMATION); |
| 383 } | 383 } |
| 384 | 384 |
| 385 void BluetoothHostPairingController::AuthorizePairing( | 385 void BluetoothHostPairingController::AuthorizePairing( |
| 386 device::BluetoothDevice* device) { | 386 device::BluetoothDevice* device) { |
| 387 // Disallow unknown device. | 387 // Disallow unknown device. |
| 388 device->RejectPairing(); | 388 device->RejectPairing(); |
| 389 } | 389 } |
| 390 | 390 |
| 391 } // namespace pairing_chromeos | 391 } // namespace pairing_chromeos |
| OLD | NEW |