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 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
67 | 67 |
68 pairing_delegate_ = NULL; | 68 pairing_delegate_ = NULL; |
69 } | 69 } |
70 | 70 |
71 void BluetoothPairingChromeOS::RequestPinCode( | 71 void BluetoothPairingChromeOS::RequestPinCode( |
72 const BluetoothAgentServiceProvider::Delegate::PinCodeCallback& callback) { | 72 const BluetoothAgentServiceProvider::Delegate::PinCodeCallback& callback) { |
73 UMA_HISTOGRAM_ENUMERATION("Bluetooth.PairingMethod", | 73 UMA_HISTOGRAM_ENUMERATION("Bluetooth.PairingMethod", |
74 UMA_PAIRING_METHOD_REQUEST_PINCODE, | 74 UMA_PAIRING_METHOD_REQUEST_PINCODE, |
75 UMA_PAIRING_METHOD_COUNT); | 75 UMA_PAIRING_METHOD_COUNT); |
76 | 76 |
77 DCHECK(pincode_callback_.is_null()); | 77 ResetCallbacks(); |
78 pincode_callback_ = callback; | 78 pincode_callback_ = callback; |
79 pairing_delegate_used_ = true; | |
79 pairing_delegate_->RequestPinCode(device_); | 80 pairing_delegate_->RequestPinCode(device_); |
80 pairing_delegate_used_ = true; | |
81 } | 81 } |
82 | 82 |
83 bool BluetoothPairingChromeOS::ExpectingPinCode() const { | 83 bool BluetoothPairingChromeOS::ExpectingPinCode() const { |
84 return !pincode_callback_.is_null(); | 84 return !pincode_callback_.is_null(); |
85 } | 85 } |
86 | 86 |
87 void BluetoothPairingChromeOS::SetPinCode(const std::string& pincode) { | 87 void BluetoothPairingChromeOS::SetPinCode(const std::string& pincode) { |
88 if (pincode_callback_.is_null()) | 88 if (pincode_callback_.is_null()) |
89 return; | 89 return; |
90 | 90 |
91 pincode_callback_.Run(BluetoothAgentServiceProvider::Delegate::SUCCESS, | 91 pincode_callback_.Run(BluetoothAgentServiceProvider::Delegate::SUCCESS, |
92 pincode); | 92 pincode); |
93 pincode_callback_.Reset(); | 93 pincode_callback_.Reset(); |
94 | 94 |
95 // If this is not an outgoing connection to the device, clean up the pairing | 95 // If this is not an outgoing connection to the device, clean up the pairing |
96 // context since the pairing is done. The outgoing connection case is cleaned | 96 // context since the pairing is done. The outgoing connection case is cleaned |
97 // up in the callback for the underlying Pair() call. | 97 // up in the callback for the underlying Pair() call. |
98 if (!device_->IsConnecting()) | 98 if (!device_->IsConnecting()) |
99 device_->EndPairing(); | 99 device_->EndPairing(); |
100 } | 100 } |
101 | 101 |
102 void BluetoothPairingChromeOS::DisplayPinCode(const std::string& pincode) { | 102 void BluetoothPairingChromeOS::DisplayPinCode(const std::string& pincode) { |
103 UMA_HISTOGRAM_ENUMERATION("Bluetooth.PairingMethod", | 103 UMA_HISTOGRAM_ENUMERATION("Bluetooth.PairingMethod", |
104 UMA_PAIRING_METHOD_DISPLAY_PINCODE, | 104 UMA_PAIRING_METHOD_DISPLAY_PINCODE, |
105 UMA_PAIRING_METHOD_COUNT); | 105 UMA_PAIRING_METHOD_COUNT); |
106 | 106 |
107 ResetCallbacks(); | |
108 pairing_delegate_used_ = true; | |
107 pairing_delegate_->DisplayPinCode(device_, pincode); | 109 pairing_delegate_->DisplayPinCode(device_, pincode); |
108 pairing_delegate_used_ = true; | |
109 | 110 |
110 // If this is not an outgoing connection to the device, the pairing context | 111 // If this is not an outgoing connection to the device, the pairing context |
111 // needs to be cleaned up again as there's no reliable indication of | 112 // needs to be cleaned up again as there's no reliable indication of |
112 // completion of incoming pairing. | 113 // completion of incoming pairing. |
113 if (!device_->IsConnecting()) | 114 if (!device_->IsConnecting()) |
114 device_->EndPairing(); | 115 device_->EndPairing(); |
115 } | 116 } |
116 | 117 |
117 void BluetoothPairingChromeOS::RequestPasskey( | 118 void BluetoothPairingChromeOS::RequestPasskey( |
118 const BluetoothAgentServiceProvider::Delegate::PasskeyCallback& callback) { | 119 const BluetoothAgentServiceProvider::Delegate::PasskeyCallback& callback) { |
119 UMA_HISTOGRAM_ENUMERATION("Bluetooth.PairingMethod", | 120 UMA_HISTOGRAM_ENUMERATION("Bluetooth.PairingMethod", |
120 UMA_PAIRING_METHOD_REQUEST_PASSKEY, | 121 UMA_PAIRING_METHOD_REQUEST_PASSKEY, |
121 UMA_PAIRING_METHOD_COUNT); | 122 UMA_PAIRING_METHOD_COUNT); |
122 | 123 |
123 DCHECK(passkey_callback_.is_null()); | 124 ResetCallbacks(); |
124 passkey_callback_ = callback; | 125 passkey_callback_ = callback; |
126 pairing_delegate_used_ = true; | |
125 pairing_delegate_->RequestPasskey(device_); | 127 pairing_delegate_->RequestPasskey(device_); |
126 pairing_delegate_used_ = true; | |
127 } | 128 } |
128 | 129 |
129 bool BluetoothPairingChromeOS::ExpectingPasskey() const { | 130 bool BluetoothPairingChromeOS::ExpectingPasskey() const { |
130 return !passkey_callback_.is_null(); | 131 return !passkey_callback_.is_null(); |
131 } | 132 } |
132 | 133 |
133 void BluetoothPairingChromeOS::SetPasskey(uint32 passkey) { | 134 void BluetoothPairingChromeOS::SetPasskey(uint32 passkey) { |
134 if (passkey_callback_.is_null()) | 135 if (passkey_callback_.is_null()) |
135 return; | 136 return; |
136 | 137 |
137 passkey_callback_.Run(BluetoothAgentServiceProvider::Delegate::SUCCESS, | 138 passkey_callback_.Run(BluetoothAgentServiceProvider::Delegate::SUCCESS, |
138 passkey); | 139 passkey); |
139 passkey_callback_.Reset(); | 140 passkey_callback_.Reset(); |
140 | 141 |
141 // If this is not an outgoing connection to the device, clean up the pairing | 142 // If this is not an outgoing connection to the device, clean up the pairing |
142 // context since the pairing is done. The outgoing connection case is cleaned | 143 // context since the pairing is done. The outgoing connection case is cleaned |
143 // up in the callback for the underlying Pair() call. | 144 // up in the callback for the underlying Pair() call. |
144 if (!device_->IsConnecting()) | 145 if (!device_->IsConnecting()) |
145 device_->EndPairing(); | 146 device_->EndPairing(); |
146 } | 147 } |
147 | 148 |
148 void BluetoothPairingChromeOS::DisplayPasskey(uint32 passkey) { | 149 void BluetoothPairingChromeOS::DisplayPasskey(uint32 passkey) { |
149 UMA_HISTOGRAM_ENUMERATION("Bluetooth.PairingMethod", | 150 UMA_HISTOGRAM_ENUMERATION("Bluetooth.PairingMethod", |
150 UMA_PAIRING_METHOD_DISPLAY_PASSKEY, | 151 UMA_PAIRING_METHOD_DISPLAY_PASSKEY, |
151 UMA_PAIRING_METHOD_COUNT); | 152 UMA_PAIRING_METHOD_COUNT); |
152 | 153 |
154 ResetCallbacks(); | |
155 pairing_delegate_used_ = true; | |
156 pairing_delegate_->DisplayPasskey(device_, passkey); | |
153 | 157 |
154 pairing_delegate_->DisplayPasskey(device_, passkey); | 158 } |
159 | |
160 void BluetoothPairingChromeOS::KeysEntered(uint16 entered) { | |
155 pairing_delegate_used_ = true; | 161 pairing_delegate_used_ = true; |
162 pairing_delegate_->KeysEntered(device_, entered); | |
156 | 163 |
157 // If this is not an outgoing connection to the device, the pairing context | 164 // If this is not an outgoing connection to the device, the pairing context |
158 // needs to be cleaned up again as there's no reliable indication of | 165 // needs to be cleaned up again as there's no reliable indication of |
159 // completion of incoming pairing. | 166 // completion of incoming pairing. |
160 if (!device_->IsConnecting()) | 167 if (entered > 6 && !device_->IsConnecting()) |
stevenjb
2014/02/28 21:40:54
const for 6
keybuk
2014/02/28 22:28:54
Done.
| |
161 device_->EndPairing(); | 168 device_->EndPairing(); |
162 } | 169 } |
163 | 170 |
164 void BluetoothPairingChromeOS::KeysEntered(uint16 entered) { | |
165 pairing_delegate_->KeysEntered(device_, entered); | |
166 pairing_delegate_used_ = true; | |
167 } | |
168 | |
169 void BluetoothPairingChromeOS::RequestConfirmation( | 171 void BluetoothPairingChromeOS::RequestConfirmation( |
170 uint32 passkey, | 172 uint32 passkey, |
171 const BluetoothAgentServiceProvider::Delegate::ConfirmationCallback& | 173 const BluetoothAgentServiceProvider::Delegate::ConfirmationCallback& |
172 callback) { | 174 callback) { |
173 UMA_HISTOGRAM_ENUMERATION("Bluetooth.PairingMethod", | 175 UMA_HISTOGRAM_ENUMERATION("Bluetooth.PairingMethod", |
174 UMA_PAIRING_METHOD_CONFIRM_PASSKEY, | 176 UMA_PAIRING_METHOD_CONFIRM_PASSKEY, |
175 UMA_PAIRING_METHOD_COUNT); | 177 UMA_PAIRING_METHOD_COUNT); |
176 | 178 |
177 DCHECK(confirmation_callback_.is_null()); | 179 ResetCallbacks(); |
178 confirmation_callback_ = callback; | 180 confirmation_callback_ = callback; |
181 pairing_delegate_used_ = true; | |
179 pairing_delegate_->ConfirmPasskey(device_, passkey); | 182 pairing_delegate_->ConfirmPasskey(device_, passkey); |
180 pairing_delegate_used_ = true; | |
181 } | 183 } |
182 | 184 |
183 void BluetoothPairingChromeOS::RequestAuthorization( | 185 void BluetoothPairingChromeOS::RequestAuthorization( |
184 const BluetoothAgentServiceProvider::Delegate::ConfirmationCallback& | 186 const BluetoothAgentServiceProvider::Delegate::ConfirmationCallback& |
185 callback) { | 187 callback) { |
186 UMA_HISTOGRAM_ENUMERATION("Bluetooth.PairingMethod", | 188 UMA_HISTOGRAM_ENUMERATION("Bluetooth.PairingMethod", |
187 UMA_PAIRING_METHOD_NONE, | 189 UMA_PAIRING_METHOD_NONE, |
188 UMA_PAIRING_METHOD_COUNT); | 190 UMA_PAIRING_METHOD_COUNT); |
189 | 191 |
190 DCHECK(confirmation_callback_.is_null()); | 192 ResetCallbacks(); |
191 confirmation_callback_ = callback; | 193 confirmation_callback_ = callback; |
194 pairing_delegate_used_ = true; | |
192 pairing_delegate_->AuthorizePairing(device_); | 195 pairing_delegate_->AuthorizePairing(device_); |
193 pairing_delegate_used_ = true; | |
194 } | 196 } |
195 | 197 |
196 bool BluetoothPairingChromeOS::ExpectingConfirmation() const { | 198 bool BluetoothPairingChromeOS::ExpectingConfirmation() const { |
197 return !confirmation_callback_.is_null(); | 199 return !confirmation_callback_.is_null(); |
198 } | 200 } |
199 | 201 |
200 void BluetoothPairingChromeOS::ConfirmPairing() { | 202 void BluetoothPairingChromeOS::ConfirmPairing() { |
201 if (confirmation_callback_.is_null()) | 203 if (confirmation_callback_.is_null()) |
202 return; | 204 return; |
203 | 205 |
(...skipping 15 matching lines...) Expand all Loading... | |
219 bool BluetoothPairingChromeOS::CancelPairing() { | 221 bool BluetoothPairingChromeOS::CancelPairing() { |
220 return RunPairingCallbacks( | 222 return RunPairingCallbacks( |
221 BluetoothAgentServiceProvider::Delegate::CANCELLED); | 223 BluetoothAgentServiceProvider::Delegate::CANCELLED); |
222 } | 224 } |
223 | 225 |
224 BluetoothDevice::PairingDelegate* | 226 BluetoothDevice::PairingDelegate* |
225 BluetoothPairingChromeOS::GetPairingDelegate() const { | 227 BluetoothPairingChromeOS::GetPairingDelegate() const { |
226 return pairing_delegate_; | 228 return pairing_delegate_; |
227 } | 229 } |
228 | 230 |
231 void BluetoothPairingChromeOS::ResetCallbacks() { | |
232 pincode_callback_.Reset(); | |
233 passkey_callback_.Reset(); | |
234 confirmation_callback_.Reset(); | |
235 } | |
236 | |
229 bool BluetoothPairingChromeOS::RunPairingCallbacks( | 237 bool BluetoothPairingChromeOS::RunPairingCallbacks( |
230 BluetoothAgentServiceProvider::Delegate::Status status) { | 238 BluetoothAgentServiceProvider::Delegate::Status status) { |
231 pairing_delegate_used_ = true; | 239 pairing_delegate_used_ = true; |
232 | 240 |
233 bool callback_run = false; | 241 bool callback_run = false; |
234 if (!pincode_callback_.is_null()) { | 242 if (!pincode_callback_.is_null()) { |
235 pincode_callback_.Run(status, ""); | 243 pincode_callback_.Run(status, ""); |
236 pincode_callback_.Reset(); | 244 pincode_callback_.Reset(); |
237 callback_run = true; | 245 callback_run = true; |
238 } | 246 } |
(...skipping 13 matching lines...) Expand all Loading... | |
252 // If this is not an outgoing connection to the device, clean up the pairing | 260 // If this is not an outgoing connection to the device, clean up the pairing |
253 // context since the pairing is done. The outgoing connection case is cleaned | 261 // context since the pairing is done. The outgoing connection case is cleaned |
254 // up in the callback for the underlying Pair() call. | 262 // up in the callback for the underlying Pair() call. |
255 if (!device_->IsConnecting()) | 263 if (!device_->IsConnecting()) |
256 device_->EndPairing(); | 264 device_->EndPairing(); |
257 | 265 |
258 return callback_run; | 266 return callback_run; |
259 } | 267 } |
260 | 268 |
261 } // namespace chromeos | 269 } // namespace chromeos |
OLD | NEW |