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

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: rpaquay@'s comments. 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 void DoWork() = 0;
71
72 private:
73 // Note: This should remain the last member so it'll be destroyed and
74 // invalidate its weak pointers before any other members are destroyed.
75 base::WeakPtrFactory<BluetoothLowEnergyExtensionFunction> weak_ptr_factory_;
rpaquay 2014/04/24 23:00:04 Is this field still needed?
armansito 2014/04/24 23:02:31 It's removed in the latest patch set.
76
77 DISALLOW_COPY_AND_ASSIGN(BluetoothLowEnergyExtensionFunction);
78 };
79
80 class BluetoothLowEnergyGetServiceFunction
81 : public BluetoothLowEnergyExtensionFunction {
15 public: 82 public:
16 DECLARE_EXTENSION_FUNCTION("bluetoothLowEnergy.getService", 83 DECLARE_EXTENSION_FUNCTION("bluetoothLowEnergy.getService",
17 BLUETOOTHLOWENERGY_GETSERVICE); 84 BLUETOOTHLOWENERGY_GETSERVICE);
18 85
19 protected: 86 protected:
20 virtual ~BluetoothLowEnergyGetServiceFunction() {} 87 virtual ~BluetoothLowEnergyGetServiceFunction() {}
21 88
22 // UIThreadExtensionFunction override. 89 // BluetoothLowEnergyExtensionFunction override.
23 virtual bool RunImpl() OVERRIDE; 90 virtual void DoWork() OVERRIDE;
24 }; 91 };
25 92
26 class BluetoothLowEnergyGetServicesFunction : public UIThreadExtensionFunction { 93 class BluetoothLowEnergyGetServicesFunction
94 : public BluetoothLowEnergyExtensionFunction {
27 public: 95 public:
28 DECLARE_EXTENSION_FUNCTION("bluetoothLowEnergy.getServices", 96 DECLARE_EXTENSION_FUNCTION("bluetoothLowEnergy.getServices",
29 BLUETOOTHLOWENERGY_GETSERVICES); 97 BLUETOOTHLOWENERGY_GETSERVICES);
30 98
31 protected: 99 protected:
32 virtual ~BluetoothLowEnergyGetServicesFunction() {} 100 virtual ~BluetoothLowEnergyGetServicesFunction() {}
33 101
34 // UIThreadExtensionFunction override. 102 // BluetoothLowEnergyExtensionFunction override.
35 virtual bool RunImpl() OVERRIDE; 103 virtual void DoWork() OVERRIDE;
36 }; 104 };
37 105
38 class BluetoothLowEnergyGetCharacteristicFunction 106 class BluetoothLowEnergyGetCharacteristicFunction
39 : public UIThreadExtensionFunction { 107 : public BluetoothLowEnergyExtensionFunction {
40 public: 108 public:
41 DECLARE_EXTENSION_FUNCTION("bluetoothLowEnergy.getCharacteristic", 109 DECLARE_EXTENSION_FUNCTION("bluetoothLowEnergy.getCharacteristic",
42 BLUETOOTHLOWENERGY_GETCHARACTERISTIC); 110 BLUETOOTHLOWENERGY_GETCHARACTERISTIC);
43 111
44 protected: 112 protected:
45 virtual ~BluetoothLowEnergyGetCharacteristicFunction() {} 113 virtual ~BluetoothLowEnergyGetCharacteristicFunction() {}
46 114
47 // UIThreadExtensionFunction override. 115 // BluetoothLowEnergyExtensionFunction override.
48 virtual bool RunImpl() OVERRIDE; 116 virtual void DoWork() OVERRIDE;
49 }; 117 };
50 118
51 class BluetoothLowEnergyGetCharacteristicsFunction 119 class BluetoothLowEnergyGetCharacteristicsFunction
52 : public UIThreadExtensionFunction { 120 : public BluetoothLowEnergyExtensionFunction {
53 public: 121 public:
54 DECLARE_EXTENSION_FUNCTION("bluetoothLowEnergy.getCharacteristics", 122 DECLARE_EXTENSION_FUNCTION("bluetoothLowEnergy.getCharacteristics",
55 BLUETOOTHLOWENERGY_GETCHARACTERISTICS); 123 BLUETOOTHLOWENERGY_GETCHARACTERISTICS);
56 124
57 protected: 125 protected:
58 virtual ~BluetoothLowEnergyGetCharacteristicsFunction() {} 126 virtual ~BluetoothLowEnergyGetCharacteristicsFunction() {}
59 127
60 // UIThreadExtensionFunction override. 128 // BluetoothLowEnergyExtensionFunction override.
61 virtual bool RunImpl() OVERRIDE; 129 virtual void DoWork() OVERRIDE;
62 }; 130 };
63 131
64 class BluetoothLowEnergyGetIncludedServicesFunction 132 class BluetoothLowEnergyGetIncludedServicesFunction
65 : public UIThreadExtensionFunction { 133 : public BluetoothLowEnergyExtensionFunction {
66 public: 134 public:
67 DECLARE_EXTENSION_FUNCTION("bluetoothLowEnergy.getIncludedServices", 135 DECLARE_EXTENSION_FUNCTION("bluetoothLowEnergy.getIncludedServices",
68 BLUETOOTHLOWENERGY_GETINCLUDEDSERVICES); 136 BLUETOOTHLOWENERGY_GETINCLUDEDSERVICES);
69 137
70 protected: 138 protected:
71 virtual ~BluetoothLowEnergyGetIncludedServicesFunction() {} 139 virtual ~BluetoothLowEnergyGetIncludedServicesFunction() {}
72 140
73 // UIThreadExtensionFunction override. 141 // BluetoothLowEnergyExtensionFunction override.
74 virtual bool RunImpl() OVERRIDE; 142 virtual void DoWork() OVERRIDE;
75 }; 143 };
76 144
77 class BluetoothLowEnergyGetDescriptorFunction 145 class BluetoothLowEnergyGetDescriptorFunction
78 : public UIThreadExtensionFunction { 146 : public BluetoothLowEnergyExtensionFunction {
79 public: 147 public:
80 DECLARE_EXTENSION_FUNCTION("bluetoothLowEnergy.getDescriptor", 148 DECLARE_EXTENSION_FUNCTION("bluetoothLowEnergy.getDescriptor",
81 BLUETOOTHLOWENERGY_GETDESCRIPTOR); 149 BLUETOOTHLOWENERGY_GETDESCRIPTOR);
82 150
83 protected: 151 protected:
84 virtual ~BluetoothLowEnergyGetDescriptorFunction() {} 152 virtual ~BluetoothLowEnergyGetDescriptorFunction() {}
85 153
86 // UIThreadExtensionFunction override. 154 // BluetoothLowEnergyExtensionFunction override.
87 virtual bool RunImpl() OVERRIDE; 155 virtual void DoWork() OVERRIDE;
88 }; 156 };
89 157
90 class BluetoothLowEnergyGetDescriptorsFunction 158 class BluetoothLowEnergyGetDescriptorsFunction
91 : public UIThreadExtensionFunction { 159 : public BluetoothLowEnergyExtensionFunction {
92 public: 160 public:
93 DECLARE_EXTENSION_FUNCTION("bluetoothLowEnergy.getDescriptors", 161 DECLARE_EXTENSION_FUNCTION("bluetoothLowEnergy.getDescriptors",
94 BLUETOOTHLOWENERGY_GETDESCRIPTORS); 162 BLUETOOTHLOWENERGY_GETDESCRIPTORS);
95 163
96 protected: 164 protected:
97 virtual ~BluetoothLowEnergyGetDescriptorsFunction() {} 165 virtual ~BluetoothLowEnergyGetDescriptorsFunction() {}
98 166
99 // UIThreadExtensionFunction override. 167 // BluetoothLowEnergyExtensionFunction override.
100 virtual bool RunImpl() OVERRIDE; 168 virtual void DoWork() OVERRIDE;
101 }; 169 };
102 170
103 class BluetoothLowEnergyReadCharacteristicValueFunction 171 class BluetoothLowEnergyReadCharacteristicValueFunction
104 : public UIThreadExtensionFunction { 172 : public BluetoothLowEnergyExtensionFunction {
105 public: 173 public:
106 DECLARE_EXTENSION_FUNCTION("bluetoothLowEnergy.readCharacteristicValue", 174 DECLARE_EXTENSION_FUNCTION("bluetoothLowEnergy.readCharacteristicValue",
107 BLUETOOTHLOWENERGY_READCHARACTERISTICVALUE); 175 BLUETOOTHLOWENERGY_READCHARACTERISTICVALUE);
108 176
109 protected: 177 protected:
110 virtual ~BluetoothLowEnergyReadCharacteristicValueFunction() {} 178 virtual ~BluetoothLowEnergyReadCharacteristicValueFunction() {}
111 179
112 // UIThreadExtensionFunction override. 180 // BluetoothLowEnergyExtensionFunction override.
113 virtual bool RunImpl() OVERRIDE; 181 virtual void DoWork() OVERRIDE;
114 }; 182 };
115 183
116 class BluetoothLowEnergyWriteCharacteristicValueFunction 184 class BluetoothLowEnergyWriteCharacteristicValueFunction
117 : public UIThreadExtensionFunction { 185 : public BluetoothLowEnergyExtensionFunction {
118 public: 186 public:
119 DECLARE_EXTENSION_FUNCTION("bluetoothLowEnergy.writeCharacteristicValue", 187 DECLARE_EXTENSION_FUNCTION("bluetoothLowEnergy.writeCharacteristicValue",
120 BLUETOOTHLOWENERGY_WRITECHARACTERISTICVALUE); 188 BLUETOOTHLOWENERGY_WRITECHARACTERISTICVALUE);
121 189
122 protected: 190 protected:
123 virtual ~BluetoothLowEnergyWriteCharacteristicValueFunction() {} 191 virtual ~BluetoothLowEnergyWriteCharacteristicValueFunction() {}
124 192
125 // UIThreadExtensionFunction override. 193 // BluetoothLowEnergyExtensionFunction override.
126 virtual bool RunImpl() OVERRIDE; 194 virtual void DoWork() OVERRIDE;
127 }; 195 };
128 196
129 class BluetoothLowEnergyReadDescriptorValueFunction 197 class BluetoothLowEnergyReadDescriptorValueFunction
130 : public UIThreadExtensionFunction { 198 : public BluetoothLowEnergyExtensionFunction {
131 public: 199 public:
132 DECLARE_EXTENSION_FUNCTION("bluetoothLowEnergy.readDescriptorValue", 200 DECLARE_EXTENSION_FUNCTION("bluetoothLowEnergy.readDescriptorValue",
133 BLUETOOTHLOWENERGY_READDESCRIPTORVALUE); 201 BLUETOOTHLOWENERGY_READDESCRIPTORVALUE);
134 202
135 protected: 203 protected:
136 virtual ~BluetoothLowEnergyReadDescriptorValueFunction() {} 204 virtual ~BluetoothLowEnergyReadDescriptorValueFunction() {}
137 205
138 // UIThreadExtensionFunction override. 206 // BluetoothLowEnergyExtensionFunction override.
139 virtual bool RunImpl() OVERRIDE; 207 virtual void DoWork() OVERRIDE;
140 }; 208 };
141 209
142 class BluetoothLowEnergyWriteDescriptorValueFunction 210 class BluetoothLowEnergyWriteDescriptorValueFunction
143 : public UIThreadExtensionFunction { 211 : public BluetoothLowEnergyExtensionFunction {
144 public: 212 public:
145 DECLARE_EXTENSION_FUNCTION("bluetoothLowEnergy.writeDescriptorValue", 213 DECLARE_EXTENSION_FUNCTION("bluetoothLowEnergy.writeDescriptorValue",
146 BLUETOOTHLOWENERGY_WRITEDESCRIPTORVALUE); 214 BLUETOOTHLOWENERGY_WRITEDESCRIPTORVALUE);
147 215
148 protected: 216 protected:
149 virtual ~BluetoothLowEnergyWriteDescriptorValueFunction() {} 217 virtual ~BluetoothLowEnergyWriteDescriptorValueFunction() {}
150 218
151 // UIThreadExtensionFunction override. 219 // BluetoothLowEnergyExtensionFunction override.
152 virtual bool RunImpl() OVERRIDE; 220 virtual void DoWork() OVERRIDE;
153 }; 221 };
154 222
155 } // namespace api 223 } // namespace api
156 } // namespace extensions 224 } // namespace extensions
157 225
158 #endif // CHROME_BROWSER_EXTENSIONS_API_BLUETOOTH_LOW_ENERGY_BLUETOOTH_LOW_ENER GY_API_H_ 226 #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