Index: fpdfsdk/fpdfxfa/cxfa_fwladaptertimermgr.cpp |
diff --git a/fpdfsdk/fpdfxfa/cxfa_fwladaptertimermgr.cpp b/fpdfsdk/fpdfxfa/cxfa_fwladaptertimermgr.cpp |
index 5a9ae95be7593d1efd31d287abbe5622ad3cd507..1e73f393407e4e8181471fe83127077b8b7cb12a 100644 |
--- a/fpdfsdk/fpdfxfa/cxfa_fwladaptertimermgr.cpp |
+++ b/fpdfsdk/fpdfxfa/cxfa_fwladaptertimermgr.cpp |
@@ -6,41 +6,61 @@ |
#include "fpdfsdk/fpdfxfa/cxfa_fwladaptertimermgr.h" |
+#include <utility> |
#include <vector> |
#include "fpdfsdk/cpdfsdk_formfillenvironment.h" |
#include "fpdfsdk/fsdk_define.h" |
-std::vector<CFWL_TimerInfo*>* CXFA_FWLAdapterTimerMgr::s_TimerArray = nullptr; |
+namespace { |
dsinclair
2016/11/22 17:20:42
Tom, can you give this a look to make sure I didn'
Tom Sepez
2016/11/22 18:29:54
UPs are fine, some other comments.
|
-void CXFA_FWLAdapterTimerMgr::Start(IFWL_Timer* pTimer, |
+class CFWL_FWLAdapterTimerInfo : public CFWL_TimerInfo { |
+ public: |
+ CFWL_FWLAdapterTimerInfo(IFWL_AdapterTimerMgr* mgr, |
+ int32_t event, |
+ CFWL_Timer* timer) |
+ : CFWL_TimerInfo(mgr), idEvent(event), pTimer(timer) {} |
+ |
+ int32_t idEvent; |
+ CFWL_Timer* pTimer; |
+}; |
+ |
+} // namespace |
+ |
+std::vector<std::unique_ptr<CFWL_TimerInfo>>* |
Tom Sepez
2016/11/22 18:29:55
where do we clean this up?
would std::set be more
|
+ CXFA_FWLAdapterTimerMgr::s_TimerArray = nullptr; |
+ |
+void CXFA_FWLAdapterTimerMgr::Start(CFWL_Timer* pTimer, |
uint32_t dwElapse, |
bool bImmediately, |
- IFWL_TimerInfo** pTimerInfo) { |
+ CFWL_TimerInfo** pTimerInfo) { |
if (!m_pFormFillEnv) |
return; |
int32_t id_event = m_pFormFillEnv->SetTimer(dwElapse, TimerProc); |
if (!s_TimerArray) |
- s_TimerArray = new std::vector<CFWL_TimerInfo*>; |
+ s_TimerArray = new std::vector<std::unique_ptr<CFWL_TimerInfo>>; |
- s_TimerArray->push_back(new CFWL_TimerInfo(this, id_event, pTimer)); |
- *pTimerInfo = s_TimerArray->back(); |
+ auto timer = |
+ pdfium::MakeUnique<CFWL_FWLAdapterTimerInfo>(this, id_event, pTimer); |
+ *pTimerInfo = timer.get(); |
+ s_TimerArray->push_back(std::move(timer)); |
} |
-void CXFA_FWLAdapterTimerMgr::Stop(IFWL_TimerInfo* pTimerInfo) { |
+void CXFA_FWLAdapterTimerMgr::Stop(CFWL_TimerInfo* pTimerInfo) { |
if (!pTimerInfo || !m_pFormFillEnv) |
return; |
- CFWL_TimerInfo* pInfo = static_cast<CFWL_TimerInfo*>(pTimerInfo); |
+ CFWL_FWLAdapterTimerInfo* pInfo = |
+ static_cast<CFWL_FWLAdapterTimerInfo*>(pTimerInfo); |
m_pFormFillEnv->KillTimer(pInfo->idEvent); |
- if (s_TimerArray) { |
- auto it = std::find(s_TimerArray->begin(), s_TimerArray->end(), pInfo); |
- if (it != s_TimerArray->end()) { |
- s_TimerArray->erase(it); |
- delete pInfo; |
- } |
- } |
+ if (!s_TimerArray) |
+ return; |
+ |
+ auto it = std::find(s_TimerArray->begin(), s_TimerArray->end(), |
+ pdfium::FakeUniquePtr<CFWL_TimerInfo>(pInfo)); |
+ if (it != s_TimerArray->end()) |
+ s_TimerArray->erase(it); |
} |
// static |
@@ -48,10 +68,13 @@ void CXFA_FWLAdapterTimerMgr::TimerProc(int32_t idEvent) { |
if (!s_TimerArray) |
return; |
- for (CFWL_TimerInfo* pInfo : *s_TimerArray) { |
- if (pInfo->idEvent == idEvent) { |
- pInfo->pTimer->Run(pInfo); |
- break; |
- } |
+ for (auto& info : *s_TimerArray) { |
Tom Sepez
2016/11/22 18:29:54
nit: const auto&
dsinclair
2016/11/22 22:05:20
Done.
|
+ CFWL_FWLAdapterTimerInfo* pInfo = |
+ static_cast<CFWL_FWLAdapterTimerInfo*>(info.get()); |
+ if (pInfo->idEvent != idEvent) |
Tom Sepez
2016/11/22 18:29:54
nit: not sure early continue helps here given the
|
+ continue; |
+ |
+ pInfo->pTimer->Run(pInfo); |
+ break; |
} |
} |