• 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_DATA_SYNC_MANAGER_H
17 #define OHOS_FILEMGMT_DATA_SYNC_MANAGER_H
18 
19 #include <map>
20 #include <memory>
21 #include <mutex>
22 #include <vector>
23 
24 #include "safe_map.h"
25 #include "i_cloud_download_callback.h"
26 #include "data_sync/data_syncer.h"
27 
28 namespace OHOS::FileManagement::CloudSync {
29 constexpr int32_t INVALID_USER_ID = -1;
30 class DataSyncManager {
31 public:
32     DataSyncManager() = default;
33     ~DataSyncManager() = default;
34 
35     int32_t TriggerStartSync(const std::string &bundleName,
36                              const int32_t userId,
37                              bool forceFlag,
38                              SyncTriggerType triggerType);
39     int32_t TriggerStopSync(const std::string &bundleName, const int32_t userId, SyncTriggerType triggerType);
40     int32_t TriggerRecoverySync(SyncTriggerType triggerType);
41     void RegisterCloudSyncCallback(const std::string &bundleName, const int32_t userId);
42     std::shared_ptr<DataSyncer> GetDataSyncer(const std::string &bundleName, const int32_t userId);
43     int32_t IsSkipSync(const std::string &bundleName, const int32_t userId);
44     int32_t StartDownloadFile(const std::string &bundleName, const int32_t userId, const std::string path);
45     int32_t StopDownloadFile(const std::string &bundleName, const int32_t userId, const std::string path);
46     int32_t RegisterDownloadFileCallback(const std::string &bundleName,
47                                          const int32_t userId,
48                                          const sptr<ICloudDownloadCallback> &downloadCallback);
49     int32_t UnregisterDownloadFileCallback(const std::string &bundleName,
50                                            const int32_t userId);
51     int32_t CleanCloudFile(const int32_t userId, const std::string &bundleName, const int action);
52     int32_t OptimizeStorage(const std::string &bundleName, const int32_t userId, const int32_t agingDays);
53     int32_t DownloadThumb();
54     int32_t CleanCache(const std::string &bundleName, const int32_t userId, const std::string &uri);
55     int32_t InitSdk(const int32_t userId, const std::string &bundleName, std::shared_ptr<DataSyncer> dataSyncer);
56     int32_t DisableCloud(const int32_t userId);
57 
58     int32_t GetUserId(int32_t &userId);
59 private:
60     SafeMap<const std::string, std::shared_ptr<DataSyncer>> dataSyncersMap_;
61     std::mutex dataSyncMutex_;
62     std::mutex sdkHelperMutex_;
63     int32_t currentUserId_{INVALID_USER_ID};
64     struct DataSyncerInfo {
65         SyncState syncState;
66     };
67     int32_t GetAllDataSyncerInfo(const int32_t userId, std::map<std::string, DataSyncerInfo> &dataSyncerInfo);
68     int32_t IsUserVerified(const int32_t userId);
69     void Convert2BundleName(const std::string &bundle, std::string &bundleName);
70 };
71 } // namespace OHOS::FileManagement::CloudSync
72 
73 #endif // OHOS_FILEMGMT_DATA_SYNC_MANAGER_H
74