| Index: ash/system/logout_button/logout_button_tray.cc
|
| diff --git a/ash/system/logout_button/logout_button_tray.cc b/ash/system/logout_button/logout_button_tray.cc
|
| index c06073040c5c26822b641ecb479f29c65cae088f..76752b79324e551e21eb5ab1c4efa381904fce33 100644
|
| --- a/ash/system/logout_button/logout_button_tray.cc
|
| +++ b/ash/system/logout_button/logout_button_tray.cc
|
| @@ -24,7 +24,6 @@
|
| #include "ui/views/painter.h"
|
|
|
| namespace ash {
|
| -
|
| namespace internal {
|
|
|
| namespace {
|
| @@ -98,16 +97,43 @@ LogoutButtonTray::LogoutButtonTray(StatusAreaWidget* status_area_widget)
|
| : TrayBackgroundView(status_area_widget),
|
| button_(NULL),
|
| login_status_(user::LOGGED_IN_NONE),
|
| - show_logout_button_in_tray_(false) {
|
| + show_logout_button_in_tray_(false),
|
| + confirmation_dialog_(NULL),
|
| + confirmation_delegate_(new LogoutConfirmationDialogView::Delegate) {
|
| button_ = new LogoutButton(this);
|
| tray_container()->AddChildView(button_);
|
| tray_container()->set_border(NULL);
|
| - Shell::GetInstance()->system_tray_notifier()->AddLogoutButtonObserver(this);
|
| + // The Shell may not exist in some unit tests.
|
| + if (Shell::HasInstance()) {
|
| + Shell::GetInstance()->system_tray_notifier()->
|
| + AddLogoutButtonObserver(this);
|
| + }
|
| }
|
|
|
| LogoutButtonTray::~LogoutButtonTray() {
|
| - Shell::GetInstance()->system_tray_notifier()->
|
| - RemoveLogoutButtonObserver(this);
|
| + EnsureConfirmationDialogIsClosed();
|
| + // The Shell may not exist in some unit tests.
|
| + if (Shell::HasInstance()) {
|
| + Shell::GetInstance()->system_tray_notifier()->
|
| + RemoveLogoutButtonObserver(this);
|
| + }
|
| +}
|
| +
|
| +bool LogoutButtonTray::IsConfirmationDialogShowing() const {
|
| + return confirmation_dialog_;
|
| +}
|
| +
|
| +void LogoutButtonTray::EnsureConfirmationDialogIsShowing() {
|
| + if (!confirmation_dialog_) {
|
| + confirmation_dialog_ = new LogoutConfirmationDialogView(
|
| + this, confirmation_delegate_.get());
|
| + confirmation_dialog_->Show(dialog_duration_);
|
| + }
|
| +}
|
| +
|
| +void LogoutButtonTray::EnsureConfirmationDialogIsClosed() {
|
| + if (confirmation_dialog_)
|
| + confirmation_dialog_->Close();
|
| }
|
|
|
| void LogoutButtonTray::SetShelfAlignment(ShelfAlignment alignment) {
|
| @@ -132,10 +158,20 @@ void LogoutButtonTray::OnShowLogoutButtonInTrayChanged(bool show) {
|
| UpdateVisibility();
|
| }
|
|
|
| +void LogoutButtonTray::OnLogoutDialogDurationChanged(base::TimeDelta duration) {
|
| + dialog_duration_ = duration;
|
| + if (confirmation_dialog_)
|
| + confirmation_dialog_->UpdateDialogDuration(dialog_duration_);
|
| +}
|
| +
|
| void LogoutButtonTray::ButtonPressed(views::Button* sender,
|
| const ui::Event& event) {
|
| DCHECK_EQ(sender, button_);
|
| - Shell::GetInstance()->system_tray_delegate()->SignOut();
|
| + // Sign out immediately if |dialog_duration_| is non-positive.
|
| + if (dialog_duration_ <= base::TimeDelta())
|
| + confirmation_delegate_->LogoutCurrentUser();
|
| + else
|
| + EnsureConfirmationDialogIsShowing();
|
| }
|
|
|
| void LogoutButtonTray::UpdateAfterLoginStatusChange(
|
| @@ -148,10 +184,21 @@ void LogoutButtonTray::UpdateAfterLoginStatusChange(
|
| UpdateVisibility();
|
| }
|
|
|
| +void LogoutButtonTray::ReleaseConfirmationDialog() {
|
| + confirmation_dialog_ = NULL;
|
| +}
|
| +
|
| +void LogoutButtonTray::SetDelegateForTest(
|
| + scoped_ptr<LogoutConfirmationDialogView::Delegate> delegate) {
|
| + confirmation_delegate_ = delegate.Pass();
|
| +}
|
| +
|
| void LogoutButtonTray::UpdateVisibility() {
|
| SetVisible(show_logout_button_in_tray_ &&
|
| login_status_ != user::LOGGED_IN_NONE &&
|
| login_status_ != user::LOGGED_IN_LOCKED);
|
| + if (!show_logout_button_in_tray_)
|
| + EnsureConfirmationDialogIsClosed();
|
| }
|
|
|
| } // namespace internal
|
|
|