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_WHITELISTCONFIGMANAGER_H
16 #define APP_DOMAIN_VERIFY_WHITELISTCONFIGMANAGER_H
17 #include <string>
18 #include <unordered_set>
19 #include <vector>
20 #include <atomic>
21 #include "singleton.h"
22 #include "preferences.h"
23 #include "preferences_helper.h"
24 namespace OHOS::AppDomainVerify {
25 class WhiteListConfigMgr {
26 public:
27     explicit WhiteListConfigMgr();
28     virtual ~WhiteListConfigMgr();
29     bool IsInWhiteList(const std::string& url);
30     void UpdateWhiteList(const std::unordered_set<std::string>& whiteList);
31 protected:
32     void Load();
33     void LoadDefault();
34     void LoadDynamic();
35     bool Save();
36     void Split(std::string urlList);
37     std::shared_ptr<NativePreferences::Preferences> GetPreference(const std::string& path);
38     std::string defaultWhiteUrl_;
39     std::unordered_set<std::string> whiteListSet_;
40     std::shared_ptr<NativePreferences::Preferences> preferences_;
41     std::mutex initLock;
42     std::atomic<bool> init{ false };
43     std::mutex whiteListLock_;
44 };
45 
46 }
47 
48 #endif  // APP_DOMAIN_VERIFY_WHITELISTCONFIGMANAGER_H
49