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

Side by Side Diff: third_party/WebKit/Source/platform/Timer.cpp

Issue 2326313003: Revert of Make canceling Timers fast. (Closed)
Patch Set: Created 4 years, 3 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
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2006, 2008 Apple Inc. All rights reserved. 2 * Copyright (C) 2006, 2008 Apple Inc. All rights reserved.
3 * Copyright (C) 2009 Google Inc. All rights reserved. 3 * Copyright (C) 2009 Google Inc. All rights reserved.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions 6 * modification, are permitted provided that the following conditions
7 * are met: 7 * are met:
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
(...skipping 25 matching lines...) Expand all
36 #include <algorithm> 36 #include <algorithm>
37 #include <limits.h> 37 #include <limits.h>
38 #include <limits> 38 #include <limits>
39 #include <math.h> 39 #include <math.h>
40 40
41 namespace blink { 41 namespace blink {
42 42
43 TimerBase::TimerBase(WebTaskRunner* webTaskRunner) 43 TimerBase::TimerBase(WebTaskRunner* webTaskRunner)
44 : m_nextFireTime(0) 44 : m_nextFireTime(0)
45 , m_repeatInterval(0) 45 , m_repeatInterval(0)
46 , m_cancellableTimerTask(nullptr)
46 , m_webTaskRunner(webTaskRunner->clone()) 47 , m_webTaskRunner(webTaskRunner->clone())
47 #if DCHECK_IS_ON() 48 #if DCHECK_IS_ON()
48 , m_thread(currentThread()) 49 , m_thread(currentThread())
49 #endif 50 #endif
50 , m_weakPtrFactory(this)
51 { 51 {
52 ASSERT(m_webTaskRunner); 52 ASSERT(m_webTaskRunner);
53 } 53 }
54 54
55 TimerBase::~TimerBase() 55 TimerBase::~TimerBase()
56 { 56 {
57 stop(); 57 stop();
58 } 58 }
59 59
60 void TimerBase::start(double nextFireInterval, double repeatInterval, const WebT raceLocation& caller) 60 void TimerBase::start(double nextFireInterval, double repeatInterval, const WebT raceLocation& caller)
61 { 61 {
62 ASSERT(m_thread == currentThread()); 62 ASSERT(m_thread == currentThread());
63 63
64 m_location = caller; 64 m_location = caller;
65 m_repeatInterval = repeatInterval; 65 m_repeatInterval = repeatInterval;
66 setNextFireTime(timerMonotonicallyIncreasingTime(), nextFireInterval); 66 setNextFireTime(timerMonotonicallyIncreasingTime(), nextFireInterval);
67 } 67 }
68 68
69 void TimerBase::stop() 69 void TimerBase::stop()
70 { 70 {
71 ASSERT(m_thread == currentThread()); 71 ASSERT(m_thread == currentThread());
72 72
73 m_repeatInterval = 0; 73 m_repeatInterval = 0;
74 m_nextFireTime = 0; 74 m_nextFireTime = 0;
75 m_weakPtrFactory.revokeAll(); 75 if (m_cancellableTimerTask)
76 m_cancellableTimerTask->cancel();
77 m_cancellableTimerTask = nullptr;
76 } 78 }
77 79
78 double TimerBase::nextFireInterval() const 80 double TimerBase::nextFireInterval() const
79 { 81 {
80 ASSERT(isActive()); 82 ASSERT(isActive());
81 double current = timerMonotonicallyIncreasingTime(); 83 double current = timerMonotonicallyIncreasingTime();
82 if (m_nextFireTime < current) 84 if (m_nextFireTime < current)
83 return 0; 85 return 0;
84 return m_nextFireTime - current; 86 return m_nextFireTime - current;
85 } 87 }
(...skipping 16 matching lines...) Expand all
102 } 104 }
103 105
104 void TimerBase::setNextFireTime(double now, double delay) 106 void TimerBase::setNextFireTime(double now, double delay)
105 { 107 {
106 ASSERT(m_thread == currentThread()); 108 ASSERT(m_thread == currentThread());
107 109
108 double newTime = now + delay; 110 double newTime = now + delay;
109 111
110 if (m_nextFireTime != newTime) { 112 if (m_nextFireTime != newTime) {
111 m_nextFireTime = newTime; 113 m_nextFireTime = newTime;
112 114 if (m_cancellableTimerTask)
113 // Cancel any previously posted task. 115 m_cancellableTimerTask->cancel();
114 m_weakPtrFactory.revokeAll(); 116 m_cancellableTimerTask = new CancellableTimerTask(this);
115 117
116 double delayMs = 1000.0 * (newTime - now); 118 double delayMs = 1000.0 * (newTime - now);
117 timerTaskRunner()->postDelayedTask(m_location, base::Bind(&TimerBase::ru nInternal, m_weakPtrFactory.createWeakPtr()), delayMs); 119 timerTaskRunner()->postDelayedTask(m_location, m_cancellableTimerTask, d elayMs);
118 } 120 }
119 } 121 }
120 122
121 NO_LAZY_SWEEP_SANITIZE_ADDRESS 123 NO_LAZY_SWEEP_SANITIZE_ADDRESS
122 void TimerBase::runInternal() 124 void TimerBase::runInternal()
123 { 125 {
124 m_weakPtrFactory.revokeAll();
125
126 if (!canFire()) 126 if (!canFire())
127 return; 127 return;
128 128
129 TRACE_EVENT0("blink", "TimerBase::run"); 129 TRACE_EVENT0("blink", "TimerBase::run");
130 #if DCHECK_IS_ON() 130 #if DCHECK_IS_ON()
131 DCHECK_EQ(m_thread, currentThread()) << "Timer posted by " << m_location.fun ction_name() << " " << m_location.file_name() << " was run on a different thread "; 131 DCHECK_EQ(m_thread, currentThread()) << "Timer posted by " << m_location.fun ction_name() << " " << m_location.file_name() << " was run on a different thread ";
132 #endif 132 #endif
133 TRACE_EVENT_SET_SAMPLING_STATE("blink", "BlinkInternal"); 133 TRACE_EVENT_SET_SAMPLING_STATE("blink", "BlinkInternal");
134 134
135 if (m_repeatInterval) { 135 if (m_repeatInterval) {
(...skipping 16 matching lines...) Expand all
152 return a->m_nextFireTime < b->m_nextFireTime; 152 return a->m_nextFireTime < b->m_nextFireTime;
153 } 153 }
154 154
155 // static 155 // static
156 double TimerBase::timerMonotonicallyIncreasingTime() const 156 double TimerBase::timerMonotonicallyIncreasingTime() const
157 { 157 {
158 return timerTaskRunner()->monotonicallyIncreasingVirtualTimeSeconds(); 158 return timerTaskRunner()->monotonicallyIncreasingVirtualTimeSeconds();
159 } 159 }
160 160
161 } // namespace blink 161 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/platform/Timer.h ('k') | third_party/WebKit/Source/platform/scheduler/base/task_queue_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698