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

Side by Side Diff: ash/common/system/chromeos/bluetooth/tray_bluetooth.cc

Issue 2761993002: cros: Eliminate bluetooth methods from SystemTrayDelegate (Closed)
Patch Set: rebase Created 3 years, 9 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "ash/common/system/chromeos/bluetooth/tray_bluetooth.h" 5 #include "ash/common/system/chromeos/bluetooth/tray_bluetooth.h"
6 6
7 #include "ash/common/session/session_state_delegate.h" 7 #include "ash/common/session/session_state_delegate.h"
8 #include "ash/common/system/chromeos/bluetooth/tray_bluetooth_helper.h"
8 #include "ash/common/system/tray/hover_highlight_view.h" 9 #include "ash/common/system/tray/hover_highlight_view.h"
9 #include "ash/common/system/tray/system_tray.h" 10 #include "ash/common/system/tray/system_tray.h"
10 #include "ash/common/system/tray/system_tray_controller.h" 11 #include "ash/common/system/tray/system_tray_controller.h"
11 #include "ash/common/system/tray/system_tray_delegate.h"
12 #include "ash/common/system/tray/system_tray_notifier.h" 12 #include "ash/common/system/tray/system_tray_notifier.h"
13 #include "ash/common/system/tray/throbber_view.h" 13 #include "ash/common/system/tray/throbber_view.h"
14 #include "ash/common/system/tray/tray_constants.h" 14 #include "ash/common/system/tray/tray_constants.h"
15 #include "ash/common/system/tray/tray_details_view.h" 15 #include "ash/common/system/tray/tray_details_view.h"
16 #include "ash/common/system/tray/tray_item_more.h" 16 #include "ash/common/system/tray/tray_item_more.h"
17 #include "ash/common/system/tray/tray_popup_item_style.h" 17 #include "ash/common/system/tray/tray_popup_item_style.h"
18 #include "ash/common/system/tray/tray_popup_utils.h" 18 #include "ash/common/system/tray/tray_popup_utils.h"
19 #include "ash/common/system/tray/tri_view.h" 19 #include "ash/common/system/tray/tri_view.h"
20 #include "ash/common/wm_shell.h" 20 #include "ash/common/wm_shell.h"
21 #include "ash/resources/grit/ash_resources.h" 21 #include "ash/resources/grit/ash_resources.h"
22 #include "ash/resources/vector_icons/vector_icons.h" 22 #include "ash/resources/vector_icons/vector_icons.h"
23 #include "ash/shell.h"
23 #include "ash/strings/grit/ash_strings.h" 24 #include "ash/strings/grit/ash_strings.h"
24 #include "device/bluetooth/bluetooth_common.h" 25 #include "device/bluetooth/bluetooth_common.h"
25 #include "ui/base/l10n/l10n_util.h" 26 #include "ui/base/l10n/l10n_util.h"
26 #include "ui/base/resource/resource_bundle.h" 27 #include "ui/base/resource/resource_bundle.h"
27 #include "ui/gfx/color_palette.h" 28 #include "ui/gfx/color_palette.h"
28 #include "ui/gfx/image/image.h" 29 #include "ui/gfx/image/image.h"
29 #include "ui/gfx/paint_vector_icon.h" 30 #include "ui/gfx/paint_vector_icon.h"
30 #include "ui/views/controls/button/toggle_button.h" 31 #include "ui/views/controls/button/toggle_button.h"
31 #include "ui/views/controls/image_view.h" 32 #include "ui/views/controls/image_view.h"
32 #include "ui/views/controls/label.h" 33 #include "ui/views/controls/label.h"
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 const int kDisabledPanelLabelBaselineY = 20; 110 const int kDisabledPanelLabelBaselineY = 20;
110 111
111 } // namespace 112 } // namespace
112 113
113 class BluetoothDefaultView : public TrayItemMore { 114 class BluetoothDefaultView : public TrayItemMore {
114 public: 115 public:
115 explicit BluetoothDefaultView(SystemTrayItem* owner) : TrayItemMore(owner) {} 116 explicit BluetoothDefaultView(SystemTrayItem* owner) : TrayItemMore(owner) {}
116 ~BluetoothDefaultView() override {} 117 ~BluetoothDefaultView() override {}
117 118
118 void Update() { 119 void Update() {
119 SystemTrayDelegate* delegate = WmShell::Get()->system_tray_delegate(); 120 TrayBluetoothHelper* helper = Shell::Get()->tray_bluetooth_helper();
120 const bool enabled = delegate->GetBluetoothEnabled(); 121 if (helper->GetBluetoothAvailable()) {
121 if (delegate->GetBluetoothAvailable()) {
122 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); 122 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
123 const base::string16 label = rb.GetLocalizedString( 123 const base::string16 label =
124 enabled ? IDS_ASH_STATUS_TRAY_BLUETOOTH_ENABLED 124 rb.GetLocalizedString(helper->GetBluetoothEnabled()
125 : IDS_ASH_STATUS_TRAY_BLUETOOTH_DISABLED); 125 ? IDS_ASH_STATUS_TRAY_BLUETOOTH_ENABLED
126 : IDS_ASH_STATUS_TRAY_BLUETOOTH_DISABLED);
126 SetLabel(label); 127 SetLabel(label);
127 SetAccessibleName(label); 128 SetAccessibleName(label);
128 SetVisible(true); 129 SetVisible(true);
129 } else { 130 } else {
130 SetVisible(false); 131 SetVisible(false);
131 } 132 }
132 UpdateStyle(); 133 UpdateStyle();
133 } 134 }
134 135
135 protected: 136 protected:
136 // TrayItemMore: 137 // TrayItemMore:
137 std::unique_ptr<TrayPopupItemStyle> HandleCreateStyle() const override { 138 std::unique_ptr<TrayPopupItemStyle> HandleCreateStyle() const override {
138 SystemTrayDelegate* delegate = WmShell::Get()->system_tray_delegate(); 139 TrayBluetoothHelper* helper = Shell::Get()->tray_bluetooth_helper();
139 std::unique_ptr<TrayPopupItemStyle> style = 140 std::unique_ptr<TrayPopupItemStyle> style =
140 TrayItemMore::HandleCreateStyle(); 141 TrayItemMore::HandleCreateStyle();
141 style->set_color_style( 142 style->set_color_style(
142 delegate->GetBluetoothEnabled() 143 helper->GetBluetoothEnabled()
143 ? TrayPopupItemStyle::ColorStyle::ACTIVE 144 ? TrayPopupItemStyle::ColorStyle::ACTIVE
144 : delegate->GetBluetoothAvailable() 145 : helper->GetBluetoothAvailable()
145 ? TrayPopupItemStyle::ColorStyle::INACTIVE 146 ? TrayPopupItemStyle::ColorStyle::INACTIVE
146 : TrayPopupItemStyle::ColorStyle::DISABLED); 147 : TrayPopupItemStyle::ColorStyle::DISABLED);
147 148
148 return style; 149 return style;
149 } 150 }
150 151
151 void UpdateStyle() override { 152 void UpdateStyle() override {
152 TrayItemMore::UpdateStyle(); 153 TrayItemMore::UpdateStyle();
153 std::unique_ptr<TrayPopupItemStyle> style = CreateStyle(); 154 std::unique_ptr<TrayPopupItemStyle> style = CreateStyle();
154 SetImage(gfx::CreateVectorIcon(GetCurrentIcon(), style->GetIconColor())); 155 SetImage(gfx::CreateVectorIcon(GetCurrentIcon(), style->GetIconColor()));
155 } 156 }
156 157
157 private: 158 private:
158 const gfx::VectorIcon& GetCurrentIcon() { 159 const gfx::VectorIcon& GetCurrentIcon() {
159 SystemTrayDelegate* delegate = WmShell::Get()->system_tray_delegate(); 160 TrayBluetoothHelper* helper = Shell::Get()->tray_bluetooth_helper();
160 if (!delegate->GetBluetoothEnabled()) 161 if (!helper->GetBluetoothEnabled())
161 return kSystemMenuBluetoothDisabledIcon; 162 return kSystemMenuBluetoothDisabledIcon;
162 163
163 bool has_connected_device = false; 164 bool has_connected_device = false;
164 BluetoothDeviceList list; 165 BluetoothDeviceList list;
165 delegate->GetAvailableBluetoothDevices(&list); 166 helper->GetAvailableBluetoothDevices(&list);
166 for (size_t i = 0; i < list.size(); ++i) { 167 for (size_t i = 0; i < list.size(); ++i) {
167 if (list[i].connected) { 168 if (list[i].connected) {
168 has_connected_device = true; 169 has_connected_device = true;
169 break; 170 break;
170 } 171 }
171 } 172 }
172 return has_connected_device ? kSystemMenuBluetoothConnectedIcon 173 return has_connected_device ? kSystemMenuBluetoothConnectedIcon
173 : kSystemMenuBluetoothIcon; 174 : kSystemMenuBluetoothIcon;
174 } 175 }
175 176
(...skipping 26 matching lines...) Expand all
202 Layout(); 203 Layout();
203 } 204 }
204 205
205 private: 206 private:
206 void CreateItems() { 207 void CreateItems() {
207 CreateScrollableList(); 208 CreateScrollableList();
208 CreateTitleRow(IDS_ASH_STATUS_TRAY_BLUETOOTH); 209 CreateTitleRow(IDS_ASH_STATUS_TRAY_BLUETOOTH);
209 } 210 }
210 211
211 void BluetoothStartDiscovering() { 212 void BluetoothStartDiscovering() {
212 SystemTrayDelegate* delegate = WmShell::Get()->system_tray_delegate(); 213 TrayBluetoothHelper* helper = Shell::Get()->tray_bluetooth_helper();
213 if (delegate->GetBluetoothDiscovering()) { 214 if (helper->HasBluetoothDiscoverySession()) {
msw 2017/03/21 01:54:43 Did you figure out if there's a meaningful differe
James Cook 2017/03/21 04:43:01 This isn't a behavior change. TrayBluetoothHelper:
214 ShowLoadingIndicator(); 215 ShowLoadingIndicator();
215 return; 216 return;
216 } 217 }
217 HideLoadingIndicator(); 218 HideLoadingIndicator();
218 if (delegate->GetBluetoothEnabled()) 219 if (helper->GetBluetoothEnabled())
219 delegate->BluetoothStartDiscovering(); 220 helper->StartBluetoothDiscovering();
220 } 221 }
221 222
222 void BluetoothStopDiscovering() { 223 void BluetoothStopDiscovering() {
223 SystemTrayDelegate* delegate = WmShell::Get()->system_tray_delegate(); 224 TrayBluetoothHelper* helper = Shell::Get()->tray_bluetooth_helper();
224 if (delegate && delegate->GetBluetoothDiscovering()) { 225 if (helper && helper->HasBluetoothDiscoverySession()) {
msw 2017/03/21 01:54:43 nit: maybe the null check isn't needed anymore? (n
James Cook 2017/03/21 04:43:01 I think this avoids a shutdown crash if the system
225 delegate->BluetoothStopDiscovering(); 226 helper->StopBluetoothDiscovering();
226 HideLoadingIndicator(); 227 HideLoadingIndicator();
227 } 228 }
228 } 229 }
229 230
230 void UpdateBluetoothDeviceList() { 231 void UpdateBluetoothDeviceList() {
231 std::set<std::string> new_connecting_devices; 232 std::set<std::string> new_connecting_devices;
232 std::set<std::string> new_connected_devices; 233 std::set<std::string> new_connected_devices;
233 std::set<std::string> new_paired_not_connected_devices; 234 std::set<std::string> new_paired_not_connected_devices;
234 std::set<std::string> new_discovered_not_paired_devices; 235 std::set<std::string> new_discovered_not_paired_devices;
235 236
236 BluetoothDeviceList list; 237 BluetoothDeviceList list;
237 WmShell::Get()->system_tray_delegate()->GetAvailableBluetoothDevices(&list); 238 Shell::Get()->tray_bluetooth_helper()->GetAvailableBluetoothDevices(&list);
238 for (size_t i = 0; i < list.size(); ++i) { 239 for (size_t i = 0; i < list.size(); ++i) {
239 if (list[i].connecting) { 240 if (list[i].connecting) {
240 new_connecting_devices.insert(list[i].address); 241 new_connecting_devices.insert(list[i].address);
241 UpdateBluetoothDeviceListHelper(&connecting_devices_, list[i]); 242 UpdateBluetoothDeviceListHelper(&connecting_devices_, list[i]);
242 } else if (list[i].connected && list[i].paired) { 243 } else if (list[i].connected && list[i].paired) {
243 new_connected_devices.insert(list[i].address); 244 new_connected_devices.insert(list[i].address);
244 UpdateBluetoothDeviceListHelper(&connected_devices_, list[i]); 245 UpdateBluetoothDeviceListHelper(&connected_devices_, list[i]);
245 } else if (list[i].paired) { 246 } else if (list[i].paired) {
246 new_paired_not_connected_devices.insert(list[i].address); 247 new_paired_not_connected_devices.insert(list[i].address);
247 UpdateBluetoothDeviceListHelper(&paired_not_connected_devices_, 248 UpdateBluetoothDeviceListHelper(&paired_not_connected_devices_,
248 list[i]); 249 list[i]);
249 } else { 250 } else {
250 new_discovered_not_paired_devices.insert(list[i].address); 251 new_discovered_not_paired_devices.insert(list[i].address);
251 UpdateBluetoothDeviceListHelper(&discovered_not_paired_devices_, 252 UpdateBluetoothDeviceListHelper(&discovered_not_paired_devices_,
252 list[i]); 253 list[i]);
253 } 254 }
254 } 255 }
255 RemoveObsoleteBluetoothDevicesFromList(&connecting_devices_, 256 RemoveObsoleteBluetoothDevicesFromList(&connecting_devices_,
256 new_connecting_devices); 257 new_connecting_devices);
257 RemoveObsoleteBluetoothDevicesFromList(&connected_devices_, 258 RemoveObsoleteBluetoothDevicesFromList(&connected_devices_,
258 new_connected_devices); 259 new_connected_devices);
259 RemoveObsoleteBluetoothDevicesFromList(&paired_not_connected_devices_, 260 RemoveObsoleteBluetoothDevicesFromList(&paired_not_connected_devices_,
260 new_paired_not_connected_devices); 261 new_paired_not_connected_devices);
261 RemoveObsoleteBluetoothDevicesFromList(&discovered_not_paired_devices_, 262 RemoveObsoleteBluetoothDevicesFromList(&discovered_not_paired_devices_,
262 new_discovered_not_paired_devices); 263 new_discovered_not_paired_devices);
263 } 264 }
264 265
265 void UpdateHeaderEntry() { 266 void UpdateHeaderEntry() {
266 bool is_bluetooth_enabled = 267 const bool is_bluetooth_enabled =
267 WmShell::Get()->system_tray_delegate()->GetBluetoothEnabled(); 268 Shell::Get()->tray_bluetooth_helper()->GetBluetoothEnabled();
268 if (toggle_) 269 if (toggle_)
269 toggle_->SetIsOn(is_bluetooth_enabled, true); 270 toggle_->SetIsOn(is_bluetooth_enabled, true);
270 } 271 }
271 272
272 void UpdateDeviceScrollList() { 273 void UpdateDeviceScrollList() {
273 std::string focused_device_address = GetFocusedDeviceAddress(); 274 std::string focused_device_address = GetFocusedDeviceAddress();
274 275
275 device_map_.clear(); 276 device_map_.clear();
276 scroll_content()->RemoveAllChildViews(true); 277 scroll_content()->RemoveAllChildViews(true);
277 278
278 SystemTrayDelegate* delegate = WmShell::Get()->system_tray_delegate(); 279 TrayBluetoothHelper* helper = Shell::Get()->tray_bluetooth_helper();
279 bool bluetooth_enabled = delegate->GetBluetoothEnabled(); 280 const bool bluetooth_enabled = helper->GetBluetoothEnabled();
280 bool bluetooth_available = delegate->GetBluetoothAvailable(); 281 const bool bluetooth_available = helper->GetBluetoothAvailable();
281 282
282 // If Bluetooth is disabled, show a panel which only indicates that it is 283 // If Bluetooth is disabled, show a panel which only indicates that it is
283 // disabled, instead of the scroller with Bluetooth devices. 284 // disabled, instead of the scroller with Bluetooth devices.
284 if (bluetooth_enabled) { 285 if (bluetooth_enabled) {
285 HideDisabledPanel(); 286 HideDisabledPanel();
286 } else { 287 } else {
287 ShowDisabledPanel(); 288 ShowDisabledPanel();
288 return; 289 return;
289 } 290 }
290 291
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
429 gfx::ImageSkia icon_image = CreateVectorIcon( 430 gfx::ImageSkia icon_image = CreateVectorIcon(
430 GetBluetoothDeviceIcon(device_type, false), style.GetIconColor()); 431 GetBluetoothDeviceIcon(device_type, false), style.GetIconColor());
431 SetupConnectingItem(container, display_name, icon_image); 432 SetupConnectingItem(container, display_name, icon_image);
432 scroll_content()->SizeToPreferredSize(); 433 scroll_content()->SizeToPreferredSize();
433 scroller()->Layout(); 434 scroller()->Layout();
434 } 435 }
435 } 436 }
436 437
437 // TrayDetailsView: 438 // TrayDetailsView:
438 void HandleViewClicked(views::View* view) override { 439 void HandleViewClicked(views::View* view) override {
439 SystemTrayDelegate* delegate = WmShell::Get()->system_tray_delegate(); 440 TrayBluetoothHelper* helper = Shell::Get()->tray_bluetooth_helper();
440 if (!delegate->GetBluetoothEnabled()) 441 if (!helper->GetBluetoothEnabled())
441 return; 442 return;
442 443
443 std::map<views::View*, std::string>::iterator find; 444 std::map<views::View*, std::string>::iterator find;
444 find = device_map_.find(view); 445 find = device_map_.find(view);
445 if (find == device_map_.end()) 446 if (find == device_map_.end())
446 return; 447 return;
447 448
448 const std::string device_id = find->second; 449 const std::string device_id = find->second;
449 if (FoundDevice(device_id, connecting_devices_, nullptr, nullptr)) 450 if (FoundDevice(device_id, connecting_devices_, nullptr, nullptr))
450 return; 451 return;
451 452
452 UpdateClickedDevice(device_id, view); 453 UpdateClickedDevice(device_id, view);
453 delegate->ConnectToBluetoothDevice(device_id); 454 helper->ConnectToBluetoothDevice(device_id);
454 } 455 }
455 456
456 void HandleButtonPressed(views::Button* sender, 457 void HandleButtonPressed(views::Button* sender,
457 const ui::Event& event) override { 458 const ui::Event& event) override {
458 if (sender == toggle_) { 459 if (sender == toggle_) {
459 SystemTrayDelegate* delegate = WmShell::Get()->system_tray_delegate(); 460 TrayBluetoothHelper* helper = Shell::Get()->tray_bluetooth_helper();
460 WmShell::Get()->RecordUserMetricsAction( 461 WmShell::Get()->RecordUserMetricsAction(
461 delegate->GetBluetoothEnabled() ? UMA_STATUS_AREA_BLUETOOTH_DISABLED 462 helper->GetBluetoothEnabled() ? UMA_STATUS_AREA_BLUETOOTH_DISABLED
462 : UMA_STATUS_AREA_BLUETOOTH_ENABLED); 463 : UMA_STATUS_AREA_BLUETOOTH_ENABLED);
463 delegate->ToggleBluetooth(); 464 helper->ToggleBluetoothEnabled();
464 } else if (sender == settings_) { 465 } else if (sender == settings_) {
465 ShowSettings(); 466 ShowSettings();
466 } else { 467 } else {
467 NOTREACHED(); 468 NOTREACHED();
468 } 469 }
469 } 470 }
470 471
471 void CreateExtraTitleRowButtons() override { 472 void CreateExtraTitleRowButtons() override {
472 if (login_ == LoginStatus::LOCKED) 473 if (login_ == LoginStatus::LOCKED)
473 return; 474 return;
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
610 611
611 views::View* TrayBluetooth::CreateDefaultView(LoginStatus status) { 612 views::View* TrayBluetooth::CreateDefaultView(LoginStatus status) {
612 CHECK(default_ == NULL); 613 CHECK(default_ == NULL);
613 default_ = new tray::BluetoothDefaultView(this); 614 default_ = new tray::BluetoothDefaultView(this);
614 default_->SetEnabled(status != LoginStatus::LOCKED); 615 default_->SetEnabled(status != LoginStatus::LOCKED);
615 default_->Update(); 616 default_->Update();
616 return default_; 617 return default_;
617 } 618 }
618 619
619 views::View* TrayBluetooth::CreateDetailedView(LoginStatus status) { 620 views::View* TrayBluetooth::CreateDetailedView(LoginStatus status) {
620 if (!WmShell::Get()->system_tray_delegate()->GetBluetoothAvailable()) 621 if (!Shell::Get()->tray_bluetooth_helper()->GetBluetoothAvailable())
621 return NULL; 622 return NULL;
622 WmShell::Get()->RecordUserMetricsAction( 623 WmShell::Get()->RecordUserMetricsAction(
623 UMA_STATUS_AREA_DETAILED_BLUETOOTH_VIEW); 624 UMA_STATUS_AREA_DETAILED_BLUETOOTH_VIEW);
624 CHECK(detailed_ == NULL); 625 CHECK(detailed_ == NULL);
625 detailed_ = new tray::BluetoothDetailedView(this, status); 626 detailed_ = new tray::BluetoothDetailedView(this, status);
626 detailed_->Update(); 627 detailed_->Update();
627 return detailed_; 628 return detailed_;
628 } 629 }
629 630
630 void TrayBluetooth::DestroyTrayView() {} 631 void TrayBluetooth::DestroyTrayView() {}
(...skipping 15 matching lines...) Expand all
646 detailed_->Update(); 647 detailed_->Update();
647 } 648 }
648 649
649 void TrayBluetooth::OnBluetoothDiscoveringChanged() { 650 void TrayBluetooth::OnBluetoothDiscoveringChanged() {
650 if (!detailed_) 651 if (!detailed_)
651 return; 652 return;
652 detailed_->Update(); 653 detailed_->Update();
653 } 654 }
654 655
655 } // namespace ash 656 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698