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

Side by Side Diff: ash/system/date/date_default_view.cc

Issue 2058173002: mash: Move SystemTrayDelegate ownership to WmShell (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: review feedback 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/date/date_default_view.h" 5 #include "ash/system/date/date_default_view.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/metrics/user_metrics_recorder.h" 11 #include "ash/metrics/user_metrics_recorder.h"
11 #include "ash/shell.h" 12 #include "ash/shell.h"
12 #include "ash/system/date/date_view.h" 13 #include "ash/system/date/date_view.h"
13 #include "ash/system/tray/special_popup_row.h" 14 #include "ash/system/tray/special_popup_row.h"
14 #include "ash/system/tray/tray_popup_header_button.h" 15 #include "ash/system/tray/tray_popup_header_button.h"
15 #include "ash/wm/lock_state_controller.h" 16 #include "ash/wm/lock_state_controller.h"
16 #include "base/i18n/rtl.h" 17 #include "base/i18n/rtl.h"
17 #include "grit/ash_resources.h" 18 #include "grit/ash_resources.h"
18 #include "grit/ash_strings.h" 19 #include "grit/ash_strings.h"
19 #include "ui/base/l10n/l10n_util.h" 20 #include "ui/base/l10n/l10n_util.h"
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 if (ash::Shell::GetInstance()->session_state_delegate()->CanLockScreen()) { 89 if (ash::Shell::GetInstance()->session_state_delegate()->CanLockScreen()) {
89 lock_button_ = new TrayPopupHeaderButton( 90 lock_button_ = new TrayPopupHeaderButton(
90 this, IDR_AURA_UBER_TRAY_LOCKSCREEN, IDR_AURA_UBER_TRAY_LOCKSCREEN, 91 this, IDR_AURA_UBER_TRAY_LOCKSCREEN, IDR_AURA_UBER_TRAY_LOCKSCREEN,
91 IDR_AURA_UBER_TRAY_LOCKSCREEN_HOVER, 92 IDR_AURA_UBER_TRAY_LOCKSCREEN_HOVER,
92 IDR_AURA_UBER_TRAY_LOCKSCREEN_HOVER, IDS_ASH_STATUS_TRAY_LOCK); 93 IDR_AURA_UBER_TRAY_LOCKSCREEN_HOVER, IDS_ASH_STATUS_TRAY_LOCK);
93 lock_button_->SetTooltipText( 94 lock_button_->SetTooltipText(
94 l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_LOCK)); 95 l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_LOCK));
95 view->AddButton(lock_button_); 96 view->AddButton(lock_button_);
96 } 97 }
97 SystemTrayDelegate* system_tray_delegate = 98 SystemTrayDelegate* system_tray_delegate =
98 Shell::GetInstance()->system_tray_delegate(); 99 WmShell::Get()->system_tray_delegate();
99 system_tray_delegate->AddShutdownPolicyObserver(this); 100 system_tray_delegate->AddShutdownPolicyObserver(this);
100 system_tray_delegate->ShouldRebootOnShutdown(base::Bind( 101 system_tray_delegate->ShouldRebootOnShutdown(base::Bind(
101 &DateDefaultView::OnShutdownPolicyChanged, weak_factory_.GetWeakPtr())); 102 &DateDefaultView::OnShutdownPolicyChanged, weak_factory_.GetWeakPtr()));
102 #endif // !defined(OS_WIN) 103 #endif // !defined(OS_WIN)
103 } 104 }
104 105
105 DateDefaultView::~DateDefaultView() { 106 DateDefaultView::~DateDefaultView() {
106 // We need the check as on shell destruction, the delegate is destroyed first. 107 // We need the check as on shell destruction, the delegate is destroyed first.
107 SystemTrayDelegate* system_tray_delegate = 108 SystemTrayDelegate* system_tray_delegate =
108 Shell::GetInstance()->system_tray_delegate(); 109 WmShell::Get()->system_tray_delegate();
109 if (system_tray_delegate) 110 if (system_tray_delegate)
110 system_tray_delegate->RemoveShutdownPolicyObserver(this); 111 system_tray_delegate->RemoveShutdownPolicyObserver(this);
111 } 112 }
112 113
113 views::View* DateDefaultView::GetHelpButtonView() { 114 views::View* DateDefaultView::GetHelpButtonView() {
114 return help_button_; 115 return help_button_;
115 } 116 }
116 117
117 const views::View* DateDefaultView::GetShutdownButtonViewForTest() const { 118 const views::View* DateDefaultView::GetShutdownButtonViewForTest() const {
118 return shutdown_button_; 119 return shutdown_button_;
119 } 120 }
120 121
121 tray::DateView* DateDefaultView::GetDateView() { 122 tray::DateView* DateDefaultView::GetDateView() {
122 return date_view_; 123 return date_view_;
123 } 124 }
124 125
125 const tray::DateView* DateDefaultView::GetDateView() const { 126 const tray::DateView* DateDefaultView::GetDateView() const {
126 return date_view_; 127 return date_view_;
127 } 128 }
128 129
129 void DateDefaultView::ButtonPressed(views::Button* sender, 130 void DateDefaultView::ButtonPressed(views::Button* sender,
130 const ui::Event& event) { 131 const ui::Event& event) {
131 ash::Shell* shell = ash::Shell::GetInstance(); 132 Shell* shell = Shell::GetInstance();
132 ash::SystemTrayDelegate* tray_delegate = shell->system_tray_delegate(); 133 SystemTrayDelegate* tray_delegate = WmShell::Get()->system_tray_delegate();
133 if (sender == help_button_) { 134 if (sender == help_button_) {
134 shell->metrics()->RecordUserMetricsAction(ash::UMA_TRAY_HELP); 135 shell->metrics()->RecordUserMetricsAction(ash::UMA_TRAY_HELP);
135 tray_delegate->ShowHelp(); 136 tray_delegate->ShowHelp();
136 } else if (sender == shutdown_button_) { 137 } else if (sender == shutdown_button_) {
137 shell->metrics()->RecordUserMetricsAction(ash::UMA_TRAY_SHUT_DOWN); 138 shell->metrics()->RecordUserMetricsAction(ash::UMA_TRAY_SHUT_DOWN);
138 ash::Shell::GetInstance()->lock_state_controller()->RequestShutdown(); 139 shell->lock_state_controller()->RequestShutdown();
139 } else if (sender == lock_button_) { 140 } else if (sender == lock_button_) {
140 shell->metrics()->RecordUserMetricsAction(ash::UMA_TRAY_LOCK_SCREEN); 141 shell->metrics()->RecordUserMetricsAction(ash::UMA_TRAY_LOCK_SCREEN);
141 tray_delegate->RequestLockScreen(); 142 tray_delegate->RequestLockScreen();
142 } else { 143 } else {
143 NOTREACHED(); 144 NOTREACHED();
144 } 145 }
145 } 146 }
146 147
147 void DateDefaultView::OnShutdownPolicyChanged(bool reboot_on_shutdown) { 148 void DateDefaultView::OnShutdownPolicyChanged(bool reboot_on_shutdown) {
148 if (!shutdown_button_) 149 if (!shutdown_button_)
149 return; 150 return;
150 151
151 shutdown_button_->SetTooltipText(l10n_util::GetStringUTF16( 152 shutdown_button_->SetTooltipText(l10n_util::GetStringUTF16(
152 reboot_on_shutdown ? IDS_ASH_STATUS_TRAY_REBOOT 153 reboot_on_shutdown ? IDS_ASH_STATUS_TRAY_REBOOT
153 : IDS_ASH_STATUS_TRAY_SHUTDOWN)); 154 : IDS_ASH_STATUS_TRAY_SHUTDOWN));
154 } 155 }
155 156
156 } // namespace ash 157 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698