summaryrefslogtreecommitdiffstats
path: root/device
diff options
context:
space:
mode:
authortzik <tzik@chromium.org>2015-04-23 01:42:15 -0700
committerCommit bot <commit-bot@chromium.org>2015-04-23 08:42:36 +0000
commit7da08ce558969cb4797baacd308d8b6fe12ff1e8 (patch)
treee9912ec553ea92f7e424eab8b494b889a175210a /device
parent0b9377aad2963ed234fb41e5be10dcf60676f7a1 (diff)
downloadchromium_src-7da08ce558969cb4797baacd308d8b6fe12ff1e8.zip
chromium_src-7da08ce558969cb4797baacd308d8b6fe12ff1e8.tar.gz
chromium_src-7da08ce558969cb4797baacd308d8b6fe12ff1e8.tar.bz2
Make BluetoothAdapter non-threadsafe RefCounted
BluetoothAdapter was RefCountedThreadSafe and is weakly referred by WeakPtrs. That potentially causes a race on deletion. This CL changes BluetoothAdapter RefCounted instead of RefCountedThreadSafe to avoid the race. BUG=476492 Review URL: https://codereview.chromium.org/1101663003 Cr-Commit-Position: refs/heads/master@{#326476}
Diffstat (limited to 'device')
-rw-r--r--device/bluetooth/bluetooth_adapter.h17
-rw-r--r--device/bluetooth/bluetooth_adapter_chromeos.cc6
-rw-r--r--device/bluetooth/bluetooth_adapter_chromeos.h2
-rw-r--r--device/bluetooth/bluetooth_adapter_mac.h2
-rw-r--r--device/bluetooth/bluetooth_adapter_mac.mm6
-rw-r--r--device/bluetooth/bluetooth_adapter_unittest.cc2
-rw-r--r--device/bluetooth/bluetooth_adapter_win.cc6
-rw-r--r--device/bluetooth/bluetooth_adapter_win.h2
-rw-r--r--device/bluetooth/test/mock_bluetooth_adapter.cc4
-rw-r--r--device/bluetooth/test/mock_bluetooth_adapter.h1
10 files changed, 2 insertions, 46 deletions
diff --git a/device/bluetooth/bluetooth_adapter.h b/device/bluetooth/bluetooth_adapter.h
index 4841048..87734d2 100644
--- a/device/bluetooth/bluetooth_adapter.h
+++ b/device/bluetooth/bluetooth_adapter.h
@@ -36,8 +36,7 @@ struct BluetoothAdapterDeleter;
// known to the adapter, discovering new devices, and providing notification of
// updates to device information.
class DEVICE_BLUETOOTH_EXPORT BluetoothAdapter
- : public base::RefCountedThreadSafe<BluetoothAdapter,
- BluetoothAdapterDeleter> {
+ : public base::RefCounted<BluetoothAdapter> {
public:
// Interface for observing changes from bluetooth adapters.
class Observer {
@@ -371,9 +370,7 @@ class DEVICE_BLUETOOTH_EXPORT BluetoothAdapter
const BluetoothAudioSink::ErrorCallback& error_callback) = 0;
protected:
- friend class base::RefCountedThreadSafe<BluetoothAdapter,
- BluetoothAdapterDeleter>;
- friend struct BluetoothAdapterDeleter;
+ friend class base::RefCounted<BluetoothAdapter>;
friend class BluetoothDiscoverySession;
typedef std::map<const std::string, BluetoothDevice*> DevicesMap;
@@ -383,9 +380,6 @@ class DEVICE_BLUETOOTH_EXPORT BluetoothAdapter
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
@@ -485,13 +479,6 @@ 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_
diff --git a/device/bluetooth/bluetooth_adapter_chromeos.cc b/device/bluetooth/bluetooth_adapter_chromeos.cc
index 8f73323..26a029b 100644
--- a/device/bluetooth/bluetooth_adapter_chromeos.cc
+++ b/device/bluetooth/bluetooth_adapter_chromeos.cc
@@ -138,12 +138,6 @@ BluetoothAdapterChromeOS::~BluetoothAdapterChromeOS() {
Shutdown();
}
-void BluetoothAdapterChromeOS::DeleteOnCorrectThread() const {
- if (ui_task_runner_->RunsTasksOnCurrentThread() ||
- !ui_task_runner_->DeleteSoon(FROM_HERE, this))
- delete this;
-}
-
std::string BluetoothAdapterChromeOS::GetAddress() const {
if (!IsPresent())
return std::string();
diff --git a/device/bluetooth/bluetooth_adapter_chromeos.h b/device/bluetooth/bluetooth_adapter_chromeos.h
index 4254b8a..7b17f53 100644
--- a/device/bluetooth/bluetooth_adapter_chromeos.h
+++ b/device/bluetooth/bluetooth_adapter_chromeos.h
@@ -65,7 +65,6 @@ class DEVICE_BLUETOOTH_EXPORT BluetoothAdapterChromeOS
// BluetoothAdapter:
void Shutdown() override;
- void DeleteOnCorrectThread() const override;
std::string GetAddress() const override;
std::string GetName() const override;
void SetName(const std::string& name,
@@ -154,7 +153,6 @@ class DEVICE_BLUETOOTH_EXPORT BluetoothAdapterChromeOS
device::BluetoothDevice::PairingDelegate* pairing_delegate) override;
private:
- friend class base::DeleteHelper<BluetoothAdapterChromeOS>;
friend class BluetoothChromeOSTest;
friend class BluetoothChromeOSTest_Shutdown_Test;
friend class BluetoothChromeOSTest_Shutdown_OnStartDiscovery_Test;
diff --git a/device/bluetooth/bluetooth_adapter_mac.h b/device/bluetooth/bluetooth_adapter_mac.h
index 3567e0f..14d5a2b 100644
--- a/device/bluetooth/bluetooth_adapter_mac.h
+++ b/device/bluetooth/bluetooth_adapter_mac.h
@@ -85,14 +85,12 @@ class DEVICE_BLUETOOTH_EXPORT BluetoothAdapterMac
device::BluetoothDevice::PairingDelegate* pairing_delegate) override;
private:
- friend class base::DeleteHelper<BluetoothAdapterMac>;
friend class BluetoothAdapterMacTest;
BluetoothAdapterMac();
~BluetoothAdapterMac() override;
// BluetoothAdapter:
- void DeleteOnCorrectThread() const override;
void AddDiscoverySession(BluetoothDiscoveryFilter* discovery_filter,
const base::Closure& callback,
const ErrorCallback& error_callback) override;
diff --git a/device/bluetooth/bluetooth_adapter_mac.mm b/device/bluetooth/bluetooth_adapter_mac.mm
index c2e77ee..a528bd7 100644
--- a/device/bluetooth/bluetooth_adapter_mac.mm
+++ b/device/bluetooth/bluetooth_adapter_mac.mm
@@ -163,12 +163,6 @@ void BluetoothAdapterMac::DeviceConnected(IOBluetoothDevice* device) {
DeviceAdded(device);
}
-void BluetoothAdapterMac::DeleteOnCorrectThread() const {
- if (ui_task_runner_->RunsTasksOnCurrentThread() ||
- !ui_task_runner_->DeleteSoon(FROM_HERE, this))
- delete this;
-}
-
void BluetoothAdapterMac::AddDiscoverySession(
BluetoothDiscoveryFilter* discovery_filter,
const base::Closure& callback,
diff --git a/device/bluetooth/bluetooth_adapter_unittest.cc b/device/bluetooth/bluetooth_adapter_unittest.cc
index 939ae05..c028b97 100644
--- a/device/bluetooth/bluetooth_adapter_unittest.cc
+++ b/device/bluetooth/bluetooth_adapter_unittest.cc
@@ -45,8 +45,6 @@ class TestBluetoothAdapter : public BluetoothAdapter {
bool IsDiscovering() const override { return false; }
- void DeleteOnCorrectThread() const override { delete this; }
-
void StartDiscoverySessionWithFilter(
scoped_ptr<BluetoothDiscoveryFilter> discovery_filter,
const DiscoverySessionCallback& callback,
diff --git a/device/bluetooth/bluetooth_adapter_win.cc b/device/bluetooth/bluetooth_adapter_win.cc
index 20cd897..4f49788 100644
--- a/device/bluetooth/bluetooth_adapter_win.cc
+++ b/device/bluetooth/bluetooth_adapter_win.cc
@@ -281,12 +281,6 @@ void BluetoothAdapterWin::DevicesPolled(
}
}
-void BluetoothAdapterWin::DeleteOnCorrectThread() const {
- if (ui_task_runner_->RunsTasksOnCurrentThread() ||
- !ui_task_runner_->DeleteSoon(FROM_HERE, this))
- delete this;
-}
-
// If the method is called when |discovery_status_| is DISCOVERY_STOPPING,
// starting again is handled by BluetoothAdapterWin::DiscoveryStopped().
void BluetoothAdapterWin::AddDiscoverySession(
diff --git a/device/bluetooth/bluetooth_adapter_win.h b/device/bluetooth/bluetooth_adapter_win.h
index bf22f3d..3bb26c9 100644
--- a/device/bluetooth/bluetooth_adapter_win.h
+++ b/device/bluetooth/bluetooth_adapter_win.h
@@ -95,7 +95,6 @@ class DEVICE_BLUETOOTH_EXPORT BluetoothAdapterWin
device::BluetoothDevice::PairingDelegate* pairing_delegate) override;
private:
- friend class base::DeleteHelper<BluetoothAdapterWin>;
friend class BluetoothAdapterWinTest;
enum DiscoveryStatus {
@@ -109,7 +108,6 @@ class DEVICE_BLUETOOTH_EXPORT BluetoothAdapterWin
virtual ~BluetoothAdapterWin();
// BluetoothAdapter:
- void DeleteOnCorrectThread() const override;
virtual void AddDiscoverySession(
BluetoothDiscoveryFilter* discovery_filter,
const base::Closure& callback,
diff --git a/device/bluetooth/test/mock_bluetooth_adapter.cc b/device/bluetooth/test/mock_bluetooth_adapter.cc
index 9a3e953..615239b 100644
--- a/device/bluetooth/test/mock_bluetooth_adapter.cc
+++ b/device/bluetooth/test/mock_bluetooth_adapter.cc
@@ -19,10 +19,6 @@ void MockBluetoothAdapter::Shutdown() {
}
#endif
-void MockBluetoothAdapter::DeleteOnCorrectThread() const {
- delete this;
-};
-
void MockBluetoothAdapter::AddDiscoverySession(
BluetoothDiscoveryFilter* discovery_filter,
const base::Closure& callback,
diff --git a/device/bluetooth/test/mock_bluetooth_adapter.h b/device/bluetooth/test/mock_bluetooth_adapter.h
index 38c2f5a..37f6450 100644
--- a/device/bluetooth/test/mock_bluetooth_adapter.h
+++ b/device/bluetooth/test/mock_bluetooth_adapter.h
@@ -100,7 +100,6 @@ class MockBluetoothAdapter : public BluetoothAdapter {
const ErrorCallback& error_callback);
protected:
- void DeleteOnCorrectThread() const override;
void AddDiscoverySession(BluetoothDiscoveryFilter* discovery_filter,
const base::Closure& callback,
const ErrorCallback& error_callback) override;