Chromium Code Reviews| 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" | |
| 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" | |
| 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" | |
| 22 #include "ui/views/widget/widget.h" | |
| 23 | |
| 24 namespace { | |
| 25 | |
| 26 const int kCountdownUpdateIntervalMs = 1000; // 1 second. | |
| 27 | |
| 28 } // namespace | |
| 29 | |
| 30 namespace ash { | |
| 31 namespace internal { | |
| 32 | |
| 33 LogoutConfirmationSettingsProvider* | |
| 34 LogoutConfirmationDialogView::provider_ = NULL; | |
| 35 | |
| 36 LogoutConfirmationSettingsProvider::LogoutConfirmationSettingsProvider() { | |
| 37 } | |
| 38 | |
| 39 LogoutConfirmationSettingsProvider::~LogoutConfirmationSettingsProvider() { | |
| 40 } | |
| 41 | |
| 42 void LogoutConfirmationSettingsProvider::LogoutCurrentUser( | |
| 43 LogoutConfirmationDialogView* dialog) { | |
| 44 if (dialog) | |
| 45 dialog->GetWidget()->Close(); | |
|
bartfab (slow)
2013/12/03 19:46:04
Nit: Can the dialog not just call GetWidget()->Clo
binjin
2013/12/05 10:08:05
I'm not sure I understand, it's the dialog it self
bartfab (slow)
2013/12/06 13:50:04
What I meant is this: The LogoutCurrentUser() call
binjin
2013/12/09 18:50:02
Done.
| |
| 46 if (Shell::HasInstance()) | |
| 47 Shell::GetInstance()->system_tray_delegate()->SignOut(); | |
| 48 } | |
| 49 | |
| 50 base::TimeTicks LogoutConfirmationSettingsProvider::GetCurrentTime() { | |
| 51 return base::TimeTicks::Now(); | |
| 52 } | |
| 53 | |
| 54 base::TimeDelta LogoutConfirmationSettingsProvider::GetUpdateInterval() { | |
| 55 return base::TimeDelta::FromMilliseconds(kCountdownUpdateIntervalMs); | |
| 56 } | |
| 57 | |
| 58 LogoutConfirmationDialogView::LogoutConfirmationDialogView( | |
| 59 base::WeakPtr<LogoutButtonTray> owner) : owner_(owner) { | |
| 60 if (!provider_) { | |
| 61 provider_ = new LogoutConfirmationSettingsProvider; | |
| 62 } | |
| 63 | |
| 64 text_label_ = new views::Label; | |
| 65 text_label_->set_border( | |
| 66 views::Border::CreateEmptyBorder(0, kTrayPopupPaddingHorizontal, | |
| 67 0, kTrayPopupPaddingHorizontal)); | |
| 68 text_label_->SetHorizontalAlignment(gfx::ALIGN_LEFT); | |
| 69 text_label_->SetMultiLine(true); | |
| 70 | |
| 71 SetLayoutManager(new views::FillLayout()); | |
| 72 | |
| 73 AddChildView(text_label_); | |
| 74 } | |
| 75 | |
| 76 LogoutConfirmationDialogView::~LogoutConfirmationDialogView() { | |
| 77 } | |
| 78 | |
| 79 void LogoutConfirmationDialogView::DeleteDelegate() { | |
| 80 if (owner_) { | |
| 81 owner_->DeleteConfirmationDialog(); | |
| 82 } | |
| 83 } | |
| 84 | |
| 85 bool LogoutConfirmationDialogView::Accept() { | |
| 86 provider_->LogoutCurrentUser(this); | |
| 87 return true; | |
| 88 } | |
| 89 | |
| 90 ui::ModalType LogoutConfirmationDialogView::GetModalType() const { | |
| 91 return ui::MODAL_TYPE_SYSTEM; | |
| 92 } | |
| 93 | |
| 94 string16 LogoutConfirmationDialogView::GetWindowTitle() const { | |
| 95 return l10n_util::GetStringUTF16(IDS_ASH_LOGOUT_CONFIRMATION_TITLE); | |
| 96 } | |
| 97 | |
| 98 string16 LogoutConfirmationDialogView::GetDialogButtonLabel( | |
| 99 ui::DialogButton button) const { | |
| 100 if (button == ui::DIALOG_BUTTON_OK) | |
| 101 return l10n_util::GetStringUTF16(IDS_ASH_LOGOUT_CONFIRMATION_BUTTON); | |
| 102 return views::DialogDelegateView::GetDialogButtonLabel(button); | |
| 103 } | |
| 104 | |
| 105 void LogoutConfirmationDialogView::Show(base::TimeDelta duration) { | |
| 106 countdown_start_time_ = provider_->GetCurrentTime(); | |
| 107 duration_ = duration; | |
| 108 | |
| 109 UpdateCountdown(); | |
| 110 | |
| 111 // For testint purpose, only run the actually display the dialog if an | |
| 112 // existing ash::Shell is available. | |
| 113 if (ash::Shell::HasInstance()) { | |
| 114 views::DialogDelegate::CreateDialogWidget( | |
| 115 this, ash::Shell::GetPrimaryRootWindow(), NULL); | |
| 116 GetWidget()->Show(); | |
| 117 } | |
| 118 | |
| 119 timer_.Start(FROM_HERE, | |
| 120 provider_->GetUpdateInterval(), | |
| 121 this, | |
| 122 &LogoutConfirmationDialogView::UpdateCountdown); | |
| 123 } | |
| 124 | |
| 125 void LogoutConfirmationDialogView::UpdateDialogDuration( | |
| 126 base::TimeDelta duration) { | |
| 127 duration_ = duration; | |
| 128 UpdateCountdown(); | |
| 129 } | |
| 130 | |
| 131 void LogoutConfirmationDialogView::SetProvider( | |
| 132 LogoutConfirmationSettingsProvider* provider) { | |
| 133 provider_ = provider; | |
| 134 } | |
| 135 | |
| 136 LogoutConfirmationSettingsProvider* | |
| 137 LogoutConfirmationDialogView::GetProvider() { | |
| 138 return provider_; | |
| 139 } | |
| 140 | |
| 141 void LogoutConfirmationDialogView::UpdateCountdown() { | |
| 142 const base::TimeDelta time_remaining = countdown_start_time_ | |
| 143 + duration_ - provider_->GetCurrentTime(); | |
| 144 // Round the remaining time to nearest second, and use this value for | |
| 145 // the count down display. | |
| 146 int seconds_remaining = (time_remaining | |
| 147 + base::TimeDelta::FromMilliseconds(500)).InSeconds(); | |
| 148 if (seconds_remaining > 0) { | |
| 149 text_label_->SetText(l10n_util::GetStringFUTF16( | |
| 150 IDS_ASH_LOGOUT_CONFIRMATION_WARNING, | |
| 151 ui::TimeFormat::TimeDurationLong(base::TimeDelta::FromSeconds( | |
| 152 seconds_remaining)))); | |
| 153 } else { | |
| 154 text_label_->SetText(l10n_util::GetStringUTF16( | |
| 155 IDS_ASH_LOGOUT_CONFIRMATION_WARNING_NOW)); | |
| 156 timer_.Stop(); | |
| 157 provider_->LogoutCurrentUser(this); | |
| 158 } | |
| 159 } | |
| 160 | |
| 161 } // namespace internal | |
| 162 } // namespace ash | |
| OLD | NEW |