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 #ifndef APP_DOMAIN_VERIFY_TASK_H 16 #define APP_DOMAIN_VERIFY_TASK_H 17 18 #include <memory> 19 #include <queue> 20 #include <shared_mutex> 21 #include <unordered_map> 22 #include "singleton.h" 23 #include "inner_verify_status.h" 24 #include "app_verify_base_info.h" 25 #include "i_http_task.h" 26 #include "ffrt.h" 27 #include "ffrt_safe_map.h" 28 29 namespace OHOS { 30 namespace AppDomainVerify { 31 using namespace OHOS::NetStack::HttpClient; 32 class AppDomainVerifyTaskMgr { 33 public: 34 AppDomainVerifyTaskMgr(); 35 ~AppDomainVerifyTaskMgr(); 36 static std::shared_ptr<AppDomainVerifyTaskMgr> GetInstance(); 37 static void DestroyInstance(); 38 DISALLOW_COPY_AND_MOVE(AppDomainVerifyTaskMgr); 39 bool AddTask(const std::shared_ptr<IHttpTask>& task); 40 bool IsIdle(); 41 42 private: 43 static std::shared_ptr<AppDomainVerifyTaskMgr> instance_; 44 bool Init(); 45 std::function<void()> GetTaskWrapper(const std::shared_ptr<IHttpTask>& httpTask); 46 int poolSize_ = 4; 47 static ffrt::mutex instanceMutex_; 48 ffrt::mutex mutex_; 49 ffrt::condition_variable cond_; 50 bool stop_ = false; 51 std::queue<std::function<void()>> tasks_; 52 SafeMap<uint32_t, std::shared_ptr<IHttpTask>> taskMap_; 53 }; 54 } 55 } 56 57 #endif