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

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

Issue 2761993002: cros: Eliminate bluetooth methods from SystemTrayDelegate (Closed)
Patch Set: review comments 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
« no previous file with comments | « no previous file | ash/common/system/chromeos/bluetooth/tray_bluetooth_helper.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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"
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 const int kDisabledPanelLabelBaselineY = 20; 110 const int kDisabledPanelLabelBaselineY = 20;
111 111
112 } // namespace 112 } // namespace
113 113
114 class BluetoothDefaultView : public TrayItemMore { 114 class BluetoothDefaultView : public TrayItemMore {
115 public: 115 public:
116 explicit BluetoothDefaultView(SystemTrayItem* owner) : TrayItemMore(owner) {} 116 explicit BluetoothDefaultView(SystemTrayItem* owner) : TrayItemMore(owner) {}
117 ~BluetoothDefaultView() override {} 117 ~BluetoothDefaultView() override {}
118 118
119 void Update() { 119 void Update() {
120 SystemTrayDelegate* delegate = Shell::Get()->system_tray_delegate(); 120 TrayBluetoothHelper* helper = Shell::Get()->tray_bluetooth_helper();
121 const bool enabled = delegate->GetBluetoothEnabled(); 121 if (helper->GetBluetoothAvailable()) {
122 if (delegate->GetBluetoothAvailable()) {
123 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); 122 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
124 const base::string16 label = rb.GetLocalizedString( 123 const base::string16 label =
125 enabled ? IDS_ASH_STATUS_TRAY_BLUETOOTH_ENABLED 124 rb.GetLocalizedString(helper->GetBluetoothEnabled()
126 : IDS_ASH_STATUS_TRAY_BLUETOOTH_DISABLED); 125 ? IDS_ASH_STATUS_TRAY_BLUETOOTH_ENABLED
126 : IDS_ASH_STATUS_TRAY_BLUETOOTH_DISABLED);
127 SetLabel(label); 127 SetLabel(label);
128 SetAccessibleName(label); 128 SetAccessibleName(label);
129 SetVisible(true); 129 SetVisible(true);
130 } else { 130 } else {
131 SetVisible(false); 131 SetVisible(false);
132 } 132 }
133 UpdateStyle(); 133 UpdateStyle();
134 } 134 }
135 135
136 protected: 136 protected:
137 // TrayItemMore: 137 // TrayItemMore:
138 std::unique_ptr<TrayPopupItemStyle> HandleCreateStyle() const override { 138 std::unique_ptr<TrayPopupItemStyle> HandleCreateStyle() const override {
139 SystemTrayDelegate* delegate = Shell::Get()->system_tray_delegate(); 139 TrayBluetoothHelper* helper = Shell::Get()->tray_bluetooth_helper();
140 std::unique_ptr<TrayPopupItemStyle> style = 140 std::unique_ptr<TrayPopupItemStyle> style =
141 TrayItemMore::HandleCreateStyle(); 141 TrayItemMore::HandleCreateStyle();
142 style->set_color_style( 142 style->set_color_style(
143 delegate->GetBluetoothEnabled() 143 helper->GetBluetoothEnabled()
144 ? TrayPopupItemStyle::ColorStyle::ACTIVE 144 ? TrayPopupItemStyle::ColorStyle::ACTIVE
145 : delegate->GetBluetoothAvailable() 145 : helper->GetBluetoothAvailable()
146 ? TrayPopupItemStyle::ColorStyle::INACTIVE 146 ? TrayPopupItemStyle::ColorStyle::INACTIVE
147 : TrayPopupItemStyle::ColorStyle::DISABLED); 147 : TrayPopupItemStyle::ColorStyle::DISABLED);
148 148
149 return style; 149 return style;
150 } 150 }
151 151
152 void UpdateStyle() override { 152 void UpdateStyle() override {
153 TrayItemMore::UpdateStyle(); 153 TrayItemMore::UpdateStyle();
154 std::unique_ptr<TrayPopupItemStyle> style = CreateStyle(); 154 std::unique_ptr<TrayPopupItemStyle> style = CreateStyle();
155 SetImage(gfx::CreateVectorIcon(GetCurrentIcon(), style->GetIconColor())); 155 SetImage(gfx::CreateVectorIcon(GetCurrentIcon(), style->GetIconColor()));
156 } 156 }
157 157
158 private: 158 private:
159 const gfx::VectorIcon& GetCurrentIcon() { 159 const gfx::VectorIcon& GetCurrentIcon() {
160 SystemTrayDelegate* delegate = Shell::Get()->system_tray_delegate(); 160 TrayBluetoothHelper* helper = Shell::Get()->tray_bluetooth_helper();
161 if (!delegate->GetBluetoothEnabled()) 161 if (!helper->GetBluetoothEnabled())
162 return kSystemMenuBluetoothDisabledIcon; 162 return kSystemMenuBluetoothDisabledIcon;
163 163
164 bool has_connected_device = false; 164 bool has_connected_device = false;
165 BluetoothDeviceList list; 165 BluetoothDeviceList list;
166 delegate->GetAvailableBluetoothDevices(&list); 166 helper->GetAvailableBluetoothDevices(&list);
167 for (size_t i = 0; i < list.size(); ++i) { 167 for (size_t i = 0; i < list.size(); ++i) {
168 if (list[i].connected) { 168 if (list[i].connected) {
169 has_connected_device = true; 169 has_connected_device = true;
170 break; 170 break;
171 } 171 }
172 } 172 }
173 return has_connected_device ? kSystemMenuBluetoothConnectedIcon 173 return has_connected_device ? kSystemMenuBluetoothConnectedIcon
174 : kSystemMenuBluetoothIcon; 174 : kSystemMenuBluetoothIcon;
175 } 175 }
176 176
(...skipping 26 matching lines...) Expand all
203 Layout(); 203 Layout();
204 } 204 }
205 205
206 private: 206 private:
207 void CreateItems() { 207 void CreateItems() {
208 CreateScrollableList(); 208 CreateScrollableList();
209 CreateTitleRow(IDS_ASH_STATUS_TRAY_BLUETOOTH); 209 CreateTitleRow(IDS_ASH_STATUS_TRAY_BLUETOOTH);
210 } 210 }
211 211
212 void BluetoothStartDiscovering() { 212 void BluetoothStartDiscovering() {
213 SystemTrayDelegate* delegate = Shell::Get()->system_tray_delegate(); 213 TrayBluetoothHelper* helper = Shell::Get()->tray_bluetooth_helper();
214 if (delegate->GetBluetoothDiscovering()) { 214 if (helper->HasBluetoothDiscoverySession()) {
215 ShowLoadingIndicator(); 215 ShowLoadingIndicator();
216 return; 216 return;
217 } 217 }
218 HideLoadingIndicator(); 218 HideLoadingIndicator();
219 if (delegate->GetBluetoothEnabled()) 219 if (helper->GetBluetoothEnabled())
220 delegate->BluetoothStartDiscovering(); 220 helper->StartBluetoothDiscovering();
221 } 221 }
222 222
223 void BluetoothStopDiscovering() { 223 void BluetoothStopDiscovering() {
224 SystemTrayDelegate* delegate = Shell::Get()->system_tray_delegate(); 224 TrayBluetoothHelper* helper = Shell::Get()->tray_bluetooth_helper();
225 if (delegate && delegate->GetBluetoothDiscovering()) { 225 if (helper && helper->HasBluetoothDiscoverySession()) {
226 delegate->BluetoothStopDiscovering(); 226 helper->StopBluetoothDiscovering();
227 HideLoadingIndicator(); 227 HideLoadingIndicator();
228 } 228 }
229 } 229 }
230 230
231 void UpdateBluetoothDeviceList() { 231 void UpdateBluetoothDeviceList() {
232 std::set<std::string> new_connecting_devices; 232 std::set<std::string> new_connecting_devices;
233 std::set<std::string> new_connected_devices; 233 std::set<std::string> new_connected_devices;
234 std::set<std::string> new_paired_not_connected_devices; 234 std::set<std::string> new_paired_not_connected_devices;
235 std::set<std::string> new_discovered_not_paired_devices; 235 std::set<std::string> new_discovered_not_paired_devices;
236 236
237 BluetoothDeviceList list; 237 BluetoothDeviceList list;
238 Shell::Get()->system_tray_delegate()->GetAvailableBluetoothDevices(&list); 238 Shell::Get()->tray_bluetooth_helper()->GetAvailableBluetoothDevices(&list);
239 for (size_t i = 0; i < list.size(); ++i) { 239 for (size_t i = 0; i < list.size(); ++i) {
240 if (list[i].connecting) { 240 if (list[i].connecting) {
241 new_connecting_devices.insert(list[i].address); 241 new_connecting_devices.insert(list[i].address);
242 UpdateBluetoothDeviceListHelper(&connecting_devices_, list[i]); 242 UpdateBluetoothDeviceListHelper(&connecting_devices_, list[i]);
243 } else if (list[i].connected && list[i].paired) { 243 } else if (list[i].connected && list[i].paired) {
244 new_connected_devices.insert(list[i].address); 244 new_connected_devices.insert(list[i].address);
245 UpdateBluetoothDeviceListHelper(&connected_devices_, list[i]); 245 UpdateBluetoothDeviceListHelper(&connected_devices_, list[i]);
246 } else if (list[i].paired) { 246 } else if (list[i].paired) {
247 new_paired_not_connected_devices.insert(list[i].address); 247 new_paired_not_connected_devices.insert(list[i].address);
248 UpdateBluetoothDeviceListHelper(&paired_not_connected_devices_, 248 UpdateBluetoothDeviceListHelper(&paired_not_connected_devices_,
249 list[i]); 249 list[i]);
250 } else { 250 } else {
251 new_discovered_not_paired_devices.insert(list[i].address); 251 new_discovered_not_paired_devices.insert(list[i].address);
252 UpdateBluetoothDeviceListHelper(&discovered_not_paired_devices_, 252 UpdateBluetoothDeviceListHelper(&discovered_not_paired_devices_,
253 list[i]); 253 list[i]);
254 } 254 }
255 } 255 }
256 RemoveObsoleteBluetoothDevicesFromList(&connecting_devices_, 256 RemoveObsoleteBluetoothDevicesFromList(&connecting_devices_,
257 new_connecting_devices); 257 new_connecting_devices);
258 RemoveObsoleteBluetoothDevicesFromList(&connected_devices_, 258 RemoveObsoleteBluetoothDevicesFromList(&connected_devices_,
259 new_connected_devices); 259 new_connected_devices);
260 RemoveObsoleteBluetoothDevicesFromList(&paired_not_connected_devices_, 260 RemoveObsoleteBluetoothDevicesFromList(&paired_not_connected_devices_,
261 new_paired_not_connected_devices); 261 new_paired_not_connected_devices);
262 RemoveObsoleteBluetoothDevicesFromList(&discovered_not_paired_devices_, 262 RemoveObsoleteBluetoothDevicesFromList(&discovered_not_paired_devices_,
263 new_discovered_not_paired_devices); 263 new_discovered_not_paired_devices);
264 } 264 }
265 265
266 void UpdateHeaderEntry() { 266 void UpdateHeaderEntry() {
267 bool is_bluetooth_enabled = 267 const bool is_bluetooth_enabled =
268 Shell::Get()->system_tray_delegate()->GetBluetoothEnabled(); 268 Shell::Get()->tray_bluetooth_helper()->GetBluetoothEnabled();
269 if (toggle_) 269 if (toggle_)
270 toggle_->SetIsOn(is_bluetooth_enabled, true); 270 toggle_->SetIsOn(is_bluetooth_enabled, true);
271 } 271 }
272 272
273 void UpdateDeviceScrollList() { 273 void UpdateDeviceScrollList() {
274 std::string focused_device_address = GetFocusedDeviceAddress(); 274 std::string focused_device_address = GetFocusedDeviceAddress();
275 275
276 device_map_.clear(); 276 device_map_.clear();
277 scroll_content()->RemoveAllChildViews(true); 277 scroll_content()->RemoveAllChildViews(true);
278 278
279 SystemTrayDelegate* delegate = Shell::Get()->system_tray_delegate(); 279 TrayBluetoothHelper* helper = Shell::Get()->tray_bluetooth_helper();
280 bool bluetooth_enabled = delegate->GetBluetoothEnabled(); 280 const bool bluetooth_enabled = helper->GetBluetoothEnabled();
281 bool bluetooth_available = delegate->GetBluetoothAvailable(); 281 const bool bluetooth_available = helper->GetBluetoothAvailable();
282 282
283 // 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
284 // disabled, instead of the scroller with Bluetooth devices. 284 // disabled, instead of the scroller with Bluetooth devices.
285 if (bluetooth_enabled) { 285 if (bluetooth_enabled) {
286 HideDisabledPanel(); 286 HideDisabledPanel();
287 } else { 287 } else {
288 ShowDisabledPanel(); 288 ShowDisabledPanel();
289 return; 289 return;
290 } 290 }
291 291
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
430 gfx::ImageSkia icon_image = CreateVectorIcon( 430 gfx::ImageSkia icon_image = CreateVectorIcon(
431 GetBluetoothDeviceIcon(device_type, false), style.GetIconColor()); 431 GetBluetoothDeviceIcon(device_type, false), style.GetIconColor());
432 SetupConnectingItem(container, display_name, icon_image); 432 SetupConnectingItem(container, display_name, icon_image);
433 scroll_content()->SizeToPreferredSize(); 433 scroll_content()->SizeToPreferredSize();
434 scroller()->Layout(); 434 scroller()->Layout();
435 } 435 }
436 } 436 }
437 437
438 // TrayDetailsView: 438 // TrayDetailsView:
439 void HandleViewClicked(views::View* view) override { 439 void HandleViewClicked(views::View* view) override {
440 SystemTrayDelegate* delegate = Shell::Get()->system_tray_delegate(); 440 TrayBluetoothHelper* helper = Shell::Get()->tray_bluetooth_helper();
441 if (!delegate->GetBluetoothEnabled()) 441 if (!helper->GetBluetoothEnabled())
442 return; 442 return;
443 443
444 std::map<views::View*, std::string>::iterator find; 444 std::map<views::View*, std::string>::iterator find;
445 find = device_map_.find(view); 445 find = device_map_.find(view);
446 if (find == device_map_.end()) 446 if (find == device_map_.end())
447 return; 447 return;
448 448
449 const std::string device_id = find->second; 449 const std::string device_id = find->second;
450 if (FoundDevice(device_id, connecting_devices_, nullptr, nullptr)) 450 if (FoundDevice(device_id, connecting_devices_, nullptr, nullptr))
451 return; 451 return;
452 452
453 UpdateClickedDevice(device_id, view); 453 UpdateClickedDevice(device_id, view);
454 delegate->ConnectToBluetoothDevice(device_id); 454 helper->ConnectToBluetoothDevice(device_id);
455 } 455 }
456 456
457 void HandleButtonPressed(views::Button* sender, 457 void HandleButtonPressed(views::Button* sender,
458 const ui::Event& event) override { 458 const ui::Event& event) override {
459 if (sender == toggle_) { 459 if (sender == toggle_) {
460 SystemTrayDelegate* delegate = Shell::Get()->system_tray_delegate(); 460 TrayBluetoothHelper* helper = Shell::Get()->tray_bluetooth_helper();
461 WmShell::Get()->RecordUserMetricsAction( 461 WmShell::Get()->RecordUserMetricsAction(
462 delegate->GetBluetoothEnabled() ? UMA_STATUS_AREA_BLUETOOTH_DISABLED 462 helper->GetBluetoothEnabled() ? UMA_STATUS_AREA_BLUETOOTH_DISABLED
463 : UMA_STATUS_AREA_BLUETOOTH_ENABLED); 463 : UMA_STATUS_AREA_BLUETOOTH_ENABLED);
464 delegate->ToggleBluetooth(); 464 helper->ToggleBluetoothEnabled();
465 } else if (sender == settings_) { 465 } else if (sender == settings_) {
466 ShowSettings(); 466 ShowSettings();
467 } else { 467 } else {
468 NOTREACHED(); 468 NOTREACHED();
469 } 469 }
470 } 470 }
471 471
472 void CreateExtraTitleRowButtons() override { 472 void CreateExtraTitleRowButtons() override {
473 if (login_ == LoginStatus::LOCKED) 473 if (login_ == LoginStatus::LOCKED)
474 return; 474 return;
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
611 611
612 views::View* TrayBluetooth::CreateDefaultView(LoginStatus status) { 612 views::View* TrayBluetooth::CreateDefaultView(LoginStatus status) {
613 CHECK(default_ == NULL); 613 CHECK(default_ == NULL);
614 default_ = new tray::BluetoothDefaultView(this); 614 default_ = new tray::BluetoothDefaultView(this);
615 default_->SetEnabled(status != LoginStatus::LOCKED); 615 default_->SetEnabled(status != LoginStatus::LOCKED);
616 default_->Update(); 616 default_->Update();
617 return default_; 617 return default_;
618 } 618 }
619 619
620 views::View* TrayBluetooth::CreateDetailedView(LoginStatus status) { 620 views::View* TrayBluetooth::CreateDetailedView(LoginStatus status) {
621 if (!Shell::Get()->system_tray_delegate()->GetBluetoothAvailable()) 621 if (!Shell::Get()->tray_bluetooth_helper()->GetBluetoothAvailable())
622 return NULL; 622 return NULL;
623 WmShell::Get()->RecordUserMetricsAction( 623 WmShell::Get()->RecordUserMetricsAction(
624 UMA_STATUS_AREA_DETAILED_BLUETOOTH_VIEW); 624 UMA_STATUS_AREA_DETAILED_BLUETOOTH_VIEW);
625 CHECK(detailed_ == NULL); 625 CHECK(detailed_ == NULL);
626 detailed_ = new tray::BluetoothDetailedView(this, status); 626 detailed_ = new tray::BluetoothDetailedView(this, status);
627 detailed_->Update(); 627 detailed_->Update();
628 return detailed_; 628 return detailed_;
629 } 629 }
630 630
631 void TrayBluetooth::DestroyTrayView() {} 631 void TrayBluetooth::DestroyTrayView() {}
(...skipping 15 matching lines...) Expand all
647 detailed_->Update(); 647 detailed_->Update();
648 } 648 }
649 649
650 void TrayBluetooth::OnBluetoothDiscoveringChanged() { 650 void TrayBluetooth::OnBluetoothDiscoveringChanged() {
651 if (!detailed_) 651 if (!detailed_)
652 return; 652 return;
653 detailed_->Update(); 653 detailed_->Update();
654 } 654 }
655 655
656 } // namespace ash 656 } // namespace ash
OLDNEW
« no previous file with comments | « no previous file | ash/common/system/chromeos/bluetooth/tray_bluetooth_helper.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698