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 "ash/system/tray/view_click_listener.h" | |
10 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
11 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
12 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
14 #include "base/strings/string16.h" | |
13 #include "base/time/time.h" | 15 #include "base/time/time.h" |
14 #include "base/timer/timer.h" | 16 #include "base/timer/timer.h" |
15 | 17 |
16 namespace ash { | 18 namespace ash { |
17 namespace test { | 19 namespace test { |
18 class TraySessionLengthLimitTest; | 20 class TraySessionLengthLimitTest; |
19 } | 21 } |
20 | 22 |
21 namespace tray { | 23 class LabelTrayView; |
22 class RemainingSessionTimeTrayView; | |
23 } | |
24 | 24 |
25 // Adds a countdown timer to the system tray if the session length is limited. | 25 // Adds a countdown timer to the system tray if the session length is limited. |
26 class ASH_EXPORT TraySessionLengthLimit : public SystemTrayItem, | 26 class ASH_EXPORT TraySessionLengthLimit : public SystemTrayItem, |
27 public SessionLengthLimitObserver { | 27 public SessionLengthLimitObserver, |
28 public: | 28 public ViewClickListener { |
29 public: | |
29 enum LimitState { | 30 enum LimitState { |
30 LIMIT_NONE, | 31 LIMIT_NONE, |
31 LIMIT_SET, | 32 LIMIT_SET, |
32 LIMIT_EXPIRING_SOON | 33 LIMIT_EXPIRING_SOON |
33 }; | 34 }; |
34 | 35 |
35 explicit TraySessionLengthLimit(SystemTray* system_tray); | 36 explicit TraySessionLengthLimit(SystemTray* system_tray); |
36 virtual ~TraySessionLengthLimit(); | 37 virtual ~TraySessionLengthLimit(); |
37 | 38 |
38 // SystemTrayItem: | 39 // SystemTrayItem: |
39 virtual views::View* CreateTrayView(user::LoginStatus status) OVERRIDE; | 40 virtual views::View* CreateDefaultView(user::LoginStatus status) OVERRIDE; |
40 virtual void DestroyTrayView() OVERRIDE; | 41 virtual void DestroyDefaultView() OVERRIDE; |
41 virtual void UpdateAfterShelfAlignmentChange( | |
42 ShelfAlignment alignment) OVERRIDE; | |
43 | 42 |
44 // SessionLengthLimitObserver: | 43 // SessionLengthLimitObserver: |
45 virtual void OnSessionStartTimeChanged() OVERRIDE; | 44 virtual void OnSessionStartTimeChanged() OVERRIDE; |
46 virtual void OnSessionLengthLimitChanged() OVERRIDE; | 45 virtual void OnSessionLengthLimitChanged() OVERRIDE; |
47 | 46 |
48 LimitState GetLimitState() const; | 47 // ViewClickListener: |
49 base::TimeDelta GetRemainingSessionTime() const; | 48 virtual void OnViewClicked(views::View* sender) OVERRIDE; |
50 | 49 |
51 private: | 50 private: |
52 friend class test::TraySessionLengthLimitTest; | 51 friend class test::TraySessionLengthLimitTest; |
53 | 52 |
54 static const char kNotificationId[]; | 53 static const char kNotificationId[]; |
55 | 54 |
55 // Update state, notification and tray bubble view. Called by the Timer in | |
bartfab (slow)
2014/05/06 17:57:00
Nit: Why is Timer capitalized? It sounds like a re
Thiemo Nagel
2014/05/06 18:49:06
Thanks, you're right. I'm using a RepeatingTimer.
| |
56 // regular intervals and also by OnSession*Changed(). | |
56 void Update(); | 57 void Update(); |
57 | 58 |
58 bool IsTrayViewVisibleForTest(); | 59 // Recalculate |limit_state_| and |remaining_session_time_|. |
60 void UpdateState(); | |
59 | 61 |
60 tray::RemainingSessionTimeTrayView* tray_view_; | 62 void UpdateNotification(); |
63 void UpdateTrayBubbleView() const; | |
61 | 64 |
62 LimitState limit_state_; | 65 // These require that the state has been updated before. |
66 base::string16 ComposeNotificationMessage() const; | |
67 base::string16 ComposeTrayBubbleMessage() const; | |
68 | |
63 base::TimeTicks session_start_time_; | 69 base::TimeTicks session_start_time_; |
64 base::TimeDelta limit_; | 70 base::TimeDelta time_limit_; |
65 base::TimeDelta remaining_session_time_; | 71 base::TimeDelta remaining_session_time_; |
72 | |
73 LimitState limit_state_; // Current state. | |
bartfab (slow)
2014/05/06 17:57:00
Nit: Style guide says: Two spaces before //, do no
Thiemo Nagel
2014/05/06 18:49:06
Where does it say that?
There is ample evidence o
bartfab (slow)
2014/05/07 12:30:53
I think you are right. I read the JavaScript style
| |
74 LimitState last_limit_state_; // State of last notification update. | |
75 | |
76 LabelTrayView* tray_bubble_view_; | |
66 scoped_ptr<base::RepeatingTimer<TraySessionLengthLimit> > timer_; | 77 scoped_ptr<base::RepeatingTimer<TraySessionLengthLimit> > timer_; |
67 | 78 |
68 DISALLOW_COPY_AND_ASSIGN(TraySessionLengthLimit); | 79 DISALLOW_COPY_AND_ASSIGN(TraySessionLengthLimit); |
69 }; | 80 }; |
70 | 81 |
71 } // namespace ash | 82 } // namespace ash |
72 | 83 |
73 #endif // ASH_SYSTEM_CHROMEOS_SESSION_SESSION_LENGTH_LIMIT_H_ | 84 #endif // ASH_SYSTEM_CHROMEOS_SESSION_SESSION_LENGTH_LIMIT_H_ |
OLD | NEW |