Chromium Code Reviews| Index: chrome/browser/extensions/api/bluetooth_low_energy/bluetooth_low_energy_api.h |
| diff --git a/chrome/browser/extensions/api/bluetooth_low_energy/bluetooth_low_energy_api.h b/chrome/browser/extensions/api/bluetooth_low_energy/bluetooth_low_energy_api.h |
| index a7f4ed5bf7fc6c2fe6298e6ab7f364f82ce6639e..6d2233d71d7339a467b395c99d97e615a74fa02d 100644 |
| --- a/chrome/browser/extensions/api/bluetooth_low_energy/bluetooth_low_energy_api.h |
| +++ b/chrome/browser/extensions/api/bluetooth_low_energy/bluetooth_low_energy_api.h |
| @@ -5,21 +5,48 @@ |
| #ifndef CHROME_BROWSER_EXTENSIONS_API_BLUETOOTH_LOW_ENERGY_BLUETOOTH_LOW_ENERGY_API_H_ |
| #define CHROME_BROWSER_EXTENSIONS_API_BLUETOOTH_LOW_ENERGY_BLUETOOTH_LOW_ENERGY_API_H_ |
| -#include <memory> |
| +#include <string> |
| #include "base/macros.h" |
| +#include "base/memory/ref_counted.h" |
| +#include "chrome/browser/extensions/api/bluetooth_low_energy/bluetooth_api_advertisement.h" |
| #include "chrome/browser/extensions/api/bluetooth_low_energy/bluetooth_low_energy_event_router.h" |
| -#include "chrome/browser/extensions/browser_context_keyed_service_factories.h" |
| +#include "content/public/browser/browser_context.h" |
| #include "device/bluetooth/bluetooth_advertisement.h" |
| #include "extensions/browser/api/api_resource_manager.h" |
| +#include "extensions/browser/browser_context_keyed_api_factory.h" |
| #include "extensions/browser/extension_function.h" |
| #include "extensions/browser/extension_function_histogram_value.h" |
| -namespace extensions { |
| +namespace apibtle = extensions::api::bluetooth_low_energy; |
|
Devlin
2016/05/02 22:27:58
nit: this isn't typically allowed - only in .cc fi
rkc
2016/05/02 23:25:50
Done.
|
| +namespace extensions { |
| class BluetoothApiAdvertisement; |
| class BluetoothLowEnergyEventRouter; |
| +namespace api { |
| +namespace bluetooth_low_energy { |
| +namespace CreateService { |
| +struct Params; |
| +} |
| +namespace CreateCharacteristic { |
| +struct Params; |
| +} |
| +namespace CreateDescriptor { |
| +struct Params; |
| +} |
| +namespace RegisterService { |
| +struct Params; |
| +} |
| +namespace UnregisterService { |
| +struct Params; |
| +} |
| +namespace SendRequestResponse { |
| +struct Params; |
| +} |
| +} // namespace bluetooth_low_energy |
| +} // namespace api |
| + |
| // The profile-keyed service that manages the bluetoothLowEnergy extension API. |
| class BluetoothLowEnergyAPI : public BrowserContextKeyedAPI { |
| public: |
| @@ -57,14 +84,19 @@ namespace api { |
| // Base class for bluetoothLowEnergy API functions. This class handles some of |
| // the common logic involved in all API functions, such as checking for |
| // platform support and returning the correct error. |
| -class BluetoothLowEnergyExtensionFunction : public AsyncExtensionFunction { |
| +// |
| +// DEPRECATED: This inherits from AsyncExtensionFunction, which we're trying to |
| +// get rid of for various reasons. Please inherit from the |
| +// BluetoothLowEnergyExtensionFunction class instead. |
| +class BluetoothLowEnergyExtensionFunctionDeprecated |
| + : public AsyncExtensionFunction { |
| public: |
| - BluetoothLowEnergyExtensionFunction(); |
| + BluetoothLowEnergyExtensionFunctionDeprecated(); |
| protected: |
| - ~BluetoothLowEnergyExtensionFunction() override; |
| + ~BluetoothLowEnergyExtensionFunctionDeprecated() override; |
| - // ExtensionFunction override. |
| + // AsyncExtensionFunction override. |
| bool RunAsync() override; |
| // Implemented by individual bluetoothLowEnergy extension functions to perform |
| @@ -74,19 +106,64 @@ class BluetoothLowEnergyExtensionFunction : public AsyncExtensionFunction { |
| virtual bool DoWork() = 0; |
| private: |
| + DISALLOW_COPY_AND_ASSIGN(BluetoothLowEnergyExtensionFunctionDeprecated); |
| +}; |
| + |
| +// Replacement for BluetoothLowEnergyExtensionFunctionDeprecated. Has the same |
| +// functionality except that instead of the SendResponse/return combo, we'll |
| +// return our response with Respond(). |
| +class BluetoothLowEnergyExtensionFunction : public UIThreadExtensionFunction { |
| + public: |
| + BluetoothLowEnergyExtensionFunction(); |
| + |
| + protected: |
| + ~BluetoothLowEnergyExtensionFunction() override; |
| + |
| + // ExtensionFunction override. |
| + ResponseAction Run() override; |
| + |
| + // Implemented by individual bluetoothLowEnergy extension functions to perform |
| + // the body of the function. This invoked asynchonously after Run after |
| + // the BluetoothLowEnergyEventRouter has obtained a handle on the |
| + // BluetoothAdapter. |
| + virtual void DoWork() = 0; |
| + |
| + private: |
| DISALLOW_COPY_AND_ASSIGN(BluetoothLowEnergyExtensionFunction); |
| }; |
| -class BluetoothLowEnergyConnectFunction |
| +// Base class for bluetoothLowEnergy API peripheral mode functions. This class |
| +// handles some of the common logic involved in all API peripheral mode |
| +// functions, such as checking for peripheral permissions and returning the |
| +// correct error. |
| +template <typename Params> |
| +class BLEPeripheralExtensionFunction |
| : public BluetoothLowEnergyExtensionFunction { |
| public: |
| + BLEPeripheralExtensionFunction(); |
| + |
| + protected: |
| + ~BLEPeripheralExtensionFunction() override; |
| + |
| + // ExtensionFunction override. |
| + ResponseAction Run() override; |
| + |
| + std::unique_ptr<Params> params_; |
| + |
| + private: |
| + DISALLOW_COPY_AND_ASSIGN(BLEPeripheralExtensionFunction); |
| +}; |
| + |
| +class BluetoothLowEnergyConnectFunction |
| + : public BluetoothLowEnergyExtensionFunctionDeprecated { |
| + public: |
| DECLARE_EXTENSION_FUNCTION("bluetoothLowEnergy.connect", |
| BLUETOOTHLOWENERGY_CONNECT); |
| protected: |
| ~BluetoothLowEnergyConnectFunction() override {} |
| - // BluetoothLowEnergyExtensionFunction override. |
| + // BluetoothLowEnergyExtensionFunctionDeprecated override. |
| bool DoWork() override; |
| private: |
| @@ -97,7 +174,7 @@ class BluetoothLowEnergyConnectFunction |
| }; |
| class BluetoothLowEnergyDisconnectFunction |
| - : public BluetoothLowEnergyExtensionFunction { |
| + : public BluetoothLowEnergyExtensionFunctionDeprecated { |
| public: |
| DECLARE_EXTENSION_FUNCTION("bluetoothLowEnergy.disconnect", |
| BLUETOOTHLOWENERGY_DISCONNECT); |
| @@ -105,7 +182,7 @@ class BluetoothLowEnergyDisconnectFunction |
| protected: |
| ~BluetoothLowEnergyDisconnectFunction() override {} |
| - // BluetoothLowEnergyExtensionFunction override. |
| + // BluetoothLowEnergyExtensionFunctionDeprecated override. |
| bool DoWork() override; |
| private: |
| @@ -116,7 +193,7 @@ class BluetoothLowEnergyDisconnectFunction |
| }; |
| class BluetoothLowEnergyGetServiceFunction |
| - : public BluetoothLowEnergyExtensionFunction { |
| + : public BluetoothLowEnergyExtensionFunctionDeprecated { |
| public: |
| DECLARE_EXTENSION_FUNCTION("bluetoothLowEnergy.getService", |
| BLUETOOTHLOWENERGY_GETSERVICE); |
| @@ -124,12 +201,12 @@ class BluetoothLowEnergyGetServiceFunction |
| protected: |
| ~BluetoothLowEnergyGetServiceFunction() override {} |
| - // BluetoothLowEnergyExtensionFunction override. |
| + // BluetoothLowEnergyExtensionFunctionDeprecated override. |
| bool DoWork() override; |
| }; |
| class BluetoothLowEnergyGetServicesFunction |
| - : public BluetoothLowEnergyExtensionFunction { |
| + : public BluetoothLowEnergyExtensionFunctionDeprecated { |
| public: |
| DECLARE_EXTENSION_FUNCTION("bluetoothLowEnergy.getServices", |
| BLUETOOTHLOWENERGY_GETSERVICES); |
| @@ -137,12 +214,12 @@ class BluetoothLowEnergyGetServicesFunction |
| protected: |
| ~BluetoothLowEnergyGetServicesFunction() override {} |
| - // BluetoothLowEnergyExtensionFunction override. |
| + // BluetoothLowEnergyExtensionFunctionDeprecated override. |
| bool DoWork() override; |
| }; |
| class BluetoothLowEnergyGetCharacteristicFunction |
| - : public BluetoothLowEnergyExtensionFunction { |
| + : public BluetoothLowEnergyExtensionFunctionDeprecated { |
| public: |
| DECLARE_EXTENSION_FUNCTION("bluetoothLowEnergy.getCharacteristic", |
| BLUETOOTHLOWENERGY_GETCHARACTERISTIC); |
| @@ -150,12 +227,12 @@ class BluetoothLowEnergyGetCharacteristicFunction |
| protected: |
| ~BluetoothLowEnergyGetCharacteristicFunction() override {} |
| - // BluetoothLowEnergyExtensionFunction override. |
| + // BluetoothLowEnergyExtensionFunctionDeprecated override. |
| bool DoWork() override; |
| }; |
| class BluetoothLowEnergyGetCharacteristicsFunction |
| - : public BluetoothLowEnergyExtensionFunction { |
| + : public BluetoothLowEnergyExtensionFunctionDeprecated { |
| public: |
| DECLARE_EXTENSION_FUNCTION("bluetoothLowEnergy.getCharacteristics", |
| BLUETOOTHLOWENERGY_GETCHARACTERISTICS); |
| @@ -163,12 +240,12 @@ class BluetoothLowEnergyGetCharacteristicsFunction |
| protected: |
| ~BluetoothLowEnergyGetCharacteristicsFunction() override {} |
| - // BluetoothLowEnergyExtensionFunction override. |
| + // BluetoothLowEnergyExtensionFunctionDeprecated override. |
| bool DoWork() override; |
| }; |
| class BluetoothLowEnergyGetIncludedServicesFunction |
| - : public BluetoothLowEnergyExtensionFunction { |
| + : public BluetoothLowEnergyExtensionFunctionDeprecated { |
| public: |
| DECLARE_EXTENSION_FUNCTION("bluetoothLowEnergy.getIncludedServices", |
| BLUETOOTHLOWENERGY_GETINCLUDEDSERVICES); |
| @@ -176,12 +253,12 @@ class BluetoothLowEnergyGetIncludedServicesFunction |
| protected: |
| ~BluetoothLowEnergyGetIncludedServicesFunction() override {} |
| - // BluetoothLowEnergyExtensionFunction override. |
| + // BluetoothLowEnergyExtensionFunctionDeprecated override. |
| bool DoWork() override; |
| }; |
| class BluetoothLowEnergyGetDescriptorFunction |
| - : public BluetoothLowEnergyExtensionFunction { |
| + : public BluetoothLowEnergyExtensionFunctionDeprecated { |
| public: |
| DECLARE_EXTENSION_FUNCTION("bluetoothLowEnergy.getDescriptor", |
| BLUETOOTHLOWENERGY_GETDESCRIPTOR); |
| @@ -189,12 +266,12 @@ class BluetoothLowEnergyGetDescriptorFunction |
| protected: |
| ~BluetoothLowEnergyGetDescriptorFunction() override {} |
| - // BluetoothLowEnergyExtensionFunction override. |
| + // BluetoothLowEnergyExtensionFunctionDeprecated override. |
| bool DoWork() override; |
| }; |
| class BluetoothLowEnergyGetDescriptorsFunction |
| - : public BluetoothLowEnergyExtensionFunction { |
| + : public BluetoothLowEnergyExtensionFunctionDeprecated { |
| public: |
| DECLARE_EXTENSION_FUNCTION("bluetoothLowEnergy.getDescriptors", |
| BLUETOOTHLOWENERGY_GETDESCRIPTORS); |
| @@ -202,12 +279,12 @@ class BluetoothLowEnergyGetDescriptorsFunction |
| protected: |
| ~BluetoothLowEnergyGetDescriptorsFunction() override {} |
| - // BluetoothLowEnergyExtensionFunction override. |
| + // BluetoothLowEnergyExtensionFunctionDeprecated override. |
| bool DoWork() override; |
| }; |
| class BluetoothLowEnergyReadCharacteristicValueFunction |
| - : public BluetoothLowEnergyExtensionFunction { |
| + : public BluetoothLowEnergyExtensionFunctionDeprecated { |
| public: |
| DECLARE_EXTENSION_FUNCTION("bluetoothLowEnergy.readCharacteristicValue", |
| BLUETOOTHLOWENERGY_READCHARACTERISTICVALUE); |
| @@ -215,7 +292,7 @@ class BluetoothLowEnergyReadCharacteristicValueFunction |
| protected: |
| ~BluetoothLowEnergyReadCharacteristicValueFunction() override {} |
| - // BluetoothLowEnergyExtensionFunction override. |
| + // BluetoothLowEnergyExtensionFunctionDeprecated override. |
| bool DoWork() override; |
| private: |
| @@ -229,7 +306,7 @@ class BluetoothLowEnergyReadCharacteristicValueFunction |
| }; |
| class BluetoothLowEnergyWriteCharacteristicValueFunction |
| - : public BluetoothLowEnergyExtensionFunction { |
| + : public BluetoothLowEnergyExtensionFunctionDeprecated { |
| public: |
| DECLARE_EXTENSION_FUNCTION("bluetoothLowEnergy.writeCharacteristicValue", |
| BLUETOOTHLOWENERGY_WRITECHARACTERISTICVALUE); |
| @@ -237,7 +314,7 @@ class BluetoothLowEnergyWriteCharacteristicValueFunction |
| protected: |
| ~BluetoothLowEnergyWriteCharacteristicValueFunction() override {} |
| - // BluetoothLowEnergyExtensionFunction override. |
| + // BluetoothLowEnergyExtensionFunctionDeprecated override. |
| bool DoWork() override; |
| private: |
| @@ -251,7 +328,7 @@ class BluetoothLowEnergyWriteCharacteristicValueFunction |
| }; |
| class BluetoothLowEnergyStartCharacteristicNotificationsFunction |
| - : public BluetoothLowEnergyExtensionFunction { |
| + : public BluetoothLowEnergyExtensionFunctionDeprecated { |
| public: |
| DECLARE_EXTENSION_FUNCTION( |
| "bluetoothLowEnergy.startCharacteristicNotifications", |
| @@ -260,7 +337,7 @@ class BluetoothLowEnergyStartCharacteristicNotificationsFunction |
| protected: |
| ~BluetoothLowEnergyStartCharacteristicNotificationsFunction() override {} |
| - // BluetoothLowEnergyExtensionFunction override. |
| + // BluetoothLowEnergyExtensionFunctionDeprecated override. |
| bool DoWork() override; |
| private: |
| @@ -271,7 +348,7 @@ class BluetoothLowEnergyStartCharacteristicNotificationsFunction |
| }; |
| class BluetoothLowEnergyStopCharacteristicNotificationsFunction |
| - : public BluetoothLowEnergyExtensionFunction { |
| + : public BluetoothLowEnergyExtensionFunctionDeprecated { |
| public: |
| DECLARE_EXTENSION_FUNCTION( |
| "bluetoothLowEnergy.stopCharacteristicNotifications", |
| @@ -280,7 +357,7 @@ class BluetoothLowEnergyStopCharacteristicNotificationsFunction |
| protected: |
| ~BluetoothLowEnergyStopCharacteristicNotificationsFunction() override {} |
| - // BluetoothLowEnergyExtensionFunction override. |
| + // BluetoothLowEnergyExtensionFunctionDeprecated override. |
| bool DoWork() override; |
| private: |
| @@ -291,7 +368,7 @@ class BluetoothLowEnergyStopCharacteristicNotificationsFunction |
| }; |
| class BluetoothLowEnergyReadDescriptorValueFunction |
| - : public BluetoothLowEnergyExtensionFunction { |
| + : public BluetoothLowEnergyExtensionFunctionDeprecated { |
| public: |
| DECLARE_EXTENSION_FUNCTION("bluetoothLowEnergy.readDescriptorValue", |
| BLUETOOTHLOWENERGY_READDESCRIPTORVALUE); |
| @@ -299,7 +376,7 @@ class BluetoothLowEnergyReadDescriptorValueFunction |
| protected: |
| ~BluetoothLowEnergyReadDescriptorValueFunction() override {} |
| - // BluetoothLowEnergyExtensionFunction override. |
| + // BluetoothLowEnergyExtensionFunctionDeprecated override. |
| bool DoWork() override; |
| private: |
| @@ -313,7 +390,7 @@ class BluetoothLowEnergyReadDescriptorValueFunction |
| }; |
| class BluetoothLowEnergyWriteDescriptorValueFunction |
| - : public BluetoothLowEnergyExtensionFunction { |
| + : public BluetoothLowEnergyExtensionFunctionDeprecated { |
| public: |
| DECLARE_EXTENSION_FUNCTION("bluetoothLowEnergy.writeDescriptorValue", |
| BLUETOOTHLOWENERGY_WRITEDESCRIPTORVALUE); |
| @@ -321,7 +398,7 @@ class BluetoothLowEnergyWriteDescriptorValueFunction |
| protected: |
| ~BluetoothLowEnergyWriteDescriptorValueFunction() override {} |
| - // BluetoothLowEnergyExtensionFunction override. |
| + // BluetoothLowEnergyExtensionFunctionDeprecated override. |
| bool DoWork() override; |
| private: |
| @@ -335,7 +412,7 @@ class BluetoothLowEnergyWriteDescriptorValueFunction |
| }; |
| class BluetoothLowEnergyAdvertisementFunction |
| - : public BluetoothLowEnergyExtensionFunction { |
| + : public BluetoothLowEnergyExtensionFunctionDeprecated { |
| public: |
| BluetoothLowEnergyAdvertisementFunction(); |
| @@ -367,7 +444,7 @@ class BluetoothLowEnergyRegisterAdvertisementFunction |
| protected: |
| ~BluetoothLowEnergyRegisterAdvertisementFunction() override {} |
| - // BluetoothLowEnergyExtensionFunction override. |
| + // BluetoothLowEnergyExtensionFunctionDeprecated override. |
| bool DoWork() override; |
| private: |
| @@ -387,7 +464,7 @@ class BluetoothLowEnergyUnregisterAdvertisementFunction |
| protected: |
| ~BluetoothLowEnergyUnregisterAdvertisementFunction() override {} |
| - // BluetoothLowEnergyExtensionFunction override. |
| + // BluetoothLowEnergyExtensionFunctionDeprecated override. |
| bool DoWork() override; |
| private: |
| @@ -399,6 +476,87 @@ class BluetoothLowEnergyUnregisterAdvertisementFunction |
| std::string instance_id_; |
| }; |
| +class BluetoothLowEnergyCreateServiceFunction |
| + : public BLEPeripheralExtensionFunction<apibtle::CreateService::Params> { |
| + public: |
| + DECLARE_EXTENSION_FUNCTION("bluetoothLowEnergy.createService", |
| + BLUETOOTHLOWENERGY_CREATESERVICE); |
| + |
| + protected: |
| + ~BluetoothLowEnergyCreateServiceFunction() override {} |
| + |
| + // BluetoothLowEnergyPeripheralExtensionFunction override. |
| + void DoWork() override; |
| +}; |
| + |
| +class BluetoothLowEnergyCreateCharacteristicFunction |
| + : public BLEPeripheralExtensionFunction< |
| + apibtle::CreateCharacteristic::Params> { |
| + public: |
| + DECLARE_EXTENSION_FUNCTION("bluetoothLowEnergy.createCharacteristic", |
| + BLUETOOTHLOWENERGY_CREATECHARACTERISTIC); |
| + |
| + protected: |
| + ~BluetoothLowEnergyCreateCharacteristicFunction() override {} |
| + |
| + // BluetoothLowEnergyPeripheralExtensionFunction override. |
| + void DoWork() override; |
| +}; |
| + |
| +class BluetoothLowEnergyCreateDescriptorFunction |
| + : public BLEPeripheralExtensionFunction<apibtle::CreateDescriptor::Params> { |
| + public: |
| + DECLARE_EXTENSION_FUNCTION("bluetoothLowEnergy.createDescriptor", |
| + BLUETOOTHLOWENERGY_CREATEDESCRIPTOR); |
| + |
| + protected: |
| + ~BluetoothLowEnergyCreateDescriptorFunction() override {} |
| + |
| + // BluetoothLowEnergyPeripheralExtensionFunction override. |
| + void DoWork() override; |
| +}; |
| + |
| +class BluetoothLowEnergyRegisterServiceFunction |
| + : public BLEPeripheralExtensionFunction<apibtle::RegisterService::Params> { |
| + public: |
| + DECLARE_EXTENSION_FUNCTION("bluetoothLowEnergy.registerService", |
| + BLUETOOTHLOWENERGY_REGISTERSERVICE); |
| + |
| + protected: |
| + ~BluetoothLowEnergyRegisterServiceFunction() override {} |
| + |
| + // BluetoothLowEnergyPeripheralExtensionFunction override. |
| + void DoWork() override; |
| +}; |
| + |
| +class BluetoothLowEnergyUnregisterServiceFunction |
| + : public BLEPeripheralExtensionFunction< |
| + apibtle::UnregisterService::Params> { |
| + public: |
| + DECLARE_EXTENSION_FUNCTION("bluetoothLowEnergy.unregisterService", |
| + BLUETOOTHLOWENERGY_UNREGISTERSERVICE); |
| + |
| + protected: |
| + ~BluetoothLowEnergyUnregisterServiceFunction() override {} |
| + |
| + // BluetoothLowEnergyPeripheralExtensionFunction override. |
| + void DoWork() override; |
| +}; |
| + |
| +class BluetoothLowEnergySendRequestResponseFunction |
| + : public BLEPeripheralExtensionFunction< |
| + apibtle::SendRequestResponse::Params> { |
| + public: |
| + DECLARE_EXTENSION_FUNCTION("bluetoothLowEnergy.sendRequestResponse", |
| + BLUETOOTHLOWENERGY_SENDREQUESTRESPONSE); |
| + |
| + protected: |
| + ~BluetoothLowEnergySendRequestResponseFunction() override {} |
| + |
| + // BluetoothLowEnergyPeripheralExtensionFunction override. |
| + void DoWork() override; |
| +}; |
| + |
| } // namespace api |
| } // namespace extensions |