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

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

Issue 2026413002: bluetooth: Repopulate chooser with existing devices (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@my-origin
Patch Set: Created 4 years, 6 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
OLDNEW
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
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
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
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 if (!chooser_.get()) {
scheib 2016/06/01 20:57:42 Maybe move this check into StartDeviceDiscovery?
ortuno 2016/06/01 22:06:50 As mentioned offline, we shouldn't get into this s
434 // If the dialog's closing, no need to start a discovery session.
435 return;
436 }
430 StartDeviceDiscovery(); 437 StartDeviceDiscovery();
431 // No need to close the chooser so we return. 438 // No need to close the chooser so we return.
432 return; 439 return;
433 case BluetoothChooser::Event::DENIED_PERMISSION: 440 case BluetoothChooser::Event::DENIED_PERMISSION:
434 RecordRequestDeviceOutcome(OutcomeFromChooserEvent(event)); 441 RecordRequestDeviceOutcome(OutcomeFromChooserEvent(event));
435 PostErrorCallback(blink::mojom::WebBluetoothError:: 442 PostErrorCallback(blink::mojom::WebBluetoothError::
436 CHOOSER_NOT_SHOWN_USER_DENIED_PERMISSION_TO_SCAN); 443 CHOOSER_NOT_SHOWN_USER_DENIED_PERMISSION_TO_SCAN);
437 break; 444 break;
438 case BluetoothChooser::Event::CANCELLED: 445 case BluetoothChooser::Event::CANCELLED:
439 RecordRequestDeviceOutcome(OutcomeFromChooserEvent(event)); 446 RecordRequestDeviceOutcome(OutcomeFromChooserEvent(event));
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
474 481
475 void BluetoothDeviceChooserController::PostErrorCallback( 482 void BluetoothDeviceChooserController::PostErrorCallback(
476 blink::mojom::WebBluetoothError error) { 483 blink::mojom::WebBluetoothError error) {
477 if (!base::ThreadTaskRunnerHandle::Get()->PostTask( 484 if (!base::ThreadTaskRunnerHandle::Get()->PostTask(
478 FROM_HERE, base::Bind(error_callback_, error))) { 485 FROM_HERE, base::Bind(error_callback_, error))) {
479 LOG(WARNING) << "No TaskRunner."; 486 LOG(WARNING) << "No TaskRunner.";
480 } 487 }
481 } 488 }
482 489
483 } // namespace content 490 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698