已合并
Fix DowngradeDownload #4268
Fix DowngradeDownload #4268
已合并
wangdengyang创建于 7月29日
共 4 个文件变更+39-5
@@ -645,6 +645,25 @@ std::string DownloadProgressObj::to_string()
645 return ss.str();645 return ss.str();
646}646}
647 647 
648+std::string DownloadProgressObj::to_string(const std::string &anonyPath)
649+{
650+ std::stringstream ss;
651+ ss << "[" << anonyPath;
652+ ss << " , " << state;
653+ ss << " , " << downloadedSize;
654+ ss << " , " << totalSize;
655+ ss << " , " << downloadErrorType;
656+ 
657+ ss << " , " << downloadId;
658+ ss << " , " << batchState;
659+ ss << " , " << batchDownloadSize;
660+ ss << " , " << batchTotalSize;
661+ ss << " , " << batchSuccNum;
662+ ss << " , " << batchFailNum;
663+ ss << " , " << batchTotalNum << "]";
664+ return ss.str();
665+}
666+ 
648std::string DowngradeProgress::to_string() const667std::string DowngradeProgress::to_string() const
649{668{
650 std::stringstream ss;669 std::stringstream ss;
@@ -68,6 +68,7 @@ struct DownloadProgressObj : public Parcelable {
68 bool Marshalling(Parcel &parcel) const override;68 bool Marshalling(Parcel &parcel) const override;
69 static DownloadProgressObj *Unmarshalling(Parcel &parcel);69 static DownloadProgressObj *Unmarshalling(Parcel &parcel);
70 std::string to_string();70 std::string to_string();
71+ std::string to_string(const std::string &anonyPath);
71};72};
72 73 
73struct UploadProgressObj : public Parcelable {74struct UploadProgressObj : public Parcelable {
@@ -146,11 +146,16 @@ void DowngradeDlCallbackImpl::UpdateTransferProgress(const DowngradeTfProgress &
146void DowngradeDlCallbackImpl::OnDownloadProcess(const DowngradeProgress &progress)146void DowngradeDlCallbackImpl::OnDownloadProcess(const DowngradeProgress &progress)
147{147{
148 LOGD("Start OnDownloadProcess");148 LOGD("Start OnDownloadProcess");
149- UpdateDownloadProgress(progress);149+ std::shared_ptr<SingleBundleProgress> progressCopy;
150+ {
151+ std::lock_guard<std::mutex> lock(dlCbMtx_);
152+ UpdateDownloadProgress(progress);
153+ progressCopy = std::make_shared<SingleBundleProgress>(*dlProgress_);
154+ }
150 std::shared_ptr<DowngradeDlCallbackImpl> callbackImpl = shared_from_this();155 std::shared_ptr<DowngradeDlCallbackImpl> callbackImpl = shared_from_this();
151 napi_status status = napi_send_event(156 napi_status status = napi_send_event(
152 callbackImpl->env_,157 callbackImpl->env_,
153- [callbackImpl]() mutable {158+ [callbackImpl, progressCopy]() mutable {
154 auto env = callbackImpl->env_;159 auto env = callbackImpl->env_;
155 auto ref = callbackImpl->cbOnRef_;160 auto ref = callbackImpl->cbOnRef_;
156 if (env == nullptr || ref == nullptr) {161 if (env == nullptr || ref == nullptr) {
@@ -170,13 +175,21 @@ void DowngradeDlCallbackImpl::OnDownloadProcess(const DowngradeProgress &progres
170 napi_close_handle_scope(env, scope);175 napi_close_handle_scope(env, scope);
171 return;176 return;
172 }177 }
173- napi_value jsProgress = callbackImpl->ConvertToValue();178+ napi_value progressVal = NClass::InstantiateClass(env, DowngradeProgressNapi::className_, {});
174- if (jsProgress == nullptr) {179+ if (progressVal == nullptr) {
180+ LOGE("Failed to instantiate class");
175 napi_close_handle_scope(env, scope);181 napi_close_handle_scope(env, scope);
176 return;182 return;
177 }183 }
184+ auto progressEntity = NClass::GetEntityOf<DowngradeProgressEntity>(env, progressVal);
185+ if (progressEntity == nullptr) {
186+ LOGE("Failed to get progressEntity");
187+ napi_close_handle_scope(env, scope);
188+ return;
189+ }
190+ progressEntity->progress = progressCopy;
178 napi_value jsResult = nullptr;191 napi_value jsResult = nullptr;
179- status = napi_call_function(env, nullptr, jsCallback, 1, &jsProgress, &jsResult);192+ status = napi_call_function(env, nullptr, jsCallback, 1, &progressVal, &jsResult);
180 if (status != napi_ok) {193 if (status != napi_ok) {
181 LOGE("napi call function failed, status: %{public}d", status);194 LOGE("napi call function failed, status: %{public}d", status);
182 }195 }
@@ -63,6 +63,7 @@ public:
63 static inline std::string taskName_ = "cloudSyncManager.DownloadProgress";63 static inline std::string taskName_ = "cloudSyncManager.DownloadProgress";
64 64 
65private:65private:
66+ std::mutex dlCbMtx_;
66 void UpdateDownloadProgress(const DowngradeProgress &progress);67 void UpdateDownloadProgress(const DowngradeProgress &progress);
67 void UpdateTransferProgress(const DowngradeTfProgress &progress);68 void UpdateTransferProgress(const DowngradeTfProgress &progress);
68 69