OLD | NEW |
---|---|
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 Loading... | |
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 return false; |
ortuno
2016/01/27 19:15:36
Hmm I wonder if we should log these so that we kno
ortuno
2016/01/27 19:15:36
Hmm I wonder if we should log these so that we kno
fbeaufortchromium
2016/01/28 08:46:52
I've added BLUETOOTH_LOG(DEBUG) for all filters.
| |
81 } | 82 } |
82 | 83 |
83 if (!filter.namePrefix.empty() && | 84 if (!filter.namePrefix.empty() && |
84 (!base::StartsWith(device_name, filter.namePrefix, | 85 (!base::StartsWith(device_name, filter.namePrefix, |
85 base::CompareCase::SENSITIVE))) { | 86 base::CompareCase::SENSITIVE))) { |
86 return false; | 87 return false; |
87 } | 88 } |
88 | 89 |
89 if (!filter.services.empty()) { | 90 if (!filter.services.empty()) { |
90 const auto& device_uuid_list = device.GetUUIDs(); | 91 const auto& device_uuid_list = device.GetUUIDs(); |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
214 discovery_session->Stop(base::Bind(&base::DoNothing), | 215 discovery_session->Stop(base::Bind(&base::DoNothing), |
215 base::Bind(&base::DoNothing)); | 216 base::Bind(&base::DoNothing)); |
216 } | 217 } |
217 | 218 |
218 // TODO(ortuno): This should really be a BluetoothDevice method. | 219 // TODO(ortuno): This should really be a BluetoothDevice method. |
219 // Replace when implemented. http://crbug.com/552022 | 220 // Replace when implemented. http://crbug.com/552022 |
220 std::vector<BluetoothGattService*> GetPrimaryServicesByUUID( | 221 std::vector<BluetoothGattService*> GetPrimaryServicesByUUID( |
221 device::BluetoothDevice* device, | 222 device::BluetoothDevice* device, |
222 const std::string& service_uuid) { | 223 const std::string& service_uuid) { |
223 std::vector<BluetoothGattService*> services; | 224 std::vector<BluetoothGattService*> services; |
224 VLOG(1) << "Looking for service: " << service_uuid; | 225 BLUETOOTH_LOG(EVENT) << "Looking for service: " << service_uuid; |
225 for (BluetoothGattService* service : device->GetGattServices()) { | 226 for (BluetoothGattService* service : device->GetGattServices()) { |
226 VLOG(1) << "Service in cache: " << service->GetUUID().canonical_value(); | 227 BLUETOOTH_LOG(EVENT) << "Service in cache: " |
228 << service->GetUUID().canonical_value(); | |
227 if (service->GetUUID().canonical_value() == service_uuid && | 229 if (service->GetUUID().canonical_value() == service_uuid && |
228 service->IsPrimary()) { | 230 service->IsPrimary()) { |
229 services.push_back(service); | 231 services.push_back(service); |
230 } | 232 } |
231 } | 233 } |
232 return services; | 234 return services; |
233 } | 235 } |
234 | 236 |
235 } // namespace | 237 } // namespace |
236 | 238 |
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
456 session->ComputeScanFilter(), | 458 session->ComputeScanFilter(), |
457 base::Bind(&BluetoothDispatcherHost::OnDiscoverySessionStarted, | 459 base::Bind(&BluetoothDispatcherHost::OnDiscoverySessionStarted, |
458 weak_ptr_on_ui_thread_, chooser_id), | 460 weak_ptr_on_ui_thread_, chooser_id), |
459 base::Bind(&BluetoothDispatcherHost::OnDiscoverySessionStartedError, | 461 base::Bind(&BluetoothDispatcherHost::OnDiscoverySessionStartedError, |
460 weak_ptr_on_ui_thread_, chooser_id)); | 462 weak_ptr_on_ui_thread_, chooser_id)); |
461 } | 463 } |
462 } | 464 } |
463 | 465 |
464 void BluetoothDispatcherHost::StopDeviceDiscovery() { | 466 void BluetoothDispatcherHost::StopDeviceDiscovery() { |
465 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 467 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
466 for (IDMap<RequestDeviceSession, IDMapOwnPointer>::iterator iter( | 468 for (IDMap<RequestDeviceSession, IDMapOwnPointer>::iterator iter( |
ortuno
2016/01/27 19:15:36
Can you add a log statement here? Something like:
fbeaufortchromium
2016/01/28 08:46:52
Done.
| |
467 &request_device_sessions_); | 469 &request_device_sessions_); |
468 !iter.IsAtEnd(); iter.Advance()) { | 470 !iter.IsAtEnd(); iter.Advance()) { |
469 RequestDeviceSession* session = iter.GetCurrentValue(); | 471 RequestDeviceSession* session = iter.GetCurrentValue(); |
470 if (session->discovery_session) { | 472 if (session->discovery_session) { |
471 StopDiscoverySession(std::move(session->discovery_session)); | 473 StopDiscoverySession(std::move(session->discovery_session)); |
472 } | 474 } |
473 if (session->chooser) { | 475 if (session->chooser) { |
474 session->chooser->ShowDiscoveryState( | 476 session->chooser->ShowDiscoveryState( |
475 BluetoothChooser::DiscoveryState::IDLE); | 477 BluetoothChooser::DiscoveryState::IDLE); |
476 } | 478 } |
(...skipping 12 matching lines...) Expand all Loading... | |
489 !iter.IsAtEnd(); iter.Advance()) { | 491 !iter.IsAtEnd(); iter.Advance()) { |
490 RequestDeviceSession* session = iter.GetCurrentValue(); | 492 RequestDeviceSession* session = iter.GetCurrentValue(); |
491 if (session->chooser) | 493 if (session->chooser) |
492 session->chooser->SetAdapterPresence(presence); | 494 session->chooser->SetAdapterPresence(presence); |
493 } | 495 } |
494 } | 496 } |
495 | 497 |
496 void BluetoothDispatcherHost::DeviceAdded(device::BluetoothAdapter* adapter, | 498 void BluetoothDispatcherHost::DeviceAdded(device::BluetoothAdapter* adapter, |
497 device::BluetoothDevice* device) { | 499 device::BluetoothDevice* device) { |
498 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 500 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
499 VLOG(1) << "Adding device to all choosers: " << device->GetAddress(); | 501 BLUETOOTH_LOG(EVENT) << "Adding device to all choosers: " |
502 << device->GetAddress(); | |
500 for (IDMap<RequestDeviceSession, IDMapOwnPointer>::iterator iter( | 503 for (IDMap<RequestDeviceSession, IDMapOwnPointer>::iterator iter( |
501 &request_device_sessions_); | 504 &request_device_sessions_); |
502 !iter.IsAtEnd(); iter.Advance()) { | 505 !iter.IsAtEnd(); iter.Advance()) { |
503 RequestDeviceSession* session = iter.GetCurrentValue(); | 506 RequestDeviceSession* session = iter.GetCurrentValue(); |
504 session->AddFilteredDevice(*device); | 507 session->AddFilteredDevice(*device); |
505 } | 508 } |
506 } | 509 } |
507 | 510 |
508 void BluetoothDispatcherHost::DeviceRemoved(device::BluetoothAdapter* adapter, | 511 void BluetoothDispatcherHost::DeviceRemoved(device::BluetoothAdapter* adapter, |
509 device::BluetoothDevice* device) { | 512 device::BluetoothDevice* device) { |
510 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 513 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
511 VLOG(1) << "Marking device removed on all choosers: " << device->GetAddress(); | 514 BLUETOOTH_LOG(EVENT) << "Marking device removed on all choosers: " |
515 << device->GetAddress(); | |
512 for (IDMap<RequestDeviceSession, IDMapOwnPointer>::iterator iter( | 516 for (IDMap<RequestDeviceSession, IDMapOwnPointer>::iterator iter( |
513 &request_device_sessions_); | 517 &request_device_sessions_); |
514 !iter.IsAtEnd(); iter.Advance()) { | 518 !iter.IsAtEnd(); iter.Advance()) { |
515 RequestDeviceSession* session = iter.GetCurrentValue(); | 519 RequestDeviceSession* session = iter.GetCurrentValue(); |
516 if (session->chooser) { | 520 if (session->chooser) { |
517 session->chooser->RemoveDevice(device->GetAddress()); | 521 session->chooser->RemoveDevice(device->GetAddress()); |
518 } | 522 } |
519 } | 523 } |
520 } | 524 } |
521 | 525 |
522 void BluetoothDispatcherHost::GattServicesDiscovered( | 526 void BluetoothDispatcherHost::GattServicesDiscovered( |
523 device::BluetoothAdapter* adapter, | 527 device::BluetoothAdapter* adapter, |
524 device::BluetoothDevice* device) { | 528 device::BluetoothDevice* device) { |
525 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 529 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
526 const std::string& device_address = device->GetAddress(); | 530 const std::string& device_address = device->GetAddress(); |
527 VLOG(1) << "Services discovered for device: " << device_address; | 531 BLUETOOTH_LOG(EVENT) << "Services discovered for device: " << device_address; |
528 | 532 |
529 auto iter = pending_primary_services_requests_.find(device_address); | 533 auto iter = pending_primary_services_requests_.find(device_address); |
530 if (iter == pending_primary_services_requests_.end()) { | 534 if (iter == pending_primary_services_requests_.end()) { |
531 return; | 535 return; |
532 } | 536 } |
533 std::vector<PrimaryServicesRequest> requests; | 537 std::vector<PrimaryServicesRequest> requests; |
534 requests.swap(iter->second); | 538 requests.swap(iter->second); |
535 pending_primary_services_requests_.erase(iter); | 539 pending_primary_services_requests_.erase(iter); |
536 | 540 |
537 for (const PrimaryServicesRequest& request : requests) { | 541 for (const PrimaryServicesRequest& request : requests) { |
538 std::vector<BluetoothGattService*> services = | 542 std::vector<BluetoothGattService*> services = |
539 GetPrimaryServicesByUUID(device, request.service_uuid); | 543 GetPrimaryServicesByUUID(device, request.service_uuid); |
540 switch (request.func) { | 544 switch (request.func) { |
541 case PrimaryServicesRequest::GET_PRIMARY_SERVICE: | 545 case PrimaryServicesRequest::GET_PRIMARY_SERVICE: |
542 if (!services.empty()) { | 546 if (!services.empty()) { |
543 AddToServicesMapAndSendGetPrimaryServiceSuccess( | 547 AddToServicesMapAndSendGetPrimaryServiceSuccess( |
544 *services[0], request.thread_id, request.request_id); | 548 *services[0], request.thread_id, request.request_id); |
545 } else { | 549 } else { |
546 VLOG(1) << "No service found"; | 550 BLUETOOTH_LOG(EVENT) << "No service found"; |
547 RecordGetPrimaryServiceOutcome( | 551 RecordGetPrimaryServiceOutcome( |
548 UMAGetPrimaryServiceOutcome::NOT_FOUND); | 552 UMAGetPrimaryServiceOutcome::NOT_FOUND); |
549 Send(new BluetoothMsg_GetPrimaryServiceError( | 553 Send(new BluetoothMsg_GetPrimaryServiceError( |
550 request.thread_id, request.request_id, | 554 request.thread_id, request.request_id, |
551 WebBluetoothError::ServiceNotFound)); | 555 WebBluetoothError::ServiceNotFound)); |
552 } | 556 } |
553 break; | 557 break; |
554 case PrimaryServicesRequest::GET_PRIMARY_SERVICES: | 558 case PrimaryServicesRequest::GET_PRIMARY_SERVICES: |
555 NOTIMPLEMENTED(); | 559 NOTIMPLEMENTED(); |
556 break; | 560 break; |
557 } | 561 } |
558 } | 562 } |
559 DCHECK(!ContainsKey(pending_primary_services_requests_, device_address)) | 563 DCHECK(!ContainsKey(pending_primary_services_requests_, device_address)) |
560 << "Sending get-service responses unexpectedly queued another request."; | 564 << "Sending get-service responses unexpectedly queued another request."; |
561 } | 565 } |
562 | 566 |
563 void BluetoothDispatcherHost::GattCharacteristicValueChanged( | 567 void BluetoothDispatcherHost::GattCharacteristicValueChanged( |
564 device::BluetoothAdapter* adapter, | 568 device::BluetoothAdapter* adapter, |
565 device::BluetoothGattCharacteristic* characteristic, | 569 device::BluetoothGattCharacteristic* characteristic, |
566 const std::vector<uint8_t>& value) { | 570 const std::vector<uint8_t>& value) { |
567 VLOG(1) << "Characteristic updated: " << characteristic->GetIdentifier(); | 571 BLUETOOTH_LOG(EVENT) << "Characteristic updated: " |
572 << characteristic->GetIdentifier(); | |
568 auto iter = | 573 auto iter = |
569 active_characteristic_threads_.find(characteristic->GetIdentifier()); | 574 active_characteristic_threads_.find(characteristic->GetIdentifier()); |
570 | 575 |
571 if (iter == active_characteristic_threads_.end()) { | 576 if (iter == active_characteristic_threads_.end()) { |
572 return; | 577 return; |
573 } | 578 } |
574 | 579 |
575 for (int thread_id : iter->second) { | 580 for (int thread_id : iter->second) { |
576 // Yield to the event loop so that the event gets dispatched after the | 581 // Yield to the event loop so that the event gets dispatched after the |
577 // readValue promise resolves. | 582 // readValue promise resolves. |
(...skipping 21 matching lines...) Expand all Loading... | |
599 void BluetoothDispatcherHost::OnRequestDevice( | 604 void BluetoothDispatcherHost::OnRequestDevice( |
600 int thread_id, | 605 int thread_id, |
601 int request_id, | 606 int request_id, |
602 int frame_routing_id, | 607 int frame_routing_id, |
603 const std::vector<BluetoothScanFilter>& filters, | 608 const std::vector<BluetoothScanFilter>& filters, |
604 const std::vector<BluetoothUUID>& optional_services) { | 609 const std::vector<BluetoothUUID>& optional_services) { |
605 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 610 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
606 RecordWebBluetoothFunctionCall(UMAWebBluetoothFunction::REQUEST_DEVICE); | 611 RecordWebBluetoothFunctionCall(UMAWebBluetoothFunction::REQUEST_DEVICE); |
607 RecordRequestDeviceArguments(filters, optional_services); | 612 RecordRequestDeviceArguments(filters, optional_services); |
608 | 613 |
609 VLOG(1) << "requestDevice called with the following filters: "; | 614 BLUETOOTH_LOG(USER) << "requestDevice called with the following filters: "; |
610 for (const BluetoothScanFilter& filter : filters) { | 615 for (const BluetoothScanFilter& filter : filters) { |
611 VLOG(1) << "Name: " << filter.name; | 616 BLUETOOTH_LOG(USER) << "Name: " << filter.name; |
612 VLOG(1) << "Name Prefix: " << filter.namePrefix; | 617 BLUETOOTH_LOG(USER) << "Name Prefix: " << filter.namePrefix; |
613 VLOG(1) << "Services:"; | 618 BLUETOOTH_LOG(USER) << "Services:"; |
614 VLOG(1) << "\t["; | 619 BLUETOOTH_LOG(USER) << "\t["; |
615 for (const BluetoothUUID& service : filter.services) | 620 for (const BluetoothUUID& service : filter.services) |
616 VLOG(1) << "\t\t" << service.value(); | 621 BLUETOOTH_LOG(USER) << "\t\t" << service.value(); |
617 VLOG(1) << "\t]"; | 622 BLUETOOTH_LOG(USER) << "\t]"; |
618 } | 623 } |
619 | 624 |
620 VLOG(1) << "requestDevice called with the following optional services: "; | 625 BLUETOOTH_LOG(USER) |
626 << "requestDevice called with the following optional services: "; | |
621 for (const BluetoothUUID& service : optional_services) | 627 for (const BluetoothUUID& service : optional_services) |
622 VLOG(1) << "\t" << service.value(); | 628 BLUETOOTH_LOG(USER) << "\t" << service.value(); |
623 | 629 |
624 RenderFrameHostImpl* render_frame_host = | 630 RenderFrameHostImpl* render_frame_host = |
625 RenderFrameHostImpl::FromID(render_process_id_, frame_routing_id); | 631 RenderFrameHostImpl::FromID(render_process_id_, frame_routing_id); |
626 | 632 |
627 if (!render_frame_host) { | 633 if (!render_frame_host) { |
628 DLOG(WARNING) | 634 DLOG(WARNING) |
629 << "Got a requestDevice IPC without a matching RenderFrameHost: " | 635 << "Got a requestDevice IPC without a matching RenderFrameHost: " |
630 << render_process_id_ << ", " << frame_routing_id; | 636 << render_process_id_ << ", " << frame_routing_id; |
631 RecordRequestDeviceOutcome(UMARequestDeviceOutcome::NO_RENDER_FRAME); | 637 RecordRequestDeviceOutcome(UMARequestDeviceOutcome::NO_RENDER_FRAME); |
632 Send(new BluetoothMsg_RequestDeviceError( | 638 Send(new BluetoothMsg_RequestDeviceError( |
633 thread_id, request_id, WebBluetoothError::RequestDeviceWithoutFrame)); | 639 thread_id, request_id, WebBluetoothError::RequestDeviceWithoutFrame)); |
634 return; | 640 return; |
635 } | 641 } |
636 | 642 |
637 if (!adapter_) { | 643 if (!adapter_) { |
638 VLOG(1) << "No BluetoothAdapter. Can't serve requestDevice."; | 644 BLUETOOTH_LOG(EVENT) << "No BluetoothAdapter. Can't serve requestDevice."; |
639 RecordRequestDeviceOutcome(UMARequestDeviceOutcome::NO_BLUETOOTH_ADAPTER); | 645 RecordRequestDeviceOutcome(UMARequestDeviceOutcome::NO_BLUETOOTH_ADAPTER); |
640 Send(new BluetoothMsg_RequestDeviceError( | 646 Send(new BluetoothMsg_RequestDeviceError( |
641 thread_id, request_id, WebBluetoothError::NoBluetoothAdapter)); | 647 thread_id, request_id, WebBluetoothError::NoBluetoothAdapter)); |
642 return; | 648 return; |
643 } | 649 } |
644 | 650 |
645 if (!adapter_->IsPresent()) { | 651 if (!adapter_->IsPresent()) { |
646 VLOG(1) << "Bluetooth Adapter not present. Can't serve requestDevice."; | 652 BLUETOOTH_LOG(EVENT) |
653 << "Bluetooth Adapter not present. Can't serve requestDevice."; | |
647 RecordRequestDeviceOutcome( | 654 RecordRequestDeviceOutcome( |
648 UMARequestDeviceOutcome::BLUETOOTH_ADAPTER_NOT_PRESENT); | 655 UMARequestDeviceOutcome::BLUETOOTH_ADAPTER_NOT_PRESENT); |
649 Send(new BluetoothMsg_RequestDeviceError( | 656 Send(new BluetoothMsg_RequestDeviceError( |
650 thread_id, request_id, WebBluetoothError::NoBluetoothAdapter)); | 657 thread_id, request_id, WebBluetoothError::NoBluetoothAdapter)); |
651 return; | 658 return; |
652 } | 659 } |
653 | 660 |
654 // The renderer should never send empty filters. | 661 // The renderer should never send empty filters. |
655 if (HasEmptyOrInvalidFilter(filters)) { | 662 if (HasEmptyOrInvalidFilter(filters)) { |
656 bad_message::ReceivedBadMessage(this, | 663 bad_message::ReceivedBadMessage(this, |
(...skipping 15 matching lines...) Expand all Loading... | |
672 WebContents::FromRenderFrameHost(render_frame_host)) { | 679 WebContents::FromRenderFrameHost(render_frame_host)) { |
673 if (WebContentsDelegate* delegate = web_contents->GetDelegate()) { | 680 if (WebContentsDelegate* delegate = web_contents->GetDelegate()) { |
674 session->chooser = delegate->RunBluetoothChooser( | 681 session->chooser = delegate->RunBluetoothChooser( |
675 web_contents, chooser_event_handler, | 682 web_contents, chooser_event_handler, |
676 // TODO(ortuno): Replace with GetLastCommittedOrigin. | 683 // TODO(ortuno): Replace with GetLastCommittedOrigin. |
677 // http://crbug.com/577451 | 684 // http://crbug.com/577451 |
678 render_frame_host->GetLastCommittedURL().GetOrigin()); | 685 render_frame_host->GetLastCommittedURL().GetOrigin()); |
679 } | 686 } |
680 } | 687 } |
681 if (!session->chooser) { | 688 if (!session->chooser) { |
682 LOG(WARNING) | 689 BLUETOOTH_LOG(EVENT) |
683 << "No Bluetooth chooser implementation; falling back to first device."; | 690 << "No Bluetooth chooser implementation; falling back to first device."; |
684 session->chooser.reset( | 691 session->chooser.reset( |
685 new FirstDeviceBluetoothChooser(chooser_event_handler)); | 692 new FirstDeviceBluetoothChooser(chooser_event_handler)); |
686 } | 693 } |
687 | 694 |
688 if (!session->chooser->CanAskForScanningPermission()) { | 695 if (!session->chooser->CanAskForScanningPermission()) { |
689 VLOG(1) << "Closing immediately because Chooser cannot obtain permission."; | 696 BLUETOOTH_LOG(EVENT) |
697 << "Closing immediately because Chooser cannot obtain permission."; | |
690 OnBluetoothChooserEvent(chooser_id, | 698 OnBluetoothChooserEvent(chooser_id, |
691 BluetoothChooser::Event::DENIED_PERMISSION, ""); | 699 BluetoothChooser::Event::DENIED_PERMISSION, ""); |
692 return; | 700 return; |
693 } | 701 } |
694 | 702 |
695 // Populate the initial list of devices. | 703 // Populate the initial list of devices. |
696 VLOG(1) << "Populating " << adapter_->GetDevices().size() | 704 BLUETOOTH_LOG(EVENT) << "Populating " << adapter_->GetDevices().size() |
697 << " devices in chooser " << chooser_id; | 705 << " devices in chooser " << chooser_id; |
698 for (const device::BluetoothDevice* device : adapter_->GetDevices()) { | 706 for (const device::BluetoothDevice* device : adapter_->GetDevices()) { |
699 VLOG(1) << "\t" << device->GetAddress(); | 707 BLUETOOTH_LOG(EVENT) << "\t" << device->GetAddress(); |
700 session->AddFilteredDevice(*device); | 708 session->AddFilteredDevice(*device); |
701 } | 709 } |
702 | 710 |
703 if (!session->chooser) { | 711 if (!session->chooser) { |
704 // If the dialog's closing, no need to do any of the rest of this. | 712 // If the dialog's closing, no need to do any of the rest of this. |
705 return; | 713 return; |
706 } | 714 } |
707 | 715 |
708 if (!adapter_->IsPowered()) { | 716 if (!adapter_->IsPowered()) { |
709 session->chooser->SetAdapterPresence( | 717 session->chooser->SetAdapterPresence( |
(...skipping 19 matching lines...) Expand all Loading... | |
729 RecordConnectGATTOutcome(query_result.outcome); | 737 RecordConnectGATTOutcome(query_result.outcome); |
730 Send(new BluetoothMsg_ConnectGATTError(thread_id, request_id, | 738 Send(new BluetoothMsg_ConnectGATTError(thread_id, request_id, |
731 query_result.GetWebError())); | 739 query_result.GetWebError())); |
732 return; | 740 return; |
733 } | 741 } |
734 | 742 |
735 // If we are already connected no need to connect again. | 743 // If we are already connected no need to connect again. |
736 auto connection_iter = device_id_to_connection_map_.find(device_id); | 744 auto connection_iter = device_id_to_connection_map_.find(device_id); |
737 if (connection_iter != device_id_to_connection_map_.end()) { | 745 if (connection_iter != device_id_to_connection_map_.end()) { |
738 if (connection_iter->second->IsConnected()) { | 746 if (connection_iter->second->IsConnected()) { |
739 VLOG(1) << "Already connected."; | 747 BLUETOOTH_LOG(EVENT) << "Already connected."; |
740 Send(new BluetoothMsg_ConnectGATTSuccess(thread_id, request_id, | 748 Send(new BluetoothMsg_ConnectGATTSuccess(thread_id, request_id, |
741 device_id)); | 749 device_id)); |
742 return; | 750 return; |
743 } | 751 } |
744 } | 752 } |
745 | 753 |
746 query_result.device->CreateGattConnection( | 754 query_result.device->CreateGattConnection( |
747 base::Bind(&BluetoothDispatcherHost::OnGATTConnectionCreated, | 755 base::Bind(&BluetoothDispatcherHost::OnGATTConnectionCreated, |
748 weak_ptr_on_ui_thread_, thread_id, request_id, device_id, | 756 weak_ptr_on_ui_thread_, thread_id, request_id, device_id, |
749 start_time), | 757 start_time), |
(...skipping 16 matching lines...) Expand all Loading... | |
766 device_id) | 774 device_id) |
767 .empty()) { | 775 .empty()) { |
768 bad_message::ReceivedBadMessage( | 776 bad_message::ReceivedBadMessage( |
769 this, bad_message::BDH_DEVICE_NOT_ALLOWED_FOR_ORIGIN); | 777 this, bad_message::BDH_DEVICE_NOT_ALLOWED_FOR_ORIGIN); |
770 return; | 778 return; |
771 } | 779 } |
772 | 780 |
773 // The last BluetoothGattConnection for a device closes the connection when | 781 // The last BluetoothGattConnection for a device closes the connection when |
774 // it's destroyed. | 782 // it's destroyed. |
775 if (device_id_to_connection_map_.erase(device_id)) { | 783 if (device_id_to_connection_map_.erase(device_id)) { |
776 VLOG(1) << "Disconnecting device: " << device_id; | 784 BLUETOOTH_LOG(EVENT) << "Disconnecting device: " << device_id; |
777 } | 785 } |
778 } | 786 } |
779 | 787 |
780 void BluetoothDispatcherHost::OnGetPrimaryService( | 788 void BluetoothDispatcherHost::OnGetPrimaryService( |
781 int thread_id, | 789 int thread_id, |
782 int request_id, | 790 int request_id, |
783 int frame_routing_id, | 791 int frame_routing_id, |
784 const std::string& device_id, | 792 const std::string& device_id, |
785 const std::string& service_uuid) { | 793 const std::string& service_uuid) { |
786 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 794 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
(...skipping 21 matching lines...) Expand all Loading... | |
808 // 3. Services discovered and service not present in |device|: Send back not | 816 // 3. Services discovered and service not present in |device|: Send back not |
809 // found error. | 817 // found error. |
810 // 4. Services not discovered and service not present in |device|: Add request | 818 // 4. Services not discovered and service not present in |device|: Add request |
811 // to map of pending getPrimaryService requests. | 819 // to map of pending getPrimaryService requests. |
812 | 820 |
813 std::vector<BluetoothGattService*> services = | 821 std::vector<BluetoothGattService*> services = |
814 GetPrimaryServicesByUUID(query_result.device, service_uuid); | 822 GetPrimaryServicesByUUID(query_result.device, service_uuid); |
815 | 823 |
816 // 1. & 2. | 824 // 1. & 2. |
817 if (!services.empty()) { | 825 if (!services.empty()) { |
818 VLOG(1) << "Service found in device."; | 826 BLUETOOTH_LOG(EVENT) << "Service found in device."; |
819 const BluetoothGattService& service = *services[0]; | 827 const BluetoothGattService& service = *services[0]; |
820 DCHECK(service.IsPrimary()); | 828 DCHECK(service.IsPrimary()); |
821 AddToServicesMapAndSendGetPrimaryServiceSuccess(service, thread_id, | 829 AddToServicesMapAndSendGetPrimaryServiceSuccess(service, thread_id, |
822 request_id); | 830 request_id); |
823 return; | 831 return; |
824 } | 832 } |
825 | 833 |
826 // 3. | 834 // 3. |
827 if (query_result.device->IsGattServicesDiscoveryComplete()) { | 835 if (query_result.device->IsGattServicesDiscoveryComplete()) { |
828 VLOG(1) << "Service not found in device."; | 836 BLUETOOTH_LOG(EVENT) << "Service not found in device."; |
829 RecordGetPrimaryServiceOutcome(UMAGetPrimaryServiceOutcome::NOT_FOUND); | 837 RecordGetPrimaryServiceOutcome(UMAGetPrimaryServiceOutcome::NOT_FOUND); |
830 Send(new BluetoothMsg_GetPrimaryServiceError( | 838 Send(new BluetoothMsg_GetPrimaryServiceError( |
831 thread_id, request_id, WebBluetoothError::ServiceNotFound)); | 839 thread_id, request_id, WebBluetoothError::ServiceNotFound)); |
832 return; | 840 return; |
833 } | 841 } |
834 | 842 |
835 VLOG(1) << "Adding service request to pending requests."; | 843 BLUETOOTH_LOG(EVENT) << "Adding service request to pending requests."; |
836 // 4. | 844 // 4. |
837 AddToPendingPrimaryServicesRequest( | 845 AddToPendingPrimaryServicesRequest( |
838 query_result.device->GetAddress(), | 846 query_result.device->GetAddress(), |
839 PrimaryServicesRequest(thread_id, request_id, service_uuid, | 847 PrimaryServicesRequest(thread_id, request_id, service_uuid, |
840 PrimaryServicesRequest::GET_PRIMARY_SERVICE)); | 848 PrimaryServicesRequest::GET_PRIMARY_SERVICE)); |
841 } | 849 } |
842 | 850 |
843 void BluetoothDispatcherHost::OnGetCharacteristic( | 851 void BluetoothDispatcherHost::OnGetCharacteristic( |
844 int thread_id, | 852 int thread_id, |
845 int request_id, | 853 int request_id, |
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1061 thread_ids_set.erase(thread_id); | 1069 thread_ids_set.erase(thread_id); |
1062 if (thread_ids_set.empty()) { | 1070 if (thread_ids_set.empty()) { |
1063 active_characteristic_threads_.erase(active_iter); | 1071 active_characteristic_threads_.erase(active_iter); |
1064 } | 1072 } |
1065 } | 1073 } |
1066 | 1074 |
1067 void BluetoothDispatcherHost::OnDiscoverySessionStarted( | 1075 void BluetoothDispatcherHost::OnDiscoverySessionStarted( |
1068 int chooser_id, | 1076 int chooser_id, |
1069 scoped_ptr<device::BluetoothDiscoverySession> discovery_session) { | 1077 scoped_ptr<device::BluetoothDiscoverySession> discovery_session) { |
1070 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 1078 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
1071 VLOG(1) << "Started discovery session for " << chooser_id; | 1079 BLUETOOTH_LOG(EVENT) << "Started discovery session for " << chooser_id; |
1072 if (RequestDeviceSession* session = | 1080 if (RequestDeviceSession* session = |
1073 request_device_sessions_.Lookup(chooser_id)) { | 1081 request_device_sessions_.Lookup(chooser_id)) { |
1074 session->discovery_session = std::move(discovery_session); | 1082 session->discovery_session = std::move(discovery_session); |
1075 | 1083 |
1076 // Arrange to stop discovery later. | 1084 // Arrange to stop discovery later. |
1077 discovery_session_timer_.Reset(); | 1085 discovery_session_timer_.Reset(); |
1078 } else { | 1086 } else { |
1079 VLOG(1) << "Chooser " << chooser_id | 1087 BLUETOOTH_LOG(EVENT) |
1080 << " was closed before the session finished starting. Stopping."; | 1088 << "Chooser " << chooser_id |
1089 << " was closed before the session finished starting. Stopping."; | |
1081 StopDiscoverySession(std::move(discovery_session)); | 1090 StopDiscoverySession(std::move(discovery_session)); |
1082 } | 1091 } |
1083 } | 1092 } |
1084 | 1093 |
1085 void BluetoothDispatcherHost::OnDiscoverySessionStartedError(int chooser_id) { | 1094 void BluetoothDispatcherHost::OnDiscoverySessionStartedError(int chooser_id) { |
1086 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 1095 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
1087 VLOG(1) << "Failed to start discovery session for " << chooser_id; | 1096 BLUETOOTH_LOG(EVENT) << "Failed to start discovery session for " |
1097 << chooser_id; | |
1088 if (RequestDeviceSession* session = | 1098 if (RequestDeviceSession* session = |
1089 request_device_sessions_.Lookup(chooser_id)) { | 1099 request_device_sessions_.Lookup(chooser_id)) { |
1090 if (session->chooser && !session->discovery_session) { | 1100 if (session->chooser && !session->discovery_session) { |
1091 session->chooser->ShowDiscoveryState( | 1101 session->chooser->ShowDiscoveryState( |
1092 BluetoothChooser::DiscoveryState::FAILED_TO_START); | 1102 BluetoothChooser::DiscoveryState::FAILED_TO_START); |
1093 } | 1103 } |
1094 } | 1104 } |
1095 // Ignore discovery session start errors when the dialog was already closed by | 1105 // Ignore discovery session start errors when the dialog was already closed by |
1096 // the time they happen. | 1106 // the time they happen. |
1097 } | 1107 } |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1148 int chooser_id, | 1158 int chooser_id, |
1149 BluetoothChooser::Event event, | 1159 BluetoothChooser::Event event, |
1150 const std::string& device_id) { | 1160 const std::string& device_id) { |
1151 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 1161 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
1152 RequestDeviceSession* session = request_device_sessions_.Lookup(chooser_id); | 1162 RequestDeviceSession* session = request_device_sessions_.Lookup(chooser_id); |
1153 DCHECK(session) << "Session removed unexpectedly."; | 1163 DCHECK(session) << "Session removed unexpectedly."; |
1154 | 1164 |
1155 if (event == BluetoothChooser::Event::CANCELLED) { | 1165 if (event == BluetoothChooser::Event::CANCELLED) { |
1156 RecordRequestDeviceOutcome( | 1166 RecordRequestDeviceOutcome( |
1157 UMARequestDeviceOutcome::BLUETOOTH_CHOOSER_CANCELLED); | 1167 UMARequestDeviceOutcome::BLUETOOTH_CHOOSER_CANCELLED); |
1158 VLOG(1) << "Bluetooth chooser cancelled"; | 1168 BLUETOOTH_LOG(EVENT) << "Bluetooth chooser cancelled"; |
1159 Send(new BluetoothMsg_RequestDeviceError( | 1169 Send(new BluetoothMsg_RequestDeviceError( |
1160 session->thread_id, session->request_id, | 1170 session->thread_id, session->request_id, |
1161 WebBluetoothError::ChooserCancelled)); | 1171 WebBluetoothError::ChooserCancelled)); |
1162 request_device_sessions_.Remove(chooser_id); | 1172 request_device_sessions_.Remove(chooser_id); |
1163 return; | 1173 return; |
1164 } | 1174 } |
1165 if (event == BluetoothChooser::Event::DENIED_PERMISSION) { | 1175 if (event == BluetoothChooser::Event::DENIED_PERMISSION) { |
1166 RecordRequestDeviceOutcome( | 1176 RecordRequestDeviceOutcome( |
1167 UMARequestDeviceOutcome::BLUETOOTH_CHOOSER_DENIED_PERMISSION); | 1177 UMARequestDeviceOutcome::BLUETOOTH_CHOOSER_DENIED_PERMISSION); |
1168 VLOG(1) << "Bluetooth chooser denied permission"; | 1178 BLUETOOTH_LOG(EVENT) << "Bluetooth chooser denied permission"; |
1169 Send(new BluetoothMsg_RequestDeviceError( | 1179 Send(new BluetoothMsg_RequestDeviceError( |
1170 session->thread_id, session->request_id, | 1180 session->thread_id, session->request_id, |
1171 WebBluetoothError::ChooserDeniedPermission)); | 1181 WebBluetoothError::ChooserDeniedPermission)); |
1172 request_device_sessions_.Remove(chooser_id); | 1182 request_device_sessions_.Remove(chooser_id); |
1173 return; | 1183 return; |
1174 } | 1184 } |
1175 DCHECK_EQ(static_cast<int>(event), | 1185 DCHECK_EQ(static_cast<int>(event), |
1176 static_cast<int>(BluetoothChooser::Event::SELECTED)); | 1186 static_cast<int>(BluetoothChooser::Event::SELECTED)); |
1177 | 1187 |
1178 // |device_id| is the Device Address that RequestDeviceSession passed to | 1188 // |device_id| is the Device Address that RequestDeviceSession passed to |
1179 // chooser->AddDevice(). | 1189 // chooser->AddDevice(). |
1180 const device::BluetoothDevice* const device = adapter_->GetDevice(device_id); | 1190 const device::BluetoothDevice* const device = adapter_->GetDevice(device_id); |
1181 if (device == nullptr) { | 1191 if (device == nullptr) { |
1182 VLOG(1) << "Device " << device_id << " no longer in adapter"; | 1192 BLUETOOTH_LOG(EVENT) << "Device " << device_id << " no longer in adapter"; |
1183 RecordRequestDeviceOutcome(UMARequestDeviceOutcome::CHOSEN_DEVICE_VANISHED); | 1193 RecordRequestDeviceOutcome(UMARequestDeviceOutcome::CHOSEN_DEVICE_VANISHED); |
1184 Send(new BluetoothMsg_RequestDeviceError( | 1194 Send(new BluetoothMsg_RequestDeviceError( |
1185 session->thread_id, session->request_id, | 1195 session->thread_id, session->request_id, |
1186 WebBluetoothError::ChosenDeviceVanished)); | 1196 WebBluetoothError::ChosenDeviceVanished)); |
1187 request_device_sessions_.Remove(chooser_id); | 1197 request_device_sessions_.Remove(chooser_id); |
1188 return; | 1198 return; |
1189 } | 1199 } |
1190 | 1200 |
1191 VLOG(1) << "Device: " << device->GetName(); | 1201 BLUETOOTH_LOG(EVENT) << "Device: " << device->GetName(); |
1192 VLOG(1) << "UUIDs: "; | 1202 BLUETOOTH_LOG(EVENT) << "UUIDs: "; |
1193 for (BluetoothUUID uuid : device->GetUUIDs()) | 1203 for (BluetoothUUID uuid : device->GetUUIDs()) |
1194 VLOG(1) << "\t" << uuid.canonical_value(); | 1204 BLUETOOTH_LOG(EVENT) << "\t" << uuid.canonical_value(); |
1195 | 1205 |
1196 const std::string& device_id_for_origin = allowed_devices_map_.AddDevice( | 1206 const std::string& device_id_for_origin = allowed_devices_map_.AddDevice( |
1197 session->origin, device->GetAddress(), session->filters, | 1207 session->origin, device->GetAddress(), session->filters, |
1198 session->optional_services); | 1208 session->optional_services); |
1199 | 1209 |
1200 content::BluetoothDevice device_ipc( | 1210 content::BluetoothDevice device_ipc( |
1201 device_id_for_origin, // id | 1211 device_id_for_origin, // id |
1202 device->GetName(), // name | 1212 device->GetName(), // name |
1203 content::BluetoothDevice::ValidatePower( | 1213 content::BluetoothDevice::ValidatePower( |
1204 device->GetInquiryTxPower()), // tx_power | 1214 device->GetInquiryTxPower()), // tx_power |
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1458 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 1468 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
1459 NOTIMPLEMENTED(); | 1469 NOTIMPLEMENTED(); |
1460 } | 1470 } |
1461 | 1471 |
1462 void BluetoothDispatcherHost::ShowNeedLocationLink() { | 1472 void BluetoothDispatcherHost::ShowNeedLocationLink() { |
1463 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 1473 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
1464 NOTIMPLEMENTED(); | 1474 NOTIMPLEMENTED(); |
1465 } | 1475 } |
1466 | 1476 |
1467 } // namespace content | 1477 } // namespace content |
OLD | NEW |