OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 NET_QUIC_QUIC_ALARM_H_ | 5 #ifndef NET_QUIC_QUIC_ALARM_H_ |
6 #define NET_QUIC_QUIC_ALARM_H_ | 6 #define NET_QUIC_QUIC_ALARM_H_ |
7 | 7 |
8 #include "base/macros.h" | 8 #include "base/macros.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "net/base/net_export.h" | 10 #include "net/base/net_export.h" |
(...skipping 18 matching lines...) Expand all Loading... |
29 // specified time. | 29 // specified time. |
30 virtual QuicTime OnAlarm() = 0; | 30 virtual QuicTime OnAlarm() = 0; |
31 }; | 31 }; |
32 | 32 |
33 explicit QuicAlarm(QuicArenaScopedPtr<Delegate> delegate); | 33 explicit QuicAlarm(QuicArenaScopedPtr<Delegate> delegate); |
34 virtual ~QuicAlarm(); | 34 virtual ~QuicAlarm(); |
35 | 35 |
36 // Sets the alarm to fire at |deadline|. Must not be called while | 36 // Sets the alarm to fire at |deadline|. Must not be called while |
37 // the alarm is set. To reschedule an alarm, call Cancel() first, | 37 // the alarm is set. To reschedule an alarm, call Cancel() first, |
38 // then Set(). | 38 // then Set(). |
39 void Set(QuicTime deadline); | 39 void Set(QuicTime new_deadline); |
40 | 40 |
41 // Cancels the alarm. May be called repeatedly. Does not | 41 // Cancels the alarm. May be called repeatedly. Does not |
42 // guarantee that the underlying scheduling system will remove | 42 // guarantee that the underlying scheduling system will remove |
43 // the alarm's associated task, but guarantees that the | 43 // the alarm's associated task, but guarantees that the |
44 // delegates OnAlarm method will not be called. | 44 // delegates OnAlarm method will not be called. |
45 void Cancel(); | 45 void Cancel(); |
46 | 46 |
47 // Cancels and sets the alarm if the |deadline| is farther from the current | 47 // Cancels and sets the alarm if the |deadline| is farther from the current |
48 // deadline than |granularity|, and otherwise does nothing. If |deadline| is | 48 // deadline than |granularity|, and otherwise does nothing. If |deadline| is |
49 // not initialized, the alarm is cancelled. | 49 // not initialized, the alarm is cancelled. |
50 void Update(QuicTime deadline, QuicTime::Delta granularity); | 50 void Update(QuicTime new_deadline, QuicTime::Delta granularity); |
51 | 51 |
| 52 // Returns true if |deadline_| has been set to a non-zero time. |
52 bool IsSet() const; | 53 bool IsSet() const; |
53 | 54 |
54 QuicTime deadline() const { return deadline_; } | 55 QuicTime deadline() const { return deadline_; } |
55 | 56 |
56 protected: | 57 protected: |
57 // Subclasses implement this method to perform the platform-specific | 58 // Subclasses implement this method to perform the platform-specific |
58 // scheduling of the alarm. Is called from Set() or Fire(), after the | 59 // scheduling of the alarm. Is called from Set() or Fire(), after the |
59 // deadline has been updated. | 60 // deadline has been updated. |
60 virtual void SetImpl() = 0; | 61 virtual void SetImpl() = 0; |
61 | 62 |
(...skipping 13 matching lines...) Expand all Loading... |
75 private: | 76 private: |
76 QuicArenaScopedPtr<Delegate> delegate_; | 77 QuicArenaScopedPtr<Delegate> delegate_; |
77 QuicTime deadline_; | 78 QuicTime deadline_; |
78 | 79 |
79 DISALLOW_COPY_AND_ASSIGN(QuicAlarm); | 80 DISALLOW_COPY_AND_ASSIGN(QuicAlarm); |
80 }; | 81 }; |
81 | 82 |
82 } // namespace net | 83 } // namespace net |
83 | 84 |
84 #endif // NET_QUIC_QUIC_ALARM_H_ | 85 #endif // NET_QUIC_QUIC_ALARM_H_ |
OLD | NEW |