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

Unified Diff: ash/system/logout_button/logout_button_tray.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: enhence tests; simplify code; fix win build(hope so) 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 side-by-side diff with in-line comments
Download patch
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..d4a1994e9490e1f0fd0b98ddfd3d3b06c9a254ee 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 {
@@ -94,20 +93,47 @@ LogoutButton::LogoutButton(views::ButtonListener* listener)
LogoutButton::~LogoutButton() {
}
-LogoutButtonTray::LogoutButtonTray(StatusAreaWidget* status_area_widget)
+LogoutButtonTray::LogoutButtonTray(StatusAreaWidget* status_area_widget,
bartfab (slow) 2013/12/10 12:41:16 Nit: Indentation: All arguments must be aligned.
binjin 2013/12/12 13:56:55 Done.
+ LogoutConfirmationDialogView::LogoutConfirmationDelegate* delegate)
: TrayBackgroundView(status_area_widget),
- button_(NULL),
bartfab (slow) 2013/12/10 12:41:16 Nit: Do not remove this. You will be setting |butt
binjin 2013/12/12 13:56:55 Done.
login_status_(user::LOGGED_IN_NONE),
- show_logout_button_in_tray_(false) {
+ show_logout_button_in_tray_(false),
+ weak_factory_(this) {
+ if (!delegate) {
+ confirmation_delegate_.reset(
+ new LogoutConfirmationDialogView::LogoutConfirmationDelegate());
bartfab (slow) 2013/12/10 12:41:16 Nit: No need for ().
binjin 2013/12/12 13:56:55 Done.
+ } else
bartfab (slow) 2013/12/10 12:41:16 Nit 1: Style guide: If the if part has curly brace
binjin 2013/12/12 13:56:55 Done.
+ confirmation_delegate_.reset(delegate);
button_ = new LogoutButton(this);
tray_container()->AddChildView(button_);
tray_container()->set_border(NULL);
- Shell::GetInstance()->system_tray_notifier()->AddLogoutButtonObserver(this);
+ // For testing purpose.
bartfab (slow) 2013/12/10 12:41:16 Nit: "For testing purpose" is slightly misleading.
binjin 2013/12/12 13:56:55 Done.
+ if (Shell::HasInstance())
+ Shell::GetInstance()->system_tray_notifier()->AddLogoutButtonObserver(this);
}
LogoutButtonTray::~LogoutButtonTray() {
- Shell::GetInstance()->system_tray_notifier()->
- RemoveLogoutButtonObserver(this);
+ EnsureConfirmationDialogIsClosed();
+ if (Shell::HasInstance())
bartfab (slow) 2013/12/10 12:41:16 Nit: Style guide: Multi-line conditionals require
binjin 2013/12/12 13:56:55 Done.
+ Shell::GetInstance()->system_tray_notifier()->
+ RemoveLogoutButtonObserver(this);
+}
+
+void LogoutButtonTray::EnsureConfirmationDialogIsShowing() {
+ if (!confirmation_dialog_) {
+ confirmation_dialog_.reset(new LogoutConfirmationDialogView(
+ weak_factory_.GetWeakPtr(), confirmation_delegate_.get()));
+ confirmation_dialog_->Show(dialog_duration_);
+ }
+}
+
+void LogoutButtonTray::EnsureConfirmationDialogIsClosed() {
+ if (confirmation_dialog_ && Shell::HasInstance())
+ confirmation_dialog_->GetWidget()->Close();
bartfab (slow) 2013/12/10 12:41:16 1) After this method has run, the dialog is closed
binjin 2013/12/12 13:56:55 Done.
+}
+
+bool LogoutButtonTray::IsConfirmationDialogShowing() {
+ return confirmation_dialog_;
}
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 kLogoutDialogDurationMs is non-positive.
bartfab (slow) 2013/12/10 12:41:16 Nit: Do not refer to the pref name here. Ash knows
binjin 2013/12/12 13:56:55 Done.
+ if (dialog_duration_ <= base::TimeDelta::FromSeconds(0))
bartfab (slow) 2013/12/10 12:41:16 Nit: The default constructor base::TimeDelta() pro
binjin 2013/12/12 13:56:55 Done.
+ confirmation_delegate_->LogoutCurrentUser();
+ else
+ EnsureConfirmationDialogIsShowing();
}
void LogoutButtonTray::UpdateAfterLoginStatusChange(
@@ -148,10 +184,25 @@ void LogoutButtonTray::UpdateAfterLoginStatusChange(
UpdateVisibility();
}
+void LogoutButtonTray::DeleteConfirmationDialog() {
+ confirmation_dialog_.reset();
+}
+
+LogoutConfirmationDialogView *LogoutButtonTray::GetConfirmationDialogForTest() {
bartfab (slow) 2013/12/10 12:41:16 Nit: Style guide: The * goes on the type.
binjin 2013/12/12 13:56:55 Done.
+ return confirmation_dialog_.get();
+}
+
+LogoutConfirmationDialogView::LogoutConfirmationDelegate*
+LogoutButtonTray::GetConfirmationDelegateForTest() {
+ return confirmation_delegate_.get();
+}
+
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

Powered by Google App Engine
This is Rietveld 408576698