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

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

Issue 2916693002: DetachFromSequence in Timer::Stop() (Closed)
Patch Set: comment nit Created 3 years, 6 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 | « base/timer/timer.h ('k') | no next file » | no next file with comments »
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 #include "base/timer/timer.h" 5 #include "base/timer/timer.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <utility> 9 #include <utility>
10 10
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 user_task_(user_task), 92 user_task_(user_task),
93 is_repeating_(is_repeating), 93 is_repeating_(is_repeating),
94 retain_user_task_(true), 94 retain_user_task_(true),
95 tick_clock_(tick_clock), 95 tick_clock_(tick_clock),
96 is_running_(false) { 96 is_running_(false) {
97 // See comment in other constructor. 97 // See comment in other constructor.
98 origin_sequence_checker_.DetachFromSequence(); 98 origin_sequence_checker_.DetachFromSequence();
99 } 99 }
100 100
101 Timer::~Timer() { 101 Timer::~Timer() {
102 // TODO(gab): Enable this once Stop() properly detaches from sequence. 102 DCHECK(origin_sequence_checker_.CalledOnValidSequence());
103 // DCHECK(origin_sequence_checker_.CalledOnValidSequence());
104 AbandonAndStop(); 103 AbandonAndStop();
105 } 104 }
106 105
107 bool Timer::IsRunning() const { 106 bool Timer::IsRunning() const {
108 DCHECK(origin_sequence_checker_.CalledOnValidSequence()); 107 DCHECK(origin_sequence_checker_.CalledOnValidSequence());
109 return is_running_; 108 return is_running_;
110 } 109 }
111 110
112 TimeDelta Timer::GetCurrentDelay() const { 111 TimeDelta Timer::GetCurrentDelay() const {
113 DCHECK(origin_sequence_checker_.CalledOnValidSequence()); 112 DCHECK(origin_sequence_checker_.CalledOnValidSequence());
(...skipping 23 matching lines...) Expand all
137 136
138 Reset(); 137 Reset();
139 } 138 }
140 139
141 void Timer::Stop() { 140 void Timer::Stop() {
142 // TODO(gab): Enable this when it's no longer called racily from 141 // TODO(gab): Enable this when it's no longer called racily from
143 // RunScheduledTask(): https://crbug.com/587199. 142 // RunScheduledTask(): https://crbug.com/587199.
144 // DCHECK(origin_sequence_checker_.CalledOnValidSequence()); 143 // DCHECK(origin_sequence_checker_.CalledOnValidSequence());
145 144
146 is_running_ = false; 145 is_running_ = false;
146
147 // It's safe to destroy or restart Timer on another sequence after Stop().
148 origin_sequence_checker_.DetachFromSequence();
149
147 if (!retain_user_task_) 150 if (!retain_user_task_)
148 user_task_.Reset(); 151 user_task_.Reset();
149 // No more member accesses here: |this| could be deleted after freeing 152 // No more member accesses here: |this| could be deleted after freeing
150 // |user_task_|. 153 // |user_task_|.
151 } 154 }
152 155
153 void Timer::Reset() { 156 void Timer::Reset() {
154 DCHECK(origin_sequence_checker_.CalledOnValidSequence()); 157 DCHECK(origin_sequence_checker_.CalledOnValidSequence());
155 DCHECK(!user_task_.is_null()); 158 DCHECK(!user_task_.is_null());
156 159
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
254 PostNewScheduledTask(delay_); 257 PostNewScheduledTask(delay_);
255 else 258 else
256 Stop(); 259 Stop();
257 260
258 task.Run(); 261 task.Run();
259 262
260 // No more member accesses here: |this| could be deleted at this point. 263 // No more member accesses here: |this| could be deleted at this point.
261 } 264 }
262 265
263 } // namespace base 266 } // namespace base
OLDNEW
« no previous file with comments | « base/timer/timer.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698