MCPcopy Create free account
hub / github.com/audacity/audacity / DownloadBlob

Method DownloadBlob

libraries/lib-cloud-audiocom/sync/RemoteProjectSnapshot.cpp:364–431  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

362}
363
364void RemoteProjectSnapshot::DownloadBlob(
365 std::string url, SuccessHandler onSuccess, int retries)
366{
367 using namespace audacity::network_manager;
368
369 auto request = Request(url);
370
371 auto response = NetworkManager::GetInstance().doGet(request);
372
373 {
374 auto responsesLock = std::lock_guard { mResponsesMutex };
375 mResponses.push_back(response);
376 }
377
378 assert(!weak_from_this().expired());
379
380 response->setDownloadProgressCallback([this, self = weak_from_this()](int64_t current, int64_t expected) {
381 auto strong = self.lock();
382 if(!strong) {
383 return;
384 }
385 ReportProgress();
386 });
387
388 response->setRequestFinishedCallback(
389 [this, self = weak_from_this(), onSuccess = std::move(onSuccess), retries, response](auto)
390 {
391 auto strong = self.lock();
392 if(!strong)
393 return;
394
395 mDownloadedBytes.fetch_add(
396 response->getBytesAvailable(), std::memory_order_acq_rel);
397
398 RemoveResponse(response.get());
399
400 auto responseResult = GetResponseResult(*response, false);
401
402 if (responseResult.Code == SyncResultCode::Cancelled)
403 return;
404
405 if (
406 responseResult.Code != SyncResultCode::Success &&
407 responseResult.Code != SyncResultCode::ConnectionFailed)
408 {
409 OnFailure(std::move(responseResult));
410 return;
411 }
412
413 // The cloud storage may throw a recoverable InternalServerError, so lets retry
414 if (responseResult.Code == SyncResultCode::ConnectionFailed || responseResult.Code == SyncResultCode::InternalServerError)
415 {
416 if (retries <= 0)
417 {
418 OnFailure(std::move(responseResult));
419 return;
420 }
421

Callers

nothing calls this directly

Calls 11

moveFunction · 0.85
GetResponseResultFunction · 0.85
doGetMethod · 0.80
RequestClass · 0.50
push_backMethod · 0.45
lockMethod · 0.45
getBytesAvailableMethod · 0.45
getMethod · 0.45
getURLMethod · 0.45

Tested by

no test coverage detected