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

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

Issue 1587723007: bluetooth: Add Bluetooth events to chrome://device-log/ (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 11 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/bluetooth_adapter.cc ('k') | no next file » | 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/bluetooth_adapter_bluez.h" 5 #include "device/bluetooth/bluetooth_adapter_bluez.h"
6 6
7 #include <string> 7 #include <string>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
11 #include "base/location.h" 11 #include "base/location.h"
12 #include "base/logging.h" 12 #include "base/logging.h"
13 #include "base/metrics/histogram.h" 13 #include "base/metrics/histogram.h"
14 #include "base/sequenced_task_runner.h" 14 #include "base/sequenced_task_runner.h"
15 #include "base/single_thread_task_runner.h" 15 #include "base/single_thread_task_runner.h"
16 #include "base/thread_task_runner_handle.h" 16 #include "base/thread_task_runner_handle.h"
17 #include "build/build_config.h" 17 #include "build/build_config.h"
18 #include "components/device_event_log/device_event_log.h"
18 #include "device/bluetooth/bluetooth_adapter_profile_bluez.h" 19 #include "device/bluetooth/bluetooth_adapter_profile_bluez.h"
19 #include "device/bluetooth/bluetooth_advertisement_bluez.h" 20 #include "device/bluetooth/bluetooth_advertisement_bluez.h"
20 #include "device/bluetooth/bluetooth_audio_sink_bluez.h" 21 #include "device/bluetooth/bluetooth_audio_sink_bluez.h"
21 #include "device/bluetooth/bluetooth_device.h" 22 #include "device/bluetooth/bluetooth_device.h"
22 #include "device/bluetooth/bluetooth_device_bluez.h" 23 #include "device/bluetooth/bluetooth_device_bluez.h"
23 #include "device/bluetooth/bluetooth_discovery_session_outcome.h" 24 #include "device/bluetooth/bluetooth_discovery_session_outcome.h"
24 #include "device/bluetooth/bluetooth_pairing_bluez.h" 25 #include "device/bluetooth/bluetooth_pairing_bluez.h"
25 #include "device/bluetooth/bluetooth_remote_gatt_characteristic_bluez.h" 26 #include "device/bluetooth/bluetooth_remote_gatt_characteristic_bluez.h"
26 #include "device/bluetooth/bluetooth_remote_gatt_descriptor_bluez.h" 27 #include "device/bluetooth/bluetooth_remote_gatt_descriptor_bluez.h"
27 #include "device/bluetooth/bluetooth_remote_gatt_service_bluez.h" 28 #include "device/bluetooth/bluetooth_remote_gatt_service_bluez.h"
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 delete it.second; 121 delete it.second;
121 profile_queues_.clear(); 122 profile_queues_.clear();
122 123
123 bluez::BluezDBusManager::Get()->GetBluetoothAdapterClient()->RemoveObserver( 124 bluez::BluezDBusManager::Get()->GetBluetoothAdapterClient()->RemoveObserver(
124 this); 125 this);
125 bluez::BluezDBusManager::Get()->GetBluetoothDeviceClient()->RemoveObserver( 126 bluez::BluezDBusManager::Get()->GetBluetoothDeviceClient()->RemoveObserver(
126 this); 127 this);
127 bluez::BluezDBusManager::Get()->GetBluetoothInputClient()->RemoveObserver( 128 bluez::BluezDBusManager::Get()->GetBluetoothInputClient()->RemoveObserver(
128 this); 129 this);
129 130
130 VLOG(1) << "Unregistering pairing agent"; 131 BLUETOOTH_LOG(EVENT) << "Unregistering pairing agent";
stevenjb 2016/01/19 21:54:59 Let's separate out these events from this CL and s
131 bluez::BluezDBusManager::Get() 132 bluez::BluezDBusManager::Get()
132 ->GetBluetoothAgentManagerClient() 133 ->GetBluetoothAgentManagerClient()
133 ->UnregisterAgent(dbus::ObjectPath(kAgentPath), 134 ->UnregisterAgent(dbus::ObjectPath(kAgentPath),
134 base::Bind(&base::DoNothing), 135 base::Bind(&base::DoNothing),
135 base::Bind(&OnUnregisterAgentError)); 136 base::Bind(&OnUnregisterAgentError));
136 137
137 agent_.reset(); 138 agent_.reset();
138 dbus_is_shutdown_ = true; 139 dbus_is_shutdown_ = true;
139 } 140 }
140 141
(...skipping 14 matching lines...) Expand all
155 dbus::Bus* system_bus = bluez::BluezDBusManager::Get()->GetSystemBus(); 156 dbus::Bus* system_bus = bluez::BluezDBusManager::Get()->GetSystemBus();
156 agent_.reset(bluez::BluetoothAgentServiceProvider::Create( 157 agent_.reset(bluez::BluetoothAgentServiceProvider::Create(
157 system_bus, dbus::ObjectPath(kAgentPath), this)); 158 system_bus, dbus::ObjectPath(kAgentPath), this));
158 DCHECK(agent_.get()); 159 DCHECK(agent_.get());
159 160
160 std::vector<dbus::ObjectPath> object_paths = bluez::BluezDBusManager::Get() 161 std::vector<dbus::ObjectPath> object_paths = bluez::BluezDBusManager::Get()
161 ->GetBluetoothAdapterClient() 162 ->GetBluetoothAdapterClient()
162 ->GetAdapters(); 163 ->GetAdapters();
163 164
164 if (!object_paths.empty()) { 165 if (!object_paths.empty()) {
165 VLOG(1) << object_paths.size() << " Bluetooth adapter(s) available."; 166 BLUETOOTH_LOG(EVENT) << object_paths.size()
167 << " Bluetooth adapter(s) available.";
166 SetAdapter(object_paths[0]); 168 SetAdapter(object_paths[0]);
167 } 169 }
168 } 170 }
169 171
170 BluetoothAdapterBlueZ::~BluetoothAdapterBlueZ() { 172 BluetoothAdapterBlueZ::~BluetoothAdapterBlueZ() {
171 Shutdown(); 173 Shutdown();
172 } 174 }
173 175
174 std::string BluetoothAdapterBlueZ::GetAddress() const { 176 std::string BluetoothAdapterBlueZ::GetAddress() const {
175 if (!IsPresent()) 177 if (!IsPresent())
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
292 294
293 return properties->discovering.value(); 295 return properties->discovering.value();
294 } 296 }
295 297
296 void BluetoothAdapterBlueZ::CreateRfcommService( 298 void BluetoothAdapterBlueZ::CreateRfcommService(
297 const BluetoothUUID& uuid, 299 const BluetoothUUID& uuid,
298 const ServiceOptions& options, 300 const ServiceOptions& options,
299 const CreateServiceCallback& callback, 301 const CreateServiceCallback& callback,
300 const CreateServiceErrorCallback& error_callback) { 302 const CreateServiceErrorCallback& error_callback) {
301 DCHECK(!dbus_is_shutdown_); 303 DCHECK(!dbus_is_shutdown_);
302 VLOG(1) << object_path_.value() 304 BLUETOOTH_LOG(EVENT) << object_path_.value() << ": Creating RFCOMM service: "
303 << ": Creating RFCOMM service: " << uuid.canonical_value(); 305 << uuid.canonical_value();
304 scoped_refptr<BluetoothSocketBlueZ> socket = 306 scoped_refptr<BluetoothSocketBlueZ> socket =
305 BluetoothSocketBlueZ::CreateBluetoothSocket(ui_task_runner_, 307 BluetoothSocketBlueZ::CreateBluetoothSocket(ui_task_runner_,
306 socket_thread_); 308 socket_thread_);
307 socket->Listen(this, BluetoothSocketBlueZ::kRfcomm, uuid, options, 309 socket->Listen(this, BluetoothSocketBlueZ::kRfcomm, uuid, options,
308 base::Bind(callback, socket), error_callback); 310 base::Bind(callback, socket), error_callback);
309 } 311 }
310 312
311 void BluetoothAdapterBlueZ::CreateL2capService( 313 void BluetoothAdapterBlueZ::CreateL2capService(
312 const BluetoothUUID& uuid, 314 const BluetoothUUID& uuid,
313 const ServiceOptions& options, 315 const ServiceOptions& options,
314 const CreateServiceCallback& callback, 316 const CreateServiceCallback& callback,
315 const CreateServiceErrorCallback& error_callback) { 317 const CreateServiceErrorCallback& error_callback) {
316 DCHECK(!dbus_is_shutdown_); 318 DCHECK(!dbus_is_shutdown_);
317 VLOG(1) << object_path_.value() 319 BLUETOOTH_LOG(EVENT) << object_path_.value() << ": Creating L2CAP service: "
318 << ": Creating L2CAP service: " << uuid.canonical_value(); 320 << uuid.canonical_value();
319 scoped_refptr<BluetoothSocketBlueZ> socket = 321 scoped_refptr<BluetoothSocketBlueZ> socket =
320 BluetoothSocketBlueZ::CreateBluetoothSocket(ui_task_runner_, 322 BluetoothSocketBlueZ::CreateBluetoothSocket(ui_task_runner_,
321 socket_thread_); 323 socket_thread_);
322 socket->Listen(this, BluetoothSocketBlueZ::kL2cap, uuid, options, 324 socket->Listen(this, BluetoothSocketBlueZ::kL2cap, uuid, options,
323 base::Bind(callback, socket), error_callback); 325 base::Bind(callback, socket), error_callback);
324 } 326 }
325 327
326 void BluetoothAdapterBlueZ::RegisterAudioSink( 328 void BluetoothAdapterBlueZ::RegisterAudioSink(
327 const BluetoothAudioSink::Options& options, 329 const BluetoothAudioSink::Options& options,
328 const device::BluetoothAdapter::AcquiredCallback& callback, 330 const device::BluetoothAdapter::AcquiredCallback& callback,
329 const BluetoothAudioSink::ErrorCallback& error_callback) { 331 const BluetoothAudioSink::ErrorCallback& error_callback) {
330 VLOG(1) << "Registering audio sink"; 332 BLUETOOTH_LOG(EVENT) << "Registering audio sink";
331 if (!this->IsPresent()) { 333 if (!this->IsPresent()) {
332 error_callback.Run(BluetoothAudioSink::ERROR_INVALID_ADAPTER); 334 error_callback.Run(BluetoothAudioSink::ERROR_INVALID_ADAPTER);
333 return; 335 return;
334 } 336 }
335 scoped_refptr<BluetoothAudioSinkBlueZ> audio_sink( 337 scoped_refptr<BluetoothAudioSinkBlueZ> audio_sink(
336 new BluetoothAudioSinkBlueZ(this)); 338 new BluetoothAudioSinkBlueZ(this));
337 audio_sink->Register(options, 339 audio_sink->Register(options,
338 base::Bind(&BluetoothAdapterBlueZ::OnRegisterAudioSink, 340 base::Bind(&BluetoothAdapterBlueZ::OnRegisterAudioSink,
339 weak_ptr_factory_.GetWeakPtr(), callback, 341 weak_ptr_factory_.GetWeakPtr(), callback,
340 error_callback, audio_sink), 342 error_callback, audio_sink),
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
443 445
444 bluez::BluetoothDeviceClient::Properties* properties = 446 bluez::BluetoothDeviceClient::Properties* properties =
445 bluez::BluezDBusManager::Get()->GetBluetoothDeviceClient()->GetProperties( 447 bluez::BluezDBusManager::Get()->GetBluetoothDeviceClient()->GetProperties(
446 object_path); 448 object_path);
447 449
448 if (property_name == properties->address.name()) { 450 if (property_name == properties->address.name()) {
449 for (DevicesMap::iterator iter = devices_.begin(); iter != devices_.end(); 451 for (DevicesMap::iterator iter = devices_.begin(); iter != devices_.end();
450 ++iter) { 452 ++iter) {
451 if (iter->second->GetAddress() == device_bluez->GetAddress()) { 453 if (iter->second->GetAddress() == device_bluez->GetAddress()) {
452 std::string old_address = iter->first; 454 std::string old_address = iter->first;
453 VLOG(1) << "Device changed address, old: " << old_address 455 BLUETOOTH_LOG(EVENT) << "Device changed address, old: " << old_address
454 << " new: " << device_bluez->GetAddress(); 456 << " new: " << device_bluez->GetAddress();
455 scoped_ptr<BluetoothDevice> scoped_device = 457 scoped_ptr<BluetoothDevice> scoped_device =
456 devices_.take_and_erase(iter); 458 devices_.take_and_erase(iter);
457 ignore_result(scoped_device.release()); 459 ignore_result(scoped_device.release());
458 460
459 DCHECK(devices_.find(device_bluez->GetAddress()) == devices_.end()); 461 DCHECK(devices_.find(device_bluez->GetAddress()) == devices_.end());
460 devices_.set(device_bluez->GetAddress(), 462 devices_.set(device_bluez->GetAddress(),
461 scoped_ptr<BluetoothDevice>(device_bluez)); 463 scoped_ptr<BluetoothDevice>(device_bluez));
462 NotifyDeviceAddressChanged(device_bluez, old_address); 464 NotifyDeviceAddressChanged(device_bluez, old_address);
463 break; 465 break;
464 } 466 }
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
522 524
523 // Properties structure can be removed, which triggers a change in the 525 // Properties structure can be removed, which triggers a change in the
524 // BluetoothDevice::IsConnectable() property, as does a change in the 526 // BluetoothDevice::IsConnectable() property, as does a change in the
525 // actual reconnect_mode property. 527 // actual reconnect_mode property.
526 if (!properties || property_name == properties->reconnect_mode.name()) { 528 if (!properties || property_name == properties->reconnect_mode.name()) {
527 NotifyDeviceChanged(device_bluez); 529 NotifyDeviceChanged(device_bluez);
528 } 530 }
529 } 531 }
530 532
531 void BluetoothAdapterBlueZ::Released() { 533 void BluetoothAdapterBlueZ::Released() {
532 VLOG(1) << "Release"; 534 BLUETOOTH_LOG(EVENT) << "Release";
533 if (!IsPresent()) 535 if (!IsPresent())
534 return; 536 return;
535 DCHECK(agent_.get()); 537 DCHECK(agent_.get());
536 538
537 // Called after we unregister the pairing agent, e.g. when changing I/O 539 // Called after we unregister the pairing agent, e.g. when changing I/O
538 // capabilities. Nothing much to be done right now. 540 // capabilities. Nothing much to be done right now.
539 } 541 }
540 542
541 void BluetoothAdapterBlueZ::RequestPinCode(const dbus::ObjectPath& device_path, 543 void BluetoothAdapterBlueZ::RequestPinCode(const dbus::ObjectPath& device_path,
542 const PinCodeCallback& callback) { 544 const PinCodeCallback& callback) {
543 DCHECK(IsPresent()); 545 DCHECK(IsPresent());
544 DCHECK(agent_.get()); 546 DCHECK(agent_.get());
545 VLOG(1) << device_path.value() << ": RequestPinCode"; 547 BLUETOOTH_LOG(EVENT) << device_path.value() << ": RequestPinCode";
546 548
547 BluetoothPairingBlueZ* pairing = GetPairing(device_path); 549 BluetoothPairingBlueZ* pairing = GetPairing(device_path);
548 if (!pairing) { 550 if (!pairing) {
549 callback.Run(REJECTED, ""); 551 callback.Run(REJECTED, "");
550 return; 552 return;
551 } 553 }
552 554
553 pairing->RequestPinCode(callback); 555 pairing->RequestPinCode(callback);
554 } 556 }
555 557
556 void BluetoothAdapterBlueZ::DisplayPinCode(const dbus::ObjectPath& device_path, 558 void BluetoothAdapterBlueZ::DisplayPinCode(const dbus::ObjectPath& device_path,
557 const std::string& pincode) { 559 const std::string& pincode) {
558 DCHECK(IsPresent()); 560 DCHECK(IsPresent());
559 DCHECK(agent_.get()); 561 DCHECK(agent_.get());
560 VLOG(1) << device_path.value() << ": DisplayPinCode: " << pincode; 562 BLUETOOTH_LOG(EVENT) << device_path.value()
563 << ": DisplayPinCode: " << pincode;
561 564
562 BluetoothPairingBlueZ* pairing = GetPairing(device_path); 565 BluetoothPairingBlueZ* pairing = GetPairing(device_path);
563 if (!pairing) 566 if (!pairing)
564 return; 567 return;
565 568
566 pairing->DisplayPinCode(pincode); 569 pairing->DisplayPinCode(pincode);
567 } 570 }
568 571
569 void BluetoothAdapterBlueZ::RequestPasskey(const dbus::ObjectPath& device_path, 572 void BluetoothAdapterBlueZ::RequestPasskey(const dbus::ObjectPath& device_path,
570 const PasskeyCallback& callback) { 573 const PasskeyCallback& callback) {
571 DCHECK(IsPresent()); 574 DCHECK(IsPresent());
572 DCHECK(agent_.get()); 575 DCHECK(agent_.get());
573 VLOG(1) << device_path.value() << ": RequestPasskey"; 576 BLUETOOTH_LOG(EVENT) << device_path.value() << ": RequestPasskey";
574 577
575 BluetoothPairingBlueZ* pairing = GetPairing(device_path); 578 BluetoothPairingBlueZ* pairing = GetPairing(device_path);
576 if (!pairing) { 579 if (!pairing) {
577 callback.Run(REJECTED, 0); 580 callback.Run(REJECTED, 0);
578 return; 581 return;
579 } 582 }
580 583
581 pairing->RequestPasskey(callback); 584 pairing->RequestPasskey(callback);
582 } 585 }
583 586
584 void BluetoothAdapterBlueZ::DisplayPasskey(const dbus::ObjectPath& device_path, 587 void BluetoothAdapterBlueZ::DisplayPasskey(const dbus::ObjectPath& device_path,
585 uint32_t passkey, 588 uint32_t passkey,
586 uint16_t entered) { 589 uint16_t entered) {
587 DCHECK(IsPresent()); 590 DCHECK(IsPresent());
588 DCHECK(agent_.get()); 591 DCHECK(agent_.get());
589 VLOG(1) << device_path.value() << ": DisplayPasskey: " << passkey << " (" 592 BLUETOOTH_LOG(EVENT) << device_path.value() << ": DisplayPasskey: " << passkey
590 << entered << " entered)"; 593 << " (" << entered << " entered)";
591 594
592 BluetoothPairingBlueZ* pairing = GetPairing(device_path); 595 BluetoothPairingBlueZ* pairing = GetPairing(device_path);
593 if (!pairing) 596 if (!pairing)
594 return; 597 return;
595 598
596 if (entered == 0) 599 if (entered == 0)
597 pairing->DisplayPasskey(passkey); 600 pairing->DisplayPasskey(passkey);
598 601
599 pairing->KeysEntered(entered); 602 pairing->KeysEntered(entered);
600 } 603 }
601 604
602 void BluetoothAdapterBlueZ::RequestConfirmation( 605 void BluetoothAdapterBlueZ::RequestConfirmation(
603 const dbus::ObjectPath& device_path, 606 const dbus::ObjectPath& device_path,
604 uint32_t passkey, 607 uint32_t passkey,
605 const ConfirmationCallback& callback) { 608 const ConfirmationCallback& callback) {
606 DCHECK(IsPresent()); 609 DCHECK(IsPresent());
607 DCHECK(agent_.get()); 610 DCHECK(agent_.get());
608 VLOG(1) << device_path.value() << ": RequestConfirmation: " << passkey; 611 BLUETOOTH_LOG(EVENT) << device_path.value()
612 << ": RequestConfirmation: " << passkey;
609 613
610 BluetoothPairingBlueZ* pairing = GetPairing(device_path); 614 BluetoothPairingBlueZ* pairing = GetPairing(device_path);
611 if (!pairing) { 615 if (!pairing) {
612 callback.Run(REJECTED); 616 callback.Run(REJECTED);
613 return; 617 return;
614 } 618 }
615 619
616 pairing->RequestConfirmation(passkey, callback); 620 pairing->RequestConfirmation(passkey, callback);
617 } 621 }
618 622
619 void BluetoothAdapterBlueZ::RequestAuthorization( 623 void BluetoothAdapterBlueZ::RequestAuthorization(
620 const dbus::ObjectPath& device_path, 624 const dbus::ObjectPath& device_path,
621 const ConfirmationCallback& callback) { 625 const ConfirmationCallback& callback) {
622 DCHECK(IsPresent()); 626 DCHECK(IsPresent());
623 DCHECK(agent_.get()); 627 DCHECK(agent_.get());
624 VLOG(1) << device_path.value() << ": RequestAuthorization"; 628 BLUETOOTH_LOG(EVENT) << device_path.value() << ": RequestAuthorization";
625 629
626 BluetoothPairingBlueZ* pairing = GetPairing(device_path); 630 BluetoothPairingBlueZ* pairing = GetPairing(device_path);
627 if (!pairing) { 631 if (!pairing) {
628 callback.Run(REJECTED); 632 callback.Run(REJECTED);
629 return; 633 return;
630 } 634 }
631 635
632 pairing->RequestAuthorization(callback); 636 pairing->RequestAuthorization(callback);
633 } 637 }
634 638
635 void BluetoothAdapterBlueZ::AuthorizeService( 639 void BluetoothAdapterBlueZ::AuthorizeService(
636 const dbus::ObjectPath& device_path, 640 const dbus::ObjectPath& device_path,
637 const std::string& uuid, 641 const std::string& uuid,
638 const ConfirmationCallback& callback) { 642 const ConfirmationCallback& callback) {
639 DCHECK(IsPresent()); 643 DCHECK(IsPresent());
640 DCHECK(agent_.get()); 644 DCHECK(agent_.get());
641 VLOG(1) << device_path.value() << ": AuthorizeService: " << uuid; 645 BLUETOOTH_LOG(EVENT) << device_path.value() << ": AuthorizeService: " << uuid;
642 646
643 BluetoothDeviceBlueZ* device_bluez = GetDeviceWithPath(device_path); 647 BluetoothDeviceBlueZ* device_bluez = GetDeviceWithPath(device_path);
644 if (!device_bluez) { 648 if (!device_bluez) {
645 callback.Run(CANCELLED); 649 callback.Run(CANCELLED);
646 return; 650 return;
647 } 651 }
648 652
649 // We always set paired devices to Trusted, so the only reason that this 653 // We always set paired devices to Trusted, so the only reason that this
650 // method call would ever be called is in the case of a race condition where 654 // method call would ever be called is in the case of a race condition where
651 // our "Set('Trusted', true)" method call is still pending in the Bluetooth 655 // our "Set('Trusted', true)" method call is still pending in the Bluetooth
652 // daemon because it's busy handling the incoming connection. 656 // daemon because it's busy handling the incoming connection.
653 if (device_bluez->IsPaired()) { 657 if (device_bluez->IsPaired()) {
654 callback.Run(SUCCESS); 658 callback.Run(SUCCESS);
655 return; 659 return;
656 } 660 }
657 661
658 // TODO(keybuk): reject service authorizations when not paired, determine 662 // TODO(keybuk): reject service authorizations when not paired, determine
659 // whether this is acceptable long-term. 663 // whether this is acceptable long-term.
660 LOG(WARNING) << "Rejecting service connection from unpaired device " 664 LOG(WARNING) << "Rejecting service connection from unpaired device "
661 << device_bluez->GetAddress() << " for UUID " << uuid; 665 << device_bluez->GetAddress() << " for UUID " << uuid;
662 callback.Run(REJECTED); 666 callback.Run(REJECTED);
663 } 667 }
664 668
665 void BluetoothAdapterBlueZ::Cancel() { 669 void BluetoothAdapterBlueZ::Cancel() {
666 DCHECK(IsPresent()); 670 DCHECK(IsPresent());
667 DCHECK(agent_.get()); 671 DCHECK(agent_.get());
668 VLOG(1) << "Cancel"; 672 BLUETOOTH_LOG(EVENT) << "Cancel";
669 } 673 }
670 674
671 void BluetoothAdapterBlueZ::OnRegisterAgent() { 675 void BluetoothAdapterBlueZ::OnRegisterAgent() {
672 VLOG(1) << "Pairing agent registered, requesting to be made default"; 676 BLUETOOTH_LOG(EVENT) << "Pairing agent registered, "
677 << "requesting to be made default";
673 678
674 bluez::BluezDBusManager::Get() 679 bluez::BluezDBusManager::Get()
675 ->GetBluetoothAgentManagerClient() 680 ->GetBluetoothAgentManagerClient()
676 ->RequestDefaultAgent( 681 ->RequestDefaultAgent(
677 dbus::ObjectPath(kAgentPath), 682 dbus::ObjectPath(kAgentPath),
678 base::Bind(&BluetoothAdapterBlueZ::OnRequestDefaultAgent, 683 base::Bind(&BluetoothAdapterBlueZ::OnRequestDefaultAgent,
679 weak_ptr_factory_.GetWeakPtr()), 684 weak_ptr_factory_.GetWeakPtr()),
680 base::Bind(&BluetoothAdapterBlueZ::OnRequestDefaultAgentError, 685 base::Bind(&BluetoothAdapterBlueZ::OnRequestDefaultAgentError,
681 weak_ptr_factory_.GetWeakPtr())); 686 weak_ptr_factory_.GetWeakPtr()));
682 } 687 }
683 688
684 void BluetoothAdapterBlueZ::OnRegisterAgentError( 689 void BluetoothAdapterBlueZ::OnRegisterAgentError(
685 const std::string& error_name, 690 const std::string& error_name,
686 const std::string& error_message) { 691 const std::string& error_message) {
687 // Our agent being already registered isn't an error. 692 // Our agent being already registered isn't an error.
688 if (error_name == bluetooth_agent_manager::kErrorAlreadyExists) 693 if (error_name == bluetooth_agent_manager::kErrorAlreadyExists)
689 return; 694 return;
690 695
691 LOG(WARNING) << ": Failed to register pairing agent: " << error_name << ": " 696 LOG(WARNING) << ": Failed to register pairing agent: " << error_name << ": "
692 << error_message; 697 << error_message;
693 } 698 }
694 699
695 void BluetoothAdapterBlueZ::OnRequestDefaultAgent() { 700 void BluetoothAdapterBlueZ::OnRequestDefaultAgent() {
696 VLOG(1) << "Pairing agent now default"; 701 BLUETOOTH_LOG(EVENT) << "Pairing agent now default";
697 } 702 }
698 703
699 void BluetoothAdapterBlueZ::OnRequestDefaultAgentError( 704 void BluetoothAdapterBlueZ::OnRequestDefaultAgentError(
700 const std::string& error_name, 705 const std::string& error_name,
701 const std::string& error_message) { 706 const std::string& error_message) {
702 LOG(WARNING) << ": Failed to make pairing agent default: " << error_name 707 LOG(WARNING) << ": Failed to make pairing agent default: " << error_name
703 << ": " << error_message; 708 << ": " << error_message;
704 } 709 }
705 710
706 void BluetoothAdapterBlueZ::OnRegisterAudioSink( 711 void BluetoothAdapterBlueZ::OnRegisterAudioSink(
707 const device::BluetoothAdapter::AcquiredCallback& callback, 712 const device::BluetoothAdapter::AcquiredCallback& callback,
708 const device::BluetoothAudioSink::ErrorCallback& error_callback, 713 const device::BluetoothAudioSink::ErrorCallback& error_callback,
709 scoped_refptr<BluetoothAudioSink> audio_sink) { 714 scoped_refptr<BluetoothAudioSink> audio_sink) {
710 if (!IsPresent()) { 715 if (!IsPresent()) {
711 VLOG(1) << "Failed to register audio sink, adapter not present"; 716 BLUETOOTH_LOG(ERROR) << "Failed to register audio sink, "
717 << "adapter not present";
712 error_callback.Run(BluetoothAudioSink::ERROR_INVALID_ADAPTER); 718 error_callback.Run(BluetoothAudioSink::ERROR_INVALID_ADAPTER);
713 return; 719 return;
714 } 720 }
715 DCHECK(audio_sink.get()); 721 DCHECK(audio_sink.get());
716 callback.Run(audio_sink); 722 callback.Run(audio_sink);
717 } 723 }
718 724
719 BluetoothDeviceBlueZ* BluetoothAdapterBlueZ::GetDeviceWithPath( 725 BluetoothDeviceBlueZ* BluetoothAdapterBlueZ::GetDeviceWithPath(
720 const dbus::ObjectPath& object_path) { 726 const dbus::ObjectPath& object_path) {
721 if (!IsPresent()) 727 if (!IsPresent())
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
753 return nullptr; 759 return nullptr;
754 760
755 return device_bluez->BeginPairing(pairing_delegate); 761 return device_bluez->BeginPairing(pairing_delegate);
756 } 762 }
757 763
758 void BluetoothAdapterBlueZ::SetAdapter(const dbus::ObjectPath& object_path) { 764 void BluetoothAdapterBlueZ::SetAdapter(const dbus::ObjectPath& object_path) {
759 DCHECK(!IsPresent()); 765 DCHECK(!IsPresent());
760 DCHECK(!dbus_is_shutdown_); 766 DCHECK(!dbus_is_shutdown_);
761 object_path_ = object_path; 767 object_path_ = object_path;
762 768
763 VLOG(1) << object_path_.value() << ": using adapter."; 769 BLUETOOTH_LOG(EVENT) << object_path_.value() << ": using adapter.";
764 770
765 VLOG(1) << "Registering pairing agent"; 771 BLUETOOTH_LOG(EVENT) << "Registering pairing agent";
766 bluez::BluezDBusManager::Get() 772 bluez::BluezDBusManager::Get()
767 ->GetBluetoothAgentManagerClient() 773 ->GetBluetoothAgentManagerClient()
768 ->RegisterAgent(dbus::ObjectPath(kAgentPath), 774 ->RegisterAgent(dbus::ObjectPath(kAgentPath),
769 bluetooth_agent_manager::kKeyboardDisplayCapability, 775 bluetooth_agent_manager::kKeyboardDisplayCapability,
770 base::Bind(&BluetoothAdapterBlueZ::OnRegisterAgent, 776 base::Bind(&BluetoothAdapterBlueZ::OnRegisterAgent,
771 weak_ptr_factory_.GetWeakPtr()), 777 weak_ptr_factory_.GetWeakPtr()),
772 base::Bind(&BluetoothAdapterBlueZ::OnRegisterAgentError, 778 base::Bind(&BluetoothAdapterBlueZ::OnRegisterAgentError,
773 weak_ptr_factory_.GetWeakPtr())); 779 weak_ptr_factory_.GetWeakPtr()));
774 780
775 SetDefaultAdapterName(); 781 SetDefaultAdapterName();
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
823 } 829 }
824 #elif defined(OS_LINUX) 830 #elif defined(OS_LINUX)
825 alias = "ChromeLinux"; 831 alias = "ChromeLinux";
826 #endif 832 #endif
827 833
828 SetName(alias, base::Bind(&base::DoNothing), base::Bind(&base::DoNothing)); 834 SetName(alias, base::Bind(&base::DoNothing), base::Bind(&base::DoNothing));
829 } 835 }
830 836
831 void BluetoothAdapterBlueZ::RemoveAdapter() { 837 void BluetoothAdapterBlueZ::RemoveAdapter() {
832 DCHECK(IsPresent()); 838 DCHECK(IsPresent());
833 VLOG(1) << object_path_.value() << ": adapter removed."; 839 BLUETOOTH_LOG(EVENT) << object_path_.value() << ": adapter removed.";
834 840
835 bluez::BluetoothAdapterClient::Properties* properties = 841 bluez::BluetoothAdapterClient::Properties* properties =
836 bluez::BluezDBusManager::Get() 842 bluez::BluezDBusManager::Get()
837 ->GetBluetoothAdapterClient() 843 ->GetBluetoothAdapterClient()
838 ->GetProperties(object_path_); 844 ->GetProperties(object_path_);
839 845
840 object_path_ = dbus::ObjectPath(""); 846 object_path_ = dbus::ObjectPath("");
841 847
842 if (properties->powered.value()) 848 if (properties->powered.value())
843 PoweredChanged(false); 849 PoweredChanged(false);
(...skipping 22 matching lines...) Expand all
866 } 872 }
867 873
868 void BluetoothAdapterBlueZ::DiscoverableChanged(bool discoverable) { 874 void BluetoothAdapterBlueZ::DiscoverableChanged(bool discoverable) {
869 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_, 875 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_,
870 AdapterDiscoverableChanged(this, discoverable)); 876 AdapterDiscoverableChanged(this, discoverable));
871 } 877 }
872 878
873 void BluetoothAdapterBlueZ::DiscoveringChanged(bool discovering) { 879 void BluetoothAdapterBlueZ::DiscoveringChanged(bool discovering) {
874 // If the adapter stopped discovery due to a reason other than a request by 880 // If the adapter stopped discovery due to a reason other than a request by
875 // us, reset the count to 0. 881 // us, reset the count to 0.
876 VLOG(1) << "Discovering changed: " << discovering; 882 BLUETOOTH_LOG(EVENT) << "Discovering changed: " << discovering;
877 if (!discovering && !discovery_request_pending_ && 883 if (!discovering && !discovery_request_pending_ &&
878 num_discovery_sessions_ > 0) { 884 num_discovery_sessions_ > 0) {
879 VLOG(1) << "Marking sessions as inactive."; 885 BLUETOOTH_LOG(EVENT) << "Marking sessions as inactive.";
880 num_discovery_sessions_ = 0; 886 num_discovery_sessions_ = 0;
881 MarkDiscoverySessionsAsInactive(); 887 MarkDiscoverySessionsAsInactive();
882 } 888 }
883 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_, 889 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_,
884 AdapterDiscoveringChanged(this, discovering)); 890 AdapterDiscoveringChanged(this, discovering));
885 } 891 }
886 892
887 void BluetoothAdapterBlueZ::PresentChanged(bool present) { 893 void BluetoothAdapterBlueZ::PresentChanged(bool present) {
888 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_, 894 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_,
889 AdapterPresentChanged(this, present)); 895 AdapterPresentChanged(this, present));
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
1022 void BluetoothAdapterBlueZ::UseProfile( 1028 void BluetoothAdapterBlueZ::UseProfile(
1023 const BluetoothUUID& uuid, 1029 const BluetoothUUID& uuid,
1024 const dbus::ObjectPath& device_path, 1030 const dbus::ObjectPath& device_path,
1025 const bluez::BluetoothProfileManagerClient::Options& options, 1031 const bluez::BluetoothProfileManagerClient::Options& options,
1026 bluez::BluetoothProfileServiceProvider::Delegate* delegate, 1032 bluez::BluetoothProfileServiceProvider::Delegate* delegate,
1027 const ProfileRegisteredCallback& success_callback, 1033 const ProfileRegisteredCallback& success_callback,
1028 const ErrorCompletionCallback& error_callback) { 1034 const ErrorCompletionCallback& error_callback) {
1029 DCHECK(delegate); 1035 DCHECK(delegate);
1030 1036
1031 if (!IsPresent()) { 1037 if (!IsPresent()) {
1032 VLOG(2) << "Adapter not present, erroring out"; 1038 BLUETOOTH_LOG(ERROR) << "Adapter not present, erroring out";
1033 error_callback.Run("Adapter not present"); 1039 error_callback.Run("Adapter not present");
1034 return; 1040 return;
1035 } 1041 }
1036 1042
1037 if (profiles_.find(uuid) != profiles_.end()) { 1043 if (profiles_.find(uuid) != profiles_.end()) {
1038 // TODO(jamuraa) check that the options are the same and error when they are 1044 // TODO(jamuraa) check that the options are the same and error when they are
1039 // not. 1045 // not.
1040 SetProfileDelegate(uuid, device_path, delegate, success_callback, 1046 SetProfileDelegate(uuid, device_path, delegate, success_callback,
1041 error_callback); 1047 error_callback);
1042 return; 1048 return;
(...skipping 10 matching lines...) Expand all
1053 1059
1054 profile_queues_[uuid]->push_back(std::make_pair( 1060 profile_queues_[uuid]->push_back(std::make_pair(
1055 base::Bind(&BluetoothAdapterBlueZ::SetProfileDelegate, this, uuid, 1061 base::Bind(&BluetoothAdapterBlueZ::SetProfileDelegate, this, uuid,
1056 device_path, delegate, success_callback, error_callback), 1062 device_path, delegate, success_callback, error_callback),
1057 error_callback)); 1063 error_callback));
1058 } 1064 }
1059 1065
1060 void BluetoothAdapterBlueZ::ReleaseProfile( 1066 void BluetoothAdapterBlueZ::ReleaseProfile(
1061 const dbus::ObjectPath& device_path, 1067 const dbus::ObjectPath& device_path,
1062 BluetoothAdapterProfileBlueZ* profile) { 1068 BluetoothAdapterProfileBlueZ* profile) {
1063 VLOG(2) << "Releasing Profile: " << profile->uuid().canonical_value() 1069 BLUETOOTH_LOG(EVENT) << "Releasing Profile: "
1064 << " from " << device_path.value(); 1070 << profile->uuid().canonical_value() << " from "
1071 << device_path.value();
1065 profile->RemoveDelegate( 1072 profile->RemoveDelegate(
1066 device_path, base::Bind(&BluetoothAdapterBlueZ::RemoveProfile, 1073 device_path, base::Bind(&BluetoothAdapterBlueZ::RemoveProfile,
1067 weak_ptr_factory_.GetWeakPtr(), profile->uuid())); 1074 weak_ptr_factory_.GetWeakPtr(), profile->uuid()));
1068 } 1075 }
1069 1076
1070 void BluetoothAdapterBlueZ::RemoveProfile(const BluetoothUUID& uuid) { 1077 void BluetoothAdapterBlueZ::RemoveProfile(const BluetoothUUID& uuid) {
1071 VLOG(2) << "Remove Profile: " << uuid.canonical_value(); 1078 BLUETOOTH_LOG(EVENT) << "Remove Profile: " << uuid.canonical_value();
1072 1079
1073 if (profiles_.find(uuid) != profiles_.end()) { 1080 if (profiles_.find(uuid) != profiles_.end()) {
1074 delete profiles_[uuid]; 1081 delete profiles_[uuid];
1075 profiles_.erase(uuid); 1082 profiles_.erase(uuid);
1076 } 1083 }
1077 } 1084 }
1078 1085
1079 void BluetoothAdapterBlueZ::OnRegisterProfile( 1086 void BluetoothAdapterBlueZ::OnRegisterProfile(
1080 const BluetoothUUID& uuid, 1087 const BluetoothUUID& uuid,
1081 scoped_ptr<BluetoothAdapterProfileBlueZ> profile) { 1088 scoped_ptr<BluetoothAdapterProfileBlueZ> profile) {
(...skipping 24 matching lines...) Expand all
1106 return; 1113 return;
1107 } 1114 }
1108 // Already set 1115 // Already set
1109 error_callback.Run(bluetooth_agent_manager::kErrorAlreadyExists); 1116 error_callback.Run(bluetooth_agent_manager::kErrorAlreadyExists);
1110 } 1117 }
1111 1118
1112 void BluetoothAdapterBlueZ::OnRegisterProfileError( 1119 void BluetoothAdapterBlueZ::OnRegisterProfileError(
1113 const BluetoothUUID& uuid, 1120 const BluetoothUUID& uuid,
1114 const std::string& error_name, 1121 const std::string& error_name,
1115 const std::string& error_message) { 1122 const std::string& error_message) {
1116 VLOG(2) << object_path_.value() 1123 BLUETOOTH_LOG(ERROR) << object_path_.value()
1117 << ": Failed to register profile: " << error_name << ": " 1124 << ": Failed to register profile: " << error_name << ": "
1118 << error_message; 1125 << error_message;
1119 if (profile_queues_.find(uuid) == profile_queues_.end()) 1126 if (profile_queues_.find(uuid) == profile_queues_.end())
1120 return; 1127 return;
1121 1128
1122 for (auto& it : *profile_queues_[uuid]) 1129 for (auto& it : *profile_queues_[uuid])
1123 it.second.Run(error_message); 1130 it.second.Run(error_message);
1124 1131
1125 delete profile_queues_[uuid]; 1132 delete profile_queues_[uuid];
1126 profile_queues_.erase(uuid); 1133 profile_queues_.erase(uuid);
1127 } 1134 }
1128 1135
(...skipping 30 matching lines...) Expand all
1159 1166
1160 void BluetoothAdapterBlueZ::AddDiscoverySession( 1167 void BluetoothAdapterBlueZ::AddDiscoverySession(
1161 BluetoothDiscoveryFilter* discovery_filter, 1168 BluetoothDiscoveryFilter* discovery_filter,
1162 const base::Closure& callback, 1169 const base::Closure& callback,
1163 const DiscoverySessionErrorCallback& error_callback) { 1170 const DiscoverySessionErrorCallback& error_callback) {
1164 if (!IsPresent()) { 1171 if (!IsPresent()) {
1165 error_callback.Run( 1172 error_callback.Run(
1166 UMABluetoothDiscoverySessionOutcome::ADAPTER_NOT_PRESENT); 1173 UMABluetoothDiscoverySessionOutcome::ADAPTER_NOT_PRESENT);
1167 return; 1174 return;
1168 } 1175 }
1169 VLOG(1) << __func__; 1176 BLUETOOTH_LOG(DEBUG) << __func__;
1170 if (discovery_request_pending_) { 1177 if (discovery_request_pending_) {
1171 // The pending request is either to stop a previous session or to start a 1178 // The pending request is either to stop a previous session or to start a
1172 // new one. Either way, queue this one. 1179 // new one. Either way, queue this one.
1173 DCHECK(num_discovery_sessions_ == 1 || num_discovery_sessions_ == 0); 1180 DCHECK(num_discovery_sessions_ == 1 || num_discovery_sessions_ == 0);
1174 VLOG(1) << "Pending request to start/stop device discovery. Queueing " 1181 BLUETOOTH_LOG(EVENT)
1175 << "request to start a new discovery session."; 1182 << "Pending request to start/stop device discovery. "
1183 << "Queueing request to start a new discovery session.";
1176 discovery_request_queue_.push( 1184 discovery_request_queue_.push(
1177 std::make_tuple(discovery_filter, callback, error_callback)); 1185 std::make_tuple(discovery_filter, callback, error_callback));
1178 return; 1186 return;
1179 } 1187 }
1180 1188
1181 // The adapter is already discovering. 1189 // The adapter is already discovering.
1182 if (num_discovery_sessions_ > 0) { 1190 if (num_discovery_sessions_ > 0) {
1183 DCHECK(IsDiscovering()); 1191 DCHECK(IsDiscovering());
1184 DCHECK(!discovery_request_pending_); 1192 DCHECK(!discovery_request_pending_);
1185 num_discovery_sessions_++; 1193 num_discovery_sessions_++;
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
1222 void BluetoothAdapterBlueZ::RemoveDiscoverySession( 1230 void BluetoothAdapterBlueZ::RemoveDiscoverySession(
1223 BluetoothDiscoveryFilter* discovery_filter, 1231 BluetoothDiscoveryFilter* discovery_filter,
1224 const base::Closure& callback, 1232 const base::Closure& callback,
1225 const DiscoverySessionErrorCallback& error_callback) { 1233 const DiscoverySessionErrorCallback& error_callback) {
1226 if (!IsPresent()) { 1234 if (!IsPresent()) {
1227 error_callback.Run( 1235 error_callback.Run(
1228 UMABluetoothDiscoverySessionOutcome::ADAPTER_NOT_PRESENT); 1236 UMABluetoothDiscoverySessionOutcome::ADAPTER_NOT_PRESENT);
1229 return; 1237 return;
1230 } 1238 }
1231 1239
1232 VLOG(1) << __func__; 1240 BLUETOOTH_LOG(DEBUG) << __func__;
1233 // There are active sessions other than the one currently being removed. 1241 // There are active sessions other than the one currently being removed.
1234 if (num_discovery_sessions_ > 1) { 1242 if (num_discovery_sessions_ > 1) {
1235 DCHECK(IsDiscovering()); 1243 DCHECK(IsDiscovering());
1236 DCHECK(!discovery_request_pending_); 1244 DCHECK(!discovery_request_pending_);
1237 num_discovery_sessions_--; 1245 num_discovery_sessions_--;
1238 1246
1239 SetDiscoveryFilter(GetMergedDiscoveryFilterMasked(discovery_filter), 1247 SetDiscoveryFilter(GetMergedDiscoveryFilterMasked(discovery_filter),
1240 callback, error_callback); 1248 callback, error_callback);
1241 return; 1249 return;
1242 } 1250 }
1243 1251
1244 // If there is a pending request to BlueZ, then queue this request. 1252 // If there is a pending request to BlueZ, then queue this request.
1245 if (discovery_request_pending_) { 1253 if (discovery_request_pending_) {
1246 VLOG(1) << "Pending request to start/stop device discovery. Queueing " 1254 BLUETOOTH_LOG(EVENT) << "Pending request to start/stop device discovery. "
1247 << "request to stop discovery session."; 1255 << "Queueing request to stop discovery session.";
1248 error_callback.Run( 1256 error_callback.Run(
1249 UMABluetoothDiscoverySessionOutcome::REMOVE_WITH_PENDING_REQUEST); 1257 UMABluetoothDiscoverySessionOutcome::REMOVE_WITH_PENDING_REQUEST);
1250 return; 1258 return;
1251 } 1259 }
1252 1260
1253 // There are no active sessions. Return error. 1261 // There are no active sessions. Return error.
1254 if (num_discovery_sessions_ == 0) { 1262 if (num_discovery_sessions_ == 0) {
1255 // TODO(armansito): This should never happen once we have the 1263 // TODO(armansito): This should never happen once we have the
1256 // DiscoverySession API. Replace this case with an assert once it's 1264 // DiscoverySession API. Replace this case with an assert once it's
1257 // the deprecated methods have been removed. (See crbug.com/3445008). 1265 // the deprecated methods have been removed. (See crbug.com/3445008).
1258 VLOG(1) << "No active discovery sessions. Returning error."; 1266 BLUETOOTH_LOG(EVENT) << "No active discovery sessions. Returning error.";
1259 error_callback.Run( 1267 error_callback.Run(
1260 UMABluetoothDiscoverySessionOutcome::ACTIVE_SESSION_NOT_IN_ADAPTER); 1268 UMABluetoothDiscoverySessionOutcome::ACTIVE_SESSION_NOT_IN_ADAPTER);
1261 return; 1269 return;
1262 } 1270 }
1263 1271
1264 // There is exactly one active discovery session. Request BlueZ to stop 1272 // There is exactly one active discovery session. Request BlueZ to stop
1265 // discovery. 1273 // discovery.
1266 DCHECK_EQ(num_discovery_sessions_, 1); 1274 DCHECK_EQ(num_discovery_sessions_, 1);
1267 discovery_request_pending_ = true; 1275 discovery_request_pending_ = true;
1268 bluez::BluezDBusManager::Get()->GetBluetoothAdapterClient()->StopDiscovery( 1276 bluez::BluezDBusManager::Get()->GetBluetoothAdapterClient()->StopDiscovery(
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
1340 base::Bind(&BluetoothAdapterBlueZ::OnSetDiscoveryFilter, 1348 base::Bind(&BluetoothAdapterBlueZ::OnSetDiscoveryFilter,
1341 weak_ptr_factory_.GetWeakPtr(), callback, error_callback), 1349 weak_ptr_factory_.GetWeakPtr(), callback, error_callback),
1342 base::Bind(&BluetoothAdapterBlueZ::OnSetDiscoveryFilterError, 1350 base::Bind(&BluetoothAdapterBlueZ::OnSetDiscoveryFilterError,
1343 weak_ptr_factory_.GetWeakPtr(), callback, error_callback)); 1351 weak_ptr_factory_.GetWeakPtr(), callback, error_callback));
1344 } 1352 }
1345 1353
1346 void BluetoothAdapterBlueZ::OnStartDiscovery( 1354 void BluetoothAdapterBlueZ::OnStartDiscovery(
1347 const base::Closure& callback, 1355 const base::Closure& callback,
1348 const DiscoverySessionErrorCallback& error_callback) { 1356 const DiscoverySessionErrorCallback& error_callback) {
1349 // Report success on the original request and increment the count. 1357 // Report success on the original request and increment the count.
1350 VLOG(1) << __func__; 1358 BLUETOOTH_LOG(DEBUG) << __func__;
1351 DCHECK(discovery_request_pending_); 1359 DCHECK(discovery_request_pending_);
1352 DCHECK_EQ(num_discovery_sessions_, 0); 1360 DCHECK_EQ(num_discovery_sessions_, 0);
1353 discovery_request_pending_ = false; 1361 discovery_request_pending_ = false;
1354 num_discovery_sessions_++; 1362 num_discovery_sessions_++;
1355 if (IsPresent()) { 1363 if (IsPresent()) {
1356 callback.Run(); 1364 callback.Run();
1357 } else { 1365 } else {
1358 error_callback.Run(UMABluetoothDiscoverySessionOutcome::ADAPTER_REMOVED); 1366 error_callback.Run(UMABluetoothDiscoverySessionOutcome::ADAPTER_REMOVED);
1359 } 1367 }
1360 1368
(...skipping 13 matching lines...) Expand all
1374 // Failed to start discovery. This can only happen if the count is at 0. 1382 // Failed to start discovery. This can only happen if the count is at 0.
1375 DCHECK_EQ(num_discovery_sessions_, 0); 1383 DCHECK_EQ(num_discovery_sessions_, 0);
1376 DCHECK(discovery_request_pending_); 1384 DCHECK(discovery_request_pending_);
1377 discovery_request_pending_ = false; 1385 discovery_request_pending_ = false;
1378 1386
1379 // Discovery request may fail if discovery was previously initiated by Chrome, 1387 // Discovery request may fail if discovery was previously initiated by Chrome,
1380 // but the session were invalidated due to the discovery state unexpectedly 1388 // but the session were invalidated due to the discovery state unexpectedly
1381 // changing to false and then back to true. In this case, report success. 1389 // changing to false and then back to true. In this case, report success.
1382 if (IsPresent() && error_name == bluetooth_device::kErrorInProgress && 1390 if (IsPresent() && error_name == bluetooth_device::kErrorInProgress &&
1383 IsDiscovering()) { 1391 IsDiscovering()) {
1384 VLOG(1) << "Discovery previously initiated. Reporting success."; 1392 BLUETOOTH_LOG(EVENT)
1393 << "Discovery previously initiated. Reporting success.";
1385 num_discovery_sessions_++; 1394 num_discovery_sessions_++;
1386 callback.Run(); 1395 callback.Run();
1387 } else { 1396 } else {
1388 error_callback.Run(TranslateDiscoveryErrorToUMA(error_name)); 1397 error_callback.Run(TranslateDiscoveryErrorToUMA(error_name));
1389 } 1398 }
1390 1399
1391 // Try to add a new discovery session for each queued request. 1400 // Try to add a new discovery session for each queued request.
1392 ProcessQueuedDiscoveryRequests(); 1401 ProcessQueuedDiscoveryRequests();
1393 } 1402 }
1394 1403
1395 void BluetoothAdapterBlueZ::OnStopDiscovery(const base::Closure& callback) { 1404 void BluetoothAdapterBlueZ::OnStopDiscovery(const base::Closure& callback) {
1396 // Report success on the original request and decrement the count. 1405 // Report success on the original request and decrement the count.
1397 VLOG(1) << __func__; 1406 BLUETOOTH_LOG(DEBUG) << __func__;
1398 DCHECK(discovery_request_pending_); 1407 DCHECK(discovery_request_pending_);
1399 DCHECK_EQ(num_discovery_sessions_, 1); 1408 DCHECK_EQ(num_discovery_sessions_, 1);
1400 discovery_request_pending_ = false; 1409 discovery_request_pending_ = false;
1401 num_discovery_sessions_--; 1410 num_discovery_sessions_--;
1402 callback.Run(); 1411 callback.Run();
1403 1412
1404 current_filter_.reset(); 1413 current_filter_.reset();
1405 1414
1406 // Try to add a new discovery session for each queued request. 1415 // Try to add a new discovery session for each queued request.
1407 ProcessQueuedDiscoveryRequests(); 1416 ProcessQueuedDiscoveryRequests();
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
1455 error_callback.Run(outcome); 1464 error_callback.Run(outcome);
1456 1465
1457 // Try to add a new discovery session for each queued request. 1466 // Try to add a new discovery session for each queued request.
1458 ProcessQueuedDiscoveryRequests(); 1467 ProcessQueuedDiscoveryRequests();
1459 } 1468 }
1460 1469
1461 void BluetoothAdapterBlueZ::OnSetDiscoveryFilter( 1470 void BluetoothAdapterBlueZ::OnSetDiscoveryFilter(
1462 const base::Closure& callback, 1471 const base::Closure& callback,
1463 const DiscoverySessionErrorCallback& error_callback) { 1472 const DiscoverySessionErrorCallback& error_callback) {
1464 // Report success on the original request and increment the count. 1473 // Report success on the original request and increment the count.
1465 VLOG(1) << __func__; 1474 BLUETOOTH_LOG(DEBUG) << __func__;
1466 if (IsPresent()) { 1475 if (IsPresent()) {
1467 callback.Run(); 1476 callback.Run();
1468 } else { 1477 } else {
1469 error_callback.Run(UMABluetoothDiscoverySessionOutcome::ADAPTER_REMOVED); 1478 error_callback.Run(UMABluetoothDiscoverySessionOutcome::ADAPTER_REMOVED);
1470 } 1479 }
1471 } 1480 }
1472 1481
1473 void BluetoothAdapterBlueZ::OnSetDiscoveryFilterError( 1482 void BluetoothAdapterBlueZ::OnSetDiscoveryFilterError(
1474 const base::Closure& callback, 1483 const base::Closure& callback,
1475 const DiscoverySessionErrorCallback& error_callback, 1484 const DiscoverySessionErrorCallback& error_callback,
(...skipping 13 matching lines...) Expand all
1489 BLUEZ_DBUS_FAILED_MAYBE_UNSUPPORTED_TRANSPORT; 1498 BLUEZ_DBUS_FAILED_MAYBE_UNSUPPORTED_TRANSPORT;
1490 } 1499 }
1491 error_callback.Run(outcome); 1500 error_callback.Run(outcome);
1492 1501
1493 // Try to add a new discovery session for each queued request. 1502 // Try to add a new discovery session for each queued request.
1494 ProcessQueuedDiscoveryRequests(); 1503 ProcessQueuedDiscoveryRequests();
1495 } 1504 }
1496 1505
1497 void BluetoothAdapterBlueZ::ProcessQueuedDiscoveryRequests() { 1506 void BluetoothAdapterBlueZ::ProcessQueuedDiscoveryRequests() {
1498 while (!discovery_request_queue_.empty()) { 1507 while (!discovery_request_queue_.empty()) {
1499 VLOG(1) << "Process queued discovery request."; 1508 BLUETOOTH_LOG(EVENT) << "Process queued discovery request.";
1500 DiscoveryParamTuple params = discovery_request_queue_.front(); 1509 DiscoveryParamTuple params = discovery_request_queue_.front();
1501 discovery_request_queue_.pop(); 1510 discovery_request_queue_.pop();
1502 AddDiscoverySession(std::get<0>(params), std::get<1>(params), 1511 AddDiscoverySession(std::get<0>(params), std::get<1>(params),
1503 std::get<2>(params)); 1512 std::get<2>(params));
1504 1513
1505 // If the queued request resulted in a pending call, then let it 1514 // If the queued request resulted in a pending call, then let it
1506 // asynchonously process the remaining queued requests once the pending 1515 // asynchonously process the remaining queued requests once the pending
1507 // call returns. 1516 // call returns.
1508 if (discovery_request_pending_) 1517 if (discovery_request_pending_)
1509 return; 1518 return;
1510 } 1519 }
1511 } 1520 }
1512 1521
1513 } // namespace bluez 1522 } // namespace bluez
OLDNEW
« no previous file with comments | « device/bluetooth/bluetooth_adapter.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698