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_bluez.h" | 5 #include "device/bluetooth/bluetooth_pairing_bluez.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_bluez.h" | 10 #include "device/bluetooth/bluetooth_device_bluez.h" |
(...skipping 10 matching lines...) Expand all Loading... |
21 UMA_PAIRING_METHOD_DISPLAY_PINCODE, | 21 UMA_PAIRING_METHOD_DISPLAY_PINCODE, |
22 UMA_PAIRING_METHOD_DISPLAY_PASSKEY, | 22 UMA_PAIRING_METHOD_DISPLAY_PASSKEY, |
23 UMA_PAIRING_METHOD_CONFIRM_PASSKEY, | 23 UMA_PAIRING_METHOD_CONFIRM_PASSKEY, |
24 // NOTE: Add new pairing methods immediately above this line. Make sure to | 24 // NOTE: Add new pairing methods immediately above this line. Make sure to |
25 // update the enum list in tools/histogram/histograms.xml accordingly. | 25 // update the enum list in tools/histogram/histograms.xml accordingly. |
26 UMA_PAIRING_METHOD_COUNT | 26 UMA_PAIRING_METHOD_COUNT |
27 }; | 27 }; |
28 | 28 |
29 // Number of keys that will be entered for a passkey, six digits plus the | 29 // Number of keys that will be entered for a passkey, six digits plus the |
30 // final enter. | 30 // final enter. |
31 const uint16 kPasskeyMaxKeysEntered = 7; | 31 const uint16_t kPasskeyMaxKeysEntered = 7; |
32 | 32 |
33 } // namespace | 33 } // namespace |
34 | 34 |
35 namespace bluez { | 35 namespace bluez { |
36 | 36 |
37 BluetoothPairingBlueZ::BluetoothPairingBlueZ( | 37 BluetoothPairingBlueZ::BluetoothPairingBlueZ( |
38 BluetoothDeviceBlueZ* device, | 38 BluetoothDeviceBlueZ* device, |
39 BluetoothDevice::PairingDelegate* pairing_delegate) | 39 BluetoothDevice::PairingDelegate* pairing_delegate) |
40 : device_(device), | 40 : device_(device), |
41 pairing_delegate_(pairing_delegate), | 41 pairing_delegate_(pairing_delegate), |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 ResetCallbacks(); | 128 ResetCallbacks(); |
129 passkey_callback_ = callback; | 129 passkey_callback_ = callback; |
130 pairing_delegate_used_ = true; | 130 pairing_delegate_used_ = true; |
131 pairing_delegate_->RequestPasskey(device_); | 131 pairing_delegate_->RequestPasskey(device_); |
132 } | 132 } |
133 | 133 |
134 bool BluetoothPairingBlueZ::ExpectingPasskey() const { | 134 bool BluetoothPairingBlueZ::ExpectingPasskey() const { |
135 return !passkey_callback_.is_null(); | 135 return !passkey_callback_.is_null(); |
136 } | 136 } |
137 | 137 |
138 void BluetoothPairingBlueZ::SetPasskey(uint32 passkey) { | 138 void BluetoothPairingBlueZ::SetPasskey(uint32_t passkey) { |
139 if (passkey_callback_.is_null()) | 139 if (passkey_callback_.is_null()) |
140 return; | 140 return; |
141 | 141 |
142 passkey_callback_.Run(bluez::BluetoothAgentServiceProvider::Delegate::SUCCESS, | 142 passkey_callback_.Run(bluez::BluetoothAgentServiceProvider::Delegate::SUCCESS, |
143 passkey); | 143 passkey); |
144 passkey_callback_.Reset(); | 144 passkey_callback_.Reset(); |
145 | 145 |
146 // If this is not an outgoing connection to the device, clean up the pairing | 146 // 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 | 147 // context since the pairing is done. The outgoing connection case is cleaned |
148 // up in the callback for the underlying Pair() call. | 148 // up in the callback for the underlying Pair() call. |
149 if (!device_->IsConnecting()) | 149 if (!device_->IsConnecting()) |
150 device_->EndPairing(); | 150 device_->EndPairing(); |
151 } | 151 } |
152 | 152 |
153 void BluetoothPairingBlueZ::DisplayPasskey(uint32 passkey) { | 153 void BluetoothPairingBlueZ::DisplayPasskey(uint32_t passkey) { |
154 UMA_HISTOGRAM_ENUMERATION("Bluetooth.PairingMethod", | 154 UMA_HISTOGRAM_ENUMERATION("Bluetooth.PairingMethod", |
155 UMA_PAIRING_METHOD_DISPLAY_PASSKEY, | 155 UMA_PAIRING_METHOD_DISPLAY_PASSKEY, |
156 UMA_PAIRING_METHOD_COUNT); | 156 UMA_PAIRING_METHOD_COUNT); |
157 | 157 |
158 ResetCallbacks(); | 158 ResetCallbacks(); |
159 pairing_delegate_used_ = true; | 159 pairing_delegate_used_ = true; |
160 pairing_delegate_->DisplayPasskey(device_, passkey); | 160 pairing_delegate_->DisplayPasskey(device_, passkey); |
161 } | 161 } |
162 | 162 |
163 void BluetoothPairingBlueZ::KeysEntered(uint16 entered) { | 163 void BluetoothPairingBlueZ::KeysEntered(uint16_t entered) { |
164 pairing_delegate_used_ = true; | 164 pairing_delegate_used_ = true; |
165 pairing_delegate_->KeysEntered(device_, entered); | 165 pairing_delegate_->KeysEntered(device_, entered); |
166 | 166 |
167 // If this is not an outgoing connection to the device, the pairing context | 167 // If this is not an outgoing connection to the device, the pairing context |
168 // needs to be cleaned up again as there's no reliable indication of | 168 // needs to be cleaned up again as there's no reliable indication of |
169 // completion of incoming pairing. | 169 // completion of incoming pairing. |
170 if (entered >= kPasskeyMaxKeysEntered && !device_->IsConnecting()) | 170 if (entered >= kPasskeyMaxKeysEntered && !device_->IsConnecting()) |
171 device_->EndPairing(); | 171 device_->EndPairing(); |
172 } | 172 } |
173 | 173 |
174 void BluetoothPairingBlueZ::RequestConfirmation( | 174 void BluetoothPairingBlueZ::RequestConfirmation( |
175 uint32 passkey, | 175 uint32_t passkey, |
176 const bluez::BluetoothAgentServiceProvider::Delegate::ConfirmationCallback& | 176 const bluez::BluetoothAgentServiceProvider::Delegate::ConfirmationCallback& |
177 callback) { | 177 callback) { |
178 UMA_HISTOGRAM_ENUMERATION("Bluetooth.PairingMethod", | 178 UMA_HISTOGRAM_ENUMERATION("Bluetooth.PairingMethod", |
179 UMA_PAIRING_METHOD_CONFIRM_PASSKEY, | 179 UMA_PAIRING_METHOD_CONFIRM_PASSKEY, |
180 UMA_PAIRING_METHOD_COUNT); | 180 UMA_PAIRING_METHOD_COUNT); |
181 | 181 |
182 ResetCallbacks(); | 182 ResetCallbacks(); |
183 confirmation_callback_ = callback; | 183 confirmation_callback_ = callback; |
184 pairing_delegate_used_ = true; | 184 pairing_delegate_used_ = true; |
185 pairing_delegate_->ConfirmPasskey(device_, passkey); | 185 pairing_delegate_->ConfirmPasskey(device_, passkey); |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
263 // If this is not an outgoing connection to the device, clean up the pairing | 263 // If this is not an outgoing connection to the device, clean up the pairing |
264 // context since the pairing is done. The outgoing connection case is cleaned | 264 // context since the pairing is done. The outgoing connection case is cleaned |
265 // up in the callback for the underlying Pair() call. | 265 // up in the callback for the underlying Pair() call. |
266 if (!device_->IsConnecting()) | 266 if (!device_->IsConnecting()) |
267 device_->EndPairing(); | 267 device_->EndPairing(); |
268 | 268 |
269 return callback_run; | 269 return callback_run; |
270 } | 270 } |
271 | 271 |
272 } // namespace bluez | 272 } // namespace bluez |
OLD | NEW |