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

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

Issue 2099443002: Migrate simple ash Shell metrics users. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Update SessionStateDelegate accessors in touched files; cleanup. 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/fixed_sized_scroll_view.h" 8 #include "ash/common/system/tray/fixed_sized_scroll_view.h"
9 #include "ash/common/system/tray/hover_highlight_view.h" 9 #include "ash/common/system/tray/hover_highlight_view.h"
10 #include "ash/common/system/tray/system_tray_delegate.h" 10 #include "ash/common/system/tray/system_tray_delegate.h"
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 BluetoothDefaultView(SystemTrayItem* owner, bool show_more) 69 BluetoothDefaultView(SystemTrayItem* owner, bool show_more)
70 : TrayItemMore(owner, show_more) { 70 : TrayItemMore(owner, show_more) {
71 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); 71 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance();
72 SetImage(bundle.GetImageNamed(IDR_AURA_UBER_TRAY_BLUETOOTH).ToImageSkia()); 72 SetImage(bundle.GetImageNamed(IDR_AURA_UBER_TRAY_BLUETOOTH).ToImageSkia());
73 UpdateLabel(); 73 UpdateLabel();
74 } 74 }
75 75
76 ~BluetoothDefaultView() override {} 76 ~BluetoothDefaultView() override {}
77 77
78 void UpdateLabel() { 78 void UpdateLabel() {
79 ash::SystemTrayDelegate* delegate = 79 SystemTrayDelegate* delegate = WmShell::Get()->system_tray_delegate();
80 ash::WmShell::Get()->system_tray_delegate();
81 if (delegate->GetBluetoothAvailable()) { 80 if (delegate->GetBluetoothAvailable()) {
82 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); 81 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
83 const base::string16 label = 82 const base::string16 label =
84 rb.GetLocalizedString(delegate->GetBluetoothEnabled() 83 rb.GetLocalizedString(delegate->GetBluetoothEnabled()
85 ? IDS_ASH_STATUS_TRAY_BLUETOOTH_ENABLED 84 ? IDS_ASH_STATUS_TRAY_BLUETOOTH_ENABLED
86 : IDS_ASH_STATUS_TRAY_BLUETOOTH_DISABLED); 85 : IDS_ASH_STATUS_TRAY_BLUETOOTH_DISABLED);
87 SetLabel(label); 86 SetLabel(label);
88 SetAccessibleName(label); 87 SetAccessibleName(label);
89 SetVisible(true); 88 SetVisible(true);
90 } else { 89 } else {
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 } 124 }
126 125
127 private: 126 private:
128 void CreateItems() { 127 void CreateItems() {
129 CreateScrollableList(); 128 CreateScrollableList();
130 AppendSettingsEntries(); 129 AppendSettingsEntries();
131 AppendHeaderEntry(); 130 AppendHeaderEntry();
132 } 131 }
133 132
134 void BluetoothStartDiscovering() { 133 void BluetoothStartDiscovering() {
135 ash::SystemTrayDelegate* delegate = 134 SystemTrayDelegate* delegate = WmShell::Get()->system_tray_delegate();
136 ash::WmShell::Get()->system_tray_delegate();
137 bool bluetooth_enabled = delegate->GetBluetoothEnabled(); 135 bool bluetooth_enabled = delegate->GetBluetoothEnabled();
138 bool bluetooth_discovering = delegate->GetBluetoothDiscovering(); 136 bool bluetooth_discovering = delegate->GetBluetoothDiscovering();
139 if (bluetooth_discovering) { 137 if (bluetooth_discovering) {
140 throbber_->Start(); 138 throbber_->Start();
141 return; 139 return;
142 } 140 }
143 throbber_->Stop(); 141 throbber_->Stop();
144 if (bluetooth_enabled) { 142 if (bluetooth_enabled) {
145 delegate->BluetoothStartDiscovering(); 143 delegate->BluetoothStartDiscovering();
146 } 144 }
147 } 145 }
148 146
149 void BluetoothStopDiscovering() { 147 void BluetoothStopDiscovering() {
150 ash::SystemTrayDelegate* delegate = 148 SystemTrayDelegate* delegate = WmShell::Get()->system_tray_delegate();
151 ash::WmShell::Get()->system_tray_delegate();
152 if (delegate && delegate->GetBluetoothDiscovering()) { 149 if (delegate && delegate->GetBluetoothDiscovering()) {
153 delegate->BluetoothStopDiscovering(); 150 delegate->BluetoothStopDiscovering();
154 throbber_->Stop(); 151 throbber_->Stop();
155 } 152 }
156 } 153 }
157 154
158 void UpdateBluetoothDeviceList() { 155 void UpdateBluetoothDeviceList() {
159 std::set<std::string> new_connecting_devices; 156 std::set<std::string> new_connecting_devices;
160 std::set<std::string> new_connected_devices; 157 std::set<std::string> new_connected_devices;
161 std::set<std::string> new_paired_not_connected_devices; 158 std::set<std::string> new_paired_not_connected_devices;
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
197 194
198 if (login_ == LoginStatus::LOCKED) 195 if (login_ == LoginStatus::LOCKED)
199 return; 196 return;
200 197
201 throbber_ = new ThrobberView; 198 throbber_ = new ThrobberView;
202 throbber_->SetTooltipText( 199 throbber_->SetTooltipText(
203 l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_BLUETOOTH_DISCOVERING)); 200 l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_BLUETOOTH_DISCOVERING));
204 footer()->AddView(throbber_, false /* separator */); 201 footer()->AddView(throbber_, false /* separator */);
205 202
206 // Do not allow toggling bluetooth in the lock screen. 203 // Do not allow toggling bluetooth in the lock screen.
207 ash::SystemTrayDelegate* delegate = 204 SystemTrayDelegate* delegate = WmShell::Get()->system_tray_delegate();
208 ash::WmShell::Get()->system_tray_delegate();
209 toggle_bluetooth_ = 205 toggle_bluetooth_ =
210 new TrayPopupHeaderButton(this, IDR_AURA_UBER_TRAY_BLUETOOTH_ENABLED, 206 new TrayPopupHeaderButton(this, IDR_AURA_UBER_TRAY_BLUETOOTH_ENABLED,
211 IDR_AURA_UBER_TRAY_BLUETOOTH_DISABLED, 207 IDR_AURA_UBER_TRAY_BLUETOOTH_DISABLED,
212 IDR_AURA_UBER_TRAY_BLUETOOTH_ENABLED_HOVER, 208 IDR_AURA_UBER_TRAY_BLUETOOTH_ENABLED_HOVER,
213 IDR_AURA_UBER_TRAY_BLUETOOTH_DISABLED_HOVER, 209 IDR_AURA_UBER_TRAY_BLUETOOTH_DISABLED_HOVER,
214 IDS_ASH_STATUS_TRAY_BLUETOOTH); 210 IDS_ASH_STATUS_TRAY_BLUETOOTH);
215 toggle_bluetooth_->SetToggled(!delegate->GetBluetoothEnabled()); 211 toggle_bluetooth_->SetToggled(!delegate->GetBluetoothEnabled());
216 toggle_bluetooth_->SetTooltipText( 212 toggle_bluetooth_->SetTooltipText(
217 l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_DISABLE_BLUETOOTH)); 213 l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_DISABLE_BLUETOOTH));
218 toggle_bluetooth_->SetToggledTooltipText( 214 toggle_bluetooth_->SetToggledTooltipText(
219 l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_ENABLE_BLUETOOTH)); 215 l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_ENABLE_BLUETOOTH));
220 toggle_bluetooth_->EnableCanvasFlippingForRTLUI(false); 216 toggle_bluetooth_->EnableCanvasFlippingForRTLUI(false);
221 footer()->AddButton(toggle_bluetooth_); 217 footer()->AddButton(toggle_bluetooth_);
222 } 218 }
223 219
224 void UpdateHeaderEntry() { 220 void UpdateHeaderEntry() {
225 if (toggle_bluetooth_) { 221 if (toggle_bluetooth_) {
226 toggle_bluetooth_->SetToggled( 222 toggle_bluetooth_->SetToggled(
227 !ash::WmShell::Get()->system_tray_delegate()->GetBluetoothEnabled()); 223 !WmShell::Get()->system_tray_delegate()->GetBluetoothEnabled());
228 } 224 }
229 } 225 }
230 226
231 void UpdateDeviceScrollList() { 227 void UpdateDeviceScrollList() {
232 device_map_.clear(); 228 device_map_.clear();
233 scroll_content()->RemoveAllChildViews(true); 229 scroll_content()->RemoveAllChildViews(true);
234 enable_bluetooth_ = NULL; 230 enable_bluetooth_ = NULL;
235 231
236 ash::SystemTrayDelegate* delegate = 232 SystemTrayDelegate* delegate = WmShell::Get()->system_tray_delegate();
237 ash::WmShell::Get()->system_tray_delegate();
238 bool bluetooth_enabled = delegate->GetBluetoothEnabled(); 233 bool bluetooth_enabled = delegate->GetBluetoothEnabled();
239 bool blueooth_available = delegate->GetBluetoothAvailable(); 234 bool blueooth_available = delegate->GetBluetoothAvailable();
240 if (blueooth_available && !bluetooth_enabled && toggle_bluetooth_) { 235 if (blueooth_available && !bluetooth_enabled && toggle_bluetooth_) {
241 enable_bluetooth_ = AddScrollListItem( 236 enable_bluetooth_ = AddScrollListItem(
242 l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_ENABLE_BLUETOOTH), 237 l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_ENABLE_BLUETOOTH),
243 false /* highlight */, false /* checked */, true /* enabled */); 238 false /* highlight */, false /* checked */, true /* enabled */);
244 } 239 }
245 240
246 AppendSameTypeDevicesToScrollList(connected_devices_, true, true, 241 AppendSameTypeDevicesToScrollList(connected_devices_, true, true,
247 bluetooth_enabled); 242 bluetooth_enabled);
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
285 HoverHighlightView* container = new HoverHighlightView(this); 280 HoverHighlightView* container = new HoverHighlightView(this);
286 views::Label* label = 281 views::Label* label =
287 container->AddCheckableLabel(text, highlight, checked); 282 container->AddCheckableLabel(text, highlight, checked);
288 label->SetEnabled(enabled); 283 label->SetEnabled(enabled);
289 scroll_content()->AddChildView(container); 284 scroll_content()->AddChildView(container);
290 return container; 285 return container;
291 } 286 }
292 287
293 // Add settings entries. 288 // Add settings entries.
294 void AppendSettingsEntries() { 289 void AppendSettingsEntries() {
295 if (!ash::WmShell::Get()->system_tray_delegate()->ShouldShowSettings()) 290 if (!WmShell::Get()->system_tray_delegate()->ShouldShowSettings())
296 return; 291 return;
297 292
298 // Add bluetooth device requires a browser window, hide it for non logged in 293 // Add bluetooth device requires a browser window, hide it for non logged in
299 // user. 294 // user.
300 bool userAddingRunning = ash::Shell::GetInstance() 295 if (login_ == LoginStatus::NOT_LOGGED_IN || login_ == LoginStatus::LOCKED ||
James Cook 2016/06/23 20:23:12 ugh, we really need a shared piece of code for thi
msw 2016/06/23 21:08:49 Acknowledged.
301 ->session_state_delegate() 296 WmShell::Get()->GetSessionStateDelegate()->IsInSecondaryLoginScreen()) {
302 ->IsInSecondaryLoginScreen(); 297 return;
298 }
303 299
304 if (login_ == LoginStatus::NOT_LOGGED_IN || login_ == LoginStatus::LOCKED || 300 SystemTrayDelegate* delegate = WmShell::Get()->system_tray_delegate();
305 userAddingRunning)
306 return;
307
308 ash::SystemTrayDelegate* delegate =
309 ash::WmShell::Get()->system_tray_delegate();
310 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); 301 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
311 HoverHighlightView* container = new HoverHighlightView(this); 302 HoverHighlightView* container = new HoverHighlightView(this);
312 container->AddLabel( 303 container->AddLabel(
313 rb.GetLocalizedString(IDS_ASH_STATUS_TRAY_BLUETOOTH_MANAGE_DEVICES), 304 rb.GetLocalizedString(IDS_ASH_STATUS_TRAY_BLUETOOTH_MANAGE_DEVICES),
314 gfx::ALIGN_LEFT, false /* highlight */); 305 gfx::ALIGN_LEFT, false /* highlight */);
315 container->SetEnabled(delegate->GetBluetoothAvailable()); 306 container->SetEnabled(delegate->GetBluetoothAvailable());
316 AddChildView(container); 307 AddChildView(container);
317 manage_devices_ = container; 308 manage_devices_ = container;
318 } 309 }
319 310
(...skipping 25 matching lines...) Expand all
345 item_container->RemoveAllChildViews(true); 336 item_container->RemoveAllChildViews(true);
346 static_cast<HoverHighlightView*>(item_container) 337 static_cast<HoverHighlightView*>(item_container)
347 ->AddCheckableLabel(display_name, true /* highlight */, false); 338 ->AddCheckableLabel(display_name, true /* highlight */, false);
348 scroll_content()->SizeToPreferredSize(); 339 scroll_content()->SizeToPreferredSize();
349 static_cast<views::View*>(scroller())->Layout(); 340 static_cast<views::View*>(scroller())->Layout();
350 } 341 }
351 } 342 }
352 343
353 // Overridden from ViewClickListener. 344 // Overridden from ViewClickListener.
354 void OnViewClicked(views::View* sender) override { 345 void OnViewClicked(views::View* sender) override {
355 ash::SystemTrayDelegate* delegate = 346 SystemTrayDelegate* delegate = WmShell::Get()->system_tray_delegate();
356 ash::WmShell::Get()->system_tray_delegate();
357 if (sender == footer()->content()) { 347 if (sender == footer()->content()) {
358 TransitionToDefaultView(); 348 TransitionToDefaultView();
359 } else if (sender == manage_devices_) { 349 } else if (sender == manage_devices_) {
360 delegate->ManageBluetoothDevices(); 350 delegate->ManageBluetoothDevices();
361 } else if (sender == enable_bluetooth_) { 351 } else if (sender == enable_bluetooth_) {
362 Shell::GetInstance()->metrics()->RecordUserMetricsAction( 352 WmShell::Get()->RecordUserMetricsAction(
363 delegate->GetBluetoothEnabled() 353 delegate->GetBluetoothEnabled()
364 ? ash::UMA_STATUS_AREA_BLUETOOTH_DISABLED 354 ? UMA_STATUS_AREA_BLUETOOTH_DISABLED
365 : ash::UMA_STATUS_AREA_BLUETOOTH_ENABLED); 355 : UMA_STATUS_AREA_BLUETOOTH_ENABLED);
366 delegate->ToggleBluetooth(); 356 delegate->ToggleBluetooth();
367 } else { 357 } else {
368 if (!delegate->GetBluetoothEnabled()) 358 if (!delegate->GetBluetoothEnabled())
369 return; 359 return;
370 std::map<views::View*, std::string>::iterator find; 360 std::map<views::View*, std::string>::iterator find;
371 find = device_map_.find(sender); 361 find = device_map_.find(sender);
372 if (find == device_map_.end()) 362 if (find == device_map_.end())
373 return; 363 return;
374 const std::string device_id = find->second; 364 const std::string device_id = find->second;
375 if (FoundDevice(device_id, connecting_devices_, NULL)) 365 if (FoundDevice(device_id, connecting_devices_, NULL))
376 return; 366 return;
377 UpdateClickedDevice(device_id, sender); 367 UpdateClickedDevice(device_id, sender);
378 delegate->ConnectToBluetoothDevice(device_id); 368 delegate->ConnectToBluetoothDevice(device_id);
379 } 369 }
380 } 370 }
381 371
382 // Overridden from ButtonListener. 372 // Overridden from ButtonListener.
383 void ButtonPressed(views::Button* sender, const ui::Event& event) override { 373 void ButtonPressed(views::Button* sender, const ui::Event& event) override {
384 ash::SystemTrayDelegate* delegate = 374 SystemTrayDelegate* delegate = WmShell::Get()->system_tray_delegate();
385 ash::WmShell::Get()->system_tray_delegate();
386 if (sender == toggle_bluetooth_) 375 if (sender == toggle_bluetooth_)
387 delegate->ToggleBluetooth(); 376 delegate->ToggleBluetooth();
388 else 377 else
389 NOTREACHED(); 378 NOTREACHED();
390 } 379 }
391 380
392 LoginStatus login_; 381 LoginStatus login_;
393 382
394 std::map<views::View*, std::string> device_map_; 383 std::map<views::View*, std::string> device_map_;
395 views::View* manage_devices_; 384 views::View* manage_devices_;
(...skipping 26 matching lines...) Expand all
422 views::View* TrayBluetooth::CreateDefaultView(LoginStatus status) { 411 views::View* TrayBluetooth::CreateDefaultView(LoginStatus status) {
423 CHECK(default_ == NULL); 412 CHECK(default_ == NULL);
424 default_ = 413 default_ =
425 new tray::BluetoothDefaultView(this, status != LoginStatus::LOCKED); 414 new tray::BluetoothDefaultView(this, status != LoginStatus::LOCKED);
426 return default_; 415 return default_;
427 } 416 }
428 417
429 views::View* TrayBluetooth::CreateDetailedView(LoginStatus status) { 418 views::View* TrayBluetooth::CreateDetailedView(LoginStatus status) {
430 if (!WmShell::Get()->system_tray_delegate()->GetBluetoothAvailable()) 419 if (!WmShell::Get()->system_tray_delegate()->GetBluetoothAvailable())
431 return NULL; 420 return NULL;
432 Shell::GetInstance()->metrics()->RecordUserMetricsAction( 421 WmShell::Get()->RecordUserMetricsAction(
433 ash::UMA_STATUS_AREA_DETAILED_BLUETOOTH_VIEW); 422 UMA_STATUS_AREA_DETAILED_BLUETOOTH_VIEW);
434 CHECK(detailed_ == NULL); 423 CHECK(detailed_ == NULL);
435 detailed_ = new tray::BluetoothDetailedView(this, status); 424 detailed_ = new tray::BluetoothDetailedView(this, status);
436 detailed_->Update(); 425 detailed_->Update();
437 return detailed_; 426 return detailed_;
438 } 427 }
439 428
440 void TrayBluetooth::DestroyTrayView() {} 429 void TrayBluetooth::DestroyTrayView() {}
441 430
442 void TrayBluetooth::DestroyDefaultView() { 431 void TrayBluetooth::DestroyDefaultView() {
443 default_ = NULL; 432 default_ = NULL;
(...skipping 12 matching lines...) Expand all
456 detailed_->Update(); 445 detailed_->Update();
457 } 446 }
458 447
459 void TrayBluetooth::OnBluetoothDiscoveringChanged() { 448 void TrayBluetooth::OnBluetoothDiscoveringChanged() {
460 if (!detailed_) 449 if (!detailed_)
461 return; 450 return;
462 detailed_->Update(); 451 detailed_->Update();
463 } 452 }
464 453
465 } // namespace ash 454 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698