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

Side by Side Diff: chrome/browser/extensions/api/bluetooth_low_energy/bluetooth_low_energy_api.h

Issue 256413003: chrome.bluetoothLowEnergy: Implement getService and getServices. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebased Created 6 years, 8 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | chrome/browser/extensions/api/bluetooth_low_energy/bluetooth_low_energy_api.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CHROME_BROWSER_EXTENSIONS_API_BLUETOOTH_LOW_ENERGY_BLUETOOTH_LOW_ENERGY_ API_H_ 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_ 6 #define CHROME_BROWSER_EXTENSIONS_API_BLUETOOTH_LOW_ENERGY_BLUETOOTH_LOW_ENERGY_ API_H_
7 7
8 #include "base/memory/scoped_ptr.h"
9 #include "extensions/browser/browser_context_keyed_api_factory.h"
8 #include "extensions/browser/extension_function.h" 10 #include "extensions/browser/extension_function.h"
9 #include "extensions/browser/extension_function_histogram_value.h" 11 #include "extensions/browser/extension_function_histogram_value.h"
10 12
11 namespace extensions { 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
12 namespace api { 51 namespace api {
13 52
14 class BluetoothLowEnergyGetServiceFunction : public UIThreadExtensionFunction { 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 UIThreadExtensionFunction {
57 public:
58 BluetoothLowEnergyExtensionFunction();
59
60 protected:
61 virtual ~BluetoothLowEnergyExtensionFunction();
62
63 // ExtensionFunction override.
64 virtual bool RunImpl() OVERRIDE;
65
66 // Implemented by individual bluetoothLowEnergy extension functions to perform
67 // the body of the function. This invoked asynchonously after RunImpl 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 {
15 public: 78 public:
16 DECLARE_EXTENSION_FUNCTION("bluetoothLowEnergy.getService", 79 DECLARE_EXTENSION_FUNCTION("bluetoothLowEnergy.getService",
17 BLUETOOTHLOWENERGY_GETSERVICE); 80 BLUETOOTHLOWENERGY_GETSERVICE);
18 81
19 protected: 82 protected:
20 virtual ~BluetoothLowEnergyGetServiceFunction() {} 83 virtual ~BluetoothLowEnergyGetServiceFunction() {}
21 84
22 // UIThreadExtensionFunction override. 85 // BluetoothLowEnergyExtensionFunction override.
23 virtual bool RunImpl() OVERRIDE; 86 virtual bool DoWork() OVERRIDE;
24 }; 87 };
25 88
26 class BluetoothLowEnergyGetServicesFunction : public UIThreadExtensionFunction { 89 class BluetoothLowEnergyGetServicesFunction
90 : public BluetoothLowEnergyExtensionFunction {
27 public: 91 public:
28 DECLARE_EXTENSION_FUNCTION("bluetoothLowEnergy.getServices", 92 DECLARE_EXTENSION_FUNCTION("bluetoothLowEnergy.getServices",
29 BLUETOOTHLOWENERGY_GETSERVICES); 93 BLUETOOTHLOWENERGY_GETSERVICES);
30 94
31 protected: 95 protected:
32 virtual ~BluetoothLowEnergyGetServicesFunction() {} 96 virtual ~BluetoothLowEnergyGetServicesFunction() {}
33 97
34 // UIThreadExtensionFunction override. 98 // BluetoothLowEnergyExtensionFunction override.
35 virtual bool RunImpl() OVERRIDE; 99 virtual bool DoWork() OVERRIDE;
36 }; 100 };
37 101
38 class BluetoothLowEnergyGetCharacteristicFunction 102 class BluetoothLowEnergyGetCharacteristicFunction
39 : public UIThreadExtensionFunction { 103 : public BluetoothLowEnergyExtensionFunction {
40 public: 104 public:
41 DECLARE_EXTENSION_FUNCTION("bluetoothLowEnergy.getCharacteristic", 105 DECLARE_EXTENSION_FUNCTION("bluetoothLowEnergy.getCharacteristic",
42 BLUETOOTHLOWENERGY_GETCHARACTERISTIC); 106 BLUETOOTHLOWENERGY_GETCHARACTERISTIC);
43 107
44 protected: 108 protected:
45 virtual ~BluetoothLowEnergyGetCharacteristicFunction() {} 109 virtual ~BluetoothLowEnergyGetCharacteristicFunction() {}
46 110
47 // UIThreadExtensionFunction override. 111 // BluetoothLowEnergyExtensionFunction override.
48 virtual bool RunImpl() OVERRIDE; 112 virtual bool DoWork() OVERRIDE;
49 }; 113 };
50 114
51 class BluetoothLowEnergyGetCharacteristicsFunction 115 class BluetoothLowEnergyGetCharacteristicsFunction
52 : public UIThreadExtensionFunction { 116 : public BluetoothLowEnergyExtensionFunction {
53 public: 117 public:
54 DECLARE_EXTENSION_FUNCTION("bluetoothLowEnergy.getCharacteristics", 118 DECLARE_EXTENSION_FUNCTION("bluetoothLowEnergy.getCharacteristics",
55 BLUETOOTHLOWENERGY_GETCHARACTERISTICS); 119 BLUETOOTHLOWENERGY_GETCHARACTERISTICS);
56 120
57 protected: 121 protected:
58 virtual ~BluetoothLowEnergyGetCharacteristicsFunction() {} 122 virtual ~BluetoothLowEnergyGetCharacteristicsFunction() {}
59 123
60 // UIThreadExtensionFunction override. 124 // BluetoothLowEnergyExtensionFunction override.
61 virtual bool RunImpl() OVERRIDE; 125 virtual bool DoWork() OVERRIDE;
62 }; 126 };
63 127
64 class BluetoothLowEnergyGetIncludedServicesFunction 128 class BluetoothLowEnergyGetIncludedServicesFunction
65 : public UIThreadExtensionFunction { 129 : public BluetoothLowEnergyExtensionFunction {
66 public: 130 public:
67 DECLARE_EXTENSION_FUNCTION("bluetoothLowEnergy.getIncludedServices", 131 DECLARE_EXTENSION_FUNCTION("bluetoothLowEnergy.getIncludedServices",
68 BLUETOOTHLOWENERGY_GETINCLUDEDSERVICES); 132 BLUETOOTHLOWENERGY_GETINCLUDEDSERVICES);
69 133
70 protected: 134 protected:
71 virtual ~BluetoothLowEnergyGetIncludedServicesFunction() {} 135 virtual ~BluetoothLowEnergyGetIncludedServicesFunction() {}
72 136
73 // UIThreadExtensionFunction override. 137 // BluetoothLowEnergyExtensionFunction override.
74 virtual bool RunImpl() OVERRIDE; 138 virtual bool DoWork() OVERRIDE;
75 }; 139 };
76 140
77 class BluetoothLowEnergyGetDescriptorFunction 141 class BluetoothLowEnergyGetDescriptorFunction
78 : public UIThreadExtensionFunction { 142 : public BluetoothLowEnergyExtensionFunction {
79 public: 143 public:
80 DECLARE_EXTENSION_FUNCTION("bluetoothLowEnergy.getDescriptor", 144 DECLARE_EXTENSION_FUNCTION("bluetoothLowEnergy.getDescriptor",
81 BLUETOOTHLOWENERGY_GETDESCRIPTOR); 145 BLUETOOTHLOWENERGY_GETDESCRIPTOR);
82 146
83 protected: 147 protected:
84 virtual ~BluetoothLowEnergyGetDescriptorFunction() {} 148 virtual ~BluetoothLowEnergyGetDescriptorFunction() {}
85 149
86 // UIThreadExtensionFunction override. 150 // BluetoothLowEnergyExtensionFunction override.
87 virtual bool RunImpl() OVERRIDE; 151 virtual bool DoWork() OVERRIDE;
88 }; 152 };
89 153
90 class BluetoothLowEnergyGetDescriptorsFunction 154 class BluetoothLowEnergyGetDescriptorsFunction
91 : public UIThreadExtensionFunction { 155 : public BluetoothLowEnergyExtensionFunction {
92 public: 156 public:
93 DECLARE_EXTENSION_FUNCTION("bluetoothLowEnergy.getDescriptors", 157 DECLARE_EXTENSION_FUNCTION("bluetoothLowEnergy.getDescriptors",
94 BLUETOOTHLOWENERGY_GETDESCRIPTORS); 158 BLUETOOTHLOWENERGY_GETDESCRIPTORS);
95 159
96 protected: 160 protected:
97 virtual ~BluetoothLowEnergyGetDescriptorsFunction() {} 161 virtual ~BluetoothLowEnergyGetDescriptorsFunction() {}
98 162
99 // UIThreadExtensionFunction override. 163 // BluetoothLowEnergyExtensionFunction override.
100 virtual bool RunImpl() OVERRIDE; 164 virtual bool DoWork() OVERRIDE;
101 }; 165 };
102 166
103 class BluetoothLowEnergyReadCharacteristicValueFunction 167 class BluetoothLowEnergyReadCharacteristicValueFunction
104 : public UIThreadExtensionFunction { 168 : public BluetoothLowEnergyExtensionFunction {
105 public: 169 public:
106 DECLARE_EXTENSION_FUNCTION("bluetoothLowEnergy.readCharacteristicValue", 170 DECLARE_EXTENSION_FUNCTION("bluetoothLowEnergy.readCharacteristicValue",
107 BLUETOOTHLOWENERGY_READCHARACTERISTICVALUE); 171 BLUETOOTHLOWENERGY_READCHARACTERISTICVALUE);
108 172
109 protected: 173 protected:
110 virtual ~BluetoothLowEnergyReadCharacteristicValueFunction() {} 174 virtual ~BluetoothLowEnergyReadCharacteristicValueFunction() {}
111 175
112 // UIThreadExtensionFunction override. 176 // BluetoothLowEnergyExtensionFunction override.
113 virtual bool RunImpl() OVERRIDE; 177 virtual bool DoWork() OVERRIDE;
114 }; 178 };
115 179
116 class BluetoothLowEnergyWriteCharacteristicValueFunction 180 class BluetoothLowEnergyWriteCharacteristicValueFunction
117 : public UIThreadExtensionFunction { 181 : public BluetoothLowEnergyExtensionFunction {
118 public: 182 public:
119 DECLARE_EXTENSION_FUNCTION("bluetoothLowEnergy.writeCharacteristicValue", 183 DECLARE_EXTENSION_FUNCTION("bluetoothLowEnergy.writeCharacteristicValue",
120 BLUETOOTHLOWENERGY_WRITECHARACTERISTICVALUE); 184 BLUETOOTHLOWENERGY_WRITECHARACTERISTICVALUE);
121 185
122 protected: 186 protected:
123 virtual ~BluetoothLowEnergyWriteCharacteristicValueFunction() {} 187 virtual ~BluetoothLowEnergyWriteCharacteristicValueFunction() {}
124 188
125 // UIThreadExtensionFunction override. 189 // BluetoothLowEnergyExtensionFunction override.
126 virtual bool RunImpl() OVERRIDE; 190 virtual bool DoWork() OVERRIDE;
127 }; 191 };
128 192
129 class BluetoothLowEnergyReadDescriptorValueFunction 193 class BluetoothLowEnergyReadDescriptorValueFunction
130 : public UIThreadExtensionFunction { 194 : public BluetoothLowEnergyExtensionFunction {
131 public: 195 public:
132 DECLARE_EXTENSION_FUNCTION("bluetoothLowEnergy.readDescriptorValue", 196 DECLARE_EXTENSION_FUNCTION("bluetoothLowEnergy.readDescriptorValue",
133 BLUETOOTHLOWENERGY_READDESCRIPTORVALUE); 197 BLUETOOTHLOWENERGY_READDESCRIPTORVALUE);
134 198
135 protected: 199 protected:
136 virtual ~BluetoothLowEnergyReadDescriptorValueFunction() {} 200 virtual ~BluetoothLowEnergyReadDescriptorValueFunction() {}
137 201
138 // UIThreadExtensionFunction override. 202 // BluetoothLowEnergyExtensionFunction override.
139 virtual bool RunImpl() OVERRIDE; 203 virtual bool DoWork() OVERRIDE;
140 }; 204 };
141 205
142 class BluetoothLowEnergyWriteDescriptorValueFunction 206 class BluetoothLowEnergyWriteDescriptorValueFunction
143 : public UIThreadExtensionFunction { 207 : public BluetoothLowEnergyExtensionFunction {
144 public: 208 public:
145 DECLARE_EXTENSION_FUNCTION("bluetoothLowEnergy.writeDescriptorValue", 209 DECLARE_EXTENSION_FUNCTION("bluetoothLowEnergy.writeDescriptorValue",
146 BLUETOOTHLOWENERGY_WRITEDESCRIPTORVALUE); 210 BLUETOOTHLOWENERGY_WRITEDESCRIPTORVALUE);
147 211
148 protected: 212 protected:
149 virtual ~BluetoothLowEnergyWriteDescriptorValueFunction() {} 213 virtual ~BluetoothLowEnergyWriteDescriptorValueFunction() {}
150 214
151 // UIThreadExtensionFunction override. 215 // BluetoothLowEnergyExtensionFunction override.
152 virtual bool RunImpl() OVERRIDE; 216 virtual bool DoWork() OVERRIDE;
153 }; 217 };
154 218
155 } // namespace api 219 } // namespace api
156 } // namespace extensions 220 } // namespace extensions
157 221
158 #endif // CHROME_BROWSER_EXTENSIONS_API_BLUETOOTH_LOW_ENERGY_BLUETOOTH_LOW_ENER GY_API_H_ 222 #endif // CHROME_BROWSER_EXTENSIONS_API_BLUETOOTH_LOW_ENERGY_BLUETOOTH_LOW_ENER GY_API_H_
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/extensions/api/bluetooth_low_energy/bluetooth_low_energy_api.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698