OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "content/browser/bluetooth/bluetooth_device_chooser_controller.h" | 5 #include "content/browser/bluetooth/bluetooth_device_chooser_controller.h" |
6 | 6 |
7 #include <set> | 7 #include <set> |
8 #include <string> | 8 #include <string> |
9 #include <unordered_set> | 9 #include <unordered_set> |
10 | 10 |
(...skipping 390 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
401 return; | 401 return; |
402 } | 402 } |
403 | 403 |
404 if (!chooser_->CanAskForScanningPermission()) { | 404 if (!chooser_->CanAskForScanningPermission()) { |
405 VLOG(1) << "Closing immediately because Chooser cannot obtain permission."; | 405 VLOG(1) << "Closing immediately because Chooser cannot obtain permission."; |
406 OnBluetoothChooserEvent(BluetoothChooser::Event::DENIED_PERMISSION, | 406 OnBluetoothChooserEvent(BluetoothChooser::Event::DENIED_PERMISSION, |
407 "" /* device_address */); | 407 "" /* device_address */); |
408 return; | 408 return; |
409 } | 409 } |
410 | 410 |
| 411 device_ids_.clear(); |
411 PopulateConnectedDevices(); | 412 PopulateConnectedDevices(); |
412 if (!chooser_.get()) { | 413 if (!chooser_.get()) { |
413 // If the dialog's closing, no need to do any of the rest of this. | 414 // If the dialog's closing, no need to do any of the rest of this. |
414 return; | 415 return; |
415 } | 416 } |
416 | 417 |
417 if (!adapter_->IsPowered()) { | 418 if (!adapter_->IsPowered()) { |
418 chooser_->SetAdapterPresence( | 419 chooser_->SetAdapterPresence( |
419 BluetoothChooser::AdapterPresence::POWERED_OFF); | 420 BluetoothChooser::AdapterPresence::POWERED_OFF); |
420 return; | 421 return; |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
498 | 499 |
499 void BluetoothDeviceChooserController::StartDeviceDiscovery() { | 500 void BluetoothDeviceChooserController::StartDeviceDiscovery() { |
500 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 501 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
501 | 502 |
502 if (discovery_session_.get() && discovery_session_->IsActive()) { | 503 if (discovery_session_.get() && discovery_session_->IsActive()) { |
503 // Already running; just increase the timeout. | 504 // Already running; just increase the timeout. |
504 discovery_session_timer_.Reset(); | 505 discovery_session_timer_.Reset(); |
505 return; | 506 return; |
506 } | 507 } |
507 | 508 |
508 device_ids_.clear(); | |
509 | |
510 scanning_start_time_ = base::TimeTicks::Now(); | 509 scanning_start_time_ = base::TimeTicks::Now(); |
511 | 510 |
512 chooser_->ShowDiscoveryState(BluetoothChooser::DiscoveryState::DISCOVERING); | 511 chooser_->ShowDiscoveryState(BluetoothChooser::DiscoveryState::DISCOVERING); |
513 adapter_->StartDiscoverySessionWithFilter( | 512 adapter_->StartDiscoverySessionWithFilter( |
514 ComputeScanFilter(options_->filters), | 513 ComputeScanFilter(options_->filters), |
515 base::Bind( | 514 base::Bind( |
516 &BluetoothDeviceChooserController::OnStartDiscoverySessionSuccess, | 515 &BluetoothDeviceChooserController::OnStartDiscoverySessionSuccess, |
517 weak_ptr_factory_.GetWeakPtr()), | 516 weak_ptr_factory_.GetWeakPtr()), |
518 base::Bind( | 517 base::Bind( |
519 &BluetoothDeviceChooserController::OnStartDiscoverySessionFailed, | 518 &BluetoothDeviceChooserController::OnStartDiscoverySessionFailed, |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
557 void BluetoothDeviceChooserController::OnBluetoothChooserEvent( | 556 void BluetoothDeviceChooserController::OnBluetoothChooserEvent( |
558 BluetoothChooser::Event event, | 557 BluetoothChooser::Event event, |
559 const std::string& device_address) { | 558 const std::string& device_address) { |
560 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 559 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
561 // Shouldn't recieve an event from a closed chooser. | 560 // Shouldn't recieve an event from a closed chooser. |
562 DCHECK(chooser_.get()); | 561 DCHECK(chooser_.get()); |
563 | 562 |
564 switch (event) { | 563 switch (event) { |
565 case BluetoothChooser::Event::RESCAN: | 564 case BluetoothChooser::Event::RESCAN: |
566 RecordRequestDeviceOutcome(OutcomeFromChooserEvent(event)); | 565 RecordRequestDeviceOutcome(OutcomeFromChooserEvent(event)); |
| 566 device_ids_.clear(); |
567 PopulateConnectedDevices(); | 567 PopulateConnectedDevices(); |
568 DCHECK(chooser_); | 568 DCHECK(chooser_); |
569 StartDeviceDiscovery(); | 569 StartDeviceDiscovery(); |
570 // No need to close the chooser so we return. | 570 // No need to close the chooser so we return. |
571 return; | 571 return; |
572 case BluetoothChooser::Event::DENIED_PERMISSION: | 572 case BluetoothChooser::Event::DENIED_PERMISSION: |
573 RecordRequestDeviceOutcome(OutcomeFromChooserEvent(event)); | 573 RecordRequestDeviceOutcome(OutcomeFromChooserEvent(event)); |
574 PostErrorCallback(blink::mojom::WebBluetoothResult:: | 574 PostErrorCallback(blink::mojom::WebBluetoothResult:: |
575 CHOOSER_NOT_SHOWN_USER_DENIED_PERMISSION_TO_SCAN); | 575 CHOOSER_NOT_SHOWN_USER_DENIED_PERMISSION_TO_SCAN); |
576 break; | 576 break; |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
616 | 616 |
617 void BluetoothDeviceChooserController::PostErrorCallback( | 617 void BluetoothDeviceChooserController::PostErrorCallback( |
618 blink::mojom::WebBluetoothResult error) { | 618 blink::mojom::WebBluetoothResult error) { |
619 if (!base::ThreadTaskRunnerHandle::Get()->PostTask( | 619 if (!base::ThreadTaskRunnerHandle::Get()->PostTask( |
620 FROM_HERE, base::Bind(error_callback_, error))) { | 620 FROM_HERE, base::Bind(error_callback_, error))) { |
621 LOG(WARNING) << "No TaskRunner."; | 621 LOG(WARNING) << "No TaskRunner."; |
622 } | 622 } |
623 } | 623 } |
624 | 624 |
625 } // namespace content | 625 } // namespace content |
OLD | NEW |