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 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 111 return !confirmation_callback_.is_null(); | 111 return !confirmation_callback_.is_null(); |
| 112 } | 112 } |
| 113 | 113 |
| 114 void BluetoothDeviceChromeOS::Connect( | 114 void BluetoothDeviceChromeOS::Connect( |
| 115 PairingDelegate* pairing_delegate, | 115 PairingDelegate* pairing_delegate, |
| 116 const base::Closure& callback, | 116 const base::Closure& callback, |
| 117 const ConnectErrorCallback& error_callback) { | 117 const ConnectErrorCallback& error_callback) { |
| 118 // This is safe because Connect() and its callbacks are called in the same | 118 // This is safe because Connect() and its callbacks are called in the same |
| 119 // thread. | 119 // thread. |
| 120 connecting_calls_++; | 120 connecting_calls_++; |
| 121 if (connecting_calls_ != 0 && !connecting_) { | |
|
keybuk
2013/04/18 00:52:24
How can connecting calls be zero if you just incre
deymo
2013/04/18 01:38:40
Probably it can't. I just translated this:
if (inv
| |
| 122 connecting_ = true; | |
| 123 adapter_->DeviceChanged(this); | |
| 124 } | |
| 121 connecting_ = !!connecting_calls_; | 125 connecting_ = !!connecting_calls_; |
| 122 // Set the decrement to be issued when either callback is called. | 126 // Set the decrement to be issued when either callback is called. |
| 123 base::Closure wrapped_callback = base::Bind( | 127 base::Closure wrapped_callback = base::Bind( |
| 124 &BluetoothDeviceChromeOS::OnConnectCallbackCalled, | 128 &BluetoothDeviceChromeOS::OnConnectCallbackCalled, |
| 125 weak_ptr_factory_.GetWeakPtr(), | 129 weak_ptr_factory_.GetWeakPtr(), |
| 126 callback); | 130 callback); |
| 127 ConnectErrorCallback wrapped_error_callback = base::Bind( | 131 ConnectErrorCallback wrapped_error_callback = base::Bind( |
| 128 &BluetoothDeviceChromeOS::OnConnectErrorCallbackCalled, | 132 &BluetoothDeviceChromeOS::OnConnectErrorCallbackCalled, |
| 129 weak_ptr_factory_.GetWeakPtr(), | 133 weak_ptr_factory_.GetWeakPtr(), |
| 130 error_callback); | 134 error_callback); |
| (...skipping 383 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 514 if (service_records_loaded_) { | 518 if (service_records_loaded_) { |
| 515 callback.Run(service_records_); | 519 callback.Run(service_records_); |
| 516 } else { | 520 } else { |
| 517 error_callback.Run(); | 521 error_callback.Run(); |
| 518 } | 522 } |
| 519 } | 523 } |
| 520 | 524 |
| 521 void BluetoothDeviceChromeOS::OnConnectCallbackCalled( | 525 void BluetoothDeviceChromeOS::OnConnectCallbackCalled( |
| 522 const base::Closure& callback) { | 526 const base::Closure& callback) { |
| 523 // Update the connecting status. | 527 // Update the connecting status. |
| 528 bool prev_connecting = !!connecting_calls_; | |
| 524 connecting_calls_--; | 529 connecting_calls_--; |
| 525 connecting_ = !!connecting_calls_; | 530 connecting_ = !!connecting_calls_; |
| 526 callback.Run(); | 531 callback.Run(); |
| 532 if (prev_connecting != connecting_) adapter_->DeviceChanged(this); | |
| 527 } | 533 } |
| 528 | 534 |
| 529 void BluetoothDeviceChromeOS::OnConnectErrorCallbackCalled( | 535 void BluetoothDeviceChromeOS::OnConnectErrorCallbackCalled( |
| 530 const ConnectErrorCallback& error_callback, | 536 const ConnectErrorCallback& error_callback, |
| 531 enum ConnectErrorCode error_code) { | 537 enum ConnectErrorCode error_code) { |
| 532 // Update the connecting status. | 538 // Update the connecting status. |
| 539 bool prev_connecting = !!connecting_calls_; | |
| 533 connecting_calls_--; | 540 connecting_calls_--; |
| 534 connecting_ = !!connecting_calls_; | 541 connecting_ = !!connecting_calls_; |
| 535 error_callback.Run(error_code); | 542 error_callback.Run(error_code); |
| 543 if (prev_connecting != connecting_) adapter_->DeviceChanged(this); | |
| 536 } | 544 } |
| 537 | 545 |
| 538 void BluetoothDeviceChromeOS::ConnectApplications( | 546 void BluetoothDeviceChromeOS::ConnectApplications( |
| 539 const base::Closure& callback, | 547 const base::Closure& callback, |
| 540 const ConnectErrorCallback& error_callback) { | 548 const ConnectErrorCallback& error_callback) { |
| 541 // Introspect the device object to determine supported applications. | 549 // Introspect the device object to determine supported applications. |
| 542 DBusThreadManager::Get()->GetIntrospectableClient()-> | 550 DBusThreadManager::Get()->GetIntrospectableClient()-> |
| 543 Introspect(bluetooth_device::kBluetoothDeviceServiceName, | 551 Introspect(bluetooth_device::kBluetoothDeviceServiceName, |
| 544 object_path_, | 552 object_path_, |
| 545 base::Bind(&BluetoothDeviceChromeOS::OnIntrospect, | 553 base::Bind(&BluetoothDeviceChromeOS::OnIntrospect, |
| (...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 847 } | 855 } |
| 848 | 856 |
| 849 | 857 |
| 850 // static | 858 // static |
| 851 BluetoothDeviceChromeOS* BluetoothDeviceChromeOS::Create( | 859 BluetoothDeviceChromeOS* BluetoothDeviceChromeOS::Create( |
| 852 BluetoothAdapterChromeOS* adapter) { | 860 BluetoothAdapterChromeOS* adapter) { |
| 853 return new BluetoothDeviceChromeOS(adapter); | 861 return new BluetoothDeviceChromeOS(adapter); |
| 854 } | 862 } |
| 855 | 863 |
| 856 } // namespace chromeos | 864 } // namespace chromeos |
| OLD | NEW |