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

Unified Diff: chrome/browser/ui/bluetooth/bluetooth_chooser_controller.cc

Issue 2155743002: Add throbber and status text to WebBluetooth chooser UI on non-Mac desktops (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: address comments Created 4 years, 5 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/bluetooth/bluetooth_chooser_controller.cc
diff --git a/chrome/browser/ui/bluetooth/bluetooth_chooser_controller.cc b/chrome/browser/ui/bluetooth/bluetooth_chooser_controller.cc
index 173fc18848dd1fe1d4f904dd4b9abd51616ab0e2..5c0f2e410d7a1a390de43fb6129f3fe0596885d3 100644
--- a/chrome/browser/ui/bluetooth/bluetooth_chooser_controller.cc
+++ b/chrome/browser/ui/bluetooth/bluetooth_chooser_controller.cc
@@ -32,10 +32,16 @@ BluetoothChooserController::BluetoothChooserController(
: ChooserController(owner,
IDS_BLUETOOTH_DEVICE_CHOOSER_PROMPT_ORIGIN,
IDS_BLUETOOTH_DEVICE_CHOOSER_PROMPT_EXTENSION_NAME),
- event_handler_(event_handler) {}
+ event_handler_(event_handler),
+ no_devices_text_(l10n_util::GetStringUTF16(
+ IDS_DEVICE_CHOOSER_NO_DEVICES_FOUND_PROMPT)) {}
BluetoothChooserController::~BluetoothChooserController() {}
+base::string16 BluetoothChooserController::GetNoOptionsText() const {
+ return no_devices_text_;
+}
+
base::string16 BluetoothChooserController::GetOkButtonLabel() const {
return l10n_util::GetStringUTF16(
IDS_BLUETOOTH_DEVICE_CHOOSER_PAIR_BUTTON_TEXT);
@@ -57,6 +63,15 @@ base::string16 BluetoothChooserController::GetOption(size_t index) const {
base::UTF8ToUTF16(device_names_and_ids_[index].second));
}
+void BluetoothChooserController::RefreshOptions() {
+ ClearAllDevices();
+ event_handler_.Run(content::BluetoothChooser::Event::RESCAN, std::string());
+}
+
+base::string16 BluetoothChooserController::GetStatus() const {
+ return status_text_;
+}
+
void BluetoothChooserController::Select(size_t index) {
DCHECK_LT(index, device_names_and_ids_.size());
event_handler_.Run(content::BluetoothChooser::Event::SELECTED,
@@ -80,6 +95,49 @@ void BluetoothChooserController::OpenHelpCenterUrl() const {
false /* is_renderer_initialized */));
}
+void BluetoothChooserController::UpdateAdapterPresence(
+ content::BluetoothChooser::AdapterPresence presence) {
+ ClearAllDevices();
+ switch (presence) {
+ case content::BluetoothChooser::AdapterPresence::ABSENT:
msw 2016/07/18 23:01:30 Should this case send observer()->AdapterEnabled(f
juncai 2016/07/19 20:42:46 When there is no Bluetooth adapter, the Bluetooth
msw 2016/07/19 22:08:10 Acknowledged.
+ break;
+ case content::BluetoothChooser::AdapterPresence::POWERED_OFF:
+ no_devices_text_ = l10n_util::GetStringUTF16(
+ IDS_BLUETOOTH_DEVICE_CHOOSER_NO_DEVICES_FOUND_ADAPTER_OFF_PROMPT);
+ status_text_ = base::string16();
+ if (observer())
+ observer()->AdapterEnabled(false /* Bluetooth adapter is truned off */);
msw 2016/07/18 23:01:30 nit: 'turned'
juncai 2016/07/19 20:42:46 Done.
+ break;
+ case content::BluetoothChooser::AdapterPresence::POWERED_ON:
+ no_devices_text_ =
+ l10n_util::GetStringUTF16(IDS_DEVICE_CHOOSER_NO_DEVICES_FOUND_PROMPT);
+ status_text_ =
+ l10n_util::GetStringUTF16(IDS_BLUETOOTH_DEVICE_CHOOSER_RE_SCAN);
+ if (observer())
+ observer()->AdapterEnabled(true /* Bluetooth adapter is turned on */);
+ break;
+ }
+}
+
+void BluetoothChooserController::UpdateDiscoveryState(
+ content::BluetoothChooser::DiscoveryState state) {
+ switch (state) {
+ case content::BluetoothChooser::DiscoveryState::DISCOVERING:
+ status_text_ =
+ l10n_util::GetStringUTF16(IDS_BLUETOOTH_DEVICE_CHOOSER_SCANNING);
+ if (observer())
+ observer()->SetRefreshing(true /* Refreshing options is in progress */);
+ break;
+ case content::BluetoothChooser::DiscoveryState::IDLE:
+ case content::BluetoothChooser::DiscoveryState::FAILED_TO_START:
+ status_text_ =
+ l10n_util::GetStringUTF16(IDS_BLUETOOTH_DEVICE_CHOOSER_RE_SCAN);
+ if (observer())
+ observer()->SetRefreshing(false /* Refreshing options is complete*/);
+ break;
+ }
+}
+
void BluetoothChooserController::AddDevice(const std::string& device_id,
const base::string16& device_name) {
device_names_and_ids_.push_back(std::make_pair(device_name, device_id));
@@ -103,3 +161,8 @@ void BluetoothChooserController::RemoveDevice(const std::string& device_id) {
}
}
}
+
+void BluetoothChooserController::ClearAllDevices() {
+ device_names_and_ids_.clear();
+ device_name_map_.clear();
+}

Powered by Google App Engine
This is Rietveld 408576698