Audacity 3.2.0
Classes | Public Types | Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | List of all members
audacity::cloud::audiocom::sync::LocalProjectSnapshot Class Referencefinal

#include <LocalProjectSnapshot.h>

Inheritance diagram for audacity::cloud::audiocom::sync::LocalProjectSnapshot:
[legend]
Collaboration diagram for audacity::cloud::audiocom::sync::LocalProjectSnapshot:
[legend]

Classes

struct  ProjectBlocksLock
 
struct  SnapshotData
 
struct  Tag
 

Public Types

using Promise = std::promise< SnapshotData >
 
using Future = std::future< SnapshotData >
 

Public Member Functions

 LocalProjectSnapshot (Tag, const ServiceConfig &config, const OAuthService &oauthService, ProjectCloudExtension &extension, std::string name, UploadMode mode, AudiocomTrace trace)
 
 ~LocalProjectSnapshot () override
 
bool IsCompleted () const override
 
std::shared_ptr< AudacityProjectGetProject ()
 
void Start () override
 
void SetUploadData (const ProjectUploadData &data) override
 
void Cancel () override
 
void Abort ()
 
- Public Member Functions inherited from audacity::cloud::audiocom::sync::ProjectUploadOperation
virtual ~ProjectUploadOperation ()=default
 
virtual void Start ()=0
 
virtual void SetUploadData (const ProjectUploadData &data)=0
 
virtual bool IsCompleted () const =0
 
- Public Member Functions inherited from audacity::concurrency::ICancellable
virtual ~ICancellable ()=default
 
virtual void Cancel ()=0
 

Static Public Member Functions

static Future Create (const ServiceConfig &config, const OAuthService &oauthService, ProjectCloudExtension &extension, std::string name, UploadMode mode, AudiocomTrace trace)
 

Private Member Functions

void UploadFailed (CloudSyncError error)
 
void DataUploadFailed (const ResponseResult &uploadResult)
 
void DataUploadFailed (const MissingBlocksUploadProgress &uploadResult)
 
void UpdateProjectSnapshot ()
 
void OnSnapshotCreated (const CreateSnapshotResponse &response, bool newProject)
 
void StorePendingSnapshot (const CreateSnapshotResponse &response, const ProjectUploadData &data)
 
void MarkSnapshotSynced ()
 
void DeleteSnapshot ()
 

Private Attributes

ProjectCloudExtensionmProjectCloudExtension
 
std::weak_ptr< AudacityProjectmWeakProject
 
std::promise< ProjectUploadDatamProjectDataPromise
 
const ServiceConfigmServiceConfig
 
const OAuthServicemOAuthService
 
const AudiocomTrace mAudiocomTrace
 
std::string mProjectName
 
std::unique_ptr< ProjectBlocksLockmProjectBlocksLock
 
std::shared_ptr< MissingBlocksUploadermMissingBlockUploader
 
std::mutex mCreateSnapshotResponseMutex
 
std::optional< CreateSnapshotResponsemCreateSnapshotResponse
 
UploadMode mUploadMode { UploadMode::Normal }
 
Promise mCreateSnapshotPromise
 
concurrency::CancellationContextPtr mCancellationContext
 
std::atomic< bool > mCompleted { false }
 
std::atomic< bool > mCancelled { false }
 
std::atomic< bool > mProjectDataReady { false }
 

Detailed Description

Definition at line 48 of file LocalProjectSnapshot.h.

Member Typedef Documentation

◆ Future

Definition at line 64 of file LocalProjectSnapshot.h.

◆ Promise

Definition at line 63 of file LocalProjectSnapshot.h.

Constructor & Destructor Documentation

◆ LocalProjectSnapshot()

audacity::cloud::audiocom::sync::LocalProjectSnapshot::LocalProjectSnapshot ( Tag  ,
const ServiceConfig config,
const OAuthService oauthService,
ProjectCloudExtension extension,
std::string  name,
UploadMode  mode,
AudiocomTrace  trace 
)

Definition at line 200 of file LocalProjectSnapshot.cpp.

205 , mWeakProject { extension.GetProject() }
206 , mServiceConfig { config }
207 , mOAuthService { oauthService }
208 , mAudiocomTrace { trace }
209 , mProjectName { std::move(name) }
210 , mUploadMode { mode }
212{
213}
wxString name
Definition: TagsEditor.cpp:166
concurrency::CancellationContextPtr mCancellationContext

