Merge lp:~ahayzen/content-hub/abort-transfer-when-no-peer into lp:content-hub

Proposed by Andrew Hayzen
Status: Merged
Approved by: Ken VanDine
Approved revision: 324
Merged at revision: 329
Proposed branch: lp:~ahayzen/content-hub/abort-transfer-when-no-peer
Merge into: lp:content-hub
Prerequisite: lp:~ahayzen/content-hub/printing-trusted-export
Diff against target: 101 lines (+30/-0)
3 files modified
include/com/ubuntu/content/hub.h (+2/-0)
src/com/ubuntu/content/hub.cpp (+25/-0)
src/com/ubuntu/content/utils.cpp (+3/-0)
To merge this branch: bzr merge lp:~ahayzen/content-hub/abort-transfer-when-no-peer
Reviewer Review Type Date Requested Status
Ken VanDine Approve
system-apps-ci-bot continuous-integration Pending
Review via email: mp+316573@code.launchpad.net

This proposal supersedes a proposal from 2017-02-02.

Commit message

* If the peer isn't valid then abort the transfer

Description of the change

* If the peer isn't valid then abort the transfer

To post a comment you must log in.
Revision history for this message
Ken VanDine (ken-vandine) wrote : Posted in a previous version of this proposal

I'm happy with this approach, please do the same for import and share as well.

Revision history for this message
Ken VanDine (ken-vandine) wrote : Posted in a previous version of this proposal

This looks great, thanks!

review: Approve
Revision history for this message
Andrew Hayzen (ahayzen) wrote :

Rebased ontop of lp:~ahayzen/content-hub/printing-trusted-export so that the silo can build :-)

322. By Andrew Hayzen

* Pull of lp:~ahayzen/content-hub/printing-trusted-export

323. By Andrew Hayzen

* Fix bad merge conflict resolution

324. By Andrew Hayzen

* Pull of lp:~ahayzen/content-hub/printing-trusted-export

Revision history for this message
Ken VanDine (ken-vandine) wrote :

Thanks

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'include/com/ubuntu/content/hub.h'
2--- include/com/ubuntu/content/hub.h 2017-02-07 15:01:58 +0000
3+++ include/com/ubuntu/content/hub.h 2017-02-07 15:01:58 +0000
4@@ -105,6 +105,8 @@
5 void onPasteFormatsChanged(const QStringList &);
6 void onPeerSelected(const QString &, const QString &);
7 void onPeerSelectionCancelled(const QString &);
8+
9+ bool isPeerValid(Peer peer);
10 void onPasteSelected(const QString &, QByteArray, bool);
11 void onPasteSelectionCancelled(const QString &);
12 protected:
13
14=== modified file 'src/com/ubuntu/content/hub.cpp'
15--- src/com/ubuntu/content/hub.cpp 2017-02-07 15:01:58 +0000
16+++ src/com/ubuntu/content/hub.cpp 2017-02-07 15:01:58 +0000
17@@ -51,10 +51,12 @@
18 QDBusConnection::sessionBus(),
19 parent))
20 {
21+ testing = !qgetenv("CONTENT_HUB_TESTING").isNull();
22 }
23
24 com::ubuntu::content::dbus::Service* service;
25 QStringList pasteFormats;
26+ bool testing;
27 };
28
29 cuc::Hub::Hub(QObject* parent) : QObject(parent), d{new cuc::Hub::Private{this}}
30@@ -369,6 +371,12 @@
31 cuc::Transfer *transfer = cuc::Transfer::Private::make_transfer(reply.value(), this);
32 const cuc::Store *store = new cuc::Store{QStandardPaths::writableLocation(QStandardPaths::CacheLocation) + "/HubIncoming/" + QString::number(transfer->id()), this};
33 transfer->setStore(store);
34+
35+ if (!isPeerValid(peer)) {
36+ TRACE() << Q_FUNC_INFO << "Aborting transfer as peer was not valid";
37+ transfer->abort();
38+ }
39+
40 return transfer;
41 }
42
43@@ -396,6 +404,12 @@
44 TRACE() << Q_FUNC_INFO << "STORE:" << store->uri();
45 transfer->setStore(store);
46 transfer->start();
47+
48+ if (!isPeerValid(peer)) {
49+ TRACE() << Q_FUNC_INFO << "Aborting transfer as peer was not valid";
50+ transfer->abort();
51+ }
52+
53 return transfer;
54 }
55
56@@ -422,6 +436,12 @@
57 TRACE() << Q_FUNC_INFO << "STORE:" << store->uri();
58 transfer->setStore(store);
59 transfer->start();
60+
61+ if (!isPeerValid(peer)) {
62+ TRACE() << Q_FUNC_INFO << "Aborting transfer as peer was not valid";
63+ transfer->abort();
64+ }
65+
66 return transfer;
67 }
68
69@@ -453,6 +473,11 @@
70 return qdbus_cast<cuc::Peer>(peer.variant());
71 }
72
73+bool cuc::Hub::isPeerValid(Peer peer)
74+{
75+ return d->testing || info_for_app_id(peer.id()).value("valid", "false") == "true";
76+}
77+
78 QDBusPendingCall cuc::Hub::createPaste(const QString &surfaceId, const QMimeData& mimeData)
79 {
80 /* This needs to be replaced with a better way to get the APP_ID */
81
82=== modified file 'src/com/ubuntu/content/utils.cpp'
83--- src/com/ubuntu/content/utils.cpp 2016-11-07 14:59:44 +0000
84+++ src/com/ubuntu/content/utils.cpp 2017-02-07 15:01:58 +0000
85@@ -231,6 +231,8 @@
86 if (!qgetenv("CONTENT_HUB_TESTING").isNull())
87 return map;
88
89+ map["valid"] = "false";
90+
91 std::shared_ptr<ual::Registry> reg = ual::Registry::getDefault();
92 auto app_id = ual::AppID::find(id.toStdString());
93 if (app_id.empty()) {
94@@ -240,6 +242,7 @@
95 auto app = ual::Application::create(app_id, reg);
96 map["name"] = QString::fromStdString(app.get()->info()->name());
97 map["iconPath"] = QString::fromStdString(app.get()->info()->iconPath());
98+ map["valid"] = "true";
99 } catch (...) {
100 qWarning() << Q_FUNC_INFO << "Failed to create Application for" << id;
101 }

Subscribers

People subscribed via source and target branches