Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/chromeos/ui/idle_logout_dialog.h" | |
| 6 | |
| 7 #include <string> | |
|
sky
2012/03/11 21:57:47
Do you really need these includes in both the head
rkc
2012/03/12 22:43:38
They weren't needed in either, removed.
Done.
| |
| 8 #include <vector> | |
| 9 | |
| 10 #include "base/bind.h" | |
| 11 #include "base/bind_helpers.h" | |
| 12 #include "base/time.h" | |
| 13 #include "base/timer.h" | |
| 14 #include "base/string_number_conversions.h" | |
| 15 #include "chrome/browser/chromeos/kiosk_mode/kiosk_mode_helper.h" | |
| 16 #include "chrome/browser/ui/browser_list.h" | |
| 17 #include "chrome/common/logging_chrome.h" | |
| 18 #include "grit/browser_resources.h" | |
| 19 #include "grit/generated_resources.h" | |
| 20 #include "ui/base/l10n/l10n_util.h" | |
| 21 #include "ui/base/resource/resource_bundle.h" | |
| 22 #include "ui/views/layout/grid_layout.h" | |
| 23 #include "ui/views/layout/layout_constants.h" | |
| 24 #include "ui/views/widget/widget.h" | |
| 25 | |
| 26 #if defined(USE_AURA) | |
| 27 #include "ash/shell.h" | |
| 28 #include "ui/aura/root_window.h" | |
| 29 #endif | |
| 30 | |
| 31 using views::GridLayout; | |
|
tfarina
2012/03/11 23:42:58
nit: I'd remove this and just have views::GridLayo
rkc
2012/03/12 22:43:38
Done.
| |
| 32 | |
| 33 namespace { | |
| 34 | |
| 35 // Global singleton instance of our dialog class. | |
| 36 IdleLogoutDialog* g_instance = NULL; | |
| 37 // Height/Width of the logout dialog. | |
| 38 const int kIdleLogoutDialogWidth = 400; | |
| 39 const int kIdleLogoutDialogHeight = 100; | |
| 40 | |
| 41 const base::TimeDelta kFudgeTime = base::TimeDelta::FromMilliseconds(100); | |
|
tfarina
2012/03/11 23:42:58
I think this adds a static initializer? See http:/
rkc
2012/03/12 22:43:38
Removed this completely.
| |
| 42 | |
| 43 } // namespace | |
| 44 | |
| 45 //////////////////////////////////////////////////////////////////////////////// | |
| 46 // IdleLogoutDialog public static methods | |
| 47 | |
| 48 void IdleLogoutDialog::ShowIdleLogoutDialog() { | |
| 49 if (!g_instance) { | |
| 50 g_instance = new IdleLogoutDialog(); | |
| 51 } | |
| 52 g_instance->Show(); | |
| 53 } | |
| 54 | |
| 55 void IdleLogoutDialog::CloseIdleLogoutDialog() { | |
| 56 if (g_instance) { | |
| 57 g_instance->Close(); | |
| 58 delete g_instance; | |
|
sky
2012/03/11 21:57:47
It's a lot safter to put this in DeleteDelegate. T
rkc
2012/03/12 22:43:38
Done.
| |
| 59 g_instance = NULL; | |
| 60 } | |
| 61 } | |
| 62 | |
| 63 //////////////////////////////////////////////////////////////////////////////// | |
| 64 // IdleLogoutDialog private methods | |
| 65 IdleLogoutDialog::IdleLogoutDialog() { | |
|
sky
2012/03/11 21:57:47
Order of methods should match header.
sky
2012/03/11 21:57:47
Have the constructor initialize warning_label_ and
rkc
2012/03/12 22:43:38
Done.
rkc
2012/03/12 22:43:38
Done.
| |
| 66 Init(); | |
| 67 } | |
| 68 | |
| 69 void IdleLogoutDialog::Init() { | |
| 70 if (!chromeos::KioskModeHelper::Get()->is_initialized()) { | |
| 71 chromeos::KioskModeHelper::Get()->Initialize( | |
|
sky
2012/03/11 21:57:47
What happens if Close is called this returns?
rkc
2012/03/12 22:43:38
Bad things. Fixed it so it's handled correctly.
Do
| |
| 72 base::Bind(&IdleLogoutDialog::Init, | |
| 73 base::Unretained(this))); | |
| 74 return; | |
| 75 } | |
| 76 | |
| 77 warning_label_ = new views::Label( | |
| 78 l10n_util::GetStringUTF16(IDS_IDLE_LOGOUT_WARNING)); | |
| 79 warning_label_->SetHorizontalAlignment(views::Label::ALIGN_LEFT); | |
| 80 warning_label_->SetMultiLine(true); | |
| 81 warning_label_->SetFont( | |
| 82 ResourceBundle::GetSharedInstance().GetFont(ResourceBundle::BaseFont)); | |
|
tfarina
2012/03/11 23:42:58
nit: Make a temp var, like:
ui::ResourceBundle& r
rkc
2012/03/12 22:43:38
Done.
| |
| 83 | |
| 84 restart_label_ = new views::Label(); | |
| 85 restart_label_->SetHorizontalAlignment(views::Label::ALIGN_LEFT); | |
| 86 restart_label_-> SetFont( | |
|
tfarina
2012/03/11 23:42:58
nit: looks like there is an extra space between ->
rkc
2012/03/12 22:43:38
Done.
| |
| 87 ResourceBundle::GetSharedInstance().GetFont( | |
| 88 ResourceBundle::BoldFont)); | |
|
tfarina
2012/03/11 23:42:58
nit: ui::ResourceBundle::
rkc
2012/03/12 22:43:38
Done.
| |
| 89 | |
| 90 GridLayout* layout = GridLayout::CreatePanel(this); | |
| 91 SetLayoutManager(layout); | |
| 92 | |
| 93 views::ColumnSet* column_set = layout->AddColumnSet(0); | |
| 94 column_set->AddColumn(GridLayout::FILL, GridLayout::CENTER, 1, | |
| 95 GridLayout::USE_PREF, 0, 0); | |
| 96 layout->StartRow(0, 0); | |
| 97 layout->AddView(warning_label_); | |
| 98 layout->AddPaddingRow(0, views::kUnrelatedControlVerticalSpacing); | |
| 99 layout->StartRow(0, 0); | |
| 100 layout->AddView(restart_label_); | |
| 101 } | |
| 102 | |
| 103 void IdleLogoutDialog::Show() { | |
| 104 // Setup the countdown label before showing. | |
| 105 countdown_end_time_ = base::Time::Now() + base::TimeDelta::FromSeconds( | |
| 106 chromeos::KioskModeHelper::Get()->GetIdleLogoutWarningTimeout()); | |
| 107 UpdateCountdownTimer(); | |
| 108 | |
| 109 #if defined(USE_AURA) | |
| 110 aura::RootWindow* root_window = ash::Shell::GetRootWindow(); | |
| 111 views::Widget::CreateWindowWithParent(this, root_window); | |
| 112 GetWidget()->Show(); | |
| 113 #else | |
| 114 NOTIMPLEMENTED(); | |
|
sky
2012/03/11 21:57:47
Do you even intend to implement this for non-aura?
rkc
2012/03/12 22:43:38
Code from this file is called from other places.
I
| |
| 115 #endif | |
| 116 | |
| 117 // Update countdown every 1 second. | |
| 118 timer_.Start(FROM_HERE, base::TimeDelta::FromSeconds(1), | |
| 119 this, &IdleLogoutDialog::UpdateCountdownTimer); | |
| 120 } | |
| 121 | |
| 122 void IdleLogoutDialog::Close() { | |
| 123 DCHECK(GetWidget()); | |
| 124 | |
| 125 timer_.Stop(); | |
| 126 GetWidget()->Close(); | |
| 127 } | |
| 128 | |
| 129 void IdleLogoutDialog::UpdateCountdownTimer() { | |
| 130 base::TimeDelta logout_warning_time = countdown_end_time_ - | |
| 131 base::Time::Now() + kFudgeTime; | |
|
sky
2012/03/11 21:57:47
Why the kFudgeTime?
rkc
2012/03/12 22:43:38
InSeconds doesn't actually round the milli/microse
| |
| 132 if (logout_warning_time.InSeconds() > 1) { | |
| 133 restart_label_->SetText(l10n_util::GetStringFUTF16( | |
| 134 IDS_IDLE_LOGOUT_WARNING_RESTART, | |
| 135 string16(base::Int64ToString16(logout_warning_time.InSeconds())))); | |
| 136 } else if (logout_warning_time.InSeconds() > 0) { | |
| 137 restart_label_->SetText(l10n_util::GetStringUTF16( | |
| 138 IDS_IDLE_LOGOUT_WARNING_RESTART_1S)); | |
| 139 } else { | |
| 140 // Set the label - the logout probably won't be instant. | |
| 141 restart_label_->SetText(l10n_util::GetStringUTF16( | |
| 142 IDS_IDLE_LOGOUT_WARNING_RESTART_NOW)); | |
| 143 | |
| 144 // Logout the current user. | |
| 145 BrowserList::AttemptUserExit(); | |
| 146 } | |
| 147 } | |
| 148 | |
| 149 //////////////////////////////////////////////////////////////////////////////// | |
| 150 // Overridden from HtmlDialogUIDelegate | |
| 151 int IdleLogoutDialog::GetDialogButtons() const { | |
| 152 return ui::DIALOG_BUTTON_NONE; | |
| 153 } | |
| 154 | |
| 155 ui::ModalType IdleLogoutDialog::GetModalType() const { | |
| 156 return ui::MODAL_TYPE_WINDOW; | |
| 157 } | |
| 158 | |
| 159 string16 IdleLogoutDialog::GetWindowTitle() const { | |
| 160 return l10n_util::GetStringUTF16(IDS_IDLE_LOGOUT_TITLE); | |
| 161 } | |
| 162 | |
| 163 views::View* IdleLogoutDialog::GetContentsView() { | |
| 164 return this; | |
| 165 } | |
| 166 | |
| 167 gfx::Size IdleLogoutDialog::GetPreferredSize() { | |
| 168 return gfx::Size(kIdleLogoutDialogWidth, kIdleLogoutDialogHeight); | |
|
sky
2012/03/11 21:57:47
Don't you want to make sure it can fit the content
rkc
2012/03/12 22:43:38
Thought that is what 'preferred size' did? Set it
sky
2012/03/12 23:33:38
The only way it knows is to ask for the preferred
rkc
2012/03/12 23:57:51
I think the user should keep the size adjusted to
sky
2012/03/13 03:43:54
I agree, but this isn't adjusting to the size of t
rkc
2012/03/14 22:35:32
I realized the main thing we really want is that o
| |
| 169 } | |
| 170 | |
| 171 void IdleLogoutDialog::Layout() { | |
| 172 GetLayoutManager()->Layout(this); | |
| 173 } | |
| OLD | NEW |