| Index: chrome/browser/extensions/api/bluetooth/bluetooth_api_socket.cc
|
| diff --git a/chrome/browser/extensions/api/bluetooth/bluetooth_api_socket.cc b/chrome/browser/extensions/api/bluetooth/bluetooth_api_socket.cc
|
| index b33c635d8313fcdb304a43746ad8fa436d49e21f..f549354bd4db2d7517646df6d5b1f2bb8dfb74df 100644
|
| --- a/chrome/browser/extensions/api/bluetooth/bluetooth_api_socket.cc
|
| +++ b/chrome/browser/extensions/api/bluetooth/bluetooth_api_socket.cc
|
| @@ -10,6 +10,7 @@
|
| namespace {
|
|
|
| const char kSocketNotConnectedError[] = "Socket not connected";
|
| +const char kSocketNotListeningError[] = "Socket not listening";
|
|
|
| } // namespace
|
|
|
| @@ -73,15 +74,30 @@ void BluetoothApiSocket::AdoptConnectedSocket(
|
| connected_ = true;
|
| }
|
|
|
| -void BluetoothApiSocket::Disconnect(const base::Closure& success_callback) {
|
| +void BluetoothApiSocket::AdoptListeningSocket(
|
| + scoped_refptr<device::BluetoothSocket> socket,
|
| + const device::BluetoothUUID& uuid) {
|
| DCHECK(content::BrowserThread::CurrentlyOn(kThreadId));
|
|
|
| - if (!socket_.get() || !IsConnected()) {
|
| - success_callback.Run();
|
| + if (socket_.get())
|
| + socket_->Close();
|
| +
|
| + socket_ = socket;
|
| + device_address_ = "";
|
| + uuid_ = uuid;
|
| + connected_ = false;
|
| +}
|
| +
|
| +void BluetoothApiSocket::Disconnect(const base::Closure& callback) {
|
| + DCHECK(content::BrowserThread::CurrentlyOn(kThreadId));
|
| +
|
| + if (!socket_.get()) {
|
| + callback.Run();
|
| return;
|
| }
|
|
|
| - socket_->Disconnect(success_callback);
|
| + connected_ = false;
|
| + socket_->Disconnect(callback);
|
| }
|
|
|
| bool BluetoothApiSocket::IsPersistent() const {
|
| @@ -153,7 +169,29 @@ void BluetoothApiSocket::OnSocketSendError(
|
| const std::string& message) {
|
| DCHECK(content::BrowserThread::CurrentlyOn(kThreadId));
|
| error_callback.Run(BluetoothApiSocket::kSystemError, message);
|
| +}
|
|
|
| +void BluetoothApiSocket::Accept(
|
| + const AcceptCompletionCallback& success_callback,
|
| + const ErrorCompletionCallback& error_callback) {
|
| + DCHECK(content::BrowserThread::CurrentlyOn(kThreadId));
|
| +
|
| + if (!socket_.get() || IsConnected()) {
|
| + error_callback.Run(BluetoothApiSocket::kNotListening,
|
| + kSocketNotListeningError);
|
| + return;
|
| + }
|
| +
|
| + socket_->Accept(success_callback,
|
| + base::Bind(&OnSocketAcceptError, error_callback));
|
| +}
|
| +
|
| +// static
|
| +void BluetoothApiSocket::OnSocketAcceptError(
|
| + const ErrorCompletionCallback& error_callback,
|
| + const std::string& message) {
|
| + DCHECK(content::BrowserThread::CurrentlyOn(kThreadId));
|
| + error_callback.Run(BluetoothApiSocket::kSystemError, message);
|
| }
|
|
|
| } // namespace extensions
|
|
|