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 "event_handler.h" 21 22 namespace OHOS::FileManagement::CloudSync { 23 enum class TaskType : uint64_t { 24 SYNC_TASK = 1, 25 DOWNLOAD_TASK = 1 << 1, 26 CLEAN_TASK = 1 << 2, 27 UPLOAD_ASSET_TASK = 1 << 3, 28 DOWNLOAD_ASSET_TASK = 1 << 4, 29 DOWNLOAD_REMOTE_ASSET_TASK = 1 << 5, 30 DOWNLOAD_THUMB_TASK = 1 << 6, 31 DISABLE_CLOUD_TASK = 1 << 7, 32 }; 33 class TaskStateManager : public NoCopyable { 34 public: 35 static TaskStateManager &GetInstance(); 36 ~TaskStateManager() = default; 37 void StartTask(std::string bundleName, TaskType task); 38 void CompleteTask(std::string bundleName, TaskType task); 39 bool HasTask(std::string bundleName, TaskType task); 40 void StartTask(); 41 private: 42 TaskStateManager(); 43 std::mutex taskMapsMutex_; 44 std::unordered_map<std::string, uint64_t> taskMaps_; 45 std::shared_ptr<AppExecFwk::EventHandler> unloadHandler_; 46 void DelayUnloadTask(); 47 }; 48 } 49 #endif // OHOS_FILEMGMT_TASK_STATE_MANAGER_H