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