Merge lp:~osomon/webbrowser-app/maxCacheSizeHint into lp:webbrowser-app

Proposed by Olivier Tilloy
Status: Merged
Approved by: Olivier Tilloy
Approved revision: 936
Merged at revision: 1019
Proposed branch: lp:~osomon/webbrowser-app/maxCacheSizeHint
Merge into: lp:webbrowser-app
Diff against target: 110 lines (+35/-3)
3 files modified
debian/control (+1/-1)
src/Ubuntu/Web/UbuntuWebContext.qml (+5/-2)
src/Ubuntu/Web/plugin.cpp (+29/-0)
To merge this branch: bzr merge lp:~osomon/webbrowser-app/maxCacheSizeHint
Reviewer Review Type Date Requested Status
Alexandre Abreu (community) Approve
PS Jenkins bot continuous-integration Needs Fixing
Review via email: mp+252472@code.launchpad.net

Commit message

Make use of the WebContext.maxCacheSizeHint property, introduced in Oxide 1.6.
This bumps the dependency of qtdeclarative5-ubuntu-web-plugin on liboxideqt-qmlplugin to 1.6.

To post a comment you must log in.
Revision history for this message
Alexandre Abreu (abreu-alexandre) wrote :

I am wondering about the hardcoded value for webapp, it is pretty arbitrary and might benefit from being adjustable for certain webapps ... could you add a argument for this?

(added a nit comment inline)

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Alexandre Abreu (abreu-alexandre) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'debian/control'
2--- debian/control 2015-04-10 13:33:10 +0000
3+++ debian/control 2015-04-28 21:31:21 +0000
4@@ -95,7 +95,7 @@
5 Pre-Depends: ${misc:Pre-Depends}
6 Depends: ${misc:Depends},
7 ${shlibs:Depends},
8- liboxideqt-qmlplugin (>= 1.5),
9+ liboxideqt-qmlplugin (>= 1.6),
10 qml-module-qtquick2 | qtdeclarative5-qtquick2-plugin,
11 qml-module-qtquick-window2 | qtdeclarative5-window-plugin,
12 qtdeclarative5-ubuntu-ui-toolkit-plugin,
13
14=== modified file 'src/Ubuntu/Web/UbuntuWebContext.qml'
15--- src/Ubuntu/Web/UbuntuWebContext.qml 2015-02-24 10:32:50 +0000
16+++ src/Ubuntu/Web/UbuntuWebContext.qml 2015-04-28 21:31:21 +0000
17@@ -17,13 +17,16 @@
18 */
19
20 import QtQuick 2.0
21-import com.canonical.Oxide 1.3 as Oxide
22+import com.canonical.Oxide 1.6 as Oxide
23
24 Oxide.WebContext {
25 readonly property string defaultUserAgent: __ua.defaultUA
26
27+ dataPath: dataLocation
28+
29 cachePath: cacheLocation
30- dataPath: dataLocation
31+ maxCacheSizeHint: cacheSizeHint
32+
33 userAgent: defaultUserAgent
34
35 networkRequestDelegate: Oxide.WebContextDelegateWorker {
36
37=== modified file 'src/Ubuntu/Web/plugin.cpp'
38--- src/Ubuntu/Web/plugin.cpp 2015-03-27 18:24:56 +0000
39+++ src/Ubuntu/Web/plugin.cpp 2015-04-28 21:31:21 +0000
40@@ -23,6 +23,7 @@
41 #include <QtCore/QDir>
42 #include <QtCore/QObject>
43 #include <QtCore/QStandardPaths>
44+#include <QtCore/QStorageInfo>
45 #include <QtCore/QString>
46 #include <QtCore/QStringList>
47 #include <QtCore/QtGlobal>
48@@ -37,6 +38,7 @@
49 Q_PROPERTY(QString cacheLocation READ cacheLocation NOTIFY cacheLocationChanged)
50 Q_PROPERTY(QString dataLocation READ dataLocation NOTIFY dataLocationChanged)
51 Q_PROPERTY(QString formFactor READ formFactor CONSTANT)
52+ Q_PROPERTY(int cacheSizeHint READ cacheSizeHint NOTIFY cacheSizeHintChanged)
53 Q_PROPERTY(QString webviewDevtoolsDebugHost READ devtoolsHost CONSTANT)
54 Q_PROPERTY(int webviewDevtoolsDebugPort READ devtoolsPort CONSTANT)
55 Q_PROPERTY(QStringList webviewHostMappingRules READ hostMappingRules CONSTANT)
56@@ -47,6 +49,7 @@
57 QString cacheLocation() const;
58 QString dataLocation() const;
59 QString formFactor();
60+ int cacheSizeHint() const;
61 QString devtoolsHost();
62 int devtoolsPort();
63 QStringList hostMappingRules();
64@@ -54,6 +57,7 @@
65 Q_SIGNALS:
66 void cacheLocationChanged() const;
67 void dataLocationChanged() const;
68+ void cacheSizeHintChanged() const;
69
70 private:
71 QString m_formFactor;
72@@ -72,6 +76,8 @@
73 this, SIGNAL(cacheLocationChanged()));
74 connect(QCoreApplication::instance(), SIGNAL(applicationNameChanged()),
75 this, SIGNAL(dataLocationChanged()));
76+ connect(QCoreApplication::instance(), SIGNAL(applicationNameChanged()),
77+ this, SIGNAL(cacheSizeHintChanged()));
78 }
79
80 QString UbuntuWebPluginContext::cacheLocation() const
81@@ -130,6 +136,29 @@
82 return m_formFactor;
83 }
84
85+int UbuntuWebPluginContext::cacheSizeHint() const
86+{
87+ if (QCoreApplication::applicationName() == "webbrowser-app") {
88+ // Let chromium decide the optimum cache size based on available disk space
89+ return 0;
90+ } else {
91+ // For webapps and other embedders, determine the cache size hint
92+ // using heuristics based on the disk space (total, and available).
93+ QStorageInfo storageInfo(QStandardPaths::writableLocation(QStandardPaths::CacheLocation));
94+ const int MB = 1024 * 1024;
95+ // The total cache size for all apps should not exceed 10% of the total disk space
96+ int maxSharedCache = storageInfo.bytesTotal() / MB * 0.1;
97+ // One given app is allowed to use up to 5% o the total cache size
98+ int maxAppCacheAllowance = maxSharedCache * 0.05;
99+ // Ensure it never exceeds 200 MB though
100+ int maxAppCacheAbsolute = qMin(maxAppCacheAllowance, 200);
101+ // Never use more than 20% of the available disk space
102+ int maxAppCacheRelative = storageInfo.bytesAvailable() / MB * 0.2;
103+ // Never set a size hint below 5 MB, as that would result in a very inefficient cache
104+ return qMax(5, qMin(maxAppCacheAbsolute, maxAppCacheRelative));
105+ }
106+}
107+
108 QStringList UbuntuWebPluginContext::hostMappingRules()
109 {
110 static const QString HOST_MAPPING_RULES_SEP = ",";

Subscribers

People subscribed via source and target branches

to status/vote changes: