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 #ifndef ASH_SYSTEM_SESSION_LENGTH_LIMIT_TRAY_SESSION_LENGTH_LIMIT_H_ 6 #define ASH_SYSTEM_SESSION_LENGTH_LIMIT_TRAY_SESSION_LENGTH_LIMIT_H_ 7 8 #include "ash/system/session_length_limit/session_length_limit_observer.h" 9 #include "ash/system/tray/system_tray_item.h" 10 #include "base/basictypes.h" 11 #include "base/compiler_specific.h" 12 #include "base/memory/scoped_ptr.h" 13 #include "base/time/time.h" 14 #include "base/timer/timer.h" 15 16 namespace ash { 17 18 namespace test { 19 class TraySessionLengthLimitTest; 20 } 21 22 namespace internal { 23 24 namespace tray { 25 class RemainingSessionTimeTrayView; 26 } 27 28 // Adds a countdown timer to the system tray if the session length is limited. 29 class ASH_EXPORT TraySessionLengthLimit : public SystemTrayItem, 30 public SessionLengthLimitObserver { 31 public: 32 enum LimitState { 33 LIMIT_NONE, 34 LIMIT_SET, 35 LIMIT_EXPIRING_SOON 36 }; 37 38 explicit TraySessionLengthLimit(SystemTray* system_tray); 39 virtual ~TraySessionLengthLimit(); 40 41 // SystemTrayItem: 42 virtual views::View* CreateTrayView(user::LoginStatus status) OVERRIDE; 43 virtual void DestroyTrayView() OVERRIDE; 44 virtual void UpdateAfterShelfAlignmentChange( 45 ShelfAlignment alignment) OVERRIDE; 46 47 // SessionLengthLimitObserver: 48 virtual void OnSessionStartTimeChanged() OVERRIDE; 49 virtual void OnSessionLengthLimitChanged() OVERRIDE; 50 51 LimitState GetLimitState() const; 52 base::TimeDelta GetRemainingSessionTime() const; 53 54 private: 55 friend class test::TraySessionLengthLimitTest; 56 57 static const char kNotificationId[]; 58 59 void Update(); 60 61 bool IsTrayViewVisibleForTest(); 62 63 tray::RemainingSessionTimeTrayView* tray_view_; 64 65 LimitState limit_state_; 66 base::TimeTicks session_start_time_; 67 base::TimeDelta limit_; 68 base::TimeDelta remaining_session_time_; 69 scoped_ptr<base::RepeatingTimer<TraySessionLengthLimit> > timer_; 70 71 DISALLOW_COPY_AND_ASSIGN(TraySessionLengthLimit); 72 }; 73 74 } // namespace internal 75 } // namespace ash 76 77 #endif // ASH_SYSTEM_SESSION_LENGTH_LIMIT_TRAY_SESSION_LENGTH_LIMIT_H_ 78