summaryrefslogtreecommitdiffstats
path: root/device
diff options
context:
space:
mode:
authorearthdok@chromium.org <earthdok@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-03-06 16:50:14 +0000
committerearthdok@chromium.org <earthdok@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-03-06 16:50:14 +0000
commit5cb096f565b7af2e785ea660afcdd9f77714f78b (patch)
tree29b579e4cb7212ca0b1d31687f9c26369fba69a9 /device
parentfb0a2206f206d6acc30c283c098690b70006b11e (diff)
downloadchromium_src-5cb096f565b7af2e785ea660afcdd9f77714f78b.zip
chromium_src-5cb096f565b7af2e785ea660afcdd9f77714f78b.tar.gz
chromium_src-5cb096f565b7af2e785ea660afcdd9f77714f78b.tar.bz2
Revert 255262 "Migrate chrome.bluetooth API backend to use devic..."
Reverted due to memory leaks. > Migrate chrome.bluetooth API backend to use device::BluetoothDiscoverySession. > > Modified chrome.bluetooth API code to use the new discovery session API for > device discovery. > > BUG=346982 > TEST=1. unit_tests, browser_tests > 2. Use multiple running extension instances with the bluetooth permission and check for the following behavior: > - Only one session per extension. Calling chrome.bluetooth.stopDiscovery from one running app should fail if that app never called chrome.bluetooth.startDiscovery. > - An app's discovery sessions should get cleaned up if that app crashes or unloads. > - Use bt_console and run "power off". This should cause all discovery sessions that have been assigned to apps to get marked as inactive. Verify by requesting a new discovery session from apps, which should succeed. > > Review URL: https://codereview.chromium.org/179123008 TBR=armansito@chromium.org BUG=349942 Review URL: https://codereview.chromium.org/188663003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@255372 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'device')
-rw-r--r--device/bluetooth/bluetooth.gyp2
-rw-r--r--device/bluetooth/bluetooth_adapter.cc2
-rw-r--r--device/bluetooth/bluetooth_discovery_session.cc15
-rw-r--r--device/bluetooth/bluetooth_discovery_session.h6
-rw-r--r--device/bluetooth/test/mock_bluetooth_adapter.cc10
-rw-r--r--device/bluetooth/test/mock_bluetooth_adapter.h13
-rw-r--r--device/bluetooth/test/mock_bluetooth_discovery_session.cc14
-rw-r--r--device/bluetooth/test/mock_bluetooth_discovery_session.h32
8 files changed, 11 insertions, 83 deletions
diff --git a/device/bluetooth/bluetooth.gyp b/device/bluetooth/bluetooth.gyp
index fd76ec2..5693fdc 100644
--- a/device/bluetooth/bluetooth.gyp
+++ b/device/bluetooth/bluetooth.gyp
@@ -123,8 +123,6 @@
'test/mock_bluetooth_adapter.h',
'test/mock_bluetooth_device.cc',
'test/mock_bluetooth_device.h',
- 'test/mock_bluetooth_discovery_session.cc',
- 'test/mock_bluetooth_discovery_session.h',
'test/mock_bluetooth_profile.cc',
'test/mock_bluetooth_profile.h',
'test/mock_bluetooth_socket.cc',
diff --git a/device/bluetooth/bluetooth_adapter.cc b/device/bluetooth/bluetooth_adapter.cc
index 2868159..ce63bdd 100644
--- a/device/bluetooth/bluetooth_adapter.cc
+++ b/device/bluetooth/bluetooth_adapter.cc
@@ -113,7 +113,7 @@ void BluetoothAdapter::OnStartDiscoverySession(
const DiscoverySessionCallback& callback) {
VLOG(1) << "Discovery session started!";
scoped_ptr<BluetoothDiscoverySession> discovery_session(
- new BluetoothDiscoverySession(scoped_refptr<BluetoothAdapter>(this)));
+ new BluetoothDiscoverySession(this));
discovery_sessions_.insert(discovery_session.get());
callback.Run(discovery_session.Pass());
}
diff --git a/device/bluetooth/bluetooth_discovery_session.cc b/device/bluetooth/bluetooth_discovery_session.cc
index 076123e..e07df34 100644
--- a/device/bluetooth/bluetooth_discovery_session.cc
+++ b/device/bluetooth/bluetooth_discovery_session.cc
@@ -9,23 +9,13 @@
namespace device {
-BluetoothDiscoverySession::BluetoothDiscoverySession(
- scoped_refptr<BluetoothAdapter> adapter)
+BluetoothDiscoverySession::BluetoothDiscoverySession(BluetoothAdapter* adapter)
: active_(true),
adapter_(adapter),
weak_ptr_factory_(this) {
- DCHECK(adapter_.get());
-}
-
-BluetoothDiscoverySession::BluetoothDiscoverySession()
- : active_(false),
- weak_ptr_factory_(this) {
}
BluetoothDiscoverySession::~BluetoothDiscoverySession() {
- if (!active_)
- return;
- DCHECK(adapter_.get());
Stop(base::Bind(&base::DoNothing), base::Bind(&base::DoNothing));
adapter_->DiscoverySessionDestroyed(this);
}
@@ -38,12 +28,11 @@ void BluetoothDiscoverySession::Stop(
const base::Closure& callback,
const ErrorCallback& error_callback) {
if (!active_) {
- LOG(WARNING) << "Discovery session not active. Cannot stop.";
+ LOG(ERROR) << "Discovery session not active. Cannot stop.";
error_callback.Run();
return;
}
VLOG(1) << "Stopping device discovery session.";
- DCHECK(adapter_.get());
adapter_->RemoveDiscoverySession(
base::Bind(&BluetoothDiscoverySession::OnStop,
weak_ptr_factory_.GetWeakPtr(),
diff --git a/device/bluetooth/bluetooth_discovery_session.h b/device/bluetooth/bluetooth_discovery_session.h
index 666538b..bc2f893 100644
--- a/device/bluetooth/bluetooth_discovery_session.h
+++ b/device/bluetooth/bluetooth_discovery_session.h
@@ -58,12 +58,10 @@ class BluetoothDiscoverySession {
const ErrorCallback& error_callback);
protected:
- BluetoothDiscoverySession(); // Called by mock.
-
- private:
friend class BluetoothAdapter;
- explicit BluetoothDiscoverySession(scoped_refptr<BluetoothAdapter> adapter);
+ explicit BluetoothDiscoverySession(BluetoothAdapter* adapter);
+ private:
// Internal callback invoked when a call to Stop has succeeded.
void OnStop(const base::Closure& callback);
diff --git a/device/bluetooth/test/mock_bluetooth_adapter.cc b/device/bluetooth/test/mock_bluetooth_adapter.cc
index 5e63ffb..5848db3 100644
--- a/device/bluetooth/test/mock_bluetooth_adapter.cc
+++ b/device/bluetooth/test/mock_bluetooth_adapter.cc
@@ -14,14 +14,4 @@ MockBluetoothAdapter::MockBluetoothAdapter() {
MockBluetoothAdapter::~MockBluetoothAdapter() {}
-void MockBluetoothAdapter::AddDiscoverySession(
- const base::Closure& callback,
- const ErrorCallback& error_callback) {
-}
-
-void MockBluetoothAdapter::RemoveDiscoverySession(
- const base::Closure& callback,
- const ErrorCallback& error_callback) {
-}
-
} // namespace device
diff --git a/device/bluetooth/test/mock_bluetooth_adapter.h b/device/bluetooth/test/mock_bluetooth_adapter.h
index 3a959e9..56647fe 100644
--- a/device/bluetooth/test/mock_bluetooth_adapter.h
+++ b/device/bluetooth/test/mock_bluetooth_adapter.h
@@ -52,9 +52,6 @@ class MockBluetoothAdapter : public BluetoothAdapter {
const base::Closure& callback,
const ErrorCallback& error_callback));
MOCK_CONST_METHOD0(IsDiscovering, bool());
- MOCK_METHOD2(StartDiscoverySession,
- void(const DiscoverySessionCallback& callback,
- const ErrorCallback& error_callback));
MOCK_METHOD2(StartDiscovering,
void(const base::Closure& callback,
const ErrorCallback& error_callback));
@@ -77,10 +74,12 @@ class MockBluetoothAdapter : public BluetoothAdapter {
MOCK_METHOD0(DefaultPairingDelegate, BluetoothDevice::PairingDelegate*());
protected:
- virtual void AddDiscoverySession(const base::Closure& callback,
- const ErrorCallback& error_callback);
- virtual void RemoveDiscoverySession(const base::Closure& callback,
- const ErrorCallback& error_callback);
+ MOCK_METHOD2(AddDiscoverySession,
+ void(const base::Closure& callback,
+ const ErrorCallback& error_callback));
+ MOCK_METHOD2(RemoveDiscoverySession,
+ void(const base::Closure& callback,
+ const ErrorCallback& error_callback));
virtual ~MockBluetoothAdapter();
MOCK_METHOD1(RemovePairingDelegateInternal,
diff --git a/device/bluetooth/test/mock_bluetooth_discovery_session.cc b/device/bluetooth/test/mock_bluetooth_discovery_session.cc
deleted file mode 100644
index 72449ee..0000000
--- a/device/bluetooth/test/mock_bluetooth_discovery_session.cc
+++ /dev/null
@@ -1,14 +0,0 @@
-// Copyright 2014 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "device/bluetooth/test/mock_bluetooth_discovery_session.h"
-
-#include "device/bluetooth/bluetooth_adapter.h"
-
-namespace device {
-
-MockBluetoothDiscoverySession::MockBluetoothDiscoverySession() {}
-MockBluetoothDiscoverySession::~MockBluetoothDiscoverySession() {}
-
-} // namespace device
diff --git a/device/bluetooth/test/mock_bluetooth_discovery_session.h b/device/bluetooth/test/mock_bluetooth_discovery_session.h
deleted file mode 100644
index 98f2125..0000000
--- a/device/bluetooth/test/mock_bluetooth_discovery_session.h
+++ /dev/null
@@ -1,32 +0,0 @@
-// Copyright 2014 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef DEVICE_BLUETOOTH_TEST_MOCK_BLUETOOTH_DISCOVERY_SESSION_H_
-#define DEVICE_BLUETOOTH_TEST_MOCK_BLUETOOTH_DISCOVERY_SESSION_H_
-
-#include "base/callback.h"
-#include "device/bluetooth/bluetooth_discovery_session.h"
-#include "testing/gmock/include/gmock/gmock.h"
-
-namespace device {
-
-class BluetoothAdapter;
-
-class MockBluetoothDiscoverySession : public BluetoothDiscoverySession {
- public:
- MockBluetoothDiscoverySession();
- virtual ~MockBluetoothDiscoverySession();
-
- MOCK_CONST_METHOD0(IsActive, bool());
- MOCK_METHOD2(Stop,
- void(const base::Closure& callback,
- const ErrorCallback& error_callback));
-
- private:
- DISALLOW_COPY_AND_ASSIGN(MockBluetoothDiscoverySession);
-};
-
-} // namespac device
-
-#endif // DEVICE_BLUETOOTH_TEST_MOCK_BLUETOOTH_DISCOVERY_SESSION_H_