◆ ~LocalProjectSnapshot()

audacity::cloud::audiocom::sync::LocalProjectSnapshot::~LocalProjectSnapshot ( )
override

Definition at line 215 of file LocalProjectSnapshot.cpp.

216{
217}

Member Function Documentation

◆ Abort()

void audacity::cloud::audiocom::sync::LocalProjectSnapshot::Abort ( )

Definition at line 287 of file LocalProjectSnapshot.cpp.

References audacity::cloud::audiocom::sync::CloudSyncError::Aborted, DeleteSnapshot(), mCancellationContext, mCancelled, mProjectDataPromise, mProjectDataReady, and UploadFailed().

Here is the call graph for this function:

◆ Cancel()

void audacity::cloud::audiocom::sync::LocalProjectSnapshot::Cancel ( )
overridevirtual

Implements audacity::concurrency::ICancellable.

Definition at line 275 of file LocalProjectSnapshot.cpp.

276{
277 mCancelled.store(true, std::memory_order_release);
278
279 mCancellationContext->Cancel();
280
281 if (!mProjectDataReady.load(std::memory_order_acquire))
282 mProjectDataPromise.set_value({});
283
285}

References audacity::cloud::audiocom::sync::CloudSyncError::Cancelled, mCancellationContext, mCancelled, mProjectDataPromise, mProjectDataReady, and UploadFailed().

Here is the call graph for this function:

◆ Create()

LocalProjectSnapshot::Future audacity::cloud::audiocom::sync::LocalProjectSnapshot::Create ( const ServiceConfig config,
const OAuthService oauthService,
ProjectCloudExtension extension,
std::string  name,
UploadMode  mode,
AudiocomTrace  trace 
)
static

Definition at line 219 of file LocalProjectSnapshot.cpp.

223{
224 auto project = extension.GetProject().lock();
225
226 if (!project)
227 return {};
228
229 auto snapshot = std::make_shared<LocalProjectSnapshot>(
230 Tag {}, config, oauthService, extension, std::move(name), mode, trace);
231
232 snapshot->mProjectCloudExtension.OnUploadOperationCreated(snapshot);
233
234 snapshot->mProjectBlocksLock = std::make_unique<ProjectBlocksLock>(
236 [weakSnapshot = std::weak_ptr(snapshot)]
237 {
238 auto snapshot = weakSnapshot.lock();
239
240 if (snapshot == nullptr)
241 return;
242
243 auto project = snapshot->GetProject();
244
245 if (project == nullptr)
246 return;
247
248 snapshot->mProjectCloudExtension.OnBlocksHashed(*snapshot);
249 });
250
251 return snapshot->mCreateSnapshotPromise.get_future();
252}
const auto project

References anonymous_namespace{CloudProjectFileIOExtensions.cpp}::extension, name, and project.

◆ DataUploadFailed() [1/2]

void audacity::cloud::audiocom::sync::LocalProjectSnapshot::DataUploadFailed ( const MissingBlocksUploadProgress uploadResult)
private

Definition at line 313 of file LocalProjectSnapshot.cpp.

315{
317
318 for (const auto& uploadError : uploadResult.UploadErrors)
319 {
320 if (
321 uploadError.Code == SyncResultCode::Success ||
322 uploadError.Code == SyncResultCode::Conflict)
323 continue;
324
325 const auto deducedError = DeduceError(uploadError.Code);
326
327 if (
329 deducedError == CloudSyncError::Network)
330 {
331 errorType = deducedError;
332 }
333 else if (
335 deducedError == CloudSyncError::Cancelled)
336 {
337 errorType = deducedError;
338 break;
339 }
340 }
341
342 UploadFailed({ errorType, {} });
343}
CloudSyncError::ErrorType DeduceError(SyncResultCode code)

References audacity::cloud::audiocom::sync::CloudSyncError::Cancelled, audacity::cloud::audiocom::Conflict, audacity::cloud::audiocom::sync::CloudSyncError::DataUploadFailed, audacity::cloud::audiocom::sync::DeduceError(), audacity::cloud::audiocom::sync::CloudSyncError::Network, audacity::cloud::audiocom::sync::CloudSyncError::ProjectStorageLimitReached, audacity::cloud::audiocom::Success, audacity::cloud::audiocom::sync::MissingBlocksUploadProgress::UploadErrors, and UploadFailed().

