1 /* 2 * Copyright (c) 2022 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 #include "aging/aging_handler_chain.h" 17 #include "app_log_wrapper.h" 18 19 namespace OHOS { 20 namespace AppExecFwk { AgingHandlerChain()21AgingHandlerChain::AgingHandlerChain() 22 { 23 } 24 ~AgingHandlerChain()25AgingHandlerChain::~AgingHandlerChain() 26 { 27 handlers.clear(); 28 APP_LOGD("AgingHandlerChain is destroyed"); 29 } 30 AddHandler(const::std::shared_ptr<AgingHandler> & handler)31void AgingHandlerChain::AddHandler(const ::std::shared_ptr<AgingHandler> &handler) 32 { 33 if (handler == nullptr) { 34 APP_LOGE("agingHandler: invalid handler."); 35 return; 36 } 37 handlers.emplace_back(handler); 38 APP_LOGD("agingHandler: %{public}s is added into handlers", handler->GetName().c_str()); 39 } 40 Process(AgingRequest & request) const41bool AgingHandlerChain::Process(AgingRequest &request) const 42 { 43 for (auto handler : handlers) { 44 bool passed = handler->Process(request); 45 APP_LOGD("agingHandler: %{public}s process passed: %{public}d", handler->GetName().c_str(), passed); 46 if (!passed) { 47 break; 48 } 49 } 50 APP_LOGD("agingHandler: aging handler chain process done."); 51 return request.IsReachEndAgingThreshold(); 52 } 53 } // namespace AppExecFwk 54 } // namespace OHOS