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

Side by Side Diff: ash/system/logout_button/logout_confirmation_dialog_view.cc

Issue 40053002: Implements the dialog view for logout button tray in public sessions. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: minor fixes Created 7 years 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
(Empty)
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "ash/system/logout_button/logout_confirmation_dialog_view.h"
6
7 #include <cmath>
8
9 #include "ash/shell.h"
10 #include "ash/system/logout_button/logout_button_tray.h"
11 #include "ash/system/tray/system_tray_delegate.h"
12 #include "ash/system/tray/tray_constants.h"
13 #include "base/location.h"
14 #include "grit/ash_strings.h"
15 #include "ui/aura/root_window.h"
16 #include "ui/base/l10n/l10n_util.h"
17 #include "ui/base/l10n/time_format.h"
18 #include "ui/base/ui_base_types.h"
19 #include "ui/gfx/text_constants.h"
20 #include "ui/views/border.h"
21 #include "ui/views/controls/label.h"
22 #include "ui/views/layout/fill_layout.h"
23 #include "ui/views/widget/widget.h"
24
25 namespace ash {
26 namespace internal {
27
28 LogoutConfirmationDialogView::Delegate::Delegate() {
29 }
30
31 LogoutConfirmationDialogView::Delegate::~Delegate() {
32 }
33
34 void
35 LogoutConfirmationDialogView::Delegate::LogoutCurrentUser() {
36 if (Shell::HasInstance())
37 Shell::GetInstance()->system_tray_delegate()->SignOut();
38 }
39
40 base::TimeTicks LogoutConfirmationDialogView::Delegate::GetCurrentTime() const {
41 return base::TimeTicks::Now();
42 }
43
44 base::TimeDelta LogoutConfirmationDialogView::Delegate::GetUpdateInterval()
45 const {
46 return base::TimeDelta::FromSeconds(1);
47 }
48
49 LogoutConfirmationDialogView::LogoutConfirmationDialogView(
50 LogoutButtonTray* owner, Delegate* delegate) : owner_(owner),
51 delegate_(delegate) {
52 text_label_ = new views::Label;
53 text_label_->set_border(
54 views::Border::CreateEmptyBorder(0, kTrayPopupPaddingHorizontal,
55 0, kTrayPopupPaddingHorizontal));
56 text_label_->SetHorizontalAlignment(gfx::ALIGN_LEFT);
57 text_label_->SetMultiLine(true);
58
59 SetLayoutManager(new views::FillLayout());
60
61 AddChildView(text_label_);
62 }
63
64 LogoutConfirmationDialogView::~LogoutConfirmationDialogView() {
65 }
66
67 void LogoutConfirmationDialogView::DeleteDelegate() {
68 OnClosed();
bartfab (slow) 2013/12/12 16:04:13 As discussed offline, it is sufficient to just do
binjin 2013/12/17 10:29:49 Done.
69 delete this;
70 }
71
72 bool LogoutConfirmationDialogView::Accept() {
73 LogoutCurrentUser();
74 return true;
75 }
76
77 ui::ModalType LogoutConfirmationDialogView::GetModalType() const {
78 return ui::MODAL_TYPE_SYSTEM;
79 }
80
81 string16 LogoutConfirmationDialogView::GetWindowTitle() const {
82 return l10n_util::GetStringUTF16(IDS_ASH_LOGOUT_CONFIRMATION_TITLE);
83 }
84
85 string16 LogoutConfirmationDialogView::GetDialogButtonLabel(
86 ui::DialogButton button) const {
87 if (button == ui::DIALOG_BUTTON_OK)
88 return l10n_util::GetStringUTF16(IDS_ASH_LOGOUT_CONFIRMATION_BUTTON);
89 return views::DialogDelegateView::GetDialogButtonLabel(button);
90 }
91
92 void LogoutConfirmationDialogView::OnClosed() {
93 if (owner_) {
bartfab (slow) 2013/12/12 16:04:13 How can the owner_ ever be NULL?
binjin 2013/12/17 10:29:49 I'm not sure the reason, but OnClosed() is actuall
bartfab (slow) 2013/12/17 13:21:03 This is a bit worrying. It would seem that OnClose
binjin 2013/12/17 14:58:08 I checked the stack trace for both calls. here is
bartfab (slow) 2013/12/17 15:57:46 I think allowing OnClosed() to be called twice is
binjin 2013/12/18 18:13:14 Done.
94 owner_->DeleteConfirmationDialog();
95 owner_ = NULL;
96 timer_.Stop();
97 // nullify the delegate to prevent future activities of the dialog.
bartfab (slow) 2013/12/12 16:04:13 Nit: s/nullify/Nullify/
binjin 2013/12/17 10:29:49 Done.
98 delegate_ = NULL;
99 }
100 }
101
102 void LogoutConfirmationDialogView::Show(base::TimeDelta duration) {
103 if (!delegate_)
104 return;
105 countdown_start_time_ = delegate_->GetCurrentTime();
106 duration_ = duration;
107
108 UpdateCountdown();
109
110 // For testing purpose, only actually display the dialog if an existing
111 // ash::Shell is available.
112 if (ash::Shell::HasInstance()) {
113 views::DialogDelegate::CreateDialogWidget(
114 this, ash::Shell::GetPrimaryRootWindow(), NULL);
115 GetWidget()->Show();
116 }
117
118 timer_.Start(FROM_HERE,
119 delegate_->GetUpdateInterval(),
120 this,
121 &LogoutConfirmationDialogView::UpdateCountdown);
122 }
123
124 void LogoutConfirmationDialogView::UpdateDialogDuration(
125 base::TimeDelta duration) {
126 duration_ = duration;
127 UpdateCountdown();
128 }
129
130 void LogoutConfirmationDialogView::LogoutCurrentUser() {
131 if (!delegate_)
132 return;
133 // Backup the delegate, since closing widget will nullify it.
134 Delegate* delegate = delegate_;
135 // For testing purpose.
136 if (GetWidget()) {
137 GetWidget()->Close();
138 delegate->LogoutCurrentUser();
bartfab (slow) 2013/12/12 16:04:13 Why did you choose this ordering? If you called Lo
binjin 2013/12/17 10:29:49 I choose this ordering because I think the session
139 } else {
140 delegate->LogoutCurrentUser();
141 DeleteDelegate();
bartfab (slow) 2013/12/12 16:04:13 Could you call Close() here instead?
binjin 2013/12/17 10:29:49 I think the default implementation of DialogDelega
142 }
143 }
144
145 void LogoutConfirmationDialogView::UpdateCountdown() {
146 if (!delegate_)
147 return;
148 const base::TimeDelta time_remaining = countdown_start_time_
149 + duration_ - delegate_->GetCurrentTime();
bartfab (slow) 2013/12/12 16:04:13 Nit: The style guide says the + should go on the p
binjin 2013/12/17 10:29:49 Done.
150 // Round the remaining time to nearest second, and use this value for
151 // the countdown display and actual enforcement.
152 int seconds_remaining = round(time_remaining.InSecondsF());
153 if (seconds_remaining > 0) {
154 text_label_->SetText(l10n_util::GetStringFUTF16(
155 IDS_ASH_LOGOUT_CONFIRMATION_WARNING,
156 ui::TimeFormat::TimeDurationLong(base::TimeDelta::FromSeconds(
157 seconds_remaining))));
158 } else {
159 text_label_->SetText(l10n_util::GetStringUTF16(
160 IDS_ASH_LOGOUT_CONFIRMATION_WARNING_NOW));
161 timer_.Stop();
162 LogoutCurrentUser();
bartfab (slow) 2013/12/12 16:04:13 At this point, the dialog is still open and the de
binjin 2013/12/17 10:29:49 The LogoutCurrentUser() here is LogoutConfirmation
163 }
164 }
165
166 } // namespace internal
167 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698