Here is the call graph for this function:

◆ DataUploadFailed() [2/2]

void audacity::cloud::audiocom::sync::LocalProjectSnapshot::DataUploadFailed ( const ResponseResult uploadResult)
private

Definition at line 308 of file LocalProjectSnapshot.cpp.

309{
310 UploadFailed({ DeduceError(uploadResult.Code), uploadResult.Content });
311}

References audacity::cloud::audiocom::ResponseResult::Code, audacity::cloud::audiocom::ResponseResult::Content, audacity::cloud::audiocom::sync::DeduceError(), and UploadFailed().

Referenced by OnSnapshotCreated().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ DeleteSnapshot()

void audacity::cloud::audiocom::sync::LocalProjectSnapshot::DeleteSnapshot ( )
private

Definition at line 608 of file LocalProjectSnapshot.cpp.

609{
611 return;
612
613 using namespace network_manager;
614
616 mCreateSnapshotResponse->Project.Id,
617 mCreateSnapshotResponse->Snapshot.Id));
618
619 SetCommonHeaders(request);
620
621 auto response = NetworkManager::GetInstance().doDelete(request);
622
623 response->setRequestFinishedCallback(
624 [this, response, strongThis = shared_from_this()](auto)
625 {
627 mCreateSnapshotResponse->Project.Id,
628 mCreateSnapshotResponse->Snapshot.Id);
629 });
630}
std::string GetDeleteSnapshotUrl(std::string_view projectId, std::string_view snapshotId) const
void RemovePendingSnapshot(std::string_view projectId, std::string_view snapshotId)
std::optional< CreateSnapshotResponse > mCreateSnapshotResponse
ResponsePtr doDelete(const Request &request)
void SetCommonHeaders(Request &request)

References audacity::network_manager::NetworkManager::doDelete(), audacity::cloud::audiocom::sync::CloudProjectsDatabase::Get(), audacity::cloud::audiocom::ServiceConfig::GetDeleteSnapshotUrl(), audacity::network_manager::NetworkManager::GetInstance(), mCreateSnapshotResponse, mServiceConfig, audacity::cloud::audiocom::sync::CloudProjectsDatabase::RemovePendingSnapshot(), and audacity::cloud::audiocom::SetCommonHeaders().

Referenced by Abort().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetProject()

std::shared_ptr< AudacityProject > audacity::cloud::audiocom::sync::LocalProjectSnapshot::GetProject ( )

Definition at line 259 of file LocalProjectSnapshot.cpp.

260{
261 return mWeakProject.lock();
262}

References mWeakProject.

◆ IsCompleted()

bool audacity::cloud::audiocom::sync::LocalProjectSnapshot::IsCompleted ( ) const
overridevirtual

Implements audacity::cloud::audiocom::sync::ProjectUploadOperation.

Definition at line 254 of file LocalProjectSnapshot.cpp.

255{
256 return mCompleted.load(std::memory_order_acquire);
257}

References mCompleted.

◆ MarkSnapshotSynced()

void audacity::cloud::audiocom::sync::LocalProjectSnapshot::MarkSnapshotSynced ( )
private

Definition at line 573 of file LocalProjectSnapshot.cpp.

574{
575 using namespace network_manager;
577 mCreateSnapshotResponse->Project.Id,
578 mCreateSnapshotResponse->Snapshot.Id));
579
580 SetCommonHeaders(request);
581
582 auto response = NetworkManager::GetInstance().doPost(request, nullptr, 0);
583
584 response->setRequestFinishedCallback(
585 [this, response, weakThis = weak_from_this()](auto)
586 {
587 auto strongThis = weakThis.lock();
588 if (!strongThis)
589 return;
590
592 mCreateSnapshotResponse->Project.Id,
593 mCreateSnapshotResponse->Snapshot.Id);
594
595 if (response->getError() != NetworkError::NoError)
596 {
598 return;
599 }
600
601 mCompleted.store(true, std::memory_order_release);
603 });
604
605 mCancellationContext->OnCancelled(response);
606}
std::string GetSnapshotSyncUrl(std::string_view projectId, std::string_view snapshotId) const
void OnSyncCompleted(const ProjectUploadOperation *uploadOperation, std::optional< CloudSyncError > error, AudiocomTrace trace)
This method is called from any thread.
ResponsePtr doPost(const Request &request, const void *data, size_t size)
CLOUD_AUDIOCOM_API CloudSyncError DeduceUploadError(audacity::network_manager::IResponse &response)

