Commit 7b3f91ee authored by bartfab@chromium.org's avatar bartfab@chromium.org

Add LogoutConfirmationController to show LogoutConfirmationDialogs

LogoutButtonTray uses and owns LogoutConfirmationDialogView, a dialog that
asks the user to confirm or deny logout. This CL generalizes the dialog
and moves its ownership to a LogoutConfirmationController accessible via
ash::Shell, allowing other classes to show the same dialog.

BUG=278247
TEST=Updated unit tests

Review URL: https://codereview.chromium.org/178183005

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@255316 0039d316-1c4b-4281-b951-d872f2087c98
parent 638fb18c
......@@ -370,14 +370,16 @@
'system/keyboard_brightness/keyboard_brightness_control_delegate.h',
'system/locale/locale_notification_controller.cc',
'system/locale/locale_notification_controller.h',
'system/logout_button/logout_button_observer.h',
'system/logout_button/logout_button_tray.cc',
'system/logout_button/logout_button_tray.h',
'system/logout_button/logout_confirmation_dialog_view.cc',
'system/logout_button/logout_confirmation_dialog_view.h',
'system/session_length_limit/session_length_limit_observer.h',
'system/session_length_limit/tray_session_length_limit.cc',
'system/session_length_limit/tray_session_length_limit.h',
'system/session/logout_button_observer.h',
'system/session/logout_button_tray.cc',
'system/session/logout_button_tray.h',
'system/session/logout_confirmation_controller.cc',
'system/session/logout_confirmation_controller.h',
'system/session/logout_confirmation_dialog.cc',
'system/session/logout_confirmation_dialog.h',
'system/session/session_length_limit_observer.h',
'system/session/tray_session_length_limit.cc',
'system/session/tray_session_length_limit.h',
'system/status_area_widget.cc',
'system/status_area_widget.h',
'system/status_area_widget_delegate.cc',
......@@ -927,8 +929,8 @@
'system/chromeos/screen_security/screen_tray_item_unittest.cc',
'system/chromeos/tray_display_unittest.cc',
'system/date/date_view_unittest.cc',
'system/logout_button/logout_button_tray_unittest.cc',
'system/session_length_limit/tray_session_length_limit_unittest.cc',
'system/session/logout_confirmation_controller_unittest.cc',
'system/session/tray_session_length_limit_unittest.cc',
'system/tray/system_tray_unittest.cc',
'system/tray/tray_details_view_unittest.cc',
'system/user/tray_user_unittest.cc',
......
......@@ -49,6 +49,7 @@
#include "ash/shell_factory.h"
#include "ash/shell_window_ids.h"
#include "ash/system/locale/locale_notification_controller.h"
#include "ash/system/session/logout_confirmation_controller.h"
#include "ash/system/status_area_widget.h"
#include "ash/system/tray/system_tray_delegate.h"
#include "ash/system/tray/system_tray_notifier.h"
......@@ -80,6 +81,7 @@
#include "ash/wm/window_util.h"
#include "ash/wm/workspace_controller.h"
#include "base/bind.h"
#include "base/bind_helpers.h"
#include "base/command_line.h"
#include "base/debug/trace_event.h"
#include "ui/aura/client/aura_constants.h"
......@@ -666,6 +668,9 @@ Shell::~Shell() {
// TODO(xiyuan): Move it back when app list container is no longer needed.
app_list_controller_.reset();
// Destroy the LogoutConfirmationController before the SystemTrayDelegate.
logout_confirmation_controller_.reset();
// Destroy SystemTrayDelegate before destroying the status area(s).
system_tray_delegate_->Shutdown();
system_tray_delegate_.reset();
......@@ -969,6 +974,12 @@ void Shell::Init() {
// Initialize system_tray_delegate_ after StatusAreaWidget is created.
system_tray_delegate_->Initialize();
// Create the LogoutConfirmationController after the SystemTrayDelegate.
logout_confirmation_controller_.reset(
new internal::LogoutConfirmationController(
base::Bind(&SystemTrayDelegate::SignOut,
base::Unretained(system_tray_delegate_.get()))));
// TODO(oshima): Initialize all RootWindowControllers once, and
// initialize controller/delegates above when initializing the
// primary root window controller.
......
......@@ -130,6 +130,7 @@ class EventTransformationHandler;
class FocusCycler;
class KeyboardUMAEventFilter;
class LocaleNotificationController;
class LogoutConfirmationController;
class MaximizeModeWindowManager;
class MouseCursorEventFilter;
class OutputConfiguratorAnimation;
......@@ -525,6 +526,10 @@ class ASH_EXPORT Shell
return window_tree_host_factory_.get();
}
internal::LogoutConfirmationController* logout_confirmation_controller() {
return logout_confirmation_controller_.get();
}
ShelfModel* shelf_model() {
return shelf_model_.get();
}
......@@ -670,6 +675,8 @@ class ASH_EXPORT Shell
scoped_ptr<internal::EventTransformationHandler>
event_transformation_handler_;
scoped_ptr<WindowTreeHostFactory> window_tree_host_factory_;
scoped_ptr<internal::LogoutConfirmationController>
logout_confirmation_controller_;
// An event filter that pre-handles key events while the partial
// screenshot UI or the keyboard overlay is active.
......
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef ASH_SYSTEM_LOGOUT_BUTTON_LOGOUT_BUTTON_OBSERVER_H_
#define ASH_SYSTEM_LOGOUT_BUTTON_LOGOUT_BUTTON_OBSERVER_H_
#ifndef ASH_SYSTEM_SESSION_LOGOUT_BUTTON_OBSERVER_H_
#define ASH_SYSTEM_SESSION_LOGOUT_BUTTON_OBSERVER_H_
#include "ash/ash_export.h"
#include "base/time/time.h"
......@@ -27,4 +27,4 @@ class ASH_EXPORT LogoutButtonObserver {
} // namespace ash
#endif // ASH_SYSTEM_LOGOUT_BUTTON_LOGOUT_BUTTON_OBSERVER_H_
#endif // ASH_SYSTEM_SESSION_LOGOUT_BUTTON_OBSERVER_H_
// Copyright 2013 The Chromium Authors. All rights reserved.
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ash/system/logout_button/logout_button_tray.h"
#include "ash/system/session/logout_button_tray.h"
#include "ash/shelf/shelf_types.h"
#include "ash/shell.h"
#include "ash/system/session/logout_confirmation_controller.h"
#include "ash/system/status_area_widget.h"
#include "ash/system/tray/system_tray_delegate.h"
#include "ash/system/tray/system_tray_notifier.h"
#include "ash/system/tray/tray_constants.h"
#include "ash/system/tray/tray_utils.h"
#include "base/logging.h"
#include "base/memory/scoped_ptr.h"
#include "grit/ash_resources.h"
#include "third_party/skia/include/core/SkColor.h"
#include "ui/events/event.h"
......@@ -62,21 +64,6 @@ class LogoutButton : public views::LabelButton {
DISALLOW_COPY_AND_ASSIGN(LogoutButton);
};
class LogoutConfirmationDialogDelegate
: public LogoutConfirmationDialogView::Delegate {
public:
LogoutConfirmationDialogDelegate() {}
virtual ~LogoutConfirmationDialogDelegate() {}
virtual void LogoutCurrentUser() OVERRIDE;
virtual base::TimeTicks GetCurrentTime() const OVERRIDE;
virtual void ShowDialog(views::DialogDelegate* dialog) OVERRIDE;
private:
DISALLOW_COPY_AND_ASSIGN(LogoutConfirmationDialogDelegate);
};
} // namespace
LogoutButton::LogoutButton(views::ButtonListener* listener)
......@@ -107,62 +94,20 @@ LogoutButton::LogoutButton(views::ButtonListener* listener)
LogoutButton::~LogoutButton() {
}
void LogoutConfirmationDialogDelegate::LogoutCurrentUser() {
Shell::GetInstance()->system_tray_delegate()->SignOut();
}
base::TimeTicks LogoutConfirmationDialogDelegate::GetCurrentTime() const {
return base::TimeTicks::Now();
}
void LogoutConfirmationDialogDelegate::ShowDialog(
views::DialogDelegate *dialog) {
views::DialogDelegate::CreateDialogWidget(
dialog, ash::Shell::GetPrimaryRootWindow(), NULL);
dialog->GetWidget()->Show();
}
LogoutButtonTray::LogoutButtonTray(StatusAreaWidget* status_area_widget)
: TrayBackgroundView(status_area_widget),
button_(NULL),
login_status_(user::LOGGED_IN_NONE),
show_logout_button_in_tray_(false),
confirmation_dialog_(NULL),
confirmation_delegate_(new LogoutConfirmationDialogDelegate) {
show_logout_button_in_tray_(false) {
button_ = new LogoutButton(this);
tray_container()->AddChildView(button_);
tray_container()->SetBorder(views::Border::NullBorder());
// The Shell may not exist in some unit tests.
if (Shell::HasInstance()) {
Shell::GetInstance()->system_tray_notifier()->
AddLogoutButtonObserver(this);
}
Shell::GetInstance()->system_tray_notifier()->AddLogoutButtonObserver(this);
}
LogoutButtonTray::~LogoutButtonTray() {
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_ != NULL;
}
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();
Shell::GetInstance()->system_tray_notifier()->
RemoveLogoutButtonObserver(this);
}
void LogoutButtonTray::SetShelfAlignment(ShelfAlignment alignment) {
......@@ -189,18 +134,18 @@ void LogoutButtonTray::OnShowLogoutButtonInTrayChanged(bool show) {
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_);
// Sign out immediately if |dialog_duration_| is non-positive.
if (dialog_duration_ <= base::TimeDelta())
confirmation_delegate_->LogoutCurrentUser();
else
EnsureConfirmationDialogIsShowing();
if (dialog_duration_ <= base::TimeDelta()) {
// Sign out immediately if |dialog_duration_| is non-positive.
Shell::GetInstance()->system_tray_delegate()->SignOut();
} else if (Shell::GetInstance()->logout_confirmation_controller()) {
Shell::GetInstance()->logout_confirmation_controller()->ConfirmLogout(
base::TimeTicks::Now() + dialog_duration_);
}
}
void LogoutButtonTray::UpdateAfterLoginStatusChange(
......@@ -213,21 +158,10 @@ 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
......
// Copyright 2013 The Chromium Authors. All rights reserved.
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef ASH_SYSTEM_LOGOUT_BUTTON_LOGOUT_BUTTON_TRAY_H_
#define ASH_SYSTEM_LOGOUT_BUTTON_LOGOUT_BUTTON_TRAY_H_
#ifndef ASH_SYSTEM_SESSION_LOGOUT_BUTTON_TRAY_H_
#define ASH_SYSTEM_SESSION_LOGOUT_BUTTON_TRAY_H_
#include "ash/ash_export.h"
#include "ash/system/logout_button/logout_button_observer.h"
#include "ash/system/logout_button/logout_confirmation_dialog_view.h"
#include "ash/system/session/logout_button_observer.h"
#include "ash/system/tray/tray_background_view.h"
#include "ash/system/user/login_status.h"
#include "base/basictypes.h"
#include "base/compiler_specific.h"
#include "base/memory/scoped_ptr.h"
#include "base/time/time.h"
#include "ui/views/controls/button/button.h"
......@@ -51,35 +49,18 @@ class ASH_EXPORT LogoutButtonTray : public TrayBackgroundView,
void UpdateAfterLoginStatusChange(user::LoginStatus login_status);
// Nullify the pointer to confirmation dialog, this is expected to be called
// when the confirmation dialog is going to be destroyed.
// Note: the confirmation dialog is not owned by LogoutButtonTray.
void ReleaseConfirmationDialog();
void SetDelegateForTest(
scoped_ptr<LogoutConfirmationDialogView::Delegate> delegate);
private:
friend class LogoutConfirmationDialogTest;
bool IsConfirmationDialogShowing() const;
void EnsureConfirmationDialogIsShowing();
void EnsureConfirmationDialogIsClosed();
void UpdateVisibility();
views::LabelButton* button_; // Not owned.
views::LabelButton* button_;
user::LoginStatus login_status_;
bool show_logout_button_in_tray_;
base::TimeDelta dialog_duration_;
LogoutConfirmationDialogView* confirmation_dialog_; // Not owned.
scoped_ptr<LogoutConfirmationDialogView::Delegate> confirmation_delegate_;
DISALLOW_COPY_AND_ASSIGN(LogoutButtonTray);
};
} // namespace internal
} // namespace ash
#endif // ASH_SYSTEM_LOGOUT_BUTTON_LOGOUT_BUTTON_TRAY_H_
#endif // ASH_SYSTEM_SESSION_LOGOUT_BUTTON_TRAY_H_
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ash/system/session/logout_confirmation_controller.h"
#include "ash/session_state_delegate.h"
#include "ash/shell.h"
#include "ash/system/session/logout_confirmation_dialog.h"
#include "base/location.h"
#include "base/time/default_tick_clock.h"
#include "base/time/tick_clock.h"
#include "ui/views/widget/widget.h"
namespace ash {
namespace internal {
LogoutConfirmationController::LogoutConfirmationController(
const base::Closure& logout_closure)
: clock_(new base::DefaultTickClock),
logout_closure_(logout_closure),
dialog_(NULL),
logout_timer_(false, false) {
if (Shell::HasInstance())
Shell::GetInstance()->AddShellObserver(this);
}
LogoutConfirmationController::~LogoutConfirmationController() {
if (Shell::HasInstance())
Shell::GetInstance()->RemoveShellObserver(this);
if (dialog_)
dialog_->GetWidget()->Close();
}
void LogoutConfirmationController::ConfirmLogout(
base::TimeTicks logout_time) {
if (!logout_time_.is_null() && logout_time >= logout_time_) {
// If a confirmation dialog is already being shown and its countdown expires
// no later than the |logout_time| requested now, keep the current dialog
// open.
return;
}
logout_time_ = logout_time;
if (!dialog_) {
// Show confirmation dialog unless this is a unit test without a Shell.
if (Shell::HasInstance())
dialog_ = new LogoutConfirmationDialog(this, logout_time_);
} else {
dialog_->Update(logout_time_);
}
logout_timer_.Start(FROM_HERE,
logout_time_ - clock_->NowTicks(),
logout_closure_);
}
void LogoutConfirmationController::SetClockForTesting(
scoped_ptr<base::TickClock> clock) {
clock_ = clock.Pass();
}
void LogoutConfirmationController::OnLockStateChanged(bool locked) {
if (!locked || logout_time_.is_null())
return;
// If the screen is locked while a confirmation dialog is being shown, close
// the dialog.
logout_time_ = base::TimeTicks();
if (dialog_)
dialog_->GetWidget()->Close();
logout_timer_.Stop();
}
void LogoutConfirmationController::OnLogoutConfirmed() {
logout_timer_.Stop();
logout_closure_.Run();
}
void LogoutConfirmationController::OnDialogClosed() {
logout_time_ = base::TimeTicks();
dialog_ = NULL;
logout_timer_.Stop();
}
} // namespace internal
} // namespace ash
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef ASH_SYSTEM_SESSION_LOGOUT_CONFIRMATION_CONTROLLER_H_
#define ASH_SYSTEM_SESSION_LOGOUT_CONFIRMATION_CONTROLLER_H_
#include "ash/ash_export.h"
#include "ash/shell_observer.h"
#include "base/basictypes.h"
#include "base/callback.h"
#include "base/memory/scoped_ptr.h"
#include "base/time/time.h"
#include "base/timer/timer.h"
namespace base {
class TickClock;
}
namespace ash {
namespace internal {
class LogoutConfirmationDialog;
// This class shows a dialog asking the user to confirm or deny logout and
// terminates the session if the user either confirms or allows the countdown
// shown in the dialog to expire.
// It is guaranteed that no more than one confirmation dialog will be visible at
// any given time. If there are multiple requests to show a confirmation dialog
// at the same time, the dialog whose countdown expires first is shown.
class ASH_EXPORT LogoutConfirmationController : public ShellObserver {
public:
// The |logout_closure| must be safe to call as long as |this| is alive.
explicit LogoutConfirmationController(const base::Closure& logout_closure);
virtual ~LogoutConfirmationController();
base::TickClock* clock() const { return clock_.get(); }
// Shows a LogoutConfirmationDialog. If a confirmation dialog is already being
// shown, it is closed and a new one opened if |logout_time| is earlier than
// the current dialog's |logout_time_|.
void ConfirmLogout(base::TimeTicks logout_time);
void SetClockForTesting(scoped_ptr<base::TickClock> clock);
// ShellObserver:
virtual void OnLockStateChanged(bool locked) OVERRIDE;
// Called by the |dialog_| when the user confirms logout.
void OnLogoutConfirmed();
// Called by the |dialog_| when it is closed.
void OnDialogClosed();
private:
scoped_ptr<base::TickClock> clock_;
base::Closure logout_closure_;
base::TimeTicks logout_time_;
LogoutConfirmationDialog* dialog_; // Owned by the Views hierarchy.
base::Timer logout_timer_;
DISALLOW_COPY_AND_ASSIGN(LogoutConfirmationController);
};
} // namespace internal
} // namespace ash
#endif // ASH_SYSTEM_SESSION_LOGOUT_CONFIRMATION_CONTROLLER_H_
......@@ -2,15 +2,14 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ash/system/logout_button/logout_confirmation_dialog_view.h"
#include "ash/system/session/logout_confirmation_dialog.h"
#include "ash/shell.h"
#include "ash/system/logout_button/logout_button_tray.h"
#include "ash/system/tray/system_tray_delegate.h"
#include "ash/system/session/logout_confirmation_controller.h"
#include "ash/system/tray/tray_constants.h"
#include "base/location.h"
#include "base/time/tick_clock.h"
#include "grit/ash_strings.h"
#include "ui/aura/window_event_dispatcher.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/l10n/time_format.h"
#include "ui/base/ui_base_types.h"
......@@ -27,104 +26,89 @@ namespace {
const int kCountdownUpdateIntervalMs = 1000; // 1 second.
const int kHalfSecondInMs = 500; // Half a second.
} // namespace
LogoutConfirmationDialogView::LogoutConfirmationDialogView(
LogoutButtonTray* owner, Delegate* delegate) : owner_(owner),
delegate_(delegate) {
text_label_ = new views::Label;
text_label_->SetBorder(views::Border::CreateEmptyBorder(
LogoutConfirmationDialog::LogoutConfirmationDialog(
LogoutConfirmationController* controller,
base::TimeTicks logout_time)
: controller_(controller),
logout_time_(logout_time) {
SetLayoutManager(new views::FillLayout());
label_ = new views::Label;
label_->SetBorder(views::Border::CreateEmptyBorder(
0, kTrayPopupPaddingHorizontal, 0, kTrayPopupPaddingHorizontal));
text_label_->SetHorizontalAlignment(gfx::ALIGN_LEFT);
text_label_->SetMultiLine(true);
label_->SetHorizontalAlignment(gfx::ALIGN_LEFT);
label_->SetMultiLine(true);
AddChildView(label_);
SetLayoutManager(new views::FillLayout());
UpdateLabel();
AddChildView(text_label_);
CreateDialogWidget(this, ash::Shell::GetPrimaryRootWindow(), NULL);
GetWidget()->Show();
update_timer_.Start(
FROM_HERE,
base::TimeDelta::FromMilliseconds(kCountdownUpdateIntervalMs),
this,
&LogoutConfirmationDialog::UpdateLabel);
}
LogoutConfirmationDialog::~LogoutConfirmationDialog() {
}
LogoutConfirmationDialogView::~LogoutConfirmationDialogView() {
void LogoutConfirmationDialog::Update(base::TimeTicks logout_time) {
logout_time_ = logout_time;
UpdateLabel();
}
bool LogoutConfirmationDialogView::Accept() {
LogoutCurrentUser();
bool LogoutConfirmationDialog::Accept() {
logout_time_ = controller_->clock()->NowTicks();
UpdateLabel();
controller_->OnLogoutConfirmed();
return true;
}
ui::ModalType LogoutConfirmationDialogView::GetModalType() const {
ui::ModalType LogoutConfirmationDialog::GetModalType() const {
return ui::MODAL_TYPE_SYSTEM;
}
base::string16 LogoutConfirmationDialogView::GetWindowTitle() const {
base::string16 LogoutConfirmationDialog::GetWindowTitle() const {
return l10n_util::GetStringUTF16(IDS_ASH_LOGOUT_CONFIRMATION_TITLE);
}
base::string16 LogoutConfirmationDialogView::GetDialogButtonLabel(
base::string16 LogoutConfirmationDialog::GetDialogButtonLabel(
ui::DialogButton button) const {
if (button == ui::DIALOG_BUTTON_OK)
return l10n_util::GetStringUTF16(IDS_ASH_LOGOUT_CONFIRMATION_BUTTON);
return views::DialogDelegateView::GetDialogButtonLabel(button);
}
void LogoutConfirmationDialogView::OnClosed() {
owner_->ReleaseConfirmationDialog();
owner_ = NULL;
timer_.Stop();
// Nullify the delegate to prevent future activities of the dialog.
delegate_ = NULL;
void LogoutConfirmationDialog::OnClosed() {
update_timer_.Stop();
controller_->OnDialogClosed();
}
void LogoutConfirmationDialogView::DeleteDelegate() {
if (owner_)
owner_->ReleaseConfirmationDialog();
void LogoutConfirmationDialog::DeleteDelegate() {
delete this;
}
void LogoutConfirmationDialogView::Show(base::TimeDelta duration) {
if (!delegate_)
return;
countdown_start_time_ = delegate_->GetCurrentTime();
duration_ = duration;
UpdateCountdown();
delegate_->ShowDialog(this);
timer_.Start(FROM_HERE,
base::TimeDelta::FromMilliseconds(kCountdownUpdateIntervalMs),
this,
&LogoutConfirmationDialogView::UpdateCountdown);
}
void LogoutConfirmationDialogView::UpdateDialogDuration(
base::TimeDelta duration) {
duration_ = duration;
UpdateCountdown();
}
void LogoutConfirmationDialogView::LogoutCurrentUser() {
if (!delegate_)
return;
delegate_->LogoutCurrentUser();
}
void LogoutConfirmationDialogView::UpdateCountdown() {
if (!delegate_)
return;
const base::TimeDelta time_remaining = countdown_start_time_ +
duration_ - delegate_->GetCurrentTime();
if (time_remaining > base::TimeDelta::FromSeconds(0)) {
text_label_->SetText(l10n_util::GetStringFUTF16(
void LogoutConfirmationDialog::UpdateLabel() {
const base::TimeDelta time_remaining =
logout_time_ - controller_->clock()->NowTicks();
if (time_remaining >= base::TimeDelta::FromMilliseconds(kHalfSecondInMs)) {
label_->SetText(l10n_util::GetStringFUTF16(
IDS_ASH_LOGOUT_CONFIRMATION_WARNING,
ui::TimeFormat::Detailed(ui::TimeFormat::FORMAT_DURATION,
ui::TimeFormat::LENGTH_LONG,
10,
time_remaining)));
} else {
text_label_->SetText(l10n_util::GetStringUTF16(
label_->SetText(l10n_util::GetStringUTF16(
IDS_ASH_LOGOUT_CONFIRMATION_WARNING_NOW));
timer_.Stop();
LogoutCurrentUser();
update_timer_.Stop();
}
}
......
......@@ -2,10 +2,9 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef ASH_SYSTEM_LOGOUT_BUTTON_LOGOUT_CONFIRMATION_DIALOG_VIEW_H_
#define ASH_SYSTEM_LOGOUT_BUTTON_LOGOUT_CONFIRMATION_DIALOG_VIEW_H_
#ifndef ASH_SYSTEM_SESSION_LOGOUT_CONFIRMATION_DIALOG_H_
#define ASH_SYSTEM_SESSION_LOGOUT_CONFIRMATION_DIALOG_H_
#include "ash/ash_export.h"
#include "base/basictypes.h"
#include "base/compiler_specific.h"
#include "base/time/time.h"
......@@ -19,59 +18,42 @@ class Label;
namespace ash {
namespace internal {
class LogoutButtonTray;
class LogoutConfirmationController;
// This class implements dialog view for logout confirmation.
class ASH_EXPORT LogoutConfirmationDialogView
: public views::DialogDelegateView {
// A dialog that asks the user to confirm or deny logout. The dialog shows a
// countdown and informs the user that a logout will happen automatically if no
// choice is made before the countdown has expired.
class LogoutConfirmationDialog : public views::DialogDelegateView {
public:
class ASH_EXPORT Delegate {
public:
virtual ~Delegate() {}
LogoutConfirmationDialog(LogoutConfirmationController* controller,
base::TimeTicks logout_time);
virtual ~LogoutConfirmationDialog();
virtual void LogoutCurrentUser() = 0;
virtual base::TimeTicks GetCurrentTime() const = 0;
virtual void ShowDialog(views::DialogDelegate* dialog) = 0;
};
LogoutConfirmationDialogView(LogoutButtonTray* owner, Delegate* delegate);
virtual ~LogoutConfirmationDialogView();
void Update(base::TimeTicks logout_time);
// views::DialogDelegateView:
virtual bool Accept() OVERRIDE;
virtual ui::ModalType GetModalType() const OVERRIDE;
virtual base::string16 GetWindowTitle() const OVERRIDE;
virtual base::string16
GetDialogButtonLabel(ui::DialogButton button) const OVERRIDE;
virtual base::string16 GetDialogButtonLabel(ui::DialogButton button) const
OVERRIDE;
virtual void OnClosed() OVERRIDE;
virtual void DeleteDelegate() OVERRIDE;
void Show(base::TimeDelta duration);
// The duration of the confirmation dialog can be changed while the dialog
// is still showing. This method is only expected to be called when the
// preference for confirmation dialog duration has changed.
void UpdateDialogDuration(base::TimeDelta duration);
private:
void LogoutCurrentUser();
void UpdateCountdown();
views::Label* text_label_;
base::TimeTicks countdown_start_time_;
base::TimeDelta duration_;
void UpdateLabel();
base::RepeatingTimer<LogoutConfirmationDialogView> timer_;
LogoutConfirmationController* controller_;
base::TimeTicks logout_time_;
LogoutButtonTray* owner_;
views::Label* label_;
Delegate* delegate_;
base::RepeatingTimer<LogoutConfirmationDialog> update_timer_;
DISALLOW_COPY_AND_ASSIGN(LogoutConfirmationDialogView);
DISALLOW_COPY_AND_ASSIGN(LogoutConfirmationDialog);
};
} // namespace internal
} // namespace ash
#endif // ASH_SYSTEM_LOGOUT_BUTTON_LOGOUT_CONFIRMATION_DIALOG_VIEW_H_
#endif // ASH_SYSTEM_SESSION_LOGOUT_CONFIRMATION_DIALOG_H_
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef ASH_SYSTEM_SESSION_LENGTH_LIMIT_SESSION_LENGTH_LIMIT_OBSERVER_H_
#define ASH_SYSTEM_SESSION_LENGTH_LIMIT_SESSION_LENGTH_LIMIT_OBSERVER_H_
#ifndef ASH_SYSTEM_SESSION_SESSION_LENGTH_LIMIT_OBSERVER_H_
#define ASH_SYSTEM_SESSION_SESSION_LENGTH_LIMIT_OBSERVER_H_
#include "ash/ash_export.h"
......@@ -23,4 +23,4 @@ class ASH_EXPORT SessionLengthLimitObserver {
} // namespace ash
#endif // ASH_SYSTEM_SESSION_LENGTH_LIMIT_SESSION_LENGTH_LIMIT_OBSERVER_H_
#endif // ASH_SYSTEM_SESSION_SESSION_LENGTH_LIMIT_OBSERVER_H_
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ash/system/session_length_limit/tray_session_length_limit.h"
#include "ash/system/session/tray_session_length_limit.h"
#include <algorithm>
......
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef ASH_SYSTEM_SESSION_LENGTH_LIMIT_TRAY_SESSION_LENGTH_LIMIT_H_
#define ASH_SYSTEM_SESSION_LENGTH_LIMIT_TRAY_SESSION_LENGTH_LIMIT_H_
#ifndef ASH_SYSTEM_SESSION_SESSION_LENGTH_LIMIT_H_
#define ASH_SYSTEM_SESSION_SESSION_LENGTH_LIMIT_H_
#include "ash/system/session_length_limit/session_length_limit_observer.h"
#include "ash/system/session/session_length_limit_observer.h"
#include "ash/system/tray/system_tray_item.h"
#include "base/basictypes.h"
#include "base/compiler_specific.h"
......@@ -74,4 +74,4 @@ class ASH_EXPORT TraySessionLengthLimit : public SystemTrayItem,
} // namespace internal
} // namespace ash
#endif // ASH_SYSTEM_SESSION_LENGTH_LIMIT_TRAY_SESSION_LENGTH_LIMIT_H_
#endif // ASH_SYSTEM_SESSION_TRAY_SESSION_LENGTH_LIMIT_H_
// Copyright 2013 The Chromium Authors. All rights reserved.
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ash/system/session_length_limit/tray_session_length_limit.h"
#include "ash/system/session/tray_session_length_limit.h"
#include "ash/root_window_controller.h"
#include "ash/shell.h"
......
......@@ -11,7 +11,7 @@
#include "ash/shell_delegate.h"
#include "ash/shell_window_ids.h"
#include "ash/system/bluetooth/bluetooth_observer.h"
#include "ash/system/logout_button/logout_button_tray.h"
#include "ash/system/session/logout_button_tray.h"
#include "ash/system/status_area_widget_delegate.h"
#include "ash/system/tray/system_tray.h"
#include "ash/system/tray/system_tray_delegate.h"
......
......@@ -15,7 +15,7 @@
#include "ash/system/date/tray_date.h"
#include "ash/system/drive/tray_drive.h"
#include "ash/system/ime/tray_ime.h"
#include "ash/system/session_length_limit/tray_session_length_limit.h"
#include "ash/system/session/tray_session_length_limit.h"
#include "ash/system/status_area_widget.h"
#include "ash/system/tray/system_tray_delegate.h"
#include "ash/system/tray/system_tray_item.h"
......
......@@ -16,8 +16,8 @@
#include "ash/system/drive/drive_observer.h"
#include "ash/system/ime/ime_observer.h"
#include "ash/system/locale/locale_observer.h"
#include "ash/system/logout_button/logout_button_observer.h"
#include "ash/system/session_length_limit/session_length_limit_observer.h"
#include "ash/system/session/logout_button_observer.h"
#include "ash/system/session/session_length_limit_observer.h"
#include "ash/system/tray_accessibility.h"
#include "ash/system/tray_caps_lock.h"
#include "ash/system/user/update_observer.h"
......
......@@ -23,7 +23,7 @@
#include "ash/system/date/clock_observer.h"
#include "ash/system/drive/drive_observer.h"
#include "ash/system/ime/ime_observer.h"
#include "ash/system/logout_button/logout_button_observer.h"
#include "ash/system/session/logout_button_observer.h"
#include "ash/system/tray/system_tray.h"
#include "ash/system/tray/system_tray_delegate.h"
#include "ash/system/tray/system_tray_notifier.h"
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment