Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / extensions / api / bluetooth_low_energy / bluetooth_low_energy_api.h
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.
4
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_
7
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"
12
13 namespace extensions {
14
15 class BluetoothLowEnergyEventRouter;
16
17 // The profile-keyed service that manages the bluetoothLowEnergy extension API.
18 class BluetoothLowEnergyAPI : public BrowserContextKeyedAPI {
19  public:
20   static BrowserContextKeyedAPIFactory<BluetoothLowEnergyAPI>*
21       GetFactoryInstance();
22
23   // Convenience method to get the BluetoothLowEnergy API for a browser context.
24   static BluetoothLowEnergyAPI* Get(content::BrowserContext* context);
25
26   explicit BluetoothLowEnergyAPI(content::BrowserContext* context);
27   virtual ~BluetoothLowEnergyAPI();
28
29   // KeyedService implementation..
30   virtual void Shutdown() OVERRIDE;
31
32   BluetoothLowEnergyEventRouter* event_router() const {
33     return event_router_.get();
34   }
35
36   // BrowserContextKeyedAPI implementation.
37   static const char* service_name() { return "BluetoothLowEnergyAPI"; }
38   static const bool kServiceRedirectedInIncognito = true;
39   static const bool kServiceIsNULLWhileTesting = true;
40
41  private:
42   friend class BrowserContextKeyedAPIFactory<BluetoothLowEnergyAPI>;
43
44   scoped_ptr<BluetoothLowEnergyEventRouter> event_router_;
45
46   content::BrowserContext* browser_context_;
47
48   DISALLOW_COPY_AND_ASSIGN(BluetoothLowEnergyAPI);
49 };
50
51 namespace api {
52
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 {
57  public:
58   BluetoothLowEnergyExtensionFunction();
59
60  protected:
61   virtual ~BluetoothLowEnergyExtensionFunction();
62
63   // ExtensionFunction override.
64   virtual bool RunAsync() OVERRIDE;
65
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
69   // BluetoothAdapter.
70   virtual bool DoWork() = 0;
71
72  private:
73   DISALLOW_COPY_AND_ASSIGN(BluetoothLowEnergyExtensionFunction);
74 };
75
76 class BluetoothLowEnergyGetServiceFunction
77     : public BluetoothLowEnergyExtensionFunction {
78  public:
79   DECLARE_EXTENSION_FUNCTION("bluetoothLowEnergy.getService",
80                              BLUETOOTHLOWENERGY_GETSERVICE);
81
82  protected:
83   virtual ~BluetoothLowEnergyGetServiceFunction() {}
84
85   // BluetoothLowEnergyExtensionFunction override.
86   virtual bool DoWork() OVERRIDE;
87 };
88
89 class BluetoothLowEnergyGetServicesFunction
90     : public BluetoothLowEnergyExtensionFunction {
91  public:
92   DECLARE_EXTENSION_FUNCTION("bluetoothLowEnergy.getServices",
93                              BLUETOOTHLOWENERGY_GETSERVICES);
94
95  protected:
96   virtual ~BluetoothLowEnergyGetServicesFunction() {}
97
98   // BluetoothLowEnergyExtensionFunction override.
99   virtual bool DoWork() OVERRIDE;
100 };
101
102 class BluetoothLowEnergyGetCharacteristicFunction
103     : public BluetoothLowEnergyExtensionFunction {
104  public:
105   DECLARE_EXTENSION_FUNCTION("bluetoothLowEnergy.getCharacteristic",
106                              BLUETOOTHLOWENERGY_GETCHARACTERISTIC);
107
108  protected:
109   virtual ~BluetoothLowEnergyGetCharacteristicFunction() {}
110
111   // BluetoothLowEnergyExtensionFunction override.
112   virtual bool DoWork() OVERRIDE;
113 };
114
115 class BluetoothLowEnergyGetCharacteristicsFunction
116     : public BluetoothLowEnergyExtensionFunction {
117  public:
118   DECLARE_EXTENSION_FUNCTION("bluetoothLowEnergy.getCharacteristics",
119                              BLUETOOTHLOWENERGY_GETCHARACTERISTICS);
120
121  protected:
122   virtual ~BluetoothLowEnergyGetCharacteristicsFunction() {}
123
124   // BluetoothLowEnergyExtensionFunction override.
125   virtual bool DoWork() OVERRIDE;
126 };
127
128 class BluetoothLowEnergyGetIncludedServicesFunction
129     : public BluetoothLowEnergyExtensionFunction {
130  public:
131   DECLARE_EXTENSION_FUNCTION("bluetoothLowEnergy.getIncludedServices",
132                              BLUETOOTHLOWENERGY_GETINCLUDEDSERVICES);
133
134  protected:
135   virtual ~BluetoothLowEnergyGetIncludedServicesFunction() {}
136
137   // BluetoothLowEnergyExtensionFunction override.
138   virtual bool DoWork() OVERRIDE;
139 };
140
141 class BluetoothLowEnergyGetDescriptorFunction
142     : public BluetoothLowEnergyExtensionFunction {
143  public:
144   DECLARE_EXTENSION_FUNCTION("bluetoothLowEnergy.getDescriptor",
145                              BLUETOOTHLOWENERGY_GETDESCRIPTOR);
146
147  protected:
148   virtual ~BluetoothLowEnergyGetDescriptorFunction() {}
149
150   // BluetoothLowEnergyExtensionFunction override.
151   virtual bool DoWork() OVERRIDE;
152 };
153
154 class BluetoothLowEnergyGetDescriptorsFunction
155     : public BluetoothLowEnergyExtensionFunction {
156  public:
157   DECLARE_EXTENSION_FUNCTION("bluetoothLowEnergy.getDescriptors",
158                              BLUETOOTHLOWENERGY_GETDESCRIPTORS);
159
160  protected:
161   virtual ~BluetoothLowEnergyGetDescriptorsFunction() {}
162
163   // BluetoothLowEnergyExtensionFunction override.
164   virtual bool DoWork() OVERRIDE;
165 };
166
167 class BluetoothLowEnergyReadCharacteristicValueFunction
168     : public BluetoothLowEnergyExtensionFunction {
169  public:
170   DECLARE_EXTENSION_FUNCTION("bluetoothLowEnergy.readCharacteristicValue",
171                              BLUETOOTHLOWENERGY_READCHARACTERISTICVALUE);
172
173  protected:
174   virtual ~BluetoothLowEnergyReadCharacteristicValueFunction() {}
175
176   // BluetoothLowEnergyExtensionFunction override.
177   virtual bool DoWork() OVERRIDE;
178
179  private:
180   // Success and error callbacks, called by
181   // BluetoothLowEnergyEventRouter::ReadCharacteristicValue.
182   void SuccessCallback();
183   void ErrorCallback();
184
185   // The instance ID of the requested characteristic.
186   std::string instance_id_;
187 };
188
189 class BluetoothLowEnergyWriteCharacteristicValueFunction
190     : public BluetoothLowEnergyExtensionFunction {
191  public:
192   DECLARE_EXTENSION_FUNCTION("bluetoothLowEnergy.writeCharacteristicValue",
193                              BLUETOOTHLOWENERGY_WRITECHARACTERISTICVALUE);
194
195  protected:
196   virtual ~BluetoothLowEnergyWriteCharacteristicValueFunction() {}
197
198   // BluetoothLowEnergyExtensionFunction override.
199   virtual bool DoWork() OVERRIDE;
200 };
201
202 class BluetoothLowEnergyReadDescriptorValueFunction
203     : public BluetoothLowEnergyExtensionFunction {
204  public:
205   DECLARE_EXTENSION_FUNCTION("bluetoothLowEnergy.readDescriptorValue",
206                              BLUETOOTHLOWENERGY_READDESCRIPTORVALUE);
207
208  protected:
209   virtual ~BluetoothLowEnergyReadDescriptorValueFunction() {}
210
211   // BluetoothLowEnergyExtensionFunction override.
212   virtual bool DoWork() OVERRIDE;
213 };
214
215 class BluetoothLowEnergyWriteDescriptorValueFunction
216     : public BluetoothLowEnergyExtensionFunction {
217  public:
218   DECLARE_EXTENSION_FUNCTION("bluetoothLowEnergy.writeDescriptorValue",
219                              BLUETOOTHLOWENERGY_WRITEDESCRIPTORVALUE);
220
221  protected:
222   virtual ~BluetoothLowEnergyWriteDescriptorValueFunction() {}
223
224   // BluetoothLowEnergyExtensionFunction override.
225   virtual bool DoWork() OVERRIDE;
226 };
227
228 }  // namespace api
229 }  // namespace extensions
230
231 #endif  // CHROME_BROWSER_EXTENSIONS_API_BLUETOOTH_LOW_ENERGY_BLUETOOTH_LOW_ENERGY_API_H_