| 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 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 141 return !confirmation_callback_.is_null(); | 141 return !confirmation_callback_.is_null(); |
| 142 } | 142 } |
| 143 | 143 |
| 144 void BluetoothDeviceChromeOS::Connect( | 144 void BluetoothDeviceChromeOS::Connect( |
| 145 PairingDelegate* pairing_delegate, | 145 PairingDelegate* pairing_delegate, |
| 146 const base::Closure& callback, | 146 const base::Closure& callback, |
| 147 const ConnectErrorCallback& error_callback) { | 147 const ConnectErrorCallback& error_callback) { |
| 148 // This is safe because Connect() and its callbacks are called in the same | 148 // This is safe because Connect() and its callbacks are called in the same |
| 149 // thread. | 149 // thread. |
| 150 connecting_calls_++; | 150 connecting_calls_++; |
| 151 if (!connecting_) { |
| 152 connecting_ = true; |
| 153 adapter_->NotifyDeviceChanged(this); |
| 154 } |
| 151 connecting_ = !!connecting_calls_; | 155 connecting_ = !!connecting_calls_; |
| 152 // Set the decrement to be issued when either callback is called. | 156 // Set the decrement to be issued when either callback is called. |
| 153 base::Closure wrapped_callback = base::Bind( | 157 base::Closure wrapped_callback = base::Bind( |
| 154 &BluetoothDeviceChromeOS::OnConnectCallbackCalled, | 158 &BluetoothDeviceChromeOS::OnConnectCallbackCalled, |
| 155 weak_ptr_factory_.GetWeakPtr(), | 159 weak_ptr_factory_.GetWeakPtr(), |
| 156 callback); | 160 callback); |
| 157 ConnectErrorCallback wrapped_error_callback = base::Bind( | 161 ConnectErrorCallback wrapped_error_callback = base::Bind( |
| 158 &BluetoothDeviceChromeOS::OnConnectErrorCallbackCalled, | 162 &BluetoothDeviceChromeOS::OnConnectErrorCallbackCalled, |
| 159 weak_ptr_factory_.GetWeakPtr(), | 163 weak_ptr_factory_.GetWeakPtr(), |
| 160 error_callback); | 164 error_callback); |
| (...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 522 if (service_records_loaded_) { | 526 if (service_records_loaded_) { |
| 523 callback.Run(service_records_); | 527 callback.Run(service_records_); |
| 524 } else { | 528 } else { |
| 525 error_callback.Run(); | 529 error_callback.Run(); |
| 526 } | 530 } |
| 527 } | 531 } |
| 528 | 532 |
| 529 void BluetoothDeviceChromeOS::OnConnectCallbackCalled( | 533 void BluetoothDeviceChromeOS::OnConnectCallbackCalled( |
| 530 const base::Closure& callback) { | 534 const base::Closure& callback) { |
| 531 // Update the connecting status. | 535 // Update the connecting status. |
| 536 bool prev_connecting = connecting_; |
| 532 connecting_calls_--; | 537 connecting_calls_--; |
| 533 connecting_ = !!connecting_calls_; | 538 connecting_ = !!connecting_calls_; |
| 534 callback.Run(); | 539 callback.Run(); |
| 540 if (prev_connecting != connecting_) adapter_->NotifyDeviceChanged(this); |
| 535 } | 541 } |
| 536 | 542 |
| 537 void BluetoothDeviceChromeOS::OnConnectErrorCallbackCalled( | 543 void BluetoothDeviceChromeOS::OnConnectErrorCallbackCalled( |
| 538 const ConnectErrorCallback& error_callback, | 544 const ConnectErrorCallback& error_callback, |
| 539 enum ConnectErrorCode error_code) { | 545 enum ConnectErrorCode error_code) { |
| 540 // Update the connecting status. | 546 // Update the connecting status. |
| 547 bool prev_connecting = connecting_; |
| 541 connecting_calls_--; | 548 connecting_calls_--; |
| 542 connecting_ = !!connecting_calls_; | 549 connecting_ = !!connecting_calls_; |
| 543 error_callback.Run(error_code); | 550 error_callback.Run(error_code); |
| 551 if (prev_connecting != connecting_) adapter_->NotifyDeviceChanged(this); |
| 544 } | 552 } |
| 545 | 553 |
| 546 void BluetoothDeviceChromeOS::ConnectApplications( | 554 void BluetoothDeviceChromeOS::ConnectApplications( |
| 547 const base::Closure& callback, | 555 const base::Closure& callback, |
| 548 const ConnectErrorCallback& error_callback) { | 556 const ConnectErrorCallback& error_callback) { |
| 549 // Introspect the device object to determine supported applications. | 557 // Introspect the device object to determine supported applications. |
| 550 DBusThreadManager::Get()->GetIntrospectableClient()-> | 558 DBusThreadManager::Get()->GetIntrospectableClient()-> |
| 551 Introspect(bluetooth_device::kBluetoothDeviceServiceName, | 559 Introspect(bluetooth_device::kBluetoothDeviceServiceName, |
| 552 object_path_, | 560 object_path_, |
| 553 base::Bind(&BluetoothDeviceChromeOS::OnIntrospect, | 561 base::Bind(&BluetoothDeviceChromeOS::OnIntrospect, |
| (...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 856 } | 864 } |
| 857 | 865 |
| 858 | 866 |
| 859 // static | 867 // static |
| 860 BluetoothDeviceChromeOS* BluetoothDeviceChromeOS::Create( | 868 BluetoothDeviceChromeOS* BluetoothDeviceChromeOS::Create( |
| 861 BluetoothAdapterChromeOS* adapter) { | 869 BluetoothAdapterChromeOS* adapter) { |
| 862 return new BluetoothDeviceChromeOS(adapter); | 870 return new BluetoothDeviceChromeOS(adapter); |
| 863 } | 871 } |
| 864 | 872 |
| 865 } // namespace chromeos | 873 } // namespace chromeos |
| OLD | NEW |