Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(140)

Side by Side Diff: base/timer/timer.h

Issue 2958003002: Expose Timer::AbandonAndStop, so it can safely be destroyed on another thread. (Closed)
Patch Set: Removed AbandonAndStop and made Stop abandon. Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | base/timer/timer.cc » ('j') | base/timer/timer.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 // OneShotTimer and RepeatingTimer provide a simple timer API. As the names 5 // OneShotTimer and RepeatingTimer provide a simple timer API. As the names
6 // suggest, OneShotTimer calls you back once after a time delay expires. 6 // suggest, OneShotTimer calls you back once after a time delay expires.
7 // RepeatingTimer on the other hand calls you back periodically with the 7 // RepeatingTimer on the other hand calls you back periodically with the
8 // prescribed time interval. 8 // prescribed time interval.
9 // 9 //
10 // OneShotTimer and RepeatingTimer both cancel the timer when they go out of 10 // OneShotTimer and RepeatingTimer both cancel the timer when they go out of
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 // means |user_task_| can run after ~Timer() and should support that). 116 // means |user_task_| can run after ~Timer() and should support that).
117 void SetTaskRunner(scoped_refptr<SequencedTaskRunner> task_runner); 117 void SetTaskRunner(scoped_refptr<SequencedTaskRunner> task_runner);
118 118
119 // Start the timer to run at the given |delay| from now. If the timer is 119 // Start the timer to run at the given |delay| from now. If the timer is
120 // already running, it will be replaced to call the given |user_task|. 120 // already running, it will be replaced to call the given |user_task|.
121 virtual void Start(const tracked_objects::Location& posted_from, 121 virtual void Start(const tracked_objects::Location& posted_from,
122 TimeDelta delay, 122 TimeDelta delay,
123 const base::Closure& user_task); 123 const base::Closure& user_task);
124 124
125 // Call this method to stop and cancel the timer. It is a no-op if the timer 125 // Call this method to stop and cancel the timer. It is a no-op if the timer
126 // is not running. 126 // is not running. Abandons any scheduled task.
127 virtual void Stop(); 127 virtual void Stop();
128 128
129 // Call this method to reset the timer delay. The |user_task_| must be set. If 129 // Call this method to reset the timer delay. The |user_task_| must be set. If
130 // the timer is not running, this will start it by posting a task. 130 // the timer is not running, this will start it by posting a task.
131 virtual void Reset(); 131 virtual void Reset();
132 132
133 const base::Closure& user_task() const { return user_task_; } 133 const base::Closure& user_task() const { return user_task_; }
134 const TimeTicks& desired_run_time() const { return desired_run_time_; } 134 const TimeTicks& desired_run_time() const { return desired_run_time_; }
135 135
136 protected: 136 protected:
(...skipping 22 matching lines...) Expand all
159 // sequence is returned. 159 // sequence is returned.
160 scoped_refptr<SequencedTaskRunner> GetTaskRunner(); 160 scoped_refptr<SequencedTaskRunner> GetTaskRunner();
161 161
162 // Disable |scheduled_task_| and abandon it so that it no longer refers back 162 // Disable |scheduled_task_| and abandon it so that it no longer refers back
163 // to this object. 163 // to this object.
164 void AbandonScheduledTask(); 164 void AbandonScheduledTask();
165 165
166 // Called by BaseTimerTaskInternal when the delayed task fires. 166 // Called by BaseTimerTaskInternal when the delayed task fires.
167 void RunScheduledTask(); 167 void RunScheduledTask();
168 168
169 // Stop running task (if any) and abandon scheduled task (if any).
170 void AbandonAndStop() {
171 AbandonScheduledTask();
172
173 Stop();
174 // No more member accesses here: |this| could be deleted at this point.
175 }
176
177 // When non-null, the |scheduled_task_| was posted to call RunScheduledTask() 169 // When non-null, the |scheduled_task_| was posted to call RunScheduledTask()
178 // at |scheduled_run_time_|. 170 // at |scheduled_run_time_|.
179 BaseTimerTaskInternal* scheduled_task_; 171 BaseTimerTaskInternal* scheduled_task_;
180 172
181 // The task runner on which the task should be scheduled. If it is null, the 173 // The task runner on which the task should be scheduled. If it is null, the
182 // task runner for the current sequence will be used. 174 // task runner for the current sequence will be used.
183 scoped_refptr<SequencedTaskRunner> task_runner_; 175 scoped_refptr<SequencedTaskRunner> task_runner_;
184 176
185 // Location in user code. 177 // Location in user code.
186 tracked_objects::Location posted_from_; 178 tracked_objects::Location posted_from_;
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
309 // to link in MSVC. But clang-plugin does not allow inline definitions of 301 // to link in MSVC. But clang-plugin does not allow inline definitions of
310 // virtual methods, so the inline definition lives in the header file here 302 // virtual methods, so the inline definition lives in the header file here
311 // to satisfy both. 303 // to satisfy both.
312 inline void DelayTimer::Reset() { 304 inline void DelayTimer::Reset() {
313 Timer::Reset(); 305 Timer::Reset();
314 } 306 }
315 307
316 } // namespace base 308 } // namespace base
317 309
318 #endif // BASE_TIMER_TIMER_H_ 310 #endif // BASE_TIMER_TIMER_H_
OLDNEW
« no previous file with comments | « no previous file | base/timer/timer.cc » ('j') | base/timer/timer.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698