Merge lp:~mandel/ubuntu-download-manager/count-ref-cache-management into lp:ubuntu-download-manager

Proposed by Manuel de la Peña
Status: Merged
Approved by: Manuel de la Peña
Approved revision: 146
Merged at revision: 144
Proposed branch: lp:~mandel/ubuntu-download-manager/count-ref-cache-management
Merge into: lp:ubuntu-download-manager
Prerequisite: lp:~mandel/ubuntu-download-manager/allow-empty-hash
Diff against target: 203 lines (+86/-11)
4 files modified
libubuntudownloadmanager/download_manager.cpp (+1/-1)
libubuntudownloadmanager/libubuntudownloadmanager.pro (+5/-5)
libubuntudownloadmanager/request_factory.cpp (+74/-4)
libubuntudownloadmanager/request_factory.h (+6/-1)
To merge this branch: bzr merge lp:~mandel/ubuntu-download-manager/count-ref-cache-management
Reviewer Review Type Date Requested Status
Alejandro J. Cura (community) Approve
PS Jenkins bot continuous-integration Approve
Barry Warsaw (community) Approve
Review via email: mp+188170@code.launchpad.net

Commit message

Keep track of the replies so that when the daemon is stoppable we clear the cache.

Description of the change

Keep track of the replies so that when the daemon is stoppable we clear the cache.

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
144. By Manuel de la Peña

Merged allow-empty-hash into count-ref-cache-management.

145. By Manuel de la Peña

Deal with ssl errors correctly.

Revision history for this message
Barry Warsaw (barry) wrote :

Ran the s-i full test suite against this branch and everything passes!

146. By Manuel de la Peña

Remove not needed explicit.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Barry Warsaw (barry) :
review: Approve
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Alejandro J. Cura (alecu) wrote :

All of the testing code enabled by _stoppable looks like it should belong in FakeRequestFactory, in the testing classes.
Is there a reason why this has to be in the code used for production?

review: Needs Information
Revision history for this message
Manuel de la Peña (mandel) wrote :

> All of the testing code enabled by _stoppable looks like it should belong in
> FakeRequestFactory, in the testing classes.
> Is there a reason why this has to be in the code used for production?

This is only used in production if the daemon is started with the -stoppable option that is only used in integration testes where a real daemon is used to perform downloads from a local server. The reason to add this is explained in the linked bug.

Revision history for this message
Alejandro J. Cura (alecu) wrote :