References audacity::cloud::audiocom::sync::DeduceUploadError(), audacity::network_manager::NetworkManager::doPost(), audacity::cloud::audiocom::sync::CloudProjectsDatabase::Get(), audacity::network_manager::NetworkManager::GetInstance(), audacity::cloud::audiocom::ServiceConfig::GetSnapshotSyncUrl(), mAudiocomTrace, mCancellationContext, mCompleted, mCreateSnapshotResponse, mProjectCloudExtension, mServiceConfig, audacity::cloud::audiocom::sync::ProjectCloudExtension::OnSyncCompleted(), audacity::cloud::audiocom::sync::CloudProjectsDatabase::RemovePendingSnapshot(), audacity::cloud::audiocom::SetCommonHeaders(), and UploadFailed().

Referenced by OnSnapshotCreated().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ OnSnapshotCreated()

void audacity::cloud::audiocom::sync::LocalProjectSnapshot::OnSnapshotCreated ( const CreateSnapshotResponse response,
bool  newProject 
)
private

Definition at line 442 of file LocalProjectSnapshot.cpp.

444{
445 auto project = mWeakProject.lock();
446
447 if (project == nullptr)
448 {
450 XO("Project was closed before snapshot was created")));
451 return;
452 }
453
454 if (newProject)
455 mProjectBlocksLock->UpdateProjectHashesInCache();
456
457 mProjectBlocksLock->FillMissingBlocks(response.SyncState.MissingBlocks);
458
460
461 {
462 auto lock = std::lock_guard { mCreateSnapshotResponseMutex };
463 mCreateSnapshotResponse = response;
464 }
465
466 mCreateSnapshotPromise.set_value({ response, shared_from_this() });
467
468 auto projectData = mProjectDataPromise.get_future().get();
469
470 if (mCancelled.load(std::memory_order_acquire))
471 return;
472
473 StorePendingSnapshot(response, projectData);
474
476 mCancellationContext, mServiceConfig, response.SyncState.FileUrls,
477 projectData.ProjectSnapshot,
478 [this, weakThis = weak_from_this()](ResponseResult result)
479 {
480 auto strongThis = weakThis.lock();
481 if (!strongThis)
482 return;
483
484 auto& db = CloudProjectsDatabase::Get();
485
486 const auto projectId = mCreateSnapshotResponse->Project.Id;
487 const auto snapshotId = mCreateSnapshotResponse->Snapshot.Id;
488
489 if (result.Code != SyncResultCode::Success)
490 {
491 db.RemovePendingSnapshot(projectId, snapshotId);
492 db.RemovePendingProjectBlob(projectId, snapshotId);
493 db.RemovePendingProjectBlocks(projectId, snapshotId);
494
495 DataUploadFailed(result);
496 return;
497 }
498
500 db.RemovePendingProjectBlob(projectId, snapshotId);
501
502 if (mProjectBlocksLock->MissingBlocks.empty())
503 {
505 return;
506 }
507
510 mProjectBlocksLock->MissingBlocks,
511 [this, weakThis = weak_from_this()](
512 auto result, auto block, auto uploadResult)
513 {
514 auto strongThis = weakThis.lock();
515 if (!strongThis)
516 return;
517
518 if (!IsUploadRecoverable(uploadResult.Code))
520 mCreateSnapshotResponse->Project.Id, block.Id);
521
523 *this, block.Hash,
524 uploadResult.Code == SyncResultCode::Success);
525
526 const auto completed =
527 result.UploadedBlocks == result.TotalBlocks ||
528 result.FailedBlocks != 0;
529 const bool succeeded = completed && result.FailedBlocks == 0;
530
531 if (!completed)
532 return;
533
534 if (succeeded)
536 else
537 DataUploadFailed(result);
538 });
539 });
540}
XO("Cut/Copy/Paste")
void RemovePendingProjectBlock(std::string_view projectId, int64_t blockId)
void Upload(CancellationContextPtr cancellationContex, const ServiceConfig &config, const UploadUrls &target, std::vector< uint8_t > data, std::function< void(ResponseResult)> callback, std::function< void(double)> progressCallback={})
void DataUploadFailed(const ResponseResult &uploadResult)
void StorePendingSnapshot(const CreateSnapshotResponse &response, const ProjectUploadData &data)
std::unique_ptr< ProjectBlocksLock > mProjectBlocksLock
std::shared_ptr< MissingBlocksUploader > mMissingBlockUploader
static std::shared_ptr< MissingBlocksUploader > Create(CancellationContextPtr cancellationContex, const ServiceConfig &serviceConfig, std::vector< BlockUploadTask > uploadTasks, MissingBlocksUploadProgressCallback progress)
void OnSnapshotCreated(const ProjectUploadOperation &uploadOperation, const CreateSnapshotResponse &response)
This method is called from the network thread.
void OnProjectDataUploaded(const ProjectUploadOperation &uploadOperation)
This method is called from the network thread.
void OnBlockUploaded(const ProjectUploadOperation &uploadOperation, std::string_view blockID, bool successful)
This method is called from the network thread.
CloudSyncError MakeClientFailure(const TranslatableString &message)
bool IsUploadRecoverable(SyncResultCode code)

