• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_DOWNLOAD_CALLBACK_MIDDLE_NAPI_H
17 #define OHOS_FILEMGMT_DOWNLOAD_CALLBACK_MIDDLE_NAPI_H
18 
19 #include <memory>
20 #include <mutex>
21 #include <string>
22 #include <unordered_map>
23 #include <vector>
24 
25 #include "cloud_download_callback.h"
26 #include "download_progress_napi.h"
27 #include "register_callback_manager_napi.h"
28 
29 namespace OHOS::FileManagement::CloudSync {
30 class CloudDlCallbackMiddleNapi : public CloudDownloadCallback,
31                                   public RegisterCallbackManagerNapi,
32                                   public std::enable_shared_from_this<CloudDlCallbackMiddleNapi> {
33 public:
CloudDlCallbackMiddleNapi(napi_env env)34     explicit CloudDlCallbackMiddleNapi(napi_env env) : RegisterCallbackManagerNapi(env) {}
35     virtual ~CloudDlCallbackMiddleNapi() = default;
36     void OnDownloadProcess(const DownloadProgressObj &progress) override;
37     void RemoveDownloadInfo(int64_t downloadId);
38 
39 protected:
DownloadProgressInner(std::shared_ptr<DlProgressNapi> progress)40     virtual void DownloadProgressInner(std::shared_ptr<DlProgressNapi> progress){};
41     std::vector<int64_t> GetDownloadIdsByUri(const std::string &uri);
42     std::shared_ptr<DlProgressNapi> GetDownloadInfo(const DownloadProgressObj &progress);
43 
44 protected:
45     std::mutex downloadInfoMtx_;
46     std::unordered_map<int64_t, std::shared_ptr<DlProgressNapi>> downloadInfos_;
47 };
48 
49 } // namespace OHOS::FileManagement::CloudSync
50 #endif // OHOS_FILEMGMT_DOWNLOAD_CALLBACK_MIDDLE_NAPI_H