• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2014 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6 
7 #include "fpdfsdk/fpdfxfa/cxfa_fwladaptertimermgr.h"
8 
9 #include <utility>
10 #include <vector>
11 
12 #include "fpdfsdk/cpdfsdk_formfillenvironment.h"
13 #include "fpdfsdk/fsdk_define.h"
14 
15 namespace {
16 
17 class CFWL_FWLAdapterTimerInfo : public CFWL_TimerInfo {
18  public:
CFWL_FWLAdapterTimerInfo(IFWL_AdapterTimerMgr * mgr,int32_t event,CFWL_Timer * timer)19   CFWL_FWLAdapterTimerInfo(IFWL_AdapterTimerMgr* mgr,
20                            int32_t event,
21                            CFWL_Timer* timer)
22       : CFWL_TimerInfo(mgr), idEvent(event), pTimer(timer) {}
23 
24   int32_t idEvent;
25   CFWL_Timer* pTimer;
26 };
27 
28 }  // namespace
29 
30 std::vector<CFWL_TimerInfo*>* CXFA_FWLAdapterTimerMgr::s_TimerArray = nullptr;
31 
Start(CFWL_Timer * pTimer,uint32_t dwElapse,bool bImmediately,CFWL_TimerInfo ** pTimerInfo)32 void CXFA_FWLAdapterTimerMgr::Start(CFWL_Timer* pTimer,
33                                     uint32_t dwElapse,
34                                     bool bImmediately,
35                                     CFWL_TimerInfo** pTimerInfo) {
36   if (!m_pFormFillEnv)
37     return;
38 
39   int32_t id_event = m_pFormFillEnv->SetTimer(dwElapse, TimerProc);
40   if (!s_TimerArray)
41     s_TimerArray = new std::vector<CFWL_TimerInfo*>;
42 
43   *pTimerInfo = new CFWL_FWLAdapterTimerInfo(this, id_event, pTimer);
44   s_TimerArray->push_back(*pTimerInfo);
45 }
46 
Stop(CFWL_TimerInfo * pTimerInfo)47 void CXFA_FWLAdapterTimerMgr::Stop(CFWL_TimerInfo* pTimerInfo) {
48   if (!pTimerInfo || !m_pFormFillEnv)
49     return;
50 
51   CFWL_FWLAdapterTimerInfo* pInfo =
52       static_cast<CFWL_FWLAdapterTimerInfo*>(pTimerInfo);
53   m_pFormFillEnv->KillTimer(pInfo->idEvent);
54   if (!s_TimerArray)
55     return;
56 
57   auto it = std::find(s_TimerArray->begin(), s_TimerArray->end(), pInfo);
58   if (it != s_TimerArray->end()) {
59     s_TimerArray->erase(it);
60     delete pInfo;
61   }
62 }
63 
64 // static
TimerProc(int32_t idEvent)65 void CXFA_FWLAdapterTimerMgr::TimerProc(int32_t idEvent) {
66   if (!s_TimerArray)
67     return;
68 
69   for (const auto info : *s_TimerArray) {
70     CFWL_FWLAdapterTimerInfo* pInfo =
71         static_cast<CFWL_FWLAdapterTimerInfo*>(info);
72     if (pInfo->idEvent == idEvent) {
73       pInfo->pTimer->Run(pInfo);
74       break;
75     }
76   }
77 }
78