Chromium Code Reviews| 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 356 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 517 if (service_records_loaded_) { | 521 if (service_records_loaded_) { |
| 518 callback.Run(service_records_); | 522 callback.Run(service_records_); |
| 519 } else { | 523 } else { |
| 520 error_callback.Run(); | 524 error_callback.Run(); |
| 521 } | 525 } |
| 522 } | 526 } |
| 523 | 527 |
| 524 void BluetoothDeviceChromeOS::OnConnectCallbackCalled( | 528 void BluetoothDeviceChromeOS::OnConnectCallbackCalled( |
| 525 const base::Closure& callback) { | 529 const base::Closure& callback) { |
| 526 // Update the connecting status. | 530 // Update the connecting status. |
| 531 bool prev_connecting = !!connecting_calls_; | |
|
keybuk
2013/04/18 15:54:17
why is this not just:
bool prev_connecting = co
deymo
2013/04/18 16:27:43
It could be any of those... why one or the other??
keybuk
2013/04/18 17:12:05
You're making an assumption that connecting_ is ca
deymo
2013/04/19 01:40:30
Done.
| |
| 527 connecting_calls_--; | 532 connecting_calls_--; |
| 528 connecting_ = !!connecting_calls_; | 533 connecting_ = !!connecting_calls_; |
| 529 callback.Run(); | 534 callback.Run(); |
| 535 if (prev_connecting != connecting_) adapter_->NotifyDeviceChanged(this); | |
| 530 } | 536 } |
| 531 | 537 |
| 532 void BluetoothDeviceChromeOS::OnConnectErrorCallbackCalled( | 538 void BluetoothDeviceChromeOS::OnConnectErrorCallbackCalled( |
| 533 const ConnectErrorCallback& error_callback, | 539 const ConnectErrorCallback& error_callback, |
| 534 enum ConnectErrorCode error_code) { | 540 enum ConnectErrorCode error_code) { |
| 535 // Update the connecting status. | 541 // Update the connecting status. |
| 542 bool prev_connecting = !!connecting_calls_; | |
|
keybuk
2013/04/18 15:54:17
ditto
deymo
2013/04/19 01:40:30
Done.
| |
| 536 connecting_calls_--; | 543 connecting_calls_--; |
| 537 connecting_ = !!connecting_calls_; | 544 connecting_ = !!connecting_calls_; |
| 538 error_callback.Run(error_code); | 545 error_callback.Run(error_code); |
| 546 if (prev_connecting != connecting_) adapter_->NotifyDeviceChanged(this); | |
| 539 } | 547 } |
| 540 | 548 |
| 541 void BluetoothDeviceChromeOS::ConnectApplications( | 549 void BluetoothDeviceChromeOS::ConnectApplications( |
| 542 const base::Closure& callback, | 550 const base::Closure& callback, |
| 543 const ConnectErrorCallback& error_callback) { | 551 const ConnectErrorCallback& error_callback) { |
| 544 // Introspect the device object to determine supported applications. | 552 // Introspect the device object to determine supported applications. |
| 545 DBusThreadManager::Get()->GetIntrospectableClient()-> | 553 DBusThreadManager::Get()->GetIntrospectableClient()-> |
| 546 Introspect(bluetooth_device::kBluetoothDeviceServiceName, | 554 Introspect(bluetooth_device::kBluetoothDeviceServiceName, |
| 547 object_path_, | 555 object_path_, |
| 548 base::Bind(&BluetoothDeviceChromeOS::OnIntrospect, | 556 base::Bind(&BluetoothDeviceChromeOS::OnIntrospect, |
| (...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 850 } | 858 } |
| 851 | 859 |
| 852 | 860 |
| 853 // static | 861 // static |
| 854 BluetoothDeviceChromeOS* BluetoothDeviceChromeOS::Create( | 862 BluetoothDeviceChromeOS* BluetoothDeviceChromeOS::Create( |
| 855 BluetoothAdapterChromeOS* adapter) { | 863 BluetoothAdapterChromeOS* adapter) { |
| 856 return new BluetoothDeviceChromeOS(adapter); | 864 return new BluetoothDeviceChromeOS(adapter); |
| 857 } | 865 } |
| 858 | 866 |
| 859 } // namespace chromeos | 867 } // namespace chromeos |
| OLD | NEW |