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

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

Issue 2577183002: Add UMA for the number of devices in the chooser when a device is paired (Closed)
Patch Set: address comments Created 4 years 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 411 matching lines...) Expand 10 before | Expand all | Expand 10 after
422 } 422 }
423 423
424 void BluetoothDeviceChooserController::AddFilteredDevice( 424 void BluetoothDeviceChooserController::AddFilteredDevice(
425 const device::BluetoothDevice& device) { 425 const device::BluetoothDevice& device) {
426 base::Optional<std::string> device_name = device.GetName(); 426 base::Optional<std::string> device_name = device.GetName();
427 if (chooser_.get()) { 427 if (chooser_.get()) {
428 if (options_->accept_all_devices || 428 if (options_->accept_all_devices ||
429 MatchesFilters(device_name ? &device_name.value() : nullptr, 429 MatchesFilters(device_name ? &device_name.value() : nullptr,
430 device.GetUUIDs(), options_->filters)) { 430 device.GetUUIDs(), options_->filters)) {
431 base::Optional<int8_t> rssi = device.GetInquiryRSSI(); 431 base::Optional<int8_t> rssi = device.GetInquiryRSSI();
432 std::string device_id = device.GetAddress();
433 device_ids_.insert(device_id);
Reilly Grant (use Gerrit) 2016/12/19 20:52:17 I was going to note that you should call device_id
juncai 2016/12/19 22:16:13 Thanks! I filed a bug for it: https://bugs.chromiu
432 chooser_->AddOrUpdateDevice( 434 chooser_->AddOrUpdateDevice(
433 device.GetAddress(), !!device.GetName() /* should_update_name */, 435 device_id, !!device.GetName() /* should_update_name */,
434 device.GetNameForDisplay(), device.IsGattConnected(), 436 device.GetNameForDisplay(), device.IsGattConnected(),
435 web_bluetooth_service_->IsDevicePaired(device.GetAddress()), 437 web_bluetooth_service_->IsDevicePaired(device.GetAddress()),
436 rssi ? CalculateSignalStrengthLevel(rssi.value()) : -1); 438 rssi ? CalculateSignalStrengthLevel(rssi.value()) : -1);
437 } 439 }
438 } 440 }
439 } 441 }
440 442
441 void BluetoothDeviceChooserController::AdapterPoweredChanged(bool powered) { 443 void BluetoothDeviceChooserController::AdapterPoweredChanged(bool powered) {
442 if (!powered && discovery_session_.get()) { 444 if (!powered && discovery_session_.get()) {
443 StopDiscoverySession(std::move(discovery_session_)); 445 StopDiscoverySession(std::move(discovery_session_));
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
494 496
495 void BluetoothDeviceChooserController::StartDeviceDiscovery() { 497 void BluetoothDeviceChooserController::StartDeviceDiscovery() {
496 DCHECK_CURRENTLY_ON(BrowserThread::UI); 498 DCHECK_CURRENTLY_ON(BrowserThread::UI);
497 499
498 if (discovery_session_.get() && discovery_session_->IsActive()) { 500 if (discovery_session_.get() && discovery_session_->IsActive()) {
499 // Already running; just increase the timeout. 501 // Already running; just increase the timeout.
500 discovery_session_timer_.Reset(); 502 discovery_session_timer_.Reset();
501 return; 503 return;
502 } 504 }
503 505
506 device_ids_.clear();
507
504 scanning_start_time_ = base::TimeTicks::Now(); 508 scanning_start_time_ = base::TimeTicks::Now();
505 509
506 chooser_->ShowDiscoveryState(BluetoothChooser::DiscoveryState::DISCOVERING); 510 chooser_->ShowDiscoveryState(BluetoothChooser::DiscoveryState::DISCOVERING);
507 adapter_->StartDiscoverySessionWithFilter( 511 adapter_->StartDiscoverySessionWithFilter(
508 ComputeScanFilter(options_->filters), 512 ComputeScanFilter(options_->filters),
509 base::Bind( 513 base::Bind(
510 &BluetoothDeviceChooserController::OnStartDiscoverySessionSuccess, 514 &BluetoothDeviceChooserController::OnStartDiscoverySessionSuccess,
511 weak_ptr_factory_.GetWeakPtr()), 515 weak_ptr_factory_.GetWeakPtr()),
512 base::Bind( 516 base::Bind(
513 &BluetoothDeviceChooserController::OnStartDiscoverySessionFailed, 517 &BluetoothDeviceChooserController::OnStartDiscoverySessionFailed,
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
581 VLOG(1) << "Adapter Off Help link pressed."; 585 VLOG(1) << "Adapter Off Help link pressed.";
582 RecordRequestDeviceOutcome(OutcomeFromChooserEvent(event)); 586 RecordRequestDeviceOutcome(OutcomeFromChooserEvent(event));
583 PostErrorCallback(blink::mojom::WebBluetoothResult::CHOOSER_CANCELLED); 587 PostErrorCallback(blink::mojom::WebBluetoothResult::CHOOSER_CANCELLED);
584 break; 588 break;
585 case BluetoothChooser::Event::SHOW_NEED_LOCATION_HELP: 589 case BluetoothChooser::Event::SHOW_NEED_LOCATION_HELP:
586 VLOG(1) << "Need Location Help link pressed."; 590 VLOG(1) << "Need Location Help link pressed.";
587 RecordRequestDeviceOutcome(OutcomeFromChooserEvent(event)); 591 RecordRequestDeviceOutcome(OutcomeFromChooserEvent(event));
588 PostErrorCallback(blink::mojom::WebBluetoothResult::CHOOSER_CANCELLED); 592 PostErrorCallback(blink::mojom::WebBluetoothResult::CHOOSER_CANCELLED);
589 break; 593 break;
590 case BluetoothChooser::Event::SELECTED: 594 case BluetoothChooser::Event::SELECTED:
595 RecordNumOfDevices(options_->accept_all_devices, device_ids_.size());
591 // RecordRequestDeviceOutcome is called in the callback, because the 596 // RecordRequestDeviceOutcome is called in the callback, because the
592 // device may have vanished. 597 // device may have vanished.
593 PostSuccessCallback(device_address); 598 PostSuccessCallback(device_address);
594 break; 599 break;
595 } 600 }
596 // Close chooser. 601 // Close chooser.
597 chooser_.reset(); 602 chooser_.reset();
598 } 603 }
599 604
600 void BluetoothDeviceChooserController::PostSuccessCallback( 605 void BluetoothDeviceChooserController::PostSuccessCallback(
601 const std::string& device_address) { 606 const std::string& device_address) {
602 if (!base::ThreadTaskRunnerHandle::Get()->PostTask( 607 if (!base::ThreadTaskRunnerHandle::Get()->PostTask(
603 FROM_HERE, 608 FROM_HERE,
604 base::Bind(success_callback_, base::Passed(std::move(options_)), 609 base::Bind(success_callback_, base::Passed(std::move(options_)),
605 device_address))) { 610 device_address))) {
606 LOG(WARNING) << "No TaskRunner."; 611 LOG(WARNING) << "No TaskRunner.";
607 } 612 }
608 } 613 }
609 614
610 void BluetoothDeviceChooserController::PostErrorCallback( 615 void BluetoothDeviceChooserController::PostErrorCallback(
611 blink::mojom::WebBluetoothResult error) { 616 blink::mojom::WebBluetoothResult error) {
612 if (!base::ThreadTaskRunnerHandle::Get()->PostTask( 617 if (!base::ThreadTaskRunnerHandle::Get()->PostTask(
613 FROM_HERE, base::Bind(error_callback_, error))) { 618 FROM_HERE, base::Bind(error_callback_, error))) {
614 LOG(WARNING) << "No TaskRunner."; 619 LOG(WARNING) << "No TaskRunner.";
615 } 620 }
616 } 621 }
617 622
618 } // namespace content 623 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/bluetooth/bluetooth_device_chooser_controller.h ('k') | content/browser/bluetooth/bluetooth_metrics.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698