• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 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_CLOUD_DOWNLOAD_CALLBACK_MANAGER_H
17 #define OHOS_FILEMGMT_CLOUD_DOWNLOAD_CALLBACK_MANAGER_H
18 
19 #include <memory>
20 #include <mutex>
21 #include <unordered_map>
22 #include <unordered_set>
23 #include "dk_assets_downloader.h"
24 
25 #include "i_cloud_download_callback.h"
26 #include "data_handler.h"
27 #include "sdk_helper.h"
28 
29 namespace OHOS::FileManagement::CloudSync {
30 
31 class CloudDownloadCallbackManager {
32 public:
33     CloudDownloadCallbackManager();
34     ~CloudDownloadCallbackManager() = default;
35 
36     bool FindDownload(const std::string path);
37     void StartDonwload(const std::string path, const int32_t userId, const int64_t downloadId);
38     bool StopDonwload(const std::string path, const int32_t userId, DownloadProgressObj &download);
39     std::vector<int64_t> StopAllDownloads(const int32_t userId);
40     void NotifyProcessStop(DownloadProgressObj &download);
41     void RegisterCallback(const int32_t userId, const sptr<ICloudDownloadCallback> downloadCallback);
42     void UnregisterCallback(const int32_t userId);
43     void OnDownloadedResult(const std::string path,
44                             std::vector<DriveKit::DKDownloadAsset> assetsToDownload,
45                             std::shared_ptr<DataHandler> handler,
46                             std::shared_ptr<DriveKit::DKContext> context,
47                             std::shared_ptr<const DriveKit::DKDatabase> database,
48                             const std::map<DriveKit::DKDownloadAsset, DriveKit::DKDownloadResult> &results,
49                             const DriveKit::DKError &err);
50     void OnDownloadProcess(const std::string path,
51                            std::shared_ptr<DriveKit::DKContext> context,
52                            DriveKit::DKDownloadAsset asset,
53                            DriveKit::TotalSize totalSize,
54                            DriveKit::DownloadSize downloadSize);
55     void SetBundleName(const std::string &bundleName);
56 
57 private:
58     std::mutex downloadsMtx_;
59     std::mutex callbackMutex_;
60     std::unordered_map<std::string, DownloadProgressObj> downloads_;
61     sptr<ICloudDownloadCallback> callback_;
62     std::string bundleName_;
63     void CheckTaskState();
64 };
65 } // namespace OHOS::FileManagement::CloudSync
66 
67 #endif // OHOS_FILEMGMT_CLOUD_DOWNLOAD_CALLBACK_MANAGER_H
68