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

Side by Side 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: removed some unnecessary include files and forward declarations 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 unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "chrome/browser/ui/bluetooth/bluetooth_chooser_controller.h" 5 #include "chrome/browser/ui/bluetooth/bluetooth_chooser_controller.h"
6 6
7 #include "base/strings/utf_string_conversions.h" 7 #include "base/strings/utf_string_conversions.h"
8 #include "chrome/browser/net/referrer.h" 8 #include "chrome/browser/net/referrer.h"
9 #include "chrome/browser/profiles/profile_manager.h" 9 #include "chrome/browser/profiles/profile_manager.h"
10 #include "chrome/browser/ui/bluetooth/bluetooth_chooser_desktop.h" 10 #include "chrome/browser/ui/bluetooth/bluetooth_chooser_desktop.h"
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 const base::string16& device_name = device_names_and_ids_[index].first; 50 const base::string16& device_name = device_names_and_ids_[index].first;
51 const auto& it = device_name_map_.find(device_name); 51 const auto& it = device_name_map_.find(device_name);
52 DCHECK(it != device_name_map_.end()); 52 DCHECK(it != device_name_map_.end());
53 return it->second == 1 53 return it->second == 1
54 ? device_name 54 ? device_name
55 : l10n_util::GetStringFUTF16( 55 : l10n_util::GetStringFUTF16(
56 IDS_DEVICE_CHOOSER_DEVICE_NAME_WITH_ID, device_name, 56 IDS_DEVICE_CHOOSER_DEVICE_NAME_WITH_ID, device_name,
57 base::UTF8ToUTF16(device_names_and_ids_[index].second)); 57 base::UTF8ToUTF16(device_names_and_ids_[index].second));
58 } 58 }
59 59
60 void BluetoothChooserController::RefreshOptions() {
61 ClearAllDevices();
62 event_handler_.Run(content::BluetoothChooser::Event::RESCAN, std::string());
63 }
64
65 bool BluetoothChooserController::NeedsThrobber() const {
66 return true;
67 }
68
69 bool BluetoothChooserController::NeedsStatus() const {
70 return true;
71 }
72
60 void BluetoothChooserController::Select(size_t index) { 73 void BluetoothChooserController::Select(size_t index) {
61 DCHECK_LT(index, device_names_and_ids_.size()); 74 DCHECK_LT(index, device_names_and_ids_.size());
62 event_handler_.Run(content::BluetoothChooser::Event::SELECTED, 75 event_handler_.Run(content::BluetoothChooser::Event::SELECTED,
63 device_names_and_ids_[index].second); 76 device_names_and_ids_[index].second);
64 } 77 }
65 78
66 void BluetoothChooserController::Cancel() { 79 void BluetoothChooserController::Cancel() {
67 event_handler_.Run(content::BluetoothChooser::Event::CANCELLED, 80 event_handler_.Run(content::BluetoothChooser::Event::CANCELLED,
68 std::string()); 81 std::string());
69 } 82 }
70 83
71 void BluetoothChooserController::Close() { 84 void BluetoothChooserController::Close() {
72 event_handler_.Run(content::BluetoothChooser::Event::CANCELLED, 85 event_handler_.Run(content::BluetoothChooser::Event::CANCELLED,
73 std::string()); 86 std::string());
74 } 87 }
75 88
76 void BluetoothChooserController::OpenHelpCenterUrl() const { 89 void BluetoothChooserController::OpenHelpCenterUrl() const {
77 GetBrowser()->OpenURL(content::OpenURLParams( 90 GetBrowser()->OpenURL(content::OpenURLParams(
78 GURL(chrome::kChooserBluetoothOverviewURL), content::Referrer(), 91 GURL(chrome::kChooserBluetoothOverviewURL), content::Referrer(),
79 NEW_FOREGROUND_TAB, ui::PAGE_TRANSITION_AUTO_TOPLEVEL, 92 NEW_FOREGROUND_TAB, ui::PAGE_TRANSITION_AUTO_TOPLEVEL,
80 false /* is_renderer_initialized */)); 93 false /* is_renderer_initialized */));
81 } 94 }
82 95
96 void BluetoothChooserController::UpdateAdapterPresence(
97 content::BluetoothChooser::AdapterPresence presence) {
98 ClearAllDevices();
99 switch (presence) {
100 case content::BluetoothChooser::AdapterPresence::ABSENT:
101 break;
102 case content::BluetoothChooser::AdapterPresence::POWERED_OFF:
103 if (observer())
104 observer()->AdapterOff();
105 break;
106 case content::BluetoothChooser::AdapterPresence::POWERED_ON:
107 if (observer())
108 observer()->AdapterOn();
109 break;
110 }
111 }
112
113 void BluetoothChooserController::UpdateDiscoveryState(
114 content::BluetoothChooser::DiscoveryState state) {
115 switch (state) {
116 case content::BluetoothChooser::DiscoveryState::DISCOVERING:
117 if (observer())
118 observer()->Refresh();
119 break;
120 case content::BluetoothChooser::DiscoveryState::IDLE:
121 case content::BluetoothChooser::DiscoveryState::FAILED_TO_START:
122 if (observer())
123 observer()->Idle();
124 break;
125 }
126 }
127
83 void BluetoothChooserController::AddDevice(const std::string& device_id, 128 void BluetoothChooserController::AddDevice(const std::string& device_id,
84 const base::string16& device_name) { 129 const base::string16& device_name) {
85 device_names_and_ids_.push_back(std::make_pair(device_name, device_id)); 130 device_names_and_ids_.push_back(std::make_pair(device_name, device_id));
86 ++device_name_map_[device_name]; 131 ++device_name_map_[device_name];
87 if (observer()) 132 if (observer())
88 observer()->OnOptionAdded(device_names_and_ids_.size() - 1); 133 observer()->OnOptionAdded(device_names_and_ids_.size() - 1);
89 } 134 }
90 135
91 void BluetoothChooserController::RemoveDevice(const std::string& device_id) { 136 void BluetoothChooserController::RemoveDevice(const std::string& device_id) {
92 for (auto it = device_names_and_ids_.begin(); 137 for (auto it = device_names_and_ids_.begin();
93 it != device_names_and_ids_.end(); ++it) { 138 it != device_names_and_ids_.end(); ++it) {
94 if (it->second == device_id) { 139 if (it->second == device_id) {
95 size_t index = it - device_names_and_ids_.begin(); 140 size_t index = it - device_names_and_ids_.begin();
96 DCHECK_GT(device_name_map_[it->first], 0); 141 DCHECK_GT(device_name_map_[it->first], 0);
97 if (--device_name_map_[it->first] == 0) 142 if (--device_name_map_[it->first] == 0)
98 device_name_map_.erase(it->first); 143 device_name_map_.erase(it->first);
99 device_names_and_ids_.erase(it); 144 device_names_and_ids_.erase(it);
100 if (observer()) 145 if (observer())
101 observer()->OnOptionRemoved(index); 146 observer()->OnOptionRemoved(index);
102 return; 147 return;
103 } 148 }
104 } 149 }
105 } 150 }
151
152 void BluetoothChooserController::ClearAllDevices() {
153 device_names_and_ids_.clear();
154 device_name_map_.clear();
155 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698