1 /* 2 * Copyright (c) 2025 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_FORM_FWK_REFRESH_CACHE_MGR_H 17 #define OHOS_FORM_FWK_REFRESH_CACHE_MGR_H 18 19 #include <singleton.h> 20 21 #include "data_center/form_record/form_record.h" 22 #include "common/timer_mgr/form_timer.h" 23 #include "form_constants.h" 24 25 namespace OHOS { 26 namespace AppExecFwk { 27 /** 28 * @class RefreshCacheMgr 29 * RefreshCacheMgr is used to cache form refresh task. 30 */ 31 class RefreshCacheMgr : public DelayedRefSingleton<RefreshCacheMgr> { 32 DECLARE_DELAYED_REF_SINGLETON(RefreshCacheMgr); 33 public: 34 DISALLOW_COPY_AND_MOVE(RefreshCacheMgr); 35 36 /** 37 * @brief Current system overload, refresh task add to cache queue. 38 * @param task Form timer task. 39 */ 40 void AddToOverloadTaskQueue(const FormTimer &task); 41 42 /** 43 * @brief System load level down, consume refresh task. 44 */ 45 void ConsumeOverloadTaskQueue(); 46 47 /** 48 * @brief Refresh task be healthy controlled, add cache flag. 49 * @param formId The formId. 50 * @param isAskForProviderData True: ask for provider data, False: update by provider data. 51 */ 52 void AddFlagByHealthyControl(const int64_t formId, bool isAskForProviderData); 53 54 /** 55 * @brief The application healthy control be released, consume cache flag. 56 * @param record The form record. 57 * @param userId Current active userId. 58 */ 59 void ConsumeHealthyControlFlag(std::vector<FormRecord>::iterator &record, const int32_t userId); 60 61 /** 62 * @brief Refresh task be form invisible controlled, add cache flag. 63 * @param formId The formId. 64 * @param refreshType The refresh source type. 65 */ 66 void AddFlagByInvisible(const int64_t formId, const int32_t refreshType); 67 68 /** 69 * @brief The form resume visible, consume cache flag. 70 * @param formId The formId. 71 * @param userId Current active userId. 72 */ 73 void ConsumeInvisibleFlag(const int64_t formId, const int32_t userId); 74 75 /** 76 * @brief Refresh task be screen off controlled, add cache flag. 77 * @param formId The formId. 78 * @param want The want of the form to refresh. 79 * @param record The form record. 80 */ 81 void AddFlagByScreenOff(const int64_t formId, const Want &want, FormRecord &record); 82 83 /** 84 * @brief Receive screen unlock, consume cache flag. 85 */ 86 void ConsumeScreenOffFlag(); 87 88 /** 89 * @brief Render task be form invisible controlled, add cache queue. 90 * @param formId The formId. 91 * @param task The render form task. 92 */ 93 void AddRenderTask(int64_t formId, std::function<void()> task); 94 95 /** 96 * @brief The form resume visible, consume cache task. 97 * @param formId The formId. 98 */ 99 void ConsumeRenderTask(int64_t formId); 100 101 /** 102 * @brief Delete the form render cache task. 103 * @param formId The formId. 104 */ 105 void DelRenderTask(int64_t formId); 106 107 private: 108 std::mutex overloadTaskMutex_; 109 std::vector<FormTimer> overloadTask_; 110 std::mutex renderTaskMapMutex_; 111 std::unordered_map<int64_t, std::function<void()>> renderTaskMap_; 112 }; 113 } // namespace AppExecFwk 114 } // namespace OHOS 115 116 #endif // OHOS_FORM_FWK_REFRESH_CACHE_MGR_H