| 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_SESSION_TRAY_SESSION_LENGTH_LIMIT_H_ | 5 #ifndef ASH_SYSTEM_SESSION_TRAY_SESSION_LENGTH_LIMIT_H_ |
| 6 #define ASH_SYSTEM_SESSION_TRAY_SESSION_LENGTH_LIMIT_H_ | 6 #define ASH_SYSTEM_SESSION_TRAY_SESSION_LENGTH_LIMIT_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 | 9 |
| 10 #include "ash/system/session/session_length_limit_observer.h" | 10 #include "ash/session/session_observer.h" |
| 11 #include "ash/system/tray/system_tray_item.h" | 11 #include "ash/system/tray/system_tray_item.h" |
| 12 #include "base/macros.h" | 12 #include "base/macros.h" |
| 13 #include "base/strings/string16.h" | 13 #include "base/strings/string16.h" |
| 14 #include "base/time/time.h" | 14 #include "base/time/time.h" |
| 15 #include "base/timer/timer.h" | 15 #include "base/timer/timer.h" |
| 16 | 16 |
| 17 namespace ash { | 17 namespace ash { |
| 18 namespace test { | 18 namespace test { |
| 19 class TraySessionLengthLimitTest; | 19 class TraySessionLengthLimitTest; |
| 20 } | 20 } |
| 21 | 21 |
| 22 class LabelTrayView; | 22 class LabelTrayView; |
| 23 | 23 |
| 24 // 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. |
| 25 class ASH_EXPORT TraySessionLengthLimit : public SystemTrayItem, | 25 class ASH_EXPORT TraySessionLengthLimit : public SystemTrayItem, |
| 26 public SessionLengthLimitObserver { | 26 public SessionObserver { |
| 27 public: | 27 public: |
| 28 enum LimitState { LIMIT_NONE, LIMIT_SET, LIMIT_EXPIRING_SOON }; | 28 enum LimitState { LIMIT_NONE, LIMIT_SET, LIMIT_EXPIRING_SOON }; |
| 29 | 29 |
| 30 explicit TraySessionLengthLimit(SystemTray* system_tray); | 30 explicit TraySessionLengthLimit(SystemTray* system_tray); |
| 31 ~TraySessionLengthLimit() override; | 31 ~TraySessionLengthLimit() override; |
| 32 | 32 |
| 33 // SystemTrayItem: | 33 // SystemTrayItem: |
| 34 views::View* CreateDefaultView(LoginStatus status) override; | 34 views::View* CreateDefaultView(LoginStatus status) override; |
| 35 void OnDefaultViewDestroyed() override; | 35 void OnDefaultViewDestroyed() override; |
| 36 | 36 |
| 37 // SessionLengthLimitObserver: | 37 // SessionObserver: |
| 38 void OnSessionStartTimeChanged() override; | |
| 39 void OnSessionLengthLimitChanged() override; | 38 void OnSessionLengthLimitChanged() override; |
| 40 | 39 |
| 41 private: | 40 private: |
| 42 friend class test::TraySessionLengthLimitTest; | 41 friend class test::TraySessionLengthLimitTest; |
| 43 | 42 |
| 44 static const char kNotificationId[]; | 43 static const char kNotificationId[]; |
| 45 | 44 |
| 46 // Update state, notification and tray bubble view. Called by the | 45 // Update state, notification and tray bubble view. Called by the |
| 47 // RepeatingTimer in regular intervals and also by OnSession*Changed(). | 46 // RepeatingTimer in regular intervals and also by OnSession*Changed(). |
| 48 void Update(); | 47 void Update(); |
| 49 | 48 |
| 50 // Recalculate |limit_state_| and |remaining_session_time_|. | 49 // Recalculate |limit_state_| and |remaining_session_time_|. |
| 51 void UpdateState(); | 50 void UpdateState(); |
| 52 | 51 |
| 53 void UpdateNotification(); | 52 void UpdateNotification(); |
| 54 void UpdateTrayBubbleView() const; | 53 void UpdateTrayBubbleView() const; |
| 55 | 54 |
| 56 // These require that the state has been updated before. | 55 // These require that the state has been updated before. |
| 57 base::string16 ComposeNotificationMessage() const; | 56 base::string16 ComposeNotificationMessage() const; |
| 58 base::string16 ComposeTrayBubbleMessage() const; | 57 base::string16 ComposeTrayBubbleMessage() const; |
| 59 | 58 |
| 60 base::TimeTicks session_start_time_; | |
| 61 base::TimeDelta time_limit_; | |
| 62 base::TimeDelta remaining_session_time_; | 59 base::TimeDelta remaining_session_time_; |
| 63 | 60 |
| 64 LimitState limit_state_; // Current state. | 61 LimitState limit_state_; // Current state. |
| 65 LimitState last_limit_state_; // State of last notification update. | 62 LimitState last_limit_state_; // State of last notification update. |
| 66 | 63 |
| 67 LabelTrayView* tray_bubble_view_; | 64 LabelTrayView* tray_bubble_view_; |
| 68 std::unique_ptr<base::RepeatingTimer> timer_; | 65 std::unique_ptr<base::RepeatingTimer> timer_; |
| 69 | 66 |
| 70 DISALLOW_COPY_AND_ASSIGN(TraySessionLengthLimit); | 67 DISALLOW_COPY_AND_ASSIGN(TraySessionLengthLimit); |
| 71 }; | 68 }; |
| 72 | 69 |
| 73 } // namespace ash | 70 } // namespace ash |
| 74 | 71 |
| 75 #endif // ASH_SYSTEM_SESSION_TRAY_SESSION_LENGTH_LIMIT_H_ | 72 #endif // ASH_SYSTEM_SESSION_TRAY_SESSION_LENGTH_LIMIT_H_ |
| OLD | NEW |