Merge lp:~alecu/unity-scope-click/in-progress into lp:unity-scope-click/devel
- in-progress
- Merge into devel
Status: | Merged |
---|---|
Approved by: | Alejandro J. Cura |
Approved revision: | 420 |
Merged at revision: | 417 |
Proposed branch: | lp:~alecu/unity-scope-click/in-progress |
Merge into: | lp:unity-scope-click/devel |
Diff against target: |
371 lines (+168/-22) 6 files modified
libclickscope/click/download-manager.cpp (+41/-3) libclickscope/click/download-manager.h (+8/-2) libclickscope/click/preview.cpp (+30/-12) libclickscope/click/preview.h (+7/-3) libclickscope/tests/test_download_manager.cpp (+4/-2) libclickscope/tests/test_preview.cpp (+78/-0) |
To merge this branch: | bzr merge lp:~alecu/unity-scope-click/in-progress |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
PS Jenkins bot (community) | continuous-integration | Approve | |
Diego Sarmentero (community) | Approve | ||
dobey (community) | Approve | ||
Review via email: mp+231740@code.launchpad.net |
Commit message
Query download manager for in-progress downloads
Description of the change
Diego Sarmentero (diegosarmentero) : | # |
- 420. By Alejandro J. Cura
-
Use only one downloader
dobey (dobey) : | # |
PS Jenkins bot (ps-jenkins) wrote : | # |
PASSED: Continuous integration, rev:420
http://
Executed test runs:
SUCCESS: http://
SUCCESS: http://
deb: http://
SUCCESS: http://
Click here to trigger a rebuild:
http://
Preview Diff
1 | === modified file 'libclickscope/click/download-manager.cpp' |
2 | --- libclickscope/click/download-manager.cpp 2014-08-11 18:30:00 +0000 |
3 | +++ libclickscope/click/download-manager.cpp 2014-08-21 14:29:59 +0000 |
4 | @@ -43,6 +43,7 @@ |
5 | |
6 | namespace udm = Ubuntu::DownloadManager; |
7 | #include <ubuntu/download_manager/download_struct.h> |
8 | +#include <ubuntu/download_manager/downloads_list.h> |
9 | #include <ubuntu/download_manager/download.h> |
10 | #include <ubuntu/download_manager/error.h> |
11 | |
12 | @@ -252,6 +253,12 @@ |
13 | emit clickTokenFetchError(QString("Network Error")); |
14 | } |
15 | |
16 | +void click::DownloadManager::getAllDownloadsWithMetadata(const QString &key, const QString &value, |
17 | + MetadataDownloadsListCb callback, |
18 | + MetadataDownloadsListCb errback) |
19 | +{ |
20 | + impl->systemDownloadManager->getAllDownloadsWithMetadata(key, value, callback, errback); |
21 | +} |
22 | |
23 | // Downloader |
24 | namespace |
25 | @@ -281,9 +288,40 @@ |
26 | { |
27 | } |
28 | |
29 | -void click::Downloader::get_download_progress(std::string /*package_name*/, const std::function<void (std::string)>& /*callback*/) |
30 | -{ |
31 | - // TODO, unimplemented. see https://bugs.launchpad.net/ubuntu-download-manager/+bug/1277814 |
32 | +click::Downloader::~Downloader() |
33 | +{ |
34 | + |
35 | +} |
36 | + |
37 | +click::DownloadManager& click::Downloader::getDownloadManager() |
38 | +{ |
39 | + return downloadManagerInstance(networkAccessManager); |
40 | +} |
41 | + |
42 | +void click::Downloader::get_download_progress(std::string package_name, const std::function<void (std::string)>& callback) |
43 | +{ |
44 | + auto& dm = getDownloadManager(); |
45 | + |
46 | + dm.getAllDownloadsWithMetadata(DOWNLOAD_APP_ID_KEY, QString::fromStdString(package_name), |
47 | + [callback, package_name](const QString& /*key*/, const QString& /*value*/, DownloadsList* downloads_list){ |
48 | + // got downloads matching metadata |
49 | + std::string object_path; |
50 | + auto downloads = downloads_list->downloads(); |
51 | + if (downloads.size() > 0) { |
52 | + auto download = downloads.at(0); |
53 | + object_path = download->id().toStdString(); |
54 | + } |
55 | + qDebug() << "Found object path" << QString::fromStdString(object_path) |
56 | + << "for package" << QString::fromStdString(package_name); |
57 | + if (downloads.size() != 1) { |
58 | + qWarning() << "More than one download with the same object path"; |
59 | + } |
60 | + callback(object_path); |
61 | + }, [callback, package_name](const QString& /*key*/, const QString& /*value*/, DownloadsList* /*downloads_list*/){ |
62 | + // no downloads found |
63 | + qDebug() << "No object path found for package" << QString::fromStdString(package_name); |
64 | + callback(""); |
65 | + }); |
66 | } |
67 | |
68 | namespace |
69 | |
70 | === modified file 'libclickscope/click/download-manager.h' |
71 | --- libclickscope/click/download-manager.h 2014-08-11 18:30:00 +0000 |
72 | +++ libclickscope/click/download-manager.h 2014-08-21 14:29:59 +0000 |
73 | @@ -63,12 +63,16 @@ |
74 | const QSharedPointer<click::CredentialsService>& ssoService, |
75 | const QSharedPointer<Ubuntu::DownloadManager::Manager>& systemDownloadManager, |
76 | QObject *parent = 0); |
77 | + DownloadManager(); |
78 | virtual ~DownloadManager(); |
79 | |
80 | public slots: |
81 | virtual void startDownload(const QString& downloadUrl, const QString& download_sha512, const QString& package_name); |
82 | virtual void fetchClickToken(const QString& downloadUrl, const QString& download_sha512); |
83 | - |
84 | + virtual void getAllDownloadsWithMetadata(const QString& key, |
85 | + const QString& value, |
86 | + MetadataDownloadsListCb callback, |
87 | + MetadataDownloadsListCb errback); |
88 | signals: |
89 | |
90 | void credentialsNotFound(); |
91 | @@ -97,9 +101,11 @@ |
92 | { |
93 | public: |
94 | Downloader(const QSharedPointer<click::network::AccessManager>& networkAccessManager); |
95 | - void get_download_progress(std::string package_name, const std::function<void (std::string)>& callback); |
96 | + virtual void get_download_progress(std::string package_name, const std::function<void (std::string)>& callback); |
97 | void startDownload(const std::string& url, const std::string& download_sha512, const std::string& package_name, |
98 | const std::function<void (std::pair<std::string, InstallError>)>& callback); |
99 | + virtual ~Downloader(); |
100 | + virtual click::DownloadManager& getDownloadManager(); |
101 | private: |
102 | QSharedPointer<click::network::AccessManager> networkAccessManager; |
103 | }; |
104 | |
105 | === modified file 'libclickscope/click/preview.cpp' |
106 | --- libclickscope/click/preview.cpp 2014-08-19 21:42:44 +0000 |
107 | +++ libclickscope/click/preview.cpp 2014-08-21 14:29:59 +0000 |
108 | @@ -146,17 +146,17 @@ |
109 | } else { |
110 | qWarning() << "unexpected action id " << QString::fromStdString(action_id) |
111 | << " given with download_url" << QString::fromStdString(download_url); |
112 | - return new UninstalledPreview(result, client, depts); |
113 | + return new UninstalledPreview(result, client, depts, nam); |
114 | } |
115 | } else if (metadict.count(click::Preview::Actions::UNINSTALL_CLICK) != 0) { |
116 | return new UninstallConfirmationPreview(result); |
117 | } else if (metadict.count(click::Preview::Actions::CONFIRM_UNINSTALL) != 0) { |
118 | - return new UninstallingPreview(result, client); |
119 | + return new UninstallingPreview(result, client, nam); |
120 | } else if (metadict.count(click::Preview::Actions::RATED) != 0) { |
121 | return new InstalledPreview(result, metadata, client, depts); |
122 | } else { |
123 | qWarning() << "preview() called with unexpected metadata. returning uninstalled preview"; |
124 | - return new UninstalledPreview(result, client, depts); |
125 | + return new UninstalledPreview(result, client, depts, nam); |
126 | } |
127 | } else { |
128 | // metadata.scope_data() is Null, so we return an appropriate "default" preview: |
129 | @@ -167,7 +167,7 @@ |
130 | if (result["installed"].get_bool() == true) { |
131 | return new InstalledPreview(result, metadata, client, depts); |
132 | } else { |
133 | - return new UninstalledPreview(result, client, depts); |
134 | + return new UninstalledPreview(result, client, depts, nam); |
135 | } |
136 | } |
137 | |
138 | @@ -526,7 +526,7 @@ |
139 | }); |
140 | } |
141 | |
142 | -scopes::PreviewWidgetList InstallingPreview::progressBarWidget(const std::string& object_path) |
143 | +scopes::PreviewWidgetList PreviewStrategy::progressBarWidget(const std::string& object_path) |
144 | { |
145 | scopes::PreviewWidgetList widgets; |
146 | scopes::PreviewWidget progress("download", "progress"); |
147 | @@ -807,11 +807,18 @@ |
148 | |
149 | // class UninstalledPreview |
150 | |
151 | +click::Downloader* UninstalledPreview::get_downloader(const QSharedPointer<click::network::AccessManager>& nam) |
152 | +{ |
153 | + static auto downloader = new click::Downloader(nam); |
154 | + return downloader; |
155 | +} |
156 | + |
157 | UninstalledPreview::UninstalledPreview(const unity::scopes::Result& result, |
158 | const QSharedPointer<click::web::Client>& client, |
159 | - const std::shared_ptr<click::DepartmentsDb>& depts) |
160 | + const std::shared_ptr<click::DepartmentsDb>& depts, |
161 | + const QSharedPointer<click::network::AccessManager>& nam) |
162 | : PreviewStrategy(result, client), |
163 | - DepartmentUpdater(depts) |
164 | + DepartmentUpdater(depts), nam(nam) |
165 | { |
166 | } |
167 | |
168 | @@ -821,11 +828,20 @@ |
169 | |
170 | void UninstalledPreview::run(unity::scopes::PreviewReplyProxy const& reply) |
171 | { |
172 | -qDebug() << "in UninstalledPreview::run, about to populate details"; |
173 | - |
174 | + qDebug() << "in UninstalledPreview::run, about to populate details"; |
175 | populateDetails([this, reply](const PackageDetails &details){ |
176 | store_department(details); |
177 | - pushPackagePreviewWidgets(reply, details, uninstalledActionButtonWidgets(details)); |
178 | + std::string app_name = result["name"].get_string(); |
179 | + get_downloader(nam)->get_download_progress(app_name, |
180 | + [this, reply, details](std::string object_path){ |
181 | + scopes::PreviewWidgetList button_widgets; |
182 | + if(object_path.empty()) { |
183 | + button_widgets = uninstalledActionButtonWidgets(details); |
184 | + } else { |
185 | + button_widgets = progressBarWidget(object_path); |
186 | + } |
187 | + pushPackagePreviewWidgets(reply, details, button_widgets); |
188 | + }); |
189 | }, |
190 | [this, reply](const ReviewList& reviewlist, |
191 | click::Reviews::Error error) { |
192 | @@ -874,10 +890,12 @@ |
193 | |
194 | // TODO: this class should be removed once uninstall() is handled elsewhere. |
195 | UninstallingPreview::UninstallingPreview(const unity::scopes::Result& result, |
196 | - const QSharedPointer<click::web::Client>& client) |
197 | - : UninstalledPreview(result, client, nullptr) |
198 | + const QSharedPointer<click::web::Client>& client, |
199 | + const QSharedPointer<click::network::AccessManager>& nam) |
200 | + : UninstalledPreview(result, client, nullptr, nam) |
201 | { |
202 | } |
203 | + |
204 | UninstallingPreview::~UninstallingPreview() |
205 | { |
206 | } |
207 | |
208 | === modified file 'libclickscope/click/preview.h' |
209 | --- libclickscope/click/preview.h 2014-08-19 21:42:44 +0000 |
210 | +++ libclickscope/click/preview.h 2014-08-21 14:29:59 +0000 |
211 | @@ -133,6 +133,7 @@ |
212 | virtual scopes::PreviewWidgetList headerWidgets(const PackageDetails &details); |
213 | virtual scopes::PreviewWidgetList screenshotsWidgets(const PackageDetails &details); |
214 | virtual scopes::PreviewWidgetList descriptionWidgets(const PackageDetails &details); |
215 | + virtual scopes::PreviewWidgetList progressBarWidget(const std::string& object_path); |
216 | virtual scopes::PreviewWidgetList reviewsWidgets(const click::ReviewList &reviewlist); |
217 | virtual scopes::PreviewWidgetList downloadErrorWidgets(); |
218 | virtual scopes::PreviewWidgetList loginErrorWidgets(); |
219 | @@ -183,7 +184,6 @@ |
220 | void run(unity::scopes::PreviewReplyProxy const& reply) override; |
221 | |
222 | protected: |
223 | - virtual scopes::PreviewWidgetList progressBarWidget(const std::string& object_path); |
224 | std::string download_url; |
225 | std::string download_sha512; |
226 | QSharedPointer<click::Downloader> downloader; |
227 | @@ -245,15 +245,18 @@ |
228 | |
229 | class UninstalledPreview : public PreviewStrategy, public DepartmentUpdater |
230 | { |
231 | + const QSharedPointer<click::network::AccessManager>& nam; |
232 | public: |
233 | UninstalledPreview(const unity::scopes::Result& result, |
234 | const QSharedPointer<click::web::Client>& client, |
235 | - const std::shared_ptr<click::DepartmentsDb>& depts); |
236 | + const std::shared_ptr<click::DepartmentsDb>& depts, |
237 | + const QSharedPointer<click::network::AccessManager>& nam); |
238 | |
239 | virtual ~UninstalledPreview(); |
240 | |
241 | void run(unity::scopes::PreviewReplyProxy const& reply) override; |
242 | protected: |
243 | + virtual click::Downloader* get_downloader(const QSharedPointer<click::network::AccessManager>& nam); |
244 | virtual scopes::PreviewWidgetList uninstalledActionButtonWidgets(const PackageDetails &details); |
245 | }; |
246 | |
247 | @@ -263,7 +266,8 @@ |
248 | { |
249 | public: |
250 | UninstallingPreview(const unity::scopes::Result& result, |
251 | - const QSharedPointer<click::web::Client>& client); |
252 | + const QSharedPointer<click::web::Client>& client, |
253 | + const QSharedPointer<click::network::AccessManager>& nam); |
254 | |
255 | virtual ~UninstallingPreview(); |
256 | |
257 | |
258 | === modified file 'libclickscope/tests/test_download_manager.cpp' |
259 | --- libclickscope/tests/test_download_manager.cpp 2014-08-11 18:30:00 +0000 |
260 | +++ libclickscope/tests/test_download_manager.cpp 2014-08-21 14:29:59 +0000 |
261 | @@ -47,6 +47,8 @@ |
262 | |
263 | #include "mock_ubuntu_download_manager.h" |
264 | |
265 | +using namespace ::testing; |
266 | + |
267 | namespace udm = Ubuntu::DownloadManager; |
268 | #include <ubuntu/download_manager/download_struct.h> |
269 | |
270 | @@ -383,13 +385,13 @@ |
271 | |
272 | std::function<void()> clickTokenSignalFunc; |
273 | if (p.clickTokenFetchSignalsError) { |
274 | - clickTokenSignalFunc = std::function<void()>([&](){ |
275 | + clickTokenSignalFunc = std::function<void()>([&](){ |
276 | dm.clickTokenFetchError(TEST_DOWNLOADERROR_STRING); |
277 | }); |
278 | EXPECT_CALL(*mockSystemDownloadManager, createDownload(_)).Times(0); |
279 | |
280 | } else { |
281 | - clickTokenSignalFunc = std::function<void()>([&](){ |
282 | + clickTokenSignalFunc = std::function<void()>([&](){ |
283 | dm.clickTokenFetched(TEST_CLICK_TOKEN_VALUE); |
284 | }); |
285 | |
286 | |
287 | === modified file 'libclickscope/tests/test_preview.cpp' |
288 | --- libclickscope/tests/test_preview.cpp 2014-08-19 21:42:44 +0000 |
289 | +++ libclickscope/tests/test_preview.cpp 2014-08-21 14:29:59 +0000 |
290 | @@ -210,3 +210,81 @@ |
291 | EXPECT_CALL(preview, build_installing(_, FAKE_SHA512, _, _, _, _)); |
292 | preview.choose_strategy(client, nam, depts); |
293 | } |
294 | + |
295 | + |
296 | +class UninstalledPreviewTest : public PreviewsBaseTest { |
297 | +public: |
298 | + FakeResult result{vm}; |
299 | + click::PackageDetails details; |
300 | + unity::scopes::PreviewWidgetList widgets; |
301 | + QSharedPointer<click::web::Client> client; |
302 | + QSharedPointer<click::network::AccessManager> nam; |
303 | + std::shared_ptr<click::DepartmentsDb> depts; |
304 | + unity::scopes::testing::MockPreviewReply reply; |
305 | + std::shared_ptr<unity::scopes::testing::MockPreviewReply> replyptr{&reply, [](unity::scopes::testing::MockPreviewReply*){}}; |
306 | +}; |
307 | + |
308 | +class FakeDownloader : public click::Downloader { |
309 | + std::string object_path; |
310 | +public: |
311 | + FakeDownloader(const std::string& object_path, const QSharedPointer<click::network::AccessManager>& networkAccessManager) |
312 | + : click::Downloader(networkAccessManager), object_path(object_path) |
313 | + { |
314 | + |
315 | + } |
316 | + void get_download_progress(std::string /*package_name*/, const std::function<void (std::string)> &callback) |
317 | + { |
318 | + callback(object_path); |
319 | + } |
320 | +}; |
321 | + |
322 | +class FakeUninstalledPreview : public click::UninstalledPreview { |
323 | + std::string object_path; |
324 | +public: |
325 | + FakeUninstalledPreview(const std::string& object_path, |
326 | + const unity::scopes::Result& result, |
327 | + const QSharedPointer<click::web::Client>& client, |
328 | + const std::shared_ptr<click::DepartmentsDb>& depts, |
329 | + const QSharedPointer<click::network::AccessManager>& nam) |
330 | + : click::UninstalledPreview(result, client, depts, nam), object_path(object_path) |
331 | + { |
332 | + |
333 | + } |
334 | + |
335 | + virtual click::Downloader* get_downloader(const QSharedPointer<click::network::AccessManager> &nam) |
336 | + { |
337 | + return new FakeDownloader(object_path, nam); |
338 | + } |
339 | + |
340 | + void populateDetails(std::function<void (const click::PackageDetails &)> details_callback, |
341 | + std::function<void (const click::ReviewList &, click::Reviews::Error)> /*reviews_callback*/) { |
342 | + click::PackageDetails details; |
343 | + details_callback(details); |
344 | + } |
345 | + MOCK_METHOD1(uninstalledActionButtonWidgets, scopes::PreviewWidgetList (const click::PackageDetails &details)); |
346 | + MOCK_METHOD1(progressBarWidget, scopes::PreviewWidgetList(const std::string& object_path)); |
347 | +}; |
348 | + |
349 | +TEST_F(UninstalledPreviewTest, testDownloadInProgress) { |
350 | + std::string fake_object_path = "/fake/object/path"; |
351 | + |
352 | + result["name"] = "fake_app_name"; |
353 | + scopes::PreviewWidgetList response; |
354 | + FakeUninstalledPreview preview(fake_object_path, result, client, depts, nam); |
355 | + EXPECT_CALL(preview, progressBarWidget(_)) |
356 | + .Times(1) |
357 | + .WillOnce(Return(response)); |
358 | + preview.run(replyptr); |
359 | +} |
360 | + |
361 | +TEST_F(UninstalledPreviewTest, testNoDownloadProgress) { |
362 | + std::string fake_object_path = ""; |
363 | + |
364 | + result["name"] = "fake_app_name"; |
365 | + scopes::PreviewWidgetList response; |
366 | + FakeUninstalledPreview preview(fake_object_path, result, client, depts, nam); |
367 | + EXPECT_CALL(preview, uninstalledActionButtonWidgets(_)) |
368 | + .Times(1) |
369 | + .WillOnce(Return(response)); |
370 | + preview.run(replyptr); |
371 | +} |
looks good, +1