Messagelib
7 #include "backoffmodemanager.h"
8 #include "checkphishingurlutil.h"
9 #include "webengineviewer_debug.h"
12 #include <KConfigGroup>
16 using namespace WebEngineViewer;
20 class WebEngineViewer::BackOffModeManagerPrivate
27 mTimer->setSingleShot(
true);
28 q->connect(mTimer, &
QTimer::timeout, q, &BackOffModeManager::slotTimerFinished);
34 Q_REQUIRED_RESULT
int calculateBackModeTime()
const;
36 void exitBackOffMode();
37 void updateTimer(
int seconds);
38 void slotTimerFinished();
42 int mNumberOfHttpFailed = 0;
43 bool isInOffMode =
false;
46 void BackOffModeManagerPrivate::save()
48 KConfig phishingurlKConfig(WebEngineViewer::CheckPhishingUrlUtil::configFileName());
52 const int calculateTimeInSeconds = calculateBackModeTime();
55 updateTimer(calculateTimeInSeconds);
62 void BackOffModeManagerPrivate::slotTimerFinished()
64 qCDebug(WEBENGINEVIEWER_LOG) <<
"Existing from BlackOffMode";
69 void BackOffModeManagerPrivate::updateTimer(
int seconds)
71 if (mTimer->isActive()) {
74 mTimer->setInterval(seconds * 1000);
78 void BackOffModeManagerPrivate::load()
80 KConfig phishingurlKConfig(WebEngineViewer::CheckPhishingUrlUtil::configFileName());
82 isInOffMode = grp.
readEntry(
"Enabled",
false);
84 const qint64 delay = grp.
readEntry(
"Delay", 0);
87 const qint64 diff = (delay - now);
96 int BackOffModeManagerPrivate::calculateBackModeTime()
const
98 return WebEngineViewer::CheckPhishingUrlUtil::generateRandomSecondValue(mNumberOfHttpFailed);
101 void BackOffModeManagerPrivate::startOffMode()
103 mNumberOfHttpFailed++;
105 qCWarning(WEBENGINEVIEWER_LOG) <<
"New failed" << mNumberOfHttpFailed;
107 qCWarning(WEBENGINEVIEWER_LOG) <<
"starting back of mode";
113 void BackOffModeManagerPrivate::exitBackOffMode()
116 mNumberOfHttpFailed = 0;
119 BackOffModeManager::BackOffModeManager(
QObject *parent)
121 , d(new BackOffModeManagerPrivate(this))
125 BackOffModeManager::~BackOffModeManager() =
default;
129 return s_backOffModeManager;
132 bool BackOffModeManager::isInBackOffMode()
const
134 return d->isInOffMode;
137 void BackOffModeManager::startOffMode()
142 int BackOffModeManager::numberOfHttpFailed()
const
144 return d->mNumberOfHttpFailed;
147 void BackOffModeManager::slotTimerFinished()
149 d->slotTimerFinished();
QString readEntry(const char *key, const char *aDefault=nullptr) const
void writeEntry(const char *key, const char *value, WriteConfigFlags pFlags=Normal)
QDateTime addSecs(qint64 s) const const
The BackOffModeManager class.
void deleteEntry(const char *key, WriteConfigFlags pFlags=Normal)
QDateTime currentDateTime()
QAction * load(const QObject *recvr, const char *slot, QObject *parent)
QDateTime currentDateTimeUtc()
Q_GLOBAL_STATIC(Internal::StaticControl, s_instance) class ControlPrivate
KConfigGroup group(const char *group)
qint64 toSecsSinceEpoch() const const
QAction * save(const QObject *recvr, const char *slot, QObject *parent)
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Thu May 19 2022 03:53:24 by
doxygen 1.8.17 written
by
Dimitri van Heesch, © 1997-2006
KDE's Doxygen guidelines are available online.