OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "device/bluetooth/bluetooth_device_experimental_chromeos.h" | |
6 | |
7 #include "base/bind.h" | |
8 #include "chromeos/dbus/dbus_thread_manager.h" | |
9 #include "chromeos/dbus/experimental_bluetooth_adapter_client.h" | |
10 #include "chromeos/dbus/experimental_bluetooth_agent_manager_client.h" | |
11 #include "chromeos/dbus/experimental_bluetooth_agent_service_provider.h" | |
12 #include "chromeos/dbus/experimental_bluetooth_device_client.h" | |
13 #include "dbus/bus.h" | |
14 #include "device/bluetooth/bluetooth_adapter_experimental_chromeos.h" | |
15 #include "device/bluetooth/bluetooth_socket.h" | |
16 #include "third_party/cros_system_api/dbus/service_constants.h" | |
17 | |
18 using device::BluetoothDevice; | |
19 | |
20 namespace { | |
21 | |
22 // The agent path is relativel meaningless since BlueZ only supports one | |
youngki
2013/04/16 15:26:56
s/relativel/relatively/
keybuk
2013/04/16 23:19:13
Done.
| |
23 // at time and will fail an attempt to register another with "Already Exists" | |
youngki
2013/04/16 15:26:56
s/fail an attempt/fail in an attempt/
keybuk
2013/04/16 23:19:13
Done.
| |
24 // (which we fail in OnRegisterAgentError with ERROR_INPROGRESS). | |
25 const dbus::ObjectPath kAgentPath("/org/chromium/bluetooth_agent"); | |
satorux1
2013/04/16 06:30:45
like haruki mentioned, please use const char
keybuk
2013/04/16 23:19:13
Done.
| |
26 | |
27 // The capability of our agents. | |
28 const char* kAgentCapability = | |
satorux1
2013/04/16 06:30:45
Can this be defined at a compilation time? otherwi
keybuk
2013/04/16 23:19:13
No
I'll drop this variable entirely and use the o
| |
29 bluetooth_agent_manager::kKeyboardDisplayCapability; | |
30 | |
31 } // namespace | |
32 | |
33 namespace chromeos { | |
34 | |
35 BluetoothDeviceExperimentalChromeOS::BluetoothDeviceExperimentalChromeOS( | |
36 BluetoothAdapterExperimentalChromeOS* adapter, | |
37 const dbus::ObjectPath& object_path) | |
38 : adapter_(adapter), | |
39 object_path_(object_path), | |
40 connecting_calls_(0), | |
41 pairing_delegate_(NULL), | |
42 weak_ptr_factory_(this) { | |
43 } | |
44 | |
45 BluetoothDeviceExperimentalChromeOS::~BluetoothDeviceExperimentalChromeOS() { | |
46 } | |
47 | |
48 uint32 BluetoothDeviceExperimentalChromeOS::GetBluetoothClass() const { | |
49 ExperimentalBluetoothDeviceClient::Properties* properties = | |
50 DBusThreadManager::Get()->GetExperimentalBluetoothDeviceClient()-> | |
51 GetProperties(object_path_); | |
52 DCHECK(properties); | |
53 | |
54 return properties->bluetooth_class.value(); | |
55 } | |
56 | |
57 std::string BluetoothDeviceExperimentalChromeOS::GetDeviceName() const { | |
58 ExperimentalBluetoothDeviceClient::Properties* properties = | |
59 DBusThreadManager::Get()->GetExperimentalBluetoothDeviceClient()-> | |
60 GetProperties(object_path_); | |
61 DCHECK(properties); | |
62 | |
63 return properties->alias.value(); | |
64 } | |
65 | |
66 std::string BluetoothDeviceExperimentalChromeOS::GetAddress() const { | |
67 ExperimentalBluetoothDeviceClient::Properties* properties = | |
68 DBusThreadManager::Get()->GetExperimentalBluetoothDeviceClient()-> | |
69 GetProperties(object_path_); | |
70 DCHECK(properties); | |
71 | |
72 return properties->address.value(); | |
73 } | |
74 | |
75 bool BluetoothDeviceExperimentalChromeOS::IsPaired() const { | |
76 ExperimentalBluetoothDeviceClient::Properties* properties = | |
77 DBusThreadManager::Get()->GetExperimentalBluetoothDeviceClient()-> | |
78 GetProperties(object_path_); | |
79 DCHECK(properties); | |
80 | |
81 return properties->paired.value(); | |
82 } | |
83 | |
84 bool BluetoothDeviceExperimentalChromeOS::IsConnected() const { | |
85 ExperimentalBluetoothDeviceClient::Properties* properties = | |
86 DBusThreadManager::Get()->GetExperimentalBluetoothDeviceClient()-> | |
87 GetProperties(object_path_); | |
88 DCHECK(properties); | |
89 | |
90 return properties->connected.value(); | |
91 } | |
92 | |
93 bool BluetoothDeviceExperimentalChromeOS::IsConnectable() const { | |
94 // TODO(deymo): implement | |
95 return false; | |
96 } | |
97 | |
98 bool BluetoothDeviceExperimentalChromeOS::IsConnecting() const { | |
99 return connecting_calls_ > 0; | |
100 } | |
101 | |
102 BluetoothDeviceExperimentalChromeOS::ServiceList | |
103 BluetoothDeviceExperimentalChromeOS::GetServices() const { | |
104 ExperimentalBluetoothDeviceClient::Properties* properties = | |
105 DBusThreadManager::Get()->GetExperimentalBluetoothDeviceClient()-> | |
106 GetProperties(object_path_); | |
107 DCHECK(properties); | |
108 | |
109 return properties->uuids.value(); | |
110 } | |
111 | |
112 void BluetoothDeviceExperimentalChromeOS::GetServiceRecords( | |
113 const ServiceRecordsCallback& callback, | |
114 const ErrorCallback& error_callback) { | |
115 // TODO(keybuk): not implemented; remove | |
116 error_callback.Run(); | |
117 } | |
118 | |
119 void BluetoothDeviceExperimentalChromeOS::ProvidesServiceWithName( | |
120 const std::string& name, | |
121 const ProvidesServiceCallback& callback) { | |
122 // TODO(keybuk): not implemented; remove | |
123 callback.Run(false); | |
124 } | |
125 | |
126 bool BluetoothDeviceExperimentalChromeOS::ExpectingPinCode() const { | |
127 return !pincode_callback_.is_null(); | |
128 } | |
129 | |
130 bool BluetoothDeviceExperimentalChromeOS::ExpectingPasskey() const { | |
131 return !passkey_callback_.is_null(); | |
132 } | |
133 | |
134 bool BluetoothDeviceExperimentalChromeOS::ExpectingConfirmation() const { | |
135 return !confirmation_callback_.is_null(); | |
136 } | |
137 | |
138 void BluetoothDeviceExperimentalChromeOS::Connect( | |
139 BluetoothDevice::PairingDelegate* pairing_delegate, | |
140 const base::Closure& callback, | |
141 const ConnectErrorCallback& error_callback) { | |
142 ++connecting_calls_; | |
143 VLOG(1) << object_path_.value() << ": Connecting, " << connecting_calls_ | |
144 << " in progress"; | |
145 | |
146 if (IsPaired() || IsConnected() || !pairing_delegate) { | |
147 // No need to pair, skip straight to connection. | |
148 ConnectInternal(callback, error_callback); | |
149 | |
youngki
2013/04/16 15:26:56
Remove the extra line. Or, we could early-return h
keybuk
2013/04/16 23:19:13
Done.
Leaving the if/else because we've had three
| |
150 } else { | |
151 // Initiate high-security connection with pairing. | |
152 DCHECK(!pairing_delegate_); | |
153 DCHECK(agent_.get() == NULL); | |
154 | |
155 pairing_delegate_ = pairing_delegate; | |
156 | |
157 // The agent path is relatively meaningless since BlueZ only supports | |
158 // one per application at a time. | |
159 dbus::Bus* system_bus = DBusThreadManager::Get()->GetSystemBus(); | |
160 agent_.reset(ExperimentalBluetoothAgentServiceProvider::Create( | |
161 system_bus, kAgentPath, this)); | |
162 DCHECK(agent_.get()); | |
163 | |
164 VLOG(1) << object_path_.value() << ": Registering agent for pairing"; | |
165 DBusThreadManager::Get()->GetExperimentalBluetoothAgentManagerClient()-> | |
166 RegisterAgent( | |
167 kAgentPath, | |
168 kAgentCapability, | |
169 base::Bind( | |
170 &BluetoothDeviceExperimentalChromeOS::OnRegisterAgent, | |
171 weak_ptr_factory_.GetWeakPtr(), | |
172 callback, error_callback), | |
youngki
2013/04/16 15:26:56
one argument per line: http://dev.chromium.org/dev
keybuk
2013/04/16 23:19:13
Done.
| |
173 base::Bind( | |
174 &BluetoothDeviceExperimentalChromeOS::OnRegisterAgentError, | |
175 weak_ptr_factory_.GetWeakPtr(), | |
176 error_callback)); | |
177 } | |
178 } | |
179 | |
180 void BluetoothDeviceExperimentalChromeOS::SetPinCode( | |
181 const std::string& pincode) { | |
182 if (!agent_.get() || pincode_callback_.is_null()) | |
183 return; | |
184 | |
185 pincode_callback_.Run(SUCCESS, pincode); | |
186 pincode_callback_.Reset(); | |
187 } | |
188 | |
189 void BluetoothDeviceExperimentalChromeOS::SetPasskey(uint32 passkey) { | |
190 if (!agent_.get() || passkey_callback_.is_null()) | |
191 return; | |
192 | |
193 passkey_callback_.Run(SUCCESS, passkey); | |
194 passkey_callback_.Reset(); | |
195 } | |
196 | |
197 void BluetoothDeviceExperimentalChromeOS::ConfirmPairing() { | |
198 if (!agent_.get() || confirmation_callback_.is_null()) | |
199 return; | |
200 | |
201 confirmation_callback_.Run(SUCCESS); | |
202 confirmation_callback_.Reset(); | |
203 } | |
204 | |
205 void BluetoothDeviceExperimentalChromeOS::RejectPairing() { | |
206 if (!agent_.get()) | |
207 return; | |
208 | |
209 if (!pincode_callback_.is_null()) { | |
210 pincode_callback_.Run(REJECTED, ""); | |
211 pincode_callback_.Reset(); | |
212 } | |
213 if (!passkey_callback_.is_null()) { | |
214 passkey_callback_.Run(REJECTED, 0); | |
215 passkey_callback_.Reset(); | |
216 } | |
217 if (!confirmation_callback_.is_null()) { | |
218 confirmation_callback_.Run(REJECTED); | |
219 confirmation_callback_.Reset(); | |
220 } | |
221 } | |
222 | |
223 void BluetoothDeviceExperimentalChromeOS::CancelPairing() { | |
224 bool have_callback = false; | |
225 if (agent_.get()) { | |
youngki
2013/04/16 15:26:56
The next 15 lines look very similar to RejectPairi
keybuk
2013/04/16 23:19:13
Done.
| |
226 if (!pincode_callback_.is_null()) { | |
227 pincode_callback_.Run(CANCELLED, ""); | |
228 pincode_callback_.Reset(); | |
229 have_callback = true; | |
230 } | |
231 if (!passkey_callback_.is_null()) { | |
232 passkey_callback_.Run(CANCELLED, 0); | |
233 passkey_callback_.Reset(); | |
234 have_callback = true; | |
235 } | |
236 if (!confirmation_callback_.is_null()) { | |
237 confirmation_callback_.Run(CANCELLED); | |
238 confirmation_callback_.Reset(); | |
239 have_callback = true; | |
240 } | |
241 } | |
242 | |
243 // If there wasn't a callback in progress that we can reply to then we | |
244 // have to send a CancelPairing() to the device instead. | |
245 if (!have_callback) { | |
246 DBusThreadManager::Get()->GetExperimentalBluetoothDeviceClient()-> | |
247 CancelPairing( | |
248 object_path_, | |
249 base::Bind(&base::DoNothing), | |
250 base::Bind( | |
251 &BluetoothDeviceExperimentalChromeOS::OnCancelPairingError, | |
252 weak_ptr_factory_.GetWeakPtr())); | |
253 } | |
254 } | |
255 | |
256 void BluetoothDeviceExperimentalChromeOS::Disconnect( | |
257 const base::Closure& callback, | |
258 const ErrorCallback& error_callback) { | |
259 VLOG(1) << object_path_.value() << ": Disconnecting"; | |
260 DBusThreadManager::Get()->GetExperimentalBluetoothDeviceClient()-> | |
261 Disconnect( | |
262 object_path_, | |
263 base::Bind( | |
264 &BluetoothDeviceExperimentalChromeOS::OnDisconnect, | |
265 weak_ptr_factory_.GetWeakPtr(), | |
266 callback), | |
267 base::Bind( | |
268 &BluetoothDeviceExperimentalChromeOS::OnDisconnectError, | |
269 weak_ptr_factory_.GetWeakPtr(), | |
270 error_callback)); | |
271 } | |
272 | |
273 void BluetoothDeviceExperimentalChromeOS::Forget( | |
274 const ErrorCallback& error_callback) { | |
275 VLOG(1) << object_path_.value() << ": Removing device"; | |
276 DBusThreadManager::Get()->GetExperimentalBluetoothAdapterClient()-> | |
277 RemoveDevice( | |
278 adapter_->object_path_, | |
279 object_path_, | |
280 base::Bind(&base::DoNothing), | |
281 base::Bind( | |
282 &BluetoothDeviceExperimentalChromeOS::OnForgetError, | |
283 weak_ptr_factory_.GetWeakPtr(), | |
284 error_callback)); | |
285 } | |
286 | |
287 void BluetoothDeviceExperimentalChromeOS::ConnectToService( | |
288 const std::string& service_uuid, | |
289 const SocketCallback& callback) { | |
290 // TODO(keybuk): implement | |
291 callback.Run(scoped_refptr<device::BluetoothSocket>()); | |
292 } | |
293 | |
294 void BluetoothDeviceExperimentalChromeOS::ConnectToProfile( | |
295 device::BluetoothProfile* profile, | |
296 const ErrorCallback& error_callback) { | |
297 // TODO(keybuk): implement | |
298 error_callback.Run(); | |
299 } | |
300 | |
301 void BluetoothDeviceExperimentalChromeOS::SetOutOfBandPairingData( | |
302 const device::BluetoothOutOfBandPairingData& data, | |
303 const base::Closure& callback, | |
304 const ErrorCallback& error_callback) { | |
305 // TODO(keybuk): implement | |
306 error_callback.Run(); | |
307 } | |
308 | |
309 void BluetoothDeviceExperimentalChromeOS::ClearOutOfBandPairingData( | |
310 const base::Closure& callback, | |
311 const ErrorCallback& error_callback) { | |
312 // TODO(keybuk): implement | |
313 error_callback.Run(); | |
314 } | |
315 | |
316 | |
317 void BluetoothDeviceExperimentalChromeOS::Release() { | |
318 DCHECK(agent_.get()); | |
319 DCHECK(pairing_delegate_); | |
320 VLOG(1) << object_path_.value() << ": Release"; | |
321 | |
322 pincode_callback_.Reset(); | |
323 passkey_callback_.Reset(); | |
324 confirmation_callback_.Reset(); | |
325 | |
326 UnregisterAgent(); | |
327 } | |
328 | |
329 void BluetoothDeviceExperimentalChromeOS::RequestPinCode( | |
330 const dbus::ObjectPath& device_path, | |
331 const PinCodeCallback& callback) { | |
332 DCHECK(agent_.get()); | |
333 DCHECK(device_path == object_path_); | |
334 VLOG(1) << object_path_.value() << ": RequestPinCode"; | |
335 | |
336 DCHECK(pairing_delegate_); | |
337 DCHECK(pincode_callback_.is_null()); | |
338 pincode_callback_ = callback; | |
339 pairing_delegate_->RequestPinCode(this); | |
340 } | |
341 | |
342 void BluetoothDeviceExperimentalChromeOS::DisplayPinCode( | |
343 const dbus::ObjectPath& device_path, | |
344 const std::string& pincode) { | |
345 DCHECK(agent_.get()); | |
346 DCHECK(device_path == object_path_); | |
347 VLOG(1) << object_path_.value() << ": DisplayPinCode: " << pincode; | |
348 | |
349 DCHECK(pairing_delegate_); | |
350 pairing_delegate_->DisplayPinCode(this, pincode); | |
351 } | |
352 | |
353 void BluetoothDeviceExperimentalChromeOS::RequestPasskey( | |
354 const dbus::ObjectPath& device_path, | |
355 const PasskeyCallback& callback) { | |
356 DCHECK(agent_.get()); | |
357 DCHECK(device_path == object_path_); | |
358 VLOG(1) << object_path_.value() << ": RequestPasskey"; | |
359 | |
360 DCHECK(pairing_delegate_); | |
361 DCHECK(passkey_callback_.is_null()); | |
362 passkey_callback_ = callback; | |
363 pairing_delegate_->RequestPasskey(this); | |
364 } | |
365 | |
366 void BluetoothDeviceExperimentalChromeOS::DisplayPasskey( | |
367 const dbus::ObjectPath& device_path, | |
368 uint32 passkey, int16 entered) { | |
369 DCHECK(agent_.get()); | |
370 DCHECK(device_path == object_path_); | |
371 VLOG(1) << object_path_.value() << ": DisplayPasskey: " << passkey | |
372 << " (" << entered << " entered)"; | |
373 | |
374 // TODO(keybuk): disambiguate entered vs display | |
375 if (entered > 0) | |
376 return; | |
377 | |
378 DCHECK(pairing_delegate_); | |
379 pairing_delegate_->DisplayPasskey(this, passkey); | |
380 } | |
381 | |
382 void BluetoothDeviceExperimentalChromeOS::RequestConfirmation( | |
383 const dbus::ObjectPath& device_path, | |
384 uint32 passkey, | |
385 const ConfirmationCallback& callback) { | |
386 DCHECK(agent_.get()); | |
387 DCHECK(device_path == object_path_); | |
388 VLOG(1) << object_path_.value() << ": RequestConfirmation: " << passkey; | |
389 | |
390 DCHECK(pairing_delegate_); | |
391 DCHECK(confirmation_callback_.is_null()); | |
392 confirmation_callback_ = callback; | |
393 pairing_delegate_->ConfirmPasskey(this, passkey); | |
394 } | |
395 | |
396 void BluetoothDeviceExperimentalChromeOS::RequestAuthorization( | |
397 const dbus::ObjectPath& device_path, | |
398 const ConfirmationCallback& callback) { | |
399 // TODO(keybuk): implement | |
400 callback.Run(CANCELLED); | |
401 } | |
402 | |
403 void BluetoothDeviceExperimentalChromeOS::AuthorizeService( | |
404 const dbus::ObjectPath& device_path, | |
405 const std::string& uuid, | |
406 const ConfirmationCallback& callback) { | |
407 // TODO(keybuk): implement | |
408 callback.Run(CANCELLED); | |
409 } | |
410 | |
411 void BluetoothDeviceExperimentalChromeOS::Cancel() { | |
412 DCHECK(agent_.get()); | |
413 VLOG(1) << object_path_.value() << ": Cancel"; | |
414 | |
415 DCHECK(pairing_delegate_); | |
416 pairing_delegate_->DismissDisplayOrConfirm(); | |
417 } | |
418 | |
419 void BluetoothDeviceExperimentalChromeOS::ConnectInternal( | |
420 const base::Closure& callback, | |
421 const ConnectErrorCallback& error_callback) { | |
422 VLOG(1) << object_path_.value() << ": Connecting"; | |
423 DBusThreadManager::Get()->GetExperimentalBluetoothDeviceClient()-> | |
424 Connect( | |
425 object_path_, | |
426 base::Bind( | |
427 &BluetoothDeviceExperimentalChromeOS::OnConnect, | |
428 weak_ptr_factory_.GetWeakPtr(), | |
429 callback), | |
430 base::Bind( | |
431 &BluetoothDeviceExperimentalChromeOS::OnConnectError, | |
432 weak_ptr_factory_.GetWeakPtr(), | |
433 error_callback)); | |
434 } | |
435 | |
436 void BluetoothDeviceExperimentalChromeOS::OnConnect( | |
437 const base::Closure& callback) { | |
438 --connecting_calls_; | |
youngki
2013/04/16 15:26:56
Can we put DCHECK(connecting_calls >= 0)?
keybuk
2013/04/16 23:19:13
Done.
| |
439 VLOG(1) << object_path_.value() << ": Connected, " << connecting_calls_ | |
440 << " still in progress"; | |
441 | |
442 callback.Run(); | |
443 } | |
444 | |
445 void BluetoothDeviceExperimentalChromeOS::OnConnectError( | |
446 const ConnectErrorCallback& error_callback, | |
447 const std::string& error_name, | |
448 const std::string& error_message) { | |
449 --connecting_calls_; | |
youngki
2013/04/16 15:26:56
Can we put DCHECK(connecting_calls >= 0)?
keybuk
2013/04/16 23:19:13
Done.
| |
450 LOG(WARNING) << object_path_.value() << ": Failed to connect device: " | |
451 << error_name << ": " << error_message; | |
452 VLOG(1) << object_path_.value() << ": " << connecting_calls_ | |
453 << " still in progress"; | |
454 | |
455 // Determine the error code from error_name. | |
456 ConnectErrorCode error_code = ERROR_UNKNOWN; | |
457 if (error_name == bluetooth_adapter::kErrorFailed) { | |
458 error_code = ERROR_FAILED; | |
459 } else if (error_name == bluetooth_adapter::kErrorInProgress) { | |
460 error_code = ERROR_INPROGRESS; | |
461 } else if (error_name == bluetooth_adapter::kErrorNotSupported) { | |
462 error_code = ERROR_UNSUPPORTED_DEVICE; | |
463 } | |
464 | |
465 error_callback.Run(error_code); | |
466 } | |
467 | |
468 void BluetoothDeviceExperimentalChromeOS::OnRegisterAgent( | |
469 const base::Closure& callback, | |
470 const ConnectErrorCallback& error_callback) { | |
471 VLOG(1) << object_path_.value() << ": Agent registered, now pairing"; | |
472 | |
473 DBusThreadManager::Get()->GetExperimentalBluetoothDeviceClient()-> | |
474 Pair( | |
475 object_path_, | |
youngki
2013/04/16 15:26:56
I think it still fits to put this into the above l
keybuk
2013/04/16 23:19:13
Done.
| |
476 base::Bind( | |
477 &BluetoothDeviceExperimentalChromeOS::OnPair, | |
478 weak_ptr_factory_.GetWeakPtr(), | |
479 callback, error_callback), | |
480 base::Bind( | |
481 &BluetoothDeviceExperimentalChromeOS::OnPairError, | |
482 weak_ptr_factory_.GetWeakPtr(), | |
483 error_callback)); | |
484 } | |
485 | |
486 void BluetoothDeviceExperimentalChromeOS::OnRegisterAgentError( | |
487 const ConnectErrorCallback& error_callback, | |
488 const std::string& error_name, | |
489 const std::string& error_message) { | |
490 --connecting_calls_; | |
youngki
2013/04/16 15:26:56
Can we put DCHECK(connecting_calls >= 0)?
keybuk
2013/04/16 23:19:13
Done.
| |
491 LOG(WARNING) << object_path_.value() << ": Failed to register agent: " | |
492 << error_name << ": " << error_message; | |
493 VLOG(1) << object_path_.value() << ": " << connecting_calls_ | |
494 << " still in progress"; | |
495 | |
496 UnregisterAgent(); | |
497 | |
498 // Determine the error code from error_name. | |
499 ConnectErrorCode error_code = ERROR_UNKNOWN; | |
500 if (error_name == bluetooth_adapter::kErrorAlreadyExists) { | |
youngki
2013/04/16 15:26:56
Remove the braces since this is one-liner if block
keybuk
2013/04/16 23:19:13
Done.
| |
501 error_code = ERROR_INPROGRESS; | |
502 } | |
503 | |
504 error_callback.Run(error_code); | |
505 } | |
506 | |
507 void BluetoothDeviceExperimentalChromeOS::OnPair( | |
508 const base::Closure& callback, | |
509 const ConnectErrorCallback& error_callback) { | |
510 VLOG(1) << object_path_.value() << ": Paired"; | |
511 | |
512 // Now that we're paired, we need to set the device as trusted so that | |
513 // incoming connections will be accepted. This should only ever fail if | |
514 // the device is removed mid-pairing, so do it in the background while | |
515 // we connect and don't worry about errors. | |
516 DBusThreadManager::Get()->GetExperimentalBluetoothDeviceClient()-> | |
517 GetProperties(object_path_)->trusted.Set( | |
518 true, | |
519 base::Bind( | |
520 &BluetoothDeviceExperimentalChromeOS::OnSetTrusted, | |
521 weak_ptr_factory_.GetWeakPtr())); | |
522 | |
523 UnregisterAgent(); | |
524 | |
525 // Now we can connect to the device! | |
526 ConnectInternal(callback, error_callback); | |
527 } | |
528 | |
529 void BluetoothDeviceExperimentalChromeOS::OnPairError( | |
530 const ConnectErrorCallback& error_callback, | |
531 const std::string& error_name, | |
532 const std::string& error_message) { | |
533 --connecting_calls_; | |
youngki
2013/04/16 15:26:56
Can we put DCHECK(connecting_calls >= 0)?
keybuk
2013/04/16 23:19:13
Done.
| |
534 LOG(WARNING) << object_path_.value() << ": Failed to pair device: " | |
535 << error_name << ": " << error_message; | |
536 VLOG(1) << object_path_.value() << ": " << connecting_calls_ | |
537 << " still in progress"; | |
538 | |
539 UnregisterAgent(); | |
540 | |
541 // Determine the error code from error_name. | |
542 ConnectErrorCode error_code = ERROR_UNKNOWN; | |
543 if (error_name == bluetooth_adapter::kErrorConnectionAttemptFailed) { | |
544 error_code = ERROR_FAILED; | |
545 } else if (error_name == bluetooth_adapter::kErrorAuthenticationFailed) { | |
546 error_code = ERROR_AUTH_FAILED; | |
547 } else if (error_name == bluetooth_adapter::kErrorAuthenticationCanceled) { | |
548 error_code = ERROR_AUTH_CANCELED; | |
549 } else if (error_name == bluetooth_adapter::kErrorAuthenticationRejected) { | |
550 error_code = ERROR_AUTH_REJECTED; | |
551 } else if (error_name == bluetooth_adapter::kErrorAuthenticationTimeout) { | |
552 error_code = ERROR_AUTH_TIMEOUT; | |
553 } | |
554 | |
555 error_callback.Run(error_code); | |
556 } | |
557 | |
558 void BluetoothDeviceExperimentalChromeOS::OnCancelPairingError( | |
559 const std::string& error_name, | |
560 const std::string& error_message) { | |
561 LOG(WARNING) << object_path_.value() << ": Failed to cancel pairing: " | |
562 << error_name << ": " << error_message; | |
563 } | |
564 | |
565 void BluetoothDeviceExperimentalChromeOS::OnSetTrusted(bool success) { | |
566 LOG_IF(WARNING, !success) << object_path_.value() | |
567 << ": Failed to set device as trusted"; | |
568 } | |
569 | |
570 void BluetoothDeviceExperimentalChromeOS::UnregisterAgent() { | |
571 DCHECK(agent_.get()); | |
572 DCHECK(pairing_delegate_); | |
573 | |
574 DCHECK(pincode_callback_.is_null()); | |
575 DCHECK(passkey_callback_.is_null()); | |
576 DCHECK(confirmation_callback_.is_null()); | |
577 | |
578 pairing_delegate_->DismissDisplayOrConfirm(); | |
579 pairing_delegate_ = NULL; | |
580 | |
581 agent_.reset(); | |
582 | |
583 // Clean up after ourselves. | |
584 VLOG(1) << object_path_.value() << ": Unregistering pairing agent"; | |
585 DBusThreadManager::Get()->GetExperimentalBluetoothAgentManagerClient()-> | |
586 UnregisterAgent( | |
587 kAgentPath, | |
588 base::Bind(&base::DoNothing), | |
589 base::Bind( | |
590 &BluetoothDeviceExperimentalChromeOS::OnUnregisterAgentError, | |
591 weak_ptr_factory_.GetWeakPtr())); | |
592 } | |
593 | |
594 void BluetoothDeviceExperimentalChromeOS::OnUnregisterAgentError( | |
595 const std::string& error_name, | |
596 const std::string& error_message) { | |
597 LOG(WARNING) << object_path_.value() << ": Failed to unregister agent: " | |
598 << error_name << ": " << error_message; | |
599 } | |
600 | |
601 void BluetoothDeviceExperimentalChromeOS::OnDisconnect( | |
602 const base::Closure& callback) { | |
603 VLOG(1) << object_path_.value() << ": Disconnected"; | |
604 callback.Run(); | |
605 } | |
606 | |
607 void BluetoothDeviceExperimentalChromeOS::OnDisconnectError( | |
608 const ErrorCallback& error_callback, | |
609 const std::string& error_name, | |
610 const std::string& error_message) { | |
611 LOG(WARNING) << object_path_.value() << ": Failed to disconnect device: " | |
612 << error_name << ": " << error_message; | |
613 error_callback.Run(); | |
614 } | |
615 | |
616 void BluetoothDeviceExperimentalChromeOS::OnForgetError( | |
617 const ErrorCallback& error_callback, | |
618 const std::string& error_name, | |
619 const std::string& error_message) { | |
620 LOG(WARNING) << object_path_.value() << ": Failed to remove device: " | |
621 << error_name << ": " << error_message; | |
622 error_callback.Run(); | |
623 } | |
624 | |
625 } // namespace chromeos | |
OLD | NEW |