| 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 45318596101cab014d5fc4c3d09cd6afd1a52dd6..f4e6e78f269dbb0c3f8c448b691ce1202dd9a339 100644
|
| --- a/chrome/browser/extensions/api/bluetooth/bluetooth_api.cc
|
| +++ b/chrome/browser/extensions/api/bluetooth/bluetooth_api.cc
|
| @@ -4,15 +4,18 @@
|
|
|
| #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"
|
| #include "chrome/common/extensions/api/experimental.bluetooth.h"
|
|
|
| #if defined(OS_CHROMEOS)
|
| +#include "base/memory/ref_counted.h"
|
| #include "base/synchronization/lock.h"
|
| #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;
|
| @@ -24,6 +27,8 @@ namespace GetDevicesWithServiceUUID =
|
| extensions::api::experimental_bluetooth::GetDevicesWithServiceUUID;
|
| namespace GetDevicesWithServiceName =
|
| extensions::api::experimental_bluetooth::GetDevicesWithServiceName;
|
| +namespace Connect = extensions::api::experimental_bluetooth::Connect;
|
| +namespace Disconnect = extensions::api::experimental_bluetooth::Disconnect;
|
|
|
| namespace extensions {
|
| namespace api {
|
| @@ -31,12 +36,15 @@ namespace api {
|
| #if defined(OS_CHROMEOS)
|
|
|
| const chromeos::BluetoothAdapter* BluetoothExtensionFunction::adapter() const {
|
| - return profile()->GetExtensionService()->bluetooth_event_router()->adapter();
|
| + const chromeos::ExtensionBluetoothEventRouter* bluetooth_event_router =
|
| + profile()->GetExtensionService()->bluetooth_event_router();
|
| + return bluetooth_event_router->adapter();
|
| }
|
|
|
| chromeos::BluetoothAdapter* BluetoothExtensionFunction::GetMutableAdapter() {
|
| - return profile()->GetExtensionService()->bluetooth_event_router()->
|
| - GetMutableAdapter();
|
| + chromeos::ExtensionBluetoothEventRouter* bluetooth_event_router =
|
| + profile()->GetExtensionService()->bluetooth_event_router();
|
| + return bluetooth_event_router->GetMutableAdapter();
|
| }
|
|
|
| const chromeos::BluetoothAdapter*
|
| @@ -135,6 +143,55 @@ bool BluetoothGetDevicesWithServiceNameFunction::RunImpl() {
|
| return true;
|
| }
|
|
|
| +void BluetoothConnectFunction::ConnectToServiceCallback(
|
| + const chromeos::BluetoothDevice* device,
|
| + const std::string& service_uuid,
|
| + scoped_refptr<chromeos::BluetoothSocket> socket) {
|
| + if (socket.get()) {
|
| + // TODO(bryeung): hold on to this socket somewhere...
|
| +
|
| + experimental_bluetooth::Socket result_socket;
|
| + result_socket.device.address = device->address();
|
| + result_socket.device.name = UTF16ToUTF8(device->GetName());
|
| + result_socket.service_uuid = service_uuid;
|
| + result_socket.id = socket->fd();
|
| + result_.reset(result_socket.ToValue().get());
|
| + SendResponse(true);
|
| + }
|
| + SendResponse(false);
|
| +}
|
| +
|
| +bool BluetoothConnectFunction::RunImpl() {
|
| + scoped_ptr<Connect::Params> params(Connect::Params::Create(*args_));
|
| +
|
| + chromeos::BluetoothDevice* device =
|
| + GetMutableAdapter()->GetDevice(params->device.address);
|
| + if (!device) {
|
| + SendResponse(false);
|
| + return false;
|
| + }
|
| +
|
| + device->ConnectToService(params->service,
|
| + base::Bind(&BluetoothConnectFunction::ConnectToServiceCallback,
|
| + this,
|
| + device,
|
| + params->service));
|
| + return true;
|
| +}
|
| +
|
| +bool BluetoothDisconnectFunction::RunImpl() {
|
| + scoped_ptr<Disconnect::Params> params(Disconnect::Params::Create(*args_));
|
| +
|
| + chromeos::BluetoothDevice* device =
|
| + GetMutableAdapter()->GetDevice(params->socket.device.address);
|
| + if (!device)
|
| + return false;
|
| +
|
| + // TODO(bryeung): implement this...
|
| +
|
| + return true;
|
| +}
|
| +
|
| #else
|
|
|
| // -----------------------------------------------------------------------------
|
| @@ -165,13 +222,18 @@ bool BluetoothGetDevicesWithServiceNameFunction::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;
|
| @@ -192,10 +254,5 @@ bool BluetoothWriteFunction::RunImpl() {
|
| return false;
|
| }
|
|
|
| -bool BluetoothConnectFunction::RunImpl() {
|
| - NOTREACHED() << "Not implemented yet";
|
| - return false;
|
| -}
|
| -
|
| } // namespace api
|
| } // namespace extensions
|
|
|