Merge lp:~mandel/ubuntu-download-manager/remove-request-factory-pimpl into lp:ubuntu-download-manager

Proposed by Manuel de la Peña
Status: Merged
Approved by: Manuel de la Peña
Approved revision: 172
Merged at revision: 184
Proposed branch: lp:~mandel/ubuntu-download-manager/remove-request-factory-pimpl
Merge into: lp:ubuntu-download-manager
Diff against target: 283 lines (+90/-129)
2 files modified
libubuntudownloadmanager/system/request_factory.cpp (+77/-121)
libubuntudownloadmanager/system/request_factory.h (+13/-8)
To merge this branch: bzr merge lp:~mandel/ubuntu-download-manager/remove-request-factory-pimpl
Reviewer Review Type Date Requested Status
Diego Sarmentero (community) Approve
PS Jenkins bot continuous-integration Approve
Review via email: mp+195247@code.launchpad.net

Commit message

Remove the not needed pimpl pattern in the RequestFactory class.

Description of the change

Remove the not needed pimpl pattern in the RequestFactory class.

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Diego Sarmentero (diegosarmentero) 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/system/request_factory.cpp'
2--- libubuntudownloadmanager/system/request_factory.cpp 2013-10-29 13:42:44 +0000
3+++ libubuntudownloadmanager/system/request_factory.cpp 2013-11-14 15:46:43 +0000
4@@ -17,8 +17,6 @@
5 */
6
7 #include <QDebug>
8-#include <QNetworkAccessManager>
9-#include <QSslError>
10 #include "request_factory.h"
11
12 namespace Ubuntu {
13@@ -27,141 +25,99 @@
14
15 namespace System {
16
17-/*
18- * PRIVATE IMPLEMENTATION
19- */
20-
21-class RequestFactoryPrivate {
22- Q_DECLARE_PUBLIC(RequestFactory)
23-
24- public:
25- RequestFactoryPrivate(bool stoppable, RequestFactory* parent)
26- : _stoppable(stoppable),
27- q_ptr(parent) {
28- _nam = new QNetworkAccessManager();
29- }
30-
31- NetworkReply* get(const QNetworkRequest& request) {
32- Q_Q(RequestFactory);
33-
34- QNetworkReply* qreply = _nam->get(request);
35- NetworkReply* reply = new NetworkReply(qreply);
36-
37- if (_certs.count() > 0) {
38- reply->setAcceptedCertificates(_certs);
39- }
40-
41- if (_stoppable) {
42- // if the daemon was started as stoppable it means that
43- // we are in testing mode and we do not want to keep
44- // the connections for too long
45- _replies.append(reply);
46-
47- q->connect(reply, SIGNAL(error(QNetworkReply::NetworkError)),
48- q, SLOT(onError(QNetworkReply::NetworkError)));
49- q->connect(reply, SIGNAL(finished()),
50- q, SLOT(onFinished()));
51- q->connect(reply, SIGNAL(sslErrors(const QList<QSslError>&)),
52- q, SLOT(onSslErrors(const QList<QSslError>&)));
53- }
54- return reply;
55- }
56-
57- QList<QSslCertificate> acceptedCertificates() {
58- return _certs;
59- }
60-
61- void setAcceptedCertificates(const QList<QSslCertificate>& certs) {
62- _certs = certs;
63- }
64-
65- void removeNetworkReply(NetworkReply* reply) {
66- if (_replies.contains(reply)) {
67- _replies.removeAll(reply);
68- // stoppable is not really needed but is better check
69- if (_stoppable && _replies.count() == 0) {
70- qDebug() << "Clearing the connections cache.";
71- _nam->clearAccessCache();
72- }
73- }
74- }
75-
76- void onError(QNetworkReply::NetworkError) {
77- Q_Q(RequestFactory);
78- NetworkReply* sender = qobject_cast<NetworkReply*>(q->sender());
79- removeNetworkReply(sender);
80- }
81-
82- void onFinished() {
83- Q_Q(RequestFactory);
84- NetworkReply* sender = qobject_cast<NetworkReply*>(q->sender());
85- removeNetworkReply(sender);
86- }
87-
88- void onSslErrors(const QList<QSslError>& errors) {
89- Q_Q(RequestFactory);
90- NetworkReply* sender = qobject_cast<NetworkReply*>(q->sender());
91- // only remove the connection and clear the cache if we cannot
92- // ignore the ssl errors!
93-
94- foreach(QSslError error, errors) {
95- QSslError::SslError type = error.error();
96- if (type != QSslError::NoError &&
97- type != QSslError::SelfSignedCertificate) {
98- // we only support self signed certificates all errors
99- // will not be ignored
100- qDebug() << "SSL error type not ignored clearing cache";
101- removeNetworkReply(sender);
102- } else if (type == QSslError::SelfSignedCertificate) {
103- // just ignore those errors of the added errors
104- if (!_certs.contains(error.certificate())) {
105- qDebug() << "SSL certificate not ignored clearing cache";
106- removeNetworkReply(sender);
107- }
108- }
109- }
110-
111- }
112-
113- private:
114- bool _stoppable = false;
115- QList<NetworkReply*> _replies;
116- QList<QSslCertificate> _certs;
117- QNetworkAccessManager* _nam;
118- RequestFactory* q_ptr;
119-};
120-
121-/*
122- * PUBLIC IMPLEMENTATION
123- */
124-
125-RequestFactory::RequestFactory(bool stoppable, QObject *parent)
126+RequestFactory::RequestFactory(bool stoppable, QObject* parent)
127 : QObject(parent),
128- d_ptr(new RequestFactoryPrivate(stoppable, this)) {
129+ _stoppable(stoppable) {
130+ _nam = new QNetworkAccessManager(this);
131 }
132
133 NetworkReply*
134 RequestFactory::get(const QNetworkRequest& request) {
135- Q_D(RequestFactory);
136- return d->get(request);
137+ QNetworkReply* qreply = _nam->get(request);
138+ NetworkReply* reply = new NetworkReply(qreply);
139+
140+ if (_certs.count() > 0) {
141+ reply->setAcceptedCertificates(_certs);
142+ }
143+
144+ if (_stoppable) {
145+ // if the daemon was started as stoppable it means that
146+ // we are in testing mode and we do not want to keep
147+ // the connections for too long
148+ _replies.append(reply);
149+
150+ connect(reply, &NetworkReply::error,
151+ this, &RequestFactory::onError);
152+ connect(reply, &NetworkReply::finished,
153+ this, &RequestFactory::onFinished);
154+ connect(reply, &NetworkReply::sslErrors,
155+ this, &RequestFactory::onSslErrors);
156+ }
157+ return reply;
158 }
159
160 QList<QSslCertificate>
161 RequestFactory::acceptedCertificates() {
162- Q_D(RequestFactory);
163- return d->acceptedCertificates();
164+ return _certs;
165 }
166
167 void
168 RequestFactory::setAcceptedCertificates(const QList<QSslCertificate>& certs) {
169- Q_D(RequestFactory);
170- d->setAcceptedCertificates(certs);
171-}
172+ _certs = certs;
173+}
174+
175+void
176+RequestFactory::removeNetworkReply(NetworkReply* reply) {
177+ if (_replies.contains(reply)) {
178+ _replies.removeAll(reply);
179+ // stoppable is not really needed but is better check
180+ if (_stoppable && _replies.count() == 0) {
181+ qDebug() << "Clearing the connections cache.";
182+ _nam->clearAccessCache();
183+ }
184+ }
185+}
186+
187+void
188+RequestFactory::onError(QNetworkReply::NetworkError) {
189+ NetworkReply* senderObj = qobject_cast<NetworkReply*>(sender());
190+ removeNetworkReply(senderObj);
191+}
192+
193+void
194+RequestFactory::onFinished() {
195+ NetworkReply* senderObj = qobject_cast<NetworkReply*>(sender());
196+ removeNetworkReply(senderObj);
197+}
198+
199+void
200+RequestFactory::onSslErrors(const QList<QSslError>& errors) {
201+ NetworkReply* senderObj = qobject_cast<NetworkReply*>(sender());
202+ // only remove the connection and clear the cache if we cannot
203+ // ignore the ssl errors!
204+
205+ foreach(QSslError error, errors) {
206+ QSslError::SslError type = error.error();
207+ if (type != QSslError::NoError &&
208+ type != QSslError::SelfSignedCertificate) {
209+ // we only support self signed certificates all errors
210+ // will not be ignored
211+ qDebug() << "SSL error type not ignored clearing cache";
212+ removeNetworkReply(senderObj);
213+ } else if (type == QSslError::SelfSignedCertificate) {
214+ // just ignore those errors of the added errors
215+ if (!_certs.contains(error.certificate())) {
216+ qDebug() << "SSL certificate not ignored clearing cache";
217+ removeNetworkReply(senderObj);
218+ }
219+ }
220+ }
221+
222+}
223+
224
225 } // System
226
227 } // DownloadManager
228
229 } // Ubuntu
230-
231-#include "moc_request_factory.cpp"
232
233=== modified file 'libubuntudownloadmanager/system/request_factory.h'
234--- libubuntudownloadmanager/system/request_factory.h 2013-10-29 13:42:44 +0000
235+++ libubuntudownloadmanager/system/request_factory.h 2013-11-14 15:46:43 +0000
236@@ -19,9 +19,11 @@
237 #ifndef DOWNLOADER_LIB_REQUEST_FACTORY_H
238 #define DOWNLOADER_LIB_REQUEST_FACTORY_H
239
240+#include <QNetworkAccessManager>
241 #include <QNetworkRequest>
242 #include <QObject>
243 #include <QSslCertificate>
244+#include <QSslError>
245 #include "app-downloader-lib_global.h"
246 #include "network_reply.h"
247
248@@ -31,10 +33,8 @@
249
250 namespace System {
251
252-class RequestFactoryPrivate;
253-class APPDOWNLOADERLIBSHARED_EXPORT RequestFactory : public QObject {
254+class RequestFactory : public QObject {
255 Q_OBJECT
256- Q_DECLARE_PRIVATE(RequestFactory)
257
258 public:
259 RequestFactory(bool stoppable = false, QObject *parent = 0);
260@@ -46,13 +46,18 @@
261 virtual void setAcceptedCertificates(const QList<QSslCertificate>& certs);
262
263 private:
264- Q_PRIVATE_SLOT(d_func(), void onError(QNetworkReply::NetworkError))
265- Q_PRIVATE_SLOT(d_func(), void onFinished())
266- Q_PRIVATE_SLOT(d_func(), void onSslErrors(const QList<QSslError>&))
267+ void removeNetworkReply(NetworkReply* reply);
268+
269+ private slots:
270+ void onError(QNetworkReply::NetworkError);
271+ void onFinished();
272+ void onSslErrors(const QList<QSslError>&);
273
274 private:
275- // use pimpl so that we can mantains ABI compatibility
276- RequestFactoryPrivate* d_ptr;
277+ bool _stoppable = false;
278+ QList<NetworkReply*> _replies;
279+ QList<QSslCertificate> _certs;
280+ QNetworkAccessManager* _nam;
281 };
282
283 } // System

Subscribers

People subscribed via source and target branches