Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1752)

Unified Diff: chrome/browser/extensions/api/bluetooth_low_energy/bluetooth_low_energy_api.h

Issue 1915243003: API Bindings for GATT server functionality. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@adapter_and_tests
Patch Set: Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..e1028cb53c541ba06f948338392da61d3f1cf2ad 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,46 @@
#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 {
-
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 +82,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 +104,69 @@ 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;
+
+// Causes link error on Windows. API will never be on Windows, so #ifdefing.
+#if !defined(OS_WIN)
+ std::unique_ptr<Params> params_;
+#else
+ Params* params_;
+#endif
+
+ 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 +177,7 @@ class BluetoothLowEnergyConnectFunction
};
class BluetoothLowEnergyDisconnectFunction
- : public BluetoothLowEnergyExtensionFunction {
+ : public BluetoothLowEnergyExtensionFunctionDeprecated {
public:
DECLARE_EXTENSION_FUNCTION("bluetoothLowEnergy.disconnect",
BLUETOOTHLOWENERGY_DISCONNECT);
@@ -105,7 +185,7 @@ class BluetoothLowEnergyDisconnectFunction
protected:
~BluetoothLowEnergyDisconnectFunction() override {}
- // BluetoothLowEnergyExtensionFunction override.
+ // BluetoothLowEnergyExtensionFunctionDeprecated override.
bool DoWork() override;
private:
@@ -116,7 +196,7 @@ class BluetoothLowEnergyDisconnectFunction
};
class BluetoothLowEnergyGetServiceFunction
- : public BluetoothLowEnergyExtensionFunction {
+ : public BluetoothLowEnergyExtensionFunctionDeprecated {
public:
DECLARE_EXTENSION_FUNCTION("bluetoothLowEnergy.getService",
BLUETOOTHLOWENERGY_GETSERVICE);
@@ -124,12 +204,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 +217,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 +230,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 +243,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 +256,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 +269,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 +282,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 +295,7 @@ class BluetoothLowEnergyReadCharacteristicValueFunction
protected:
~BluetoothLowEnergyReadCharacteristicValueFunction() override {}
- // BluetoothLowEnergyExtensionFunction override.
+ // BluetoothLowEnergyExtensionFunctionDeprecated override.
bool DoWork() override;
private:
@@ -229,7 +309,7 @@ class BluetoothLowEnergyReadCharacteristicValueFunction
};
class BluetoothLowEnergyWriteCharacteristicValueFunction
- : public BluetoothLowEnergyExtensionFunction {
+ : public BluetoothLowEnergyExtensionFunctionDeprecated {
public:
DECLARE_EXTENSION_FUNCTION("bluetoothLowEnergy.writeCharacteristicValue",
BLUETOOTHLOWENERGY_WRITECHARACTERISTICVALUE);
@@ -237,7 +317,7 @@ class BluetoothLowEnergyWriteCharacteristicValueFunction
protected:
~BluetoothLowEnergyWriteCharacteristicValueFunction() override {}
- // BluetoothLowEnergyExtensionFunction override.
+ // BluetoothLowEnergyExtensionFunctionDeprecated override.
bool DoWork() override;
private:
@@ -251,7 +331,7 @@ class BluetoothLowEnergyWriteCharacteristicValueFunction
};
class BluetoothLowEnergyStartCharacteristicNotificationsFunction
- : public BluetoothLowEnergyExtensionFunction {
+ : public BluetoothLowEnergyExtensionFunctionDeprecated {
public:
DECLARE_EXTENSION_FUNCTION(
"bluetoothLowEnergy.startCharacteristicNotifications",
@@ -260,7 +340,7 @@ class BluetoothLowEnergyStartCharacteristicNotificationsFunction
protected:
~BluetoothLowEnergyStartCharacteristicNotificationsFunction() override {}
- // BluetoothLowEnergyExtensionFunction override.
+ // BluetoothLowEnergyExtensionFunctionDeprecated override.
bool DoWork() override;
private:
@@ -271,7 +351,7 @@ class BluetoothLowEnergyStartCharacteristicNotificationsFunction
};
class BluetoothLowEnergyStopCharacteristicNotificationsFunction
- : public BluetoothLowEnergyExtensionFunction {
+ : public BluetoothLowEnergyExtensionFunctionDeprecated {
public:
DECLARE_EXTENSION_FUNCTION(
"bluetoothLowEnergy.stopCharacteristicNotifications",
@@ -280,7 +360,7 @@ class BluetoothLowEnergyStopCharacteristicNotificationsFunction
protected:
~BluetoothLowEnergyStopCharacteristicNotificationsFunction() override {}
- // BluetoothLowEnergyExtensionFunction override.
+ // BluetoothLowEnergyExtensionFunctionDeprecated override.
bool DoWork() override;
private:
@@ -291,7 +371,7 @@ class BluetoothLowEnergyStopCharacteristicNotificationsFunction
};
class BluetoothLowEnergyReadDescriptorValueFunction
- : public BluetoothLowEnergyExtensionFunction {
+ : public BluetoothLowEnergyExtensionFunctionDeprecated {
public:
DECLARE_EXTENSION_FUNCTION("bluetoothLowEnergy.readDescriptorValue",
BLUETOOTHLOWENERGY_READDESCRIPTORVALUE);
@@ -299,7 +379,7 @@ class BluetoothLowEnergyReadDescriptorValueFunction
protected:
~BluetoothLowEnergyReadDescriptorValueFunction() override {}
- // BluetoothLowEnergyExtensionFunction override.
+ // BluetoothLowEnergyExtensionFunctionDeprecated override.
bool DoWork() override;
private:
@@ -313,7 +393,7 @@ class BluetoothLowEnergyReadDescriptorValueFunction
};
class BluetoothLowEnergyWriteDescriptorValueFunction
- : public BluetoothLowEnergyExtensionFunction {
+ : public BluetoothLowEnergyExtensionFunctionDeprecated {
public:
DECLARE_EXTENSION_FUNCTION("bluetoothLowEnergy.writeDescriptorValue",
BLUETOOTHLOWENERGY_WRITEDESCRIPTORVALUE);
@@ -321,7 +401,7 @@ class BluetoothLowEnergyWriteDescriptorValueFunction
protected:
~BluetoothLowEnergyWriteDescriptorValueFunction() override {}
- // BluetoothLowEnergyExtensionFunction override.
+ // BluetoothLowEnergyExtensionFunctionDeprecated override.
bool DoWork() override;
private:
@@ -335,7 +415,7 @@ class BluetoothLowEnergyWriteDescriptorValueFunction
};
class BluetoothLowEnergyAdvertisementFunction
- : public BluetoothLowEnergyExtensionFunction {
+ : public BluetoothLowEnergyExtensionFunctionDeprecated {
public:
BluetoothLowEnergyAdvertisementFunction();
@@ -367,7 +447,7 @@ class BluetoothLowEnergyRegisterAdvertisementFunction
protected:
~BluetoothLowEnergyRegisterAdvertisementFunction() override {}
- // BluetoothLowEnergyExtensionFunction override.
+ // BluetoothLowEnergyExtensionFunctionDeprecated override.
bool DoWork() override;
private:
@@ -387,7 +467,7 @@ class BluetoothLowEnergyUnregisterAdvertisementFunction
protected:
~BluetoothLowEnergyUnregisterAdvertisementFunction() override {}
- // BluetoothLowEnergyExtensionFunction override.
+ // BluetoothLowEnergyExtensionFunctionDeprecated override.
bool DoWork() override;
private:
@@ -399,6 +479,90 @@ class BluetoothLowEnergyUnregisterAdvertisementFunction
std::string instance_id_;
};
+class BluetoothLowEnergyCreateServiceFunction
+ : public BLEPeripheralExtensionFunction<
+ extensions::api::bluetooth_low_energy::CreateService::Params> {
+ public:
+ DECLARE_EXTENSION_FUNCTION("bluetoothLowEnergy.createService",
+ BLUETOOTHLOWENERGY_CREATESERVICE);
+
+ protected:
+ ~BluetoothLowEnergyCreateServiceFunction() override {}
+
+ // BluetoothLowEnergyPeripheralExtensionFunction override.
+ void DoWork() override;
+};
+
+class BluetoothLowEnergyCreateCharacteristicFunction
+ : public BLEPeripheralExtensionFunction<
+ extensions::api::bluetooth_low_energy::CreateCharacteristic::Params> {
+ public:
+ DECLARE_EXTENSION_FUNCTION("bluetoothLowEnergy.createCharacteristic",
+ BLUETOOTHLOWENERGY_CREATECHARACTERISTIC);
+
+ protected:
+ ~BluetoothLowEnergyCreateCharacteristicFunction() override {}
+
+ // BluetoothLowEnergyPeripheralExtensionFunction override.
+ void DoWork() override;
+};
+
+class BluetoothLowEnergyCreateDescriptorFunction
+ : public BLEPeripheralExtensionFunction<
+ extensions::api::bluetooth_low_energy::CreateDescriptor::Params> {
+ public:
+ DECLARE_EXTENSION_FUNCTION("bluetoothLowEnergy.createDescriptor",
+ BLUETOOTHLOWENERGY_CREATEDESCRIPTOR);
+
+ protected:
+ ~BluetoothLowEnergyCreateDescriptorFunction() override {}
+
+ // BluetoothLowEnergyPeripheralExtensionFunction override.
+ void DoWork() override;
+};
+
+class BluetoothLowEnergyRegisterServiceFunction
+ : public BLEPeripheralExtensionFunction<
+ extensions::api::bluetooth_low_energy::RegisterService::Params> {
+ public:
+ DECLARE_EXTENSION_FUNCTION("bluetoothLowEnergy.registerService",
+ BLUETOOTHLOWENERGY_REGISTERSERVICE);
+
+ protected:
+ ~BluetoothLowEnergyRegisterServiceFunction() override {}
+
+ // BluetoothLowEnergyPeripheralExtensionFunction override.
+ void DoWork() override;
+};
+
+class BluetoothLowEnergyUnregisterServiceFunction
+ : public BLEPeripheralExtensionFunction<
+ extensions::api::bluetooth_low_energy::UnregisterService::Params> {
+ public:
+ DECLARE_EXTENSION_FUNCTION("bluetoothLowEnergy.unregisterService",
+ BLUETOOTHLOWENERGY_UNREGISTERSERVICE);
+
+ protected:
+ ~BluetoothLowEnergyUnregisterServiceFunction() override {}
+
+ // BluetoothLowEnergyPeripheralExtensionFunction override.
+ void DoWork() override;
+};
+
+class BluetoothLowEnergySendRequestResponseFunction
+ : public BLEPeripheralExtensionFunction<
+ extensions::api::bluetooth_low_energy::SendRequestResponse::Params> {
+ public:
+ DECLARE_EXTENSION_FUNCTION("bluetoothLowEnergy.sendRequestResponse",
+ BLUETOOTHLOWENERGY_SENDREQUESTRESPONSE);
+
+ protected:
+ ~BluetoothLowEnergySendRequestResponseFunction() override {}
+
+ // BluetoothLowEnergyPeripheralExtensionFunction override.
+ void DoWork() override;
+};
+
} // namespace api
} // namespace extensions

Powered by Google App Engine
This is Rietveld 408576698