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_TASK_STATE_MANAGER_H 17 #define OHOS_FILEMGMT_TASK_STATE_MANAGER_H 18 19 #include <nocopyable.h> 20 #include "ffrt_inner.h" 21 22 namespace OHOS::FileManagement::CloudSync { 23 static const std::string CLOUD_FILE_SERVICE_SA_STATUS_FLAG = "persist.kernel.medialibrarydata.stopflag"; 24 static const std::string CLOUD_FILE_SERVICE_SA_START = "0"; 25 static const std::string CLOUD_FILE_SERVICE_SA_END = "1"; 26 enum class TaskType : uint64_t { 27 SYNC_TASK = 1, 28 DOWNLOAD_TASK = 1 << 1, 29 CLEAN_TASK = 1 << 2, 30 UPLOAD_ASSET_TASK = 1 << 3, 31 DOWNLOAD_ASSET_TASK = 1 << 4, 32 DOWNLOAD_REMOTE_ASSET_TASK = 1 << 5, 33 DOWNLOAD_THUMB_TASK = 1 << 6, 34 DISABLE_CLOUD_TASK = 1 << 7, 35 CACHE_VIDEO_TASK = 1 << 8, 36 }; 37 class TaskStateManager : public NoCopyable { 38 public: 39 static TaskStateManager &GetInstance(); 40 ~TaskStateManager() = default; 41 void StartTask(std::string bundleName, TaskType task); 42 void CompleteTask(std::string bundleName, TaskType task); 43 bool HasTask(std::string bundleName, TaskType task); 44 void StartTask(); 45 private: 46 TaskStateManager(); 47 void DelayUnloadTask(); 48 void CancelUnloadTask(); 49 50 std::mutex taskMapsMutex_; 51 std::unordered_map<std::string, uint64_t> taskMaps_; 52 ffrt::queue queue_; 53 ffrt::task_handle unloadTaskHandle_; 54 ffrt::mutex unloadTaskMutex_; 55 }; 56 } 57 #endif // OHOS_FILEMGMT_TASK_STATE_MANAGER_H