From 32b0f43884fefb10d0577cded9bc9838229a8232 Mon Sep 17 00:00:00 2001 From: Raine Makelainen Date: Tue, 11 Nov 2014 08:50:24 +0200 Subject: [PATCH] [sailfish-browser] Virtualize background tabs when another application is opened Current implementation virtualizes backgrounded tabs when low memory notification (warning / critical) is received even if the browser is at foreground. Virtualizing backgrounded tabs when another application is brought foreground guarantees that there are no background tabs when another application is running regardless of low memory notification. --- src/webpages.cpp | 21 ++++++++++++++++++++- src/webpages.h | 1 + 2 files changed, 21 insertions(+), 1 deletion(-) 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);