| OLD | NEW |
| 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 EXTENSIONS_BROWSER_API_BLUETOOTH_SOCKET_BLUETOOTH_SOCKET_API_H_ | 5 #ifndef EXTENSIONS_BROWSER_API_BLUETOOTH_SOCKET_BLUETOOTH_SOCKET_API_H_ |
| 6 #define EXTENSIONS_BROWSER_API_BLUETOOTH_SOCKET_BLUETOOTH_SOCKET_API_H_ | 6 #define EXTENSIONS_BROWSER_API_BLUETOOTH_SOCKET_BLUETOOTH_SOCKET_API_H_ |
| 7 | 7 |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 | 9 |
| 10 #include <memory> |
| 10 #include <string> | 11 #include <string> |
| 11 | 12 |
| 12 #include "base/containers/hash_tables.h" | 13 #include "base/containers/hash_tables.h" |
| 13 #include "base/memory/ref_counted.h" | 14 #include "base/memory/ref_counted.h" |
| 14 #include "base/memory/scoped_ptr.h" | |
| 15 #include "device/bluetooth/bluetooth_adapter.h" | 15 #include "device/bluetooth/bluetooth_adapter.h" |
| 16 #include "extensions/browser/api/api_resource_manager.h" | 16 #include "extensions/browser/api/api_resource_manager.h" |
| 17 #include "extensions/browser/api/async_api_function.h" | 17 #include "extensions/browser/api/async_api_function.h" |
| 18 #include "extensions/browser/api/bluetooth_socket/bluetooth_api_socket.h" | 18 #include "extensions/browser/api/bluetooth_socket/bluetooth_api_socket.h" |
| 19 #include "extensions/browser/extension_function.h" | 19 #include "extensions/browser/extension_function.h" |
| 20 #include "extensions/browser/extension_function_histogram_value.h" | 20 #include "extensions/browser/extension_function_histogram_value.h" |
| 21 #include "extensions/common/api/bluetooth_socket.h" | 21 #include "extensions/common/api/bluetooth_socket.h" |
| 22 | 22 |
| 23 namespace device { | 23 namespace device { |
| 24 class BluetoothSocket; | 24 class BluetoothSocket; |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 74 BluetoothSocketCreateFunction(); | 74 BluetoothSocketCreateFunction(); |
| 75 | 75 |
| 76 protected: | 76 protected: |
| 77 ~BluetoothSocketCreateFunction() override; | 77 ~BluetoothSocketCreateFunction() override; |
| 78 | 78 |
| 79 // BluetoothSocketAsyncApiFunction: | 79 // BluetoothSocketAsyncApiFunction: |
| 80 bool Prepare() override; | 80 bool Prepare() override; |
| 81 void Work() override; | 81 void Work() override; |
| 82 | 82 |
| 83 private: | 83 private: |
| 84 scoped_ptr<bluetooth_socket::Create::Params> params_; | 84 std::unique_ptr<bluetooth_socket::Create::Params> params_; |
| 85 }; | 85 }; |
| 86 | 86 |
| 87 class BluetoothSocketUpdateFunction : public BluetoothSocketAsyncApiFunction { | 87 class BluetoothSocketUpdateFunction : public BluetoothSocketAsyncApiFunction { |
| 88 public: | 88 public: |
| 89 DECLARE_EXTENSION_FUNCTION("bluetoothSocket.update", BLUETOOTHSOCKET_UPDATE); | 89 DECLARE_EXTENSION_FUNCTION("bluetoothSocket.update", BLUETOOTHSOCKET_UPDATE); |
| 90 | 90 |
| 91 BluetoothSocketUpdateFunction(); | 91 BluetoothSocketUpdateFunction(); |
| 92 | 92 |
| 93 protected: | 93 protected: |
| 94 ~BluetoothSocketUpdateFunction() override; | 94 ~BluetoothSocketUpdateFunction() override; |
| 95 | 95 |
| 96 // BluetoothSocketAsyncApiFunction: | 96 // BluetoothSocketAsyncApiFunction: |
| 97 bool Prepare() override; | 97 bool Prepare() override; |
| 98 void Work() override; | 98 void Work() override; |
| 99 | 99 |
| 100 private: | 100 private: |
| 101 scoped_ptr<bluetooth_socket::Update::Params> params_; | 101 std::unique_ptr<bluetooth_socket::Update::Params> params_; |
| 102 }; | 102 }; |
| 103 | 103 |
| 104 class BluetoothSocketSetPausedFunction | 104 class BluetoothSocketSetPausedFunction |
| 105 : public BluetoothSocketAsyncApiFunction { | 105 : public BluetoothSocketAsyncApiFunction { |
| 106 public: | 106 public: |
| 107 DECLARE_EXTENSION_FUNCTION("bluetoothSocket.setPaused", | 107 DECLARE_EXTENSION_FUNCTION("bluetoothSocket.setPaused", |
| 108 BLUETOOTHSOCKET_SETPAUSED); | 108 BLUETOOTHSOCKET_SETPAUSED); |
| 109 | 109 |
| 110 BluetoothSocketSetPausedFunction(); | 110 BluetoothSocketSetPausedFunction(); |
| 111 | 111 |
| 112 protected: | 112 protected: |
| 113 ~BluetoothSocketSetPausedFunction() override; | 113 ~BluetoothSocketSetPausedFunction() override; |
| 114 | 114 |
| 115 // BluetoothSocketAsyncApiFunction: | 115 // BluetoothSocketAsyncApiFunction: |
| 116 bool Prepare() override; | 116 bool Prepare() override; |
| 117 void Work() override; | 117 void Work() override; |
| 118 | 118 |
| 119 private: | 119 private: |
| 120 scoped_ptr<bluetooth_socket::SetPaused::Params> params_; | 120 std::unique_ptr<bluetooth_socket::SetPaused::Params> params_; |
| 121 BluetoothSocketEventDispatcher* socket_event_dispatcher_; | 121 BluetoothSocketEventDispatcher* socket_event_dispatcher_; |
| 122 }; | 122 }; |
| 123 | 123 |
| 124 class BluetoothSocketListenFunction : public BluetoothSocketAsyncApiFunction { | 124 class BluetoothSocketListenFunction : public BluetoothSocketAsyncApiFunction { |
| 125 public: | 125 public: |
| 126 BluetoothSocketListenFunction(); | 126 BluetoothSocketListenFunction(); |
| 127 | 127 |
| 128 virtual bool CreateParams() = 0; | 128 virtual bool CreateParams() = 0; |
| 129 virtual void CreateService( | 129 virtual void CreateService( |
| 130 scoped_refptr<device::BluetoothAdapter> adapter, | 130 scoped_refptr<device::BluetoothAdapter> adapter, |
| 131 const device::BluetoothUUID& uuid, | 131 const device::BluetoothUUID& uuid, |
| 132 scoped_ptr<std::string> name, | 132 std::unique_ptr<std::string> name, |
| 133 const device::BluetoothAdapter::CreateServiceCallback& callback, | 133 const device::BluetoothAdapter::CreateServiceCallback& callback, |
| 134 const device::BluetoothAdapter::CreateServiceErrorCallback& | 134 const device::BluetoothAdapter::CreateServiceErrorCallback& |
| 135 error_callback) = 0; | 135 error_callback) = 0; |
| 136 virtual void CreateResults() = 0; | 136 virtual void CreateResults() = 0; |
| 137 | 137 |
| 138 virtual int socket_id() const = 0; | 138 virtual int socket_id() const = 0; |
| 139 virtual const std::string& uuid() const = 0; | 139 virtual const std::string& uuid() const = 0; |
| 140 | 140 |
| 141 // BluetoothSocketAsyncApiFunction: | 141 // BluetoothSocketAsyncApiFunction: |
| 142 bool Prepare() override; | 142 bool Prepare() override; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 161 BluetoothSocketListenUsingRfcommFunction(); | 161 BluetoothSocketListenUsingRfcommFunction(); |
| 162 | 162 |
| 163 // BluetoothSocketListenFunction: | 163 // BluetoothSocketListenFunction: |
| 164 int socket_id() const override; | 164 int socket_id() const override; |
| 165 const std::string& uuid() const override; | 165 const std::string& uuid() const override; |
| 166 | 166 |
| 167 bool CreateParams() override; | 167 bool CreateParams() override; |
| 168 void CreateService( | 168 void CreateService( |
| 169 scoped_refptr<device::BluetoothAdapter> adapter, | 169 scoped_refptr<device::BluetoothAdapter> adapter, |
| 170 const device::BluetoothUUID& uuid, | 170 const device::BluetoothUUID& uuid, |
| 171 scoped_ptr<std::string> name, | 171 std::unique_ptr<std::string> name, |
| 172 const device::BluetoothAdapter::CreateServiceCallback& callback, | 172 const device::BluetoothAdapter::CreateServiceCallback& callback, |
| 173 const device::BluetoothAdapter::CreateServiceErrorCallback& | 173 const device::BluetoothAdapter::CreateServiceErrorCallback& |
| 174 error_callback) override; | 174 error_callback) override; |
| 175 void CreateResults() override; | 175 void CreateResults() override; |
| 176 | 176 |
| 177 protected: | 177 protected: |
| 178 ~BluetoothSocketListenUsingRfcommFunction() override; | 178 ~BluetoothSocketListenUsingRfcommFunction() override; |
| 179 | 179 |
| 180 private: | 180 private: |
| 181 scoped_ptr<bluetooth_socket::ListenUsingRfcomm::Params> params_; | 181 std::unique_ptr<bluetooth_socket::ListenUsingRfcomm::Params> params_; |
| 182 }; | 182 }; |
| 183 | 183 |
| 184 class BluetoothSocketListenUsingL2capFunction | 184 class BluetoothSocketListenUsingL2capFunction |
| 185 : public BluetoothSocketListenFunction { | 185 : public BluetoothSocketListenFunction { |
| 186 public: | 186 public: |
| 187 DECLARE_EXTENSION_FUNCTION("bluetoothSocket.listenUsingL2cap", | 187 DECLARE_EXTENSION_FUNCTION("bluetoothSocket.listenUsingL2cap", |
| 188 BLUETOOTHSOCKET_LISTENUSINGL2CAP); | 188 BLUETOOTHSOCKET_LISTENUSINGL2CAP); |
| 189 | 189 |
| 190 BluetoothSocketListenUsingL2capFunction(); | 190 BluetoothSocketListenUsingL2capFunction(); |
| 191 | 191 |
| 192 // BluetoothSocketListenFunction: | 192 // BluetoothSocketListenFunction: |
| 193 int socket_id() const override; | 193 int socket_id() const override; |
| 194 const std::string& uuid() const override; | 194 const std::string& uuid() const override; |
| 195 | 195 |
| 196 bool CreateParams() override; | 196 bool CreateParams() override; |
| 197 void CreateService( | 197 void CreateService( |
| 198 scoped_refptr<device::BluetoothAdapter> adapter, | 198 scoped_refptr<device::BluetoothAdapter> adapter, |
| 199 const device::BluetoothUUID& uuid, | 199 const device::BluetoothUUID& uuid, |
| 200 scoped_ptr<std::string> name, | 200 std::unique_ptr<std::string> name, |
| 201 const device::BluetoothAdapter::CreateServiceCallback& callback, | 201 const device::BluetoothAdapter::CreateServiceCallback& callback, |
| 202 const device::BluetoothAdapter::CreateServiceErrorCallback& | 202 const device::BluetoothAdapter::CreateServiceErrorCallback& |
| 203 error_callback) override; | 203 error_callback) override; |
| 204 void CreateResults() override; | 204 void CreateResults() override; |
| 205 | 205 |
| 206 protected: | 206 protected: |
| 207 ~BluetoothSocketListenUsingL2capFunction() override; | 207 ~BluetoothSocketListenUsingL2capFunction() override; |
| 208 | 208 |
| 209 private: | 209 private: |
| 210 scoped_ptr<bluetooth_socket::ListenUsingL2cap::Params> params_; | 210 std::unique_ptr<bluetooth_socket::ListenUsingL2cap::Params> params_; |
| 211 }; | 211 }; |
| 212 | 212 |
| 213 class BluetoothSocketAbstractConnectFunction : | 213 class BluetoothSocketAbstractConnectFunction : |
| 214 public BluetoothSocketAsyncApiFunction { | 214 public BluetoothSocketAsyncApiFunction { |
| 215 public: | 215 public: |
| 216 BluetoothSocketAbstractConnectFunction(); | 216 BluetoothSocketAbstractConnectFunction(); |
| 217 | 217 |
| 218 protected: | 218 protected: |
| 219 ~BluetoothSocketAbstractConnectFunction() override; | 219 ~BluetoothSocketAbstractConnectFunction() override; |
| 220 | 220 |
| 221 // BluetoothSocketAsyncApiFunction: | 221 // BluetoothSocketAsyncApiFunction: |
| 222 bool Prepare() override; | 222 bool Prepare() override; |
| 223 void AsyncWorkStart() override; | 223 void AsyncWorkStart() override; |
| 224 | 224 |
| 225 // Subclasses should implement this method to connect to the service | 225 // Subclasses should implement this method to connect to the service |
| 226 // registered with |uuid| on the |device|. | 226 // registered with |uuid| on the |device|. |
| 227 virtual void ConnectToService(device::BluetoothDevice* device, | 227 virtual void ConnectToService(device::BluetoothDevice* device, |
| 228 const device::BluetoothUUID& uuid) = 0; | 228 const device::BluetoothUUID& uuid) = 0; |
| 229 | 229 |
| 230 virtual void OnConnect(scoped_refptr<device::BluetoothSocket> socket); | 230 virtual void OnConnect(scoped_refptr<device::BluetoothSocket> socket); |
| 231 virtual void OnConnectError(const std::string& message); | 231 virtual void OnConnectError(const std::string& message); |
| 232 | 232 |
| 233 private: | 233 private: |
| 234 virtual void OnGetAdapter(scoped_refptr<device::BluetoothAdapter> adapter); | 234 virtual void OnGetAdapter(scoped_refptr<device::BluetoothAdapter> adapter); |
| 235 | 235 |
| 236 scoped_ptr<bluetooth_socket::Connect::Params> params_; | 236 std::unique_ptr<bluetooth_socket::Connect::Params> params_; |
| 237 BluetoothSocketEventDispatcher* socket_event_dispatcher_; | 237 BluetoothSocketEventDispatcher* socket_event_dispatcher_; |
| 238 }; | 238 }; |
| 239 | 239 |
| 240 class BluetoothSocketConnectFunction : | 240 class BluetoothSocketConnectFunction : |
| 241 public BluetoothSocketAbstractConnectFunction { | 241 public BluetoothSocketAbstractConnectFunction { |
| 242 public: | 242 public: |
| 243 DECLARE_EXTENSION_FUNCTION("bluetoothSocket.connect", | 243 DECLARE_EXTENSION_FUNCTION("bluetoothSocket.connect", |
| 244 BLUETOOTHSOCKET_CONNECT); | 244 BLUETOOTHSOCKET_CONNECT); |
| 245 | 245 |
| 246 BluetoothSocketConnectFunction(); | 246 BluetoothSocketConnectFunction(); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 264 protected: | 264 protected: |
| 265 ~BluetoothSocketDisconnectFunction() override; | 265 ~BluetoothSocketDisconnectFunction() override; |
| 266 | 266 |
| 267 // BluetoothSocketAsyncApiFunction: | 267 // BluetoothSocketAsyncApiFunction: |
| 268 bool Prepare() override; | 268 bool Prepare() override; |
| 269 void AsyncWorkStart() override; | 269 void AsyncWorkStart() override; |
| 270 | 270 |
| 271 private: | 271 private: |
| 272 virtual void OnSuccess(); | 272 virtual void OnSuccess(); |
| 273 | 273 |
| 274 scoped_ptr<bluetooth_socket::Disconnect::Params> params_; | 274 std::unique_ptr<bluetooth_socket::Disconnect::Params> params_; |
| 275 }; | 275 }; |
| 276 | 276 |
| 277 class BluetoothSocketCloseFunction : public BluetoothSocketAsyncApiFunction { | 277 class BluetoothSocketCloseFunction : public BluetoothSocketAsyncApiFunction { |
| 278 public: | 278 public: |
| 279 DECLARE_EXTENSION_FUNCTION("bluetoothSocket.close", BLUETOOTHSOCKET_CLOSE); | 279 DECLARE_EXTENSION_FUNCTION("bluetoothSocket.close", BLUETOOTHSOCKET_CLOSE); |
| 280 | 280 |
| 281 BluetoothSocketCloseFunction(); | 281 BluetoothSocketCloseFunction(); |
| 282 | 282 |
| 283 protected: | 283 protected: |
| 284 ~BluetoothSocketCloseFunction() override; | 284 ~BluetoothSocketCloseFunction() override; |
| 285 | 285 |
| 286 // BluetoothSocketAsyncApiFunction: | 286 // BluetoothSocketAsyncApiFunction: |
| 287 bool Prepare() override; | 287 bool Prepare() override; |
| 288 void Work() override; | 288 void Work() override; |
| 289 | 289 |
| 290 private: | 290 private: |
| 291 scoped_ptr<bluetooth_socket::Close::Params> params_; | 291 std::unique_ptr<bluetooth_socket::Close::Params> params_; |
| 292 }; | 292 }; |
| 293 | 293 |
| 294 class BluetoothSocketSendFunction : public BluetoothSocketAsyncApiFunction { | 294 class BluetoothSocketSendFunction : public BluetoothSocketAsyncApiFunction { |
| 295 public: | 295 public: |
| 296 DECLARE_EXTENSION_FUNCTION("bluetoothSocket.send", BLUETOOTHSOCKET_SEND); | 296 DECLARE_EXTENSION_FUNCTION("bluetoothSocket.send", BLUETOOTHSOCKET_SEND); |
| 297 | 297 |
| 298 BluetoothSocketSendFunction(); | 298 BluetoothSocketSendFunction(); |
| 299 | 299 |
| 300 protected: | 300 protected: |
| 301 ~BluetoothSocketSendFunction() override; | 301 ~BluetoothSocketSendFunction() override; |
| 302 | 302 |
| 303 // BluetoothSocketAsyncApiFunction: | 303 // BluetoothSocketAsyncApiFunction: |
| 304 bool Prepare() override; | 304 bool Prepare() override; |
| 305 void AsyncWorkStart() override; | 305 void AsyncWorkStart() override; |
| 306 | 306 |
| 307 private: | 307 private: |
| 308 void OnSuccess(int bytes_sent); | 308 void OnSuccess(int bytes_sent); |
| 309 void OnError(BluetoothApiSocket::ErrorReason reason, | 309 void OnError(BluetoothApiSocket::ErrorReason reason, |
| 310 const std::string& message); | 310 const std::string& message); |
| 311 | 311 |
| 312 scoped_ptr<bluetooth_socket::Send::Params> params_; | 312 std::unique_ptr<bluetooth_socket::Send::Params> params_; |
| 313 scoped_refptr<net::IOBuffer> io_buffer_; | 313 scoped_refptr<net::IOBuffer> io_buffer_; |
| 314 size_t io_buffer_size_; | 314 size_t io_buffer_size_; |
| 315 }; | 315 }; |
| 316 | 316 |
| 317 class BluetoothSocketGetInfoFunction : public BluetoothSocketAsyncApiFunction { | 317 class BluetoothSocketGetInfoFunction : public BluetoothSocketAsyncApiFunction { |
| 318 public: | 318 public: |
| 319 DECLARE_EXTENSION_FUNCTION("bluetoothSocket.getInfo", | 319 DECLARE_EXTENSION_FUNCTION("bluetoothSocket.getInfo", |
| 320 BLUETOOTHSOCKET_GETINFO); | 320 BLUETOOTHSOCKET_GETINFO); |
| 321 | 321 |
| 322 BluetoothSocketGetInfoFunction(); | 322 BluetoothSocketGetInfoFunction(); |
| 323 | 323 |
| 324 protected: | 324 protected: |
| 325 ~BluetoothSocketGetInfoFunction() override; | 325 ~BluetoothSocketGetInfoFunction() override; |
| 326 | 326 |
| 327 // BluetoothSocketAsyncApiFunction: | 327 // BluetoothSocketAsyncApiFunction: |
| 328 bool Prepare() override; | 328 bool Prepare() override; |
| 329 void Work() override; | 329 void Work() override; |
| 330 | 330 |
| 331 private: | 331 private: |
| 332 scoped_ptr<bluetooth_socket::GetInfo::Params> params_; | 332 std::unique_ptr<bluetooth_socket::GetInfo::Params> params_; |
| 333 }; | 333 }; |
| 334 | 334 |
| 335 class BluetoothSocketGetSocketsFunction | 335 class BluetoothSocketGetSocketsFunction |
| 336 : public BluetoothSocketAsyncApiFunction { | 336 : public BluetoothSocketAsyncApiFunction { |
| 337 public: | 337 public: |
| 338 DECLARE_EXTENSION_FUNCTION("bluetoothSocket.getSockets", | 338 DECLARE_EXTENSION_FUNCTION("bluetoothSocket.getSockets", |
| 339 BLUETOOTHSOCKET_GETSOCKETS); | 339 BLUETOOTHSOCKET_GETSOCKETS); |
| 340 | 340 |
| 341 BluetoothSocketGetSocketsFunction(); | 341 BluetoothSocketGetSocketsFunction(); |
| 342 | 342 |
| 343 protected: | 343 protected: |
| 344 ~BluetoothSocketGetSocketsFunction() override; | 344 ~BluetoothSocketGetSocketsFunction() override; |
| 345 | 345 |
| 346 // BluetoothSocketAsyncApiFunction: | 346 // BluetoothSocketAsyncApiFunction: |
| 347 bool Prepare() override; | 347 bool Prepare() override; |
| 348 void Work() override; | 348 void Work() override; |
| 349 }; | 349 }; |
| 350 | 350 |
| 351 } // namespace api | 351 } // namespace api |
| 352 } // namespace extensions | 352 } // namespace extensions |
| 353 | 353 |
| 354 #endif // EXTENSIONS_BROWSER_API_BLUETOOTH_SOCKET_BLUETOOTH_SOCKET_API_H_ | 354 #endif // EXTENSIONS_BROWSER_API_BLUETOOTH_SOCKET_BLUETOOTH_SOCKET_API_H_ |
| OLD | NEW |