Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Toggle main menu visibility
Loading...
Searching...
No Matches
global_timer.cpp
Go to the documentation of this file.
1
// Copyright 2017 The PDFium Authors
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
"fxjs/global_timer.h"
8
9
#
include
<
map
>
10
11
#
include
"core/fxcrt/cfx_timer.h"
12
#
include
"core/fxcrt/check.h"
13
#
include
"core/fxcrt/containers/contains.h"
14
#
include
"fxjs/cjs_app.h"
15
16
namespace
{
17
18
using
TimerMap = std::map<int32_t, GlobalTimer*>;
19
TimerMap* g_global_timer_map =
nullptr
;
20
21
}
// namespace
22
23
// static
24
void
GlobalTimer
::
InitializeGlobals
() {
25
CHECK
(!g_global_timer_map);
26
g_global_timer_map =
new
TimerMap();
27
}
28
29
// static
30
void
GlobalTimer
::
DestroyGlobals
() {
31
delete
g_global_timer_map;
32
g_global_timer_map =
nullptr
;
33
}
34
35
GlobalTimer
::
GlobalTimer
(CJS_App* pObj,
36
CJS_Runtime* pRuntime,
37
Type
nType,
38
const
WideString
& script,
39
uint32_t dwElapse,
40
uint32_t dwTimeOut)
41
: m_nType(nType),
42
m_nTimerID(pRuntime
->
GetTimerHandler
(
)
->
SetTimer
(
dwElapse
,
Trigger
)
),
43
m_dwTimeOut(dwTimeOut),
44
m_swJScript
(
script
),
45
m_pRuntime
(
pRuntime
),
46
m_pEmbedApp
(
pObj
) {
47
if
(HasValidID()) {
48
DCHECK
(!pdfium::Contains((*g_global_timer_map), m_nTimerID));
49
(*g_global_timer_map)[m_nTimerID] =
this
;
50
}
51
}
52
53
GlobalTimer
::~
GlobalTimer
() {
54
if
(!HasValidID())
55
return
;
56
57
if
(m_pRuntime && m_pRuntime->GetTimerHandler())
58
m_pRuntime->GetTimerHandler()->KillTimer(m_nTimerID);
59
60
DCHECK
(pdfium::Contains((*g_global_timer_map), m_nTimerID));
61
g_global_timer_map->erase(m_nTimerID);
62
}
63
64
// static
65
void
GlobalTimer
::
Trigger
(int32_t nTimerID) {
66
auto
it = g_global_timer_map->find(nTimerID);
67
if
(it == g_global_timer_map->end()) {
68
return
;
69
}
70
71
GlobalTimer
* pTimer = it->second;
72
if
(pTimer->m_bProcessing)
73
return
;
74
75
pTimer->m_bProcessing =
true
;
76
if
(pTimer->m_pEmbedApp)
77
pTimer->m_pEmbedApp->TimerProc(pTimer);
78
79
// Timer proc may have destroyed timer, find it again.
80
it = g_global_timer_map->find(nTimerID);
81
if
(it == g_global_timer_map->end()) {
82
return
;
83
}
84
85
pTimer = it->second;
86
pTimer->m_bProcessing =
false
;
87
if
(pTimer
->
IsOneShot
(
)
)
88
pTimer->m_pEmbedApp->CancelProc(pTimer);
89
}
90
91
// static
92
void
GlobalTimer
::
Cancel
(int32_t nTimerID) {
93
auto
it = g_global_timer_map->find(nTimerID);
94
if
(it == g_global_timer_map->end()) {
95
return
;
96
}
97
98
GlobalTimer
* pTimer = it->second;
99
pTimer->m_pEmbedApp->CancelProc(pTimer);
100
}
101
102
bool
GlobalTimer
::HasValidID()
const
{
103
return
m_nTimerID !=
CFX_Timer
::
HandlerIface
::
kInvalidTimerID
;
104
}
DCHECK
#define DCHECK
Definition
check.h:33
CFX_Timer::HandlerIface
Definition
cfx_timer.h:19
CFX_Timer::HandlerIface::kInvalidTimerID
static constexpr int32_t kInvalidTimerID
Definition
cfx_timer.h:21
CFX_Timer::HandlerIface::SetTimer
virtual int32_t SetTimer(int32_t uElapse, TimerCallback lpTimerFunc)=0
CFX_Timer
Definition
cfx_timer.h:15
CJS_Runtime::GetTimerHandler
CFX_Timer::HandlerIface * GetTimerHandler() const
Definition
cjs_runtime.cpp:144
GlobalTimer
Definition
global_timer.h:15
GlobalTimer::DestroyGlobals
static void DestroyGlobals()
Definition
global_timer.cpp:30
GlobalTimer::~GlobalTimer
~GlobalTimer()
Definition
global_timer.cpp:53
GlobalTimer::InitializeGlobals
static void InitializeGlobals()
Definition
global_timer.cpp:24
GlobalTimer::GlobalTimer
GlobalTimer(CJS_App *pObj, CJS_Runtime *pRuntime, Type nType, const WideString &script, uint32_t dwElapse, uint32_t dwTimeOut)
Definition
global_timer.cpp:35
GlobalTimer::Type
Type
Definition
global_timer.h:17
GlobalTimer::Trigger
static void Trigger(int32_t nTimerID)
Definition
global_timer.cpp:65
GlobalTimer::IsOneShot
bool IsOneShot() const
Definition
global_timer.h:36
GlobalTimer::Cancel
static void Cancel(int32_t nTimerID)
Definition
global_timer.cpp:92
CHECK
#define CHECK(cvref)
Definition
q23utility.cpp:15
WideString
fxcrt::WideString WideString
Definition
widestring.h:207
qtwebengine
src
3rdparty
chromium
third_party
pdfium
fxjs
global_timer.cpp
Generated on
for Qt by
1.18.0