Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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. | |
| 4 | |
| 5 #ifndef BASE_TIMER_ALARM_TIMER_CHROMEOS_H_ | |
| 6 #define BASE_TIMER_ALARM_TIMER_CHROMEOS_H_ | |
| 7 | |
| 8 #include "base/base_export.h" | |
| 9 #include "base/callback.h" | |
| 10 #include "base/macros.h" | |
| 11 #include "base/memory/ref_counted.h" | |
| 12 #include "base/memory/weak_ptr.h" | |
| 13 #include "base/message_loop/message_loop.h" | |
| 14 #include "base/time/time.h" | |
| 15 #include "base/timer/timer.h" | |
| 16 | |
| 17 namespace base { | |
| 18 | |
| 19 struct PendingTask; | |
| 20 | |
| 21 // The class implements a timer that is capable of waking the system up from a | |
| 22 // suspended state. For example, this is useful for running tasks that are | |
| 23 // needed for maintaining network connectivity, like sending heartbeat messages. | |
| 24 // Currently, this feature is only available on Chrome OS systems running linux | |
| 25 // version 3.11 or higher. On all other platforms, the AlarmTimer behaves | |
| 26 // exactly the same way as a regular Timer. | |
| 27 class BASE_EXPORT AlarmTimer : public Timer, | |
| 28 public MessageLoop::DestructionObserver { | |
| 29 public: | |
| 30 // The delegate is responsible for managing the system level details for | |
| 31 // actually setting up and monitoring a timer that is capable of waking the | |
| 32 // system from suspend. This class is reference counted because it may need | |
| 33 // to outlive the timer in order to clean up after itself. | |
| 34 class Delegate : public RefCountedThreadSafe<Delegate> { | |
| 35 public: | |
| 36 // Initializes the timer. Should return true iff the system has timers that | |
| 37 // can wake it up from suspend. Will only be called once. | |
| 38 virtual bool Init(WeakPtr<AlarmTimer> timer) = 0; | |
| 39 | |
| 40 // Stop the currently running timer. It should be safe to call this more | |
|
Daniel Erat
2014/10/15 15:04:22
nit: s/Stop/Stops/
Chirantan Ekbote
2014/10/16 21:26:38
Done.
| |
| 41 // than once. | |
| 42 virtual void Stop() = 0; | |
| 43 | |
| 44 // Reset the timer to fire after |delay| amount of time has passed. Cancels | |
|
Daniel Erat
2014/10/15 15:04:22
nit: s/Reset/Resets/; can also remove "amount of t
Chirantan Ekbote
2014/10/16 21:26:38
Done.
| |
| 45 // any pre-existing delay. | |
| 46 virtual void Reset(TimeDelta delay) = 0; | |
| 47 | |
| 48 protected: | |
| 49 virtual ~Delegate() {}; | |
| 50 | |
| 51 private: | |
| 52 friend class RefCountedThreadSafe<Delegate>; | |
| 53 }; | |
| 54 | |
| 55 AlarmTimer(bool retain_user_task, bool is_repeating); | |
| 56 | |
| 57 AlarmTimer(const tracked_objects::Location& posted_from, | |
| 58 TimeDelta delay, | |
| 59 const Closure& user_task, | |
| 60 bool is_repeating); | |
| 61 | |
| 62 virtual ~AlarmTimer(); | |
| 63 | |
| 64 // Timer overrides. | |
| 65 virtual bool IsRunning() const override; | |
| 66 virtual TimeDelta GetCurrentDelay() const override; | |
| 67 virtual void Start(const tracked_objects::Location& posted_from, | |
| 68 TimeDelta delay, | |
| 69 const Closure& user_task) override; | |
| 70 virtual void Stop() override; | |
| 71 virtual void Reset() override; | |
| 72 | |
| 73 // MessageLoop::DestructionObserver overrides. | |
| 74 virtual void WillDestroyCurrentMessageLoop() override; | |
| 75 | |
| 76 // Must be called by the delegate to indicate that the timer has fired and | |
| 77 // that the user task should be run. | |
| 78 void OnTimerFired(); | |
| 79 | |
| 80 private: | |
| 81 // Delegate that will manage actually setting the timer. | |
| 82 scoped_refptr<Delegate> delegate_; | |
| 83 | |
| 84 // Keeps track of the user task we want to run. A new one is constructed | |
| 85 // every timer Reset() is called. | |
| 86 scoped_ptr<PendingTask> pending_task_; | |
| 87 | |
| 88 // Tracks whether the timer has the ability to wake the system up from | |
| 89 // suspend. This is a runtime check because we won't know if the system | |
| 90 // supports being woken up from suspend until the delegate actually tries to | |
| 91 // set it up. | |
| 92 bool can_wake_from_suspend_; | |
| 93 | |
| 94 // Pointer to the message loop that started the timer. Used to track the | |
| 95 // destruction of that message loop. | |
| 96 MessageLoop* origin_message_loop_; | |
| 97 | |
| 98 WeakPtrFactory<AlarmTimer> weak_factory_; | |
| 99 | |
| 100 DISALLOW_COPY_AND_ASSIGN(AlarmTimer); | |
| 101 }; | |
| 102 | |
| 103 } // namespace base | |
|
Daniel Erat
2014/10/15 15:04:22
nit: add blank line after this one
Chirantan Ekbote
2014/10/16 21:26:38
Done.
| |
| 104 #endif // BASE_TIMER_ALARM_TIMER_CHROMEOS_H_ | |
| OLD | NEW |