References audacity::cloud::audiocom::ResponseResult::Code, audacity::cloud::audiocom::sync::MissingBlocksUploader::Create(), DataUploadFailed(), audacity::cloud::audiocom::sync::ProjectSyncState::FileUrls, audacity::cloud::audiocom::sync::CloudProjectsDatabase::Get(), audacity::cloud::audiocom::sync::DataUploader::Get(), audacity::cloud::audiocom::IsUploadRecoverable(), audacity::cloud::audiocom::sync::MakeClientFailure(), MarkSnapshotSynced(), mCancellationContext, mCancelled, mCreateSnapshotPromise, mCreateSnapshotResponse, mCreateSnapshotResponseMutex, audacity::cloud::audiocom::sync::ProjectSyncState::MissingBlocks, mMissingBlockUploader, mProjectBlocksLock, mProjectCloudExtension, mProjectDataPromise, mServiceConfig, mWeakProject, audacity::cloud::audiocom::sync::ProjectCloudExtension::OnBlockUploaded(), audacity::cloud::audiocom::sync::ProjectCloudExtension::OnProjectDataUploaded(), audacity::cloud::audiocom::sync::ProjectCloudExtension::OnSnapshotCreated(), project, audacity::cloud::audiocom::sync::CloudProjectsDatabase::RemovePendingProjectBlock(), StorePendingSnapshot(), audacity::cloud::audiocom::Success, audacity::cloud::audiocom::sync::CreateSnapshotResponse::SyncState, audacity::cloud::audiocom::sync::DataUploader::Upload(), UploadFailed(), and XO().

Referenced by UpdateProjectSnapshot().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SetUploadData()

void audacity::cloud::audiocom::sync::LocalProjectSnapshot::SetUploadData ( const ProjectUploadData data)
overridevirtual

Implements audacity::cloud::audiocom::sync::ProjectUploadOperation.

Definition at line 269 of file LocalProjectSnapshot.cpp.

270{
271 mProjectDataReady.store(true);
272 mProjectDataPromise.set_value(data);
273}

References mProjectDataPromise, and mProjectDataReady.

◆ Start()

void audacity::cloud::audiocom::sync::LocalProjectSnapshot::Start ( )
overridevirtual

Implements audacity::cloud::audiocom::sync::ProjectUploadOperation.

Definition at line 264 of file LocalProjectSnapshot.cpp.

References UpdateProjectSnapshot().

Here is the call graph for this function:

◆ StorePendingSnapshot()

void audacity::cloud::audiocom::sync::LocalProjectSnapshot::StorePendingSnapshot ( const CreateSnapshotResponse response,
const ProjectUploadData data 
)
private

Definition at line 542 of file LocalProjectSnapshot.cpp.

