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/fpdfxfa/cxfa_fwladaptertimermgr.h" | 7 #include "fpdfsdk/fpdfxfa/cxfa_fwladaptertimermgr.h" |
| 8 | 8 |
| 9 #include <utility> | |
| 9 #include <vector> | 10 #include <vector> |
| 10 | 11 |
| 11 #include "fpdfsdk/cpdfsdk_formfillenvironment.h" | 12 #include "fpdfsdk/cpdfsdk_formfillenvironment.h" |
| 12 #include "fpdfsdk/fsdk_define.h" | 13 #include "fpdfsdk/fsdk_define.h" |
| 13 | 14 |
| 14 std::vector<CFWL_TimerInfo*>* CXFA_FWLAdapterTimerMgr::s_TimerArray = nullptr; | 15 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.
| |
| 15 | 16 |
| 16 void CXFA_FWLAdapterTimerMgr::Start(IFWL_Timer* pTimer, | 17 class CFWL_FWLAdapterTimerInfo : public CFWL_TimerInfo { |
| 18 public: | |
| 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<std::unique_ptr<CFWL_TimerInfo>>* | |
|
Tom Sepez
2016/11/22 18:29:55
where do we clean this up?
would std::set be more
| |
| 31 CXFA_FWLAdapterTimerMgr::s_TimerArray = nullptr; | |
| 32 | |
| 33 void CXFA_FWLAdapterTimerMgr::Start(CFWL_Timer* pTimer, | |
| 17 uint32_t dwElapse, | 34 uint32_t dwElapse, |
| 18 bool bImmediately, | 35 bool bImmediately, |
| 19 IFWL_TimerInfo** pTimerInfo) { | 36 CFWL_TimerInfo** pTimerInfo) { |
| 20 if (!m_pFormFillEnv) | 37 if (!m_pFormFillEnv) |
| 21 return; | 38 return; |
| 22 | 39 |
| 23 int32_t id_event = m_pFormFillEnv->SetTimer(dwElapse, TimerProc); | 40 int32_t id_event = m_pFormFillEnv->SetTimer(dwElapse, TimerProc); |
| 24 if (!s_TimerArray) | 41 if (!s_TimerArray) |
| 25 s_TimerArray = new std::vector<CFWL_TimerInfo*>; | 42 s_TimerArray = new std::vector<std::unique_ptr<CFWL_TimerInfo>>; |
| 26 | 43 |
| 27 s_TimerArray->push_back(new CFWL_TimerInfo(this, id_event, pTimer)); | 44 auto timer = |
| 28 *pTimerInfo = s_TimerArray->back(); | 45 pdfium::MakeUnique<CFWL_FWLAdapterTimerInfo>(this, id_event, pTimer); |
| 46 *pTimerInfo = timer.get(); | |
| 47 s_TimerArray->push_back(std::move(timer)); | |
| 29 } | 48 } |
| 30 | 49 |
| 31 void CXFA_FWLAdapterTimerMgr::Stop(IFWL_TimerInfo* pTimerInfo) { | 50 void CXFA_FWLAdapterTimerMgr::Stop(CFWL_TimerInfo* pTimerInfo) { |
| 32 if (!pTimerInfo || !m_pFormFillEnv) | 51 if (!pTimerInfo || !m_pFormFillEnv) |
| 33 return; | 52 return; |
| 34 | 53 |
| 35 CFWL_TimerInfo* pInfo = static_cast<CFWL_TimerInfo*>(pTimerInfo); | 54 CFWL_FWLAdapterTimerInfo* pInfo = |
| 55 static_cast<CFWL_FWLAdapterTimerInfo*>(pTimerInfo); | |
| 36 m_pFormFillEnv->KillTimer(pInfo->idEvent); | 56 m_pFormFillEnv->KillTimer(pInfo->idEvent); |
| 37 if (s_TimerArray) { | 57 if (!s_TimerArray) |
| 38 auto it = std::find(s_TimerArray->begin(), s_TimerArray->end(), pInfo); | 58 return; |
| 39 if (it != s_TimerArray->end()) { | 59 |
| 40 s_TimerArray->erase(it); | 60 auto it = std::find(s_TimerArray->begin(), s_TimerArray->end(), |
| 41 delete pInfo; | 61 pdfium::FakeUniquePtr<CFWL_TimerInfo>(pInfo)); |
| 42 } | 62 if (it != s_TimerArray->end()) |
| 43 } | 63 s_TimerArray->erase(it); |
| 44 } | 64 } |
| 45 | 65 |
| 46 // static | 66 // static |
| 47 void CXFA_FWLAdapterTimerMgr::TimerProc(int32_t idEvent) { | 67 void CXFA_FWLAdapterTimerMgr::TimerProc(int32_t idEvent) { |
| 48 if (!s_TimerArray) | 68 if (!s_TimerArray) |
| 49 return; | 69 return; |
| 50 | 70 |
| 51 for (CFWL_TimerInfo* pInfo : *s_TimerArray) { | 71 for (auto& info : *s_TimerArray) { |
|
Tom Sepez
2016/11/22 18:29:54
nit: const auto&
dsinclair
2016/11/22 22:05:20
Done.
| |
| 52 if (pInfo->idEvent == idEvent) { | 72 CFWL_FWLAdapterTimerInfo* pInfo = |
| 53 pInfo->pTimer->Run(pInfo); | 73 static_cast<CFWL_FWLAdapterTimerInfo*>(info.get()); |
| 54 break; | 74 if (pInfo->idEvent != idEvent) |
|
Tom Sepez
2016/11/22 18:29:54
nit: not sure early continue helps here given the
| |
| 55 } | 75 continue; |
| 76 | |
| 77 pInfo->pTimer->Run(pInfo); | |
| 78 break; | |
| 56 } | 79 } |
| 57 } | 80 } |
| OLD | NEW |