summaryrefslogtreecommitdiffstats
path: root/chrome/browser/extensions
diff options
context:
space:
mode:
authorbryeung@chromium.org <bryeung@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-06-18 19:11:30 +0000
committerbryeung@chromium.org <bryeung@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-06-18 19:11:30 +0000
commit01e37094d08339c8e7ae650bf36884c87ab000c0 (patch)
tree0223002e7c4388d4883a49d7fed285300ee11dc8 /chrome/browser/extensions
parenta1e2a175190e37a0ae0a075c3dc217fde81760f2 (diff)
downloadchromium_src-01e37094d08339c8e7ae650bf36884c87ab000c0.zip
chromium_src-01e37094d08339c8e7ae650bf36884c87ab000c0.tar.gz
chromium_src-01e37094d08339c8e7ae650bf36884c87ab000c0.tar.bz2
Bluetooth API: Add getServices
This CL depends on https://chromiumcodereview.appspot.com/10543170/ TEST=coming soon BUG=132598 Review URL: https://chromiumcodereview.appspot.com/10543171 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@142775 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/extensions')
-rw-r--r--chrome/browser/extensions/api/bluetooth/bluetooth_api.cc57
-rw-r--r--chrome/browser/extensions/api/bluetooth/bluetooth_api.h22
2 files changed, 78 insertions, 1 deletions
diff --git a/chrome/browser/extensions/api/bluetooth/bluetooth_api.cc b/chrome/browser/extensions/api/bluetooth/bluetooth_api.cc
index 76d2233..b1e34ba 100644
--- a/chrome/browser/extensions/api/bluetooth/bluetooth_api.cc
+++ b/chrome/browser/extensions/api/bluetooth/bluetooth_api.cc
@@ -50,6 +50,7 @@ const char kCouldNotSetOutOfBandPairingData[] =
"Could not set Out Of Band Pairing Data";
const char kFailedToConnect[] = "Connection failed";
const char kInvalidDevice[] = "Invalid device";
+const char kServiceDiscoveryFailed[] = "Service discovery failed";
const char kSocketNotFoundError[] = "Socket not found: invalid socket id";
const char kStartDiscoveryFailed[] =
"Starting discovery failed, or already discovering";
@@ -60,6 +61,7 @@ const char kStopDiscoveryFailed[] = "Failed to stop discovery";
namespace Connect = extensions::api::experimental_bluetooth::Connect;
namespace Disconnect = extensions::api::experimental_bluetooth::Disconnect;
namespace GetDevices = extensions::api::experimental_bluetooth::GetDevices;
+namespace GetServices = extensions::api::experimental_bluetooth::GetServices;
namespace Read = extensions::api::experimental_bluetooth::Read;
namespace SetOutOfBandPairingData =
extensions::api::experimental_bluetooth::SetOutOfBandPairingData;
@@ -154,6 +156,56 @@ bool BluetoothGetDevicesFunction::RunImpl() {
return true;
}
+void BluetoothGetServicesFunction::GetServiceRecordsCallback(
+ base::ListValue* services,
+ const chromeos::BluetoothDevice::ServiceRecordList& records) {
+ for (chromeos::BluetoothDevice::ServiceRecordList::const_iterator i =
+ records.begin(); i != records.end(); ++i) {
+ const chromeos::BluetoothServiceRecord& record = **i;
+ experimental_bluetooth::ServiceRecord api_record;
+ api_record.name = record.name();
+ if (!record.uuid().empty())
+ api_record.uuid.reset(new std::string(record.uuid()));
+ services->Append(api_record.ToValue().release());
+ }
+
+ SendResponse(true);
+ Release(); // Added in RunImpl
+}
+
+void BluetoothGetServicesFunction::OnErrorCallback() {
+ SetError(kServiceDiscoveryFailed);
+ SendResponse(false);
+ Release(); // Added in RunImpl
+}
+
+bool BluetoothGetServicesFunction::RunImpl() {
+ scoped_ptr<GetServices::Params> params(GetServices::Params::Create(*args_));
+ EXTENSION_FUNCTION_VALIDATE(params.get() != NULL);
+ const experimental_bluetooth::GetServicesOptions& options = params->options;
+
+ chromeos::BluetoothDevice* device =
+ GetMutableAdapter(profile())->GetDevice(options.device_address);
+ if (!device) {
+ SendResponse(false);
+ SetError(kInvalidDevice);
+ return false;
+ }
+
+ ListValue* services = new ListValue;
+ result_.reset(services);
+
+ AddRef(); // Released in GetServiceRecordsCallback or OnErrorCallback
+ device->GetServiceRecords(
+ base::Bind(&BluetoothGetServicesFunction::GetServiceRecordsCallback,
+ this,
+ services),
+ base::Bind(&BluetoothGetServicesFunction::OnErrorCallback,
+ this));
+
+ return true;
+}
+
void BluetoothConnectFunction::ConnectToServiceCallback(
const chromeos::BluetoothDevice* device,
const std::string& service_uuid,
@@ -483,6 +535,11 @@ bool BluetoothGetDevicesFunction::RunImpl() {
return false;
}
+bool BluetoothGetServicesFunction::RunImpl() {
+ NOTREACHED() << "Not implemented yet";
+ return false;
+}
+
bool BluetoothConnectFunction::RunImpl() {
NOTREACHED() << "Not implemented yet";
return false;
diff --git a/chrome/browser/extensions/api/bluetooth/bluetooth_api.h b/chrome/browser/extensions/api/bluetooth/bluetooth_api.h
index 4abe159..397e0e3 100644
--- a/chrome/browser/extensions/api/bluetooth/bluetooth_api.h
+++ b/chrome/browser/extensions/api/bluetooth/bluetooth_api.h
@@ -13,11 +13,11 @@
#if defined(OS_CHROMEOS)
#include "base/memory/ref_counted.h"
+#include "chrome/browser/chromeos/bluetooth/bluetooth_device.h"
#include "chrome/browser/chromeos/bluetooth/bluetooth_socket.h"
namespace chromeos {
-class BluetoothDevice;
class BluetoothSocket;
struct BluetoothOutOfBandPairingData;
@@ -84,6 +84,26 @@ class BluetoothGetDevicesFunction : public AsyncExtensionFunction {
#endif
};
+class BluetoothGetServicesFunction : public AsyncExtensionFunction {
+ public:
+ DECLARE_EXTENSION_FUNCTION_NAME("experimental.bluetooth.getServices")
+
+ protected:
+ virtual ~BluetoothGetServicesFunction() {}
+
+ // ExtensionFunction:
+ virtual bool RunImpl() OVERRIDE;
+
+
+#if defined(OS_CHROMEOS)
+ private:
+ void GetServiceRecordsCallback(
+ base::ListValue* services,
+ const chromeos::BluetoothDevice::ServiceRecordList& records);
+ void OnErrorCallback();
+#endif
+};
+
class BluetoothConnectFunction : public AsyncExtensionFunction {
public:
DECLARE_EXTENSION_FUNCTION_NAME("experimental.bluetooth.connect")