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

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

Issue 2058173002: mash: Move SystemTrayDelegate ownership to WmShell (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 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/system/chromeos/bluetooth/tray_bluetooth.h" 5 #include "ash/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/tray/system_tray_delegate.h" 8 #include "ash/common/system/tray/system_tray_delegate.h"
9 #include "ash/common/system/tray/tray_constants.h" 9 #include "ash/common/system/tray/tray_constants.h"
10 #include "ash/common/wm_shell.h"
10 #include "ash/shell.h" 11 #include "ash/shell.h"
11 #include "ash/system/tray/fixed_sized_scroll_view.h" 12 #include "ash/system/tray/fixed_sized_scroll_view.h"
12 #include "ash/system/tray/hover_highlight_view.h" 13 #include "ash/system/tray/hover_highlight_view.h"
13 #include "ash/system/tray/system_tray.h" 14 #include "ash/system/tray/system_tray.h"
14 #include "ash/system/tray/system_tray_notifier.h" 15 #include "ash/system/tray/system_tray_notifier.h"
15 #include "ash/system/tray/throbber_view.h" 16 #include "ash/system/tray/throbber_view.h"
16 #include "ash/system/tray/tray_details_view.h" 17 #include "ash/system/tray/tray_details_view.h"
17 #include "ash/system/tray/tray_item_more.h" 18 #include "ash/system/tray/tray_item_more.h"
18 #include "ash/system/tray/tray_popup_header_button.h" 19 #include "ash/system/tray/tray_popup_header_button.h"
19 #include "grit/ash_resources.h" 20 #include "grit/ash_resources.h"
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 : TrayItemMore(owner, show_more) { 69 : TrayItemMore(owner, show_more) {
69 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); 70 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance();
70 SetImage(bundle.GetImageNamed(IDR_AURA_UBER_TRAY_BLUETOOTH).ToImageSkia()); 71 SetImage(bundle.GetImageNamed(IDR_AURA_UBER_TRAY_BLUETOOTH).ToImageSkia());
71 UpdateLabel(); 72 UpdateLabel();
72 } 73 }
73 74
74 ~BluetoothDefaultView() override {} 75 ~BluetoothDefaultView() override {}
75 76
76 void UpdateLabel() { 77 void UpdateLabel() {
77 ash::SystemTrayDelegate* delegate = 78 ash::SystemTrayDelegate* delegate =
78 ash::Shell::GetInstance()->system_tray_delegate(); 79 ash::WmShell::Get()->system_tray_delegate();
79 if (delegate->GetBluetoothAvailable()) { 80 if (delegate->GetBluetoothAvailable()) {
80 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); 81 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
81 const base::string16 label = 82 const base::string16 label =
82 rb.GetLocalizedString(delegate->GetBluetoothEnabled() 83 rb.GetLocalizedString(delegate->GetBluetoothEnabled()
83 ? IDS_ASH_STATUS_TRAY_BLUETOOTH_ENABLED 84 ? IDS_ASH_STATUS_TRAY_BLUETOOTH_ENABLED
84 : IDS_ASH_STATUS_TRAY_BLUETOOTH_DISABLED); 85 : IDS_ASH_STATUS_TRAY_BLUETOOTH_DISABLED);
85 SetLabel(label); 86 SetLabel(label);
86 SetAccessibleName(label); 87 SetAccessibleName(label);
87 SetVisible(true); 88 SetVisible(true);
88 } else { 89 } else {
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 125
125 private: 126 private:
126 void CreateItems() { 127 void CreateItems() {
127 CreateScrollableList(); 128 CreateScrollableList();
128 AppendSettingsEntries(); 129 AppendSettingsEntries();
129 AppendHeaderEntry(); 130 AppendHeaderEntry();
130 } 131 }
131 132
132 void BluetoothStartDiscovering() { 133 void BluetoothStartDiscovering() {
133 ash::SystemTrayDelegate* delegate = 134 ash::SystemTrayDelegate* delegate =
134 ash::Shell::GetInstance()->system_tray_delegate(); 135 ash::WmShell::Get()->system_tray_delegate();
135 bool bluetooth_enabled = delegate->GetBluetoothEnabled(); 136 bool bluetooth_enabled = delegate->GetBluetoothEnabled();
136 bool bluetooth_discovering = delegate->GetBluetoothDiscovering(); 137 bool bluetooth_discovering = delegate->GetBluetoothDiscovering();
137 if (bluetooth_discovering) { 138 if (bluetooth_discovering) {
138 throbber_->Start(); 139 throbber_->Start();
139 return; 140 return;
140 } 141 }
141 throbber_->Stop(); 142 throbber_->Stop();
142 if (bluetooth_enabled) { 143 if (bluetooth_enabled) {
143 delegate->BluetoothStartDiscovering(); 144 delegate->BluetoothStartDiscovering();
144 } 145 }
145 } 146 }
146 147
147 void BluetoothStopDiscovering() { 148 void BluetoothStopDiscovering() {
148 ash::SystemTrayDelegate* delegate = 149 ash::SystemTrayDelegate* delegate =
149 ash::Shell::GetInstance()->system_tray_delegate(); 150 ash::WmShell::Get()->system_tray_delegate();
150 if (delegate && delegate->GetBluetoothDiscovering()) { 151 if (delegate && delegate->GetBluetoothDiscovering()) {
151 delegate->BluetoothStopDiscovering(); 152 delegate->BluetoothStopDiscovering();
152 throbber_->Stop(); 153 throbber_->Stop();
153 } 154 }
154 } 155 }
155 156
156 void UpdateBluetoothDeviceList() { 157 void UpdateBluetoothDeviceList() {
157 std::set<std::string> new_connecting_devices; 158 std::set<std::string> new_connecting_devices;
158 std::set<std::string> new_connected_devices; 159 std::set<std::string> new_connected_devices;
159 std::set<std::string> new_paired_not_connected_devices; 160 std::set<std::string> new_paired_not_connected_devices;
160 std::set<std::string> new_discovered_not_paired_devices; 161 std::set<std::string> new_discovered_not_paired_devices;
161 162
162 BluetoothDeviceList list; 163 BluetoothDeviceList list;
163 Shell::GetInstance()->system_tray_delegate()->GetAvailableBluetoothDevices( 164 WmShell::Get()->system_tray_delegate()->GetAvailableBluetoothDevices(&list);
164 &list);
165 for (size_t i = 0; i < list.size(); ++i) { 165 for (size_t i = 0; i < list.size(); ++i) {
166 if (list[i].connecting) { 166 if (list[i].connecting) {
167 list[i].display_name = l10n_util::GetStringFUTF16( 167 list[i].display_name = l10n_util::GetStringFUTF16(
168 IDS_ASH_STATUS_TRAY_BLUETOOTH_CONNECTING, list[i].display_name); 168 IDS_ASH_STATUS_TRAY_BLUETOOTH_CONNECTING, list[i].display_name);
169 new_connecting_devices.insert(list[i].address); 169 new_connecting_devices.insert(list[i].address);
170 UpdateBluetoothDeviceListHelper(&connecting_devices_, list[i]); 170 UpdateBluetoothDeviceListHelper(&connecting_devices_, list[i]);
171 } else if (list[i].connected && list[i].paired) { 171 } else if (list[i].connected && list[i].paired) {
172 new_connected_devices.insert(list[i].address); 172 new_connected_devices.insert(list[i].address);
173 UpdateBluetoothDeviceListHelper(&connected_devices_, list[i]); 173 UpdateBluetoothDeviceListHelper(&connected_devices_, list[i]);
174 } else if (list[i].paired) { 174 } else if (list[i].paired) {
(...skipping 22 matching lines...) Expand all
197 if (login_ == LoginStatus::LOCKED) 197 if (login_ == LoginStatus::LOCKED)
198 return; 198 return;
199 199
200 throbber_ = new ThrobberView; 200 throbber_ = new ThrobberView;
201 throbber_->SetTooltipText( 201 throbber_->SetTooltipText(
202 l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_BLUETOOTH_DISCOVERING)); 202 l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_BLUETOOTH_DISCOVERING));
203 footer()->AddView(throbber_, false /* separator */); 203 footer()->AddView(throbber_, false /* separator */);
204 204
205 // Do not allow toggling bluetooth in the lock screen. 205 // Do not allow toggling bluetooth in the lock screen.
206 ash::SystemTrayDelegate* delegate = 206 ash::SystemTrayDelegate* delegate =
207 ash::Shell::GetInstance()->system_tray_delegate(); 207 ash::WmShell::Get()->system_tray_delegate();
208 toggle_bluetooth_ = 208 toggle_bluetooth_ =
209 new TrayPopupHeaderButton(this, IDR_AURA_UBER_TRAY_BLUETOOTH_ENABLED, 209 new TrayPopupHeaderButton(this, IDR_AURA_UBER_TRAY_BLUETOOTH_ENABLED,
210 IDR_AURA_UBER_TRAY_BLUETOOTH_DISABLED, 210 IDR_AURA_UBER_TRAY_BLUETOOTH_DISABLED,
211 IDR_AURA_UBER_TRAY_BLUETOOTH_ENABLED_HOVER, 211 IDR_AURA_UBER_TRAY_BLUETOOTH_ENABLED_HOVER,
212 IDR_AURA_UBER_TRAY_BLUETOOTH_DISABLED_HOVER, 212 IDR_AURA_UBER_TRAY_BLUETOOTH_DISABLED_HOVER,
213 IDS_ASH_STATUS_TRAY_BLUETOOTH); 213 IDS_ASH_STATUS_TRAY_BLUETOOTH);
214 toggle_bluetooth_->SetToggled(!delegate->GetBluetoothEnabled()); 214 toggle_bluetooth_->SetToggled(!delegate->GetBluetoothEnabled());
215 toggle_bluetooth_->SetTooltipText( 215 toggle_bluetooth_->SetTooltipText(
216 l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_DISABLE_BLUETOOTH)); 216 l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_DISABLE_BLUETOOTH));
217 toggle_bluetooth_->SetToggledTooltipText( 217 toggle_bluetooth_->SetToggledTooltipText(
218 l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_ENABLE_BLUETOOTH)); 218 l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_ENABLE_BLUETOOTH));
219 toggle_bluetooth_->EnableCanvasFlippingForRTLUI(false); 219 toggle_bluetooth_->EnableCanvasFlippingForRTLUI(false);
220 footer()->AddButton(toggle_bluetooth_); 220 footer()->AddButton(toggle_bluetooth_);
221 } 221 }
222 222
223 void UpdateHeaderEntry() { 223 void UpdateHeaderEntry() {
224 if (toggle_bluetooth_) { 224 if (toggle_bluetooth_) {
225 toggle_bluetooth_->SetToggled(!ash::Shell::GetInstance() 225 toggle_bluetooth_->SetToggled(
226 ->system_tray_delegate() 226 !ash::WmShell::Get()->system_tray_delegate()->GetBluetoothEnabled());
227 ->GetBluetoothEnabled());
228 } 227 }
229 } 228 }
230 229
231 void UpdateDeviceScrollList() { 230 void UpdateDeviceScrollList() {
232 device_map_.clear(); 231 device_map_.clear();
233 scroll_content()->RemoveAllChildViews(true); 232 scroll_content()->RemoveAllChildViews(true);
234 enable_bluetooth_ = NULL; 233 enable_bluetooth_ = NULL;
235 234
236 ash::SystemTrayDelegate* delegate = 235 ash::SystemTrayDelegate* delegate =
237 ash::Shell::GetInstance()->system_tray_delegate(); 236 ash::WmShell::Get()->system_tray_delegate();
238 bool bluetooth_enabled = delegate->GetBluetoothEnabled(); 237 bool bluetooth_enabled = delegate->GetBluetoothEnabled();
239 bool blueooth_available = delegate->GetBluetoothAvailable(); 238 bool blueooth_available = delegate->GetBluetoothAvailable();
240 if (blueooth_available && !bluetooth_enabled && toggle_bluetooth_) { 239 if (blueooth_available && !bluetooth_enabled && toggle_bluetooth_) {
241 enable_bluetooth_ = AddScrollListItem( 240 enable_bluetooth_ = AddScrollListItem(
242 l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_ENABLE_BLUETOOTH), 241 l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_ENABLE_BLUETOOTH),
243 false /* highlight */, false /* checked */, true /* enabled */); 242 false /* highlight */, false /* checked */, true /* enabled */);
244 } 243 }
245 244
246 AppendSameTypeDevicesToScrollList(connected_devices_, true, true, 245 AppendSameTypeDevicesToScrollList(connected_devices_, true, true,
247 bluetooth_enabled); 246 bluetooth_enabled);
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
285 HoverHighlightView* container = new HoverHighlightView(this); 284 HoverHighlightView* container = new HoverHighlightView(this);
286 views::Label* label = 285 views::Label* label =
287 container->AddCheckableLabel(text, highlight, checked); 286 container->AddCheckableLabel(text, highlight, checked);
288 label->SetEnabled(enabled); 287 label->SetEnabled(enabled);
289 scroll_content()->AddChildView(container); 288 scroll_content()->AddChildView(container);
290 return container; 289 return container;
291 } 290 }
292 291
293 // Add settings entries. 292 // Add settings entries.
294 void AppendSettingsEntries() { 293 void AppendSettingsEntries() {
295 if (!ash::Shell::GetInstance() 294 if (!ash::WmShell::Get()->system_tray_delegate()->ShouldShowSettings()) {
msw 2016/06/10 18:48:20 nit: remove curlies
James Cook 2016/06/10 20:20:30 Done.
296 ->system_tray_delegate()
297 ->ShouldShowSettings()) {
298 return; 295 return;
299 } 296 }
300 297
301 // Add bluetooth device requires a browser window, hide it for non logged in 298 // Add bluetooth device requires a browser window, hide it for non logged in
302 // user. 299 // user.
303 bool userAddingRunning = ash::Shell::GetInstance() 300 bool userAddingRunning = ash::Shell::GetInstance()
304 ->session_state_delegate() 301 ->session_state_delegate()
305 ->IsInSecondaryLoginScreen(); 302 ->IsInSecondaryLoginScreen();
306 303
307 if (login_ == LoginStatus::NOT_LOGGED_IN || login_ == LoginStatus::LOCKED || 304 if (login_ == LoginStatus::NOT_LOGGED_IN || login_ == LoginStatus::LOCKED ||
308 userAddingRunning) 305 userAddingRunning)
309 return; 306 return;
310 307
311 ash::SystemTrayDelegate* delegate = 308 ash::SystemTrayDelegate* delegate =
312 ash::Shell::GetInstance()->system_tray_delegate(); 309 ash::WmShell::Get()->system_tray_delegate();
313 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); 310 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
314 HoverHighlightView* container = new HoverHighlightView(this); 311 HoverHighlightView* container = new HoverHighlightView(this);
315 container->AddLabel( 312 container->AddLabel(
316 rb.GetLocalizedString(IDS_ASH_STATUS_TRAY_BLUETOOTH_MANAGE_DEVICES), 313 rb.GetLocalizedString(IDS_ASH_STATUS_TRAY_BLUETOOTH_MANAGE_DEVICES),
317 gfx::ALIGN_LEFT, false /* highlight */); 314 gfx::ALIGN_LEFT, false /* highlight */);
318 container->SetEnabled(delegate->GetBluetoothAvailable()); 315 container->SetEnabled(delegate->GetBluetoothAvailable());
319 AddChildView(container); 316 AddChildView(container);
320 manage_devices_ = container; 317 manage_devices_ = container;
321 } 318 }
322 319
(...skipping 26 matching lines...) Expand all
349 static_cast<HoverHighlightView*>(item_container) 346 static_cast<HoverHighlightView*>(item_container)
350 ->AddCheckableLabel(display_name, true /* highlight */, false); 347 ->AddCheckableLabel(display_name, true /* highlight */, false);
351 scroll_content()->SizeToPreferredSize(); 348 scroll_content()->SizeToPreferredSize();
352 static_cast<views::View*>(scroller())->Layout(); 349 static_cast<views::View*>(scroller())->Layout();
353 } 350 }
354 } 351 }
355 352
356 // Overridden from ViewClickListener. 353 // Overridden from ViewClickListener.
357 void OnViewClicked(views::View* sender) override { 354 void OnViewClicked(views::View* sender) override {
358 ash::SystemTrayDelegate* delegate = 355 ash::SystemTrayDelegate* delegate =
359 ash::Shell::GetInstance()->system_tray_delegate(); 356 ash::WmShell::Get()->system_tray_delegate();
360 if (sender == footer()->content()) { 357 if (sender == footer()->content()) {
361 TransitionToDefaultView(); 358 TransitionToDefaultView();
362 } else if (sender == manage_devices_) { 359 } else if (sender == manage_devices_) {
363 delegate->ManageBluetoothDevices(); 360 delegate->ManageBluetoothDevices();
364 } else if (sender == enable_bluetooth_) { 361 } else if (sender == enable_bluetooth_) {
365 Shell::GetInstance()->metrics()->RecordUserMetricsAction( 362 Shell::GetInstance()->metrics()->RecordUserMetricsAction(
366 delegate->GetBluetoothEnabled() 363 delegate->GetBluetoothEnabled()
367 ? ash::UMA_STATUS_AREA_BLUETOOTH_DISABLED 364 ? ash::UMA_STATUS_AREA_BLUETOOTH_DISABLED
368 : ash::UMA_STATUS_AREA_BLUETOOTH_ENABLED); 365 : ash::UMA_STATUS_AREA_BLUETOOTH_ENABLED);
369 delegate->ToggleBluetooth(); 366 delegate->ToggleBluetooth();
370 } else { 367 } else {
371 if (!delegate->GetBluetoothEnabled()) 368 if (!delegate->GetBluetoothEnabled())
372 return; 369 return;
373 std::map<views::View*, std::string>::iterator find; 370 std::map<views::View*, std::string>::iterator find;
374 find = device_map_.find(sender); 371 find = device_map_.find(sender);
375 if (find == device_map_.end()) 372 if (find == device_map_.end())
376 return; 373 return;
377 const std::string device_id = find->second; 374 const std::string device_id = find->second;
378 if (FoundDevice(device_id, connecting_devices_, NULL)) 375 if (FoundDevice(device_id, connecting_devices_, NULL))
379 return; 376 return;
380 UpdateClickedDevice(device_id, sender); 377 UpdateClickedDevice(device_id, sender);
381 delegate->ConnectToBluetoothDevice(device_id); 378 delegate->ConnectToBluetoothDevice(device_id);
382 } 379 }
383 } 380 }
384 381
385 // Overridden from ButtonListener. 382 // Overridden from ButtonListener.
386 void ButtonPressed(views::Button* sender, const ui::Event& event) override { 383 void ButtonPressed(views::Button* sender, const ui::Event& event) override {
387 ash::SystemTrayDelegate* delegate = 384 ash::SystemTrayDelegate* delegate =
388 ash::Shell::GetInstance()->system_tray_delegate(); 385 ash::WmShell::Get()->system_tray_delegate();
389 if (sender == toggle_bluetooth_) 386 if (sender == toggle_bluetooth_)
390 delegate->ToggleBluetooth(); 387 delegate->ToggleBluetooth();
391 else 388 else
392 NOTREACHED(); 389 NOTREACHED();
393 } 390 }
394 391
395 LoginStatus login_; 392 LoginStatus login_;
396 393
397 std::map<views::View*, std::string> device_map_; 394 std::map<views::View*, std::string> device_map_;
398 views::View* manage_devices_; 395 views::View* manage_devices_;
(...skipping 24 matching lines...) Expand all
423 } 420 }
424 421
425 views::View* TrayBluetooth::CreateDefaultView(LoginStatus status) { 422 views::View* TrayBluetooth::CreateDefaultView(LoginStatus status) {
426 CHECK(default_ == NULL); 423 CHECK(default_ == NULL);
427 default_ = 424 default_ =
428 new tray::BluetoothDefaultView(this, status != LoginStatus::LOCKED); 425 new tray::BluetoothDefaultView(this, status != LoginStatus::LOCKED);
429 return default_; 426 return default_;
430 } 427 }
431 428
432 views::View* TrayBluetooth::CreateDetailedView(LoginStatus status) { 429 views::View* TrayBluetooth::CreateDetailedView(LoginStatus status) {
433 if (!Shell::GetInstance()->system_tray_delegate()->GetBluetoothAvailable()) 430 if (!WmShell::Get()->system_tray_delegate()->GetBluetoothAvailable())
434 return NULL; 431 return NULL;
435 Shell::GetInstance()->metrics()->RecordUserMetricsAction( 432 Shell::GetInstance()->metrics()->RecordUserMetricsAction(
436 ash::UMA_STATUS_AREA_DETAILED_BLUETOOTH_VIEW); 433 ash::UMA_STATUS_AREA_DETAILED_BLUETOOTH_VIEW);
437 CHECK(detailed_ == NULL); 434 CHECK(detailed_ == NULL);
438 detailed_ = new tray::BluetoothDetailedView(this, status); 435 detailed_ = new tray::BluetoothDetailedView(this, status);
439 detailed_->Update(); 436 detailed_->Update();
440 return detailed_; 437 return detailed_;
441 } 438 }
442 439
443 void TrayBluetooth::DestroyTrayView() {} 440 void TrayBluetooth::DestroyTrayView() {}
(...skipping 15 matching lines...) Expand all
459 detailed_->Update(); 456 detailed_->Update();
460 } 457 }
461 458
462 void TrayBluetooth::OnBluetoothDiscoveringChanged() { 459 void TrayBluetooth::OnBluetoothDiscoveringChanged() {
463 if (!detailed_) 460 if (!detailed_)
464 return; 461 return;
465 detailed_->Update(); 462 detailed_->Update();
466 } 463 }
467 464
468 } // namespace ash 465 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698