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/bluez/bluetooth_adapter_bluez.h" | 5 #include "device/bluetooth/bluez/bluetooth_adapter_bluez.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <cstdint> | 8 #include <cstdint> |
9 #include <limits> | 9 #include <limits> |
10 #include <memory> | 10 #include <memory> |
11 #include <set> | 11 #include <set> |
12 #include <string> | 12 #include <string> |
13 #include <utility> | 13 #include <utility> |
14 | 14 |
15 #include "base/bind.h" | 15 #include "base/bind.h" |
16 #include "base/location.h" | 16 #include "base/location.h" |
17 #include "base/logging.h" | 17 #include "base/logging.h" |
18 #include "base/memory/ptr_util.h" | 18 #include "base/memory/ptr_util.h" |
19 #include "base/metrics/histogram_macros.h" | 19 #include "base/metrics/histogram_macros.h" |
20 #include "base/sequenced_task_runner.h" | 20 #include "base/sequenced_task_runner.h" |
21 #include "base/single_thread_task_runner.h" | 21 #include "base/single_thread_task_runner.h" |
22 #include "base/strings/stringprintf.h" | 22 #include "base/strings/stringprintf.h" |
23 #include "base/threading/thread_task_runner_handle.h" | 23 #include "base/threading/thread_task_runner_handle.h" |
24 #include "base/time/time.h" | 24 #include "base/time/time.h" |
25 #include "build/build_config.h" | 25 #include "build/build_config.h" |
| 26 #include "components/device_event_log/device_event_log.h" |
26 #include "device/bluetooth/bluetooth_common.h" | 27 #include "device/bluetooth/bluetooth_common.h" |
27 #include "device/bluetooth/bluetooth_device.h" | 28 #include "device/bluetooth/bluetooth_device.h" |
28 #include "device/bluetooth/bluetooth_discovery_session_outcome.h" | 29 #include "device/bluetooth/bluetooth_discovery_session_outcome.h" |
29 #include "device/bluetooth/bluetooth_socket_thread.h" | 30 #include "device/bluetooth/bluetooth_socket_thread.h" |
30 #include "device/bluetooth/bluetooth_uuid.h" | 31 #include "device/bluetooth/bluetooth_uuid.h" |
31 #include "device/bluetooth/bluez/bluetooth_adapter_profile_bluez.h" | 32 #include "device/bluetooth/bluez/bluetooth_adapter_profile_bluez.h" |
32 #include "device/bluetooth/bluez/bluetooth_advertisement_bluez.h" | 33 #include "device/bluetooth/bluez/bluetooth_advertisement_bluez.h" |
33 #include "device/bluetooth/bluez/bluetooth_device_bluez.h" | 34 #include "device/bluetooth/bluez/bluetooth_device_bluez.h" |
34 #include "device/bluetooth/bluez/bluetooth_gatt_service_bluez.h" | 35 #include "device/bluetooth/bluez/bluetooth_gatt_service_bluez.h" |
35 #include "device/bluetooth/bluez/bluetooth_local_gatt_characteristic_bluez.h" | 36 #include "device/bluetooth/bluez/bluetooth_local_gatt_characteristic_bluez.h" |
(...skipping 29 matching lines...) Expand all Loading... |
65 // exist per D-Bus connection, it just has to be unique within Chromium. | 66 // exist per D-Bus connection, it just has to be unique within Chromium. |
66 const char kAgentPath[] = "/org/chromium/bluetooth_agent"; | 67 const char kAgentPath[] = "/org/chromium/bluetooth_agent"; |
67 const char kGattApplicationObjectPath[] = "/gatt_application"; | 68 const char kGattApplicationObjectPath[] = "/gatt_application"; |
68 | 69 |
69 void OnUnregisterAgentError(const std::string& error_name, | 70 void OnUnregisterAgentError(const std::string& error_name, |
70 const std::string& error_message) { | 71 const std::string& error_message) { |
71 // It's okay if the agent didn't exist, it means we never saw an adapter. | 72 // It's okay if the agent didn't exist, it means we never saw an adapter. |
72 if (error_name == bluetooth_agent_manager::kErrorDoesNotExist) | 73 if (error_name == bluetooth_agent_manager::kErrorDoesNotExist) |
73 return; | 74 return; |
74 | 75 |
75 LOG(WARNING) << "Failed to unregister pairing agent: " << error_name << ": " | 76 BLUETOOTH_LOG(ERROR) << "Failed to unregister pairing agent: " << error_name |
76 << error_message; | 77 << ": " << error_message; |
77 } | 78 } |
78 | 79 |
79 UMABluetoothDiscoverySessionOutcome TranslateDiscoveryErrorToUMA( | 80 UMABluetoothDiscoverySessionOutcome TranslateDiscoveryErrorToUMA( |
80 const std::string& error_name) { | 81 const std::string& error_name) { |
81 if (error_name == bluez::BluetoothAdapterClient::kUnknownAdapterError) { | 82 if (error_name == bluez::BluetoothAdapterClient::kUnknownAdapterError) { |
82 return UMABluetoothDiscoverySessionOutcome::BLUEZ_DBUS_UNKNOWN_ADAPTER; | 83 return UMABluetoothDiscoverySessionOutcome::BLUEZ_DBUS_UNKNOWN_ADAPTER; |
83 } else if (error_name == bluez::BluetoothAdapterClient::kNoResponseError) { | 84 } else if (error_name == bluez::BluetoothAdapterClient::kNoResponseError) { |
84 return UMABluetoothDiscoverySessionOutcome::BLUEZ_DBUS_NO_RESPONSE; | 85 return UMABluetoothDiscoverySessionOutcome::BLUEZ_DBUS_NO_RESPONSE; |
85 } else if (error_name == bluetooth_device::kErrorInProgress) { | 86 } else if (error_name == bluetooth_device::kErrorInProgress) { |
86 return UMABluetoothDiscoverySessionOutcome::BLUEZ_DBUS_IN_PROGRESS; | 87 return UMABluetoothDiscoverySessionOutcome::BLUEZ_DBUS_IN_PROGRESS; |
87 } else if (error_name == bluetooth_device::kErrorNotReady) { | 88 } else if (error_name == bluetooth_device::kErrorNotReady) { |
88 return UMABluetoothDiscoverySessionOutcome::BLUEZ_DBUS_NOT_READY; | 89 return UMABluetoothDiscoverySessionOutcome::BLUEZ_DBUS_NOT_READY; |
89 } else if (error_name == bluetooth_device::kErrorNotSupported) { | 90 } else if (error_name == bluetooth_device::kErrorNotSupported) { |
90 return UMABluetoothDiscoverySessionOutcome::BLUEZ_DBUS_UNSUPPORTED_DEVICE; | 91 return UMABluetoothDiscoverySessionOutcome::BLUEZ_DBUS_UNSUPPORTED_DEVICE; |
91 } else if (error_name == bluetooth_device::kErrorFailed) { | 92 } else if (error_name == bluetooth_device::kErrorFailed) { |
92 return UMABluetoothDiscoverySessionOutcome::FAILED; | 93 return UMABluetoothDiscoverySessionOutcome::FAILED; |
93 } else { | 94 } else { |
94 LOG(WARNING) << "Can't histogram DBus error " << error_name; | 95 BLUETOOTH_LOG(ERROR) << "Unrecognized DBus error " << error_name; |
95 return UMABluetoothDiscoverySessionOutcome::UNKNOWN; | 96 return UMABluetoothDiscoverySessionOutcome::UNKNOWN; |
96 } | 97 } |
97 } | 98 } |
98 | 99 |
99 } // namespace | 100 } // namespace |
100 | 101 |
101 namespace device { | 102 namespace device { |
102 | 103 |
103 // static | 104 // static |
104 base::WeakPtr<BluetoothAdapter> BluetoothAdapter::CreateAdapter( | 105 base::WeakPtr<BluetoothAdapter> BluetoothAdapter::CreateAdapter( |
105 const InitCallback& init_callback) { | 106 const InitCallback& init_callback) { |
106 return bluez::BluetoothAdapterBlueZ::CreateAdapter(init_callback); | 107 return bluez::BluetoothAdapterBlueZ::CreateAdapter(init_callback); |
107 } | 108 } |
108 | 109 |
109 } // namespace device | 110 } // namespace device |
110 | 111 |
111 namespace bluez { | 112 namespace bluez { |
112 | 113 |
113 namespace { | 114 namespace { |
114 | 115 |
115 void OnRegisterationErrorCallback( | 116 void OnRegisterationErrorCallback( |
116 const device::BluetoothGattService::ErrorCallback& error_callback, | 117 const device::BluetoothGattService::ErrorCallback& error_callback, |
117 bool is_register_callback, | 118 bool is_register_callback, |
118 const std::string& error_name, | 119 const std::string& error_name, |
119 const std::string& error_message) { | 120 const std::string& error_message) { |
120 if (is_register_callback) { | 121 if (is_register_callback) { |
121 VLOG(1) << "Failed to Register service: " << error_name << ", " | 122 BLUETOOTH_LOG(ERROR) << "Failed to Register service: " << error_name << ", " |
122 << error_message; | 123 << error_message; |
123 } else { | 124 } else { |
124 VLOG(1) << "Failed to Unregister service: " << error_name << ", " | 125 BLUETOOTH_LOG(ERROR) << "Failed to Unregister service: " << error_name |
125 << error_message; | 126 << ", " << error_message; |
126 } | 127 } |
127 error_callback.Run( | 128 error_callback.Run( |
128 BluetoothGattServiceBlueZ::DBusErrorToServiceError(error_name)); | 129 BluetoothGattServiceBlueZ::DBusErrorToServiceError(error_name)); |
129 } | 130 } |
130 | 131 |
131 void DoNothingOnError( | 132 void DoNothingOnError( |
132 device::BluetoothGattService::GattErrorCode /*error_code*/) {} | 133 device::BluetoothGattService::GattErrorCode /*error_code*/) {} |
133 void DoNothingOnAdvertisementError( | 134 void DoNothingOnAdvertisementError( |
134 device::BluetoothAdvertisement::ErrorCode /*error_code*/) {} | 135 device::BluetoothAdvertisement::ErrorCode /*error_code*/) {} |
135 | 136 |
136 void SetIntervalErrorCallbackConnector( | 137 void SetIntervalErrorCallbackConnector( |
137 const device::BluetoothAdapter::AdvertisementErrorCallback& error_callback, | 138 const device::BluetoothAdapter::AdvertisementErrorCallback& error_callback, |
138 const std::string& error_name, | 139 const std::string& error_name, |
139 const std::string& error_message) { | 140 const std::string& error_message) { |
140 LOG(ERROR) << "Error while registering advertisement. error_name = " | 141 BLUETOOTH_LOG(ERROR) << "Error while registering advertisement. error_name = " |
141 << error_name << ", error_message = " << error_message; | 142 << error_name << ", error_message = " << error_message; |
142 | 143 |
143 device::BluetoothAdvertisement::ErrorCode code = device:: | 144 device::BluetoothAdvertisement::ErrorCode code = device:: |
144 BluetoothAdvertisement::ErrorCode::INVALID_ADVERTISEMENT_ERROR_CODE; | 145 BluetoothAdvertisement::ErrorCode::INVALID_ADVERTISEMENT_ERROR_CODE; |
145 if (error_name == bluetooth_advertising_manager::kErrorInvalidArguments) { | 146 if (error_name == bluetooth_advertising_manager::kErrorInvalidArguments) { |
146 code = device::BluetoothAdvertisement::ErrorCode:: | 147 code = device::BluetoothAdvertisement::ErrorCode:: |
147 ERROR_INVALID_ADVERTISEMENT_INTERVAL; | 148 ERROR_INVALID_ADVERTISEMENT_INTERVAL; |
148 } | 149 } |
149 error_callback.Run(code); | 150 error_callback.Run(code); |
150 } | 151 } |
151 | 152 |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
200 } | 201 } |
201 advertisements_.clear(); | 202 advertisements_.clear(); |
202 | 203 |
203 bluez::BluezDBusManager::Get()->GetBluetoothAdapterClient()->RemoveObserver( | 204 bluez::BluezDBusManager::Get()->GetBluetoothAdapterClient()->RemoveObserver( |
204 this); | 205 this); |
205 bluez::BluezDBusManager::Get()->GetBluetoothDeviceClient()->RemoveObserver( | 206 bluez::BluezDBusManager::Get()->GetBluetoothDeviceClient()->RemoveObserver( |
206 this); | 207 this); |
207 bluez::BluezDBusManager::Get()->GetBluetoothInputClient()->RemoveObserver( | 208 bluez::BluezDBusManager::Get()->GetBluetoothInputClient()->RemoveObserver( |
208 this); | 209 this); |
209 | 210 |
210 VLOG(1) << "Unregistering pairing agent"; | 211 BLUETOOTH_LOG(EVENT) << "Unregistering pairing agent"; |
211 bluez::BluezDBusManager::Get() | 212 bluez::BluezDBusManager::Get() |
212 ->GetBluetoothAgentManagerClient() | 213 ->GetBluetoothAgentManagerClient() |
213 ->UnregisterAgent(dbus::ObjectPath(kAgentPath), | 214 ->UnregisterAgent(dbus::ObjectPath(kAgentPath), |
214 base::Bind(&base::DoNothing), | 215 base::Bind(&base::DoNothing), |
215 base::Bind(&OnUnregisterAgentError)); | 216 base::Bind(&OnUnregisterAgentError)); |
216 | 217 |
217 agent_.reset(); | 218 agent_.reset(); |
218 | 219 |
219 dbus_is_shutdown_ = true; | 220 dbus_is_shutdown_ = true; |
220 } | 221 } |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
260 dbus::Bus* system_bus = bluez::BluezDBusManager::Get()->GetSystemBus(); | 261 dbus::Bus* system_bus = bluez::BluezDBusManager::Get()->GetSystemBus(); |
261 agent_.reset(bluez::BluetoothAgentServiceProvider::Create( | 262 agent_.reset(bluez::BluetoothAgentServiceProvider::Create( |
262 system_bus, dbus::ObjectPath(kAgentPath), this)); | 263 system_bus, dbus::ObjectPath(kAgentPath), this)); |
263 DCHECK(agent_.get()); | 264 DCHECK(agent_.get()); |
264 | 265 |
265 std::vector<dbus::ObjectPath> object_paths = bluez::BluezDBusManager::Get() | 266 std::vector<dbus::ObjectPath> object_paths = bluez::BluezDBusManager::Get() |
266 ->GetBluetoothAdapterClient() | 267 ->GetBluetoothAdapterClient() |
267 ->GetAdapters(); | 268 ->GetAdapters(); |
268 | 269 |
269 if (!object_paths.empty()) { | 270 if (!object_paths.empty()) { |
270 VLOG(1) << object_paths.size() << " Bluetooth adapter(s) available."; | 271 BLUETOOTH_LOG(EVENT) << "BlueZ Initialized. Adapters available: " |
| 272 << object_paths.size(); |
271 SetAdapter(object_paths[0]); | 273 SetAdapter(object_paths[0]); |
272 } | 274 } |
273 initialized_ = true; | 275 initialized_ = true; |
274 init_callback_.Run(); | 276 init_callback_.Run(); |
275 } | 277 } |
276 | 278 |
277 BluetoothAdapterBlueZ::~BluetoothAdapterBlueZ() { | 279 BluetoothAdapterBlueZ::~BluetoothAdapterBlueZ() { |
278 Shutdown(); | 280 Shutdown(); |
279 } | 281 } |
280 | 282 |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
338 ->GetBluetoothAdapterClient() | 340 ->GetBluetoothAdapterClient() |
339 ->GetProperties(object_path_); | 341 ->GetProperties(object_path_); |
340 | 342 |
341 return properties->powered.value(); | 343 return properties->powered.value(); |
342 } | 344 } |
343 | 345 |
344 void BluetoothAdapterBlueZ::SetPowered(bool powered, | 346 void BluetoothAdapterBlueZ::SetPowered(bool powered, |
345 const base::Closure& callback, | 347 const base::Closure& callback, |
346 const ErrorCallback& error_callback) { | 348 const ErrorCallback& error_callback) { |
347 if (!IsPresent()) { | 349 if (!IsPresent()) { |
| 350 BLUETOOTH_LOG(ERROR) << "SetPowered: " << powered << ". Not Present!"; |
348 error_callback.Run(); | 351 error_callback.Run(); |
349 return; | 352 return; |
350 } | 353 } |
351 | 354 |
| 355 BLUETOOTH_LOG(EVENT) << "SetPowered: " << powered; |
| 356 |
352 bluez::BluezDBusManager::Get() | 357 bluez::BluezDBusManager::Get() |
353 ->GetBluetoothAdapterClient() | 358 ->GetBluetoothAdapterClient() |
354 ->GetProperties(object_path_) | 359 ->GetProperties(object_path_) |
355 ->powered.Set( | 360 ->powered.Set( |
356 powered, | 361 powered, |
357 base::Bind(&BluetoothAdapterBlueZ::OnPropertyChangeCompleted, | 362 base::Bind(&BluetoothAdapterBlueZ::OnPropertyChangeCompleted, |
358 weak_ptr_factory_.GetWeakPtr(), callback, error_callback)); | 363 weak_ptr_factory_.GetWeakPtr(), callback, error_callback)); |
359 } | 364 } |
360 | 365 |
361 bool BluetoothAdapterBlueZ::IsDiscoverable() const { | 366 bool BluetoothAdapterBlueZ::IsDiscoverable() const { |
(...skipping 10 matching lines...) Expand all Loading... |
372 | 377 |
373 void BluetoothAdapterBlueZ::SetDiscoverable( | 378 void BluetoothAdapterBlueZ::SetDiscoverable( |
374 bool discoverable, | 379 bool discoverable, |
375 const base::Closure& callback, | 380 const base::Closure& callback, |
376 const ErrorCallback& error_callback) { | 381 const ErrorCallback& error_callback) { |
377 if (!IsPresent()) { | 382 if (!IsPresent()) { |
378 error_callback.Run(); | 383 error_callback.Run(); |
379 return; | 384 return; |
380 } | 385 } |
381 | 386 |
| 387 BLUETOOTH_LOG(EVENT) << "SetDiscoverable: " << discoverable; |
| 388 |
382 bluez::BluezDBusManager::Get() | 389 bluez::BluezDBusManager::Get() |
383 ->GetBluetoothAdapterClient() | 390 ->GetBluetoothAdapterClient() |
384 ->GetProperties(object_path_) | 391 ->GetProperties(object_path_) |
385 ->discoverable.Set( | 392 ->discoverable.Set( |
386 discoverable, | 393 discoverable, |
387 base::Bind(&BluetoothAdapterBlueZ::OnSetDiscoverable, | 394 base::Bind(&BluetoothAdapterBlueZ::OnSetDiscoverable, |
388 weak_ptr_factory_.GetWeakPtr(), callback, error_callback)); | 395 weak_ptr_factory_.GetWeakPtr(), callback, error_callback)); |
389 } | 396 } |
390 | 397 |
391 uint32_t BluetoothAdapterBlueZ::GetDiscoverableTimeout() const { | 398 uint32_t BluetoothAdapterBlueZ::GetDiscoverableTimeout() const { |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
452 | 459 |
453 return UUIDList(uuids.begin(), uuids.end()); | 460 return UUIDList(uuids.begin(), uuids.end()); |
454 } | 461 } |
455 | 462 |
456 void BluetoothAdapterBlueZ::CreateRfcommService( | 463 void BluetoothAdapterBlueZ::CreateRfcommService( |
457 const BluetoothUUID& uuid, | 464 const BluetoothUUID& uuid, |
458 const ServiceOptions& options, | 465 const ServiceOptions& options, |
459 const CreateServiceCallback& callback, | 466 const CreateServiceCallback& callback, |
460 const CreateServiceErrorCallback& error_callback) { | 467 const CreateServiceErrorCallback& error_callback) { |
461 DCHECK(!dbus_is_shutdown_); | 468 DCHECK(!dbus_is_shutdown_); |
462 VLOG(1) << object_path_.value() | 469 BLUETOOTH_LOG(DEBUG) << object_path_.value() << ": Creating RFCOMM service: " |
463 << ": Creating RFCOMM service: " << uuid.canonical_value(); | 470 << uuid.canonical_value(); |
464 scoped_refptr<BluetoothSocketBlueZ> socket = | 471 scoped_refptr<BluetoothSocketBlueZ> socket = |
465 BluetoothSocketBlueZ::CreateBluetoothSocket(ui_task_runner_, | 472 BluetoothSocketBlueZ::CreateBluetoothSocket(ui_task_runner_, |
466 socket_thread_); | 473 socket_thread_); |
467 socket->Listen(this, BluetoothSocketBlueZ::kRfcomm, uuid, options, | 474 socket->Listen(this, BluetoothSocketBlueZ::kRfcomm, uuid, options, |
468 base::Bind(callback, socket), error_callback); | 475 base::Bind(callback, socket), error_callback); |
469 } | 476 } |
470 | 477 |
471 void BluetoothAdapterBlueZ::CreateL2capService( | 478 void BluetoothAdapterBlueZ::CreateL2capService( |
472 const BluetoothUUID& uuid, | 479 const BluetoothUUID& uuid, |
473 const ServiceOptions& options, | 480 const ServiceOptions& options, |
474 const CreateServiceCallback& callback, | 481 const CreateServiceCallback& callback, |
475 const CreateServiceErrorCallback& error_callback) { | 482 const CreateServiceErrorCallback& error_callback) { |
476 DCHECK(!dbus_is_shutdown_); | 483 DCHECK(!dbus_is_shutdown_); |
477 VLOG(1) << object_path_.value() | 484 BLUETOOTH_LOG(DEBUG) << object_path_.value() << ": Creating L2CAP service: " |
478 << ": Creating L2CAP service: " << uuid.canonical_value(); | 485 << uuid.canonical_value(); |
479 scoped_refptr<BluetoothSocketBlueZ> socket = | 486 scoped_refptr<BluetoothSocketBlueZ> socket = |
480 BluetoothSocketBlueZ::CreateBluetoothSocket(ui_task_runner_, | 487 BluetoothSocketBlueZ::CreateBluetoothSocket(ui_task_runner_, |
481 socket_thread_); | 488 socket_thread_); |
482 socket->Listen(this, BluetoothSocketBlueZ::kL2cap, uuid, options, | 489 socket->Listen(this, BluetoothSocketBlueZ::kL2cap, uuid, options, |
483 base::Bind(callback, socket), error_callback); | 490 base::Bind(callback, socket), error_callback); |
484 } | 491 } |
485 | 492 |
486 void BluetoothAdapterBlueZ::RegisterAdvertisement( | 493 void BluetoothAdapterBlueZ::RegisterAdvertisement( |
487 std::unique_ptr<device::BluetoothAdvertisement::Data> advertisement_data, | 494 std::unique_ptr<device::BluetoothAdvertisement::Data> advertisement_data, |
488 const CreateAdvertisementCallback& callback, | 495 const CreateAdvertisementCallback& callback, |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
608 return; | 615 return; |
609 | 616 |
610 bluez::BluetoothDeviceClient::Properties* properties = | 617 bluez::BluetoothDeviceClient::Properties* properties = |
611 bluez::BluezDBusManager::Get()->GetBluetoothDeviceClient()->GetProperties( | 618 bluez::BluezDBusManager::Get()->GetBluetoothDeviceClient()->GetProperties( |
612 object_path); | 619 object_path); |
613 | 620 |
614 if (property_name == properties->address.name()) { | 621 if (property_name == properties->address.name()) { |
615 for (auto iter = devices_.begin(); iter != devices_.end(); ++iter) { | 622 for (auto iter = devices_.begin(); iter != devices_.end(); ++iter) { |
616 if (iter->second->GetAddress() == device_bluez->GetAddress()) { | 623 if (iter->second->GetAddress() == device_bluez->GetAddress()) { |
617 std::string old_address = iter->first; | 624 std::string old_address = iter->first; |
618 VLOG(1) << "Device changed address, old: " << old_address | 625 BLUETOOTH_LOG(EVENT) << "Device changed address, old: " << old_address |
619 << " new: " << device_bluez->GetAddress(); | 626 << " new: " << device_bluez->GetAddress(); |
620 std::unique_ptr<BluetoothDevice> scoped_device = | 627 std::unique_ptr<BluetoothDevice> scoped_device = |
621 std::move(iter->second); | 628 std::move(iter->second); |
622 devices_.erase(iter); | 629 devices_.erase(iter); |
623 | 630 |
624 DCHECK(devices_.find(device_bluez->GetAddress()) == devices_.end()); | 631 DCHECK(devices_.find(device_bluez->GetAddress()) == devices_.end()); |
625 devices_[device_bluez->GetAddress()] = std::move(scoped_device); | 632 devices_[device_bluez->GetAddress()] = std::move(scoped_device); |
626 NotifyDeviceAddressChanged(device_bluez, old_address); | 633 NotifyDeviceAddressChanged(device_bluez, old_address); |
627 break; | 634 break; |
628 } | 635 } |
629 } | 636 } |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
693 | 700 |
694 // Properties structure can be removed, which triggers a change in the | 701 // Properties structure can be removed, which triggers a change in the |
695 // BluetoothDevice::IsConnectable() property, as does a change in the | 702 // BluetoothDevice::IsConnectable() property, as does a change in the |
696 // actual reconnect_mode property. | 703 // actual reconnect_mode property. |
697 if (!properties || property_name == properties->reconnect_mode.name()) { | 704 if (!properties || property_name == properties->reconnect_mode.name()) { |
698 NotifyDeviceChanged(device_bluez); | 705 NotifyDeviceChanged(device_bluez); |
699 } | 706 } |
700 } | 707 } |
701 | 708 |
702 void BluetoothAdapterBlueZ::Released() { | 709 void BluetoothAdapterBlueZ::Released() { |
703 VLOG(1) << "Release"; | 710 BLUETOOTH_LOG(EVENT) << "Released"; |
704 if (!IsPresent()) | 711 if (!IsPresent()) |
705 return; | 712 return; |
706 DCHECK(agent_.get()); | 713 DCHECK(agent_.get()); |
707 | 714 |
708 // Called after we unregister the pairing agent, e.g. when changing I/O | 715 // Called after we unregister the pairing agent, e.g. when changing I/O |
709 // capabilities. Nothing much to be done right now. | 716 // capabilities. Nothing much to be done right now. |
710 } | 717 } |
711 | 718 |
712 void BluetoothAdapterBlueZ::RequestPinCode(const dbus::ObjectPath& device_path, | 719 void BluetoothAdapterBlueZ::RequestPinCode(const dbus::ObjectPath& device_path, |
713 const PinCodeCallback& callback) { | 720 const PinCodeCallback& callback) { |
714 DCHECK(IsPresent()); | 721 DCHECK(IsPresent()); |
715 DCHECK(agent_.get()); | 722 DCHECK(agent_.get()); |
716 VLOG(1) << device_path.value() << ": RequestPinCode"; | 723 BLUETOOTH_LOG(EVENT) << device_path.value() << ": RequestPinCode"; |
717 | 724 |
718 BluetoothPairingBlueZ* pairing = GetPairing(device_path); | 725 BluetoothPairingBlueZ* pairing = GetPairing(device_path); |
719 if (!pairing) { | 726 if (!pairing) { |
720 callback.Run(REJECTED, ""); | 727 callback.Run(REJECTED, ""); |
721 return; | 728 return; |
722 } | 729 } |
723 | 730 |
724 pairing->RequestPinCode(callback); | 731 pairing->RequestPinCode(callback); |
725 } | 732 } |
726 | 733 |
727 void BluetoothAdapterBlueZ::DisplayPinCode(const dbus::ObjectPath& device_path, | 734 void BluetoothAdapterBlueZ::DisplayPinCode(const dbus::ObjectPath& device_path, |
728 const std::string& pincode) { | 735 const std::string& pincode) { |
729 DCHECK(IsPresent()); | 736 DCHECK(IsPresent()); |
730 DCHECK(agent_.get()); | 737 DCHECK(agent_.get()); |
731 VLOG(1) << device_path.value() << ": DisplayPinCode: " << pincode; | 738 BLUETOOTH_LOG(EVENT) << device_path.value() |
| 739 << ": DisplayPinCode: " << pincode; |
732 | 740 |
733 BluetoothPairingBlueZ* pairing = GetPairing(device_path); | 741 BluetoothPairingBlueZ* pairing = GetPairing(device_path); |
734 if (!pairing) | 742 if (!pairing) |
735 return; | 743 return; |
736 | 744 |
737 pairing->DisplayPinCode(pincode); | 745 pairing->DisplayPinCode(pincode); |
738 } | 746 } |
739 | 747 |
740 void BluetoothAdapterBlueZ::RequestPasskey(const dbus::ObjectPath& device_path, | 748 void BluetoothAdapterBlueZ::RequestPasskey(const dbus::ObjectPath& device_path, |
741 const PasskeyCallback& callback) { | 749 const PasskeyCallback& callback) { |
742 DCHECK(IsPresent()); | 750 DCHECK(IsPresent()); |
743 DCHECK(agent_.get()); | 751 DCHECK(agent_.get()); |
744 VLOG(1) << device_path.value() << ": RequestPasskey"; | 752 BLUETOOTH_LOG(EVENT) << device_path.value() << ": RequestPasskey"; |
745 | 753 |
746 BluetoothPairingBlueZ* pairing = GetPairing(device_path); | 754 BluetoothPairingBlueZ* pairing = GetPairing(device_path); |
747 if (!pairing) { | 755 if (!pairing) { |
748 callback.Run(REJECTED, 0); | 756 callback.Run(REJECTED, 0); |
749 return; | 757 return; |
750 } | 758 } |
751 | 759 |
752 pairing->RequestPasskey(callback); | 760 pairing->RequestPasskey(callback); |
753 } | 761 } |
754 | 762 |
755 void BluetoothAdapterBlueZ::DisplayPasskey(const dbus::ObjectPath& device_path, | 763 void BluetoothAdapterBlueZ::DisplayPasskey(const dbus::ObjectPath& device_path, |
756 uint32_t passkey, | 764 uint32_t passkey, |
757 uint16_t entered) { | 765 uint16_t entered) { |
758 DCHECK(IsPresent()); | 766 DCHECK(IsPresent()); |
759 DCHECK(agent_.get()); | 767 DCHECK(agent_.get()); |
760 VLOG(1) << device_path.value() << ": DisplayPasskey: " << passkey << " (" | 768 BLUETOOTH_LOG(EVENT) << device_path.value() << ": DisplayPasskey: " << passkey |
761 << entered << " entered)"; | 769 << " (" << entered << " entered)"; |
762 | 770 |
763 BluetoothPairingBlueZ* pairing = GetPairing(device_path); | 771 BluetoothPairingBlueZ* pairing = GetPairing(device_path); |
764 if (!pairing) | 772 if (!pairing) |
765 return; | 773 return; |
766 | 774 |
767 if (entered == 0) | 775 if (entered == 0) |
768 pairing->DisplayPasskey(passkey); | 776 pairing->DisplayPasskey(passkey); |
769 | 777 |
770 pairing->KeysEntered(entered); | 778 pairing->KeysEntered(entered); |
771 } | 779 } |
772 | 780 |
773 void BluetoothAdapterBlueZ::RequestConfirmation( | 781 void BluetoothAdapterBlueZ::RequestConfirmation( |
774 const dbus::ObjectPath& device_path, | 782 const dbus::ObjectPath& device_path, |
775 uint32_t passkey, | 783 uint32_t passkey, |
776 const ConfirmationCallback& callback) { | 784 const ConfirmationCallback& callback) { |
777 DCHECK(IsPresent()); | 785 DCHECK(IsPresent()); |
778 DCHECK(agent_.get()); | 786 DCHECK(agent_.get()); |
779 VLOG(1) << device_path.value() << ": RequestConfirmation: " << passkey; | 787 BLUETOOTH_LOG(EVENT) << device_path.value() |
| 788 << ": RequestConfirmation: " << passkey; |
780 | 789 |
781 BluetoothPairingBlueZ* pairing = GetPairing(device_path); | 790 BluetoothPairingBlueZ* pairing = GetPairing(device_path); |
782 if (!pairing) { | 791 if (!pairing) { |
783 callback.Run(REJECTED); | 792 callback.Run(REJECTED); |
784 return; | 793 return; |
785 } | 794 } |
786 | 795 |
787 pairing->RequestConfirmation(passkey, callback); | 796 pairing->RequestConfirmation(passkey, callback); |
788 } | 797 } |
789 | 798 |
790 void BluetoothAdapterBlueZ::RequestAuthorization( | 799 void BluetoothAdapterBlueZ::RequestAuthorization( |
791 const dbus::ObjectPath& device_path, | 800 const dbus::ObjectPath& device_path, |
792 const ConfirmationCallback& callback) { | 801 const ConfirmationCallback& callback) { |
793 DCHECK(IsPresent()); | 802 DCHECK(IsPresent()); |
794 DCHECK(agent_.get()); | 803 DCHECK(agent_.get()); |
795 VLOG(1) << device_path.value() << ": RequestAuthorization"; | 804 BLUETOOTH_LOG(EVENT) << device_path.value() << ": RequestAuthorization"; |
796 | 805 |
797 BluetoothPairingBlueZ* pairing = GetPairing(device_path); | 806 BluetoothPairingBlueZ* pairing = GetPairing(device_path); |
798 if (!pairing) { | 807 if (!pairing) { |
799 callback.Run(REJECTED); | 808 callback.Run(REJECTED); |
800 return; | 809 return; |
801 } | 810 } |
802 | 811 |
803 pairing->RequestAuthorization(callback); | 812 pairing->RequestAuthorization(callback); |
804 } | 813 } |
805 | 814 |
806 void BluetoothAdapterBlueZ::AuthorizeService( | 815 void BluetoothAdapterBlueZ::AuthorizeService( |
807 const dbus::ObjectPath& device_path, | 816 const dbus::ObjectPath& device_path, |
808 const std::string& uuid, | 817 const std::string& uuid, |
809 const ConfirmationCallback& callback) { | 818 const ConfirmationCallback& callback) { |
810 DCHECK(IsPresent()); | 819 DCHECK(IsPresent()); |
811 DCHECK(agent_.get()); | 820 DCHECK(agent_.get()); |
812 VLOG(1) << device_path.value() << ": AuthorizeService: " << uuid; | 821 BLUETOOTH_LOG(EVENT) << device_path.value() << ": AuthorizeService: " << uuid; |
813 | 822 |
814 BluetoothDeviceBlueZ* device_bluez = GetDeviceWithPath(device_path); | 823 BluetoothDeviceBlueZ* device_bluez = GetDeviceWithPath(device_path); |
815 if (!device_bluez) { | 824 if (!device_bluez) { |
816 callback.Run(CANCELLED); | 825 callback.Run(CANCELLED); |
817 return; | 826 return; |
818 } | 827 } |
819 | 828 |
820 // We always set paired devices to Trusted, so the only reason that this | 829 // We always set paired devices to Trusted, so the only reason that this |
821 // method call would ever be called is in the case of a race condition where | 830 // method call would ever be called is in the case of a race condition where |
822 // our "Set('Trusted', true)" method call is still pending in the Bluetooth | 831 // our "Set('Trusted', true)" method call is still pending in the Bluetooth |
823 // daemon because it's busy handling the incoming connection. | 832 // daemon because it's busy handling the incoming connection. |
824 if (device_bluez->IsPaired()) { | 833 if (device_bluez->IsPaired()) { |
825 callback.Run(SUCCESS); | 834 callback.Run(SUCCESS); |
826 return; | 835 return; |
827 } | 836 } |
828 | 837 |
829 // TODO(keybuk): reject service authorizations when not paired, determine | 838 // TODO(keybuk): reject service authorizations when not paired, determine |
830 // whether this is acceptable long-term. | 839 // whether this is acceptable long-term. |
831 LOG(WARNING) << "Rejecting service connection from unpaired device " | 840 BLUETOOTH_LOG(ERROR) << "Rejecting service connection from unpaired device " |
832 << device_bluez->GetAddress() << " for UUID " << uuid; | 841 << device_bluez->GetAddress() << " for UUID " << uuid; |
833 callback.Run(REJECTED); | 842 callback.Run(REJECTED); |
834 } | 843 } |
835 | 844 |
836 void BluetoothAdapterBlueZ::Cancel() { | 845 void BluetoothAdapterBlueZ::Cancel() { |
837 DCHECK(IsPresent()); | 846 DCHECK(IsPresent()); |
838 DCHECK(agent_.get()); | 847 DCHECK(agent_.get()); |
839 VLOG(1) << "Cancel"; | 848 BLUETOOTH_LOG(EVENT) << "Cancel"; |
840 } | 849 } |
841 | 850 |
842 void BluetoothAdapterBlueZ::OnRegisterAgent() { | 851 void BluetoothAdapterBlueZ::OnRegisterAgent() { |
843 VLOG(1) << "Pairing agent registered, requesting to be made default"; | 852 BLUETOOTH_LOG(EVENT) |
| 853 << "Pairing agent registered, requesting to be made default"; |
844 | 854 |
845 bluez::BluezDBusManager::Get() | 855 bluez::BluezDBusManager::Get() |
846 ->GetBluetoothAgentManagerClient() | 856 ->GetBluetoothAgentManagerClient() |
847 ->RequestDefaultAgent( | 857 ->RequestDefaultAgent( |
848 dbus::ObjectPath(kAgentPath), | 858 dbus::ObjectPath(kAgentPath), |
849 base::Bind(&BluetoothAdapterBlueZ::OnRequestDefaultAgent, | 859 base::Bind(&BluetoothAdapterBlueZ::OnRequestDefaultAgent, |
850 weak_ptr_factory_.GetWeakPtr()), | 860 weak_ptr_factory_.GetWeakPtr()), |
851 base::Bind(&BluetoothAdapterBlueZ::OnRequestDefaultAgentError, | 861 base::Bind(&BluetoothAdapterBlueZ::OnRequestDefaultAgentError, |
852 weak_ptr_factory_.GetWeakPtr())); | 862 weak_ptr_factory_.GetWeakPtr())); |
853 } | 863 } |
854 | 864 |
855 void BluetoothAdapterBlueZ::OnRegisterAgentError( | 865 void BluetoothAdapterBlueZ::OnRegisterAgentError( |
856 const std::string& error_name, | 866 const std::string& error_name, |
857 const std::string& error_message) { | 867 const std::string& error_message) { |
858 // Our agent being already registered isn't an error. | 868 // Our agent being already registered isn't an error. |
859 if (error_name == bluetooth_agent_manager::kErrorAlreadyExists) | 869 if (error_name == bluetooth_agent_manager::kErrorAlreadyExists) |
860 return; | 870 return; |
861 | 871 |
862 LOG(WARNING) << ": Failed to register pairing agent: " << error_name << ": " | 872 BLUETOOTH_LOG(ERROR) << "Failed to register pairing agent: " << error_name |
863 << error_message; | 873 << ": " << error_message; |
864 } | 874 } |
865 | 875 |
866 void BluetoothAdapterBlueZ::OnRequestDefaultAgent() { | 876 void BluetoothAdapterBlueZ::OnRequestDefaultAgent() { |
867 VLOG(1) << "Pairing agent now default"; | 877 BLUETOOTH_LOG(EVENT) << "Pairing agent now default"; |
868 } | 878 } |
869 | 879 |
870 void BluetoothAdapterBlueZ::OnRequestDefaultAgentError( | 880 void BluetoothAdapterBlueZ::OnRequestDefaultAgentError( |
871 const std::string& error_name, | 881 const std::string& error_name, |
872 const std::string& error_message) { | 882 const std::string& error_message) { |
873 LOG(WARNING) << ": Failed to make pairing agent default: " << error_name | 883 BLUETOOTH_LOG(ERROR) << "Failed to make pairing agent default: " << error_name |
874 << ": " << error_message; | 884 << ": " << error_message; |
875 } | 885 } |
876 | 886 |
877 void BluetoothAdapterBlueZ::CreateServiceRecord( | 887 void BluetoothAdapterBlueZ::CreateServiceRecord( |
878 const BluetoothServiceRecordBlueZ& record, | 888 const BluetoothServiceRecordBlueZ& record, |
879 const ServiceRecordCallback& callback, | 889 const ServiceRecordCallback& callback, |
880 const ServiceRecordErrorCallback& error_callback) { | 890 const ServiceRecordErrorCallback& error_callback) { |
881 bluez::BluezDBusManager::Get() | 891 bluez::BluezDBusManager::Get() |
882 ->GetBluetoothAdapterClient() | 892 ->GetBluetoothAdapterClient() |
883 ->CreateServiceRecord( | 893 ->CreateServiceRecord( |
884 object_path_, record, callback, | 894 object_path_, record, callback, |
(...skipping 26 matching lines...) Expand all Loading... |
911 } | 921 } |
912 | 922 |
913 return nullptr; | 923 return nullptr; |
914 } | 924 } |
915 | 925 |
916 BluetoothPairingBlueZ* BluetoothAdapterBlueZ::GetPairing( | 926 BluetoothPairingBlueZ* BluetoothAdapterBlueZ::GetPairing( |
917 const dbus::ObjectPath& object_path) { | 927 const dbus::ObjectPath& object_path) { |
918 DCHECK(IsPresent()); | 928 DCHECK(IsPresent()); |
919 BluetoothDeviceBlueZ* device_bluez = GetDeviceWithPath(object_path); | 929 BluetoothDeviceBlueZ* device_bluez = GetDeviceWithPath(object_path); |
920 if (!device_bluez) { | 930 if (!device_bluez) { |
921 LOG(WARNING) << "Pairing Agent request for unknown device: " | 931 BLUETOOTH_LOG(ERROR) << "Pairing Agent request for unknown device: " |
922 << object_path.value(); | 932 << object_path.value(); |
923 return nullptr; | 933 return nullptr; |
924 } | 934 } |
925 | 935 |
926 BluetoothPairingBlueZ* pairing = device_bluez->GetPairing(); | 936 BluetoothPairingBlueZ* pairing = device_bluez->GetPairing(); |
927 if (pairing) | 937 if (pairing) |
928 return pairing; | 938 return pairing; |
929 | 939 |
930 // The device doesn't have its own pairing context, so this is an incoming | 940 // The device doesn't have its own pairing context, so this is an incoming |
931 // pairing request that should use our best default delegate (if we have one). | 941 // pairing request that should use our best default delegate (if we have one). |
932 BluetoothDevice::PairingDelegate* pairing_delegate = DefaultPairingDelegate(); | 942 BluetoothDevice::PairingDelegate* pairing_delegate = DefaultPairingDelegate(); |
933 if (!pairing_delegate) | 943 if (!pairing_delegate) |
934 return nullptr; | 944 return nullptr; |
935 | 945 |
936 return device_bluez->BeginPairing(pairing_delegate); | 946 return device_bluez->BeginPairing(pairing_delegate); |
937 } | 947 } |
938 | 948 |
939 void BluetoothAdapterBlueZ::SetAdapter(const dbus::ObjectPath& object_path) { | 949 void BluetoothAdapterBlueZ::SetAdapter(const dbus::ObjectPath& object_path) { |
940 DCHECK(!IsPresent()); | 950 DCHECK(!IsPresent()); |
941 DCHECK(!dbus_is_shutdown_); | 951 DCHECK(!dbus_is_shutdown_); |
942 object_path_ = object_path; | 952 object_path_ = object_path; |
943 | 953 |
944 VLOG(1) << object_path_.value() << ": using adapter."; | 954 BLUETOOTH_LOG(EVENT) << object_path_.value() << ": using adapter."; |
945 | 955 |
946 VLOG(1) << "Registering pairing agent"; | 956 BLUETOOTH_LOG(DEBUG) << "Registering pairing agent"; |
947 bluez::BluezDBusManager::Get() | 957 bluez::BluezDBusManager::Get() |
948 ->GetBluetoothAgentManagerClient() | 958 ->GetBluetoothAgentManagerClient() |
949 ->RegisterAgent(dbus::ObjectPath(kAgentPath), | 959 ->RegisterAgent(dbus::ObjectPath(kAgentPath), |
950 bluetooth_agent_manager::kKeyboardDisplayCapability, | 960 bluetooth_agent_manager::kKeyboardDisplayCapability, |
951 base::Bind(&BluetoothAdapterBlueZ::OnRegisterAgent, | 961 base::Bind(&BluetoothAdapterBlueZ::OnRegisterAgent, |
952 weak_ptr_factory_.GetWeakPtr()), | 962 weak_ptr_factory_.GetWeakPtr()), |
953 base::Bind(&BluetoothAdapterBlueZ::OnRegisterAgentError, | 963 base::Bind(&BluetoothAdapterBlueZ::OnRegisterAgentError, |
954 weak_ptr_factory_.GetWeakPtr())); | 964 weak_ptr_factory_.GetWeakPtr())); |
955 | 965 |
956 #if defined(OS_CHROMEOS) | 966 #if defined(OS_CHROMEOS) |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1009 const std::string address = GetAddress(); | 1019 const std::string address = GetAddress(); |
1010 alias = base::StringPrintf( | 1020 alias = base::StringPrintf( |
1011 "%s_%04X", alias.c_str(), | 1021 "%s_%04X", alias.c_str(), |
1012 base::SuperFastHash(address.data(), address.size()) & 0xFFFF); | 1022 base::SuperFastHash(address.data(), address.size()) & 0xFFFF); |
1013 SetName(alias, base::Bind(&base::DoNothing), base::Bind(&base::DoNothing)); | 1023 SetName(alias, base::Bind(&base::DoNothing), base::Bind(&base::DoNothing)); |
1014 } | 1024 } |
1015 #endif | 1025 #endif |
1016 | 1026 |
1017 void BluetoothAdapterBlueZ::RemoveAdapter() { | 1027 void BluetoothAdapterBlueZ::RemoveAdapter() { |
1018 DCHECK(IsPresent()); | 1028 DCHECK(IsPresent()); |
1019 VLOG(1) << object_path_.value() << ": adapter removed."; | 1029 BLUETOOTH_LOG(EVENT) << object_path_.value() << ": adapter removed."; |
1020 | 1030 |
1021 bluez::BluetoothAdapterClient::Properties* properties = | 1031 bluez::BluetoothAdapterClient::Properties* properties = |
1022 bluez::BluezDBusManager::Get() | 1032 bluez::BluezDBusManager::Get() |
1023 ->GetBluetoothAdapterClient() | 1033 ->GetBluetoothAdapterClient() |
1024 ->GetProperties(object_path_); | 1034 ->GetProperties(object_path_); |
1025 | 1035 |
1026 object_path_ = dbus::ObjectPath(""); | 1036 object_path_ = dbus::ObjectPath(""); |
1027 | 1037 |
1028 if (properties->powered.value()) | 1038 if (properties->powered.value()) |
1029 NotifyAdapterPoweredChanged(false); | 1039 NotifyAdapterPoweredChanged(false); |
(...skipping 17 matching lines...) Expand all Loading... |
1047 } | 1057 } |
1048 | 1058 |
1049 void BluetoothAdapterBlueZ::DiscoverableChanged(bool discoverable) { | 1059 void BluetoothAdapterBlueZ::DiscoverableChanged(bool discoverable) { |
1050 for (auto& observer : observers_) | 1060 for (auto& observer : observers_) |
1051 observer.AdapterDiscoverableChanged(this, discoverable); | 1061 observer.AdapterDiscoverableChanged(this, discoverable); |
1052 } | 1062 } |
1053 | 1063 |
1054 void BluetoothAdapterBlueZ::DiscoveringChanged(bool discovering) { | 1064 void BluetoothAdapterBlueZ::DiscoveringChanged(bool discovering) { |
1055 // If the adapter stopped discovery due to a reason other than a request by | 1065 // If the adapter stopped discovery due to a reason other than a request by |
1056 // us, reset the count to 0. | 1066 // us, reset the count to 0. |
1057 VLOG(1) << "Discovering changed: " << discovering; | 1067 BLUETOOTH_LOG(EVENT) << "Discovering changed: " << discovering; |
1058 if (!discovering && !discovery_request_pending_ && | 1068 if (!discovering && !discovery_request_pending_ && |
1059 num_discovery_sessions_ > 0) { | 1069 num_discovery_sessions_ > 0) { |
1060 VLOG(1) << "Marking sessions as inactive."; | 1070 BLUETOOTH_LOG(DEBUG) << "Marking sessions as inactive."; |
1061 num_discovery_sessions_ = 0; | 1071 num_discovery_sessions_ = 0; |
1062 MarkDiscoverySessionsAsInactive(); | 1072 MarkDiscoverySessionsAsInactive(); |
1063 } | 1073 } |
1064 for (auto& observer : observers_) | 1074 for (auto& observer : observers_) |
1065 observer.AdapterDiscoveringChanged(this, discovering); | 1075 observer.AdapterDiscoveringChanged(this, discovering); |
1066 } | 1076 } |
1067 | 1077 |
1068 void BluetoothAdapterBlueZ::PresentChanged(bool present) { | 1078 void BluetoothAdapterBlueZ::PresentChanged(bool present) { |
1069 for (auto& observer : observers_) | 1079 for (auto& observer : observers_) |
1070 observer.AdapterPresentChanged(this, present); | 1080 observer.AdapterPresentChanged(this, present); |
(...skipping 11 matching lines...) Expand all Loading... |
1082 void BluetoothAdapterBlueZ::UseProfile( | 1092 void BluetoothAdapterBlueZ::UseProfile( |
1083 const BluetoothUUID& uuid, | 1093 const BluetoothUUID& uuid, |
1084 const dbus::ObjectPath& device_path, | 1094 const dbus::ObjectPath& device_path, |
1085 const bluez::BluetoothProfileManagerClient::Options& options, | 1095 const bluez::BluetoothProfileManagerClient::Options& options, |
1086 bluez::BluetoothProfileServiceProvider::Delegate* delegate, | 1096 bluez::BluetoothProfileServiceProvider::Delegate* delegate, |
1087 const ProfileRegisteredCallback& success_callback, | 1097 const ProfileRegisteredCallback& success_callback, |
1088 const ErrorCompletionCallback& error_callback) { | 1098 const ErrorCompletionCallback& error_callback) { |
1089 DCHECK(delegate); | 1099 DCHECK(delegate); |
1090 | 1100 |
1091 if (!IsPresent()) { | 1101 if (!IsPresent()) { |
1092 VLOG(2) << "Adapter not present, erroring out"; | 1102 BLUETOOTH_LOG(DEBUG) << "Adapter not present, erroring out"; |
1093 error_callback.Run("Adapter not present"); | 1103 error_callback.Run("Adapter not present"); |
1094 return; | 1104 return; |
1095 } | 1105 } |
1096 | 1106 |
1097 if (profiles_.find(uuid) != profiles_.end()) { | 1107 if (profiles_.find(uuid) != profiles_.end()) { |
1098 // TODO(jamuraa) check that the options are the same and error when they are | 1108 // TODO(jamuraa) check that the options are the same and error when they are |
1099 // not. | 1109 // not. |
1100 SetProfileDelegate(uuid, device_path, delegate, success_callback, | 1110 SetProfileDelegate(uuid, device_path, delegate, success_callback, |
1101 error_callback); | 1111 error_callback); |
1102 return; | 1112 return; |
(...skipping 10 matching lines...) Expand all Loading... |
1113 | 1123 |
1114 profile_queues_[uuid]->push_back(std::make_pair( | 1124 profile_queues_[uuid]->push_back(std::make_pair( |
1115 base::Bind(&BluetoothAdapterBlueZ::SetProfileDelegate, this, uuid, | 1125 base::Bind(&BluetoothAdapterBlueZ::SetProfileDelegate, this, uuid, |
1116 device_path, delegate, success_callback, error_callback), | 1126 device_path, delegate, success_callback, error_callback), |
1117 error_callback)); | 1127 error_callback)); |
1118 } | 1128 } |
1119 | 1129 |
1120 void BluetoothAdapterBlueZ::ReleaseProfile( | 1130 void BluetoothAdapterBlueZ::ReleaseProfile( |
1121 const dbus::ObjectPath& device_path, | 1131 const dbus::ObjectPath& device_path, |
1122 BluetoothAdapterProfileBlueZ* profile) { | 1132 BluetoothAdapterProfileBlueZ* profile) { |
1123 VLOG(2) << "Releasing Profile: " << profile->uuid().canonical_value() | 1133 BLUETOOTH_LOG(EVENT) << "Releasing Profile: " |
1124 << " from " << device_path.value(); | 1134 << profile->uuid().canonical_value() << " from " |
| 1135 << device_path.value(); |
1125 BluetoothUUID uuid = profile->uuid(); | 1136 BluetoothUUID uuid = profile->uuid(); |
1126 auto iter = profiles_.find(uuid); | 1137 auto iter = profiles_.find(uuid); |
1127 if (iter == profiles_.end()) { | 1138 if (iter == profiles_.end()) { |
1128 LOG(ERROR) << "Profile not found for: " << uuid.canonical_value(); | 1139 BLUETOOTH_LOG(ERROR) << "Profile not found for: " << uuid.canonical_value(); |
1129 return; | 1140 return; |
1130 } | 1141 } |
1131 released_profiles_[uuid] = iter->second; | 1142 released_profiles_[uuid] = iter->second; |
1132 profiles_.erase(iter); | 1143 profiles_.erase(iter); |
1133 profile->RemoveDelegate(device_path, | 1144 profile->RemoveDelegate(device_path, |
1134 base::Bind(&BluetoothAdapterBlueZ::RemoveProfile, | 1145 base::Bind(&BluetoothAdapterBlueZ::RemoveProfile, |
1135 weak_ptr_factory_.GetWeakPtr(), uuid)); | 1146 weak_ptr_factory_.GetWeakPtr(), uuid)); |
1136 } | 1147 } |
1137 | 1148 |
1138 void BluetoothAdapterBlueZ::RemoveProfile(const BluetoothUUID& uuid) { | 1149 void BluetoothAdapterBlueZ::RemoveProfile(const BluetoothUUID& uuid) { |
1139 VLOG(2) << "Remove Profile: " << uuid.canonical_value(); | 1150 BLUETOOTH_LOG(EVENT) << "Remove Profile: " << uuid.canonical_value(); |
1140 | 1151 |
1141 auto iter = released_profiles_.find(uuid); | 1152 auto iter = released_profiles_.find(uuid); |
1142 if (iter == released_profiles_.end()) { | 1153 if (iter == released_profiles_.end()) { |
1143 LOG(ERROR) << "Released Profile not found: " << uuid.canonical_value(); | 1154 BLUETOOTH_LOG(ERROR) << "Released Profile not found: " |
| 1155 << uuid.canonical_value(); |
1144 return; | 1156 return; |
1145 } | 1157 } |
1146 delete iter->second; | 1158 delete iter->second; |
1147 released_profiles_.erase(iter); | 1159 released_profiles_.erase(iter); |
1148 } | 1160 } |
1149 | 1161 |
1150 void BluetoothAdapterBlueZ::AddLocalGattService( | 1162 void BluetoothAdapterBlueZ::AddLocalGattService( |
1151 std::unique_ptr<BluetoothLocalGattServiceBlueZ> service) { | 1163 std::unique_ptr<BluetoothLocalGattServiceBlueZ> service) { |
1152 owned_gatt_services_[service->object_path()] = std::move(service); | 1164 owned_gatt_services_[service->object_path()] = std::move(service); |
1153 } | 1165 } |
1154 | 1166 |
1155 void BluetoothAdapterBlueZ::RemoveLocalGattService( | 1167 void BluetoothAdapterBlueZ::RemoveLocalGattService( |
1156 BluetoothLocalGattServiceBlueZ* service) { | 1168 BluetoothLocalGattServiceBlueZ* service) { |
1157 auto service_iter = owned_gatt_services_.find(service->object_path()); | 1169 auto service_iter = owned_gatt_services_.find(service->object_path()); |
1158 if (service_iter == owned_gatt_services_.end()) { | 1170 if (service_iter == owned_gatt_services_.end()) { |
1159 LOG(WARNING) << "Trying to remove service: " | 1171 BLUETOOTH_LOG(ERROR) << "Trying to remove service: " |
1160 << service->object_path().value() | 1172 << service->object_path().value() |
1161 << " from adapter: " << object_path_.value() | 1173 << " from adapter: " << object_path_.value() |
1162 << " that doesn't own it."; | 1174 << " that doesn't own it."; |
1163 return; | 1175 return; |
1164 } | 1176 } |
1165 | 1177 |
1166 if (registered_gatt_services_.count(service->object_path()) != 0) { | 1178 if (registered_gatt_services_.count(service->object_path()) != 0) { |
1167 registered_gatt_services_.erase(service->object_path()); | 1179 registered_gatt_services_.erase(service->object_path()); |
1168 UpdateRegisteredApplication(true, base::Bind(&base::DoNothing), | 1180 UpdateRegisteredApplication(true, base::Bind(&base::DoNothing), |
1169 base::Bind(&DoNothingOnError)); | 1181 base::Bind(&DoNothingOnError)); |
1170 } | 1182 } |
1171 | 1183 |
1172 owned_gatt_services_.erase(service_iter); | 1184 owned_gatt_services_.erase(service_iter); |
1173 } | 1185 } |
1174 | 1186 |
1175 void BluetoothAdapterBlueZ::RegisterGattService( | 1187 void BluetoothAdapterBlueZ::RegisterGattService( |
1176 BluetoothLocalGattServiceBlueZ* service, | 1188 BluetoothLocalGattServiceBlueZ* service, |
1177 const base::Closure& callback, | 1189 const base::Closure& callback, |
1178 const device::BluetoothGattService::ErrorCallback& error_callback) { | 1190 const device::BluetoothGattService::ErrorCallback& error_callback) { |
1179 if (registered_gatt_services_.count(service->object_path()) > 0) { | 1191 if (registered_gatt_services_.count(service->object_path()) > 0) { |
1180 LOG(WARNING) << "Re-registering a service that is already registered!"; | 1192 BLUETOOTH_LOG(ERROR) |
| 1193 << "Re-registering a service that is already registered!"; |
1181 error_callback.Run(device::BluetoothGattService::GATT_ERROR_FAILED); | 1194 error_callback.Run(device::BluetoothGattService::GATT_ERROR_FAILED); |
1182 return; | 1195 return; |
1183 } | 1196 } |
1184 | 1197 |
1185 registered_gatt_services_[service->object_path()] = service; | 1198 registered_gatt_services_[service->object_path()] = service; |
1186 | 1199 |
1187 // Always assume that we were already registered. If we weren't registered | 1200 // Always assume that we were already registered. If we weren't registered |
1188 // we'll just get an error back which we can ignore. Any other approach will | 1201 // we'll just get an error back which we can ignore. Any other approach will |
1189 // introduce a race since we will always have a period when we may have been | 1202 // introduce a race since we will always have a period when we may have been |
1190 // registered with BlueZ, but not know that the registration succeeded | 1203 // registered with BlueZ, but not know that the registration succeeded |
1191 // because the callback hasn't come back yet. | 1204 // because the callback hasn't come back yet. |
1192 UpdateRegisteredApplication(true, callback, error_callback); | 1205 UpdateRegisteredApplication(true, callback, error_callback); |
1193 } | 1206 } |
1194 | 1207 |
1195 void BluetoothAdapterBlueZ::UnregisterGattService( | 1208 void BluetoothAdapterBlueZ::UnregisterGattService( |
1196 BluetoothLocalGattServiceBlueZ* service, | 1209 BluetoothLocalGattServiceBlueZ* service, |
1197 const base::Closure& callback, | 1210 const base::Closure& callback, |
1198 const device::BluetoothGattService::ErrorCallback& error_callback) { | 1211 const device::BluetoothGattService::ErrorCallback& error_callback) { |
1199 DCHECK(bluez::BluezDBusManager::Get()); | 1212 DCHECK(bluez::BluezDBusManager::Get()); |
1200 | 1213 |
1201 if (registered_gatt_services_.count(service->object_path()) == 0) { | 1214 if (registered_gatt_services_.count(service->object_path()) == 0) { |
1202 LOG(WARNING) << "Unregistering a service that isn't registered! path: " | 1215 BLUETOOTH_LOG(ERROR) |
1203 << service->object_path().value(); | 1216 << "Unregistering a service that isn't registered! path: " |
| 1217 << service->object_path().value(); |
1204 error_callback.Run(device::BluetoothGattService::GATT_ERROR_FAILED); | 1218 error_callback.Run(device::BluetoothGattService::GATT_ERROR_FAILED); |
1205 return; | 1219 return; |
1206 } | 1220 } |
1207 | 1221 |
1208 registered_gatt_services_.erase(service->object_path()); | 1222 registered_gatt_services_.erase(service->object_path()); |
1209 UpdateRegisteredApplication(false, callback, error_callback); | 1223 UpdateRegisteredApplication(false, callback, error_callback); |
1210 } | 1224 } |
1211 | 1225 |
1212 bool BluetoothAdapterBlueZ::IsGattServiceRegistered( | 1226 bool BluetoothAdapterBlueZ::IsGattServiceRegistered( |
1213 BluetoothLocalGattServiceBlueZ* service) { | 1227 BluetoothLocalGattServiceBlueZ* service) { |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1261 return; | 1275 return; |
1262 } | 1276 } |
1263 // Already set | 1277 // Already set |
1264 error_callback.Run(bluetooth_agent_manager::kErrorAlreadyExists); | 1278 error_callback.Run(bluetooth_agent_manager::kErrorAlreadyExists); |
1265 } | 1279 } |
1266 | 1280 |
1267 void BluetoothAdapterBlueZ::OnRegisterProfileError( | 1281 void BluetoothAdapterBlueZ::OnRegisterProfileError( |
1268 const BluetoothUUID& uuid, | 1282 const BluetoothUUID& uuid, |
1269 const std::string& error_name, | 1283 const std::string& error_name, |
1270 const std::string& error_message) { | 1284 const std::string& error_message) { |
1271 VLOG(2) << object_path_.value() | 1285 BLUETOOTH_LOG(ERROR) << object_path_.value() |
1272 << ": Failed to register profile: " << error_name << ": " | 1286 << ": Failed to register profile: " << error_name << ": " |
1273 << error_message; | 1287 << error_message; |
1274 if (profile_queues_.find(uuid) == profile_queues_.end()) | 1288 if (profile_queues_.find(uuid) == profile_queues_.end()) |
1275 return; | 1289 return; |
1276 | 1290 |
1277 for (auto& it : *profile_queues_[uuid]) | 1291 for (auto& it : *profile_queues_[uuid]) |
1278 it.second.Run(error_message); | 1292 it.second.Run(error_message); |
1279 | 1293 |
1280 delete profile_queues_[uuid]; | 1294 delete profile_queues_[uuid]; |
1281 profile_queues_.erase(uuid); | 1295 profile_queues_.erase(uuid); |
1282 } | 1296 } |
1283 | 1297 |
(...skipping 30 matching lines...) Expand all Loading... |
1314 | 1328 |
1315 void BluetoothAdapterBlueZ::AddDiscoverySession( | 1329 void BluetoothAdapterBlueZ::AddDiscoverySession( |
1316 BluetoothDiscoveryFilter* discovery_filter, | 1330 BluetoothDiscoveryFilter* discovery_filter, |
1317 const base::Closure& callback, | 1331 const base::Closure& callback, |
1318 const DiscoverySessionErrorCallback& error_callback) { | 1332 const DiscoverySessionErrorCallback& error_callback) { |
1319 if (!IsPresent()) { | 1333 if (!IsPresent()) { |
1320 error_callback.Run( | 1334 error_callback.Run( |
1321 UMABluetoothDiscoverySessionOutcome::ADAPTER_NOT_PRESENT); | 1335 UMABluetoothDiscoverySessionOutcome::ADAPTER_NOT_PRESENT); |
1322 return; | 1336 return; |
1323 } | 1337 } |
1324 VLOG(1) << __func__; | 1338 BLUETOOTH_LOG(EVENT) << __func__; |
1325 if (discovery_request_pending_) { | 1339 if (discovery_request_pending_) { |
1326 // The pending request is either to stop a previous session or to start a | 1340 // The pending request is either to stop a previous session or to start a |
1327 // new one. Either way, queue this one. | 1341 // new one. Either way, queue this one. |
1328 DCHECK(num_discovery_sessions_ == 1 || num_discovery_sessions_ == 0); | 1342 DCHECK(num_discovery_sessions_ == 1 || num_discovery_sessions_ == 0); |
1329 VLOG(1) << "Pending request to start/stop device discovery. Queueing " | 1343 BLUETOOTH_LOG(DEBUG) |
1330 << "request to start a new discovery session."; | 1344 << "Pending request to start/stop device discovery. Queueing " |
| 1345 << "request to start a new discovery session."; |
1331 discovery_request_queue_.push( | 1346 discovery_request_queue_.push( |
1332 std::make_tuple(discovery_filter, callback, error_callback)); | 1347 std::make_tuple(discovery_filter, callback, error_callback)); |
1333 return; | 1348 return; |
1334 } | 1349 } |
1335 | 1350 |
1336 // The adapter is already discovering. | 1351 // The adapter is already discovering. |
1337 if (num_discovery_sessions_ > 0) { | 1352 if (num_discovery_sessions_ > 0) { |
1338 DCHECK(IsDiscovering()); | 1353 DCHECK(IsDiscovering()); |
1339 DCHECK(!discovery_request_pending_); | 1354 DCHECK(!discovery_request_pending_); |
1340 num_discovery_sessions_++; | 1355 num_discovery_sessions_++; |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1377 void BluetoothAdapterBlueZ::RemoveDiscoverySession( | 1392 void BluetoothAdapterBlueZ::RemoveDiscoverySession( |
1378 BluetoothDiscoveryFilter* discovery_filter, | 1393 BluetoothDiscoveryFilter* discovery_filter, |
1379 const base::Closure& callback, | 1394 const base::Closure& callback, |
1380 const DiscoverySessionErrorCallback& error_callback) { | 1395 const DiscoverySessionErrorCallback& error_callback) { |
1381 if (!IsPresent()) { | 1396 if (!IsPresent()) { |
1382 error_callback.Run( | 1397 error_callback.Run( |
1383 UMABluetoothDiscoverySessionOutcome::ADAPTER_NOT_PRESENT); | 1398 UMABluetoothDiscoverySessionOutcome::ADAPTER_NOT_PRESENT); |
1384 return; | 1399 return; |
1385 } | 1400 } |
1386 | 1401 |
1387 VLOG(1) << __func__; | 1402 BLUETOOTH_LOG(EVENT) << __func__; |
1388 // There are active sessions other than the one currently being removed. | 1403 // There are active sessions other than the one currently being removed. |
1389 if (num_discovery_sessions_ > 1) { | 1404 if (num_discovery_sessions_ > 1) { |
1390 DCHECK(IsDiscovering()); | 1405 DCHECK(IsDiscovering()); |
1391 DCHECK(!discovery_request_pending_); | 1406 DCHECK(!discovery_request_pending_); |
1392 num_discovery_sessions_--; | 1407 num_discovery_sessions_--; |
1393 | 1408 |
1394 SetDiscoveryFilter(GetMergedDiscoveryFilterMasked(discovery_filter), | 1409 SetDiscoveryFilter(GetMergedDiscoveryFilterMasked(discovery_filter), |
1395 callback, error_callback); | 1410 callback, error_callback); |
1396 return; | 1411 return; |
1397 } | 1412 } |
1398 | 1413 |
1399 // If there is a pending request to BlueZ, then queue this request. | 1414 // If there is a pending request to BlueZ, then queue this request. |
1400 if (discovery_request_pending_) { | 1415 if (discovery_request_pending_) { |
1401 VLOG(1) << "Pending request to start/stop device discovery. Queueing " | 1416 BLUETOOTH_LOG(DEBUG) |
1402 << "request to stop discovery session."; | 1417 << "Pending request to start/stop device discovery. Queueing " |
| 1418 << "request to stop discovery session."; |
1403 error_callback.Run( | 1419 error_callback.Run( |
1404 UMABluetoothDiscoverySessionOutcome::REMOVE_WITH_PENDING_REQUEST); | 1420 UMABluetoothDiscoverySessionOutcome::REMOVE_WITH_PENDING_REQUEST); |
1405 return; | 1421 return; |
1406 } | 1422 } |
1407 | 1423 |
1408 // There are no active sessions. Return error. | 1424 // There are no active sessions. Return error. |
1409 if (num_discovery_sessions_ == 0) { | 1425 if (num_discovery_sessions_ == 0) { |
1410 // TODO(armansito): This should never happen once we have the | 1426 // TODO(armansito): This should never happen once we have the |
1411 // DiscoverySession API. Replace this case with an assert once it's | 1427 // DiscoverySession API. Replace this case with an assert once it's |
1412 // the deprecated methods have been removed. (See crbug.com/3445008). | 1428 // the deprecated methods have been removed. (See crbug.com/3445008). |
1413 VLOG(1) << "No active discovery sessions. Returning error."; | 1429 BLUETOOTH_LOG(DEBUG) << "No active discovery sessions. Returning error."; |
1414 error_callback.Run( | 1430 error_callback.Run( |
1415 UMABluetoothDiscoverySessionOutcome::ACTIVE_SESSION_NOT_IN_ADAPTER); | 1431 UMABluetoothDiscoverySessionOutcome::ACTIVE_SESSION_NOT_IN_ADAPTER); |
1416 return; | 1432 return; |
1417 } | 1433 } |
1418 | 1434 |
1419 // There is exactly one active discovery session. Request BlueZ to stop | 1435 // There is exactly one active discovery session. Request BlueZ to stop |
1420 // discovery. | 1436 // discovery. |
1421 DCHECK_EQ(num_discovery_sessions_, 1); | 1437 DCHECK_EQ(num_discovery_sessions_, 1); |
1422 discovery_request_pending_ = true; | 1438 discovery_request_pending_ = true; |
1423 bluez::BluezDBusManager::Get()->GetBluetoothAdapterClient()->StopDiscovery( | 1439 bluez::BluezDBusManager::Get()->GetBluetoothAdapterClient()->StopDiscovery( |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1493 base::Bind(&BluetoothAdapterBlueZ::OnSetDiscoveryFilter, | 1509 base::Bind(&BluetoothAdapterBlueZ::OnSetDiscoveryFilter, |
1494 weak_ptr_factory_.GetWeakPtr(), callback, error_callback), | 1510 weak_ptr_factory_.GetWeakPtr(), callback, error_callback), |
1495 base::Bind(&BluetoothAdapterBlueZ::OnSetDiscoveryFilterError, | 1511 base::Bind(&BluetoothAdapterBlueZ::OnSetDiscoveryFilterError, |
1496 weak_ptr_factory_.GetWeakPtr(), callback, error_callback)); | 1512 weak_ptr_factory_.GetWeakPtr(), callback, error_callback)); |
1497 } | 1513 } |
1498 | 1514 |
1499 void BluetoothAdapterBlueZ::OnStartDiscovery( | 1515 void BluetoothAdapterBlueZ::OnStartDiscovery( |
1500 const base::Closure& callback, | 1516 const base::Closure& callback, |
1501 const DiscoverySessionErrorCallback& error_callback) { | 1517 const DiscoverySessionErrorCallback& error_callback) { |
1502 // Report success on the original request and increment the count. | 1518 // Report success on the original request and increment the count. |
1503 VLOG(1) << __func__; | 1519 BLUETOOTH_LOG(EVENT) << __func__; |
1504 DCHECK(discovery_request_pending_); | 1520 DCHECK(discovery_request_pending_); |
1505 DCHECK_EQ(num_discovery_sessions_, 0); | 1521 DCHECK_EQ(num_discovery_sessions_, 0); |
1506 discovery_request_pending_ = false; | 1522 discovery_request_pending_ = false; |
1507 num_discovery_sessions_++; | 1523 num_discovery_sessions_++; |
1508 if (IsPresent()) { | 1524 if (IsPresent()) { |
1509 callback.Run(); | 1525 callback.Run(); |
1510 } else { | 1526 } else { |
1511 error_callback.Run(UMABluetoothDiscoverySessionOutcome::ADAPTER_REMOVED); | 1527 error_callback.Run(UMABluetoothDiscoverySessionOutcome::ADAPTER_REMOVED); |
1512 } | 1528 } |
1513 | 1529 |
1514 // Try to add a new discovery session for each queued request. | 1530 // Try to add a new discovery session for each queued request. |
1515 ProcessQueuedDiscoveryRequests(); | 1531 ProcessQueuedDiscoveryRequests(); |
1516 } | 1532 } |
1517 | 1533 |
1518 void BluetoothAdapterBlueZ::OnStartDiscoveryError( | 1534 void BluetoothAdapterBlueZ::OnStartDiscoveryError( |
1519 const base::Closure& callback, | 1535 const base::Closure& callback, |
1520 const DiscoverySessionErrorCallback& error_callback, | 1536 const DiscoverySessionErrorCallback& error_callback, |
1521 const std::string& error_name, | 1537 const std::string& error_name, |
1522 const std::string& error_message) { | 1538 const std::string& error_message) { |
1523 LOG(WARNING) << object_path_.value() | 1539 BLUETOOTH_LOG(ERROR) << object_path_.value() |
1524 << ": Failed to start discovery: " << error_name << ": " | 1540 << ": Failed to start discovery: " << error_name << ": " |
1525 << error_message; | 1541 << error_message; |
1526 | 1542 |
1527 // Failed to start discovery. This can only happen if the count is at 0. | 1543 // Failed to start discovery. This can only happen if the count is at 0. |
1528 DCHECK_EQ(num_discovery_sessions_, 0); | 1544 DCHECK_EQ(num_discovery_sessions_, 0); |
1529 DCHECK(discovery_request_pending_); | 1545 DCHECK(discovery_request_pending_); |
1530 discovery_request_pending_ = false; | 1546 discovery_request_pending_ = false; |
1531 | 1547 |
1532 // Discovery request may fail if discovery was previously initiated by Chrome, | 1548 // Discovery request may fail if discovery was previously initiated by Chrome, |
1533 // but the session were invalidated due to the discovery state unexpectedly | 1549 // but the session were invalidated due to the discovery state unexpectedly |
1534 // changing to false and then back to true. In this case, report success. | 1550 // changing to false and then back to true. In this case, report success. |
1535 if (IsPresent() && error_name == bluetooth_device::kErrorInProgress && | 1551 if (IsPresent() && error_name == bluetooth_device::kErrorInProgress && |
1536 IsDiscovering()) { | 1552 IsDiscovering()) { |
1537 VLOG(1) << "Discovery previously initiated. Reporting success."; | 1553 BLUETOOTH_LOG(DEBUG) |
| 1554 << "Discovery previously initiated. Reporting success."; |
1538 num_discovery_sessions_++; | 1555 num_discovery_sessions_++; |
1539 callback.Run(); | 1556 callback.Run(); |
1540 } else { | 1557 } else { |
1541 error_callback.Run(TranslateDiscoveryErrorToUMA(error_name)); | 1558 error_callback.Run(TranslateDiscoveryErrorToUMA(error_name)); |
1542 } | 1559 } |
1543 | 1560 |
1544 // Try to add a new discovery session for each queued request. | 1561 // Try to add a new discovery session for each queued request. |
1545 ProcessQueuedDiscoveryRequests(); | 1562 ProcessQueuedDiscoveryRequests(); |
1546 } | 1563 } |
1547 | 1564 |
1548 void BluetoothAdapterBlueZ::OnStopDiscovery(const base::Closure& callback) { | 1565 void BluetoothAdapterBlueZ::OnStopDiscovery(const base::Closure& callback) { |
1549 // Report success on the original request and decrement the count. | 1566 // Report success on the original request and decrement the count. |
1550 VLOG(1) << __func__; | 1567 BLUETOOTH_LOG(EVENT) << __func__; |
1551 DCHECK(discovery_request_pending_); | 1568 DCHECK(discovery_request_pending_); |
1552 DCHECK_EQ(num_discovery_sessions_, 1); | 1569 DCHECK_EQ(num_discovery_sessions_, 1); |
1553 discovery_request_pending_ = false; | 1570 discovery_request_pending_ = false; |
1554 num_discovery_sessions_--; | 1571 num_discovery_sessions_--; |
1555 callback.Run(); | 1572 callback.Run(); |
1556 | 1573 |
1557 current_filter_.reset(); | 1574 current_filter_.reset(); |
1558 | 1575 |
1559 // Try to add a new discovery session for each queued request. | 1576 // Try to add a new discovery session for each queued request. |
1560 ProcessQueuedDiscoveryRequests(); | 1577 ProcessQueuedDiscoveryRequests(); |
1561 } | 1578 } |
1562 | 1579 |
1563 void BluetoothAdapterBlueZ::OnStopDiscoveryError( | 1580 void BluetoothAdapterBlueZ::OnStopDiscoveryError( |
1564 const DiscoverySessionErrorCallback& error_callback, | 1581 const DiscoverySessionErrorCallback& error_callback, |
1565 const std::string& error_name, | 1582 const std::string& error_name, |
1566 const std::string& error_message) { | 1583 const std::string& error_message) { |
1567 LOG(WARNING) << object_path_.value() | 1584 BLUETOOTH_LOG(ERROR) << object_path_.value() |
1568 << ": Failed to stop discovery: " << error_name << ": " | 1585 << ": Failed to stop discovery: " << error_name << ": " |
1569 << error_message; | 1586 << error_message; |
1570 | 1587 |
1571 // Failed to stop discovery. This can only happen if the count is at 1. | 1588 // Failed to stop discovery. This can only happen if the count is at 1. |
1572 DCHECK(discovery_request_pending_); | 1589 DCHECK(discovery_request_pending_); |
1573 DCHECK_EQ(num_discovery_sessions_, 1); | 1590 DCHECK_EQ(num_discovery_sessions_, 1); |
1574 discovery_request_pending_ = false; | 1591 discovery_request_pending_ = false; |
1575 error_callback.Run(TranslateDiscoveryErrorToUMA(error_name)); | 1592 error_callback.Run(TranslateDiscoveryErrorToUMA(error_name)); |
1576 | 1593 |
1577 // Try to add a new discovery session for each queued request. | 1594 // Try to add a new discovery session for each queued request. |
1578 ProcessQueuedDiscoveryRequests(); | 1595 ProcessQueuedDiscoveryRequests(); |
1579 } | 1596 } |
(...skipping 10 matching lines...) Expand all Loading... |
1590 base::Bind(&BluetoothAdapterBlueZ::OnStartDiscovery, | 1607 base::Bind(&BluetoothAdapterBlueZ::OnStartDiscovery, |
1591 weak_ptr_factory_.GetWeakPtr(), callback, error_callback), | 1608 weak_ptr_factory_.GetWeakPtr(), callback, error_callback), |
1592 base::Bind(&BluetoothAdapterBlueZ::OnStartDiscoveryError, | 1609 base::Bind(&BluetoothAdapterBlueZ::OnStartDiscoveryError, |
1593 weak_ptr_factory_.GetWeakPtr(), callback, error_callback)); | 1610 weak_ptr_factory_.GetWeakPtr(), callback, error_callback)); |
1594 } | 1611 } |
1595 | 1612 |
1596 void BluetoothAdapterBlueZ::OnPreSetDiscoveryFilterError( | 1613 void BluetoothAdapterBlueZ::OnPreSetDiscoveryFilterError( |
1597 const base::Closure& callback, | 1614 const base::Closure& callback, |
1598 const DiscoverySessionErrorCallback& error_callback, | 1615 const DiscoverySessionErrorCallback& error_callback, |
1599 UMABluetoothDiscoverySessionOutcome outcome) { | 1616 UMABluetoothDiscoverySessionOutcome outcome) { |
1600 LOG(WARNING) << object_path_.value() | 1617 BLUETOOTH_LOG(ERROR) << object_path_.value() |
1601 << ": Failed to pre set discovery filter."; | 1618 << ": Failed to pre set discovery filter."; |
1602 | 1619 |
1603 // Failed to start discovery. This can only happen if the count is at 0. | 1620 // Failed to start discovery. This can only happen if the count is at 0. |
1604 DCHECK_EQ(num_discovery_sessions_, 0); | 1621 DCHECK_EQ(num_discovery_sessions_, 0); |
1605 DCHECK(discovery_request_pending_); | 1622 DCHECK(discovery_request_pending_); |
1606 discovery_request_pending_ = false; | 1623 discovery_request_pending_ = false; |
1607 | 1624 |
1608 error_callback.Run(outcome); | 1625 error_callback.Run(outcome); |
1609 | 1626 |
1610 // Try to add a new discovery session for each queued request. | 1627 // Try to add a new discovery session for each queued request. |
1611 ProcessQueuedDiscoveryRequests(); | 1628 ProcessQueuedDiscoveryRequests(); |
1612 } | 1629 } |
1613 | 1630 |
1614 void BluetoothAdapterBlueZ::OnSetDiscoveryFilter( | 1631 void BluetoothAdapterBlueZ::OnSetDiscoveryFilter( |
1615 const base::Closure& callback, | 1632 const base::Closure& callback, |
1616 const DiscoverySessionErrorCallback& error_callback) { | 1633 const DiscoverySessionErrorCallback& error_callback) { |
1617 // Report success on the original request and increment the count. | 1634 // Report success on the original request and increment the count. |
1618 VLOG(1) << __func__; | 1635 BLUETOOTH_LOG(EVENT) << __func__; |
1619 if (IsPresent()) { | 1636 if (IsPresent()) { |
1620 callback.Run(); | 1637 callback.Run(); |
1621 } else { | 1638 } else { |
1622 error_callback.Run(UMABluetoothDiscoverySessionOutcome::ADAPTER_REMOVED); | 1639 error_callback.Run(UMABluetoothDiscoverySessionOutcome::ADAPTER_REMOVED); |
1623 } | 1640 } |
1624 } | 1641 } |
1625 | 1642 |
1626 void BluetoothAdapterBlueZ::OnSetDiscoveryFilterError( | 1643 void BluetoothAdapterBlueZ::OnSetDiscoveryFilterError( |
1627 const base::Closure& callback, | 1644 const base::Closure& callback, |
1628 const DiscoverySessionErrorCallback& error_callback, | 1645 const DiscoverySessionErrorCallback& error_callback, |
1629 const std::string& error_name, | 1646 const std::string& error_name, |
1630 const std::string& error_message) { | 1647 const std::string& error_message) { |
1631 LOG(WARNING) << object_path_.value() | 1648 BLUETOOTH_LOG(ERROR) << object_path_.value() |
1632 << ": Failed to set discovery filter: " << error_name << ": " | 1649 << ": Failed to set discovery filter: " << error_name |
1633 << error_message; | 1650 << ": " << error_message; |
1634 | 1651 |
1635 UMABluetoothDiscoverySessionOutcome outcome = | 1652 UMABluetoothDiscoverySessionOutcome outcome = |
1636 TranslateDiscoveryErrorToUMA(error_name); | 1653 TranslateDiscoveryErrorToUMA(error_name); |
1637 if (outcome == UMABluetoothDiscoverySessionOutcome::FAILED) { | 1654 if (outcome == UMABluetoothDiscoverySessionOutcome::FAILED) { |
1638 // bluez/doc/adapter-api.txt says "Failed" is returned from | 1655 // bluez/doc/adapter-api.txt says "Failed" is returned from |
1639 // SetDiscoveryFilter when the controller doesn't support the requested | 1656 // SetDiscoveryFilter when the controller doesn't support the requested |
1640 // transport. | 1657 // transport. |
1641 outcome = UMABluetoothDiscoverySessionOutcome:: | 1658 outcome = UMABluetoothDiscoverySessionOutcome:: |
1642 BLUEZ_DBUS_FAILED_MAYBE_UNSUPPORTED_TRANSPORT; | 1659 BLUEZ_DBUS_FAILED_MAYBE_UNSUPPORTED_TRANSPORT; |
1643 } | 1660 } |
1644 error_callback.Run(outcome); | 1661 error_callback.Run(outcome); |
1645 | 1662 |
1646 // Try to add a new discovery session for each queued request. | 1663 // Try to add a new discovery session for each queued request. |
1647 ProcessQueuedDiscoveryRequests(); | 1664 ProcessQueuedDiscoveryRequests(); |
1648 } | 1665 } |
1649 | 1666 |
1650 void BluetoothAdapterBlueZ::ProcessQueuedDiscoveryRequests() { | 1667 void BluetoothAdapterBlueZ::ProcessQueuedDiscoveryRequests() { |
1651 while (!discovery_request_queue_.empty()) { | 1668 while (!discovery_request_queue_.empty()) { |
1652 VLOG(1) << "Process queued discovery request."; | 1669 BLUETOOTH_LOG(EVENT) << "Process queued discovery request."; |
1653 DiscoveryParamTuple params = discovery_request_queue_.front(); | 1670 DiscoveryParamTuple params = discovery_request_queue_.front(); |
1654 discovery_request_queue_.pop(); | 1671 discovery_request_queue_.pop(); |
1655 AddDiscoverySession(std::get<0>(params), std::get<1>(params), | 1672 AddDiscoverySession(std::get<0>(params), std::get<1>(params), |
1656 std::get<2>(params)); | 1673 std::get<2>(params)); |
1657 | 1674 |
1658 // If the queued request resulted in a pending call, then let it | 1675 // If the queued request resulted in a pending call, then let it |
1659 // asynchonously process the remaining queued requests once the pending | 1676 // asynchonously process the remaining queued requests once the pending |
1660 // call returns. | 1677 // call returns. |
1661 if (discovery_request_pending_) | 1678 if (discovery_request_pending_) |
1662 return; | 1679 return; |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1714 const device::BluetoothGattService::ErrorCallback& error_callback, | 1731 const device::BluetoothGattService::ErrorCallback& error_callback, |
1715 const std::string& /* error_name */, | 1732 const std::string& /* error_name */, |
1716 const std::string& /* error_message */) { | 1733 const std::string& /* error_message */) { |
1717 RegisterApplication(callback, error_callback); | 1734 RegisterApplication(callback, error_callback); |
1718 } | 1735 } |
1719 | 1736 |
1720 void BluetoothAdapterBlueZ::ServiceRecordErrorConnector( | 1737 void BluetoothAdapterBlueZ::ServiceRecordErrorConnector( |
1721 const ServiceRecordErrorCallback& error_callback, | 1738 const ServiceRecordErrorCallback& error_callback, |
1722 const std::string& error_name, | 1739 const std::string& error_name, |
1723 const std::string& error_message) { | 1740 const std::string& error_message) { |
1724 VLOG(1) << "Creating service record failed: error: " << error_name << " - " | 1741 BLUETOOTH_LOG(EVENT) << "Creating service record failed: error: " |
1725 << error_message; | 1742 << error_name << " - " << error_message; |
1726 | 1743 |
1727 BluetoothServiceRecordBlueZ::ErrorCode code = | 1744 BluetoothServiceRecordBlueZ::ErrorCode code = |
1728 BluetoothServiceRecordBlueZ::ErrorCode::UNKNOWN; | 1745 BluetoothServiceRecordBlueZ::ErrorCode::UNKNOWN; |
1729 if (error_name == bluetooth_adapter::kErrorInvalidArguments) { | 1746 if (error_name == bluetooth_adapter::kErrorInvalidArguments) { |
1730 code = BluetoothServiceRecordBlueZ::ErrorCode::ERROR_INVALID_ARGUMENTS; | 1747 code = BluetoothServiceRecordBlueZ::ErrorCode::ERROR_INVALID_ARGUMENTS; |
1731 } else if (error_name == bluetooth_adapter::kErrorDoesNotExist) { | 1748 } else if (error_name == bluetooth_adapter::kErrorDoesNotExist) { |
1732 code = BluetoothServiceRecordBlueZ::ErrorCode::ERROR_RECORD_DOES_NOT_EXIST; | 1749 code = BluetoothServiceRecordBlueZ::ErrorCode::ERROR_RECORD_DOES_NOT_EXIST; |
1733 } else if (error_name == bluetooth_adapter::kErrorAlreadyExists) { | 1750 } else if (error_name == bluetooth_adapter::kErrorAlreadyExists) { |
1734 code = BluetoothServiceRecordBlueZ::ErrorCode::ERROR_RECORD_ALREADY_EXISTS; | 1751 code = BluetoothServiceRecordBlueZ::ErrorCode::ERROR_RECORD_ALREADY_EXISTS; |
1735 } else if (error_name == bluetooth_adapter::kErrorNotReady) { | 1752 } else if (error_name == bluetooth_adapter::kErrorNotReady) { |
1736 code = BluetoothServiceRecordBlueZ::ErrorCode::ERROR_ADAPTER_NOT_READY; | 1753 code = BluetoothServiceRecordBlueZ::ErrorCode::ERROR_ADAPTER_NOT_READY; |
1737 } | 1754 } |
1738 | 1755 |
1739 error_callback.Run(code); | 1756 error_callback.Run(code); |
1740 } | 1757 } |
1741 | 1758 |
1742 } // namespace bluez | 1759 } // namespace bluez |
OLD | NEW |