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

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

Issue 2550373005: Make WebTaskRunner ThreadSafeRefCounted (Closed)
Patch Set: mac fix Created 4 years 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(WebTaskRunner* webTaskRunner) 43 TimerBase::TimerBase(RefPtr<WebTaskRunner> webTaskRunner)
44 : m_nextFireTime(0), 44 : m_nextFireTime(0),
45 m_repeatInterval(0), 45 m_repeatInterval(0),
46 m_webTaskRunner(webTaskRunner->clone()), 46 m_webTaskRunner(std::move(webTaskRunner)),
47 #if DCHECK_IS_ON() 47 #if DCHECK_IS_ON()
48 m_thread(currentThread()), 48 m_thread(currentThread()),
49 #endif 49 #endif
50 m_weakPtrFactory(this) { 50 m_weakPtrFactory(this) {
51 ASSERT(m_webTaskRunner); 51 ASSERT(m_webTaskRunner);
52 } 52 }
53 53
54 TimerBase::~TimerBase() { 54 TimerBase::~TimerBase() {
55 stop(); 55 stop();
56 } 56 }
(...skipping 22 matching lines...) Expand all
79 79
80 double TimerBase::nextFireInterval() const { 80 double TimerBase::nextFireInterval() const {
81 ASSERT(isActive()); 81 ASSERT(isActive());
82 double current = timerMonotonicallyIncreasingTime(); 82 double current = timerMonotonicallyIncreasingTime();
83 if (m_nextFireTime < current) 83 if (m_nextFireTime < current)
84 return 0; 84 return 0;
85 return m_nextFireTime - current; 85 return m_nextFireTime - current;
86 } 86 }
87 87
88 // static 88 // static
89 WebTaskRunner* TimerBase::getTimerTaskRunner() { 89 RefPtr<WebTaskRunner> TimerBase::getTimerTaskRunner() {
90 return Platform::current()->currentThread()->scheduler()->timerTaskRunner(); 90 return Platform::current()->currentThread()->scheduler()->timerTaskRunner();
91 } 91 }
92 92
93 // static 93 // static
94 WebTaskRunner* TimerBase::getUnthrottledTaskRunner() { 94 RefPtr<WebTaskRunner> TimerBase::getUnthrottledTaskRunner() {
95 return Platform::current()->currentThread()->getWebTaskRunner(); 95 return Platform::current()->currentThread()->getWebTaskRunner();
96 } 96 }
97 97
98 WebTaskRunner* TimerBase::timerTaskRunner() const { 98 RefPtr<WebTaskRunner> TimerBase::timerTaskRunner() const {
99 return m_webTaskRunner.get(); 99 return m_webTaskRunner;
100 } 100 }
101 101
102 void TimerBase::setNextFireTime(double now, double delay) { 102 void TimerBase::setNextFireTime(double now, double delay) {
103 #if DCHECK_IS_ON() 103 #if DCHECK_IS_ON()
104 DCHECK_EQ(m_thread, currentThread()); 104 DCHECK_EQ(m_thread, currentThread());
105 #endif 105 #endif
106 106
107 double newTime = now + delay; 107 double newTime = now + delay;
108 108
109 if (m_nextFireTime != newTime) { 109 if (m_nextFireTime != newTime) {
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 const TimerBase* b) const { 153 const TimerBase* b) const {
154 return a->m_nextFireTime < b->m_nextFireTime; 154 return a->m_nextFireTime < b->m_nextFireTime;
155 } 155 }
156 156
157 // static 157 // static
158 double TimerBase::timerMonotonicallyIncreasingTime() const { 158 double TimerBase::timerMonotonicallyIncreasingTime() const {
159 return timerTaskRunner()->monotonicallyIncreasingVirtualTimeSeconds(); 159 return timerTaskRunner()->monotonicallyIncreasingVirtualTimeSeconds();
160 } 160 }
161 161
162 } // namespace blink 162 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698