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

Unified Diff: chrome/browser/chromeos/ui/idle_logout_dialog.cc

Issue 9665031: Change the idle logout dialog over to use views. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Review comments. Created 8 years, 9 months 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: chrome/browser/chromeos/ui/idle_logout_dialog.cc
diff --git a/chrome/browser/chromeos/ui/idle_logout_dialog.cc b/chrome/browser/chromeos/ui/idle_logout_dialog.cc
new file mode 100644
index 0000000000000000000000000000000000000000..f87bc6478fd8607c9d62b75f542264a252bdf33e
--- /dev/null
+++ b/chrome/browser/chromeos/ui/idle_logout_dialog.cc
@@ -0,0 +1,198 @@
+// Copyright (c) 2012 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 "chrome/browser/chromeos/ui/idle_logout_dialog.h"
+
+#include "base/bind.h"
+#include "base/bind_helpers.h"
+#include "base/time.h"
+#include "base/timer.h"
+#include "base/string_number_conversions.h"
+#include "chrome/browser/chromeos/kiosk_mode/kiosk_mode_helper.h"
+#include "chrome/browser/ui/browser_list.h"
+#include "chrome/common/logging_chrome.h"
+#include "grit/browser_resources.h"
+#include "grit/generated_resources.h"
+#include "ui/base/l10n/l10n_util.h"
+#include "ui/base/resource/resource_bundle.h"
+#include "ui/views/layout/grid_layout.h"
+#include "ui/views/layout/layout_constants.h"
+#include "ui/views/widget/widget.h"
+
+#if defined(USE_AURA)
+#include "ash/shell.h"
+#include "ui/aura/root_window.h"
+#endif
+
+using views::GridLayout;
+
+namespace {
+
+// Global singleton instance of our dialog class.
+IdleLogoutDialog* g_instance = NULL;
+// Height/Width of the logout dialog.
+const int kIdleLogoutDialogWidth = 400;
+const int kIdleLogoutDialogHeight = 100;
+
+const int kCountdownUpdateInterval = 1; // second.
+
+} // namespace
+
+////////////////////////////////////////////////////////////////////////////////
+// IdleLogoutDialog public static methods
+
+void IdleLogoutDialog::ShowIdleLogoutDialog() {
+ if (!g_instance)
+ g_instance = new IdleLogoutDialog();
+ g_instance->Show();
+}
+
+void IdleLogoutDialog::CloseIdleLogoutDialog() {
+ if (g_instance) {
+ g_instance->set_closed();
+ g_instance->Close();
+ g_instance = NULL;
+ }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// Overridden from views::DialogDelegateView
+int IdleLogoutDialog::GetDialogButtons() const {
+ return ui::DIALOG_BUTTON_NONE;
+}
+
+ui::ModalType IdleLogoutDialog::GetModalType() const {
+ return ui::MODAL_TYPE_WINDOW;
+}
+
+string16 IdleLogoutDialog::GetWindowTitle() const {
+ return l10n_util::GetStringUTF16(IDS_IDLE_LOGOUT_TITLE);
+}
+
+views::View* IdleLogoutDialog::GetContentsView() {
+ return this;
+}
+
+void IdleLogoutDialog::DeleteDelegate() {
+ // There isn't a delegate method that is called on close and is 'not' called
+ // async; this can cause an issue with us setting the g_instance to NULL
+ // 'after' another Show call has been called on it. So instead, we rely on
+ // CloseIdleLogoutDialog to set g_instance to NULL; in the case that we get
+ // closed by any other way than CloseIdleLogoutDialog, we check if our
+ // 'closed' state is set - if not, then we set it and set g_instance to null,
+ // since that means that CloseIdleLogoutDialog was never called.
+ if (!this->is_closed()) {
+ g_instance->set_closed();
+ g_instance = NULL;
+ }
+ delete this;
+}
+
+
+////////////////////////////////////////////////////////////////////////////////
+// Overridden from views::View
+void IdleLogoutDialog::Layout() {
+ GetLayoutManager()->Layout(this);
+}
+
+gfx::Size IdleLogoutDialog::GetPreferredSize() {
+ return gfx::Size(kIdleLogoutDialogWidth, kIdleLogoutDialogHeight);
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// IdleLogoutDialog private methods
+IdleLogoutDialog::IdleLogoutDialog() : restart_label_(NULL),
sky 2012/03/12 23:33:38 nit: wrap to next line and indent 4.
rkc 2012/03/12 23:57:51 Done.
+ warning_label_(NULL) {
+ instance_holder_ = new IdleLogoutDialog*(this);
+ Init();
+}
+
+// Calls init if the instance it was called from has not been closed yet.
+void CallInit(IdleLogoutDialog** instance_holder) {
+ if (*instance_holder)
sky 2012/03/12 23:33:38 Is instance_holder_ leaked?
rkc 2012/03/12 23:57:51 Was, fixed.
+ (*instance_holder)->Init();
+}
+
+void IdleLogoutDialog::Init() {
+ if (!chromeos::KioskModeHelper::Get()->is_initialized()) {
+ chromeos::KioskModeHelper::Get()->Initialize(
+ base::Bind(&CallInit, instance_holder_));
+ return;
+ }
+
+ ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
+
+ warning_label_ = new views::Label(
+ l10n_util::GetStringUTF16(IDS_IDLE_LOGOUT_WARNING));
+ warning_label_->SetHorizontalAlignment(views::Label::ALIGN_LEFT);
+ warning_label_->SetMultiLine(true);
+ warning_label_->SetFont(rb.GetFont(ui::ResourceBundle::BaseFont));
+
+ restart_label_ = new views::Label();
+ restart_label_->SetHorizontalAlignment(views::Label::ALIGN_LEFT);
+ restart_label_->SetFont(rb.GetFont(ui::ResourceBundle::BoldFont));
+
+ views::GridLayout* layout = views::GridLayout::CreatePanel(this);
+ SetLayoutManager(layout);
+
+ views::ColumnSet* column_set = layout->AddColumnSet(0);
+ column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::CENTER, 1,
+ views::GridLayout::USE_PREF, 0, 0);
+ layout->StartRow(0, 0);
+ layout->AddView(warning_label_);
+ layout->AddPaddingRow(0, views::kUnrelatedControlVerticalSpacing);
+ layout->StartRow(0, 0);
+ layout->AddView(restart_label_);
+}
+
+void IdleLogoutDialog::Show() {
+ // Setup the countdown label before showing.
+ countdown_end_time_ = base::Time::Now() + base::TimeDelta::FromSeconds(
+ chromeos::KioskModeHelper::Get()->GetIdleLogoutWarningTimeout());
+ UpdateCountdownTimer();
+
+#if defined(USE_AURA)
+ aura::RootWindow* root_window = ash::Shell::GetRootWindow();
+ views::Widget::CreateWindowWithParent(this, root_window);
sky 2012/03/12 23:33:38 Why are you parenting this to the root window?
rkc 2012/03/12 23:57:51 The IdleLogout can come up at any point; whether o
sky 2012/03/13 03:43:54 I believe that means it could go in from of the lo
rkc 2012/03/14 22:35:32 Done.
+ GetWidget()->Show();
+#else
+ NOTIMPLEMENTED();
+#endif
+
+ // Update countdown every 1 second.
+ timer_.Start(FROM_HERE,
+ base::TimeDelta::FromSeconds(kCountdownUpdateInterval),
+ this,
+ &IdleLogoutDialog::UpdateCountdownTimer);
+}
+
+void IdleLogoutDialog::Close() {
+ DCHECK(GetWidget());
+
+ timer_.Stop();
+ GetWidget()->Close();
+}
+
+void IdleLogoutDialog::UpdateCountdownTimer() {
+ base::TimeDelta logout_warning_time = countdown_end_time_ -
+ base::Time::Now();
+ int64 seconds_left = (logout_warning_time.InMillisecondsF() /
+ base::Time::kMillisecondsPerSecond) + 0.5;
+
+ if (seconds_left > 1) {
+ restart_label_->SetText(l10n_util::GetStringFUTF16(
+ IDS_IDLE_LOGOUT_WARNING_RESTART,
+ string16(base::Int64ToString16(seconds_left))));
+ } else if (seconds_left > 0) {
+ restart_label_->SetText(l10n_util::GetStringUTF16(
+ IDS_IDLE_LOGOUT_WARNING_RESTART_1S));
+ } else {
+ // Set the label - the logout probably won't be instant.
+ restart_label_->SetText(l10n_util::GetStringUTF16(
+ IDS_IDLE_LOGOUT_WARNING_RESTART_NOW));
+
+ // Logout the current user.
+ BrowserList::AttemptUserExit();
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698