summaryrefslogtreecommitdiffstats
path: root/chrome/browser/extensions
diff options
context:
space:
mode:
authorbryeung@chromium.org <bryeung@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-06-15 15:55:26 +0000
committerbryeung@chromium.org <bryeung@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-06-15 15:55:26 +0000
commitb2fcf9eaefb2b71ca34280343e87bf0c788f1af4 (patch)
tree44e2eb0ccbcedc5495f4fcb1b4e54486a0924867 /chrome/browser/extensions
parent5cfd4d7b7cb444a08024dadb7df34be9a98cd921 (diff)
downloadchromium_src-b2fcf9eaefb2b71ca34280343e87bf0c788f1af4.zip
chromium_src-b2fcf9eaefb2b71ca34280343e87bf0c788f1af4.tar.gz
chromium_src-b2fcf9eaefb2b71ca34280343e87bf0c788f1af4.tar.bz2
Add additional device attributes.
TEST=updated apitest BUG=none Committed: http://src.chromium.org/viewvc/chrome?view=rev&revision=142360 Review URL: https://chromiumcodereview.appspot.com/10537167 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@142396 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/extensions')
-rw-r--r--chrome/browser/extensions/api/bluetooth/bluetooth_api.cc36
-rw-r--r--chrome/browser/extensions/api/bluetooth/bluetooth_apitest_chromeos.cc21
2 files changed, 40 insertions, 17 deletions
diff --git a/chrome/browser/extensions/api/bluetooth/bluetooth_api.cc b/chrome/browser/extensions/api/bluetooth/bluetooth_api.cc
index 3b6e034..92ca8a3 100644
--- a/chrome/browser/extensions/api/bluetooth/bluetooth_api.cc
+++ b/chrome/browser/extensions/api/bluetooth/bluetooth_api.cc
@@ -43,6 +43,23 @@ chromeos::BluetoothAdapter* GetMutableAdapter(Profile* profile) {
return GetEventRouter(profile)->GetMutableAdapter();
}
+// Fill in a Device object from a chromeos::BluetoothDevice.
+void PopulateApiDevice(const chromeos::BluetoothDevice& device,
+ extensions::api::experimental_bluetooth::Device* out) {
+ out->name = UTF16ToUTF8(device.GetName());
+ out->address = device.address();
+ out->paired = device.IsPaired();
+ out->bonded = device.IsBonded();
+ out->connected = device.IsConnected();
+}
+
+// The caller takes ownership of the returned pointer.
+base::Value* BluetoothDeviceToValue(const chromeos::BluetoothDevice& device) {
+ extensions::api::experimental_bluetooth::Device api_device;
+ PopulateApiDevice(device, &api_device);
+ return api_device.ToValue().release();
+}
+
} // namespace
#endif
@@ -103,12 +120,8 @@ bool BluetoothGetDevicesWithServiceUUIDFunction::RunImpl() {
ListValue* matches = new ListValue;
for (BluetoothAdapter::ConstDeviceList::const_iterator i =
devices.begin(); i != devices.end(); ++i) {
- if ((*i)->ProvidesServiceWithUUID(params->uuid)) {
- experimental_bluetooth::Device device;
- device.name = UTF16ToUTF8((*i)->GetName());
- device.address = (*i)->address();
- matches->Append(device.ToValue().release());
- }
+ if ((*i)->ProvidesServiceWithUUID(params->uuid))
+ matches->Append(BluetoothDeviceToValue(**i));
}
result_.reset(matches);
@@ -122,12 +135,8 @@ void BluetoothGetDevicesWithServiceNameFunction::AddDeviceIfTrue(
ListValue* list, const BluetoothDevice* device, bool result) {
DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
- if (result) {
- experimental_bluetooth::Device device_result;
- device_result.name = UTF16ToUTF8(device->GetName());
- device_result.address = device->address();
- list->Append(device_result.ToValue().release());
- }
+ if (result)
+ list->Append(BluetoothDeviceToValue(*device));
callbacks_pending_--;
if (callbacks_pending_ == 0) {
@@ -175,8 +184,7 @@ void BluetoothConnectFunction::ConnectToServiceCallback(
int socket_id = GetEventRouter(profile())->RegisterSocket(socket);
experimental_bluetooth::Socket result_socket;
- result_socket.device.address = device->address();
- result_socket.device.name = UTF16ToUTF8(device->GetName());
+ PopulateApiDevice(*device, &result_socket.device);
result_socket.service_uuid = service_uuid;
result_socket.id = socket_id;
result_.reset(result_socket.ToValue().release());
diff --git a/chrome/browser/extensions/api/bluetooth/bluetooth_apitest_chromeos.cc b/chrome/browser/extensions/api/bluetooth/bluetooth_apitest_chromeos.cc
index 4e0602f..62ac9ae 100644
--- a/chrome/browser/extensions/api/bluetooth/bluetooth_apitest_chromeos.cc
+++ b/chrome/browser/extensions/api/bluetooth/bluetooth_apitest_chromeos.cc
@@ -135,9 +135,11 @@ IN_PROC_BROWSER_TEST_F(BluetoothApiTest, IsPowered) {
IN_PROC_BROWSER_TEST_F(BluetoothApiTest, GetDevicesWithServiceUUID) {
testing::NiceMock<chromeos::MockBluetoothDevice> device1(
- mock_adapter_, "d1", "11:12:13:14:15:16");
+ mock_adapter_, "d1", "11:12:13:14:15:16",
+ true /* paired */, false /* bonded */, true /* connected */);
testing::NiceMock<chromeos::MockBluetoothDevice> device2(
- mock_adapter_, "d2", "21:22:23:24:25:26");
+ mock_adapter_, "d2", "21:22:23:24:25:26",
+ false /* paired */, true /* bonded */, false /* connected */);
chromeos::BluetoothAdapter::ConstDeviceList devices;
devices.push_back(&device1);
devices.push_back(&device2);
@@ -171,6 +173,18 @@ IN_PROC_BROWSER_TEST_F(BluetoothApiTest, GetDevicesWithServiceUUID) {
std::string name;
ASSERT_TRUE(device->GetString("name", &name));
EXPECT_EQ("d2", name);
+ std::string address;
+ ASSERT_TRUE(device->GetString("address", &address));
+ EXPECT_EQ("21:22:23:24:25:26", address);
+ bool paired;
+ ASSERT_TRUE(device->GetBoolean("paired", &paired));
+ EXPECT_EQ(false, paired);
+ bool bonded;
+ ASSERT_TRUE(device->GetBoolean("bonded", &bonded));
+ EXPECT_EQ(true, bonded);
+ bool connected;
+ ASSERT_TRUE(device->GetBoolean("connected", &connected));
+ EXPECT_EQ(false, connected);
}
IN_PROC_BROWSER_TEST_F(BluetoothApiTest, GetLocalOutOfBandPairingData) {
@@ -221,7 +235,8 @@ IN_PROC_BROWSER_TEST_F(BluetoothApiTest, DISABLED_SetOutOfBandPairingData) {
IN_PROC_BROWSER_TEST_F(BluetoothApiTest, ClearOutOfBandPairingData) {
std::string device_address("11:12:13:14:15:16");
testing::NiceMock<chromeos::MockBluetoothDevice> device(
- mock_adapter_, "d1", device_address);
+ mock_adapter_, "d1", device_address,
+ true /* paired */, false /* bonded */, true /* connected */);
EXPECT_CALL(*mock_adapter_, GetDevice(device_address))
.WillOnce(testing::Return(&device));
EXPECT_CALL(device,