544{
546 { response.Project.Id, response.Snapshot.Id,
548 response.Project.Id, response.Snapshot.Id) });
549
551 { response.Project.Id, response.Snapshot.Id,
552 response.SyncState.FileUrls.UploadUrl,
553 response.SyncState.FileUrls.SuccessUrl,
554 response.SyncState.FileUrls.FailUrl, projectData.ProjectSnapshot });
555
556 if (mProjectBlocksLock->MissingBlocks.empty())
557 return;
558
559 std::vector<PendingProjectBlockData> pendingBlocks;
560 pendingBlocks.reserve(mProjectBlocksLock->MissingBlocks.size());
561
562 for (const auto& block : mProjectBlocksLock->MissingBlocks)
563 {
564 pendingBlocks.push_back(PendingProjectBlockData {
565 response.Project.Id, response.Snapshot.Id, block.BlockUrls.UploadUrl,
566 block.BlockUrls.SuccessUrl, block.BlockUrls.FailUrl, block.Block.Id,
567 static_cast<int>(block.Block.Format), block.Block.Hash });
568 }
569
571}
void AddPendingSnapshot(const PendingSnapshotData &snapshotData)
void AddPendingProjectBlocks(const std::vector< PendingProjectBlockData > &blockData)
void AddPendingProjectBlob(const PendingProjectBlobData &blobData)

References audacity::cloud::audiocom::sync::CloudProjectsDatabase::AddPendingProjectBlob(), audacity::cloud::audiocom::sync::CloudProjectsDatabase::AddPendingProjectBlocks(), audacity::cloud::audiocom::sync::CloudProjectsDatabase::AddPendingSnapshot(), audacity::cloud::audiocom::sync::UploadUrls::FailUrl, audacity::cloud::audiocom::sync::ProjectSyncState::FileUrls, audacity::cloud::audiocom::sync::CloudProjectsDatabase::Get(), audacity::cloud::audiocom::ServiceConfig::GetSnapshotSyncUrl(), audacity::cloud::audiocom::sync::SnapshotInfo::Id, audacity::cloud::audiocom::sync::ProjectInfo::Id, mProjectBlocksLock, mServiceConfig, audacity::cloud::audiocom::sync::CreateSnapshotResponse::Project, audacity::cloud::audiocom::sync::ProjectUploadData::ProjectSnapshot, audacity::cloud::audiocom::sync::CreateSnapshotResponse::Snapshot, audacity::cloud::audiocom::sync::UploadUrls::SuccessUrl, audacity::cloud::audiocom::sync::CreateSnapshotResponse::SyncState, and audacity::cloud::audiocom::sync::UploadUrls::UploadUrl.

Referenced by OnSnapshotCreated().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ UpdateProjectSnapshot()

void audacity::cloud::audiocom::sync::LocalProjectSnapshot::UpdateProjectSnapshot ( )
private

Definition at line 345 of file LocalProjectSnapshot.cpp.

