Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1374)

Unified Diff: device/bluetooth/bluetooth_adapter.h

Issue 812673002: bluetooth: BluetoothAdapterDeleter used to control BluetoothAdapter destruction. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@lkcr
Patch Set: respond to armansito & fix Mock Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: device/bluetooth/bluetooth_adapter.h
diff --git a/device/bluetooth/bluetooth_adapter.h b/device/bluetooth/bluetooth_adapter.h
index 6c70fdf510580a338f7a6f22a4ebf0ed3cb500b0..5184f2953a09bb018f56dc7192422b1156571e89 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,11 +336,16 @@ 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();
+ // 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
// make sure that the underlying controller is constantly searching for nearby
@@ -420,6 +427,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_
« no previous file with comments | « no previous file | device/bluetooth/bluetooth_adapter_chromeos.h » ('j') | device/bluetooth/test/mock_bluetooth_adapter.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698