| Index: chrome/browser/extensions/api/bluetooth/bluetooth_api.cc
|
| diff --git a/chrome/browser/extensions/api/bluetooth/bluetooth_api.cc b/chrome/browser/extensions/api/bluetooth/bluetooth_api.cc
|
| index 76b5940c0e1ef09a285a4c41d36ae0e5037f1c7c..5ac730c741ad90fda1a3123ef3be420a436c4ba0 100644
|
| --- a/chrome/browser/extensions/api/bluetooth/bluetooth_api.cc
|
| +++ b/chrome/browser/extensions/api/bluetooth/bluetooth_api.cc
|
| @@ -4,6 +4,7 @@
|
|
|
| #include "chrome/browser/extensions/api/bluetooth/bluetooth_api.h"
|
|
|
| +#include "base/memory/weak_ptr.h"
|
| #include "base/utf_string_conversions.h"
|
| #include "chrome/browser/extensions/extension_service.h"
|
| #include "chrome/browser/profiles/profile.h"
|
| @@ -12,6 +13,7 @@
|
| #if defined(OS_CHROMEOS)
|
| #include "chrome/browser/chromeos/bluetooth/bluetooth_adapter.h"
|
| #include "chrome/browser/chromeos/bluetooth/bluetooth_device.h"
|
| +#include "chrome/browser/chromeos/bluetooth/bluetooth_socket.h"
|
| #include "chrome/browser/chromeos/extensions/bluetooth_event_router.h"
|
|
|
| using chromeos::BluetoothAdapter;
|
| @@ -20,33 +22,32 @@ using chromeos::BluetoothDevice;
|
|
|
| namespace GetDevicesWithService =
|
| extensions::api::experimental_bluetooth::GetDevicesWithService;
|
| +namespace Connect = extensions::api::experimental_bluetooth::Connect;
|
| +namespace Disconnect = extensions::api::experimental_bluetooth::Disconnect;
|
|
|
| namespace extensions {
|
| namespace api {
|
|
|
| #if defined(OS_CHROMEOS)
|
| -BluetoothExtensionFunction::BluetoothExtensionFunction() : adapter_(
|
| - profile()->GetExtensionService()->bluetooth_event_router()->adapter()) {
|
| +BluetoothExtensionFunction::BluetoothExtensionFunction() {
|
| + chromeos::ExtensionBluetoothEventRouter* event_router =
|
| + profile()->GetExtensionService()->bluetooth_event_router();
|
| + const_adapter_ = event_router->adapter();
|
| + adapter_ = event_router->GetMutableAdapter();
|
| }
|
|
|
| bool BluetoothIsAvailableFunction::RunImpl() {
|
| - const BluetoothAdapter *adapter =
|
| - profile()->GetExtensionService()->bluetooth_event_router()->adapter();
|
| - result_.reset(Value::CreateBooleanValue(adapter->IsPresent()));
|
| + result_.reset(Value::CreateBooleanValue(const_adapter_->IsPresent()));
|
| return true;
|
| }
|
|
|
| bool BluetoothIsPoweredFunction::RunImpl() {
|
| - const BluetoothAdapter *adapter =
|
| - profile()->GetExtensionService()->bluetooth_event_router()->adapter();
|
| - result_.reset(Value::CreateBooleanValue(adapter->IsPowered()));
|
| + result_.reset(Value::CreateBooleanValue(const_adapter_->IsPowered()));
|
| return true;
|
| }
|
|
|
| bool BluetoothGetAddressFunction::RunImpl() {
|
| - const chromeos::BluetoothAdapter *adapter =
|
| - profile()->GetExtensionService()->bluetooth_event_router()->adapter();
|
| - result_.reset(Value::CreateStringValue(adapter->address()));
|
| + result_.reset(Value::CreateStringValue(const_adapter_->address()));
|
| return false;
|
| }
|
|
|
| @@ -54,7 +55,7 @@ bool BluetoothGetDevicesWithServiceFunction::RunImpl() {
|
| scoped_ptr<GetDevicesWithService::Params> params(
|
| GetDevicesWithService::Params::Create(*args_));
|
|
|
| - BluetoothAdapter::ConstDeviceList devices = adapter_->GetDevices();
|
| + BluetoothAdapter::ConstDeviceList devices = const_adapter_->GetDevices();
|
|
|
| ListValue* matches = new ListValue();
|
| for (BluetoothAdapter::ConstDeviceList::const_iterator i =
|
| @@ -75,6 +76,41 @@ bool BluetoothGetDevicesWithServiceFunction::RunImpl() {
|
| return true;
|
| }
|
|
|
| +bool BluetoothConnectFunction::RunImpl() {
|
| + scoped_ptr<Connect::Params> params(Connect::Params::Create(*args_));
|
| +
|
| + chromeos::BluetoothDevice* device =
|
| + adapter_->GetDevice(params->device.address);
|
| + if (!device)
|
| + return false;
|
| +
|
| + base::WeakPtr<chromeos::BluetoothSocket> socket =
|
| + device->OpenSocket(params->service);
|
| + if (!socket)
|
| + return false;
|
| +
|
| + experimental_bluetooth::Socket result_socket;
|
| + result_socket.device.address = device->address();
|
| + result_socket.device.name = UTF16ToUTF8(device->GetName());
|
| + result_socket.service_uuid = params->service;
|
| + result_socket.id = socket->id();
|
| + result_.reset(result_socket.ToValue().get());
|
| + return true;
|
| +}
|
| +
|
| +bool BluetoothDisconnectFunction::RunImpl() {
|
| + scoped_ptr<Disconnect::Params> params(Disconnect::Params::Create(*args_));
|
| +
|
| + chromeos::BluetoothDevice* device =
|
| + adapter_->GetDevice(params->socket.device.address);
|
| + if (!device)
|
| + return false;
|
| +
|
| + device->CloseSocket(params->socket.id);
|
| +
|
| + return true;
|
| +}
|
| +
|
| #else
|
|
|
| BluetoothExtensionFunction::BluetoothExtensionFunction() {}
|
| @@ -102,13 +138,18 @@ bool BluetoothGetDevicesWithServiceFunction::RunImpl() {
|
| return false;
|
| }
|
|
|
| -#endif
|
| +bool BluetoothConnectFunction::RunImpl() {
|
| + NOTREACHED() << "Not implemented yet";
|
| + return false;
|
| +}
|
|
|
| bool BluetoothDisconnectFunction::RunImpl() {
|
| NOTREACHED() << "Not implemented yet";
|
| return false;
|
| }
|
|
|
| +#endif
|
| +
|
| bool BluetoothReadFunction::RunImpl() {
|
| NOTREACHED() << "Not implemented yet";
|
| return false;
|
| @@ -129,10 +170,5 @@ bool BluetoothWriteFunction::RunImpl() {
|
| return false;
|
| }
|
|
|
| -bool BluetoothConnectFunction::RunImpl() {
|
| - NOTREACHED() << "Not implemented yet";
|
| - return false;
|
| -}
|
| -
|
| } // namespace api
|
| } // namespace extensions
|
|
|