Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops. This sentence got copied here as well. Should not be here.

Another way to implement this kind of early release would be to do this when screen is dimmed meaning that browser goes to background and it is not requesting screen to be on.

* 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