OLD | NEW |
---|---|
(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 "ash/shell.h" | |
8 #include "ash/system/logout_button/logout_button_tray.h" | |
bartfab (slow)
2013/12/10 12:41:16
Nit: Actually not needed once you remove |owner| a
| |
9 #include "ash/system/tray/system_tray_delegate.h" | |
10 #include "ash/system/tray/tray_constants.h" | |
11 #include "base/location.h" | |
12 #include "grit/ash_strings.h" | |
13 #include "grit/ui_strings.h" | |
bartfab (slow)
2013/12/10 12:41:16
Nit: Where is this used?
binjin
2013/12/12 13:56:55
Done.
| |
14 #include "ui/aura/root_window.h" | |
15 #include "ui/base/l10n/l10n_util.h" | |
16 #include "ui/base/l10n/time_format.h" | |
17 #include "ui/base/ui_base_types.h" | |
18 #include "ui/gfx/text_constants.h" | |
19 #include "ui/views/controls/label.h" | |
20 #include "ui/views/layout/fill_layout.h" | |
21 #include "ui/views/layout/layout_constants.h" | |
bartfab (slow)
2013/12/10 12:41:16
Nit: Where is this used?
binjin
2013/12/12 13:56:55
Done.
| |
22 #include "ui/views/widget/widget.h" | |
23 | |
24 namespace { | |
25 | |
26 const int kCountdownUpdateIntervalMs = 1000; // 1 second. | |
bartfab (slow)
2013/12/10 12:41:16
Nit: Two spaces between inline comment.
binjin
2013/12/12 13:56:55
Done.
| |
27 | |
28 } // namespace | |
29 | |
30 namespace ash { | |
31 namespace internal { | |
32 | |
33 LogoutConfirmationDialogView::LogoutConfirmationDelegate:: | |
34 LogoutConfirmationDelegate() { | |
35 } | |
36 | |
37 LogoutConfirmationDialogView::LogoutConfirmationDelegate:: | |
38 ~LogoutConfirmationDelegate() { | |
39 } | |
40 | |
41 void | |
42 LogoutConfirmationDialogView::LogoutConfirmationDelegate::LogoutCurrentUser() { | |
43 if (Shell::HasInstance()) | |
44 Shell::GetInstance()->system_tray_delegate()->SignOut(); | |
45 } | |
46 | |
47 base::TimeTicks LogoutConfirmationDialogView::LogoutConfirmationDelegate:: | |
48 GetCurrentTime() { | |
49 return base::TimeTicks::Now(); | |
50 } | |
51 | |
52 base::TimeDelta LogoutConfirmationDialogView::LogoutConfirmationDelegate:: | |
53 GetUpdateInterval() { | |
54 return base::TimeDelta::FromMilliseconds(kCountdownUpdateIntervalMs); | |
bartfab (slow)
2013/12/10 12:41:16
Nit: You could use FromSeconds(1), removing the ne
binjin
2013/12/12 13:56:55
Done.
| |
55 } | |
56 | |
57 LogoutConfirmationDialogView::LogoutConfirmationDialogView( | |
58 base::WeakPtr<LogoutButtonTray> owner, | |
59 LogoutConfirmationDelegate* delegate) : owner_(owner), delegate_(delegate) { | |
60 | |
bartfab (slow)
2013/12/10 12:41:16
Nit: Remove blank line.
binjin
2013/12/12 13:56:55
Done.
| |
61 text_label_ = new views::Label; | |
62 text_label_->set_border( | |
63 views::Border::CreateEmptyBorder(0, kTrayPopupPaddingHorizontal, | |
bartfab (slow)
2013/12/10 12:41:16
Nit: #include "ui/views/border.h"
binjin
2013/12/12 13:56:55
Done.
| |
64 0, kTrayPopupPaddingHorizontal)); | |
65 text_label_->SetHorizontalAlignment(gfx::ALIGN_LEFT); | |
66 text_label_->SetMultiLine(true); | |
67 | |
68 SetLayoutManager(new views::FillLayout()); | |
69 | |
70 AddChildView(text_label_); | |
71 } | |
72 | |
73 LogoutConfirmationDialogView::~LogoutConfirmationDialogView() { | |
74 } | |
75 | |
76 void LogoutConfirmationDialogView::DeleteDelegate() { | |
bartfab (slow)
2013/12/10 12:41:16
This is actually not needed. You could post a Dele
| |
77 if (owner_) { | |
bartfab (slow)
2013/12/10 12:41:16
Nit: No curly braces for single-line conditionals.
binjin
2013/12/12 13:56:55
Done.
| |
78 owner_->DeleteConfirmationDialog(); | |
79 } | |
80 } | |
81 | |
82 bool LogoutConfirmationDialogView::Accept() { | |
83 LogoutCurrentUser(); | |
84 return true; | |
85 } | |
86 | |
87 ui::ModalType LogoutConfirmationDialogView::GetModalType() const { | |
88 return ui::MODAL_TYPE_SYSTEM; | |
89 } | |
90 | |
91 string16 LogoutConfirmationDialogView::GetWindowTitle() const { | |
92 return l10n_util::GetStringUTF16(IDS_ASH_LOGOUT_CONFIRMATION_TITLE); | |
93 } | |
94 | |
95 string16 LogoutConfirmationDialogView::GetDialogButtonLabel( | |
96 ui::DialogButton button) const { | |
97 if (button == ui::DIALOG_BUTTON_OK) | |
98 return l10n_util::GetStringUTF16(IDS_ASH_LOGOUT_CONFIRMATION_BUTTON); | |
99 return views::DialogDelegateView::GetDialogButtonLabel(button); | |
100 } | |
101 | |
102 void LogoutConfirmationDialogView::Show(base::TimeDelta duration) { | |
103 countdown_start_time_ = delegate_->GetCurrentTime(); | |
104 duration_ = duration; | |
105 | |
106 UpdateCountdown(); | |
107 | |
108 // For testint purpose, only run the actually display the dialog if an | |
bartfab (slow)
2013/12/10 12:41:16
Nit 1: s/testint/testing/.
Nit 2: s/run the//.
binjin
2013/12/12 13:56:55
Done.
| |
109 // existing ash::Shell is available. | |
110 if (ash::Shell::HasInstance()) { | |
111 views::DialogDelegate::CreateDialogWidget( | |
112 this, ash::Shell::GetPrimaryRootWindow(), NULL); | |
113 GetWidget()->Show(); | |
114 } | |
115 | |
116 timer_.Start(FROM_HERE, | |
117 delegate_->GetUpdateInterval(), | |
118 this, | |
119 &LogoutConfirmationDialogView::UpdateCountdown); | |
120 } | |
121 | |
122 void LogoutConfirmationDialogView::UpdateDialogDuration( | |
123 base::TimeDelta duration) { | |
124 duration_ = duration; | |
125 UpdateCountdown(); | |
126 } | |
127 | |
128 void LogoutConfirmationDialogView::LogoutCurrentUser() { | |
129 // For testing purpose. | |
130 if (GetWidget()) { | |
131 GetWidget()->Close(); | |
132 delegate_->LogoutCurrentUser(); | |
133 } else { | |
134 delegate_->LogoutCurrentUser(); | |
135 DeleteDelegate(); | |
136 } | |
137 } | |
138 | |
139 void LogoutConfirmationDialogView::UpdateCountdown() { | |
140 const base::TimeDelta time_remaining = countdown_start_time_ | |
bartfab (slow)
2013/12/10 12:41:16
In its destructor, LogoutButtonTray calls confirma
binjin
2013/12/12 13:56:55
Done.
| |
141 + duration_ - delegate_->GetCurrentTime(); | |
142 // Round the remaining time to nearest second, and use this value for | |
143 // the count down display. | |
bartfab (slow)
2013/12/10 12:41:16
Nit 1: s/count down/countdown/.
Nit 2: Contrary to
binjin
2013/12/12 13:56:55
Done.
| |
144 int seconds_remaining = (time_remaining | |
bartfab (slow)
2013/12/10 12:41:16
Nit: Why not round(InSecondsF())?
binjin
2013/12/12 13:56:55
Done.
| |
145 + base::TimeDelta::FromMilliseconds(500)).InSeconds(); | |
146 if (seconds_remaining > 0) { | |
147 text_label_->SetText(l10n_util::GetStringFUTF16( | |
148 IDS_ASH_LOGOUT_CONFIRMATION_WARNING, | |
149 ui::TimeFormat::TimeDurationLong(base::TimeDelta::FromSeconds( | |
150 seconds_remaining)))); | |
151 } else { | |
152 text_label_->SetText(l10n_util::GetStringUTF16( | |
153 IDS_ASH_LOGOUT_CONFIRMATION_WARNING_NOW)); | |
154 timer_.Stop(); | |
155 LogoutCurrentUser(); | |
156 } | |
157 } | |
158 | |
159 } // namespace internal | |
160 } // namespace ash | |
OLD | NEW |