Merge lp:~unity-team/unity8/cache-network-data into lp:unity8

Proposed by Michal Hruby
Status: Merged
Approved by: Michał Sawicz
Approved revision: 999
Merged at revision: 1000
Proposed branch: lp:~unity-team/unity8/cache-network-data
Merge into: lp:unity8
Diff against target: 165 lines (+118/-2)
4 files modified
src/CMakeLists.txt (+1/-0)
src/CachingNetworkManagerFactory.cpp (+62/-0)
src/CachingNetworkManagerFactory.h (+50/-0)
src/main.cpp (+5/-2)
To merge this branch: bzr merge lp:~unity-team/unity8/cache-network-data
Reviewer Review Type Date Requested Status
PS Jenkins bot (community) continuous-integration Needs Fixing
Michał Sawicz Approve
Florian Boucault Pending
Review via email: mp+224995@code.launchpad.net

Commit message

Cache network requests to reduce data usage and increase dash icon loading speed.

Description of the change

Cache network requests to reduce data usage and increase dash icon loading speed.

 * Are there any related MPs required for this MP to build/function as expected? Please list.

No

 * Did you perform an exploratory manual test run of your code change and any related functionality?

Yes

 * Did you make sure that your branch does not contain spurious tags?

Yes

 * If you changed the packaging (debian), did you subscribe the ubuntu-unity team to this MP?

N/A

 * If you changed the UI, has there been a design review?

N/A

To post a comment you must log in.
998. By Michal Hruby

Hook up with QNetworkConfigurationManager

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Michał Sawicz (saviq) wrote :

Just one small comment inline.

review: Approve (code)
999. By Michal Hruby

Remove unneeded include

Revision history for this message
Michal Hruby (mhr3) :
Revision history for this message
Michał Sawicz (saviq) wrote :

 * Did you perform an exploratory manual test run of the code change and any related functionality?
Yeah, everything works fine, feels slightly faster to load known preview images (and should improve after servers send correct cache control headers).

 * Did CI run pass? If not, please explain why.
