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

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

Issue 2271413002: bluetooth: Implement RSSI indicator on android (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@bluetooth-impl-rssi-tx-power
Patch Set: Clean up Created 4 years, 3 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 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 FROM_HERE, 207 FROM_HERE,
208 // TODO(jyasskin): Add a way for tests to control the dialog 208 // TODO(jyasskin): Add a way for tests to control the dialog
209 // directly, and change this to a reasonable discovery timeout. 209 // directly, and change this to a reasonable discovery timeout.
210 base::TimeDelta::FromSeconds( 210 base::TimeDelta::FromSeconds(
211 use_test_scan_duration_ ? kTestScanDuration : kScanDuration), 211 use_test_scan_duration_ ? kTestScanDuration : kScanDuration),
212 base::Bind(&BluetoothDeviceChooserController::StopDeviceDiscovery, 212 base::Bind(&BluetoothDeviceChooserController::StopDeviceDiscovery,
213 // base::Timer guarantees it won't call back after its 213 // base::Timer guarantees it won't call back after its
214 // destructor starts. 214 // destructor starts.
215 base::Unretained(this)), 215 base::Unretained(this)),
216 /*is_repeating=*/false), 216 /*is_repeating=*/false),
217 should_update_chooser_(false),
217 weak_ptr_factory_(this) { 218 weak_ptr_factory_(this) {
218 CHECK(adapter_); 219 CHECK(adapter_);
219 } 220 }
220 221
221 BluetoothDeviceChooserController::~BluetoothDeviceChooserController() { 222 BluetoothDeviceChooserController::~BluetoothDeviceChooserController() {
222 if (chooser_) { 223 if (chooser_) {
223 DCHECK(!error_callback_.is_null()); 224 DCHECK(!error_callback_.is_null());
224 error_callback_.Run(blink::mojom::WebBluetoothError::CHOOSER_CANCELLED); 225 error_callback_.Run(blink::mojom::WebBluetoothError::CHOOSER_CANCELLED);
225 } 226 }
226 } 227 }
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
324 return; 325 return;
325 } 326 }
326 327
327 if (!chooser_->CanAskForScanningPermission()) { 328 if (!chooser_->CanAskForScanningPermission()) {
328 VLOG(1) << "Closing immediately because Chooser cannot obtain permission."; 329 VLOG(1) << "Closing immediately because Chooser cannot obtain permission.";
329 OnBluetoothChooserEvent(BluetoothChooser::Event::DENIED_PERMISSION, 330 OnBluetoothChooserEvent(BluetoothChooser::Event::DENIED_PERMISSION,
330 "" /* device_address */); 331 "" /* device_address */);
331 return; 332 return;
332 } 333 }
333 334
335 should_update_chooser_ = true;
334 PopulateConnectedDevices(); 336 PopulateConnectedDevices();
335 if (!chooser_.get()) { 337 if (!chooser_.get()) {
336 // If the dialog's closing, no need to do any of the rest of this. 338 // If the dialog's closing, no need to do any of the rest of this.
337 return; 339 return;
338 } 340 }
339 341
340 if (!adapter_->IsPowered()) { 342 if (!adapter_->IsPowered()) {
341 chooser_->SetAdapterPresence( 343 chooser_->SetAdapterPresence(
342 BluetoothChooser::AdapterPresence::POWERED_OFF); 344 BluetoothChooser::AdapterPresence::POWERED_OFF);
343 return; 345 return;
344 } 346 }
345 347
346 StartDeviceDiscovery(); 348 StartDeviceDiscovery();
347 } 349 }
348 350
349 void BluetoothDeviceChooserController::AddFilteredDevice( 351 void BluetoothDeviceChooserController::AddFilteredDevice(
350 const device::BluetoothDevice& device) { 352 const device::BluetoothDevice& device) {
351 if (chooser_.get() && MatchesFilters(device, options_->filters)) { 353 if (should_update_chooser_ && chooser_.get() &&
354 MatchesFilters(device, options_->filters)) {
352 base::Optional<int8_t> rssi = device.GetInquiryRSSI(); 355 base::Optional<int8_t> rssi = device.GetInquiryRSSI();
353 chooser_->AddOrUpdateDevice( 356 chooser_->AddOrUpdateDevice(
354 device.GetAddress(), !!device.GetName() /* should_update_name */, 357 device.GetAddress(), !!device.GetName() /* should_update_name */,
355 device.GetNameForDisplay(), 358 device.GetNameForDisplay(),
356 // TODO(http://crbug.com/543466): Show connection and paired status. 359 // TODO(http://crbug.com/543466): Show connection and paired status.
357 false /* is_gatt_connected */, false /* is_paired */, 360 false /* is_gatt_connected */, false /* is_paired */,
358 rssi ? CalculateSignalStrengthLevel(rssi.value()) : -1); 361 rssi ? CalculateSignalStrengthLevel(rssi.value()) : -1);
359 } 362 }
360 } 363 }
361 364
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
419 base::Bind( 422 base::Bind(
420 &BluetoothDeviceChooserController::OnStartDiscoverySessionSuccess, 423 &BluetoothDeviceChooserController::OnStartDiscoverySessionSuccess,
421 weak_ptr_factory_.GetWeakPtr()), 424 weak_ptr_factory_.GetWeakPtr()),
422 base::Bind( 425 base::Bind(
423 &BluetoothDeviceChooserController::OnStartDiscoverySessionFailed, 426 &BluetoothDeviceChooserController::OnStartDiscoverySessionFailed,
424 weak_ptr_factory_.GetWeakPtr())); 427 weak_ptr_factory_.GetWeakPtr()));
425 } 428 }
426 429
427 void BluetoothDeviceChooserController::StopDeviceDiscovery() { 430 void BluetoothDeviceChooserController::StopDeviceDiscovery() {
428 DCHECK_CURRENTLY_ON(BrowserThread::UI); 431 DCHECK_CURRENTLY_ON(BrowserThread::UI);
432 should_update_chooser_ = false;
429 StopDiscoverySession(std::move(discovery_session_)); 433 StopDiscoverySession(std::move(discovery_session_));
430 if (chooser_) { 434 if (chooser_) {
431 chooser_->ShowDiscoveryState(BluetoothChooser::DiscoveryState::IDLE); 435 chooser_->ShowDiscoveryState(BluetoothChooser::DiscoveryState::IDLE);
432 } 436 }
433 } 437 }
434 438
435 void BluetoothDeviceChooserController::OnStartDiscoverySessionSuccess( 439 void BluetoothDeviceChooserController::OnStartDiscoverySessionSuccess(
436 std::unique_ptr<device::BluetoothDiscoverySession> discovery_session) { 440 std::unique_ptr<device::BluetoothDiscoverySession> discovery_session) {
437 DCHECK_CURRENTLY_ON(BrowserThread::UI); 441 DCHECK_CURRENTLY_ON(BrowserThread::UI);
438 VLOG(1) << "Started discovery session."; 442 VLOG(1) << "Started discovery session.";
(...skipping 14 matching lines...) Expand all
453 457
454 void BluetoothDeviceChooserController::OnBluetoothChooserEvent( 458 void BluetoothDeviceChooserController::OnBluetoothChooserEvent(
455 BluetoothChooser::Event event, 459 BluetoothChooser::Event event,
456 const std::string& device_address) { 460 const std::string& device_address) {
457 DCHECK_CURRENTLY_ON(BrowserThread::UI); 461 DCHECK_CURRENTLY_ON(BrowserThread::UI);
458 // Shouldn't recieve an event from a closed chooser. 462 // Shouldn't recieve an event from a closed chooser.
459 DCHECK(chooser_.get()); 463 DCHECK(chooser_.get());
460 464
461 switch (event) { 465 switch (event) {
462 case BluetoothChooser::Event::RESCAN: 466 case BluetoothChooser::Event::RESCAN:
467 should_update_chooser_ = true;
463 PopulateConnectedDevices(); 468 PopulateConnectedDevices();
464 DCHECK(chooser_); 469 DCHECK(chooser_);
465 StartDeviceDiscovery(); 470 StartDeviceDiscovery();
466 // No need to close the chooser so we return. 471 // No need to close the chooser so we return.
467 return; 472 return;
468 case BluetoothChooser::Event::DENIED_PERMISSION: 473 case BluetoothChooser::Event::DENIED_PERMISSION:
469 RecordRequestDeviceOutcome(OutcomeFromChooserEvent(event)); 474 RecordRequestDeviceOutcome(OutcomeFromChooserEvent(event));
470 PostErrorCallback(blink::mojom::WebBluetoothError:: 475 PostErrorCallback(blink::mojom::WebBluetoothError::
471 CHOOSER_NOT_SHOWN_USER_DENIED_PERMISSION_TO_SCAN); 476 CHOOSER_NOT_SHOWN_USER_DENIED_PERMISSION_TO_SCAN);
472 break; 477 break;
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
509 514
510 void BluetoothDeviceChooserController::PostErrorCallback( 515 void BluetoothDeviceChooserController::PostErrorCallback(
511 blink::mojom::WebBluetoothError error) { 516 blink::mojom::WebBluetoothError error) {
512 if (!base::ThreadTaskRunnerHandle::Get()->PostTask( 517 if (!base::ThreadTaskRunnerHandle::Get()->PostTask(
513 FROM_HERE, base::Bind(error_callback_, error))) { 518 FROM_HERE, base::Bind(error_callback_, error))) {
514 LOG(WARNING) << "No TaskRunner."; 519 LOG(WARNING) << "No TaskRunner.";
515 } 520 }
516 } 521 }
517 522
518 } // namespace content 523 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698