1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_EXTENSIONS_API_BLUETOOTH_LOW_ENERGY_BLUETOOTH_LOW_ENERGY_API_H_
6 #define CHROME_BROWSER_EXTENSIONS_API_BLUETOOTH_LOW_ENERGY_BLUETOOTH_LOW_ENERGY_API_H_
8 #include "base/memory/scoped_ptr.h"
9 #include "extensions/browser/browser_context_keyed_api_factory.h"
10 #include "extensions/browser/extension_function.h"
11 #include "extensions/browser/extension_function_histogram_value.h"
13 namespace extensions {
15 class BluetoothLowEnergyEventRouter;
17 // The profile-keyed service that manages the bluetoothLowEnergy extension API.
18 class BluetoothLowEnergyAPI : public BrowserContextKeyedAPI {
20 static BrowserContextKeyedAPIFactory<BluetoothLowEnergyAPI>*
23 // Convenience method to get the BluetoothLowEnergy API for a browser context.
24 static BluetoothLowEnergyAPI* Get(content::BrowserContext* context);
26 explicit BluetoothLowEnergyAPI(content::BrowserContext* context);
27 virtual ~BluetoothLowEnergyAPI();
29 // KeyedService implementation..
30 virtual void Shutdown() OVERRIDE;
32 BluetoothLowEnergyEventRouter* event_router() const {
33 return event_router_.get();
36 // BrowserContextKeyedAPI implementation.
37 static const char* service_name() { return "BluetoothLowEnergyAPI"; }
38 static const bool kServiceRedirectedInIncognito = true;
39 static const bool kServiceIsNULLWhileTesting = true;
42 friend class BrowserContextKeyedAPIFactory<BluetoothLowEnergyAPI>;
44 scoped_ptr<BluetoothLowEnergyEventRouter> event_router_;
46 content::BrowserContext* browser_context_;
48 DISALLOW_COPY_AND_ASSIGN(BluetoothLowEnergyAPI);
53 // Base class for bluetoothLowEnergy API functions. This class handles some of
54 // the common logic involved in all API functions, such as checking for
55 // platform support and returning the correct error.
56 class BluetoothLowEnergyExtensionFunction : public AsyncExtensionFunction {
58 BluetoothLowEnergyExtensionFunction();
61 virtual ~BluetoothLowEnergyExtensionFunction();
63 // ExtensionFunction override.
64 virtual bool RunAsync() OVERRIDE;
66 // Implemented by individual bluetoothLowEnergy extension functions to perform
67 // the body of the function. This invoked asynchonously after RunAsync after
68 // the BluetoothLowEnergyEventRouter has obtained a handle on the
70 virtual bool DoWork() = 0;
73 DISALLOW_COPY_AND_ASSIGN(BluetoothLowEnergyExtensionFunction);
76 class BluetoothLowEnergyGetServiceFunction
77 : public BluetoothLowEnergyExtensionFunction {
79 DECLARE_EXTENSION_FUNCTION("bluetoothLowEnergy.getService",
80 BLUETOOTHLOWENERGY_GETSERVICE);
83 virtual ~BluetoothLowEnergyGetServiceFunction() {}
85 // BluetoothLowEnergyExtensionFunction override.
86 virtual bool DoWork() OVERRIDE;
89 class BluetoothLowEnergyGetServicesFunction
90 : public BluetoothLowEnergyExtensionFunction {
92 DECLARE_EXTENSION_FUNCTION("bluetoothLowEnergy.getServices",
93 BLUETOOTHLOWENERGY_GETSERVICES);
96 virtual ~BluetoothLowEnergyGetServicesFunction() {}
98 // BluetoothLowEnergyExtensionFunction override.
99 virtual bool DoWork() OVERRIDE;
102 class BluetoothLowEnergyGetCharacteristicFunction
103 : public BluetoothLowEnergyExtensionFunction {
105 DECLARE_EXTENSION_FUNCTION("bluetoothLowEnergy.getCharacteristic",
106 BLUETOOTHLOWENERGY_GETCHARACTERISTIC);
109 virtual ~BluetoothLowEnergyGetCharacteristicFunction() {}
111 // BluetoothLowEnergyExtensionFunction override.
112 virtual bool DoWork() OVERRIDE;
115 class BluetoothLowEnergyGetCharacteristicsFunction
116 : public BluetoothLowEnergyExtensionFunction {
118 DECLARE_EXTENSION_FUNCTION("bluetoothLowEnergy.getCharacteristics",
119 BLUETOOTHLOWENERGY_GETCHARACTERISTICS);
122 virtual ~BluetoothLowEnergyGetCharacteristicsFunction() {}
124 // BluetoothLowEnergyExtensionFunction override.
125 virtual bool DoWork() OVERRIDE;
128 class BluetoothLowEnergyGetIncludedServicesFunction
129 : public BluetoothLowEnergyExtensionFunction {
131 DECLARE_EXTENSION_FUNCTION("bluetoothLowEnergy.getIncludedServices",
132 BLUETOOTHLOWENERGY_GETINCLUDEDSERVICES);
135 virtual ~BluetoothLowEnergyGetIncludedServicesFunction() {}
137 // BluetoothLowEnergyExtensionFunction override.
138 virtual bool DoWork() OVERRIDE;
141 class BluetoothLowEnergyGetDescriptorFunction
142 : public BluetoothLowEnergyExtensionFunction {
144 DECLARE_EXTENSION_FUNCTION("bluetoothLowEnergy.getDescriptor",
145 BLUETOOTHLOWENERGY_GETDESCRIPTOR);
148 virtual ~BluetoothLowEnergyGetDescriptorFunction() {}
150 // BluetoothLowEnergyExtensionFunction override.
151 virtual bool DoWork() OVERRIDE;
154 class BluetoothLowEnergyGetDescriptorsFunction
155 : public BluetoothLowEnergyExtensionFunction {
157 DECLARE_EXTENSION_FUNCTION("bluetoothLowEnergy.getDescriptors",
158 BLUETOOTHLOWENERGY_GETDESCRIPTORS);
161 virtual ~BluetoothLowEnergyGetDescriptorsFunction() {}
163 // BluetoothLowEnergyExtensionFunction override.
164 virtual bool DoWork() OVERRIDE;
167 class BluetoothLowEnergyReadCharacteristicValueFunction
168 : public BluetoothLowEnergyExtensionFunction {
170 DECLARE_EXTENSION_FUNCTION("bluetoothLowEnergy.readCharacteristicValue",
171 BLUETOOTHLOWENERGY_READCHARACTERISTICVALUE);
174 virtual ~BluetoothLowEnergyReadCharacteristicValueFunction() {}
176 // BluetoothLowEnergyExtensionFunction override.
177 virtual bool DoWork() OVERRIDE;
180 // Success and error callbacks, called by
181 // BluetoothLowEnergyEventRouter::ReadCharacteristicValue.
182 void SuccessCallback();
183 void ErrorCallback();
185 // The instance ID of the requested characteristic.
186 std::string instance_id_;
189 class BluetoothLowEnergyWriteCharacteristicValueFunction
190 : public BluetoothLowEnergyExtensionFunction {
192 DECLARE_EXTENSION_FUNCTION("bluetoothLowEnergy.writeCharacteristicValue",
193 BLUETOOTHLOWENERGY_WRITECHARACTERISTICVALUE);
196 virtual ~BluetoothLowEnergyWriteCharacteristicValueFunction() {}
198 // BluetoothLowEnergyExtensionFunction override.
199 virtual bool DoWork() OVERRIDE;
202 class BluetoothLowEnergyReadDescriptorValueFunction
203 : public BluetoothLowEnergyExtensionFunction {
205 DECLARE_EXTENSION_FUNCTION("bluetoothLowEnergy.readDescriptorValue",
206 BLUETOOTHLOWENERGY_READDESCRIPTORVALUE);
209 virtual ~BluetoothLowEnergyReadDescriptorValueFunction() {}
211 // BluetoothLowEnergyExtensionFunction override.
212 virtual bool DoWork() OVERRIDE;
215 class BluetoothLowEnergyWriteDescriptorValueFunction
216 : public BluetoothLowEnergyExtensionFunction {
218 DECLARE_EXTENSION_FUNCTION("bluetoothLowEnergy.writeDescriptorValue",
219 BLUETOOTHLOWENERGY_WRITEDESCRIPTORVALUE);
222 virtual ~BluetoothLowEnergyWriteDescriptorValueFunction() {}
224 // BluetoothLowEnergyExtensionFunction override.
225 virtual bool DoWork() OVERRIDE;
229 } // namespace extensions
231 #endif // CHROME_BROWSER_EXTENSIONS_API_BLUETOOTH_LOW_ENERGY_BLUETOOTH_LOW_ENERGY_API_H_