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), |
| 264 base::Bind(&base::DoNothing)); |
| 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 1169 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 |