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

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

Issue 2191533003: Refactor Timer classes in preparation for landing FrameTimers. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 4 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 22 matching lines...) Expand all
33 #include "wtf/Atomics.h" 33 #include "wtf/Atomics.h"
34 #include "wtf/CurrentTime.h" 34 #include "wtf/CurrentTime.h"
35 #include "wtf/HashSet.h" 35 #include "wtf/HashSet.h"
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() : TimerBase(Platform::current()->currentThread()->schedul er()->timerTaskRunner()) { }
44
45 TimerBase::TimerBase(WebTaskRunner* webTaskRunner) 43 TimerBase::TimerBase(WebTaskRunner* webTaskRunner)
46 : m_nextFireTime(0) 44 : m_nextFireTime(0)
47 , m_repeatInterval(0) 45 , m_repeatInterval(0)
48 , m_cancellableTimerTask(nullptr) 46 , m_cancellableTimerTask(nullptr)
49 , m_webTaskRunner(webTaskRunner) 47 , m_webTaskRunner(webTaskRunner)
50 #if DCHECK_IS_ON() 48 #if DCHECK_IS_ON()
51 , m_thread(currentThread()) 49 , m_thread(currentThread())
52 #endif 50 #endif
53 { 51 {
54 ASSERT(m_webTaskRunner); 52 ASSERT(m_webTaskRunner);
(...skipping 26 matching lines...) Expand all
81 79
82 double TimerBase::nextFireInterval() const 80 double TimerBase::nextFireInterval() const
83 { 81 {
84 ASSERT(isActive()); 82 ASSERT(isActive());
85 double current = timerMonotonicallyIncreasingTime(); 83 double current = timerMonotonicallyIncreasingTime();
86 if (m_nextFireTime < current) 84 if (m_nextFireTime < current)
87 return 0; 85 return 0;
88 return m_nextFireTime - current; 86 return m_nextFireTime - current;
89 } 87 }
90 88
89 // static
90 WebTaskRunner* TimerBase::getTimerTaskRunner()
91 {
92 return Platform::current()->currentThread()->scheduler()->timerTaskRunner();
93 }
94
95 // static
96 WebTaskRunner* TimerBase::getDefaultTaskRunner()
97 {
98 return Platform::current()->currentThread()->getWebTaskRunner();
99 }
100
91 WebTaskRunner* TimerBase::timerTaskRunner() const 101 WebTaskRunner* TimerBase::timerTaskRunner() const
92 { 102 {
93 return m_webTaskRunner; 103 return m_webTaskRunner;
94 } 104 }
95 105
96 void TimerBase::setNextFireTime(double now, double delay) 106 void TimerBase::setNextFireTime(double now, double delay)
97 { 107 {
98 ASSERT(m_thread == currentThread()); 108 ASSERT(m_thread == currentThread());
99 109
100 double newTime = now + delay; 110 double newTime = now + delay;
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 fired(); 146 fired();
137 TRACE_EVENT_SET_SAMPLING_STATE("blink", "Sleeping"); 147 TRACE_EVENT_SET_SAMPLING_STATE("blink", "Sleeping");
138 } 148 }
139 149
140 bool TimerBase::Comparator::operator()(const TimerBase* a, const TimerBase* b) c onst 150 bool TimerBase::Comparator::operator()(const TimerBase* a, const TimerBase* b) c onst
141 { 151 {
142 return a->m_nextFireTime < b->m_nextFireTime; 152 return a->m_nextFireTime < b->m_nextFireTime;
143 } 153 }
144 154
145 // static 155 // static
146 WebTaskRunner* TimerBase::UnthrottledWebTaskRunner()
147 {
148 return Platform::current()->currentThread()->getWebTaskRunner();
149 }
150
151 double TimerBase::timerMonotonicallyIncreasingTime() const 156 double TimerBase::timerMonotonicallyIncreasingTime() const
152 { 157 {
153 return timerTaskRunner()->monotonicallyIncreasingVirtualTimeSeconds(); 158 return timerTaskRunner()->monotonicallyIncreasingVirtualTimeSeconds();
154 } 159 }
155 160
156 } // namespace blink 161 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698