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 EXTENSIONS_BROWSER_API_BLUETOOTH_LOW_ENERGY_BLUETOOTH_LOW_ENERGY_API_H_
6 #define EXTENSIONS_BROWSER_API_BLUETOOTH_LOW_ENERGY_BLUETOOTH_LOW_ENERGY_API_H_
8 #include "base/memory/scoped_ptr.h"
9 #include "extensions/browser/api/bluetooth_low_energy/bluetooth_low_energy_event_router.h"
10 #include "extensions/browser/browser_context_keyed_api_factory.h"
11 #include "extensions/browser/extension_function.h"
12 #include "extensions/browser/extension_function_histogram_value.h"
14 namespace extensions {
16 class BluetoothLowEnergyEventRouter;
18 // The profile-keyed service that manages the bluetoothLowEnergy extension API.
19 class BluetoothLowEnergyAPI : public BrowserContextKeyedAPI {
21 static BrowserContextKeyedAPIFactory<BluetoothLowEnergyAPI>*
24 // Convenience method to get the BluetoothLowEnergy API for a browser context.
25 static BluetoothLowEnergyAPI* Get(content::BrowserContext* context);
27 explicit BluetoothLowEnergyAPI(content::BrowserContext* context);
28 virtual ~BluetoothLowEnergyAPI();
30 // KeyedService implementation..
31 virtual void Shutdown() OVERRIDE;
33 BluetoothLowEnergyEventRouter* event_router() const {
34 return event_router_.get();
37 // BrowserContextKeyedAPI implementation.
38 static const char* service_name() { return "BluetoothLowEnergyAPI"; }
39 static const bool kServiceRedirectedInIncognito = true;
40 static const bool kServiceIsNULLWhileTesting = true;
43 friend class BrowserContextKeyedAPIFactory<BluetoothLowEnergyAPI>;
45 scoped_ptr<BluetoothLowEnergyEventRouter> event_router_;
47 content::BrowserContext* browser_context_;
49 DISALLOW_COPY_AND_ASSIGN(BluetoothLowEnergyAPI);
54 // Base class for bluetoothLowEnergy API functions. This class handles some of
55 // the common logic involved in all API functions, such as checking for
56 // platform support and returning the correct error.
57 class BluetoothLowEnergyExtensionFunction : public AsyncExtensionFunction {
59 BluetoothLowEnergyExtensionFunction();
62 virtual ~BluetoothLowEnergyExtensionFunction();
64 // ExtensionFunction override.
65 virtual bool RunAsync() OVERRIDE;
67 // Implemented by individual bluetoothLowEnergy extension functions to perform
68 // the body of the function. This invoked asynchonously after RunAsync after
69 // the BluetoothLowEnergyEventRouter has obtained a handle on the
71 virtual bool DoWork() = 0;
74 DISALLOW_COPY_AND_ASSIGN(BluetoothLowEnergyExtensionFunction);
77 class BluetoothLowEnergyConnectFunction
78 : public BluetoothLowEnergyExtensionFunction {
80 DECLARE_EXTENSION_FUNCTION("bluetoothLowEnergy.connect",
81 BLUETOOTHLOWENERGY_CONNECT);
84 virtual ~BluetoothLowEnergyConnectFunction() {}
86 // BluetoothLowEnergyExtensionFunction override.
87 virtual bool DoWork() OVERRIDE;
90 // Success and error callbacks, called by
91 // BluetoothLowEnergyEventRouter::Connect.
92 void SuccessCallback();
93 void ErrorCallback(BluetoothLowEnergyEventRouter::Status status);
96 class BluetoothLowEnergyDisconnectFunction
97 : public BluetoothLowEnergyExtensionFunction {
99 DECLARE_EXTENSION_FUNCTION("bluetoothLowEnergy.disconnect",
100 BLUETOOTHLOWENERGY_DISCONNECT);
103 virtual ~BluetoothLowEnergyDisconnectFunction() {}
105 // BluetoothLowEnergyExtensionFunction override.
106 virtual bool DoWork() OVERRIDE;
109 // Success and error callbacks, called by
110 // BluetoothLowEnergyEventRouter::Disconnect.
111 void SuccessCallback();
112 void ErrorCallback(BluetoothLowEnergyEventRouter::Status status);
115 class BluetoothLowEnergyGetServiceFunction
116 : public BluetoothLowEnergyExtensionFunction {
118 DECLARE_EXTENSION_FUNCTION("bluetoothLowEnergy.getService",
119 BLUETOOTHLOWENERGY_GETSERVICE);
122 virtual ~BluetoothLowEnergyGetServiceFunction() {}
124 // BluetoothLowEnergyExtensionFunction override.
125 virtual bool DoWork() OVERRIDE;
128 class BluetoothLowEnergyGetServicesFunction
129 : public BluetoothLowEnergyExtensionFunction {
131 DECLARE_EXTENSION_FUNCTION("bluetoothLowEnergy.getServices",
132 BLUETOOTHLOWENERGY_GETSERVICES);
135 virtual ~BluetoothLowEnergyGetServicesFunction() {}
137 // BluetoothLowEnergyExtensionFunction override.
138 virtual bool DoWork() OVERRIDE;
141 class BluetoothLowEnergyGetCharacteristicFunction
142 : public BluetoothLowEnergyExtensionFunction {
144 DECLARE_EXTENSION_FUNCTION("bluetoothLowEnergy.getCharacteristic",
145 BLUETOOTHLOWENERGY_GETCHARACTERISTIC);
148 virtual ~BluetoothLowEnergyGetCharacteristicFunction() {}
150 // BluetoothLowEnergyExtensionFunction override.
151 virtual bool DoWork() OVERRIDE;
154 class BluetoothLowEnergyGetCharacteristicsFunction
155 : public BluetoothLowEnergyExtensionFunction {
157 DECLARE_EXTENSION_FUNCTION("bluetoothLowEnergy.getCharacteristics",
158 BLUETOOTHLOWENERGY_GETCHARACTERISTICS);
161 virtual ~BluetoothLowEnergyGetCharacteristicsFunction() {}
163 // BluetoothLowEnergyExtensionFunction override.
164 virtual bool DoWork() OVERRIDE;
167 class BluetoothLowEnergyGetIncludedServicesFunction
168 : public BluetoothLowEnergyExtensionFunction {
170 DECLARE_EXTENSION_FUNCTION("bluetoothLowEnergy.getIncludedServices",
171 BLUETOOTHLOWENERGY_GETINCLUDEDSERVICES);
174 virtual ~BluetoothLowEnergyGetIncludedServicesFunction() {}
176 // BluetoothLowEnergyExtensionFunction override.
177 virtual bool DoWork() OVERRIDE;
180 class BluetoothLowEnergyGetDescriptorFunction
181 : public BluetoothLowEnergyExtensionFunction {
183 DECLARE_EXTENSION_FUNCTION("bluetoothLowEnergy.getDescriptor",
184 BLUETOOTHLOWENERGY_GETDESCRIPTOR);
187 virtual ~BluetoothLowEnergyGetDescriptorFunction() {}
189 // BluetoothLowEnergyExtensionFunction override.
190 virtual bool DoWork() OVERRIDE;
193 class BluetoothLowEnergyGetDescriptorsFunction
194 : public BluetoothLowEnergyExtensionFunction {
196 DECLARE_EXTENSION_FUNCTION("bluetoothLowEnergy.getDescriptors",
197 BLUETOOTHLOWENERGY_GETDESCRIPTORS);
200 virtual ~BluetoothLowEnergyGetDescriptorsFunction() {}
202 // BluetoothLowEnergyExtensionFunction override.
203 virtual bool DoWork() OVERRIDE;
206 class BluetoothLowEnergyReadCharacteristicValueFunction
207 : public BluetoothLowEnergyExtensionFunction {
209 DECLARE_EXTENSION_FUNCTION("bluetoothLowEnergy.readCharacteristicValue",
210 BLUETOOTHLOWENERGY_READCHARACTERISTICVALUE);
213 virtual ~BluetoothLowEnergyReadCharacteristicValueFunction() {}
215 // BluetoothLowEnergyExtensionFunction override.
216 virtual bool DoWork() OVERRIDE;
219 // Success and error callbacks, called by
220 // BluetoothLowEnergyEventRouter::ReadCharacteristicValue.
221 void SuccessCallback();
222 void ErrorCallback(BluetoothLowEnergyEventRouter::Status status);
224 // The instance ID of the requested characteristic.
225 std::string instance_id_;
228 class BluetoothLowEnergyWriteCharacteristicValueFunction
229 : public BluetoothLowEnergyExtensionFunction {
231 DECLARE_EXTENSION_FUNCTION("bluetoothLowEnergy.writeCharacteristicValue",
232 BLUETOOTHLOWENERGY_WRITECHARACTERISTICVALUE);
235 virtual ~BluetoothLowEnergyWriteCharacteristicValueFunction() {}
237 // BluetoothLowEnergyExtensionFunction override.
238 virtual bool DoWork() OVERRIDE;
241 // Success and error callbacks, called by
242 // BluetoothLowEnergyEventRouter::WriteCharacteristicValue.
243 void SuccessCallback();
244 void ErrorCallback(BluetoothLowEnergyEventRouter::Status status);
246 // The instance ID of the requested characteristic.
247 std::string instance_id_;
250 class BluetoothLowEnergyStartCharacteristicNotificationsFunction
251 : public BluetoothLowEnergyExtensionFunction {
253 DECLARE_EXTENSION_FUNCTION(
254 "bluetoothLowEnergy.startCharacteristicNotifications",
255 BLUETOOTHLOWENERGY_STARTCHARACTERISTICNOTIFICATIONS);
258 virtual ~BluetoothLowEnergyStartCharacteristicNotificationsFunction() {}
260 // BluetoothLowEnergyExtensionFunction override.
261 virtual bool DoWork() OVERRIDE;
264 // Success and error callbacks, called by
265 // BluetoothLowEnergyEventRouter::StartCharacteristicNotifications.
266 void SuccessCallback();
267 void ErrorCallback(BluetoothLowEnergyEventRouter::Status status);
270 class BluetoothLowEnergyStopCharacteristicNotificationsFunction
271 : public BluetoothLowEnergyExtensionFunction {
273 DECLARE_EXTENSION_FUNCTION(
274 "bluetoothLowEnergy.stopCharacteristicNotifications",
275 BLUETOOTHLOWENERGY_STOPCHARACTERISTICNOTIFICATIONS);
278 virtual ~BluetoothLowEnergyStopCharacteristicNotificationsFunction() {}
280 // BluetoothLowEnergyExtensionFunction override.
281 virtual bool DoWork() OVERRIDE;
284 // Success and error callbacks, called by
285 // BluetoothLowEnergyEventRouter::StopCharacteristicNotifications.
286 void SuccessCallback();
287 void ErrorCallback(BluetoothLowEnergyEventRouter::Status status);
290 class BluetoothLowEnergyReadDescriptorValueFunction
291 : public BluetoothLowEnergyExtensionFunction {
293 DECLARE_EXTENSION_FUNCTION("bluetoothLowEnergy.readDescriptorValue",
294 BLUETOOTHLOWENERGY_READDESCRIPTORVALUE);
297 virtual ~BluetoothLowEnergyReadDescriptorValueFunction() {}
299 // BluetoothLowEnergyExtensionFunction override.
300 virtual bool DoWork() OVERRIDE;
303 // Success and error callbacks, called by
304 // BluetoothLowEnergyEventRouter::ReadDescriptorValue.
305 void SuccessCallback();
306 void ErrorCallback(BluetoothLowEnergyEventRouter::Status status);
308 // The instance ID of the requested descriptor.
309 std::string instance_id_;
312 class BluetoothLowEnergyWriteDescriptorValueFunction
313 : public BluetoothLowEnergyExtensionFunction {
315 DECLARE_EXTENSION_FUNCTION("bluetoothLowEnergy.writeDescriptorValue",
316 BLUETOOTHLOWENERGY_WRITEDESCRIPTORVALUE);
319 virtual ~BluetoothLowEnergyWriteDescriptorValueFunction() {}
321 // BluetoothLowEnergyExtensionFunction override.
322 virtual bool DoWork() OVERRIDE;
325 // Success and error callbacks, called by
326 // BluetoothLowEnergyEventRouter::WriteDescriptorValue.
327 void SuccessCallback();
328 void ErrorCallback(BluetoothLowEnergyEventRouter::Status status);
330 // The instance ID of the requested descriptor.
331 std::string instance_id_;
334 } // namespace core_api
335 } // namespace extensions
337 #endif // EXTENSIONS_BROWSER_API_BLUETOOTH_LOW_ENERGY_BLUETOOTH_LOW_ENERGY_API_H_