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 DOWNGRADE_DOWNLOAD_TASK = 1 << 9, 37 }; 38 class TaskStateManager : public NoCopyable { 39 public: 40 static TaskStateManager &GetInstance(); 41 ~TaskStateManager() = default; 42 void StartTask(std::string bundleName, TaskType task); 43 void CompleteTask(std::string bundleName, TaskType task); 44 bool HasTask(std::string bundleName, TaskType task); 45 void StartTask(); 46 private: 47 TaskStateManager(); 48 void DelayUnloadTask(bool needSetCritical); 49 void CancelUnloadTask(); 50 51 bool criticalStatus_ = true; 52 std::mutex taskMapsMutex_; 53 std::unordered_map<std::string, uint64_t> taskMaps_; 54 ffrt::queue queue_; 55 ffrt::task_handle unloadTaskHandle_; 56 ffrt::mutex unloadTaskMutex_; 57 }; 58 } 59 #endif // OHOS_FILEMGMT_TASK_STATE_MANAGER_H