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

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: Draft of LevelListDrawable and StateListDrawable Created 4 years, 2 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 200 matching lines...) Expand 10 before | Expand all | Expand 10 after
211 FROM_HERE, 211 FROM_HERE,
212 // TODO(jyasskin): Add a way for tests to control the dialog 212 // TODO(jyasskin): Add a way for tests to control the dialog
213 // directly, and change this to a reasonable discovery timeout. 213 // directly, and change this to a reasonable discovery timeout.
214 base::TimeDelta::FromSeconds( 214 base::TimeDelta::FromSeconds(
215 use_test_scan_duration_ ? kTestScanDuration : kScanDuration), 215 use_test_scan_duration_ ? kTestScanDuration : kScanDuration),
216 base::Bind(&BluetoothDeviceChooserController::StopDeviceDiscovery, 216 base::Bind(&BluetoothDeviceChooserController::StopDeviceDiscovery,
217 // base::Timer guarantees it won't call back after its 217 // base::Timer guarantees it won't call back after its
218 // destructor starts. 218 // destructor starts.
219 base::Unretained(this)), 219 base::Unretained(this)),
220 /*is_repeating=*/false), 220 /*is_repeating=*/false),
221 should_update_chooser_(false),
221 weak_ptr_factory_(this) { 222 weak_ptr_factory_(this) {
222 CHECK(adapter_); 223 CHECK(adapter_);
223 } 224 }
224 225
225 BluetoothDeviceChooserController::~BluetoothDeviceChooserController() { 226 BluetoothDeviceChooserController::~BluetoothDeviceChooserController() {
226 if (chooser_) { 227 if (chooser_) {
227 DCHECK(!error_callback_.is_null()); 228 DCHECK(!error_callback_.is_null());
228 error_callback_.Run(blink::mojom::WebBluetoothError::CHOOSER_CANCELLED); 229 error_callback_.Run(blink::mojom::WebBluetoothError::CHOOSER_CANCELLED);
229 } 230 }
230 } 231 }
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
328 return; 329 return;
329 } 330 }
330 331
331 if (!chooser_->CanAskForScanningPermission()) { 332 if (!chooser_->CanAskForScanningPermission()) {
332 VLOG(1) << "Closing immediately because Chooser cannot obtain permission."; 333 VLOG(1) << "Closing immediately because Chooser cannot obtain permission.";
333 OnBluetoothChooserEvent(BluetoothChooser::Event::DENIED_PERMISSION, 334 OnBluetoothChooserEvent(BluetoothChooser::Event::DENIED_PERMISSION,
334 "" /* device_address */); 335 "" /* device_address */);
335 return; 336 return;
336 } 337 }
337 338
339 should_update_chooser_ = true;
338 PopulateConnectedDevices(); 340 PopulateConnectedDevices();
339 if (!chooser_.get()) { 341 if (!chooser_.get()) {
340 // If the dialog's closing, no need to do any of the rest of this. 342 // If the dialog's closing, no need to do any of the rest of this.
341 return; 343 return;
342 } 344 }
343 345
344 if (!adapter_->IsPowered()) { 346 if (!adapter_->IsPowered()) {
345 chooser_->SetAdapterPresence( 347 chooser_->SetAdapterPresence(
346 BluetoothChooser::AdapterPresence::POWERED_OFF); 348 BluetoothChooser::AdapterPresence::POWERED_OFF);
347 return; 349 return;
348 } 350 }
349 351
350 StartDeviceDiscovery(); 352 StartDeviceDiscovery();
351 } 353 }
352 354
353 void BluetoothDeviceChooserController::AddFilteredDevice( 355 void BluetoothDeviceChooserController::AddFilteredDevice(
354 const device::BluetoothDevice& device) { 356 const device::BluetoothDevice& device) {
355 if (chooser_.get() && MatchesFilters(device, options_->filters)) { 357 if (should_update_chooser_ && chooser_.get() &&
358 MatchesFilters(device, options_->filters)) {
356 base::Optional<int8_t> rssi = device.GetInquiryRSSI(); 359 base::Optional<int8_t> rssi = device.GetInquiryRSSI();
357 chooser_->AddOrUpdateDevice( 360 chooser_->AddOrUpdateDevice(
358 device.GetAddress(), !!device.GetName() /* should_update_name */, 361 device.GetAddress(), !!device.GetName() /* should_update_name */,
359 device.GetNameForDisplay(), device.IsGattConnected(), 362 device.GetNameForDisplay(), device.IsGattConnected(),
360 web_bluetooth_service_->IsDevicePaired(device.GetAddress()), 363 web_bluetooth_service_->IsDevicePaired(device.GetAddress()),
361 rssi ? CalculateSignalStrengthLevel(rssi.value()) : -1); 364 rssi ? CalculateSignalStrengthLevel(rssi.value()) : -1);
362 } 365 }
363 } 366 }
364 367
365 void BluetoothDeviceChooserController::AdapterPoweredChanged(bool powered) { 368 void BluetoothDeviceChooserController::AdapterPoweredChanged(bool powered) {
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
422 base::Bind( 425 base::Bind(
423 &BluetoothDeviceChooserController::OnStartDiscoverySessionSuccess, 426 &BluetoothDeviceChooserController::OnStartDiscoverySessionSuccess,
424 weak_ptr_factory_.GetWeakPtr()), 427 weak_ptr_factory_.GetWeakPtr()),
425 base::Bind( 428 base::Bind(
426 &BluetoothDeviceChooserController::OnStartDiscoverySessionFailed, 429 &BluetoothDeviceChooserController::OnStartDiscoverySessionFailed,
427 weak_ptr_factory_.GetWeakPtr())); 430 weak_ptr_factory_.GetWeakPtr()));
428 } 431 }
429 432
430 void BluetoothDeviceChooserController::StopDeviceDiscovery() { 433 void BluetoothDeviceChooserController::StopDeviceDiscovery() {
431 DCHECK_CURRENTLY_ON(BrowserThread::UI); 434 DCHECK_CURRENTLY_ON(BrowserThread::UI);
435 should_update_chooser_ = false;
432 StopDiscoverySession(std::move(discovery_session_)); 436 StopDiscoverySession(std::move(discovery_session_));
433 if (chooser_) { 437 if (chooser_) {
434 chooser_->ShowDiscoveryState(BluetoothChooser::DiscoveryState::IDLE); 438 chooser_->ShowDiscoveryState(BluetoothChooser::DiscoveryState::IDLE);
435 } 439 }
436 } 440 }
437 441
438 void BluetoothDeviceChooserController::OnStartDiscoverySessionSuccess( 442 void BluetoothDeviceChooserController::OnStartDiscoverySessionSuccess(
439 std::unique_ptr<device::BluetoothDiscoverySession> discovery_session) { 443 std::unique_ptr<device::BluetoothDiscoverySession> discovery_session) {
440 DCHECK_CURRENTLY_ON(BrowserThread::UI); 444 DCHECK_CURRENTLY_ON(BrowserThread::UI);
441 VLOG(1) << "Started discovery session."; 445 VLOG(1) << "Started discovery session.";
(...skipping 14 matching lines...) Expand all
456 460
457 void BluetoothDeviceChooserController::OnBluetoothChooserEvent( 461 void BluetoothDeviceChooserController::OnBluetoothChooserEvent(
458 BluetoothChooser::Event event, 462 BluetoothChooser::Event event,
459 const std::string& device_address) { 463 const std::string& device_address) {
460 DCHECK_CURRENTLY_ON(BrowserThread::UI); 464 DCHECK_CURRENTLY_ON(BrowserThread::UI);
461 // Shouldn't recieve an event from a closed chooser. 465 // Shouldn't recieve an event from a closed chooser.
462 DCHECK(chooser_.get()); 466 DCHECK(chooser_.get());
463 467
464 switch (event) { 468 switch (event) {
465 case BluetoothChooser::Event::RESCAN: 469 case BluetoothChooser::Event::RESCAN:
470 should_update_chooser_ = true;
466 PopulateConnectedDevices(); 471 PopulateConnectedDevices();
467 DCHECK(chooser_); 472 DCHECK(chooser_);
468 StartDeviceDiscovery(); 473 StartDeviceDiscovery();
469 // No need to close the chooser so we return. 474 // No need to close the chooser so we return.
470 return; 475 return;
471 case BluetoothChooser::Event::DENIED_PERMISSION: 476 case BluetoothChooser::Event::DENIED_PERMISSION:
472 RecordRequestDeviceOutcome(OutcomeFromChooserEvent(event)); 477 RecordRequestDeviceOutcome(OutcomeFromChooserEvent(event));
473 PostErrorCallback(blink::mojom::WebBluetoothError:: 478 PostErrorCallback(blink::mojom::WebBluetoothError::
474 CHOOSER_NOT_SHOWN_USER_DENIED_PERMISSION_TO_SCAN); 479 CHOOSER_NOT_SHOWN_USER_DENIED_PERMISSION_TO_SCAN);
475 break; 480 break;
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
512 517
513 void BluetoothDeviceChooserController::PostErrorCallback( 518 void BluetoothDeviceChooserController::PostErrorCallback(
514 blink::mojom::WebBluetoothError error) { 519 blink::mojom::WebBluetoothError error) {
515 if (!base::ThreadTaskRunnerHandle::Get()->PostTask( 520 if (!base::ThreadTaskRunnerHandle::Get()->PostTask(
516 FROM_HERE, base::Bind(error_callback_, error))) { 521 FROM_HERE, base::Bind(error_callback_, error))) {
517 LOG(WARNING) << "No TaskRunner."; 522 LOG(WARNING) << "No TaskRunner.";
518 } 523 }
519 } 524 }
520 525
521 } // namespace content 526 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698