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 "i_cloud_download_callback.h" 25 #include "data_sync/data_syncer.h" 26 27 namespace OHOS::FileManagement::CloudSync { 28 constexpr int32_t INVALID_USER_ID = -1; 29 class DataSyncManager { 30 public: 31 DataSyncManager() = default; 32 ~DataSyncManager() = default; 33 34 int32_t TriggerStartSync(const std::string &bundleName, 35 const int32_t userId, 36 bool forceFlag, 37 SyncTriggerType triggerType); 38 int32_t TriggerStopSync(const std::string &bundleName, const int32_t userId, SyncTriggerType triggerType); 39 int32_t TriggerRecoverySync(SyncTriggerType triggerType); 40 void RegisterCloudSyncCallback(const std::string &bundleName, const int32_t userId); 41 std::shared_ptr<DataSyncer> GetDataSyncer(const std::string &bundleName, const int32_t userId); 42 int32_t IsSkipSync(const std::string &bundleName, const int32_t userId) const; 43 int32_t StartDownloadFile(const std::string &bundleName, const int32_t userId, const std::string path); 44 int32_t StopDownloadFile(const std::string &bundleName, const int32_t userId, const std::string path); 45 int32_t RegisterDownloadFileCallback(const std::string &bundleName, 46 const int32_t userId, 47 const sptr<ICloudDownloadCallback> &downloadCallback); 48 int32_t UnregisterDownloadFileCallback(const std::string &bundleName, 49 const int32_t userId); 50 int32_t CleanCloudFile(const int32_t userId, const std::string &bundleName, const int action); 51 52 private: 53 std::vector<std::shared_ptr<DataSyncer>> dataSyncers_; 54 std::mutex dataSyncMutex_; 55 int32_t currentUserId_{INVALID_USER_ID}; 56 }; 57 } // namespace OHOS::FileManagement::CloudSync 58 59 #endif // OHOS_FILEMGMT_DATA_SYNC_MANAGER_H 60