Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(6)

Side by Side Diff: device/bluetooth/bluez/bluetooth_adapter_bluez.cc

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

Powered by Google App Engine
This is Rietveld 408576698