1 /* 2 * Copyright (c) 2025 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef OHOS_FILEMGMT_DOWNGRADE_DOWNLOAD_NAPI_H 17 #define OHOS_FILEMGMT_DOWNGRADE_DOWNLOAD_NAPI_H 18 19 #include <list> 20 #include <mutex> 21 #include <unordered_set> 22 23 #include "cloud_sync_common.h" 24 #include "downgrade_dl_callback.h" 25 #include "downgrade_progress_napi.h" 26 #include "filemgmt_libn.h" 27 28 namespace OHOS::FileManagement::CloudSync { 29 class DowngradeDownloadNapi final : public LibN::NExporter { 30 public: DowngradeDownloadNapi(napi_env env,napi_value exports)31 DowngradeDownloadNapi(napi_env env, napi_value exports) : NExporter(env, exports) {} 32 ~DowngradeDownloadNapi() = default; 33 34 bool Export() override; 35 bool ToExport(std::vector<napi_property_descriptor> props); 36 std::string GetClassName() override; 37 static napi_value Constructor(napi_env env, napi_callback_info info); 38 static napi_value GetCloudFileInfo(napi_env env, napi_callback_info info); 39 static napi_value StartDownload(napi_env env, napi_callback_info info); 40 static napi_value StopDownload(napi_env env, napi_callback_info info); 41 42 private: 43 inline static std::string className_ = "DowngradeDownload"; 44 }; 45 46 class DowngradeDlCallbackImpl : public DowngradeDlCallback, 47 public std::enable_shared_from_this<DowngradeDlCallbackImpl> { 48 public: 49 DowngradeDlCallbackImpl(napi_env env, napi_value func); 50 ~DowngradeDlCallbackImpl(); 51 void OnDownloadProcess(const DowngradeProgress &progress) override; 52 napi_value ConvertToValue(); 53 54 public: 55 napi_ref cbOnRef_; 56 napi_env env_; 57 58 private: 59 void UpdateDownloadProgress(const DowngradeProgress &progress); 60 61 private: 62 std::shared_ptr<SingleBundleProgress> dlProgress_; 63 }; 64 65 struct DowngradeEntity { DowngradeEntityDowngradeEntity66 explicit DowngradeEntity(std::string bundle) : bundleName(bundle) {} 67 std::string bundleName; 68 std::shared_ptr<DowngradeDlCallbackImpl> callbackImpl{nullptr}; 69 }; 70 } // namespace OHOS::FileManagement::CloudSync 71 #endif // OHOS_FILEMGMT_DOWNGRADE_DOWNLOAD_NAPI_H