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

Side by Side Diff: third_party/WebKit/Source/core/frame/DOMTimerCoordinator.cpp

Issue 1972663002: Eagerly remove disposed DOMTimers as observers upon completion. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebased Created 4 years, 7 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 | « third_party/WebKit/Source/core/frame/DOMTimerCoordinator.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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "core/frame/DOMTimerCoordinator.h" 5 #include "core/frame/DOMTimerCoordinator.h"
6 6
7 #include "core/dom/ExecutionContext.h" 7 #include "core/dom/ExecutionContext.h"
8 #include "core/frame/DOMTimer.h" 8 #include "core/frame/DOMTimer.h"
9 #include <algorithm> 9 #include <algorithm>
10 10
(...skipping 13 matching lines...) Expand all
24 int timeoutID = nextID(); 24 int timeoutID = nextID();
25 TimeoutMap::AddResult result = m_timers.add(timeoutID, DOMTimer::create(cont ext, action, timeout, singleShot, timeoutID)); 25 TimeoutMap::AddResult result = m_timers.add(timeoutID, DOMTimer::create(cont ext, action, timeout, singleShot, timeoutID));
26 ASSERT(result.isNewEntry); 26 ASSERT(result.isNewEntry);
27 DOMTimer* timer = result.storedValue->value.get(); 27 DOMTimer* timer = result.storedValue->value.get();
28 28
29 timer->suspendIfNeeded(); 29 timer->suspendIfNeeded();
30 30
31 return timeoutID; 31 return timeoutID;
32 } 32 }
33 33
34 void DOMTimerCoordinator::removeTimeoutByID(int timeoutID) 34 DOMTimer* DOMTimerCoordinator::removeTimeoutByID(int timeoutID)
35 { 35 {
36 if (timeoutID <= 0) 36 if (timeoutID <= 0)
37 return; 37 return nullptr;
38 38
39 if (DOMTimer* removedTimer = m_timers.get(timeoutID)) 39 DOMTimer* removedTimer = m_timers.take(timeoutID);
40 if (removedTimer)
40 removedTimer->disposeTimer(); 41 removedTimer->disposeTimer();
41 42
42 m_timers.remove(timeoutID); 43 return removedTimer;
43 } 44 }
44 45
45 DEFINE_TRACE(DOMTimerCoordinator) 46 DEFINE_TRACE(DOMTimerCoordinator)
46 { 47 {
47 visitor->trace(m_timers); 48 visitor->trace(m_timers);
48 } 49 }
49 50
50 int DOMTimerCoordinator::nextID() 51 int DOMTimerCoordinator::nextID()
51 { 52 {
52 while (true) { 53 while (true) {
53 ++m_circularSequentialID; 54 ++m_circularSequentialID;
54 55
55 if (m_circularSequentialID <= 0) 56 if (m_circularSequentialID <= 0)
56 m_circularSequentialID = 1; 57 m_circularSequentialID = 1;
57 58
58 if (!m_timers.contains(m_circularSequentialID)) 59 if (!m_timers.contains(m_circularSequentialID))
59 return m_circularSequentialID; 60 return m_circularSequentialID;
60 } 61 }
61 } 62 }
62 63
63 void DOMTimerCoordinator::setTimerTaskRunner(PassOwnPtr<WebTaskRunner> timerTask Runner) 64 void DOMTimerCoordinator::setTimerTaskRunner(PassOwnPtr<WebTaskRunner> timerTask Runner)
64 { 65 {
65 m_timerTaskRunner = std::move(timerTaskRunner); 66 m_timerTaskRunner = std::move(timerTaskRunner);
66 } 67 }
67 68
68 } // namespace blink 69 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/frame/DOMTimerCoordinator.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698