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..2e2fce893f462ea1375d80212564dc3ed2cec21b 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,42 @@ 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_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_.reset(new LogoutConfirmationDialogView( |
+ this, confirmation_delegate_.get())); |
+ confirmation_dialog_->Show(dialog_duration_); |
+ } |
+} |
+ |
+void LogoutButtonTray::EnsureConfirmationDialogIsClosed() { |
+ if (confirmation_dialog_) |
+ confirmation_dialog_->DeleteDelegate(); |
} |
void LogoutButtonTray::SetShelfAlignment(ShelfAlignment alignment) { |
@@ -132,10 +157,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 +183,30 @@ void LogoutButtonTray::UpdateAfterLoginStatusChange( |
UpdateVisibility(); |
} |
+void LogoutButtonTray::DeleteConfirmationDialog() { |
+ confirmation_dialog_.release()->NullifyOwner(); |
+} |
+ |
+LogoutConfirmationDialogView* LogoutButtonTray::GetConfirmationDialogForTest() { |
+ return confirmation_dialog_.get(); |
+} |
+ |
+LogoutConfirmationDialogView::Delegate* |
+LogoutButtonTray::GetConfirmationDelegateForTest() { |
+ return confirmation_delegate_.get(); |
+} |
+ |
+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 |