Chromium Code Reviews| Index: device/bluetooth/bluetooth_adapter.h |
| diff --git a/device/bluetooth/bluetooth_adapter.h b/device/bluetooth/bluetooth_adapter.h |
| index 6c70fdf510580a338f7a6f22a4ebf0ed3cb500b0..d71d316b68eca5993f24a41a52531166ecf481e0 100644 |
| --- a/device/bluetooth/bluetooth_adapter.h |
| +++ b/device/bluetooth/bluetooth_adapter.h |
| @@ -25,6 +25,7 @@ class BluetoothGattDescriptor; |
| class BluetoothGattService; |
| class BluetoothSocket; |
| class BluetoothUUID; |
| +struct BluetoothAdapterDeleter; |
| // BluetoothAdapter represents a local Bluetooth adapter which may be used to |
| // interact with remote Bluetooth devices. As well as providing support for |
| @@ -33,7 +34,8 @@ class BluetoothUUID; |
| // known to the adapter, discovering new devices, and providing notification of |
| // updates to device information. |
| class DEVICE_BLUETOOTH_EXPORT BluetoothAdapter |
| - : public base::RefCounted<BluetoothAdapter> { |
| + : public base::RefCountedThreadSafe<BluetoothAdapter, |
| + BluetoothAdapterDeleter> { |
| public: |
| // Interface for observing changes from bluetooth adapters. |
| class Observer { |
| @@ -334,10 +336,14 @@ class DEVICE_BLUETOOTH_EXPORT BluetoothAdapter |
| const CreateServiceErrorCallback& error_callback) = 0; |
| protected: |
| - friend class base::RefCounted<BluetoothAdapter>; |
| + friend class base::RefCountedThreadSafe<BluetoothAdapter, |
| + BluetoothAdapterDeleter>; |
| + friend struct BluetoothAdapterDeleter; |
| friend class BluetoothDiscoverySession; |
| BluetoothAdapter(); |
| virtual ~BluetoothAdapter(); |
|
armansito
2014/12/16 22:01:47
nit: Empty line after destructor.
scheib
2014/12/16 22:15:26
Done.
|
| + // Called by RefCountedThreadSafeDeleteOnCorrectThread to destroy this. |
| + virtual void DeleteOnCorrectThread() const = 0; |
| // Internal methods for initiating and terminating device discovery sessions. |
| // An implementation of BluetoothAdapter keeps an internal reference count to |
| @@ -420,6 +426,13 @@ class DEVICE_BLUETOOTH_EXPORT BluetoothAdapter |
| base::WeakPtrFactory<BluetoothAdapter> weak_ptr_factory_; |
| }; |
| +// Trait for RefCountedThreadSafe that deletes BluetoothAdapter. |
| +struct BluetoothAdapterDeleter { |
| + static void Destruct(const BluetoothAdapter* adapter) { |
| + adapter->DeleteOnCorrectThread(); |
| + } |
| +}; |
| + |
| } // namespace device |
| #endif // DEVICE_BLUETOOTH_BLUETOOTH_ADAPTER_H_ |