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

Side by Side Diff: fpdfsdk/javascript/JS_Object.cpp

Issue 2221513002: Remove another potential stale CJS_Timer usage (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: rework, weak refs, single deletion path 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 // Copyright 2014 PDFium Authors. All rights reserved. 1 // Copyright 2014 PDFium 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 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6 6
7 #include "fpdfsdk/javascript/JS_Object.h" 7 #include "fpdfsdk/javascript/JS_Object.h"
8 8
9 #include "fpdfsdk/include/fsdk_mgr.h" 9 #include "fpdfsdk/include/fsdk_mgr.h"
10 #include "fpdfsdk/javascript/JS_Define.h" 10 #include "fpdfsdk/javascript/JS_Define.h"
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 : m_nTimerID(0), 83 : m_nTimerID(0),
84 m_pEmbedObj(pObj), 84 m_pEmbedObj(pObj),
85 m_bProcessing(false), 85 m_bProcessing(false),
86 m_bValid(true), 86 m_bValid(true),
87 m_nType(nType), 87 m_nType(nType),
88 m_dwTimeOut(dwTimeOut), 88 m_dwTimeOut(dwTimeOut),
89 m_swJScript(script), 89 m_swJScript(script),
90 m_pRuntime(pRuntime), 90 m_pRuntime(pRuntime),
91 m_pApp(pApp) { 91 m_pApp(pApp) {
92 CFX_SystemHandler* pHandler = m_pApp->GetSysHandler(); 92 CFX_SystemHandler* pHandler = m_pApp->GetSysHandler();
93 m_nTimerID = pHandler->SetTimer(dwElapse, TimerProc); 93 m_nTimerID = pHandler->SetTimer(dwElapse, Trigger);
94 (*GetGlobalTimerMap())[m_nTimerID] = this; 94 (*GetGlobalTimerMap())[m_nTimerID] = this;
95 m_pRuntime->AddObserver(this); 95 m_pRuntime->AddObserver(this);
96 } 96 }
97 97
98 CJS_Timer::~CJS_Timer() { 98 CJS_Timer::~CJS_Timer() {
99 CJS_Runtime* pRuntime = GetRuntime(); 99 CJS_Runtime* pRuntime = GetRuntime();
100 if (pRuntime) 100 if (pRuntime)
101 pRuntime->RemoveObserver(this); 101 pRuntime->RemoveObserver(this);
102 KillJSTimer();
103 }
104 102
105 void CJS_Timer::KillJSTimer() { 103 if (!m_nTimerID)
Lei Zhang 2016/08/05 22:29:54 I wonder if this can eval to true.
Tom Sepez 2016/08/05 23:11:42 Probably not. The CTOR sets this to zero, so if w
106 if (m_nTimerID) { 104 return;
107 if (m_bValid) { 105
108 CFX_SystemHandler* pHandler = m_pApp->GetSysHandler(); 106 if (m_bValid)
109 pHandler->KillTimer(m_nTimerID); 107 m_pApp->GetSysHandler()->KillTimer(m_nTimerID);
110 } 108
111 GetGlobalTimerMap()->erase(m_nTimerID); 109 GetGlobalTimerMap()->erase(m_nTimerID);
112 m_nTimerID = 0;
113 }
114 } 110 }
115 111
116 // static 112 // static
117 void CJS_Timer::TimerProc(int idEvent) { 113 void CJS_Timer::Trigger(int nTimerID) {
118 auto it = GetGlobalTimerMap()->find(idEvent); 114 auto it = GetGlobalTimerMap()->find(nTimerID);
119 if (it == GetGlobalTimerMap()->end()) 115 if (it == GetGlobalTimerMap()->end())
120 return; 116 return;
121 117
122 CJS_Timer* pTimer = it->second; 118 CJS_Timer* pTimer = it->second;
123 if (pTimer->m_bProcessing) 119 if (pTimer->m_bProcessing)
124 return; 120 return;
125 121
126 pTimer->m_bProcessing = true; 122 pTimer->m_bProcessing = true;
127 if (pTimer->m_pEmbedObj) 123 if (pTimer->m_pEmbedObj)
128 pTimer->m_pEmbedObj->TimerProc(pTimer); 124 pTimer->m_pEmbedObj->TimerProc(pTimer);
129 125
130 // Timer proc may have destroyed timer, find it again. 126 // Timer proc may have destroyed timer, find it again.
131 it = GetGlobalTimerMap()->find(idEvent); 127 it = GetGlobalTimerMap()->find(nTimerID);
132 if (it == GetGlobalTimerMap()->end()) 128 if (it == GetGlobalTimerMap()->end())
133 return; 129 return;
134 130
135 pTimer = it->second; 131 pTimer = it->second;
136 pTimer->m_bProcessing = false; 132 pTimer->m_bProcessing = false;
133 if (pTimer->IsOneTime())
134 pTimer->m_pEmbedObj->CancelProc(pTimer);
137 } 135 }
138 136
139 // static 137 // static
138 void CJS_Timer::Cancel(int nTimerID) {
139 auto it = GetGlobalTimerMap()->find(nTimerID);
140 if (it == GetGlobalTimerMap()->end())
141 return;
142
143 CJS_Timer* pTimer = it->second;
144 pTimer->m_pEmbedObj->CancelProc(pTimer);
145 }
146
147 // static
140 CJS_Timer::TimerMap* CJS_Timer::GetGlobalTimerMap() { 148 CJS_Timer::TimerMap* CJS_Timer::GetGlobalTimerMap() {
141 // Leak the timer array at shutdown. 149 // Leak the timer array at shutdown.
142 static auto* s_TimerMap = new TimerMap; 150 static auto* s_TimerMap = new TimerMap;
143 return s_TimerMap; 151 return s_TimerMap;
144 } 152 }
145 153
146 void CJS_Timer::OnDestroyed() { 154 void CJS_Timer::OnDestroyed() {
147 m_bValid = false; 155 m_bValid = false;
148 } 156 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698