| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 #include "device/bluetooth/bluetooth_socket_chromeos.h" | 5 #include "device/bluetooth/bluetooth_socket_chromeos.h" |
| 6 | 6 |
| 7 #include <queue> | 7 #include <queue> |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 79 scoped_refptr<base::SequencedTaskRunner> ui_task_runner, | 79 scoped_refptr<base::SequencedTaskRunner> ui_task_runner, |
| 80 scoped_refptr<BluetoothSocketThread> socket_thread) | 80 scoped_refptr<BluetoothSocketThread> socket_thread) |
| 81 : BluetoothSocketNet(ui_task_runner, socket_thread), profile_(nullptr) { | 81 : BluetoothSocketNet(ui_task_runner, socket_thread), profile_(nullptr) { |
| 82 } | 82 } |
| 83 | 83 |
| 84 BluetoothSocketChromeOS::~BluetoothSocketChromeOS() { | 84 BluetoothSocketChromeOS::~BluetoothSocketChromeOS() { |
| 85 DCHECK(!profile_); | 85 DCHECK(!profile_); |
| 86 | 86 |
| 87 if (adapter_.get()) { | 87 if (adapter_.get()) { |
| 88 adapter_->RemoveObserver(this); | 88 adapter_->RemoveObserver(this); |
| 89 adapter_ = NULL; | 89 adapter_ = nullptr; |
| 90 } | 90 } |
| 91 } | 91 } |
| 92 | 92 |
| 93 void BluetoothSocketChromeOS::Connect( | 93 void BluetoothSocketChromeOS::Connect( |
| 94 const BluetoothDeviceChromeOS* device, | 94 const BluetoothDeviceChromeOS* device, |
| 95 const BluetoothUUID& uuid, | 95 const BluetoothUUID& uuid, |
| 96 SecurityLevel security_level, | 96 SecurityLevel security_level, |
| 97 const base::Closure& success_callback, | 97 const base::Closure& success_callback, |
| 98 const ErrorCompletionCallback& error_callback) { | 98 const ErrorCompletionCallback& error_callback) { |
| 99 DCHECK(ui_task_runner()->RunsTasksOnCurrentThread()); | 99 DCHECK(ui_task_runner()->RunsTasksOnCurrentThread()); |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 161 | 161 |
| 162 if (profile_) | 162 if (profile_) |
| 163 UnregisterProfile(); | 163 UnregisterProfile(); |
| 164 | 164 |
| 165 // In the case below, where an asynchronous task gets posted on the socket | 165 // In the case below, where an asynchronous task gets posted on the socket |
| 166 // thread in BluetoothSocketNet::Close, a reference will be held to this | 166 // thread in BluetoothSocketNet::Close, a reference will be held to this |
| 167 // socket by the callback. This may cause the BluetoothAdapter to outlive | 167 // socket by the callback. This may cause the BluetoothAdapter to outlive |
| 168 // DBusThreadManager during shutdown if that callback executes too late. | 168 // DBusThreadManager during shutdown if that callback executes too late. |
| 169 if (adapter_.get()) { | 169 if (adapter_.get()) { |
| 170 adapter_->RemoveObserver(this); | 170 adapter_->RemoveObserver(this); |
| 171 adapter_ = NULL; | 171 adapter_ = nullptr; |
| 172 } | 172 } |
| 173 | 173 |
| 174 if (!device_path_.value().empty()) { | 174 if (!device_path_.value().empty()) { |
| 175 BluetoothSocketNet::Close(); | 175 BluetoothSocketNet::Close(); |
| 176 } else { | 176 } else { |
| 177 DoCloseListening(); | 177 DoCloseListening(); |
| 178 } | 178 } |
| 179 } | 179 } |
| 180 | 180 |
| 181 void BluetoothSocketChromeOS::Disconnect(const base::Closure& callback) { | 181 void BluetoothSocketChromeOS::Disconnect(const base::Closure& callback) { |
| 182 DCHECK(ui_task_runner()->RunsTasksOnCurrentThread()); | 182 DCHECK(ui_task_runner()->RunsTasksOnCurrentThread()); |
| 183 | 183 |
| 184 if (profile_) | 184 if (profile_) |
| 185 UnregisterProfile(); | 185 UnregisterProfile(); |
| 186 | 186 |
| 187 if (!device_path_.value().empty()) { | 187 if (!device_path_.value().empty()) { |
| 188 BluetoothSocketNet::Disconnect(callback); | 188 BluetoothSocketNet::Disconnect(callback); |
| 189 } else { | 189 } else { |
| 190 DoCloseListening(); | 190 DoCloseListening(); |
| 191 callback.Run(); | 191 callback.Run(); |
| 192 } | 192 } |
| 193 } | 193 } |
| 194 | 194 |
| 195 void BluetoothSocketChromeOS::Accept( | 195 void BluetoothSocketChromeOS::Accept( |
| (...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 516 BluetoothDeviceChromeOS* device = | 516 BluetoothDeviceChromeOS* device = |
| 517 static_cast<BluetoothAdapterChromeOS*>(adapter_.get())-> | 517 static_cast<BluetoothAdapterChromeOS*>(adapter_.get())-> |
| 518 GetDeviceWithPath(request->device_path); | 518 GetDeviceWithPath(request->device_path); |
| 519 DCHECK(device); | 519 DCHECK(device); |
| 520 | 520 |
| 521 accept_request_->success_callback.Run(device, socket); | 521 accept_request_->success_callback.Run(device, socket); |
| 522 } else { | 522 } else { |
| 523 accept_request_->error_callback.Run(kAcceptFailed); | 523 accept_request_->error_callback.Run(kAcceptFailed); |
| 524 } | 524 } |
| 525 | 525 |
| 526 accept_request_.reset(NULL); | 526 accept_request_.reset(nullptr); |
| 527 connection_request_queue_.pop(); | 527 connection_request_queue_.pop(); |
| 528 | 528 |
| 529 callback.Run(status); | 529 callback.Run(status); |
| 530 } | 530 } |
| 531 | 531 |
| 532 void BluetoothSocketChromeOS::DoCloseListening() { | 532 void BluetoothSocketChromeOS::DoCloseListening() { |
| 533 DCHECK(ui_task_runner()->RunsTasksOnCurrentThread()); | 533 DCHECK(ui_task_runner()->RunsTasksOnCurrentThread()); |
| 534 | 534 |
| 535 if (accept_request_) { | 535 if (accept_request_) { |
| 536 accept_request_->error_callback.Run( | 536 accept_request_->error_callback.Run( |
| 537 net::ErrorToString(net::ERR_CONNECTION_CLOSED)); | 537 net::ErrorToString(net::ERR_CONNECTION_CLOSED)); |
| 538 accept_request_.reset(NULL); | 538 accept_request_.reset(nullptr); |
| 539 } | 539 } |
| 540 | 540 |
| 541 while (connection_request_queue_.size() > 0) { | 541 while (connection_request_queue_.size() > 0) { |
| 542 linked_ptr<ConnectionRequest> request = connection_request_queue_.front(); | 542 linked_ptr<ConnectionRequest> request = connection_request_queue_.front(); |
| 543 request->callback.Run(REJECTED); | 543 request->callback.Run(REJECTED); |
| 544 connection_request_queue_.pop(); | 544 connection_request_queue_.pop(); |
| 545 } | 545 } |
| 546 } | 546 } |
| 547 | 547 |
| 548 void BluetoothSocketChromeOS::UnregisterProfile() { | 548 void BluetoothSocketChromeOS::UnregisterProfile() { |
| 549 DCHECK(ui_task_runner()->RunsTasksOnCurrentThread()); | 549 DCHECK(ui_task_runner()->RunsTasksOnCurrentThread()); |
| 550 DCHECK(profile_); | 550 DCHECK(profile_); |
| 551 | 551 |
| 552 VLOG(1) << profile_->object_path().value() << ": Release profile"; | 552 VLOG(1) << profile_->object_path().value() << ": Release profile"; |
| 553 | 553 |
| 554 static_cast<BluetoothAdapterChromeOS*>(adapter_.get()) | 554 static_cast<BluetoothAdapterChromeOS*>(adapter_.get()) |
| 555 ->ReleaseProfile(device_path_, profile_); | 555 ->ReleaseProfile(device_path_, profile_); |
| 556 profile_ = nullptr; | 556 profile_ = nullptr; |
| 557 } | 557 } |
| 558 | 558 |
| 559 } // namespace chromeos | 559 } // namespace chromeos |
| OLD | NEW |