346{
347 auto project = mWeakProject.lock();
348
349 if (project == nullptr)
350 {
352 XO("Project was closed before snapshot was created")));
353 return;
354 }
355
356 const bool isCloudProject = mProjectCloudExtension.IsCloudProject();
357 const bool createNew =
358 mUploadMode == UploadMode::CreateNew || !isCloudProject;
359
360 ProjectForm projectForm;
361
362 if (createNew)
363 projectForm.Name = mProjectName;
364 else
365 projectForm.HeadSnapshotId = mProjectCloudExtension.GetSnapshotId();
366
367 // For empty projects, mProjectBlocksLock will be nullptr at this point
368 if (mProjectBlocksLock != nullptr)
369 {
370 projectForm.Hashes.reserve(mProjectBlocksLock->Blocks.size());
371 std::transform(
372 mProjectBlocksLock->Blocks.begin(), mProjectBlocksLock->Blocks.end(),
373 std::back_inserter(projectForm.Hashes),
374 [](const auto& block) { return block.Hash; });
375 }
376
377 using namespace audacity::network_manager;
378
379 const auto url = createNew ? mServiceConfig.GetCreateProjectUrl() :
382
383 projectForm.Force = !createNew && mUploadMode == UploadMode::ForceOverwrite;
384
385 auto request = Request(url);
386
387 request.setHeader(
389 request.setHeader(
391 // request.setHeader(common_headers::ContentEncoding, "gzip");
392
393 const auto language = mServiceConfig.GetAcceptLanguageValue();
394
395 if (!language.empty())
396 request.setHeader(
398
399 request.setHeader(
401
402 auto serializedForm = Serialize(projectForm);
403
404 auto response = NetworkManager::GetInstance().doPost(
405 request, serializedForm.data(), serializedForm.size());
406
407 response->setRequestFinishedCallback(
408 [this, response, createNew, weakThis = weak_from_this()](auto)
409 {
410 auto strongThis = weakThis.lock();
411 if (!strongThis)
412 return;
413
414 const auto error = response->getError();
415
416 if (error != NetworkError::NoError)
417 {
419
420 mCreateSnapshotPromise.set_value({});
421 return;
422 }
423
424 const auto body = response->readAll<std::string>();
425 auto result = DeserializeCreateSnapshotResponse(body);
426
427 if (!result)
428 {
430 XO("Invalid Response: %s").Format(body).Translation()));
431
432 mCreateSnapshotPromise.set_value({});
433 return;
434 }
435
436 OnSnapshotCreated(*result, createNew);
437 });
438
439 mCancellationContext->OnCancelled(response);
440}
Abstract base class used in importing a file.
std::string GetAccessToken() const
Return the current access token, if any.
std::string GetCreateSnapshotUrl(std::string_view projectId) const
std::string GetAcceptLanguageValue() const
Returns the preferred language.
void OnSnapshotCreated(const CreateSnapshotResponse &response, bool newProject)
std::string Serialize(const ProjectForm &form)
std::optional< CreateSnapshotResponse > DeserializeCreateSnapshotResponse(const std::string &data)

References audacity::network_manager::common_headers::Accept, audacity::network_manager::common_headers::AcceptLanguage, audacity::network_manager::common_content_types::ApplicationJson, audacity::network_manager::common_headers::Authorization, audacity::network_manager::common_headers::ContentType, audacity::cloud::audiocom::sync::CreateNew, audacity::cloud::audiocom::sync::DeduceUploadError(), audacity::cloud::audiocom::sync::DeserializeCreateSnapshotResponse(), audacity::network_manager::NetworkManager::doPost(), audacity::cloud::audiocom::sync::ProjectForm::Force, audacity::cloud::audiocom::sync::ForceOverwrite, audacity::cloud::audiocom::ServiceConfig::GetAcceptLanguageValue(), audacity::cloud::audiocom::OAuthService::GetAccessToken(), audacity::cloud::audiocom::sync::ProjectCloudExtension::GetCloudProjectId(), audacity::cloud::audiocom::ServiceConfig::GetCreateProjectUrl(), audacity::cloud::audiocom::ServiceConfig::GetCreateSnapshotUrl(), audacity::network_manager::NetworkManager::GetInstance(), audacity::cloud::audiocom::sync::ProjectCloudExtension::GetSnapshotId(), audacity::cloud::audiocom::sync::ProjectForm::Hashes, audacity::cloud::audiocom::sync::ProjectForm::HeadSnapshotId, audacity::cloud::audiocom::sync::ProjectCloudExtension::IsCloudProject(), audacity::cloud::audiocom::sync::MakeClientFailure(), mCancellationContext, mCreateSnapshotPromise, mOAuthService, mProjectBlocksLock, mProjectCloudExtension, mProjectName, mServiceConfig, mUploadMode, mWeakProject, audacity::cloud::audiocom::sync::ProjectForm::Name, OnSnapshotCreated(), project, audacity::cloud::audiocom::sync::Serialize(), UploadFailed(), and XO().

Referenced by Start().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ UploadFailed()

void audacity::cloud::audiocom::sync::LocalProjectSnapshot::UploadFailed ( CloudSyncError  error)
private

Definition at line 301 of file LocalProjectSnapshot.cpp.

302{
303 if (!mCompleted.exchange(true, std::memory_order_release))
305 this, std::make_optional(error), mAudiocomTrace);
306}

References mAudiocomTrace, mCompleted, mProjectCloudExtension, and audacity::cloud::audiocom::sync::ProjectCloudExtension::OnSyncCompleted().

Referenced by Abort(), Cancel(), DataUploadFailed(), MarkSnapshotSynced(), OnSnapshotCreated(), and UpdateProjectSnapshot().

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ mAudiocomTrace

const AudiocomTrace audacity::cloud::audiocom::sync::LocalProjectSnapshot::mAudiocomTrace
private

Definition at line 109 of file LocalProjectSnapshot.h.

