Commit a889e94c authored by tnagel@chromium.org's avatar tnagel@chromium.org

Move session length timer into tray bubble.

BUG=287784

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@269813 0039d316-1c4b-4281-b951-d872f2087c98
parent ae018707
...@@ -512,11 +512,11 @@ Press Shift + Alt to switch. ...@@ -512,11 +512,11 @@ Press Shift + Alt to switch.
<message name="IDS_ASH_STATUS_TRAY_SHUTDOWN" desc="The accessible text for the shutdown button."> <message name="IDS_ASH_STATUS_TRAY_SHUTDOWN" desc="The accessible text for the shutdown button.">
Shut down Shut down
</message> </message>
<message name="IDS_ASH_STATUS_TRAY_REMAINING_SESSION_TIME" desc="The time remaining until the end of the session. Shown if the session length is limited."> <message name="IDS_ASH_STATUS_TRAY_BUBBLE_SESSION_LENGTH_LIMIT" desc="Tray bubble item shown to inform the user that the session length is limited.">
<ph name="hours">$1<ex>01</ex></ph>:<ph name="minutes">$2<ex>35</ex></ph>:<ph name="seconds">$3<ex>12</ex></ph> Session ends in <ph name="session_time_remaining">$1<ex>4 minutes 23 seconds</ex></ph>.
</message> </message>
<message name="IDS_ASH_STATUS_TRAY_REMAINING_SESSION_TIME_NOTIFICATION" desc="Notification shown to inform the user that the session length is limited."> <message name="IDS_ASH_STATUS_TRAY_NOTIFICATION_SESSION_LENGTH_LIMIT" desc="Notification shown to inform the user that the session length is limited.">
This session will end in <ph name="session_time_remaining">$1<ex>15 minutes</ex></ph>. You will be automatically signed out. Session ends in <ph name="session_time_remaining">$1<ex>4 minutes 23 seconds</ex></ph>. You will be signed out.
</message> </message>
<message name="IDS_ASH_STATUS_TRAY_LOCALLY_MANAGED_LABEL" desc="Label shown instead of email for supervised users"> <message name="IDS_ASH_STATUS_TRAY_LOCALLY_MANAGED_LABEL" desc="Label shown instead of email for supervised users">
......
...@@ -143,7 +143,6 @@ ...@@ -143,7 +143,6 @@
<structure type="chrome_scaled_image" name="IDR_AURA_UBER_TRAY_POWER_SMALL_CHARGING_UNRELIABLE_DARK" file="cros/status/status_power_small_all_dark_fluctuating.png" /> <structure type="chrome_scaled_image" name="IDR_AURA_UBER_TRAY_POWER_SMALL_CHARGING_UNRELIABLE_DARK" file="cros/status/status_power_small_all_dark_fluctuating.png" />
<structure type="chrome_scaled_image" name="IDR_AURA_UBER_TRAY_SCREENSHARE" file="cros/status/status_screenshare.png" /> <structure type="chrome_scaled_image" name="IDR_AURA_UBER_TRAY_SCREENSHARE" file="cros/status/status_screenshare.png" />
<structure type="chrome_scaled_image" name="IDR_AURA_UBER_TRAY_SCREENSHARE_DARK" file="cros/status/status_screenshare_dark.png" /> <structure type="chrome_scaled_image" name="IDR_AURA_UBER_TRAY_SCREENSHARE_DARK" file="cros/status/status_screenshare_dark.png" />
<structure type="chrome_scaled_image" name="IDR_AURA_UBER_TRAY_SESSION_LENGTH_LIMIT_TIMER" file="cros/status/status_session_length_limit_timer.png" />
<structure type="chrome_scaled_image" name="IDR_AURA_UBER_TRAY_SETTINGS" file="cros/status/status_settings.png" /> <structure type="chrome_scaled_image" name="IDR_AURA_UBER_TRAY_SETTINGS" file="cros/status/status_settings.png" />
<structure type="chrome_scaled_image" name="IDR_AURA_UBER_TRAY_SHUTDOWN" file="cros/status/status_shutdown.png" /> <structure type="chrome_scaled_image" name="IDR_AURA_UBER_TRAY_SHUTDOWN" file="cros/status/status_shutdown.png" />
<structure type="chrome_scaled_image" name="IDR_AURA_UBER_TRAY_SHUTDOWN_HOVER" file="cros/status/status_shutdown_hover.png" /> <structure type="chrome_scaled_image" name="IDR_AURA_UBER_TRAY_SHUTDOWN_HOVER" file="cros/status/status_shutdown_hover.png" />
...@@ -155,6 +154,7 @@ ...@@ -155,6 +154,7 @@
<if expr="chromeos"> <if expr="chromeos">
<structure type="chrome_scaled_image" name="IDR_AURA_NOTIFICATION_LOW_POWER_CHARGER" file="cros/notification/notification_low_power_charger.png" /> <structure type="chrome_scaled_image" name="IDR_AURA_NOTIFICATION_LOW_POWER_CHARGER" file="cros/notification/notification_low_power_charger.png" />
<structure type="chrome_scaled_image" name="IDR_AURA_NOTIFICATION_DISPLAY" file="cros/notification/display_notification_icon.png" /> <structure type="chrome_scaled_image" name="IDR_AURA_NOTIFICATION_DISPLAY" file="cros/notification/display_notification_icon.png" />
<structure type="chrome_scaled_image" name="IDR_AURA_UBER_TRAY_BUBBLE_SESSION_LENGTH_LIMIT" file="cros/status/status_session_length_timer.png" />
<structure type="chrome_scaled_image" name="IDR_AURA_UBER_TRAY_ENTERPRISE" file="cros/status/status_managed.png" /> <structure type="chrome_scaled_image" name="IDR_AURA_UBER_TRAY_ENTERPRISE" file="cros/status/status_managed.png" />
<structure type="chrome_scaled_image" name="IDR_AURA_UBER_TRAY_MANAGED_USER" file="cros/status/status_managed_mode_user.png" /> <structure type="chrome_scaled_image" name="IDR_AURA_UBER_TRAY_MANAGED_USER" file="cros/status/status_managed_mode_user.png" />
<structure type="chrome_scaled_image" name="IDR_AURA_UBER_TRAY_NETWORK_1X" file="cros/network/statusbar_network_1x.png" /> <structure type="chrome_scaled_image" name="IDR_AURA_UBER_TRAY_NETWORK_1X" file="cros/network/statusbar_network_1x.png" />
...@@ -188,6 +188,7 @@ ...@@ -188,6 +188,7 @@
<structure type="chrome_scaled_image" name="IDR_AURA_UBER_TRAY_NETWORK_VPN" file="cros/network/statusbar_vpn_dark.png" /> <structure type="chrome_scaled_image" name="IDR_AURA_UBER_TRAY_NETWORK_VPN" file="cros/network/statusbar_vpn_dark.png" />
<structure type="chrome_scaled_image" name="IDR_AURA_UBER_TRAY_NETWORK_VPN_BADGE" file="cros/network/statusbar_network_vpn_badge.png" /> <structure type="chrome_scaled_image" name="IDR_AURA_UBER_TRAY_NETWORK_VPN_BADGE" file="cros/network/statusbar_network_vpn_badge.png" />
<structure type="chrome_scaled_image" name="IDR_AURA_UBER_TRAY_NETWORK_WIRED" file="cros/network/statusbar_wired.png" /> <structure type="chrome_scaled_image" name="IDR_AURA_UBER_TRAY_NETWORK_WIRED" file="cros/network/statusbar_wired.png" />
<structure type="chrome_scaled_image" name="IDR_AURA_UBER_TRAY_NOTIFICATION_SESSION_LENGTH_LIMIT" file="cros/notification/notification_session_length_timer.png" />
<structure type="chrome_scaled_image" name="IDR_AURA_UBER_TRAY_RECORDING" file="cros/status/status_recording.png" /> <structure type="chrome_scaled_image" name="IDR_AURA_UBER_TRAY_RECORDING" file="cros/status/status_recording.png" />
<structure type="chrome_scaled_image" name="IDR_AURA_UBER_TRAY_RECORDING_RED" file="cros/status/status_recording_red.png" /> <structure type="chrome_scaled_image" name="IDR_AURA_UBER_TRAY_RECORDING_RED" file="cros/status/status_recording_red.png" />
<structure type="chrome_scaled_image" name="IDR_AURA_UBER_TRAY_VIRTUAL_KEYBOARD" file="cros/status/status_virtual_keyboard.png" /> <structure type="chrome_scaled_image" name="IDR_AURA_UBER_TRAY_VIRTUAL_KEYBOARD" file="cros/status/status_virtual_keyboard.png" />
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include "base/basictypes.h" #include "base/basictypes.h"
#include "base/compiler_specific.h" #include "base/compiler_specific.h"
#include "base/memory/scoped_ptr.h" #include "base/memory/scoped_ptr.h"
#include "base/strings/string16.h"
#include "base/time/time.h" #include "base/time/time.h"
#include "base/timer/timer.h" #include "base/timer/timer.h"
...@@ -18,14 +19,12 @@ namespace test { ...@@ -18,14 +19,12 @@ namespace test {
class TraySessionLengthLimitTest; class TraySessionLengthLimitTest;
} }
namespace tray { class LabelTrayView;
class RemainingSessionTimeTrayView;
}
// Adds a countdown timer to the system tray if the session length is limited. // Adds a countdown timer to the system tray if the session length is limited.
class ASH_EXPORT TraySessionLengthLimit : public SystemTrayItem, class ASH_EXPORT TraySessionLengthLimit : public SystemTrayItem,
public SessionLengthLimitObserver { public SessionLengthLimitObserver {
public: public:
enum LimitState { enum LimitState {
LIMIT_NONE, LIMIT_NONE,
LIMIT_SET, LIMIT_SET,
...@@ -36,33 +35,40 @@ class ASH_EXPORT TraySessionLengthLimit : public SystemTrayItem, ...@@ -36,33 +35,40 @@ class ASH_EXPORT TraySessionLengthLimit : public SystemTrayItem,
virtual ~TraySessionLengthLimit(); virtual ~TraySessionLengthLimit();
// SystemTrayItem: // SystemTrayItem:
virtual views::View* CreateTrayView(user::LoginStatus status) OVERRIDE; virtual views::View* CreateDefaultView(user::LoginStatus status) OVERRIDE;
virtual void DestroyTrayView() OVERRIDE; virtual void DestroyDefaultView() OVERRIDE;
virtual void UpdateAfterShelfAlignmentChange(
ShelfAlignment alignment) OVERRIDE;
// SessionLengthLimitObserver: // SessionLengthLimitObserver:
virtual void OnSessionStartTimeChanged() OVERRIDE; virtual void OnSessionStartTimeChanged() OVERRIDE;
virtual void OnSessionLengthLimitChanged() OVERRIDE; virtual void OnSessionLengthLimitChanged() OVERRIDE;
LimitState GetLimitState() const;
base::TimeDelta GetRemainingSessionTime() const;
private: private:
friend class test::TraySessionLengthLimitTest; friend class test::TraySessionLengthLimitTest;
static const char kNotificationId[]; static const char kNotificationId[];
// Update state, notification and tray bubble view. Called by the
// RepeatingTimer in regular intervals and also by OnSession*Changed().
void Update(); void Update();
bool IsTrayViewVisibleForTest(); // Recalculate |limit_state_| and |remaining_session_time_|.
void UpdateState();
void UpdateNotification();
void UpdateTrayBubbleView() const;
tray::RemainingSessionTimeTrayView* tray_view_; // These require that the state has been updated before.
base::string16 ComposeNotificationMessage() const;
base::string16 ComposeTrayBubbleMessage() const;
LimitState limit_state_;
base::TimeTicks session_start_time_; base::TimeTicks session_start_time_;
base::TimeDelta limit_; base::TimeDelta time_limit_;
base::TimeDelta remaining_session_time_; base::TimeDelta remaining_session_time_;
LimitState limit_state_; // Current state.
LimitState last_limit_state_; // State of last notification update.
LabelTrayView* tray_bubble_view_;
scoped_ptr<base::RepeatingTimer<TraySessionLengthLimit> > timer_; scoped_ptr<base::RepeatingTimer<TraySessionLengthLimit> > timer_;
DISALLOW_COPY_AND_ASSIGN(TraySessionLengthLimit); DISALLOW_COPY_AND_ASSIGN(TraySessionLengthLimit);
......
...@@ -59,17 +59,13 @@ class TraySessionLengthLimitTest : public AshTestBase { ...@@ -59,17 +59,13 @@ class TraySessionLengthLimitTest : public AshTestBase {
void RemoveNotification() { void RemoveNotification() {
message_center::MessageCenter::Get()->RemoveNotification( message_center::MessageCenter::Get()->RemoveNotification(
TraySessionLengthLimit::kNotificationId, true /* by_user */); TraySessionLengthLimit::kNotificationId, false /* by_user */);
} }
TraySessionLengthLimit* tray_session_length_limit() { TraySessionLengthLimit* tray_session_length_limit() {
return tray_session_length_limit_; return tray_session_length_limit_;
} }
bool IsTrayViewVisible() {
return tray_session_length_limit_->IsTrayViewVisibleForTest();
}
private: private:
// Weak reference, owned by the SystemTray. // Weak reference, owned by the SystemTray.
TraySessionLengthLimit* tray_session_length_limit_; TraySessionLengthLimit* tray_session_length_limit_;
...@@ -77,41 +73,6 @@ class TraySessionLengthLimitTest : public AshTestBase { ...@@ -77,41 +73,6 @@ class TraySessionLengthLimitTest : public AshTestBase {
DISALLOW_COPY_AND_ASSIGN(TraySessionLengthLimitTest); DISALLOW_COPY_AND_ASSIGN(TraySessionLengthLimitTest);
}; };
TEST_F(TraySessionLengthLimitTest, TrayView) {
// No session limit.
EXPECT_FALSE(IsTrayViewVisible());
// Limit is 15 min.
UpdateSessionLengthLimitInMin(15);
EXPECT_EQ(TraySessionLengthLimit::LIMIT_SET,
tray_session_length_limit()->GetLimitState());
EXPECT_TRUE(IsTrayViewVisible());
// Limit is 3 min.
UpdateSessionLengthLimitInMin(3);
EXPECT_EQ(TraySessionLengthLimit::LIMIT_EXPIRING_SOON,
tray_session_length_limit()->GetLimitState());
EXPECT_TRUE(IsTrayViewVisible());
// Nothing left.
UpdateSessionLengthLimitInMin(0);
EXPECT_EQ(TraySessionLengthLimit::LIMIT_EXPIRING_SOON,
tray_session_length_limit()->GetLimitState());
EXPECT_TRUE(IsTrayViewVisible());
// Checks the behavior in case the limit goes negative.
UpdateSessionLengthLimitInMin(-5);
EXPECT_EQ(TraySessionLengthLimit::LIMIT_EXPIRING_SOON,
tray_session_length_limit()->GetLimitState());
EXPECT_TRUE(IsTrayViewVisible());
// Clears the session length limit, the TrayView should get invisible.
ClearSessionLengthLimit();
ASSERT_EQ(TraySessionLengthLimit::LIMIT_NONE,
tray_session_length_limit()->GetLimitState());
EXPECT_FALSE(IsTrayViewVisible());
}
TEST_F(TraySessionLengthLimitTest, Notification) { TEST_F(TraySessionLengthLimitTest, Notification) {
// No notifications when no session limit. // No notifications when no session limit.
EXPECT_FALSE(GetNotification()); EXPECT_FALSE(GetNotification());
...@@ -121,7 +82,7 @@ TEST_F(TraySessionLengthLimitTest, Notification) { ...@@ -121,7 +82,7 @@ TEST_F(TraySessionLengthLimitTest, Notification) {
message_center::Notification* notification = GetNotification(); message_center::Notification* notification = GetNotification();
EXPECT_TRUE(notification); EXPECT_TRUE(notification);
EXPECT_EQ(message_center::SYSTEM_PRIORITY, notification->priority()); EXPECT_EQ(message_center::SYSTEM_PRIORITY, notification->priority());
base::string16 first_content = notification->title(); base::string16 first_content = notification->message();
// Should read the content. // Should read the content.
EXPECT_TRUE(notification->rich_notification_data(). EXPECT_TRUE(notification->rich_notification_data().
should_make_spoken_feedback_for_popup_updates); should_make_spoken_feedback_for_popup_updates);
...@@ -132,7 +93,7 @@ TEST_F(TraySessionLengthLimitTest, Notification) { ...@@ -132,7 +93,7 @@ TEST_F(TraySessionLengthLimitTest, Notification) {
EXPECT_TRUE(notification); EXPECT_TRUE(notification);
EXPECT_EQ(message_center::SYSTEM_PRIORITY, notification->priority()); EXPECT_EQ(message_center::SYSTEM_PRIORITY, notification->priority());
// The content should be updated. // The content should be updated.
EXPECT_NE(first_content, notification->title()); EXPECT_NE(first_content, notification->message());
// Should NOT read, because just update the remaining time. // Should NOT read, because just update the remaining time.
EXPECT_FALSE(notification->rich_notification_data(). EXPECT_FALSE(notification->rich_notification_data().
should_make_spoken_feedback_for_popup_updates); should_make_spoken_feedback_for_popup_updates);
...@@ -146,15 +107,14 @@ TEST_F(TraySessionLengthLimitTest, Notification) { ...@@ -146,15 +107,14 @@ TEST_F(TraySessionLengthLimitTest, Notification) {
EXPECT_TRUE(notification->rich_notification_data(). EXPECT_TRUE(notification->rich_notification_data().
should_make_spoken_feedback_for_popup_updates); should_make_spoken_feedback_for_popup_updates);
// Session length limit is updated to longer. This should not read the // Session length limit is updated to longer: 15 min.
// notification content again.
UpdateSessionLengthLimitInMin(15); UpdateSessionLengthLimitInMin(15);
notification = GetNotification(); notification = GetNotification();
EXPECT_TRUE(notification); EXPECT_TRUE(notification);
EXPECT_EQ(message_center::SYSTEM_PRIORITY, notification->priority()); EXPECT_EQ(message_center::SYSTEM_PRIORITY, notification->priority());
// Should not read again because the state has changed to longer. // Should read again because an increase of the remaining time is noteworthy.
EXPECT_FALSE(notification->rich_notification_data(). EXPECT_TRUE(notification->rich_notification_data().
should_make_spoken_feedback_for_popup_updates); should_make_spoken_feedback_for_popup_updates);
// Clears the limit: the notification should be gone. // Clears the limit: the notification should be gone.
ClearSessionLengthLimit(); ClearSessionLengthLimit();
...@@ -162,32 +122,37 @@ TEST_F(TraySessionLengthLimitTest, Notification) { ...@@ -162,32 +122,37 @@ TEST_F(TraySessionLengthLimitTest, Notification) {
} }
TEST_F(TraySessionLengthLimitTest, RemoveNotification) { TEST_F(TraySessionLengthLimitTest, RemoveNotification) {
message_center::Notification* notification;
// Limit is 15 min. // Limit is 15 min.
UpdateSessionLengthLimitInMin(15); UpdateSessionLengthLimitInMin(15);
EXPECT_TRUE(GetNotification()); EXPECT_TRUE(GetNotification());
// Limit is 14 min.
UpdateSessionLengthLimitInMin(14);
EXPECT_TRUE(GetNotification());
// Removes the notification. // Removes the notification.
RemoveNotification(); RemoveNotification();
EXPECT_FALSE(GetNotification()); EXPECT_FALSE(GetNotification());
// Limit is 13 min. The notification should not re-appear. // Limit is 10 min. The notification should not re-appear.
UpdateSessionLengthLimitInMin(13); UpdateSessionLengthLimitInMin(10);
EXPECT_FALSE(GetNotification()); EXPECT_FALSE(GetNotification());
// Limit is 3 min. The notification should re-appear because of state change. // Limit is 3 min. The notification should re-appear and should be re-read
// because of state change.
UpdateSessionLengthLimitInMin(3); UpdateSessionLengthLimitInMin(3);
EXPECT_TRUE(GetNotification()); notification = GetNotification();
EXPECT_TRUE(notification);
EXPECT_TRUE(notification->rich_notification_data().
should_make_spoken_feedback_for_popup_updates);
RemoveNotification(); RemoveNotification();
// Session length limit is updated to longer state. This should not re-appear // Session length limit is updated to longer state. Notification should
// the notification. // re-appear and be re-read.
UpdateSessionLengthLimitInMin(15); UpdateSessionLengthLimitInMin(15);
EXPECT_FALSE(GetNotification()); notification = GetNotification();
EXPECT_TRUE(notification);
EXPECT_TRUE(notification->rich_notification_data().
should_make_spoken_feedback_for_popup_updates);
} }
} // namespace test } // namespace test
......
...@@ -153,9 +153,6 @@ void SystemTray::InitializeTrayItems(SystemTrayDelegate* delegate) { ...@@ -153,9 +153,6 @@ void SystemTray::InitializeTrayItems(SystemTrayDelegate* delegate) {
} }
void SystemTray::CreateItems(SystemTrayDelegate* delegate) { void SystemTray::CreateItems(SystemTrayDelegate* delegate) {
#if defined(OS_CHROMEOS)
AddTrayItem(new TraySessionLengthLimit(this));
#endif
#if !defined(OS_WIN) #if !defined(OS_WIN)
// Create user items for each possible user. // Create user items for each possible user.
ash::Shell* shell = ash::Shell::GetInstance(); ash::Shell* shell = ash::Shell::GetInstance();
...@@ -175,6 +172,7 @@ void SystemTray::CreateItems(SystemTrayDelegate* delegate) { ...@@ -175,6 +172,7 @@ void SystemTray::CreateItems(SystemTrayDelegate* delegate) {
tray_date_ = new TrayDate(this); tray_date_ = new TrayDate(this);
#if defined(OS_CHROMEOS) #if defined(OS_CHROMEOS)
AddTrayItem(new TraySessionLengthLimit(this));
AddTrayItem(new TrayEnterprise(this)); AddTrayItem(new TrayEnterprise(this));
AddTrayItem(new TrayLocallyManagedUser(this)); AddTrayItem(new TrayLocallyManagedUser(this));
AddTrayItem(new TrayIME(this)); AddTrayItem(new TrayIME(this));
......
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