diff --git a/src/webpages.cpp b/src/webpages.cpp index e7bc05bd9d6b..146e0738bf4a 100644 --- a/src/webpages.cpp +++ b/src/webpages.cpp @@ -35,6 +35,9 @@ static const qint64 gMemoryPressureTimeout = 600 * 1000; // 600 sec // In normal cases gLowMemoryEnabled is true. Can be disabled e.g. for test runs. static const bool gLowMemoryEnabled = qgetenv("LOW_MEMORY_DISABLED").isEmpty(); +static const QLatin1String gLowMemoryWarning("warning"); +static const QLatin1String gLowMemoryCritical("critical"); + WebPages::WebPages(QObject *parent) : QObject(parent) , m_backgroundTimestamp(0) @@ -58,15 +61,31 @@ void WebPages::initialize(DeclarativeWebContainer *webContainer, QQmlComponent * } connect(webContainer, SIGNAL(foregroundChanged()), this, SLOT(updateBackgroundTimestamp())); + connect(webContainer, SIGNAL(backgroundChanged()), this, SLOT(virtualizeInactive())); } void WebPages::updateBackgroundTimestamp() { + // In Switcher. if (!m_webContainer->foreground()) { m_backgroundTimestamp = QDateTime::currentMSecsSinceEpoch(); } } +/*! + * Virtualize pages that are inactive (all but the first). + * This also takes a time stamp that is later used to + * trigger gc and heap minimizing when low memory notifacations + * is recieved after some time. + */ +void WebPages::virtualizeInactive() +{ + // Another application got opened. + if (m_webContainer->background()) { + handleMemNotify(gLowMemoryWarning); + } +} + bool WebPages::initialized() const { return m_webContainer && m_webPageComponent; @@ -188,7 +207,7 @@ void WebPages::dumpPages() const void WebPages::handleMemNotify(const QString &memoryLevel) { - if (memoryLevel == QString("warning") || memoryLevel == QString("critical")) { + if (memoryLevel == gLowMemoryWarning || memoryLevel == gLowMemoryCritical) { m_activePages.virtualizeInactive(); if (!m_webContainer->foreground() && diff --git a/src/webpages.h b/src/webpages.h index 8d966d419e3c..9c9ee7a12dc0 100644 --- a/src/webpages.h +++ b/src/webpages.h @@ -55,6 +55,7 @@ class WebPages : public QObject private slots: void handleMemNotify(const QString &memoryLevel); void updateBackgroundTimestamp(); + void virtualizeInactive(); private: void updateStates(DeclarativeWebPage *oldActivePage, DeclarativeWebPage *newActivePage);