| 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 "device/bluetooth/bluetooth_pairing_chromeos.h" | 5 #include "device/bluetooth/bluetooth_pairing_chromeos.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/metrics/histogram.h" | 8 #include "base/metrics/histogram.h" |
| 9 #include "device/bluetooth/bluetooth_device.h" | 9 #include "device/bluetooth/bluetooth_device.h" |
| 10 #include "device/bluetooth/bluetooth_device_chromeos.h" | 10 #include "device/bluetooth/bluetooth_device_chromeos.h" |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 << device_->GetAddress(); | 49 << device_->GetAddress(); |
| 50 | 50 |
| 51 if (!pairing_delegate_used_) { | 51 if (!pairing_delegate_used_) { |
| 52 UMA_HISTOGRAM_ENUMERATION("Bluetooth.PairingMethod", | 52 UMA_HISTOGRAM_ENUMERATION("Bluetooth.PairingMethod", |
| 53 UMA_PAIRING_METHOD_NONE, | 53 UMA_PAIRING_METHOD_NONE, |
| 54 UMA_PAIRING_METHOD_COUNT); | 54 UMA_PAIRING_METHOD_COUNT); |
| 55 } | 55 } |
| 56 | 56 |
| 57 if (!pincode_callback_.is_null()) { | 57 if (!pincode_callback_.is_null()) { |
| 58 pincode_callback_.Run( | 58 pincode_callback_.Run( |
| 59 BluetoothAgentServiceProvider::Delegate::CANCELLED, ""); | 59 bluez::BluetoothAgentServiceProvider::Delegate::CANCELLED, ""); |
| 60 } | 60 } |
| 61 | 61 |
| 62 if (!passkey_callback_.is_null()) { | 62 if (!passkey_callback_.is_null()) { |
| 63 passkey_callback_.Run( | 63 passkey_callback_.Run( |
| 64 BluetoothAgentServiceProvider::Delegate::CANCELLED, 0); | 64 bluez::BluetoothAgentServiceProvider::Delegate::CANCELLED, 0); |
| 65 } | 65 } |
| 66 | 66 |
| 67 if (!confirmation_callback_.is_null()) { | 67 if (!confirmation_callback_.is_null()) { |
| 68 confirmation_callback_.Run( | 68 confirmation_callback_.Run( |
| 69 BluetoothAgentServiceProvider::Delegate::CANCELLED); | 69 bluez::BluetoothAgentServiceProvider::Delegate::CANCELLED); |
| 70 } | 70 } |
| 71 | 71 |
| 72 pairing_delegate_ = NULL; | 72 pairing_delegate_ = NULL; |
| 73 } | 73 } |
| 74 | 74 |
| 75 void BluetoothPairingChromeOS::RequestPinCode( | 75 void BluetoothPairingChromeOS::RequestPinCode( |
| 76 const BluetoothAgentServiceProvider::Delegate::PinCodeCallback& callback) { | 76 const bluez::BluetoothAgentServiceProvider::Delegate::PinCodeCallback& |
| 77 callback) { |
| 77 UMA_HISTOGRAM_ENUMERATION("Bluetooth.PairingMethod", | 78 UMA_HISTOGRAM_ENUMERATION("Bluetooth.PairingMethod", |
| 78 UMA_PAIRING_METHOD_REQUEST_PINCODE, | 79 UMA_PAIRING_METHOD_REQUEST_PINCODE, |
| 79 UMA_PAIRING_METHOD_COUNT); | 80 UMA_PAIRING_METHOD_COUNT); |
| 80 | 81 |
| 81 ResetCallbacks(); | 82 ResetCallbacks(); |
| 82 pincode_callback_ = callback; | 83 pincode_callback_ = callback; |
| 83 pairing_delegate_used_ = true; | 84 pairing_delegate_used_ = true; |
| 84 pairing_delegate_->RequestPinCode(device_); | 85 pairing_delegate_->RequestPinCode(device_); |
| 85 } | 86 } |
| 86 | 87 |
| 87 bool BluetoothPairingChromeOS::ExpectingPinCode() const { | 88 bool BluetoothPairingChromeOS::ExpectingPinCode() const { |
| 88 return !pincode_callback_.is_null(); | 89 return !pincode_callback_.is_null(); |
| 89 } | 90 } |
| 90 | 91 |
| 91 void BluetoothPairingChromeOS::SetPinCode(const std::string& pincode) { | 92 void BluetoothPairingChromeOS::SetPinCode(const std::string& pincode) { |
| 92 if (pincode_callback_.is_null()) | 93 if (pincode_callback_.is_null()) |
| 93 return; | 94 return; |
| 94 | 95 |
| 95 pincode_callback_.Run(BluetoothAgentServiceProvider::Delegate::SUCCESS, | 96 pincode_callback_.Run(bluez::BluetoothAgentServiceProvider::Delegate::SUCCESS, |
| 96 pincode); | 97 pincode); |
| 97 pincode_callback_.Reset(); | 98 pincode_callback_.Reset(); |
| 98 | 99 |
| 99 // If this is not an outgoing connection to the device, clean up the pairing | 100 // If this is not an outgoing connection to the device, clean up the pairing |
| 100 // context since the pairing is done. The outgoing connection case is cleaned | 101 // context since the pairing is done. The outgoing connection case is cleaned |
| 101 // up in the callback for the underlying Pair() call. | 102 // up in the callback for the underlying Pair() call. |
| 102 if (!device_->IsConnecting()) | 103 if (!device_->IsConnecting()) |
| 103 device_->EndPairing(); | 104 device_->EndPairing(); |
| 104 } | 105 } |
| 105 | 106 |
| 106 void BluetoothPairingChromeOS::DisplayPinCode(const std::string& pincode) { | 107 void BluetoothPairingChromeOS::DisplayPinCode(const std::string& pincode) { |
| 107 UMA_HISTOGRAM_ENUMERATION("Bluetooth.PairingMethod", | 108 UMA_HISTOGRAM_ENUMERATION("Bluetooth.PairingMethod", |
| 108 UMA_PAIRING_METHOD_DISPLAY_PINCODE, | 109 UMA_PAIRING_METHOD_DISPLAY_PINCODE, |
| 109 UMA_PAIRING_METHOD_COUNT); | 110 UMA_PAIRING_METHOD_COUNT); |
| 110 | 111 |
| 111 ResetCallbacks(); | 112 ResetCallbacks(); |
| 112 pairing_delegate_used_ = true; | 113 pairing_delegate_used_ = true; |
| 113 pairing_delegate_->DisplayPinCode(device_, pincode); | 114 pairing_delegate_->DisplayPinCode(device_, pincode); |
| 114 | 115 |
| 115 // If this is not an outgoing connection to the device, the pairing context | 116 // If this is not an outgoing connection to the device, the pairing context |
| 116 // needs to be cleaned up again as there's no reliable indication of | 117 // needs to be cleaned up again as there's no reliable indication of |
| 117 // completion of incoming pairing. | 118 // completion of incoming pairing. |
| 118 if (!device_->IsConnecting()) | 119 if (!device_->IsConnecting()) |
| 119 device_->EndPairing(); | 120 device_->EndPairing(); |
| 120 } | 121 } |
| 121 | 122 |
| 122 void BluetoothPairingChromeOS::RequestPasskey( | 123 void BluetoothPairingChromeOS::RequestPasskey( |
| 123 const BluetoothAgentServiceProvider::Delegate::PasskeyCallback& callback) { | 124 const bluez::BluetoothAgentServiceProvider::Delegate::PasskeyCallback& |
| 125 callback) { |
| 124 UMA_HISTOGRAM_ENUMERATION("Bluetooth.PairingMethod", | 126 UMA_HISTOGRAM_ENUMERATION("Bluetooth.PairingMethod", |
| 125 UMA_PAIRING_METHOD_REQUEST_PASSKEY, | 127 UMA_PAIRING_METHOD_REQUEST_PASSKEY, |
| 126 UMA_PAIRING_METHOD_COUNT); | 128 UMA_PAIRING_METHOD_COUNT); |
| 127 | 129 |
| 128 ResetCallbacks(); | 130 ResetCallbacks(); |
| 129 passkey_callback_ = callback; | 131 passkey_callback_ = callback; |
| 130 pairing_delegate_used_ = true; | 132 pairing_delegate_used_ = true; |
| 131 pairing_delegate_->RequestPasskey(device_); | 133 pairing_delegate_->RequestPasskey(device_); |
| 132 } | 134 } |
| 133 | 135 |
| 134 bool BluetoothPairingChromeOS::ExpectingPasskey() const { | 136 bool BluetoothPairingChromeOS::ExpectingPasskey() const { |
| 135 return !passkey_callback_.is_null(); | 137 return !passkey_callback_.is_null(); |
| 136 } | 138 } |
| 137 | 139 |
| 138 void BluetoothPairingChromeOS::SetPasskey(uint32 passkey) { | 140 void BluetoothPairingChromeOS::SetPasskey(uint32 passkey) { |
| 139 if (passkey_callback_.is_null()) | 141 if (passkey_callback_.is_null()) |
| 140 return; | 142 return; |
| 141 | 143 |
| 142 passkey_callback_.Run(BluetoothAgentServiceProvider::Delegate::SUCCESS, | 144 passkey_callback_.Run(bluez::BluetoothAgentServiceProvider::Delegate::SUCCESS, |
| 143 passkey); | 145 passkey); |
| 144 passkey_callback_.Reset(); | 146 passkey_callback_.Reset(); |
| 145 | 147 |
| 146 // If this is not an outgoing connection to the device, clean up the pairing | 148 // If this is not an outgoing connection to the device, clean up the pairing |
| 147 // context since the pairing is done. The outgoing connection case is cleaned | 149 // context since the pairing is done. The outgoing connection case is cleaned |
| 148 // up in the callback for the underlying Pair() call. | 150 // up in the callback for the underlying Pair() call. |
| 149 if (!device_->IsConnecting()) | 151 if (!device_->IsConnecting()) |
| 150 device_->EndPairing(); | 152 device_->EndPairing(); |
| 151 } | 153 } |
| 152 | 154 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 167 | 169 |
| 168 // If this is not an outgoing connection to the device, the pairing context | 170 // If this is not an outgoing connection to the device, the pairing context |
| 169 // needs to be cleaned up again as there's no reliable indication of | 171 // needs to be cleaned up again as there's no reliable indication of |
| 170 // completion of incoming pairing. | 172 // completion of incoming pairing. |
| 171 if (entered >= kPasskeyMaxKeysEntered && !device_->IsConnecting()) | 173 if (entered >= kPasskeyMaxKeysEntered && !device_->IsConnecting()) |
| 172 device_->EndPairing(); | 174 device_->EndPairing(); |
| 173 } | 175 } |
| 174 | 176 |
| 175 void BluetoothPairingChromeOS::RequestConfirmation( | 177 void BluetoothPairingChromeOS::RequestConfirmation( |
| 176 uint32 passkey, | 178 uint32 passkey, |
| 177 const BluetoothAgentServiceProvider::Delegate::ConfirmationCallback& | 179 const bluez::BluetoothAgentServiceProvider::Delegate::ConfirmationCallback& |
| 178 callback) { | 180 callback) { |
| 179 UMA_HISTOGRAM_ENUMERATION("Bluetooth.PairingMethod", | 181 UMA_HISTOGRAM_ENUMERATION("Bluetooth.PairingMethod", |
| 180 UMA_PAIRING_METHOD_CONFIRM_PASSKEY, | 182 UMA_PAIRING_METHOD_CONFIRM_PASSKEY, |
| 181 UMA_PAIRING_METHOD_COUNT); | 183 UMA_PAIRING_METHOD_COUNT); |
| 182 | 184 |
| 183 ResetCallbacks(); | 185 ResetCallbacks(); |
| 184 confirmation_callback_ = callback; | 186 confirmation_callback_ = callback; |
| 185 pairing_delegate_used_ = true; | 187 pairing_delegate_used_ = true; |
| 186 pairing_delegate_->ConfirmPasskey(device_, passkey); | 188 pairing_delegate_->ConfirmPasskey(device_, passkey); |
| 187 } | 189 } |
| 188 | 190 |
| 189 void BluetoothPairingChromeOS::RequestAuthorization( | 191 void BluetoothPairingChromeOS::RequestAuthorization( |
| 190 const BluetoothAgentServiceProvider::Delegate::ConfirmationCallback& | 192 const bluez::BluetoothAgentServiceProvider::Delegate::ConfirmationCallback& |
| 191 callback) { | 193 callback) { |
| 192 UMA_HISTOGRAM_ENUMERATION("Bluetooth.PairingMethod", | 194 UMA_HISTOGRAM_ENUMERATION("Bluetooth.PairingMethod", |
| 193 UMA_PAIRING_METHOD_NONE, | 195 UMA_PAIRING_METHOD_NONE, |
| 194 UMA_PAIRING_METHOD_COUNT); | 196 UMA_PAIRING_METHOD_COUNT); |
| 195 | 197 |
| 196 ResetCallbacks(); | 198 ResetCallbacks(); |
| 197 confirmation_callback_ = callback; | 199 confirmation_callback_ = callback; |
| 198 pairing_delegate_used_ = true; | 200 pairing_delegate_used_ = true; |
| 199 pairing_delegate_->AuthorizePairing(device_); | 201 pairing_delegate_->AuthorizePairing(device_); |
| 200 } | 202 } |
| 201 | 203 |
| 202 bool BluetoothPairingChromeOS::ExpectingConfirmation() const { | 204 bool BluetoothPairingChromeOS::ExpectingConfirmation() const { |
| 203 return !confirmation_callback_.is_null(); | 205 return !confirmation_callback_.is_null(); |
| 204 } | 206 } |
| 205 | 207 |
| 206 void BluetoothPairingChromeOS::ConfirmPairing() { | 208 void BluetoothPairingChromeOS::ConfirmPairing() { |
| 207 if (confirmation_callback_.is_null()) | 209 if (confirmation_callback_.is_null()) |
| 208 return; | 210 return; |
| 209 | 211 |
| 210 confirmation_callback_.Run(BluetoothAgentServiceProvider::Delegate::SUCCESS); | 212 confirmation_callback_.Run( |
| 213 bluez::BluetoothAgentServiceProvider::Delegate::SUCCESS); |
| 211 confirmation_callback_.Reset(); | 214 confirmation_callback_.Reset(); |
| 212 | 215 |
| 213 // If this is not an outgoing connection to the device, clean up the pairing | 216 // If this is not an outgoing connection to the device, clean up the pairing |
| 214 // context since the pairing is done. The outgoing connection case is cleaned | 217 // context since the pairing is done. The outgoing connection case is cleaned |
| 215 // up in the callback for the underlying Pair() call. | 218 // up in the callback for the underlying Pair() call. |
| 216 if (!device_->IsConnecting()) | 219 if (!device_->IsConnecting()) |
| 217 device_->EndPairing(); | 220 device_->EndPairing(); |
| 218 } | 221 } |
| 219 | 222 |
| 220 bool BluetoothPairingChromeOS::RejectPairing() { | 223 bool BluetoothPairingChromeOS::RejectPairing() { |
| 221 return RunPairingCallbacks( | 224 return RunPairingCallbacks( |
| 222 BluetoothAgentServiceProvider::Delegate::REJECTED); | 225 bluez::BluetoothAgentServiceProvider::Delegate::REJECTED); |
| 223 } | 226 } |
| 224 | 227 |
| 225 bool BluetoothPairingChromeOS::CancelPairing() { | 228 bool BluetoothPairingChromeOS::CancelPairing() { |
| 226 return RunPairingCallbacks( | 229 return RunPairingCallbacks( |
| 227 BluetoothAgentServiceProvider::Delegate::CANCELLED); | 230 bluez::BluetoothAgentServiceProvider::Delegate::CANCELLED); |
| 228 } | 231 } |
| 229 | 232 |
| 230 BluetoothDevice::PairingDelegate* | 233 BluetoothDevice::PairingDelegate* |
| 231 BluetoothPairingChromeOS::GetPairingDelegate() const { | 234 BluetoothPairingChromeOS::GetPairingDelegate() const { |
| 232 return pairing_delegate_; | 235 return pairing_delegate_; |
| 233 } | 236 } |
| 234 | 237 |
| 235 void BluetoothPairingChromeOS::ResetCallbacks() { | 238 void BluetoothPairingChromeOS::ResetCallbacks() { |
| 236 pincode_callback_.Reset(); | 239 pincode_callback_.Reset(); |
| 237 passkey_callback_.Reset(); | 240 passkey_callback_.Reset(); |
| 238 confirmation_callback_.Reset(); | 241 confirmation_callback_.Reset(); |
| 239 } | 242 } |
| 240 | 243 |
| 241 bool BluetoothPairingChromeOS::RunPairingCallbacks( | 244 bool BluetoothPairingChromeOS::RunPairingCallbacks( |
| 242 BluetoothAgentServiceProvider::Delegate::Status status) { | 245 bluez::BluetoothAgentServiceProvider::Delegate::Status status) { |
| 243 pairing_delegate_used_ = true; | 246 pairing_delegate_used_ = true; |
| 244 | 247 |
| 245 bool callback_run = false; | 248 bool callback_run = false; |
| 246 if (!pincode_callback_.is_null()) { | 249 if (!pincode_callback_.is_null()) { |
| 247 pincode_callback_.Run(status, ""); | 250 pincode_callback_.Run(status, ""); |
| 248 pincode_callback_.Reset(); | 251 pincode_callback_.Reset(); |
| 249 callback_run = true; | 252 callback_run = true; |
| 250 } | 253 } |
| 251 | 254 |
| 252 if (!passkey_callback_.is_null()) { | 255 if (!passkey_callback_.is_null()) { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 264 // If this is not an outgoing connection to the device, clean up the pairing | 267 // If this is not an outgoing connection to the device, clean up the pairing |
| 265 // context since the pairing is done. The outgoing connection case is cleaned | 268 // context since the pairing is done. The outgoing connection case is cleaned |
| 266 // up in the callback for the underlying Pair() call. | 269 // up in the callback for the underlying Pair() call. |
| 267 if (!device_->IsConnecting()) | 270 if (!device_->IsConnecting()) |
| 268 device_->EndPairing(); | 271 device_->EndPairing(); |
| 269 | 272 |
| 270 return callback_run; | 273 return callback_run; |
| 271 } | 274 } |
| 272 | 275 |
| 273 } // namespace chromeos | 276 } // namespace chromeos |
| OLD | NEW |