OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_BLUETOOTH_API_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_API_BLUETOOTH_BLUETOOTH_API_H_ |
6 #define CHROME_BROWSER_EXTENSIONS_API_BLUETOOTH_BLUETOOTH_API_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_API_BLUETOOTH_BLUETOOTH_API_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/memory/ref_counted.h" | |
10 #include "chrome/browser/extensions/api/api_function.h" | 11 #include "chrome/browser/extensions/api/api_function.h" |
11 #include "chrome/browser/extensions/extension_function.h" | 12 #include "chrome/browser/extensions/extension_function.h" |
13 #include "device/bluetooth/bluetooth_device.h" | |
14 #include "device/bluetooth/bluetooth_socket.h" | |
12 | 15 |
13 #if defined(OS_CHROMEOS) | 16 namespace bluetooth { |
14 #include "base/memory/ref_counted.h" | |
15 #include "chrome/browser/chromeos/bluetooth/bluetooth_device.h" | |
16 #include "chrome/browser/chromeos/bluetooth/bluetooth_socket.h" | |
17 | |
18 namespace chromeos { | |
19 | 17 |
20 class BluetoothSocket; | 18 class BluetoothSocket; |
bryeung
2012/10/11 15:15:39
please remove this (it's not needed, nor was it be
youngki
2012/10/11 16:21:18
BluetoothSocket is being used as a scoped_refptr i
| |
21 struct BluetoothOutOfBandPairingData; | 19 struct BluetoothOutOfBandPairingData; |
22 | 20 |
23 } // namespace chromeos | 21 } // namespace bluetooth |
24 #endif | |
25 | 22 |
26 namespace extensions { | 23 namespace extensions { |
27 namespace api { | 24 namespace api { |
28 | 25 |
29 class BluetoothIsAvailableFunction : public SyncExtensionFunction { | 26 class BluetoothIsAvailableFunction : public SyncExtensionFunction { |
30 public: | 27 public: |
31 DECLARE_EXTENSION_FUNCTION_NAME("experimental.bluetooth.isAvailable") | 28 DECLARE_EXTENSION_FUNCTION_NAME("experimental.bluetooth.isAvailable") |
32 | 29 |
33 protected: | 30 protected: |
34 virtual ~BluetoothIsAvailableFunction() {} | 31 virtual ~BluetoothIsAvailableFunction() {} |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
67 virtual ~BluetoothGetNameFunction() {} | 64 virtual ~BluetoothGetNameFunction() {} |
68 | 65 |
69 // ExtensionFunction: | 66 // ExtensionFunction: |
70 virtual bool RunImpl() OVERRIDE; | 67 virtual bool RunImpl() OVERRIDE; |
71 }; | 68 }; |
72 | 69 |
73 class BluetoothGetDevicesFunction : public AsyncExtensionFunction { | 70 class BluetoothGetDevicesFunction : public AsyncExtensionFunction { |
74 public: | 71 public: |
75 DECLARE_EXTENSION_FUNCTION_NAME("experimental.bluetooth.getDevices") | 72 DECLARE_EXTENSION_FUNCTION_NAME("experimental.bluetooth.getDevices") |
76 | 73 |
77 #if defined(OS_CHROMEOS) | |
78 BluetoothGetDevicesFunction(); | 74 BluetoothGetDevicesFunction(); |
79 #endif | |
80 | 75 |
81 protected: | 76 protected: |
82 virtual ~BluetoothGetDevicesFunction() {} | 77 virtual ~BluetoothGetDevicesFunction() {} |
83 | 78 |
84 // ExtensionFunction: | 79 // ExtensionFunction: |
85 virtual bool RunImpl() OVERRIDE; | 80 virtual bool RunImpl() OVERRIDE; |
86 | 81 |
87 private: | 82 private: |
88 #if defined(OS_CHROMEOS) | 83 void DispatchDeviceSearchResult(const bluetooth::BluetoothDevice& device); |
89 void DispatchDeviceSearchResult(const chromeos::BluetoothDevice& device); | 84 void ProvidesServiceCallback(const bluetooth::BluetoothDevice* device, |
90 void ProvidesServiceCallback(const chromeos::BluetoothDevice* device, | |
91 bool providesService); | 85 bool providesService); |
92 | 86 |
93 int callbacks_pending_; | 87 int callbacks_pending_; |
94 #endif | |
95 }; | 88 }; |
96 | 89 |
97 class BluetoothGetServicesFunction : public AsyncExtensionFunction { | 90 class BluetoothGetServicesFunction : public AsyncExtensionFunction { |
98 public: | 91 public: |
99 DECLARE_EXTENSION_FUNCTION_NAME("experimental.bluetooth.getServices") | 92 DECLARE_EXTENSION_FUNCTION_NAME("experimental.bluetooth.getServices") |
100 | 93 |
101 protected: | 94 protected: |
102 virtual ~BluetoothGetServicesFunction() {} | 95 virtual ~BluetoothGetServicesFunction() {} |
103 | 96 |
104 // ExtensionFunction: | 97 // ExtensionFunction: |
105 virtual bool RunImpl() OVERRIDE; | 98 virtual bool RunImpl() OVERRIDE; |
106 | 99 |
107 #if defined(OS_CHROMEOS) | |
108 private: | 100 private: |
109 void GetServiceRecordsCallback( | 101 void GetServiceRecordsCallback( |
110 base::ListValue* services, | 102 base::ListValue* services, |
111 const chromeos::BluetoothDevice::ServiceRecordList& records); | 103 const bluetooth::BluetoothDevice::ServiceRecordList& records); |
112 void OnErrorCallback(); | 104 void OnErrorCallback(); |
113 #endif | |
114 }; | 105 }; |
115 | 106 |
116 class BluetoothConnectFunction : public AsyncExtensionFunction { | 107 class BluetoothConnectFunction : public AsyncExtensionFunction { |
117 public: | 108 public: |
118 DECLARE_EXTENSION_FUNCTION_NAME("experimental.bluetooth.connect") | 109 DECLARE_EXTENSION_FUNCTION_NAME("experimental.bluetooth.connect") |
119 | 110 |
120 protected: | 111 protected: |
121 virtual ~BluetoothConnectFunction() {} | 112 virtual ~BluetoothConnectFunction() {} |
122 | 113 |
123 virtual bool RunImpl() OVERRIDE; | 114 virtual bool RunImpl() OVERRIDE; |
124 | 115 |
125 private: | 116 private: |
126 #if defined(OS_CHROMEOS) | |
127 void ConnectToServiceCallback( | 117 void ConnectToServiceCallback( |
128 const chromeos::BluetoothDevice* device, | 118 const bluetooth::BluetoothDevice* device, |
129 const std::string& service_uuid, | 119 const std::string& service_uuid, |
130 scoped_refptr<chromeos::BluetoothSocket> socket); | 120 scoped_refptr<bluetooth::BluetoothSocket> socket); |
131 #endif | |
132 }; | 121 }; |
133 | 122 |
134 class BluetoothDisconnectFunction : public SyncExtensionFunction { | 123 class BluetoothDisconnectFunction : public SyncExtensionFunction { |
135 public: | 124 public: |
136 DECLARE_EXTENSION_FUNCTION_NAME("experimental.bluetooth.disconnect") | 125 DECLARE_EXTENSION_FUNCTION_NAME("experimental.bluetooth.disconnect") |
137 | 126 |
138 protected: | 127 protected: |
139 virtual ~BluetoothDisconnectFunction() {} | 128 virtual ~BluetoothDisconnectFunction() {} |
140 | 129 |
141 // ExtensionFunction: | 130 // ExtensionFunction: |
142 virtual bool RunImpl() OVERRIDE; | 131 virtual bool RunImpl() OVERRIDE; |
143 }; | 132 }; |
144 | 133 |
145 class BluetoothReadFunction : public AsyncApiFunction { | 134 class BluetoothReadFunction : public AsyncApiFunction { |
146 public: | 135 public: |
147 DECLARE_EXTENSION_FUNCTION_NAME("experimental.bluetooth.read") | 136 DECLARE_EXTENSION_FUNCTION_NAME("experimental.bluetooth.read") |
148 BluetoothReadFunction(); | 137 BluetoothReadFunction(); |
149 | 138 |
150 protected: | 139 protected: |
151 virtual ~BluetoothReadFunction(); | 140 virtual ~BluetoothReadFunction(); |
152 | 141 |
153 // AsyncApiFunction: | 142 // AsyncApiFunction: |
154 virtual bool Prepare() OVERRIDE; | 143 virtual bool Prepare() OVERRIDE; |
155 virtual bool Respond() OVERRIDE; | 144 virtual bool Respond() OVERRIDE; |
156 virtual void Work() OVERRIDE; | 145 virtual void Work() OVERRIDE; |
157 | 146 |
158 private: | 147 private: |
159 #if defined(OS_CHROMEOS) | |
160 bool success_; | 148 bool success_; |
161 scoped_refptr<chromeos::BluetoothSocket> socket_; | 149 scoped_refptr<bluetooth::BluetoothSocket> socket_; |
162 #endif | |
163 }; | 150 }; |
164 | 151 |
165 class BluetoothWriteFunction : public AsyncApiFunction { | 152 class BluetoothWriteFunction : public AsyncApiFunction { |
166 public: | 153 public: |
167 DECLARE_EXTENSION_FUNCTION_NAME("experimental.bluetooth.write") | 154 DECLARE_EXTENSION_FUNCTION_NAME("experimental.bluetooth.write") |
168 BluetoothWriteFunction(); | 155 BluetoothWriteFunction(); |
169 | 156 |
170 protected: | 157 protected: |
171 virtual ~BluetoothWriteFunction(); | 158 virtual ~BluetoothWriteFunction(); |
172 | 159 |
173 // AsyncApiFunction: | 160 // AsyncApiFunction: |
174 virtual bool Prepare() OVERRIDE; | 161 virtual bool Prepare() OVERRIDE; |
175 virtual bool Respond() OVERRIDE; | 162 virtual bool Respond() OVERRIDE; |
176 virtual void Work() OVERRIDE; | 163 virtual void Work() OVERRIDE; |
177 | 164 |
178 private: | 165 private: |
179 #if defined(OS_CHROMEOS) | |
180 bool success_; | 166 bool success_; |
181 const base::BinaryValue* data_to_write_; // memory is owned by args_ | 167 const base::BinaryValue* data_to_write_; // memory is owned by args_ |
182 scoped_refptr<chromeos::BluetoothSocket> socket_; | 168 scoped_refptr<bluetooth::BluetoothSocket> socket_; |
183 #endif | |
184 }; | 169 }; |
185 | 170 |
186 class BluetoothSetOutOfBandPairingDataFunction | 171 class BluetoothSetOutOfBandPairingDataFunction |
187 : public AsyncExtensionFunction { | 172 : public AsyncExtensionFunction { |
188 public: | 173 public: |
189 DECLARE_EXTENSION_FUNCTION_NAME( | 174 DECLARE_EXTENSION_FUNCTION_NAME( |
190 "experimental.bluetooth.setOutOfBandPairingData") | 175 "experimental.bluetooth.setOutOfBandPairingData") |
191 | 176 |
192 protected: | 177 protected: |
193 virtual ~BluetoothSetOutOfBandPairingDataFunction() {} | 178 virtual ~BluetoothSetOutOfBandPairingDataFunction() {} |
194 | 179 |
195 #if defined(OS_CHROMEOS) | |
196 void OnSuccessCallback(); | 180 void OnSuccessCallback(); |
197 void OnErrorCallback(); | 181 void OnErrorCallback(); |
198 #endif | |
199 | 182 |
200 // ExtensionFunction: | 183 // ExtensionFunction: |
201 virtual bool RunImpl() OVERRIDE; | 184 virtual bool RunImpl() OVERRIDE; |
202 }; | 185 }; |
203 | 186 |
204 class BluetoothGetLocalOutOfBandPairingDataFunction | 187 class BluetoothGetLocalOutOfBandPairingDataFunction |
205 : public AsyncExtensionFunction { | 188 : public AsyncExtensionFunction { |
206 public: | 189 public: |
207 DECLARE_EXTENSION_FUNCTION_NAME( | 190 DECLARE_EXTENSION_FUNCTION_NAME( |
208 "experimental.bluetooth.getLocalOutOfBandPairingData") | 191 "experimental.bluetooth.getLocalOutOfBandPairingData") |
209 | 192 |
210 protected: | 193 protected: |
211 virtual ~BluetoothGetLocalOutOfBandPairingDataFunction() {} | 194 virtual ~BluetoothGetLocalOutOfBandPairingDataFunction() {} |
212 | 195 |
213 #if defined(OS_CHROMEOS) | 196 void ReadCallback( |
214 void ReadCallback(const chromeos::BluetoothOutOfBandPairingData& data); | 197 const bluetooth::BluetoothOutOfBandPairingData& data); |
215 void ErrorCallback(); | 198 void ErrorCallback(); |
216 #endif | |
217 | 199 |
218 // ExtensionFunction: | 200 // ExtensionFunction: |
219 virtual bool RunImpl() OVERRIDE; | 201 virtual bool RunImpl() OVERRIDE; |
220 }; | 202 }; |
221 | 203 |
222 class BluetoothStartDiscoveryFunction : public AsyncExtensionFunction { | 204 class BluetoothStartDiscoveryFunction : public AsyncExtensionFunction { |
223 public: | 205 public: |
224 DECLARE_EXTENSION_FUNCTION_NAME("experimental.bluetooth.startDiscovery") | 206 DECLARE_EXTENSION_FUNCTION_NAME("experimental.bluetooth.startDiscovery") |
225 | 207 |
226 protected: | 208 protected: |
227 virtual ~BluetoothStartDiscoveryFunction() {} | 209 virtual ~BluetoothStartDiscoveryFunction() {} |
228 | 210 |
229 // ExtensionFunction: | 211 // ExtensionFunction: |
230 virtual bool RunImpl() OVERRIDE; | 212 virtual bool RunImpl() OVERRIDE; |
231 | 213 |
232 #if defined(OS_CHROMEOS) | |
233 private: | 214 private: |
234 void OnSuccessCallback(); | 215 void OnSuccessCallback(); |
235 void OnErrorCallback(); | 216 void OnErrorCallback(); |
236 #endif | |
237 }; | 217 }; |
238 | 218 |
239 class BluetoothStopDiscoveryFunction : public AsyncExtensionFunction { | 219 class BluetoothStopDiscoveryFunction : public AsyncExtensionFunction { |
240 public: | 220 public: |
241 DECLARE_EXTENSION_FUNCTION_NAME("experimental.bluetooth.stopDiscovery") | 221 DECLARE_EXTENSION_FUNCTION_NAME("experimental.bluetooth.stopDiscovery") |
242 | 222 |
243 protected: | 223 protected: |
244 virtual ~BluetoothStopDiscoveryFunction() {} | 224 virtual ~BluetoothStopDiscoveryFunction() {} |
245 | 225 |
246 // ExtensionFunction: | 226 // ExtensionFunction: |
247 virtual bool RunImpl() OVERRIDE; | 227 virtual bool RunImpl() OVERRIDE; |
248 | 228 |
249 #if defined(OS_CHROMEOS) | |
250 private: | 229 private: |
251 void OnSuccessCallback(); | 230 void OnSuccessCallback(); |
252 void OnErrorCallback(); | 231 void OnErrorCallback(); |
253 #endif | |
254 }; | 232 }; |
255 | 233 |
256 } // namespace api | 234 } // namespace api |
257 } // namespace extensions | 235 } // namespace extensions |
258 | 236 |
259 #endif // CHROME_BROWSER_EXTENSIONS_API_BLUETOOTH_BLUETOOTH_API_H_ | 237 #endif // CHROME_BROWSER_EXTENSIONS_API_BLUETOOTH_BLUETOOTH_API_H_ |
OLD | NEW |