summaryrefslogtreecommitdiffstats
path: root/device/bluetooth
diff options
context:
space:
mode:
authorkeybuk@chromium.org <keybuk@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-04-02 23:59:30 +0000
committerkeybuk@chromium.org <keybuk@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-04-02 23:59:30 +0000
commita18799c9f639c926ded27d3df1b8135b76ba3aef (patch)
treef8796b7f6b1f1881acac7239e30a508cc9351d7f /device/bluetooth
parent102738a6facd9f1d9b020e55ba79f06fb26db0a7 (diff)
downloadchromium_src-a18799c9f639c926ded27d3df1b8135b76ba3aef.zip
chromium_src-a18799c9f639c926ded27d3df1b8135b76ba3aef.tar.gz
chromium_src-a18799c9f639c926ded27d3df1b8135b76ba3aef.tar.bz2
Bluetooth: remove private members from BluetoothAdapter
BluetoothAdapter had two private member variables: address_ and name_ and expected implementations to fill them in so its address() and name() member functions could return const refs to them. That's a bad design, and prevented implementations from just fetching these properties on demand, so make the functions pure virtual and expect implementations to provide them. BUG=none TEST=device_unittests, unit_tests, browser_tests Review URL: https://chromiumcodereview.appspot.com/13224004 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@191941 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'device/bluetooth')
-rw-r--r--device/bluetooth/bluetooth_adapter.cc8
-rw-r--r--device/bluetooth/bluetooth_adapter.h10
-rw-r--r--device/bluetooth/bluetooth_adapter_chromeos.cc8
-rw-r--r--device/bluetooth/bluetooth_adapter_chromeos.h4
-rw-r--r--device/bluetooth/bluetooth_adapter_chromeos_experimental.cc8
-rw-r--r--device/bluetooth/bluetooth_adapter_chromeos_experimental.h2
-rw-r--r--device/bluetooth/bluetooth_adapter_mac.h4
-rw-r--r--device/bluetooth/bluetooth_adapter_mac.mm8
-rw-r--r--device/bluetooth/bluetooth_adapter_win.cc8
-rw-r--r--device/bluetooth/bluetooth_adapter_win.h4
-rw-r--r--device/bluetooth/test/mock_bluetooth_adapter.cc5
-rw-r--r--device/bluetooth/test/mock_bluetooth_adapter.h4
12 files changed, 52 insertions, 21 deletions
diff --git a/device/bluetooth/bluetooth_adapter.cc b/device/bluetooth/bluetooth_adapter.cc
index b64c143..8cce6ec 100644
--- a/device/bluetooth/bluetooth_adapter.cc
+++ b/device/bluetooth/bluetooth_adapter.cc
@@ -16,14 +16,6 @@ BluetoothAdapter::~BluetoothAdapter() {
STLDeleteValues(&devices_);
}
-const std::string& BluetoothAdapter::address() const {
- return address_;
-}
-
-const std::string& BluetoothAdapter::name() const {
- return name_;
-}
-
BluetoothAdapter::DeviceList BluetoothAdapter::GetDevices() {
ConstDeviceList const_devices =
const_cast<const BluetoothAdapter *>(this)->GetDevices();
diff --git a/device/bluetooth/bluetooth_adapter.h b/device/bluetooth/bluetooth_adapter.h
index f1a7f51..7ea7095 100644
--- a/device/bluetooth/bluetooth_adapter.h
+++ b/device/bluetooth/bluetooth_adapter.h
@@ -86,10 +86,10 @@ class BluetoothAdapter : public base::RefCounted<BluetoothAdapter> {
// The address of this adapter. The address format is "XX:XX:XX:XX:XX:XX",
// where each XX is a hexadecimal number.
- virtual const std::string& address() const;
+ virtual std::string address() const = 0;
// The name of the adapter.
- virtual const std::string& name() const;
+ virtual std::string name() const = 0;
// Indicates whether the adapter is initialized and ready to use.
virtual bool IsInitialized() const = 0;
@@ -157,12 +157,6 @@ class BluetoothAdapter : public base::RefCounted<BluetoothAdapter> {
BluetoothAdapter();
virtual ~BluetoothAdapter();
- // Address of the adapter.
- std::string address_;
-
- // Name of the adapter.
- std::string name_;
-
// Devices paired with, connected to, discovered by, or visible to the
// adapter. The key is the Bluetooth address of the device and the value
// is the BluetoothDevice object whose lifetime is managed by the
diff --git a/device/bluetooth/bluetooth_adapter_chromeos.cc b/device/bluetooth/bluetooth_adapter_chromeos.cc
index 26c91e2..6ba6343 100644
--- a/device/bluetooth/bluetooth_adapter_chromeos.cc
+++ b/device/bluetooth/bluetooth_adapter_chromeos.cc
@@ -65,6 +65,14 @@ void BluetoothAdapterChromeOS::RemoveObserver(
observers_.RemoveObserver(observer);
}
+std::string BluetoothAdapterChromeOS::address() const {
+ return address_;
+}
+
+std::string BluetoothAdapterChromeOS::name() const {
+ return name_;
+}
+
// TODO(youngki) Return true when object path and properties of the adapter are
// initialized.
bool BluetoothAdapterChromeOS::IsInitialized() const {
diff --git a/device/bluetooth/bluetooth_adapter_chromeos.h b/device/bluetooth/bluetooth_adapter_chromeos.h
index 3e794e3..0c4f960 100644
--- a/device/bluetooth/bluetooth_adapter_chromeos.h
+++ b/device/bluetooth/bluetooth_adapter_chromeos.h
@@ -42,6 +42,8 @@ class BluetoothAdapterChromeOS
device::BluetoothAdapter::Observer* observer) OVERRIDE;
virtual void RemoveObserver(
device::BluetoothAdapter::Observer* observer) OVERRIDE;
+ virtual std::string address() const OVERRIDE;
+ virtual std::string name() const OVERRIDE;
virtual bool IsInitialized() const OVERRIDE;
virtual bool IsPresent() const OVERRIDE;
virtual bool IsPowered() const OVERRIDE;
@@ -214,6 +216,8 @@ class BluetoothAdapterChromeOS
// Tracked adapter state, cached locally so we only send change notifications
// to observers on a genuine change.
+ std::string address_;
+ std::string name_;
bool powered_;
bool discovering_;
diff --git a/device/bluetooth/bluetooth_adapter_chromeos_experimental.cc b/device/bluetooth/bluetooth_adapter_chromeos_experimental.cc
index 4a09e56..35c0db6 100644
--- a/device/bluetooth/bluetooth_adapter_chromeos_experimental.cc
+++ b/device/bluetooth/bluetooth_adapter_chromeos_experimental.cc
@@ -26,6 +26,14 @@ void BluetoothAdapterChromeOSExperimental::RemoveObserver(
BluetoothAdapter::Observer* observer) {
}
+std::string BluetoothAdapterChromeOSExperimental::address() const {
+ return std::string();
+}
+
+std::string BluetoothAdapterChromeOSExperimental::name() const {
+ return std::string();
+}
+
bool BluetoothAdapterChromeOSExperimental::IsInitialized() const {
return true;
}
diff --git a/device/bluetooth/bluetooth_adapter_chromeos_experimental.h b/device/bluetooth/bluetooth_adapter_chromeos_experimental.h
index 8dea9c2..72cf039 100644
--- a/device/bluetooth/bluetooth_adapter_chromeos_experimental.h
+++ b/device/bluetooth/bluetooth_adapter_chromeos_experimental.h
@@ -30,6 +30,8 @@ class BluetoothAdapterChromeOSExperimental
device::BluetoothAdapter::Observer* observer) OVERRIDE;
virtual void RemoveObserver(
device::BluetoothAdapter::Observer* observer) OVERRIDE;
+ virtual std::string address() const OVERRIDE;
+ virtual std::string name() const OVERRIDE;
virtual bool IsInitialized() const OVERRIDE;
virtual bool IsPresent() const OVERRIDE;
virtual bool IsPowered() const OVERRIDE;
diff --git a/device/bluetooth/bluetooth_adapter_mac.h b/device/bluetooth/bluetooth_adapter_mac.h
index 5f193a8..3f107d2 100644
--- a/device/bluetooth/bluetooth_adapter_mac.h
+++ b/device/bluetooth/bluetooth_adapter_mac.h
@@ -43,6 +43,8 @@ class BluetoothAdapterMac : public BluetoothAdapter {
// BluetoothAdapter override
virtual void AddObserver(BluetoothAdapter::Observer* observer) OVERRIDE;
virtual void RemoveObserver(BluetoothAdapter::Observer* observer) OVERRIDE;
+ virtual std::string address() const OVERRIDE;
+ virtual std::string name() const OVERRIDE;
virtual bool IsInitialized() const OVERRIDE;
virtual bool IsPresent() const OVERRIDE;
virtual bool IsPowered() const OVERRIDE;
@@ -106,6 +108,8 @@ class BluetoothAdapterMac : public BluetoothAdapter {
void RunCallbacks(const DiscoveryCallbackList& callback_list,
bool success) const;
+ std::string address_;
+ std::string name_;
bool powered_;
DiscoveryStatus discovery_status_;
diff --git a/device/bluetooth/bluetooth_adapter_mac.mm b/device/bluetooth/bluetooth_adapter_mac.mm
index c057841..0d2233c 100644
--- a/device/bluetooth/bluetooth_adapter_mac.mm
+++ b/device/bluetooth/bluetooth_adapter_mac.mm
@@ -117,6 +117,14 @@ void BluetoothAdapterMac::RemoveObserver(BluetoothAdapter::Observer* observer) {
observers_.RemoveObserver(observer);
}
+std::string BluetoothAdapterMac::address() const {
+ return address_;
+}
+
+std::string BluetoothAdapterMac::name() const {
+ return name_;
+}
+
bool BluetoothAdapterMac::IsInitialized() const {
return true;
}
diff --git a/device/bluetooth/bluetooth_adapter_win.cc b/device/bluetooth/bluetooth_adapter_win.cc
index 4b0f532..28d3dcc 100644
--- a/device/bluetooth/bluetooth_adapter_win.cc
+++ b/device/bluetooth/bluetooth_adapter_win.cc
@@ -45,6 +45,14 @@ void BluetoothAdapterWin::RemoveObserver(BluetoothAdapter::Observer* observer) {
observers_.RemoveObserver(observer);
}
+std::string BluetoothAdapterWin::address() const {
+ return address_;
+}
+
+std::string BluetoothAdapterWin::name() const {
+ return name_;
+}
+
// TODO(youngki): Return true when |task_manager_| initializes the adapter
// state.
bool BluetoothAdapterWin::IsInitialized() const {
diff --git a/device/bluetooth/bluetooth_adapter_win.h b/device/bluetooth/bluetooth_adapter_win.h
index 59e1a53..d255448 100644
--- a/device/bluetooth/bluetooth_adapter_win.h
+++ b/device/bluetooth/bluetooth_adapter_win.h
@@ -36,6 +36,8 @@ class BluetoothAdapterWin : public BluetoothAdapter,
// BluetoothAdapter override
virtual void AddObserver(BluetoothAdapter::Observer* observer) OVERRIDE;
virtual void RemoveObserver(BluetoothAdapter::Observer* observer) OVERRIDE;
+ virtual std::string address() const OVERRIDE;
+ virtual std::string name() const OVERRIDE;
virtual bool IsInitialized() const OVERRIDE;
virtual bool IsPresent() const OVERRIDE;
virtual bool IsPowered() const OVERRIDE;
@@ -87,6 +89,8 @@ class BluetoothAdapterWin : public BluetoothAdapter,
void MaybePostStopDiscoveryTask();
InitCallback init_callback_;
+ std::string address_;
+ std::string name_;
bool initialized_;
bool powered_;
DiscoveryStatus discovery_status_;
diff --git a/device/bluetooth/test/mock_bluetooth_adapter.cc b/device/bluetooth/test/mock_bluetooth_adapter.cc
index cae8829..5848db3 100644
--- a/device/bluetooth/test/mock_bluetooth_adapter.cc
+++ b/device/bluetooth/test/mock_bluetooth_adapter.cc
@@ -9,10 +9,7 @@ namespace device {
MockBluetoothAdapter::Observer::Observer() {}
MockBluetoothAdapter::Observer::~Observer() {}
-MockBluetoothAdapter::MockBluetoothAdapter(const std::string& address,
- const std::string& name) {
- address_ = address;
- name_ = name;
+MockBluetoothAdapter::MockBluetoothAdapter() {
}
MockBluetoothAdapter::~MockBluetoothAdapter() {}
diff --git a/device/bluetooth/test/mock_bluetooth_adapter.h b/device/bluetooth/test/mock_bluetooth_adapter.h
index 078d353..f375b4c 100644
--- a/device/bluetooth/test/mock_bluetooth_adapter.h
+++ b/device/bluetooth/test/mock_bluetooth_adapter.h
@@ -29,10 +29,12 @@ class MockBluetoothAdapter : public BluetoothAdapter {
MOCK_METHOD2(DeviceRemoved, void(BluetoothAdapter*, BluetoothDevice*));
};
- MockBluetoothAdapter(const std::string& address, const std::string& name);
+ MockBluetoothAdapter();
MOCK_METHOD1(AddObserver, void(BluetoothAdapter::Observer*));
MOCK_METHOD1(RemoveObserver, void(BluetoothAdapter::Observer*));
+ MOCK_CONST_METHOD0(address, std::string());
+ MOCK_CONST_METHOD0(name, std::string());
MOCK_CONST_METHOD0(IsInitialized, bool());
MOCK_CONST_METHOD0(IsPresent, bool());
MOCK_CONST_METHOD0(IsPowered, bool());