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

Side by Side Diff: content/browser/bluetooth/bluetooth_dispatcher_host.cc

Issue 1639293002: bluetooth: update bluetooth_dispatcher_host VLOG to BLUETOOTH_LOG (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@btDeviceLog
Patch Set: Removed gyp file update Created 4 years, 10 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 | « content/browser/BUILD.gn ('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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 // ID Not In Map Note: 5 // ID Not In Map Note:
6 // A service, characteristic, or descriptor ID not in the corresponding 6 // A service, characteristic, or descriptor ID not in the corresponding
7 // BluetoothDispatcherHost map [service_to_device_, characteristic_to_service_, 7 // BluetoothDispatcherHost map [service_to_device_, characteristic_to_service_,
8 // descriptor_to_characteristic_] implies a hostile renderer because a renderer 8 // descriptor_to_characteristic_] implies a hostile renderer because a renderer
9 // obtains the corresponding ID from this class and it will be added to the map 9 // obtains the corresponding ID from this class and it will be added to the map
10 // at that time. 10 // at that time.
11 11
12 #include "content/browser/bluetooth/bluetooth_dispatcher_host.h" 12 #include "content/browser/bluetooth/bluetooth_dispatcher_host.h"
13 13
14 #include <stddef.h> 14 #include <stddef.h>
15 15
16 #include <utility> 16 #include <utility>
17 17
18 #include "base/bind.h" 18 #include "base/bind.h"
19 #include "base/single_thread_task_runner.h" 19 #include "base/single_thread_task_runner.h"
20 #include "base/strings/utf_string_conversions.h" 20 #include "base/strings/utf_string_conversions.h"
21 #include "base/thread_task_runner_handle.h" 21 #include "base/thread_task_runner_handle.h"
22 #include "components/device_event_log/device_event_log.h"
22 #include "content/browser/bad_message.h" 23 #include "content/browser/bad_message.h"
23 #include "content/browser/bluetooth/bluetooth_metrics.h" 24 #include "content/browser/bluetooth/bluetooth_metrics.h"
24 #include "content/browser/bluetooth/first_device_bluetooth_chooser.h" 25 #include "content/browser/bluetooth/first_device_bluetooth_chooser.h"
25 #include "content/browser/frame_host/render_frame_host_impl.h" 26 #include "content/browser/frame_host/render_frame_host_impl.h"
26 #include "content/common/bluetooth/bluetooth_messages.h" 27 #include "content/common/bluetooth/bluetooth_messages.h"
27 #include "content/public/browser/web_contents.h" 28 #include "content/public/browser/web_contents.h"
28 #include "content/public/browser/web_contents_delegate.h" 29 #include "content/public/browser/web_contents_delegate.h"
29 #include "device/bluetooth/bluetooth_adapter.h" 30 #include "device/bluetooth/bluetooth_adapter.h"
30 #include "device/bluetooth/bluetooth_adapter_factory.h" 31 #include "device/bluetooth/bluetooth_adapter_factory.h"
31 #include "device/bluetooth/bluetooth_device.h" 32 #include "device/bluetooth/bluetooth_device.h"
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 71
71 // Defined at 72 // Defined at
72 // https://webbluetoothchrome.github.io/web-bluetooth/#dfn-matches-a-filter 73 // https://webbluetoothchrome.github.io/web-bluetooth/#dfn-matches-a-filter
73 bool MatchesFilter(const device::BluetoothDevice& device, 74 bool MatchesFilter(const device::BluetoothDevice& device,
74 const content::BluetoothScanFilter& filter) { 75 const content::BluetoothScanFilter& filter) {
75 DCHECK(!IsEmptyOrInvalidFilter(filter)); 76 DCHECK(!IsEmptyOrInvalidFilter(filter));
76 77
77 const std::string device_name = base::UTF16ToUTF8(device.GetName()); 78 const std::string device_name = base::UTF16ToUTF8(device.GetName());
78 79
79 if (!filter.name.empty() && (device_name != filter.name)) { 80 if (!filter.name.empty() && (device_name != filter.name)) {
80 return false; 81 BLUETOOTH_LOG(DEBUG) << "Name filter does not match device: "
82 << device_name;
83 return false;
81 } 84 }
82 85
83 if (!filter.namePrefix.empty() && 86 if (!filter.namePrefix.empty() &&
84 (!base::StartsWith(device_name, filter.namePrefix, 87 (!base::StartsWith(device_name, filter.namePrefix,
85 base::CompareCase::SENSITIVE))) { 88 base::CompareCase::SENSITIVE))) {
89 BLUETOOTH_LOG(DEBUG) << "Name prefix filter does not match device: "
90 << device_name;
86 return false; 91 return false;
87 } 92 }
88 93
89 if (!filter.services.empty()) { 94 if (!filter.services.empty()) {
90 const auto& device_uuid_list = device.GetUUIDs(); 95 const auto& device_uuid_list = device.GetUUIDs();
91 const std::set<BluetoothUUID> device_uuids(device_uuid_list.begin(), 96 const std::set<BluetoothUUID> device_uuids(device_uuid_list.begin(),
92 device_uuid_list.end()); 97 device_uuid_list.end());
93 for (const auto& service : filter.services) { 98 for (const auto& service : filter.services) {
94 if (!ContainsKey(device_uuids, service)) { 99 if (!ContainsKey(device_uuids, service)) {
100 BLUETOOTH_LOG(DEBUG) << "Services filter does not match device: "
101 << device_name;
95 return false; 102 return false;
96 } 103 }
97 } 104 }
98 } 105 }
99 106
100 return true; 107 return true;
101 } 108 }
102 109
103 bool MatchesFilters(const device::BluetoothDevice& device, 110 bool MatchesFilters(const device::BluetoothDevice& device,
104 const std::vector<content::BluetoothScanFilter>& filters) { 111 const std::vector<content::BluetoothScanFilter>& filters) {
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
214 discovery_session->Stop(base::Bind(&base::DoNothing), 221 discovery_session->Stop(base::Bind(&base::DoNothing),
215 base::Bind(&base::DoNothing)); 222 base::Bind(&base::DoNothing));
216 } 223 }
217 224
218 // TODO(ortuno): This should really be a BluetoothDevice method. 225 // TODO(ortuno): This should really be a BluetoothDevice method.
219 // Replace when implemented. http://crbug.com/552022 226 // Replace when implemented. http://crbug.com/552022
220 std::vector<BluetoothGattService*> GetPrimaryServicesByUUID( 227 std::vector<BluetoothGattService*> GetPrimaryServicesByUUID(
221 device::BluetoothDevice* device, 228 device::BluetoothDevice* device,
222 const std::string& service_uuid) { 229 const std::string& service_uuid) {
223 std::vector<BluetoothGattService*> services; 230 std::vector<BluetoothGattService*> services;
224 VLOG(1) << "Looking for service: " << service_uuid; 231 BLUETOOTH_LOG(EVENT) << "Looking for service: " << service_uuid;
225 for (BluetoothGattService* service : device->GetGattServices()) { 232 for (BluetoothGattService* service : device->GetGattServices()) {
226 VLOG(1) << "Service in cache: " << service->GetUUID().canonical_value(); 233 BLUETOOTH_LOG(EVENT) << "Service in cache: "
234 << service->GetUUID().canonical_value();
227 if (service->GetUUID().canonical_value() == service_uuid && 235 if (service->GetUUID().canonical_value() == service_uuid &&
228 service->IsPrimary()) { 236 service->IsPrimary()) {
229 services.push_back(service); 237 services.push_back(service);
230 } 238 }
231 } 239 }
232 return services; 240 return services;
233 } 241 }
234 242
235 } // namespace 243 } // namespace
236 244
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after
456 session->ComputeScanFilter(), 464 session->ComputeScanFilter(),
457 base::Bind(&BluetoothDispatcherHost::OnDiscoverySessionStarted, 465 base::Bind(&BluetoothDispatcherHost::OnDiscoverySessionStarted,
458 weak_ptr_on_ui_thread_, chooser_id), 466 weak_ptr_on_ui_thread_, chooser_id),
459 base::Bind(&BluetoothDispatcherHost::OnDiscoverySessionStartedError, 467 base::Bind(&BluetoothDispatcherHost::OnDiscoverySessionStartedError,
460 weak_ptr_on_ui_thread_, chooser_id)); 468 weak_ptr_on_ui_thread_, chooser_id));
461 } 469 }
462 } 470 }
463 471
464 void BluetoothDispatcherHost::StopDeviceDiscovery() { 472 void BluetoothDispatcherHost::StopDeviceDiscovery() {
465 DCHECK_CURRENTLY_ON(BrowserThread::UI); 473 DCHECK_CURRENTLY_ON(BrowserThread::UI);
474 BLUETOOTH_LOG(EVENT) << "Stopping discovery session";
466 for (IDMap<RequestDeviceSession, IDMapOwnPointer>::iterator iter( 475 for (IDMap<RequestDeviceSession, IDMapOwnPointer>::iterator iter(
467 &request_device_sessions_); 476 &request_device_sessions_);
468 !iter.IsAtEnd(); iter.Advance()) { 477 !iter.IsAtEnd(); iter.Advance()) {
469 RequestDeviceSession* session = iter.GetCurrentValue(); 478 RequestDeviceSession* session = iter.GetCurrentValue();
470 if (session->discovery_session) { 479 if (session->discovery_session) {
471 StopDiscoverySession(std::move(session->discovery_session)); 480 StopDiscoverySession(std::move(session->discovery_session));
472 } 481 }
473 if (session->chooser) { 482 if (session->chooser) {
474 session->chooser->ShowDiscoveryState( 483 session->chooser->ShowDiscoveryState(
475 BluetoothChooser::DiscoveryState::IDLE); 484 BluetoothChooser::DiscoveryState::IDLE);
(...skipping 13 matching lines...) Expand all
489 !iter.IsAtEnd(); iter.Advance()) { 498 !iter.IsAtEnd(); iter.Advance()) {
490 RequestDeviceSession* session = iter.GetCurrentValue(); 499 RequestDeviceSession* session = iter.GetCurrentValue();
491 if (session->chooser) 500 if (session->chooser)
492 session->chooser->SetAdapterPresence(presence); 501 session->chooser->SetAdapterPresence(presence);
493 } 502 }
494 } 503 }
495 504
496 void BluetoothDispatcherHost::DeviceAdded(device::BluetoothAdapter* adapter, 505 void BluetoothDispatcherHost::DeviceAdded(device::BluetoothAdapter* adapter,
497 device::BluetoothDevice* device) { 506 device::BluetoothDevice* device) {
498 DCHECK_CURRENTLY_ON(BrowserThread::UI); 507 DCHECK_CURRENTLY_ON(BrowserThread::UI);
499 VLOG(1) << "Adding device to all choosers: " << device->GetAddress(); 508 BLUETOOTH_LOG(EVENT) << "Adding device to all choosers: "
509 << device->GetAddress();
500 for (IDMap<RequestDeviceSession, IDMapOwnPointer>::iterator iter( 510 for (IDMap<RequestDeviceSession, IDMapOwnPointer>::iterator iter(
501 &request_device_sessions_); 511 &request_device_sessions_);
502 !iter.IsAtEnd(); iter.Advance()) { 512 !iter.IsAtEnd(); iter.Advance()) {
503 RequestDeviceSession* session = iter.GetCurrentValue(); 513 RequestDeviceSession* session = iter.GetCurrentValue();
504 session->AddFilteredDevice(*device); 514 session->AddFilteredDevice(*device);
505 } 515 }
506 } 516 }
507 517
508 void BluetoothDispatcherHost::DeviceRemoved(device::BluetoothAdapter* adapter, 518 void BluetoothDispatcherHost::DeviceRemoved(device::BluetoothAdapter* adapter,
509 device::BluetoothDevice* device) { 519 device::BluetoothDevice* device) {
510 DCHECK_CURRENTLY_ON(BrowserThread::UI); 520 DCHECK_CURRENTLY_ON(BrowserThread::UI);
511 VLOG(1) << "Marking device removed on all choosers: " << device->GetAddress(); 521 BLUETOOTH_LOG(EVENT) << "Marking device removed on all choosers: "
522 << device->GetAddress();
512 for (IDMap<RequestDeviceSession, IDMapOwnPointer>::iterator iter( 523 for (IDMap<RequestDeviceSession, IDMapOwnPointer>::iterator iter(
513 &request_device_sessions_); 524 &request_device_sessions_);
514 !iter.IsAtEnd(); iter.Advance()) { 525 !iter.IsAtEnd(); iter.Advance()) {
515 RequestDeviceSession* session = iter.GetCurrentValue(); 526 RequestDeviceSession* session = iter.GetCurrentValue();
516 if (session->chooser) { 527 if (session->chooser) {
517 session->chooser->RemoveDevice(device->GetAddress()); 528 session->chooser->RemoveDevice(device->GetAddress());
518 } 529 }
519 } 530 }
520 } 531 }
521 532
522 void BluetoothDispatcherHost::GattServicesDiscovered( 533 void BluetoothDispatcherHost::GattServicesDiscovered(
523 device::BluetoothAdapter* adapter, 534 device::BluetoothAdapter* adapter,
524 device::BluetoothDevice* device) { 535 device::BluetoothDevice* device) {
525 DCHECK_CURRENTLY_ON(BrowserThread::UI); 536 DCHECK_CURRENTLY_ON(BrowserThread::UI);
526 const std::string& device_address = device->GetAddress(); 537 const std::string& device_address = device->GetAddress();
527 VLOG(1) << "Services discovered for device: " << device_address; 538 BLUETOOTH_LOG(EVENT) << "Services discovered for device: " << device_address;
528 539
529 auto iter = pending_primary_services_requests_.find(device_address); 540 auto iter = pending_primary_services_requests_.find(device_address);
530 if (iter == pending_primary_services_requests_.end()) { 541 if (iter == pending_primary_services_requests_.end()) {
531 return; 542 return;
532 } 543 }
533 std::vector<PrimaryServicesRequest> requests; 544 std::vector<PrimaryServicesRequest> requests;
534 requests.swap(iter->second); 545 requests.swap(iter->second);
535 pending_primary_services_requests_.erase(iter); 546 pending_primary_services_requests_.erase(iter);
536 547
537 for (const PrimaryServicesRequest& request : requests) { 548 for (const PrimaryServicesRequest& request : requests) {
538 std::vector<BluetoothGattService*> services = 549 std::vector<BluetoothGattService*> services =
539 GetPrimaryServicesByUUID(device, request.service_uuid); 550 GetPrimaryServicesByUUID(device, request.service_uuid);
540 switch (request.func) { 551 switch (request.func) {
541 case PrimaryServicesRequest::GET_PRIMARY_SERVICE: 552 case PrimaryServicesRequest::GET_PRIMARY_SERVICE:
542 if (!services.empty()) { 553 if (!services.empty()) {
543 AddToServicesMapAndSendGetPrimaryServiceSuccess( 554 AddToServicesMapAndSendGetPrimaryServiceSuccess(
544 *services[0], request.thread_id, request.request_id); 555 *services[0], request.thread_id, request.request_id);
545 } else { 556 } else {
546 VLOG(1) << "No service found"; 557 BLUETOOTH_LOG(EVENT) << "No service found";
547 RecordGetPrimaryServiceOutcome( 558 RecordGetPrimaryServiceOutcome(
548 UMAGetPrimaryServiceOutcome::NOT_FOUND); 559 UMAGetPrimaryServiceOutcome::NOT_FOUND);
549 Send(new BluetoothMsg_GetPrimaryServiceError( 560 Send(new BluetoothMsg_GetPrimaryServiceError(
550 request.thread_id, request.request_id, 561 request.thread_id, request.request_id,
551 WebBluetoothError::ServiceNotFound)); 562 WebBluetoothError::ServiceNotFound));
552 } 563 }
553 break; 564 break;
554 case PrimaryServicesRequest::GET_PRIMARY_SERVICES: 565 case PrimaryServicesRequest::GET_PRIMARY_SERVICES:
555 NOTIMPLEMENTED(); 566 NOTIMPLEMENTED();
556 break; 567 break;
557 } 568 }
558 } 569 }
559 DCHECK(!ContainsKey(pending_primary_services_requests_, device_address)) 570 DCHECK(!ContainsKey(pending_primary_services_requests_, device_address))
560 << "Sending get-service responses unexpectedly queued another request."; 571 << "Sending get-service responses unexpectedly queued another request.";
561 } 572 }
562 573
563 void BluetoothDispatcherHost::GattCharacteristicValueChanged( 574 void BluetoothDispatcherHost::GattCharacteristicValueChanged(
564 device::BluetoothAdapter* adapter, 575 device::BluetoothAdapter* adapter,
565 device::BluetoothGattCharacteristic* characteristic, 576 device::BluetoothGattCharacteristic* characteristic,
566 const std::vector<uint8_t>& value) { 577 const std::vector<uint8_t>& value) {
567 VLOG(1) << "Characteristic updated: " << characteristic->GetIdentifier(); 578 BLUETOOTH_LOG(EVENT) << "Characteristic updated: "
579 << characteristic->GetIdentifier();
568 auto iter = 580 auto iter =
569 active_characteristic_threads_.find(characteristic->GetIdentifier()); 581 active_characteristic_threads_.find(characteristic->GetIdentifier());
570 582
571 if (iter == active_characteristic_threads_.end()) { 583 if (iter == active_characteristic_threads_.end()) {
572 return; 584 return;
573 } 585 }
574 586
575 for (int thread_id : iter->second) { 587 for (int thread_id : iter->second) {
576 // Yield to the event loop so that the event gets dispatched after the 588 // Yield to the event loop so that the event gets dispatched after the
577 // readValue promise resolves. 589 // readValue promise resolves.
(...skipping 21 matching lines...) Expand all
599 void BluetoothDispatcherHost::OnRequestDevice( 611 void BluetoothDispatcherHost::OnRequestDevice(
600 int thread_id, 612 int thread_id,
601 int request_id, 613 int request_id,
602 int frame_routing_id, 614 int frame_routing_id,
603 const std::vector<BluetoothScanFilter>& filters, 615 const std::vector<BluetoothScanFilter>& filters,
604 const std::vector<BluetoothUUID>& optional_services) { 616 const std::vector<BluetoothUUID>& optional_services) {
605 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 617 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
606 RecordWebBluetoothFunctionCall(UMAWebBluetoothFunction::REQUEST_DEVICE); 618 RecordWebBluetoothFunctionCall(UMAWebBluetoothFunction::REQUEST_DEVICE);
607 RecordRequestDeviceArguments(filters, optional_services); 619 RecordRequestDeviceArguments(filters, optional_services);
608 620
609 VLOG(1) << "requestDevice called with the following filters: "; 621 BLUETOOTH_LOG(USER) << "requestDevice called with the following filters: ";
610 for (const BluetoothScanFilter& filter : filters) { 622 for (const BluetoothScanFilter& filter : filters) {
611 VLOG(1) << "Name: " << filter.name; 623 BLUETOOTH_LOG(USER) << "Name: " << filter.name;
612 VLOG(1) << "Name Prefix: " << filter.namePrefix; 624 BLUETOOTH_LOG(USER) << "Name Prefix: " << filter.namePrefix;
613 VLOG(1) << "Services:"; 625 BLUETOOTH_LOG(USER) << "Services:";
614 VLOG(1) << "\t["; 626 BLUETOOTH_LOG(USER) << "\t[";
615 for (const BluetoothUUID& service : filter.services) 627 for (const BluetoothUUID& service : filter.services)
616 VLOG(1) << "\t\t" << service.value(); 628 BLUETOOTH_LOG(USER) << "\t\t" << service.value();
617 VLOG(1) << "\t]"; 629 BLUETOOTH_LOG(USER) << "\t]";
618 } 630 }
619 631
620 VLOG(1) << "requestDevice called with the following optional services: "; 632 BLUETOOTH_LOG(USER)
633 << "requestDevice called with the following optional services: ";
621 for (const BluetoothUUID& service : optional_services) 634 for (const BluetoothUUID& service : optional_services)
622 VLOG(1) << "\t" << service.value(); 635 BLUETOOTH_LOG(USER) << "\t" << service.value();
623 636
624 RenderFrameHostImpl* render_frame_host = 637 RenderFrameHostImpl* render_frame_host =
625 RenderFrameHostImpl::FromID(render_process_id_, frame_routing_id); 638 RenderFrameHostImpl::FromID(render_process_id_, frame_routing_id);
626 639
627 if (!render_frame_host) { 640 if (!render_frame_host) {
628 DLOG(WARNING) 641 DLOG(WARNING)
629 << "Got a requestDevice IPC without a matching RenderFrameHost: " 642 << "Got a requestDevice IPC without a matching RenderFrameHost: "
630 << render_process_id_ << ", " << frame_routing_id; 643 << render_process_id_ << ", " << frame_routing_id;
631 RecordRequestDeviceOutcome(UMARequestDeviceOutcome::NO_RENDER_FRAME); 644 RecordRequestDeviceOutcome(UMARequestDeviceOutcome::NO_RENDER_FRAME);
632 Send(new BluetoothMsg_RequestDeviceError( 645 Send(new BluetoothMsg_RequestDeviceError(
633 thread_id, request_id, WebBluetoothError::RequestDeviceWithoutFrame)); 646 thread_id, request_id, WebBluetoothError::RequestDeviceWithoutFrame));
634 return; 647 return;
635 } 648 }
636 649
637 if (!adapter_) { 650 if (!adapter_) {
638 VLOG(1) << "No BluetoothAdapter. Can't serve requestDevice."; 651 BLUETOOTH_LOG(EVENT) << "No BluetoothAdapter. Can't serve requestDevice.";
639 RecordRequestDeviceOutcome(UMARequestDeviceOutcome::NO_BLUETOOTH_ADAPTER); 652 RecordRequestDeviceOutcome(UMARequestDeviceOutcome::NO_BLUETOOTH_ADAPTER);
640 Send(new BluetoothMsg_RequestDeviceError( 653 Send(new BluetoothMsg_RequestDeviceError(
641 thread_id, request_id, WebBluetoothError::NoBluetoothAdapter)); 654 thread_id, request_id, WebBluetoothError::NoBluetoothAdapter));
642 return; 655 return;
643 } 656 }
644 657
645 if (!adapter_->IsPresent()) { 658 if (!adapter_->IsPresent()) {
646 VLOG(1) << "Bluetooth Adapter not present. Can't serve requestDevice."; 659 BLUETOOTH_LOG(EVENT)
660 << "Bluetooth Adapter not present. Can't serve requestDevice.";
647 RecordRequestDeviceOutcome( 661 RecordRequestDeviceOutcome(
648 UMARequestDeviceOutcome::BLUETOOTH_ADAPTER_NOT_PRESENT); 662 UMARequestDeviceOutcome::BLUETOOTH_ADAPTER_NOT_PRESENT);
649 Send(new BluetoothMsg_RequestDeviceError( 663 Send(new BluetoothMsg_RequestDeviceError(
650 thread_id, request_id, WebBluetoothError::NoBluetoothAdapter)); 664 thread_id, request_id, WebBluetoothError::NoBluetoothAdapter));
651 return; 665 return;
652 } 666 }
653 667
654 // The renderer should never send empty filters. 668 // The renderer should never send empty filters.
655 if (HasEmptyOrInvalidFilter(filters)) { 669 if (HasEmptyOrInvalidFilter(filters)) {
656 bad_message::ReceivedBadMessage(this, 670 bad_message::ReceivedBadMessage(this,
(...skipping 15 matching lines...) Expand all
672 WebContents::FromRenderFrameHost(render_frame_host)) { 686 WebContents::FromRenderFrameHost(render_frame_host)) {
673 if (WebContentsDelegate* delegate = web_contents->GetDelegate()) { 687 if (WebContentsDelegate* delegate = web_contents->GetDelegate()) {
674 session->chooser = delegate->RunBluetoothChooser( 688 session->chooser = delegate->RunBluetoothChooser(
675 web_contents, chooser_event_handler, 689 web_contents, chooser_event_handler,
676 // TODO(ortuno): Replace with GetLastCommittedOrigin. 690 // TODO(ortuno): Replace with GetLastCommittedOrigin.
677 // http://crbug.com/577451 691 // http://crbug.com/577451
678 render_frame_host->GetLastCommittedURL().GetOrigin()); 692 render_frame_host->GetLastCommittedURL().GetOrigin());
679 } 693 }
680 } 694 }
681 if (!session->chooser) { 695 if (!session->chooser) {
682 LOG(WARNING) 696 BLUETOOTH_LOG(EVENT)
683 << "No Bluetooth chooser implementation; falling back to first device."; 697 << "No Bluetooth chooser implementation; falling back to first device.";
684 session->chooser.reset( 698 session->chooser.reset(
685 new FirstDeviceBluetoothChooser(chooser_event_handler)); 699 new FirstDeviceBluetoothChooser(chooser_event_handler));
686 } 700 }
687 701
688 if (!session->chooser->CanAskForScanningPermission()) { 702 if (!session->chooser->CanAskForScanningPermission()) {
689 VLOG(1) << "Closing immediately because Chooser cannot obtain permission."; 703 BLUETOOTH_LOG(EVENT)
704 << "Closing immediately because Chooser cannot obtain permission.";
690 OnBluetoothChooserEvent(chooser_id, 705 OnBluetoothChooserEvent(chooser_id,
691 BluetoothChooser::Event::DENIED_PERMISSION, ""); 706 BluetoothChooser::Event::DENIED_PERMISSION, "");
692 return; 707 return;
693 } 708 }
694 709
695 // Populate the initial list of devices. 710 // Populate the initial list of devices.
696 VLOG(1) << "Populating " << adapter_->GetDevices().size() 711 BLUETOOTH_LOG(EVENT) << "Populating " << adapter_->GetDevices().size()
697 << " devices in chooser " << chooser_id; 712 << " devices in chooser " << chooser_id;
698 for (const device::BluetoothDevice* device : adapter_->GetDevices()) { 713 for (const device::BluetoothDevice* device : adapter_->GetDevices()) {
699 VLOG(1) << "\t" << device->GetAddress(); 714 BLUETOOTH_LOG(EVENT) << "\t" << device->GetAddress();
700 session->AddFilteredDevice(*device); 715 session->AddFilteredDevice(*device);
701 } 716 }
702 717
703 if (!session->chooser) { 718 if (!session->chooser) {
704 // If the dialog's closing, no need to do any of the rest of this. 719 // If the dialog's closing, no need to do any of the rest of this.
705 return; 720 return;
706 } 721 }
707 722
708 if (!adapter_->IsPowered()) { 723 if (!adapter_->IsPowered()) {
709 session->chooser->SetAdapterPresence( 724 session->chooser->SetAdapterPresence(
(...skipping 19 matching lines...) Expand all
729 RecordConnectGATTOutcome(query_result.outcome); 744 RecordConnectGATTOutcome(query_result.outcome);
730 Send(new BluetoothMsg_ConnectGATTError(thread_id, request_id, 745 Send(new BluetoothMsg_ConnectGATTError(thread_id, request_id,
731 query_result.GetWebError())); 746 query_result.GetWebError()));
732 return; 747 return;
733 } 748 }
734 749
735 // If we are already connected no need to connect again. 750 // If we are already connected no need to connect again.
736 auto connection_iter = device_id_to_connection_map_.find(device_id); 751 auto connection_iter = device_id_to_connection_map_.find(device_id);
737 if (connection_iter != device_id_to_connection_map_.end()) { 752 if (connection_iter != device_id_to_connection_map_.end()) {
738 if (connection_iter->second->IsConnected()) { 753 if (connection_iter->second->IsConnected()) {
739 VLOG(1) << "Already connected."; 754 BLUETOOTH_LOG(EVENT) << "Already connected.";
740 Send(new BluetoothMsg_ConnectGATTSuccess(thread_id, request_id, 755 Send(new BluetoothMsg_ConnectGATTSuccess(thread_id, request_id,
741 device_id)); 756 device_id));
742 return; 757 return;
743 } 758 }
744 } 759 }
745 760
746 query_result.device->CreateGattConnection( 761 query_result.device->CreateGattConnection(
747 base::Bind(&BluetoothDispatcherHost::OnGATTConnectionCreated, 762 base::Bind(&BluetoothDispatcherHost::OnGATTConnectionCreated,
748 weak_ptr_on_ui_thread_, thread_id, request_id, device_id, 763 weak_ptr_on_ui_thread_, thread_id, request_id, device_id,
749 start_time), 764 start_time),
(...skipping 16 matching lines...) Expand all
766 device_id) 781 device_id)
767 .empty()) { 782 .empty()) {
768 bad_message::ReceivedBadMessage( 783 bad_message::ReceivedBadMessage(
769 this, bad_message::BDH_DEVICE_NOT_ALLOWED_FOR_ORIGIN); 784 this, bad_message::BDH_DEVICE_NOT_ALLOWED_FOR_ORIGIN);
770 return; 785 return;
771 } 786 }
772 787
773 // The last BluetoothGattConnection for a device closes the connection when 788 // The last BluetoothGattConnection for a device closes the connection when
774 // it's destroyed. 789 // it's destroyed.
775 if (device_id_to_connection_map_.erase(device_id)) { 790 if (device_id_to_connection_map_.erase(device_id)) {
776 VLOG(1) << "Disconnecting device: " << device_id; 791 BLUETOOTH_LOG(EVENT) << "Disconnecting device: " << device_id;
777 } 792 }
778 } 793 }
779 794
780 void BluetoothDispatcherHost::OnGetPrimaryService( 795 void BluetoothDispatcherHost::OnGetPrimaryService(
781 int thread_id, 796 int thread_id,
782 int request_id, 797 int request_id,
783 int frame_routing_id, 798 int frame_routing_id,
784 const std::string& device_id, 799 const std::string& device_id,
785 const std::string& service_uuid) { 800 const std::string& service_uuid) {
786 DCHECK_CURRENTLY_ON(BrowserThread::UI); 801 DCHECK_CURRENTLY_ON(BrowserThread::UI);
(...skipping 21 matching lines...) Expand all
808 // 3. Services discovered and service not present in |device|: Send back not 823 // 3. Services discovered and service not present in |device|: Send back not
809 // found error. 824 // found error.
810 // 4. Services not discovered and service not present in |device|: Add request 825 // 4. Services not discovered and service not present in |device|: Add request
811 // to map of pending getPrimaryService requests. 826 // to map of pending getPrimaryService requests.
812 827
813 std::vector<BluetoothGattService*> services = 828 std::vector<BluetoothGattService*> services =
814 GetPrimaryServicesByUUID(query_result.device, service_uuid); 829 GetPrimaryServicesByUUID(query_result.device, service_uuid);
815 830
816 // 1. & 2. 831 // 1. & 2.
817 if (!services.empty()) { 832 if (!services.empty()) {
818 VLOG(1) << "Service found in device."; 833 BLUETOOTH_LOG(EVENT) << "Service found in device.";
819 const BluetoothGattService& service = *services[0]; 834 const BluetoothGattService& service = *services[0];
820 DCHECK(service.IsPrimary()); 835 DCHECK(service.IsPrimary());
821 AddToServicesMapAndSendGetPrimaryServiceSuccess(service, thread_id, 836 AddToServicesMapAndSendGetPrimaryServiceSuccess(service, thread_id,
822 request_id); 837 request_id);
823 return; 838 return;
824 } 839 }
825 840
826 // 3. 841 // 3.
827 if (query_result.device->IsGattServicesDiscoveryComplete()) { 842 if (query_result.device->IsGattServicesDiscoveryComplete()) {
828 VLOG(1) << "Service not found in device."; 843 BLUETOOTH_LOG(EVENT) << "Service not found in device.";
829 RecordGetPrimaryServiceOutcome(UMAGetPrimaryServiceOutcome::NOT_FOUND); 844 RecordGetPrimaryServiceOutcome(UMAGetPrimaryServiceOutcome::NOT_FOUND);
830 Send(new BluetoothMsg_GetPrimaryServiceError( 845 Send(new BluetoothMsg_GetPrimaryServiceError(
831 thread_id, request_id, WebBluetoothError::ServiceNotFound)); 846 thread_id, request_id, WebBluetoothError::ServiceNotFound));
832 return; 847 return;
833 } 848 }
834 849
835 VLOG(1) << "Adding service request to pending requests."; 850 BLUETOOTH_LOG(EVENT) << "Adding service request to pending requests.";
836 // 4. 851 // 4.
837 AddToPendingPrimaryServicesRequest( 852 AddToPendingPrimaryServicesRequest(
838 query_result.device->GetAddress(), 853 query_result.device->GetAddress(),
839 PrimaryServicesRequest(thread_id, request_id, service_uuid, 854 PrimaryServicesRequest(thread_id, request_id, service_uuid,
840 PrimaryServicesRequest::GET_PRIMARY_SERVICE)); 855 PrimaryServicesRequest::GET_PRIMARY_SERVICE));
841 } 856 }
842 857
843 void BluetoothDispatcherHost::OnGetCharacteristic( 858 void BluetoothDispatcherHost::OnGetCharacteristic(
844 int thread_id, 859 int thread_id,
845 int request_id, 860 int request_id,
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after
1061 thread_ids_set.erase(thread_id); 1076 thread_ids_set.erase(thread_id);
1062 if (thread_ids_set.empty()) { 1077 if (thread_ids_set.empty()) {
1063 active_characteristic_threads_.erase(active_iter); 1078 active_characteristic_threads_.erase(active_iter);
1064 } 1079 }
1065 } 1080 }
1066 1081
1067 void BluetoothDispatcherHost::OnDiscoverySessionStarted( 1082 void BluetoothDispatcherHost::OnDiscoverySessionStarted(
1068 int chooser_id, 1083 int chooser_id,
1069 scoped_ptr<device::BluetoothDiscoverySession> discovery_session) { 1084 scoped_ptr<device::BluetoothDiscoverySession> discovery_session) {
1070 DCHECK_CURRENTLY_ON(BrowserThread::UI); 1085 DCHECK_CURRENTLY_ON(BrowserThread::UI);
1071 VLOG(1) << "Started discovery session for " << chooser_id; 1086 BLUETOOTH_LOG(EVENT) << "Started discovery session for " << chooser_id;
1072 if (RequestDeviceSession* session = 1087 if (RequestDeviceSession* session =
1073 request_device_sessions_.Lookup(chooser_id)) { 1088 request_device_sessions_.Lookup(chooser_id)) {
1074 session->discovery_session = std::move(discovery_session); 1089 session->discovery_session = std::move(discovery_session);
1075 1090
1076 // Arrange to stop discovery later. 1091 // Arrange to stop discovery later.
1077 discovery_session_timer_.Reset(); 1092 discovery_session_timer_.Reset();
1078 } else { 1093 } else {
1079 VLOG(1) << "Chooser " << chooser_id 1094 BLUETOOTH_LOG(EVENT)
1080 << " was closed before the session finished starting. Stopping."; 1095 << "Chooser " << chooser_id
1096 << " was closed before the session finished starting. Stopping.";
1081 StopDiscoverySession(std::move(discovery_session)); 1097 StopDiscoverySession(std::move(discovery_session));
1082 } 1098 }
1083 } 1099 }
1084 1100
1085 void BluetoothDispatcherHost::OnDiscoverySessionStartedError(int chooser_id) { 1101 void BluetoothDispatcherHost::OnDiscoverySessionStartedError(int chooser_id) {
1086 DCHECK_CURRENTLY_ON(BrowserThread::UI); 1102 DCHECK_CURRENTLY_ON(BrowserThread::UI);
1087 VLOG(1) << "Failed to start discovery session for " << chooser_id; 1103 BLUETOOTH_LOG(EVENT) << "Failed to start discovery session for "
1104 << chooser_id;
1088 if (RequestDeviceSession* session = 1105 if (RequestDeviceSession* session =
1089 request_device_sessions_.Lookup(chooser_id)) { 1106 request_device_sessions_.Lookup(chooser_id)) {
1090 if (session->chooser && !session->discovery_session) { 1107 if (session->chooser && !session->discovery_session) {
1091 session->chooser->ShowDiscoveryState( 1108 session->chooser->ShowDiscoveryState(
1092 BluetoothChooser::DiscoveryState::FAILED_TO_START); 1109 BluetoothChooser::DiscoveryState::FAILED_TO_START);
1093 } 1110 }
1094 } 1111 }
1095 // Ignore discovery session start errors when the dialog was already closed by 1112 // Ignore discovery session start errors when the dialog was already closed by
1096 // the time they happen. 1113 // the time they happen.
1097 } 1114 }
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
1148 int chooser_id, 1165 int chooser_id,
1149 BluetoothChooser::Event event, 1166 BluetoothChooser::Event event,
1150 const std::string& device_id) { 1167 const std::string& device_id) {
1151 DCHECK_CURRENTLY_ON(BrowserThread::UI); 1168 DCHECK_CURRENTLY_ON(BrowserThread::UI);
1152 RequestDeviceSession* session = request_device_sessions_.Lookup(chooser_id); 1169 RequestDeviceSession* session = request_device_sessions_.Lookup(chooser_id);
1153 DCHECK(session) << "Session removed unexpectedly."; 1170 DCHECK(session) << "Session removed unexpectedly.";
1154 1171
1155 if (event == BluetoothChooser::Event::CANCELLED) { 1172 if (event == BluetoothChooser::Event::CANCELLED) {
1156 RecordRequestDeviceOutcome( 1173 RecordRequestDeviceOutcome(
1157 UMARequestDeviceOutcome::BLUETOOTH_CHOOSER_CANCELLED); 1174 UMARequestDeviceOutcome::BLUETOOTH_CHOOSER_CANCELLED);
1158 VLOG(1) << "Bluetooth chooser cancelled"; 1175 BLUETOOTH_LOG(EVENT) << "Bluetooth chooser cancelled";
1159 Send(new BluetoothMsg_RequestDeviceError( 1176 Send(new BluetoothMsg_RequestDeviceError(
1160 session->thread_id, session->request_id, 1177 session->thread_id, session->request_id,
1161 WebBluetoothError::ChooserCancelled)); 1178 WebBluetoothError::ChooserCancelled));
1162 request_device_sessions_.Remove(chooser_id); 1179 request_device_sessions_.Remove(chooser_id);
1163 return; 1180 return;
1164 } 1181 }
1165 if (event == BluetoothChooser::Event::DENIED_PERMISSION) { 1182 if (event == BluetoothChooser::Event::DENIED_PERMISSION) {
1166 RecordRequestDeviceOutcome( 1183 RecordRequestDeviceOutcome(
1167 UMARequestDeviceOutcome::BLUETOOTH_CHOOSER_DENIED_PERMISSION); 1184 UMARequestDeviceOutcome::BLUETOOTH_CHOOSER_DENIED_PERMISSION);
1168 VLOG(1) << "Bluetooth chooser denied permission"; 1185 BLUETOOTH_LOG(EVENT) << "Bluetooth chooser denied permission";
1169 Send(new BluetoothMsg_RequestDeviceError( 1186 Send(new BluetoothMsg_RequestDeviceError(
1170 session->thread_id, session->request_id, 1187 session->thread_id, session->request_id,
1171 WebBluetoothError::ChooserDeniedPermission)); 1188 WebBluetoothError::ChooserDeniedPermission));
1172 request_device_sessions_.Remove(chooser_id); 1189 request_device_sessions_.Remove(chooser_id);
1173 return; 1190 return;
1174 } 1191 }
1175 DCHECK_EQ(static_cast<int>(event), 1192 DCHECK_EQ(static_cast<int>(event),
1176 static_cast<int>(BluetoothChooser::Event::SELECTED)); 1193 static_cast<int>(BluetoothChooser::Event::SELECTED));
1177 1194
1178 // |device_id| is the Device Address that RequestDeviceSession passed to 1195 // |device_id| is the Device Address that RequestDeviceSession passed to
1179 // chooser->AddDevice(). 1196 // chooser->AddDevice().
1180 const device::BluetoothDevice* const device = adapter_->GetDevice(device_id); 1197 const device::BluetoothDevice* const device = adapter_->GetDevice(device_id);
1181 if (device == nullptr) { 1198 if (device == nullptr) {
1182 VLOG(1) << "Device " << device_id << " no longer in adapter"; 1199 BLUETOOTH_LOG(EVENT) << "Device " << device_id << " no longer in adapter";
1183 RecordRequestDeviceOutcome(UMARequestDeviceOutcome::CHOSEN_DEVICE_VANISHED); 1200 RecordRequestDeviceOutcome(UMARequestDeviceOutcome::CHOSEN_DEVICE_VANISHED);
1184 Send(new BluetoothMsg_RequestDeviceError( 1201 Send(new BluetoothMsg_RequestDeviceError(
1185 session->thread_id, session->request_id, 1202 session->thread_id, session->request_id,
1186 WebBluetoothError::ChosenDeviceVanished)); 1203 WebBluetoothError::ChosenDeviceVanished));
1187 request_device_sessions_.Remove(chooser_id); 1204 request_device_sessions_.Remove(chooser_id);
1188 return; 1205 return;
1189 } 1206 }
1190 1207
1191 VLOG(1) << "Device: " << device->GetName(); 1208 BLUETOOTH_LOG(EVENT) << "Device: " << device->GetName();
1192 VLOG(1) << "UUIDs: "; 1209 BLUETOOTH_LOG(EVENT) << "UUIDs: ";
1193 for (BluetoothUUID uuid : device->GetUUIDs()) 1210 for (BluetoothUUID uuid : device->GetUUIDs())
1194 VLOG(1) << "\t" << uuid.canonical_value(); 1211 BLUETOOTH_LOG(EVENT) << "\t" << uuid.canonical_value();
1195 1212
1196 const std::string& device_id_for_origin = allowed_devices_map_.AddDevice( 1213 const std::string& device_id_for_origin = allowed_devices_map_.AddDevice(
1197 session->origin, device->GetAddress(), session->filters, 1214 session->origin, device->GetAddress(), session->filters,
1198 session->optional_services); 1215 session->optional_services);
1199 1216
1200 content::BluetoothDevice device_ipc( 1217 content::BluetoothDevice device_ipc(
1201 device_id_for_origin, // id 1218 device_id_for_origin, // id
1202 device->GetName(), // name 1219 device->GetName(), // name
1203 content::BluetoothDevice::ValidatePower( 1220 content::BluetoothDevice::ValidatePower(
1204 device->GetInquiryTxPower()), // tx_power 1221 device->GetInquiryTxPower()), // tx_power
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after
1458 DCHECK_CURRENTLY_ON(BrowserThread::UI); 1475 DCHECK_CURRENTLY_ON(BrowserThread::UI);
1459 NOTIMPLEMENTED(); 1476 NOTIMPLEMENTED();
1460 } 1477 }
1461 1478
1462 void BluetoothDispatcherHost::ShowNeedLocationLink() { 1479 void BluetoothDispatcherHost::ShowNeedLocationLink() {
1463 DCHECK_CURRENTLY_ON(BrowserThread::UI); 1480 DCHECK_CURRENTLY_ON(BrowserThread::UI);
1464 NOTIMPLEMENTED(); 1481 NOTIMPLEMENTED();
1465 } 1482 }
1466 1483
1467 } // namespace content 1484 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/BUILD.gn ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698