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

Side by Side Diff: ash/common/system/tiles/tiles_default_view.cc

Issue 2497123002: chromeos: Move device shutdown handling out of chrome into ash (Closed)
Patch Set: rebase Created 4 years, 1 month 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 | « ash/common/system/tiles/tiles_default_view.h ('k') | ash/common/system/tiles/tray_tiles.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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/tiles/tiles_default_view.h" 5 #include "ash/common/system/tiles/tiles_default_view.h"
6 6
7 #include "ash/common/metrics/user_metrics_action.h" 7 #include "ash/common/metrics/user_metrics_action.h"
8 #include "ash/common/session/session_state_delegate.h" 8 #include "ash/common/session/session_state_delegate.h"
9 #include "ash/common/shutdown_controller.h"
9 #include "ash/common/system/tray/system_menu_button.h" 10 #include "ash/common/system/tray/system_menu_button.h"
10 #include "ash/common/system/tray/system_tray.h" 11 #include "ash/common/system/tray/system_tray.h"
11 #include "ash/common/system/tray/system_tray_controller.h" 12 #include "ash/common/system/tray/system_tray_controller.h"
12 #include "ash/common/system/tray/system_tray_delegate.h" 13 #include "ash/common/system/tray/system_tray_delegate.h"
13 #include "ash/common/system/tray/system_tray_item.h" 14 #include "ash/common/system/tray/system_tray_item.h"
14 #include "ash/common/system/tray/tray_constants.h" 15 #include "ash/common/system/tray/tray_constants.h"
15 #include "ash/common/system/tray/tray_popup_utils.h" 16 #include "ash/common/system/tray/tray_popup_utils.h"
16 #include "ash/common/wm_shell.h" 17 #include "ash/common/wm_shell.h"
17 #include "ash/resources/vector_icons/vector_icons.h" 18 #include "ash/resources/vector_icons/vector_icons.h"
18 #include "grit/ash_strings.h" 19 #include "grit/ash_strings.h"
(...skipping 18 matching lines...) Expand all
37 } // namespace 38 } // namespace
38 39
39 namespace ash { 40 namespace ash {
40 41
41 TilesDefaultView::TilesDefaultView(SystemTrayItem* owner, LoginStatus login) 42 TilesDefaultView::TilesDefaultView(SystemTrayItem* owner, LoginStatus login)
42 : owner_(owner), 43 : owner_(owner),
43 login_(login), 44 login_(login),
44 settings_button_(nullptr), 45 settings_button_(nullptr),
45 help_button_(nullptr), 46 help_button_(nullptr),
46 lock_button_(nullptr), 47 lock_button_(nullptr),
47 power_button_(nullptr), 48 power_button_(nullptr) {}
48 weak_factory_(this) {}
49 49
50 TilesDefaultView::~TilesDefaultView() { 50 TilesDefaultView::~TilesDefaultView() {}
51 SystemTrayDelegate* system_tray_delegate =
52 WmShell::Get()->system_tray_delegate();
53
54 // Perform this check since the delegate is destroyed first upon shell
55 // destruction.
56 if (system_tray_delegate)
57 system_tray_delegate->RemoveShutdownPolicyObserver(this);
58 }
59 51
60 void TilesDefaultView::Init() { 52 void TilesDefaultView::Init() {
61 WmShell* shell = WmShell::Get(); 53 WmShell* shell = WmShell::Get();
62 views::BoxLayout* box_layout = 54 views::BoxLayout* box_layout =
63 new views::BoxLayout(views::BoxLayout::kHorizontal, 4, 0, 0); 55 new views::BoxLayout(views::BoxLayout::kHorizontal, 4, 0, 0);
64 box_layout->set_main_axis_alignment( 56 box_layout->set_main_axis_alignment(
65 views::BoxLayout::MAIN_AXIS_ALIGNMENT_START); 57 views::BoxLayout::MAIN_AXIS_ALIGNMENT_START);
66 box_layout->set_cross_axis_alignment( 58 box_layout->set_cross_axis_alignment(
67 views::BoxLayout::CROSS_AXIS_ALIGNMENT_CENTER); 59 views::BoxLayout::CROSS_AXIS_ALIGNMENT_CENTER);
68 SetLayoutManager(box_layout); 60 SetLayoutManager(box_layout);
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 if (disable_buttons || !shell->GetSessionStateDelegate()->CanLockScreen()) 94 if (disable_buttons || !shell->GetSessionStateDelegate()->CanLockScreen())
103 lock_button_->SetState(views::Button::STATE_DISABLED); 95 lock_button_->SetState(views::Button::STATE_DISABLED);
104 96
105 AddChildView(lock_button_); 97 AddChildView(lock_button_);
106 AddChildView(TrayPopupUtils::CreateVerticalSeparator()); 98 AddChildView(TrayPopupUtils::CreateVerticalSeparator());
107 99
108 power_button_ = 100 power_button_ =
109 new SystemMenuButton(this, SystemMenuButton::InkDropStyle::FLOOD_FILL, 101 new SystemMenuButton(this, SystemMenuButton::InkDropStyle::FLOOD_FILL,
110 kSystemMenuPowerIcon, IDS_ASH_STATUS_TRAY_SHUTDOWN); 102 kSystemMenuPowerIcon, IDS_ASH_STATUS_TRAY_SHUTDOWN);
111 AddChildView(power_button_); 103 AddChildView(power_button_);
112 SystemTrayDelegate* system_tray_delegate = shell->system_tray_delegate(); 104 // This object is recreated every time the menu opens. Don't bother updating
113 system_tray_delegate->AddShutdownPolicyObserver(this); 105 // the tooltip if the shutdown policy changes while the menu is open.
114 system_tray_delegate->ShouldRebootOnShutdown(base::Bind( 106 bool reboot = WmShell::Get()->shutdown_controller()->reboot_on_shutdown();
115 &TilesDefaultView::OnShutdownPolicyChanged, weak_factory_.GetWeakPtr())); 107 power_button_->SetTooltipText(l10n_util::GetStringUTF16(
108 reboot ? IDS_ASH_STATUS_TRAY_REBOOT : IDS_ASH_STATUS_TRAY_SHUTDOWN));
116 #endif // !defined(OS_WIN) 109 #endif // !defined(OS_WIN)
117 } 110 }
118 111
119 void TilesDefaultView::ButtonPressed(views::Button* sender, 112 void TilesDefaultView::ButtonPressed(views::Button* sender,
120 const ui::Event& event) { 113 const ui::Event& event) {
121 DCHECK(sender); 114 DCHECK(sender);
122 WmShell* shell = WmShell::Get(); 115 WmShell* shell = WmShell::Get();
123 if (sender == settings_button_) { 116 if (sender == settings_button_) {
124 shell->RecordUserMetricsAction(UMA_TRAY_SETTINGS); 117 shell->RecordUserMetricsAction(UMA_TRAY_SETTINGS);
125 shell->system_tray_controller()->ShowSettings(); 118 shell->system_tray_controller()->ShowSettings();
126 } else if (sender == help_button_) { 119 } else if (sender == help_button_) {
127 shell->RecordUserMetricsAction(UMA_TRAY_HELP); 120 shell->RecordUserMetricsAction(UMA_TRAY_HELP);
128 shell->system_tray_controller()->ShowHelp(); 121 shell->system_tray_controller()->ShowHelp();
129 } else if (sender == lock_button_) { 122 } else if (sender == lock_button_) {
130 shell->RecordUserMetricsAction(UMA_TRAY_LOCK_SCREEN); 123 shell->RecordUserMetricsAction(UMA_TRAY_LOCK_SCREEN);
131 #if defined(OS_CHROMEOS) 124 #if defined(OS_CHROMEOS)
132 chromeos::DBusThreadManager::Get() 125 chromeos::DBusThreadManager::Get()
133 ->GetSessionManagerClient() 126 ->GetSessionManagerClient()
134 ->RequestLockScreen(); 127 ->RequestLockScreen();
135 #endif 128 #endif
136 } else if (sender == power_button_) { 129 } else if (sender == power_button_) {
137 shell->RecordUserMetricsAction(UMA_TRAY_SHUT_DOWN); 130 shell->RecordUserMetricsAction(UMA_TRAY_SHUT_DOWN);
138 shell->RequestShutdown(); 131 shell->RequestShutdown();
139 } 132 }
140 133
141 owner_->system_tray()->CloseSystemBubble(); 134 owner_->system_tray()->CloseSystemBubble();
142 } 135 }
143 136
144 void TilesDefaultView::OnShutdownPolicyChanged(bool reboot_on_shutdown) {
145 if (!power_button_)
146 return;
147
148 power_button_->SetTooltipText(l10n_util::GetStringUTF16(
149 reboot_on_shutdown ? IDS_ASH_STATUS_TRAY_REBOOT
150 : IDS_ASH_STATUS_TRAY_SHUTDOWN));
151 }
152
153 views::View* TilesDefaultView::GetHelpButtonView() const { 137 views::View* TilesDefaultView::GetHelpButtonView() const {
154 return help_button_; 138 return help_button_;
155 } 139 }
156 140
157 const views::CustomButton* TilesDefaultView::GetShutdownButtonViewForTest() 141 const views::CustomButton* TilesDefaultView::GetShutdownButtonViewForTest()
158 const { 142 const {
159 return power_button_; 143 return power_button_;
160 } 144 }
161 145
162 } // namespace ash 146 } // namespace ash
OLDNEW
« no previous file with comments | « ash/common/system/tiles/tiles_default_view.h ('k') | ash/common/system/tiles/tray_tiles.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698