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 #include "components/timers/alarm_timer.h" | 5 #include "components/timers/alarm_timer.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
9 #include "base/files/file_util.h" | 9 #include "base/files/file_util.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 27 matching lines...) Expand all Loading... | |
38 Stop(); | 38 Stop(); |
39 } | 39 } |
40 | 40 |
41 void AlarmTimer::Stop() { | 41 void AlarmTimer::Stop() { |
42 if (!can_wake_from_suspend_) { | 42 if (!can_wake_from_suspend_) { |
43 base::Timer::Stop(); | 43 base::Timer::Stop(); |
44 return; | 44 return; |
45 } | 45 } |
46 | 46 |
47 // Clear the running flag, stop the delegate, and delete the pending task. | 47 // Clear the running flag, stop the delegate, and delete the pending task. |
48 base::Timer::set_is_running(false); | 48 base::Timer::set_is_running(false); |
gromer
2014/12/05 20:13:40
Why not just "set_is_running(false)"? It's necessa
Chirantan Ekbote
2014/12/31 00:58:29
Yes it's not really necessary but I find that it i
| |
49 delegate_->Stop(); | 49 delegate_->Stop(); |
50 pending_task_.reset(); | 50 pending_task_.reset(); |
51 | 51 |
52 // Stop is called when the AlarmTimer is destroyed so we need to remove | 52 // Stop is called when the AlarmTimer is destroyed so we need to remove |
53 // ourselves as a MessageLoop::DestructionObserver to prevent a segfault | 53 // ourselves as a MessageLoop::DestructionObserver to prevent a segfault |
54 // later. | 54 // later. |
55 if (origin_message_loop_) { | 55 if (origin_message_loop_) { |
56 origin_message_loop_->RemoveDestructionObserver(this); | 56 origin_message_loop_->RemoveDestructionObserver(this); |
57 origin_message_loop_ = NULL; | 57 origin_message_loop_ = NULL; |
58 } | 58 } |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
93 } | 93 } |
94 base::MessageLoop::current()->task_annotator()->DidQueueTask( | 94 base::MessageLoop::current()->task_annotator()->DidQueueTask( |
95 "AlarmTimer::Reset", *pending_task_); | 95 "AlarmTimer::Reset", *pending_task_); |
96 | 96 |
97 // Now start up the timer. | 97 // Now start up the timer. |
98 delegate_->Reset(base::Timer::GetCurrentDelay()); | 98 delegate_->Reset(base::Timer::GetCurrentDelay()); |
99 base::Timer::set_is_running(true); | 99 base::Timer::set_is_running(true); |
100 } | 100 } |
101 | 101 |
102 void AlarmTimer::WillDestroyCurrentMessageLoop() { | 102 void AlarmTimer::WillDestroyCurrentMessageLoop() { |
103 Stop(); | 103 Stop(); |
gromer
2014/12/05 20:13:40
Could you avoid all the AddDestructionObserver()/R
Chirantan Ekbote
2014/12/31 00:58:29
I'm not sure what you mean by this. I would still
gromer
2015/02/10 23:47:10
Yeah, I'm not sure what I meant by this either.
| |
104 } | 104 } |
105 | 105 |
106 void AlarmTimer::OnTimerFired() { | 106 void AlarmTimer::OnTimerFired() { |
107 if (!base::Timer::is_running()) | 107 if (!base::Timer::is_running()) |
108 return; | 108 return; |
109 | 109 |
110 DCHECK(pending_task_.get()); | 110 DCHECK(pending_task_.get()); |
111 | 111 |
112 // Take ownership of the pending user task, which is going to be cleared by | 112 // Take ownership of the pending user task, which is going to be cleared by |
113 // the Stop() or Reset() functions below. | 113 // the Stop() or Reset() functions below. |
114 scoped_ptr<base::PendingTask> pending_user_task(pending_task_.Pass()); | 114 scoped_ptr<base::PendingTask> pending_user_task(pending_task_.Pass()); |
115 | 115 |
116 // Re-schedule or stop the timer as requested. | 116 // Re-schedule or stop the timer as requested. |
117 if (base::Timer::is_repeating()) | 117 if (base::Timer::is_repeating()) |
118 Reset(); | 118 Reset(); |
119 else | 119 else |
120 Stop(); | 120 Stop(); |
121 | 121 |
122 // Now run the user task. | 122 // Now run the user task. |
123 base::MessageLoop::current()->task_annotator()->RunTask( | 123 base::MessageLoop::current()->task_annotator()->RunTask( |
124 "AlarmTimer::Reset", "AlarmTimer::OnTimerFired", *pending_user_task); | 124 "AlarmTimer::Reset", "AlarmTimer::OnTimerFired", *pending_user_task); |
125 } | 125 } |
126 | 126 |
127 | |
127 } // namespace timers | 128 } // namespace timers |
OLD | NEW |