OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_device_chromeos.h" | 5 #include "device/bluetooth/bluetooth_device_chromeos.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
156 callback); | 156 callback); |
157 ConnectErrorCallback wrapped_error_callback = base::Bind( | 157 ConnectErrorCallback wrapped_error_callback = base::Bind( |
158 &BluetoothDeviceChromeOS::OnConnectErrorCallbackCalled, | 158 &BluetoothDeviceChromeOS::OnConnectErrorCallbackCalled, |
159 weak_ptr_factory_.GetWeakPtr(), | 159 weak_ptr_factory_.GetWeakPtr(), |
160 error_callback); | 160 error_callback); |
161 | 161 |
162 if (IsPaired() || IsConnected()) { | 162 if (IsPaired() || IsConnected()) { |
163 // Connection to already paired or connected device. | 163 // Connection to already paired or connected device. |
164 ConnectApplications(wrapped_callback, wrapped_error_callback); | 164 ConnectApplications(wrapped_callback, wrapped_error_callback); |
165 | 165 |
166 } else if (!pairing_delegate) { | 166 } else if (!pairing_delegate || !IsPairable()) { |
167 // No pairing delegate supplied, initiate low-security connection only. | 167 // No pairing delegate supplied, or unpairable device; initiate |
| 168 // low-security connection only. |
168 DBusThreadManager::Get()->GetBluetoothAdapterClient()-> | 169 DBusThreadManager::Get()->GetBluetoothAdapterClient()-> |
169 CreateDevice(adapter_->object_path_, | 170 CreateDevice(adapter_->object_path_, |
170 address_, | 171 address_, |
171 base::Bind(&BluetoothDeviceChromeOS::OnCreateDevice, | 172 base::Bind(&BluetoothDeviceChromeOS::OnCreateDevice, |
172 weak_ptr_factory_.GetWeakPtr(), | 173 weak_ptr_factory_.GetWeakPtr(), |
173 wrapped_callback, | 174 wrapped_callback, |
174 wrapped_error_callback), | 175 wrapped_error_callback), |
175 base::Bind(&BluetoothDeviceChromeOS::OnCreateDeviceError, | 176 base::Bind(&BluetoothDeviceChromeOS::OnCreateDeviceError, |
176 weak_ptr_factory_.GetWeakPtr(), | 177 weak_ptr_factory_.GetWeakPtr(), |
177 wrapped_error_callback)); | 178 wrapped_error_callback)); |
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
403 VLOG(1) << "Connection successful: " << device_path.value(); | 404 VLOG(1) << "Connection successful: " << device_path.value(); |
404 if (object_path_.value().empty()) { | 405 if (object_path_.value().empty()) { |
405 object_path_ = device_path; | 406 object_path_ = device_path; |
406 } else { | 407 } else { |
407 LOG_IF(WARNING, object_path_ != device_path) | 408 LOG_IF(WARNING, object_path_ != device_path) |
408 << "Conflicting device paths for objects, result gave: " | 409 << "Conflicting device paths for objects, result gave: " |
409 << device_path.value() << " but signal gave: " | 410 << device_path.value() << " but signal gave: " |
410 << object_path_.value(); | 411 << object_path_.value(); |
411 } | 412 } |
412 | 413 |
413 // Mark the device trusted so it can connect to us automatically, and | 414 SetTrusted(); |
414 // we can connect after rebooting. This information is part of the | |
415 // pairing information of the device, and is unique to the combination | |
416 // of our bluetooth address and the device's bluetooth address. A | |
417 // different host needs a new pairing, so it's not useful to sync. | |
418 DBusThreadManager::Get()->GetBluetoothDeviceClient()-> | |
419 GetProperties(object_path_)->trusted.Set( | |
420 true, | |
421 base::Bind(&BluetoothDeviceChromeOS::OnSetTrusted, | |
422 weak_ptr_factory_.GetWeakPtr())); | |
423 | 415 |
424 // In parallel with the |trusted| property change, call GetServiceRecords to | 416 // In parallel with the |trusted| property change, call GetServiceRecords to |
425 // retrieve the SDP from the device and then, either on success or failure, | 417 // retrieve the SDP from the device and then, either on success or failure, |
426 // call ConnectApplications. | 418 // call ConnectApplications. |
427 GetServiceRecords( | 419 GetServiceRecords( |
428 base::Bind(&BluetoothDeviceChromeOS::OnInitialGetServiceRecords, | 420 base::Bind(&BluetoothDeviceChromeOS::OnInitialGetServiceRecords, |
429 weak_ptr_factory_.GetWeakPtr(), | 421 weak_ptr_factory_.GetWeakPtr(), |
430 callback, | 422 callback, |
431 error_callback), | 423 error_callback), |
432 base::Bind(&BluetoothDeviceChromeOS::OnInitialGetServiceRecordsError, | 424 base::Bind(&BluetoothDeviceChromeOS::OnInitialGetServiceRecordsError, |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
483 for (BluetoothDeviceClient::ServiceMap::const_iterator i = | 475 for (BluetoothDeviceClient::ServiceMap::const_iterator i = |
484 service_map.begin(); i != service_map.end(); ++i) { | 476 service_map.begin(); i != service_map.end(); ++i) { |
485 service_records_.push_back( | 477 service_records_.push_back( |
486 new BluetoothServiceRecordChromeOS(address_, i->second)); | 478 new BluetoothServiceRecordChromeOS(address_, i->second)); |
487 } | 479 } |
488 service_records_loaded_ = true; | 480 service_records_loaded_ = true; |
489 | 481 |
490 callback.Run(service_records_); | 482 callback.Run(service_records_); |
491 } | 483 } |
492 | 484 |
| 485 void BluetoothDeviceChromeOS::SetTrusted() { |
| 486 // Unconditionally send the property change, rather than checking the value |
| 487 // first; there's no harm in doing this and it solves any race conditions |
| 488 // with the property becoming true or false and this call happening before |
| 489 // we get the D-Bus signal about the earlier change. |
| 490 DBusThreadManager::Get()->GetBluetoothDeviceClient()-> |
| 491 GetProperties(object_path_)->trusted.Set( |
| 492 true, |
| 493 base::Bind( |
| 494 &BluetoothDeviceChromeOS::OnSetTrusted, |
| 495 weak_ptr_factory_.GetWeakPtr())); |
| 496 } |
| 497 |
493 void BluetoothDeviceChromeOS::OnSetTrusted(bool success) { | 498 void BluetoothDeviceChromeOS::OnSetTrusted(bool success) { |
494 LOG_IF(WARNING, !success) << "Failed to set device as trusted: " << address_; | 499 LOG_IF(WARNING, !success) << "Failed to set device as trusted: " << address_; |
495 } | 500 } |
496 | 501 |
497 void BluetoothDeviceChromeOS::OnInitialGetServiceRecords( | 502 void BluetoothDeviceChromeOS::OnInitialGetServiceRecords( |
498 const base::Closure& callback, | 503 const base::Closure& callback, |
499 const ConnectErrorCallback& error_callback, | 504 const ConnectErrorCallback& error_callback, |
500 const ServiceRecordList& list) { | 505 const ServiceRecordList& list) { |
501 // Connect application-layer protocols. | 506 // Connect application-layer protocols. |
502 ConnectApplications(callback, error_callback); | 507 ConnectApplications(callback, error_callback); |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
606 << ": " << interface_name; | 611 << ": " << interface_name; |
607 | 612 |
608 connecting_applications_counter_--; | 613 connecting_applications_counter_--; |
609 // |callback| should only be called once, meaning it cannot be called before | 614 // |callback| should only be called once, meaning it cannot be called before |
610 // all requests have been started. The extra decrement after all requests | 615 // all requests have been started. The extra decrement after all requests |
611 // have been started, and the check for -1 instead of 0 below, insure only a | 616 // have been started, and the check for -1 instead of 0 below, insure only a |
612 // single call to |callback| will occur (provided OnConnect and OnIntrospect | 617 // single call to |callback| will occur (provided OnConnect and OnIntrospect |
613 // run on the same thread, which is true). | 618 // run on the same thread, which is true). |
614 if (connecting_applications_counter_ == -1) { | 619 if (connecting_applications_counter_ == -1) { |
615 connecting_applications_counter_ = 0; | 620 connecting_applications_counter_ = 0; |
| 621 SetTrusted(); |
616 callback.Run(); | 622 callback.Run(); |
617 } | 623 } |
618 } | 624 } |
619 | 625 |
620 void BluetoothDeviceChromeOS::OnConnectError( | 626 void BluetoothDeviceChromeOS::OnConnectError( |
621 const ConnectErrorCallback& error_callback, | 627 const ConnectErrorCallback& error_callback, |
622 const std::string& interface_name, | 628 const std::string& interface_name, |
623 const dbus::ObjectPath& device_path, | 629 const dbus::ObjectPath& device_path, |
624 const std::string& error_name, | 630 const std::string& error_name, |
625 const std::string& error_message) { | 631 const std::string& error_message) { |
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
850 } | 856 } |
851 | 857 |
852 | 858 |
853 // static | 859 // static |
854 BluetoothDeviceChromeOS* BluetoothDeviceChromeOS::Create( | 860 BluetoothDeviceChromeOS* BluetoothDeviceChromeOS::Create( |
855 BluetoothAdapterChromeOS* adapter) { | 861 BluetoothAdapterChromeOS* adapter) { |
856 return new BluetoothDeviceChromeOS(adapter); | 862 return new BluetoothDeviceChromeOS(adapter); |
857 } | 863 } |
858 | 864 |
859 } // namespace chromeos | 865 } // namespace chromeos |
OLD | NEW |