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

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

Issue 2217573002: bluetooth: Only add new devices, connected devices and devices that changed. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@bluetooth-add-or-update
Patch Set: Fix typo Created 4 years, 4 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 303 matching lines...) Expand 10 before | Expand all | Expand 10 after
314 blink::mojom::WebBluetoothError::WEB_BLUETOOTH_NOT_SUPPORTED); 314 blink::mojom::WebBluetoothError::WEB_BLUETOOTH_NOT_SUPPORTED);
315 } 315 }
316 316
317 if (!chooser_->CanAskForScanningPermission()) { 317 if (!chooser_->CanAskForScanningPermission()) {
318 VLOG(1) << "Closing immediately because Chooser cannot obtain permission."; 318 VLOG(1) << "Closing immediately because Chooser cannot obtain permission.";
319 OnBluetoothChooserEvent(BluetoothChooser::Event::DENIED_PERMISSION, 319 OnBluetoothChooserEvent(BluetoothChooser::Event::DENIED_PERMISSION,
320 "" /* device_address */); 320 "" /* device_address */);
321 return; 321 return;
322 } 322 }
323 323
324 PopulateFoundDevices(); 324 PopulateConnectedDevices();
325 if (!chooser_.get()) { 325 if (!chooser_.get()) {
326 // If the dialog's closing, no need to do any of the rest of this. 326 // If the dialog's closing, no need to do any of the rest of this.
327 return; 327 return;
328 } 328 }
329 329
330 if (!adapter_->IsPowered()) { 330 if (!adapter_->IsPowered()) {
331 chooser_->SetAdapterPresence( 331 chooser_->SetAdapterPresence(
332 BluetoothChooser::AdapterPresence::POWERED_OFF); 332 BluetoothChooser::AdapterPresence::POWERED_OFF);
333 return; 333 return;
334 } 334 }
335 335
336 StartDeviceDiscovery(); 336 StartDeviceDiscovery();
337 } 337 }
338 338
339 void BluetoothDeviceChooserController::AddFilteredDevice( 339 void BluetoothDeviceChooserController::AddFilteredDevice(
340 const device::BluetoothDevice& device) { 340 const device::BluetoothDevice& device) {
341 if (chooser_.get() && MatchesFilters(device, options_->filters)) { 341 if (chooser_.get() && MatchesFilters(device, options_->filters)) {
342 VLOG(1) << "Adding device to chooser: " << device.GetAddress();
343 chooser_->AddOrUpdateDevice( 342 chooser_->AddOrUpdateDevice(
344 device.GetAddress(), 343 device.GetAddress(),
345 // TODO(https://crbug.com/634366): Update device's name when necessary. 344 // TODO(https://crbug.com/634366): Update device's name when necessary.
346 false /* should_update_name */, device.GetNameForDisplay(), 345 false /* should_update_name */, device.GetNameForDisplay(),
347 // TODO(http://crbug.com/543466): Show connection and paired status. 346 // TODO(http://crbug.com/543466): Show connection and paired status.
348 false /* is_gatt_connected */, false /* is_paired */, 347 false /* is_gatt_connected */, false /* is_paired */,
349 // TODO(http://crbug.com/629689): Add signal strength indicator. 348 // TODO(http://crbug.com/629689): Add signal strength indicator.
350 nullptr /* rssi */); 349 nullptr /* rssi */);
351 } 350 }
352 } 351 }
(...skipping 15 matching lines...) Expand all
368 367
369 if (!powered) { 368 if (!powered) {
370 discovery_session_timer_.Stop(); 369 discovery_session_timer_.Stop();
371 } 370 }
372 } 371 }
373 372
374 void BluetoothDeviceChooserController::SetTestScanDurationForTesting() { 373 void BluetoothDeviceChooserController::SetTestScanDurationForTesting() {
375 BluetoothDeviceChooserController::use_test_scan_duration_ = true; 374 BluetoothDeviceChooserController::use_test_scan_duration_ = true;
376 } 375 }
377 376
378 void BluetoothDeviceChooserController::PopulateFoundDevices() { 377 void BluetoothDeviceChooserController::PopulateConnectedDevices() {
379 VLOG(1) << "Populating " << adapter_->GetDevices().size()
380 << " devices in chooser.";
381 for (const device::BluetoothDevice* device : adapter_->GetDevices()) { 378 for (const device::BluetoothDevice* device : adapter_->GetDevices()) {
382 AddFilteredDevice(*device); 379 if (device->IsGattConnected()) {
380 AddFilteredDevice(*device);
381 }
383 } 382 }
384 } 383 }
385 384
386 void BluetoothDeviceChooserController::StartDeviceDiscovery() { 385 void BluetoothDeviceChooserController::StartDeviceDiscovery() {
387 DCHECK_CURRENTLY_ON(BrowserThread::UI); 386 DCHECK_CURRENTLY_ON(BrowserThread::UI);
388 387
389 if (discovery_session_.get() && discovery_session_->IsActive()) { 388 if (discovery_session_.get() && discovery_session_->IsActive()) {
390 // Already running; just increase the timeout. 389 // Already running; just increase the timeout.
391 discovery_session_timer_.Reset(); 390 discovery_session_timer_.Reset();
392 return; 391 return;
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
432 431
433 void BluetoothDeviceChooserController::OnBluetoothChooserEvent( 432 void BluetoothDeviceChooserController::OnBluetoothChooserEvent(
434 BluetoothChooser::Event event, 433 BluetoothChooser::Event event,
435 const std::string& device_address) { 434 const std::string& device_address) {
436 DCHECK_CURRENTLY_ON(BrowserThread::UI); 435 DCHECK_CURRENTLY_ON(BrowserThread::UI);
437 // Shouldn't recieve an event from a closed chooser. 436 // Shouldn't recieve an event from a closed chooser.
438 DCHECK(chooser_.get()); 437 DCHECK(chooser_.get());
439 438
440 switch (event) { 439 switch (event) {
441 case BluetoothChooser::Event::RESCAN: 440 case BluetoothChooser::Event::RESCAN:
442 PopulateFoundDevices(); 441 PopulateConnectedDevices();
443 DCHECK(chooser_); 442 DCHECK(chooser_);
444 StartDeviceDiscovery(); 443 StartDeviceDiscovery();
445 // No need to close the chooser so we return. 444 // No need to close the chooser so we return.
446 return; 445 return;
447 case BluetoothChooser::Event::DENIED_PERMISSION: 446 case BluetoothChooser::Event::DENIED_PERMISSION:
448 RecordRequestDeviceOutcome(OutcomeFromChooserEvent(event)); 447 RecordRequestDeviceOutcome(OutcomeFromChooserEvent(event));
449 PostErrorCallback(blink::mojom::WebBluetoothError:: 448 PostErrorCallback(blink::mojom::WebBluetoothError::
450 CHOOSER_NOT_SHOWN_USER_DENIED_PERMISSION_TO_SCAN); 449 CHOOSER_NOT_SHOWN_USER_DENIED_PERMISSION_TO_SCAN);
451 break; 450 break;
452 case BluetoothChooser::Event::CANCELLED: 451 case BluetoothChooser::Event::CANCELLED:
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
488 487
489 void BluetoothDeviceChooserController::PostErrorCallback( 488 void BluetoothDeviceChooserController::PostErrorCallback(
490 blink::mojom::WebBluetoothError error) { 489 blink::mojom::WebBluetoothError error) {
491 if (!base::ThreadTaskRunnerHandle::Get()->PostTask( 490 if (!base::ThreadTaskRunnerHandle::Get()->PostTask(
492 FROM_HERE, base::Bind(error_callback_, error))) { 491 FROM_HERE, base::Bind(error_callback_, error))) {
493 LOG(WARNING) << "No TaskRunner."; 492 LOG(WARNING) << "No TaskRunner.";
494 } 493 }
495 } 494 }
496 495
497 } // namespace content 496 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698