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_adapter_bluez.h" | 5 #include "device/bluetooth/bluetooth_adapter_bluez.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
146 base::Bind(&OnUnregisterAgentError)); | 146 base::Bind(&OnUnregisterAgentError)); |
147 | 147 |
148 agent_.reset(); | 148 agent_.reset(); |
149 dbus_is_shutdown_ = true; | 149 dbus_is_shutdown_ = true; |
150 } | 150 } |
151 | 151 |
152 BluetoothAdapterBlueZ::BluetoothAdapterBlueZ(const InitCallback& init_callback) | 152 BluetoothAdapterBlueZ::BluetoothAdapterBlueZ(const InitCallback& init_callback) |
153 : init_callback_(init_callback), | 153 : init_callback_(init_callback), |
154 initialized_(false), | 154 initialized_(false), |
155 dbus_is_shutdown_(false), | 155 dbus_is_shutdown_(false), |
156 is_disabled_(false), | |
156 num_discovery_sessions_(0), | 157 num_discovery_sessions_(0), |
157 discovery_request_pending_(false), | 158 discovery_request_pending_(false), |
158 weak_ptr_factory_(this) { | 159 weak_ptr_factory_(this) { |
159 ui_task_runner_ = base::ThreadTaskRunnerHandle::Get(); | 160 ui_task_runner_ = base::ThreadTaskRunnerHandle::Get(); |
160 socket_thread_ = device::BluetoothSocketThread::Get(); | 161 socket_thread_ = device::BluetoothSocketThread::Get(); |
161 | 162 |
162 // Can't initialize the adapter until DBus clients are ready. | 163 // Can't initialize the adapter until DBus clients are ready. |
163 if (bluez::BluezDBusManager::Get()->IsObjectManagerSupportKnown()) { | 164 if (bluez::BluezDBusManager::Get()->IsObjectManagerSupportKnown()) { |
164 base::ThreadTaskRunnerHandle::Get()->PostTask( | 165 base::ThreadTaskRunnerHandle::Get()->PostTask( |
165 FROM_HERE, base::Bind(&BluetoothAdapterBlueZ::Init, | 166 FROM_HERE, base::Bind(&BluetoothAdapterBlueZ::Init, |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
247 name, | 248 name, |
248 base::Bind(&BluetoothAdapterBlueZ::OnPropertyChangeCompleted, | 249 base::Bind(&BluetoothAdapterBlueZ::OnPropertyChangeCompleted, |
249 weak_ptr_factory_.GetWeakPtr(), callback, error_callback)); | 250 weak_ptr_factory_.GetWeakPtr(), callback, error_callback)); |
250 } | 251 } |
251 | 252 |
252 bool BluetoothAdapterBlueZ::IsInitialized() const { | 253 bool BluetoothAdapterBlueZ::IsInitialized() const { |
253 return initialized_; | 254 return initialized_; |
254 } | 255 } |
255 | 256 |
256 bool BluetoothAdapterBlueZ::IsPresent() const { | 257 bool BluetoothAdapterBlueZ::IsPresent() const { |
257 return !dbus_is_shutdown_ && !object_path_.value().empty(); | 258 return !is_disabled_ && !dbus_is_shutdown_ && !object_path_.value().empty(); |
259 } | |
260 | |
261 void BluetoothAdapterBlueZ::SetDisabled(bool disabled) { | |
262 if (disabled) { | |
263 SetPowered(false, base::Bind(&base::DoNothing), | |
Andrew T Wilson (Slow)
2016/04/13 13:55:11
I am slightly nervous that any operations that are
Ivan Šandrk
2016/04/14 18:08:47
https://code.google.com/p/chromium/codesearch#chro
scheib
2016/04/15 17:46:53
At shutdown we believe things won't crash -- handl
Ivan Šandrk
2016/04/15 17:52:28
Okay thanks for your input. I'll ask my supervisor
| |
264 base::Bind(&base::DoNothing)); | |
Andrew T Wilson (Slow)
2016/04/13 13:55:11
This line is indented wrong.
Ivan Šandrk
2016/04/13 17:19:04
Done.
| |
265 } | |
266 is_disabled_ = disabled; | |
258 } | 267 } |
259 | 268 |
260 bool BluetoothAdapterBlueZ::IsPowered() const { | 269 bool BluetoothAdapterBlueZ::IsPowered() const { |
261 if (!IsPresent()) | 270 if (!IsPresent()) |
262 return false; | 271 return false; |
263 | 272 |
264 bluez::BluetoothAdapterClient::Properties* properties = | 273 bluez::BluetoothAdapterClient::Properties* properties = |
265 bluez::BluezDBusManager::Get() | 274 bluez::BluezDBusManager::Get() |
266 ->GetBluetoothAdapterClient() | 275 ->GetBluetoothAdapterClient() |
267 ->GetProperties(object_path_); | 276 ->GetProperties(object_path_); |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
326 ->GetProperties(object_path_); | 335 ->GetProperties(object_path_); |
327 | 336 |
328 return properties->discovering.value(); | 337 return properties->discovering.value(); |
329 } | 338 } |
330 | 339 |
331 void BluetoothAdapterBlueZ::CreateRfcommService( | 340 void BluetoothAdapterBlueZ::CreateRfcommService( |
332 const BluetoothUUID& uuid, | 341 const BluetoothUUID& uuid, |
333 const ServiceOptions& options, | 342 const ServiceOptions& options, |
334 const CreateServiceCallback& callback, | 343 const CreateServiceCallback& callback, |
335 const CreateServiceErrorCallback& error_callback) { | 344 const CreateServiceErrorCallback& error_callback) { |
336 DCHECK(!dbus_is_shutdown_); | 345 DCHECK(!dbus_is_shutdown_); |
Andrew T Wilson (Slow)
2016/04/13 13:55:11
Should this (and code below) also be checking if t
Ivan Šandrk
2016/04/14 18:08:47
That's a very good point.
Bluetooth guys, what do
| |
337 VLOG(1) << object_path_.value() | 346 VLOG(1) << object_path_.value() |
338 << ": Creating RFCOMM service: " << uuid.canonical_value(); | 347 << ": Creating RFCOMM service: " << uuid.canonical_value(); |
339 scoped_refptr<BluetoothSocketBlueZ> socket = | 348 scoped_refptr<BluetoothSocketBlueZ> socket = |
340 BluetoothSocketBlueZ::CreateBluetoothSocket(ui_task_runner_, | 349 BluetoothSocketBlueZ::CreateBluetoothSocket(ui_task_runner_, |
341 socket_thread_); | 350 socket_thread_); |
342 socket->Listen(this, BluetoothSocketBlueZ::kRfcomm, uuid, options, | 351 socket->Listen(this, BluetoothSocketBlueZ::kRfcomm, uuid, options, |
343 base::Bind(callback, socket), error_callback); | 352 base::Bind(callback, socket), error_callback); |
344 } | 353 } |
345 | 354 |
346 void BluetoothAdapterBlueZ::CreateL2capService( | 355 void BluetoothAdapterBlueZ::CreateL2capService( |
(...skipping 1090 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1437 | 1446 |
1438 // If the queued request resulted in a pending call, then let it | 1447 // If the queued request resulted in a pending call, then let it |
1439 // asynchonously process the remaining queued requests once the pending | 1448 // asynchonously process the remaining queued requests once the pending |
1440 // call returns. | 1449 // call returns. |
1441 if (discovery_request_pending_) | 1450 if (discovery_request_pending_) |
1442 return; | 1451 return; |
1443 } | 1452 } |
1444 } | 1453 } |
1445 | 1454 |
1446 } // namespace bluez | 1455 } // namespace bluez |
OLD | NEW |