Skip to content

Commit

Permalink
[sailfish-browser] Virtualize background tabs when another applicatio…
Browse files Browse the repository at this point in the history
…n 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.
  • Loading branch information
Raine Makelainen committed Nov 11, 2014
1 parent 9707bff commit 32b0f43
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
21 changes: 20 additions & 1 deletion src/webpages.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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;
Expand Down Expand Up @@ -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() &&
Expand Down
1 change: 1 addition & 0 deletions src/webpages.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 32b0f43

Please sign in to comment.