Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / ash / system / chromeos / session / tray_session_length_limit.h
blob8afe5aa85dbd20a9be57ec114c6f4bfcdb281afe
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
3 // found in the LICENSE file.
5 #ifndef ASH_SYSTEM_CHROMEOS_SESSION_SESSION_LENGTH_LIMIT_H_
6 #define ASH_SYSTEM_CHROMEOS_SESSION_SESSION_LENGTH_LIMIT_H_
8 #include "ash/system/chromeos/session/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/strings/string16.h"
14 #include "base/time/time.h"
15 #include "base/timer/timer.h"
17 namespace ash {
18 namespace test {
19 class TraySessionLengthLimitTest;
22 class LabelTrayView;
24 // Adds a countdown timer to the system tray if the session length is limited.
25 class ASH_EXPORT TraySessionLengthLimit : public SystemTrayItem,
26 public SessionLengthLimitObserver {
27 public:
28 enum LimitState {
29 LIMIT_NONE,
30 LIMIT_SET,
31 LIMIT_EXPIRING_SOON
34 explicit TraySessionLengthLimit(SystemTray* system_tray);
35 ~TraySessionLengthLimit() override;
37 // SystemTrayItem:
38 views::View* CreateDefaultView(user::LoginStatus status) override;
39 void DestroyDefaultView() override;
41 // SessionLengthLimitObserver:
42 void OnSessionStartTimeChanged() override;
43 void OnSessionLengthLimitChanged() override;
45 private:
46 friend class test::TraySessionLengthLimitTest;
48 static const char kNotificationId[];
50 // Update state, notification and tray bubble view. Called by the
51 // RepeatingTimer in regular intervals and also by OnSession*Changed().
52 void Update();
54 // Recalculate |limit_state_| and |remaining_session_time_|.
55 void UpdateState();
57 void UpdateNotification();
58 void UpdateTrayBubbleView() const;
60 // These require that the state has been updated before.
61 base::string16 ComposeNotificationMessage() const;
62 base::string16 ComposeTrayBubbleMessage() const;
64 base::TimeTicks session_start_time_;
65 base::TimeDelta time_limit_;
66 base::TimeDelta remaining_session_time_;
68 LimitState limit_state_; // Current state.
69 LimitState last_limit_state_; // State of last notification update.
71 LabelTrayView* tray_bubble_view_;
72 scoped_ptr<base::RepeatingTimer<TraySessionLengthLimit> > timer_;
74 DISALLOW_COPY_AND_ASSIGN(TraySessionLengthLimit);
77 } // namespace ash
79 #endif // ASH_SYSTEM_CHROMEOS_SESSION_SESSION_LENGTH_LIMIT_H_