• 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     void StartDonwload(const std::string path, const int32_t userId);
37     void StopDonwload(const std::string path, const int32_t userId);
38     void RegisterCallback(const int32_t userId, const sptr<ICloudDownloadCallback> downloadCallback);
39     void UnregisterCallback(const int32_t userId);
40     void OnDownloadedResult(const std::string path,
41                             std::vector<DriveKit::DKDownloadAsset> assetsToDownload,
42                             std::shared_ptr<DataHandler> handler,
43                             std::shared_ptr<DriveKit::DKContext> context,
44                             std::shared_ptr<const DriveKit::DKDatabase> database,
45                             const std::map<DriveKit::DKDownloadAsset, DriveKit::DKDownloadResult> &results,
46                             const DriveKit::DKError &err);
47     void OnDownloadProcess(const std::string path,
48                            std::shared_ptr<DriveKit::DKContext> context,
49                            DriveKit::DKDownloadAsset asset,
50                            DriveKit::TotalSize totalSize,
51                            DriveKit::DownloadSize downloadSize);
52 
53 private:
54     std::mutex downloadsMtx_;
55     std::unordered_map<std::string, DownloadProgressObj> downloads_;
56     sptr<ICloudDownloadCallback> callback_;
57 };
58 } // namespace OHOS::FileManagement::CloudSync
59 
60 #endif // OHOS_FILEMGMT_CLOUD_DOWNLOAD_CALLBACK_MANAGER_H