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