Referenced by MarkSnapshotSynced(), and UploadFailed().

◆ mCancellationContext

concurrency::CancellationContextPtr audacity::cloud::audiocom::sync::LocalProjectSnapshot::mCancellationContext
private

◆ mCancelled

std::atomic<bool> audacity::cloud::audiocom::sync::LocalProjectSnapshot::mCancelled { false }
private

Definition at line 128 of file LocalProjectSnapshot.h.

Referenced by Abort(), Cancel(), and OnSnapshotCreated().

◆ mCompleted

std::atomic<bool> audacity::cloud::audiocom::sync::LocalProjectSnapshot::mCompleted { false }
private

Definition at line 127 of file LocalProjectSnapshot.h.

Referenced by IsCompleted(), MarkSnapshotSynced(), and UploadFailed().

◆ mCreateSnapshotPromise

Promise audacity::cloud::audiocom::sync::LocalProjectSnapshot::mCreateSnapshotPromise
private

Definition at line 123 of file LocalProjectSnapshot.h.

Referenced by OnSnapshotCreated(), and UpdateProjectSnapshot().

◆ mCreateSnapshotResponse

std::optional<CreateSnapshotResponse> audacity::cloud::audiocom::sync::LocalProjectSnapshot::mCreateSnapshotResponse
private

Definition at line 119 of file LocalProjectSnapshot.h.

Referenced by DeleteSnapshot(), MarkSnapshotSynced(), and OnSnapshotCreated().

◆ mCreateSnapshotResponseMutex

std::mutex audacity::cloud::audiocom::sync::LocalProjectSnapshot::mCreateSnapshotResponseMutex
private

Definition at line 118 of file LocalProjectSnapshot.h.

Referenced by OnSnapshotCreated().

◆ mMissingBlockUploader

std::shared_ptr<MissingBlocksUploader> audacity::cloud::audiocom::sync::LocalProjectSnapshot::mMissingBlockUploader
private

Definition at line 116 of file LocalProjectSnapshot.h.

Referenced by OnSnapshotCreated().

◆ mOAuthService

const OAuthService& audacity::cloud::audiocom::sync::LocalProjectSnapshot::mOAuthService
private

Definition at line 108 of file LocalProjectSnapshot.h.

Referenced by UpdateProjectSnapshot().

◆ mProjectBlocksLock

std::unique_ptr<ProjectBlocksLock> audacity::cloud::audiocom::sync::LocalProjectSnapshot::mProjectBlocksLock
private

◆ mProjectCloudExtension

ProjectCloudExtension& audacity::cloud::audiocom::sync::LocalProjectSnapshot::mProjectCloudExtension
private

◆ mProjectDataPromise

std::promise<ProjectUploadData> audacity::cloud::audiocom::sync::LocalProjectSnapshot::mProjectDataPromise
private

Definition at line 105 of file LocalProjectSnapshot.h.

Referenced by Abort(), Cancel(), OnSnapshotCreated(), and SetUploadData().

◆ mProjectDataReady

std::atomic<bool> audacity::cloud::audiocom::sync::LocalProjectSnapshot::mProjectDataReady { false }
private

Definition at line 129 of file LocalProjectSnapshot.h.

Referenced by Abort(), Cancel(), and SetUploadData().

◆ mProjectName

std::string audacity::cloud::audiocom::sync::LocalProjectSnapshot::mProjectName
private

Definition at line 111 of file LocalProjectSnapshot.h.

Referenced by UpdateProjectSnapshot().

◆ mServiceConfig

const ServiceConfig& audacity::cloud::audiocom::sync::LocalProjectSnapshot::mServiceConfig
private

◆ mUploadMode

UploadMode audacity::cloud::audiocom::sync::LocalProjectSnapshot::mUploadMode { UploadMode::Normal }
private

Definition at line 121 of file LocalProjectSnapshot.h.

Referenced by UpdateProjectSnapshot().

◆ mWeakProject

std::weak_ptr<AudacityProject> audacity::cloud::audiocom::sync::LocalProjectSnapshot::mWeakProject
private

Definition at line 103 of file LocalProjectSnapshot.h.

Referenced by GetProject(), OnSnapshotCreated(), and UpdateProjectSnapshot().


The documentation for this class was generated from the following files: