Chromium Code Reviews| Index: chrome/browser/extensions/api/bluetooth_low_energy/bluetooth_low_energy_api.cc |
| diff --git a/chrome/browser/extensions/api/bluetooth_low_energy/bluetooth_low_energy_api.cc b/chrome/browser/extensions/api/bluetooth_low_energy/bluetooth_low_energy_api.cc |
| index 8328f82cc883d6be535276e0460c8883534d1f20..b5348b802f06f8b1450d5a248b38ed681fe7cb10 100644 |
| --- a/chrome/browser/extensions/api/bluetooth_low_energy/bluetooth_low_energy_api.cc |
| +++ b/chrome/browser/extensions/api/bluetooth_low_energy/bluetooth_low_energy_api.cc |
| @@ -6,20 +6,22 @@ |
| #include <stdint.h> |
| #include <algorithm> |
| -#include <utility> |
| +#include <iterator> |
| +#include <vector> |
| #include "base/bind.h" |
| +#include "base/callback.h" |
| +#include "base/callback_forward.h" |
| #include "base/command_line.h" |
| #include "base/lazy_instance.h" |
| -#include "base/strings/stringprintf.h" |
| -#include "build/build_config.h" |
| -#include "chrome/browser/extensions/api/bluetooth_low_energy/bluetooth_api_advertisement.h" |
| +#include "base/logging.h" |
| +#include "base/values.h" |
| #include "chrome/browser/extensions/api/bluetooth_low_energy/utils.h" |
| #include "chrome/common/extensions/api/bluetooth_low_energy.h" |
| #include "content/public/browser/browser_thread.h" |
| -#include "extensions/browser/event_router.h" |
| +#include "device/bluetooth/bluetooth_adapter.h" |
| #include "extensions/common/api/bluetooth/bluetooth_manifest_data.h" |
| -#include "extensions/common/permissions/permissions_data.h" |
| +#include "extensions/common/extension.h" |
| #include "extensions/common/switches.h" |
| #if defined(OS_CHROMEOS) |
| @@ -127,7 +129,12 @@ extensions::BluetoothLowEnergyEventRouter* GetEventRouter( |
| return extensions::BluetoothLowEnergyAPI::Get(context)->event_router(); |
| } |
| -void DoWorkCallback(const base::Callback<bool()>& callback) { |
| +void DoWorkReturnBoolCallback(const base::Callback<bool()>& callback) { |
|
Devlin
2016/04/27 14:45:03
if you wanted to be extra fancy you could do somet
rkc
2016/04/27 20:38:56
Converting DoWork to return void would require cha
|
| + DCHECK(!callback.is_null()); |
| + callback.Run(); |
| +} |
| + |
| +void DoWorkCallback(const base::Callback<void()>& callback) { |
| DCHECK(!callback.is_null()); |
| callback.Run(); |
| } |
| @@ -189,13 +196,13 @@ void BluetoothLowEnergyAPI::Shutdown() { |
| namespace api { |
| -BluetoothLowEnergyExtensionFunction::BluetoothLowEnergyExtensionFunction() { |
| -} |
| +BluetoothLowEnergyExtensionFunctionDeprecated:: |
| + BluetoothLowEnergyExtensionFunctionDeprecated() {} |
| -BluetoothLowEnergyExtensionFunction::~BluetoothLowEnergyExtensionFunction() { |
| -} |
| +BluetoothLowEnergyExtensionFunctionDeprecated:: |
| + ~BluetoothLowEnergyExtensionFunctionDeprecated() {} |
| -bool BluetoothLowEnergyExtensionFunction::RunAsync() { |
| +bool BluetoothLowEnergyExtensionFunctionDeprecated::RunAsync() { |
| DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| if (!BluetoothManifestData::CheckLowEnergyPermitted(extension())) { |
| @@ -212,8 +219,9 @@ bool BluetoothLowEnergyExtensionFunction::RunAsync() { |
| // It is safe to pass |this| here as ExtensionFunction is refcounted. |
| if (!event_router->InitializeAdapterAndInvokeCallback(base::Bind( |
| - &DoWorkCallback, |
| - base::Bind(&BluetoothLowEnergyExtensionFunction::DoWork, this)))) { |
| + &DoWorkReturnBoolCallback, |
| + base::Bind(&BluetoothLowEnergyExtensionFunctionDeprecated::DoWork, |
| + this)))) { |
| SetError(kErrorAdapterNotInitialized); |
| return false; |
| } |
| @@ -221,6 +229,33 @@ bool BluetoothLowEnergyExtensionFunction::RunAsync() { |
| return true; |
| } |
| +BluetoothLowEnergyExtensionFunction::BluetoothLowEnergyExtensionFunction() {} |
| + |
| +BluetoothLowEnergyExtensionFunction::~BluetoothLowEnergyExtensionFunction() {} |
| + |
| +ExtensionFunction::ResponseAction BluetoothLowEnergyExtensionFunction::Run() { |
| + DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| + |
| + if (!BluetoothManifestData::CheckLowEnergyPermitted(extension())) { |
| + return RespondNow(Error(kErrorPermissionDenied)); |
| + } |
| + |
| + BluetoothLowEnergyEventRouter* event_router = |
| + GetEventRouter(browser_context()); |
| + if (!event_router->IsBluetoothSupported()) { |
| + return RespondNow(Error(kErrorPlatformNotSupported)); |
| + } |
| + |
| + // It is safe to pass |this| here as ExtensionFunction is refcounted. |
| + if (!event_router->InitializeAdapterAndInvokeCallback(base::Bind( |
| + &DoWorkCallback, |
| + base::Bind(&BluetoothLowEnergyExtensionFunction::DoWork, this)))) { |
| + return RespondNow(Error(kErrorAdapterNotInitialized)); |
| + } |
| + |
| + return RespondLater(); |
| +} |
| + |
| bool BluetoothLowEnergyConnectFunction::DoWork() { |
| DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| @@ -874,7 +909,7 @@ void BluetoothLowEnergyAdvertisementFunction::RemoveAdvertisement( |
| bool BluetoothLowEnergyAdvertisementFunction::RunAsync() { |
| Initialize(); |
| - return BluetoothLowEnergyExtensionFunction::RunAsync(); |
| + return BluetoothLowEnergyExtensionFunctionDeprecated::RunAsync(); |
| } |
| void BluetoothLowEnergyAdvertisementFunction::Initialize() { |
| @@ -1065,5 +1100,34 @@ void BluetoothLowEnergyUnregisterAdvertisementFunction::ErrorCallback( |
| SendResponse(false); |
| } |
| +void BluetoothLowEnergyCreateServiceFunction::DoWork() { |
| + DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| + Respond(ArgumentList(apibtle::CreateService::Results::Create(std::string()))); |
| +} |
| + |
| +void BluetoothLowEnergyCreateCharacteristicFunction::DoWork() { |
| + DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| + Respond(ArgumentList( |
| + apibtle::CreateCharacteristic::Results::Create(std::string()))); |
| +} |
| + |
| +void BluetoothLowEnergyCreateDescriptorFunction::DoWork() { |
| + DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| + Respond( |
| + ArgumentList(apibtle::CreateDescriptor::Results::Create(std::string()))); |
| +} |
| + |
| +void BluetoothLowEnergyRegisterServiceFunction::DoWork() { |
| + DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| + Respond(ArgumentList(apibtle::RegisterService::Results::Create( |
| + apibtle::SERVICE_RESULT_SUCCESS))); |
| +} |
| + |
| +void BluetoothLowEnergyUnregisterServiceFunction::DoWork() { |
| + DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| + Respond(ArgumentList(apibtle::UnregisterService::Results::Create( |
| + apibtle::SERVICE_RESULT_SUCCESS))); |
| +} |
| + |
| } // namespace api |
| } // namespace extensions |