Chromium Code Reviews| OLD | NEW |
|---|---|
| 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/include/fsdk_define.h" | 7 #include "fpdfsdk/include/fsdk_define.h" |
| 8 #include "fpdfsdk/include/fsdk_mgr.h" | 8 #include "fpdfsdk/include/fsdk_mgr.h" |
| 9 #include "fpdfsdk/include/fpdfxfa/fpdfxfa_util.h" | 9 #include "fpdfsdk/include/fpdfxfa/fpdfxfa_util.h" |
| 10 | 10 |
| 11 CFX_PtrArray CXFA_FWLAdapterTimerMgr::ms_timerArray; | 11 std::vector<CFWL_TimerInfo*> CXFA_FWLAdapterTimerMgr::s_TimerArray; |
| 12 | 12 |
| 13 FWL_ERR CXFA_FWLAdapterTimerMgr::Start(IFWL_Timer* pTimer, | 13 FWL_ERR CXFA_FWLAdapterTimerMgr::Start(IFWL_Timer* pTimer, |
| 14 FX_DWORD dwElapse, | 14 FX_DWORD dwElapse, |
| 15 FWL_HTIMER& hTimer, | 15 FWL_HTIMER& hTimer, |
| 16 FX_BOOL bImmediately /* = TRUE */) { | 16 FX_BOOL bImmediately) { |
| 17 if (m_pEnv) { | 17 if (!m_pEnv) |
| 18 uint32_t uIDEvent = m_pEnv->FFI_SetTimer(dwElapse, TimerProc); | 18 return FWL_ERR_Indefinite; |
| 19 CFWL_TimerInfo* pInfo = new CFWL_TimerInfo; | |
| 20 pInfo->uIDEvent = uIDEvent; | |
| 21 pInfo->pTimer = pTimer; | |
| 22 ms_timerArray.Add(pInfo); | |
| 23 | 19 |
| 24 hTimer = (FWL_HTIMER)pInfo; | 20 uint32_t uIDEvent = m_pEnv->FFI_SetTimer(dwElapse, TimerProc); |
| 25 return FWL_ERR_Succeeded; | 21 s_TimerArray.push_back(new CFWL_TimerInfo(uIDEvent, pTimer)); |
| 26 } | 22 hTimer = reinterpret_cast<FWL_HTIMER>(s_TimerArray.back()); |
| 27 | 23 return FWL_ERR_Succeeded; |
| 28 return FWL_ERR_Indefinite; | |
| 29 } | 24 } |
| 30 | 25 |
| 31 FWL_ERR CXFA_FWLAdapterTimerMgr::Stop(FWL_HTIMER hTimer) { | 26 FWL_ERR CXFA_FWLAdapterTimerMgr::Stop(FWL_HTIMER hTimer) { |
| 32 if (!hTimer) | 27 if (!hTimer || !m_pEnv) |
| 33 return FWL_ERR_Indefinite; | 28 return FWL_ERR_Indefinite; |
| 34 | 29 |
| 35 if (m_pEnv) { | 30 CFWL_TimerInfo* pInfo = reinterpret_cast<CFWL_TimerInfo*>(hTimer); |
| 36 CFWL_TimerInfo* pInfo = (CFWL_TimerInfo*)hTimer; | 31 m_pEnv->FFI_KillTimer(pInfo->uIDEvent); |
| 37 | 32 auto it = std::find(s_TimerArray.begin(), s_TimerArray.end(), pInfo); |
| 38 m_pEnv->FFI_KillTimer(pInfo->uIDEvent); | 33 if (it != s_TimerArray.end()) { |
| 39 | 34 s_TimerArray.erase(it); |
| 40 int32_t index = ms_timerArray.Find(pInfo); | 35 delete *it; |
|
Lei Zhang
2016/02/04 20:03:24
I think you need to delete first. |it| is invalida
Tom Sepez
2016/02/04 20:26:11
Acknowledged.
| |
| 41 if (index >= 0) { | |
| 42 ms_timerArray.RemoveAt(index); | |
| 43 delete pInfo; | |
| 44 } | |
| 45 return FWL_ERR_Succeeded; | |
| 46 } | 36 } |
| 47 | 37 return FWL_ERR_Succeeded; |
| 48 return FWL_ERR_Indefinite; | |
| 49 } | 38 } |
| 50 | 39 |
| 51 void CXFA_FWLAdapterTimerMgr::TimerProc(int32_t idEvent) { | 40 void CXFA_FWLAdapterTimerMgr::TimerProc(int32_t idEvent) { |
| 52 CFWL_TimerInfo* pInfo = NULL; | 41 for (CFWL_TimerInfo* pInfo : s_TimerArray) { |
| 53 int32_t iCount = CXFA_FWLAdapterTimerMgr::ms_timerArray.GetSize(); | 42 if (pInfo->uIDEvent == idEvent) { |
| 54 for (int32_t i = 0; i < iCount; i++) { | 43 pInfo->pTimer->Run(reinterpret_cast<FWL_HTIMER>(pInfo)); |
| 55 CFWL_TimerInfo* pTemp = | |
| 56 (CFWL_TimerInfo*)CXFA_FWLAdapterTimerMgr::ms_timerArray.GetAt(i); | |
| 57 if (pTemp->uIDEvent == idEvent) { | |
| 58 pInfo = pTemp; | |
| 59 break; | 44 break; |
| 60 } | 45 } |
| 61 } | 46 } |
| 62 if (pInfo) { | |
| 63 pInfo->pTimer->Run((FWL_HTIMER)pInfo); | |
| 64 } | |
| 65 } | 47 } |
| OLD | NEW |