+1

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'libubuntudownloadmanager/download_manager.cpp'
2--- libubuntudownloadmanager/download_manager.cpp 2013-09-25 16:07:02 +0000
3+++ libubuntudownloadmanager/download_manager.cpp 2013-09-27 22:32:13 +0000
4@@ -47,7 +47,7 @@
5 _networkInfo = QSharedPointer<SystemNetworkInfo>(
6 new SystemNetworkInfo());
7 QSharedPointer<RequestFactory> nam = QSharedPointer<RequestFactory>(
8- new RequestFactory());
9+ new RequestFactory(_stoppable));
10 _processFactory = QSharedPointer<ProcessFactory>(new ProcessFactory());
11 _downloadFactory = QSharedPointer<DownloadFactory>(
12 new DownloadFactory(_apparmor, _networkInfo, nam,
13
14=== modified file 'libubuntudownloadmanager/libubuntudownloadmanager.pro'
15--- libubuntudownloadmanager/libubuntudownloadmanager.pro 2013-09-09 09:19:11 +0000
16+++ libubuntudownloadmanager/libubuntudownloadmanager.pro 2013-09-27 22:32:13 +0000
17@@ -10,6 +10,7 @@
18
19 SOURCES += \
20 application.cpp \
21+ apparmor.cpp \
22 dbus_connection.cpp \
23 download.cpp \
24 download_adaptor.cpp \
25@@ -35,13 +36,14 @@
26 file_manager.cpp \
27 download_struct.cpp \
28 downloads_db.cpp \
29- dbus_proxy.cpp \
30- apparmor.cpp
31+ dbus_proxy.cpp
32
33 HEADERS +=\
34 app-downloader-lib_global.h \
35+ apparmor.h \
36 application.h \
37 dbus_connection.h \
38+ dbus_proxy.h \
39 download.h \
40 download_adaptor.h \
41 download_daemon.h \
42@@ -66,9 +68,7 @@
43 download_factory.h \
44 file_manager.h \
45 download_struct.h \
46- downloads_db.h \
47- dbus_proxy.h \
48- apparmor.h
49+ downloads_db.h
50
51 OTHER_FILES += \
52 generate_adaptors.sh \
53
54=== modified file 'libubuntudownloadmanager/request_factory.cpp'
55--- libubuntudownloadmanager/request_factory.cpp 2013-09-23 11:17:17 +0000
56+++ libubuntudownloadmanager/request_factory.cpp 2013-09-27 22:32:13 +0000
57@@ -16,6 +16,7 @@
58 * Boston, MA 02110-1301, USA.
59 */
60
61+#include <QDebug>
62 #include <QNetworkAccessManager>
63 #include <QSslError>
64 #include "./request_factory.h"
65@@ -28,18 +29,35 @@
66 Q_DECLARE_PUBLIC(RequestFactory)
67
68 public:
69- explicit RequestFactoryPrivate(RequestFactory* parent)
70- : q_ptr(parent) {
71+ RequestFactoryPrivate(bool stoppable, RequestFactory* parent)
72+ : _stoppable(stoppable),
73+ q_ptr(parent) {
74 _nam = new QNetworkAccessManager();
75 }
76
77 NetworkReply* get(const QNetworkRequest& request) {
78+ Q_Q(RequestFactory);
79+
80 QNetworkReply* qreply = _nam->get(request);
81 NetworkReply* reply = new NetworkReply(qreply);
82
83 if (_certs.count() > 0) {
84 reply->setAcceptedCertificates(_certs);
85 }
86+
87+ if (_stoppable) {
88+ // if the daemon was started as stoppable it means that
89+ // we are in testing mode and we do not want to keep
90+ // the connections for too long
91+ _replies.append(reply);
92+
93+ q->connect(reply, SIGNAL(error(QNetworkReply::NetworkError)),
94+ q, SLOT(onError(QNetworkReply::NetworkError)));
95+ q->connect(reply, SIGNAL(finished()),
96+ q, SLOT(onFinished()));
97+ q->connect(reply, SIGNAL(sslErrors(const QList<QSslError>&)),
98+ q, SLOT(onSslErrors(const QList<QSslError>&)));
99+ }
100 return reply;
101 }
102
103@@ -51,7 +69,57 @@
104 _certs = certs;
105 }
106
107+ void removeNetworkReply(NetworkReply* reply) {
108+ if (_replies.contains(reply)) {
109+ _replies.removeAll(reply);
110+ // stoppable is not really needed but is better check
111+ if (_stoppable && _replies.count() == 0) {
112+ qDebug() << "Clearing the connections cache.";
113+ _nam->clearAccessCache();
114+ }
115+ }
116+ }
117+
118+ void onError(QNetworkReply::NetworkError) {
119+ Q_Q(RequestFactory);
120+ NetworkReply* sender = qobject_cast<NetworkReply*>(q->sender());
121+ removeNetworkReply(sender);
122+ }
123+
124+ void onFinished() {
125+ Q_Q(RequestFactory);
126+ NetworkReply* sender = qobject_cast<NetworkReply*>(q->sender());
127+ removeNetworkReply(sender);
128+ }
129+
130+ void onSslErrors(const QList<QSslError>& errors) {
131+ Q_Q(RequestFactory);
132+ NetworkReply* sender = qobject_cast<NetworkReply*>(q->sender());
133+ // only remove the connection and clear the cache if we cannot
134+ // ignore the ssl errors!
135+
136+ foreach(QSslError error, errors) {
137+ QSslError::SslError type = error.error();
138+ if (type != QSslError::NoError &&
139+ type != QSslError::SelfSignedCertificate) {
140+ // we only support self signed certificates all errors
141+ // will not be ignored
142+ qDebug() << "SSL error type not ignored clearing cache";
143+ removeNetworkReply(sender);
144+ } else if (type == QSslError::SelfSignedCertificate) {
145+ // just ignore those errors of the added errors
146+ if (!_certs.contains(error.certificate())) {
147+ qDebug() << "SSL certificate not ignored clearing cache";
148+ removeNetworkReply(sender);
149+ }
150+ }
151+ }
152+
153+ }
154+
155 private:
156+ bool _stoppable = false;
157+ QList<NetworkReply*> _replies;
158 QList<QSslCertificate> _certs;
159 QNetworkAccessManager* _nam;
160 RequestFactory* q_ptr;
161@@ -61,9 +129,9 @@
162 * PUBLIC IMPLEMENTATION
163 */
164
165-RequestFactory::RequestFactory(QObject *parent)
166+RequestFactory::RequestFactory(bool stoppable, QObject *parent)
167 : QObject(parent),
168- d_ptr(new RequestFactoryPrivate(this)) {
169+ d_ptr(new RequestFactoryPrivate(stoppable, this)) {
170 }
171
172 NetworkReply*
173@@ -83,3 +151,5 @@
174 Q_D(RequestFactory);
175 d->setAcceptedCertificates(certs);
176 }
177+
178+#include "moc_request_factory.cpp"
179
180=== modified file 'libubuntudownloadmanager/request_factory.h'
181--- libubuntudownloadmanager/request_factory.h 2013-09-17 10:37:08 +0000
182+++ libubuntudownloadmanager/request_factory.h 2013-09-27 22:32:13 +0000
183@@ -31,7 +31,7 @@
184 Q_DECLARE_PRIVATE(RequestFactory)
185
186 public:
187- explicit RequestFactory(QObject *parent = 0);
188+ RequestFactory(bool stoppable = false, QObject *parent = 0);
189
190 virtual NetworkReply* get(const QNetworkRequest& request);
191
192@@ -40,6 +40,11 @@
193 virtual void setAcceptedCertificates(const QList<QSslCertificate>& certs);
194
195 private:
196+ Q_PRIVATE_SLOT(d_func(), void onError(QNetworkReply::NetworkError))
197+ Q_PRIVATE_SLOT(d_func(), void onFinished())
198+ Q_PRIVATE_SLOT(d_func(), void onSslErrors(const QList<QSslError>&))
199+
200+ private:
201 // use pimpl so that we can mantains ABI compatibility
202 RequestFactoryPrivate* d_ptr;
203 };

Subscribers

People subscribed via source and target branches