| 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 308 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 319 chooser_.reset(new FirstDeviceBluetoothChooser(chooser_event_handler)); | 319 chooser_.reset(new FirstDeviceBluetoothChooser(chooser_event_handler)); |
| 320 } | 320 } |
| 321 | 321 |
| 322 if (!chooser_->CanAskForScanningPermission()) { | 322 if (!chooser_->CanAskForScanningPermission()) { |
| 323 VLOG(1) << "Closing immediately because Chooser cannot obtain permission."; | 323 VLOG(1) << "Closing immediately because Chooser cannot obtain permission."; |
| 324 OnBluetoothChooserEvent(BluetoothChooser::Event::DENIED_PERMISSION, | 324 OnBluetoothChooserEvent(BluetoothChooser::Event::DENIED_PERMISSION, |
| 325 "" /* device_address */); | 325 "" /* device_address */); |
| 326 return; | 326 return; |
| 327 } | 327 } |
| 328 | 328 |
| 329 // Populate the initial list of devices. | 329 PopulateFoundDevices(); |
| 330 VLOG(1) << "Populating " << adapter_->GetDevices().size() | |
| 331 << " devices in chooser."; | |
| 332 for (const device::BluetoothDevice* device : adapter_->GetDevices()) { | |
| 333 AddFilteredDevice(*device); | |
| 334 } | |
| 335 | |
| 336 if (!chooser_.get()) { | 330 if (!chooser_.get()) { |
| 337 // If the dialog's closing, no need to do any of the rest of this. | 331 // If the dialog's closing, no need to do any of the rest of this. |
| 338 return; | 332 return; |
| 339 } | 333 } |
| 340 | 334 |
| 341 if (!adapter_->IsPowered()) { | 335 if (!adapter_->IsPowered()) { |
| 342 chooser_->SetAdapterPresence( | 336 chooser_->SetAdapterPresence( |
| 343 BluetoothChooser::AdapterPresence::POWERED_OFF); | 337 BluetoothChooser::AdapterPresence::POWERED_OFF); |
| 344 return; | 338 return; |
| 345 } | 339 } |
| (...skipping 18 matching lines...) Expand all Loading... |
| 364 chooser_->SetAdapterPresence( | 358 chooser_->SetAdapterPresence( |
| 365 powered ? BluetoothChooser::AdapterPresence::POWERED_ON | 359 powered ? BluetoothChooser::AdapterPresence::POWERED_ON |
| 366 : BluetoothChooser::AdapterPresence::POWERED_OFF); | 360 : BluetoothChooser::AdapterPresence::POWERED_OFF); |
| 367 } | 361 } |
| 368 | 362 |
| 369 if (!powered) { | 363 if (!powered) { |
| 370 discovery_session_timer_.Stop(); | 364 discovery_session_timer_.Stop(); |
| 371 } | 365 } |
| 372 } | 366 } |
| 373 | 367 |
| 368 void BluetoothDeviceChooserController::PopulateFoundDevices() { |
| 369 VLOG(1) << "Populating " << adapter_->GetDevices().size() |
| 370 << " devices in chooser."; |
| 371 for (const device::BluetoothDevice* device : adapter_->GetDevices()) { |
| 372 AddFilteredDevice(*device); |
| 373 } |
| 374 } |
| 375 |
| 374 void BluetoothDeviceChooserController::StartDeviceDiscovery() { | 376 void BluetoothDeviceChooserController::StartDeviceDiscovery() { |
| 375 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 377 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 376 | 378 |
| 377 if (discovery_session_.get() && discovery_session_->IsActive()) { | 379 if (discovery_session_.get() && discovery_session_->IsActive()) { |
| 378 // Already running; just increase the timeout. | 380 // Already running; just increase the timeout. |
| 379 discovery_session_timer_.Reset(); | 381 discovery_session_timer_.Reset(); |
| 380 return; | 382 return; |
| 381 } | 383 } |
| 382 | 384 |
| 383 chooser_->ShowDiscoveryState(BluetoothChooser::DiscoveryState::DISCOVERING); | 385 chooser_->ShowDiscoveryState(BluetoothChooser::DiscoveryState::DISCOVERING); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 420 | 422 |
| 421 void BluetoothDeviceChooserController::OnBluetoothChooserEvent( | 423 void BluetoothDeviceChooserController::OnBluetoothChooserEvent( |
| 422 BluetoothChooser::Event event, | 424 BluetoothChooser::Event event, |
| 423 const std::string& device_address) { | 425 const std::string& device_address) { |
| 424 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 426 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 425 // Shouldn't recieve an event from a closed chooser. | 427 // Shouldn't recieve an event from a closed chooser. |
| 426 DCHECK(chooser_.get()); | 428 DCHECK(chooser_.get()); |
| 427 | 429 |
| 428 switch (event) { | 430 switch (event) { |
| 429 case BluetoothChooser::Event::RESCAN: | 431 case BluetoothChooser::Event::RESCAN: |
| 432 PopulateFoundDevices(); |
| 433 DCHECK(chooser_); |
| 430 StartDeviceDiscovery(); | 434 StartDeviceDiscovery(); |
| 431 // No need to close the chooser so we return. | 435 // No need to close the chooser so we return. |
| 432 return; | 436 return; |
| 433 case BluetoothChooser::Event::DENIED_PERMISSION: | 437 case BluetoothChooser::Event::DENIED_PERMISSION: |
| 434 RecordRequestDeviceOutcome(OutcomeFromChooserEvent(event)); | 438 RecordRequestDeviceOutcome(OutcomeFromChooserEvent(event)); |
| 435 PostErrorCallback(blink::mojom::WebBluetoothError:: | 439 PostErrorCallback(blink::mojom::WebBluetoothError:: |
| 436 CHOOSER_NOT_SHOWN_USER_DENIED_PERMISSION_TO_SCAN); | 440 CHOOSER_NOT_SHOWN_USER_DENIED_PERMISSION_TO_SCAN); |
| 437 break; | 441 break; |
| 438 case BluetoothChooser::Event::CANCELLED: | 442 case BluetoothChooser::Event::CANCELLED: |
| 439 RecordRequestDeviceOutcome(OutcomeFromChooserEvent(event)); | 443 RecordRequestDeviceOutcome(OutcomeFromChooserEvent(event)); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 474 | 478 |
| 475 void BluetoothDeviceChooserController::PostErrorCallback( | 479 void BluetoothDeviceChooserController::PostErrorCallback( |
| 476 blink::mojom::WebBluetoothError error) { | 480 blink::mojom::WebBluetoothError error) { |
| 477 if (!base::ThreadTaskRunnerHandle::Get()->PostTask( | 481 if (!base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 478 FROM_HERE, base::Bind(error_callback_, error))) { | 482 FROM_HERE, base::Bind(error_callback_, error))) { |
| 479 LOG(WARNING) << "No TaskRunner."; | 483 LOG(WARNING) << "No TaskRunner."; |
| 480 } | 484 } |
| 481 } | 485 } |
| 482 | 486 |
| 483 } // namespace content | 487 } // namespace content |
| OLD | NEW |