| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef ASH_SYSTEM_CHROMEOS_SESSION_SESSION_LENGTH_LIMIT_H_ | 5 #ifndef ASH_SYSTEM_CHROMEOS_SESSION_SESSION_LENGTH_LIMIT_H_ |
| 6 #define ASH_SYSTEM_CHROMEOS_SESSION_SESSION_LENGTH_LIMIT_H_ | 6 #define ASH_SYSTEM_CHROMEOS_SESSION_SESSION_LENGTH_LIMIT_H_ |
| 7 | 7 |
| 8 #include "ash/system/chromeos/session/session_length_limit_observer.h" | 8 #include "ash/system/chromeos/session/session_length_limit_observer.h" |
| 9 #include "ash/system/tray/system_tray_item.h" | 9 #include "ash/system/tray/system_tray_item.h" |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| 11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
| 12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
| 13 #include "base/strings/string16.h" |
| 13 #include "base/time/time.h" | 14 #include "base/time/time.h" |
| 14 #include "base/timer/timer.h" | 15 #include "base/timer/timer.h" |
| 15 | 16 |
| 16 namespace ash { | 17 namespace ash { |
| 17 namespace test { | 18 namespace test { |
| 18 class TraySessionLengthLimitTest; | 19 class TraySessionLengthLimitTest; |
| 19 } | 20 } |
| 20 | 21 |
| 21 namespace tray { | 22 class LabelTrayView; |
| 22 class RemainingSessionTimeTrayView; | |
| 23 } | |
| 24 | 23 |
| 25 // Adds a countdown timer to the system tray if the session length is limited. | 24 // Adds a countdown timer to the system tray if the session length is limited. |
| 26 class ASH_EXPORT TraySessionLengthLimit : public SystemTrayItem, | 25 class ASH_EXPORT TraySessionLengthLimit : public SystemTrayItem, |
| 27 public SessionLengthLimitObserver { | 26 public SessionLengthLimitObserver { |
| 28 public: | 27 public: |
| 29 enum LimitState { | 28 enum LimitState { |
| 30 LIMIT_NONE, | 29 LIMIT_NONE, |
| 31 LIMIT_SET, | 30 LIMIT_SET, |
| 32 LIMIT_EXPIRING_SOON | 31 LIMIT_EXPIRING_SOON |
| 33 }; | 32 }; |
| 34 | 33 |
| 35 explicit TraySessionLengthLimit(SystemTray* system_tray); | 34 explicit TraySessionLengthLimit(SystemTray* system_tray); |
| 36 virtual ~TraySessionLengthLimit(); | 35 virtual ~TraySessionLengthLimit(); |
| 37 | 36 |
| 38 // SystemTrayItem: | 37 // SystemTrayItem: |
| 39 virtual views::View* CreateTrayView(user::LoginStatus status) OVERRIDE; | 38 virtual views::View* CreateDefaultView(user::LoginStatus status) OVERRIDE; |
| 40 virtual void DestroyTrayView() OVERRIDE; | 39 virtual void DestroyDefaultView() OVERRIDE; |
| 41 virtual void UpdateAfterShelfAlignmentChange( | |
| 42 ShelfAlignment alignment) OVERRIDE; | |
| 43 | 40 |
| 44 // SessionLengthLimitObserver: | 41 // SessionLengthLimitObserver: |
| 45 virtual void OnSessionStartTimeChanged() OVERRIDE; | 42 virtual void OnSessionStartTimeChanged() OVERRIDE; |
| 46 virtual void OnSessionLengthLimitChanged() OVERRIDE; | 43 virtual void OnSessionLengthLimitChanged() OVERRIDE; |
| 47 | 44 |
| 48 LimitState GetLimitState() const; | |
| 49 base::TimeDelta GetRemainingSessionTime() const; | |
| 50 | |
| 51 private: | 45 private: |
| 52 friend class test::TraySessionLengthLimitTest; | 46 friend class test::TraySessionLengthLimitTest; |
| 53 | 47 |
| 54 static const char kNotificationId[]; | 48 static const char kNotificationId[]; |
| 55 | 49 |
| 50 // Update state, notification and tray bubble view. Called by the |
| 51 // RepeatingTimer in regular intervals and also by OnSession*Changed(). |
| 56 void Update(); | 52 void Update(); |
| 57 | 53 |
| 58 bool IsTrayViewVisibleForTest(); | 54 // Recalculate |limit_state_| and |remaining_session_time_|. |
| 55 void UpdateState(); |
| 59 | 56 |
| 60 tray::RemainingSessionTimeTrayView* tray_view_; | 57 void UpdateNotification(); |
| 58 void UpdateTrayBubbleView() const; |
| 61 | 59 |
| 62 LimitState limit_state_; | 60 // These require that the state has been updated before. |
| 61 base::string16 ComposeNotificationMessage() const; |
| 62 base::string16 ComposeTrayBubbleMessage() const; |
| 63 |
| 63 base::TimeTicks session_start_time_; | 64 base::TimeTicks session_start_time_; |
| 64 base::TimeDelta limit_; | 65 base::TimeDelta time_limit_; |
| 65 base::TimeDelta remaining_session_time_; | 66 base::TimeDelta remaining_session_time_; |
| 67 |
| 68 LimitState limit_state_; // Current state. |
| 69 LimitState last_limit_state_; // State of last notification update. |
| 70 |
| 71 LabelTrayView* tray_bubble_view_; |
| 66 scoped_ptr<base::RepeatingTimer<TraySessionLengthLimit> > timer_; | 72 scoped_ptr<base::RepeatingTimer<TraySessionLengthLimit> > timer_; |
| 67 | 73 |
| 68 DISALLOW_COPY_AND_ASSIGN(TraySessionLengthLimit); | 74 DISALLOW_COPY_AND_ASSIGN(TraySessionLengthLimit); |
| 69 }; | 75 }; |
| 70 | 76 |
| 71 } // namespace ash | 77 } // namespace ash |
| 72 | 78 |
| 73 #endif // ASH_SYSTEM_CHROMEOS_SESSION_SESSION_LENGTH_LIMIT_H_ | 79 #endif // ASH_SYSTEM_CHROMEOS_SESSION_SESSION_LENGTH_LIMIT_H_ |
| OLD | NEW |