Not sure, the failed tests pass locally.

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

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'src/CMakeLists.txt'
--- src/CMakeLists.txt 2014-06-11 15:36:51 +0000
+++ src/CMakeLists.txt 2014-07-02 07:56:49 +0000
@@ -19,6 +19,7 @@
19 ApplicationArguments.h19 ApplicationArguments.h
20 main.cpp20 main.cpp
21 MouseTouchAdaptor.cpp21 MouseTouchAdaptor.cpp
22 CachingNetworkManagerFactory.cpp
22 ${QML_FILES} # This is to make qml and image files appear in the IDE's project tree23 ${QML_FILES} # This is to make qml and image files appear in the IDE's project tree
23)24)
2425
2526
=== added file 'src/CachingNetworkManagerFactory.cpp'
--- src/CachingNetworkManagerFactory.cpp 1970-01-01 00:00:00 +0000
+++ src/CachingNetworkManagerFactory.cpp 2014-07-02 07:56:49 +0000
@@ -0,0 +1,62 @@
1/*
2 * Copyright (C) 2014 Canonical, Ltd.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 3.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 */
17
18#include "CachingNetworkManagerFactory.h"
19
20#include <QNetworkDiskCache>
21#include <QNetworkAccessManager>
22#include <QStandardPaths>
23#include <QNetworkConfigurationManager>
24
25CachingNetworkAccessManager::CachingNetworkAccessManager(QObject *parent)
26 : QNetworkAccessManager(parent)
27{
28 m_networkManager = new QNetworkConfigurationManager(this);
29
30 QObject::connect(m_networkManager, &QNetworkConfigurationManager::onlineStateChanged, this, &CachingNetworkAccessManager::onlineStateChanged);
31 m_isOnline = m_networkManager->isOnline();
32}
33
34void CachingNetworkAccessManager::onlineStateChanged(bool isOnline)
35{
36 m_isOnline = isOnline;
37}
38
39QNetworkReply* CachingNetworkAccessManager::createRequest(Operation op, const QNetworkRequest &request, QIODevice *outgoingData)
40{
41 if (!m_isOnline) {
42 QNetworkRequest req(request);
43 req.setAttribute(QNetworkRequest::CacheLoadControlAttribute, QNetworkRequest::AlwaysCache);
44 return QNetworkAccessManager::createRequest(op, req, outgoingData);
45 }
46
47 return QNetworkAccessManager::createRequest(op, request, outgoingData);
48}
49
50CachingNetworkManagerFactory::CachingNetworkManagerFactory()
51{
52}
53
54QNetworkAccessManager *CachingNetworkManagerFactory::create(QObject *parent) {
55 QNetworkAccessManager *manager = new CachingNetworkAccessManager(parent);
56
57 QNetworkDiskCache* cache = new QNetworkDiskCache(manager);
58 cache->setCacheDirectory(QString("%1/network").arg(QStandardPaths::writableLocation(QStandardPaths::CacheLocation)));
59
60 manager->setCache(cache);
61 return manager;
62}
063
=== added file 'src/CachingNetworkManagerFactory.h'
--- src/CachingNetworkManagerFactory.h 1970-01-01 00:00:00 +0000
+++ src/CachingNetworkManagerFactory.h 2014-07-02 07:56:49 +0000
@@ -0,0 +1,50 @@
1/*
2 * Copyright (C) 2014 Canonical, Ltd.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 3.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 */
17
18#ifndef CACHINGNETWORKMANAGERFACTORY_H
19#define CACHINGNETWORKMANAGERFACTORY_H
20
21#include <QQmlNetworkAccessManagerFactory>
22#include <QNetworkAccessManager>
23
24class QNetworkConfigurationManager;
25
26class CachingNetworkAccessManager : public QNetworkAccessManager
27{
28public:
29 CachingNetworkAccessManager(QObject *parent = 0);
30
31protected:
32 QNetworkReply* createRequest(Operation op, const QNetworkRequest &req, QIODevice *outgoingData = 0) override;
33
34private Q_SLOTS:
35 void onlineStateChanged(bool isOnline);
36
37private:
38 QNetworkConfigurationManager* m_networkManager;
39 bool m_isOnline;
40};
41
42class CachingNetworkManagerFactory : public QQmlNetworkAccessManagerFactory
43{
44public:
45 CachingNetworkManagerFactory();
46
47 QNetworkAccessManager *create(QObject *parent) override;
48};
49
50#endif // CACHINGNETWORKMANAGERFACTORY_H
051
=== modified file 'src/main.cpp'
--- src/main.cpp 2014-06-20 17:04:02 +0000
+++ src/main.cpp 2014-07-02 07:56:49 +0000
@@ -34,15 +34,15 @@
34#include <paths.h>34#include <paths.h>
35#include "MouseTouchAdaptor.h"35#include "MouseTouchAdaptor.h"
36#include "ApplicationArguments.h"36#include "ApplicationArguments.h"
37#include "CachingNetworkManagerFactory.h"
3738
38#include <unity-mir/qmirserver.h>39#include <unity-mir/qmirserver.h>
3940
40
41int startShell(int argc, const char** argv, void* server)41int startShell(int argc, const char** argv, void* server)
42{42{
43 const bool isUbuntuMirServer = qgetenv("QT_QPA_PLATFORM") == "ubuntumirserver";43 const bool isUbuntuMirServer = qgetenv("QT_QPA_PLATFORM") == "ubuntumirserver";
4444
45 QGuiApplication::setApplicationName("Unity 8");45 QGuiApplication::setApplicationName("unity8");
46 QGuiApplication *application;46 QGuiApplication *application;
4747
48 QCommandLineParser parser;48 QCommandLineParser parser;
@@ -159,6 +159,9 @@
159 }159 }
160 appendImportPaths(view->engine(), ::fallbackImportPaths());160 appendImportPaths(view->engine(), ::fallbackImportPaths());
161161
162 CachingNetworkManagerFactory *managerFactory = new CachingNetworkManagerFactory();
163 view->engine()->setNetworkAccessManagerFactory(managerFactory);
164
162 view->setSource(source);165 view->setSource(source);
163 view->setColor("transparent");166 view->setColor("transparent");
164 QObject::connect(view->engine(), SIGNAL(quit()), application, SLOT(quit()));167 QObject::connect(view->engine(), SIGNAL(quit()), application, SLOT(quit()));

Subscribers

People subscribed via source and target branches