Clean up GlobalTimer.
- Move GetGlobalTimerMap() into an anonymous namespace.
- Make GlobalTimer's type a class enum.
Change-Id: I8fb9d090661bfcefb6e9a1c43633ad0dca1aa380
Reviewed-on: https://pdfium-review.googlesource.com/c/48034
Commit-Queue: Lei Zhang <thestig@chromium.org>
Reviewed-by: Tom Sepez <tsepez@chromium.org>
diff --git a/fxjs/cjs_app.cpp b/fxjs/cjs_app.cpp
index d241d03..89db289 100644
--- a/fxjs/cjs_app.cpp
+++ b/fxjs/cjs_app.cpp
@@ -316,7 +316,8 @@
uint32_t dwInterval = params.size() > 1 ? pRuntime->ToInt32(params[1]) : 1000;
auto timerRef = pdfium::MakeUnique<GlobalTimer>(
- this, pRuntime->GetFormFillEnv(), pRuntime, 0, script, dwInterval, 0);
+ this, pRuntime->GetFormFillEnv(), pRuntime, GlobalTimer::Type::kRepeating,
+ script, dwInterval, 0);
GlobalTimer* pTimerRef = timerRef.get();
m_Timers.insert(std::move(timerRef));
@@ -344,8 +345,8 @@
uint32_t dwTimeOut = params.size() > 1 ? pRuntime->ToInt32(params[1]) : 1000;
auto timerRef = pdfium::MakeUnique<GlobalTimer>(
- this, pRuntime->GetFormFillEnv(), pRuntime, 1, script, dwTimeOut,
- dwTimeOut);
+ this, pRuntime->GetFormFillEnv(), pRuntime, GlobalTimer::Type::kOneShot,
+ script, dwTimeOut, dwTimeOut);
GlobalTimer* pTimerRef = timerRef.get();
m_Timers.insert(std::move(timerRef));
diff --git a/fxjs/global_timer.cpp b/fxjs/global_timer.cpp
index 16372cf..a4d3c04 100644
--- a/fxjs/global_timer.cpp
+++ b/fxjs/global_timer.cpp
@@ -6,13 +6,26 @@
#include "fxjs/global_timer.h"
+#include <map>
+
#include "fpdfsdk/cfx_systemhandler.h"
#include "fxjs/cjs_app.h"
+namespace {
+
+using TimerMap = std::map<int32_t, GlobalTimer*>;
+TimerMap* GetGlobalTimerMap() {
+ // Leak the timer array at shutdown.
+ static auto* s_TimerMap = new TimerMap;
+ return s_TimerMap;
+}
+
+} // namespace
+
GlobalTimer::GlobalTimer(CJS_App* pObj,
CPDFSDK_FormFillEnvironment* pFormFillEnv,
CJS_Runtime* pRuntime,
- int nType,
+ Type nType,
const WideString& script,
uint32_t dwElapse,
uint32_t dwTimeOut)
@@ -72,13 +85,6 @@
pTimer->m_pEmbedApp->CancelProc(pTimer);
}
-// static
-GlobalTimer::TimerMap* GlobalTimer::GetGlobalTimerMap() {
- // Leak the timer array at shutdown.
- static auto* s_TimerMap = new TimerMap;
- return s_TimerMap;
-}
-
bool GlobalTimer::HasValidID() const {
return m_nTimerID != CFX_SystemHandler::kInvalidTimerID;
}
diff --git a/fxjs/global_timer.h b/fxjs/global_timer.h
index 463ed19..8c63ceb 100644
--- a/fxjs/global_timer.h
+++ b/fxjs/global_timer.h
@@ -7,8 +7,6 @@
#ifndef FXJS_GLOBAL_TIMER_H_
#define FXJS_GLOBAL_TIMER_H_
-#include <map>
-
#include "fpdfsdk/cpdfsdk_formfillenvironment.h"
#include "fxjs/cjs_runtime.h"
@@ -16,10 +14,15 @@
class GlobalTimer {
public:
+ enum class Type : bool {
+ kRepeating = false,
+ kOneShot = true,
+ };
+
GlobalTimer(CJS_App* pObj,
CPDFSDK_FormFillEnvironment* pFormFillEnv,
CJS_Runtime* pRuntime,
- int nType,
+ Type nType,
const WideString& script,
uint32_t dwElapse,
uint32_t dwTimeOut);
@@ -28,16 +31,13 @@
static void Trigger(int32_t nTimerID);
static void Cancel(int32_t nTimerID);
- bool IsOneShot() const { return m_nType == 1; }
+ bool IsOneShot() const { return m_nType == Type::kOneShot; }
uint32_t GetTimeOut() const { return m_dwTimeOut; }
int32_t GetTimerID() const { return m_nTimerID; }
CJS_Runtime* GetRuntime() const { return m_pRuntime.Get(); }
WideString GetJScript() const { return m_swJScript; }
private:
- using TimerMap = std::map<int32_t, GlobalTimer*>;
- static TimerMap* GetGlobalTimerMap();
-
bool HasValidID() const;
const int32_t m_nTimerID;
@@ -45,7 +45,7 @@
bool m_bProcessing = false;
// data
- const int m_nType; // 0:Interval; 1:TimeOut
+ const Type m_nType;
const uint32_t m_dwTimeOut;
const WideString m_swJScript;
CJS_Runtime::ObservedPtr m_pRuntime;