• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #ifndef OHOS_WEB_DNS_DATA_BASE_ADAPTER_IMPL_H
17 #define OHOS_WEB_DNS_DATA_BASE_ADAPTER_IMPL_H
18 
19 #include "ohos_web_data_base_adapter.h"
20 
21 #include <string>
22 
23 #include "rdb_errno.h"
24 #include "rdb_helper.h"
25 #include "rdb_open_callback.h"
26 #include "rdb_store.h"
27 #include "rdb_store_config.h"
28 #include "rdb_types.h"
29 
30 namespace OHOS::NWeb {
31     class DnsDataBaseRdbOpenCallBack : public OHOS::NativeRdb::RdbOpenCallback {
32     public:
33         int32_t OnCreate(OHOS::NativeRdb::RdbStore& rdbStore) override;
34 
35         int32_t OnUpgrade(OHOS::NativeRdb::RdbStore& rdbStore, int32_t currentVersion, int32_t targetVersion) override;
36     };
37 
38     class OhosWebDnsDataBaseAdapterImpl : public OhosWebDnsDataBaseAdapter {
39     public:
40         static OhosWebDnsDataBaseAdapterImpl& GetInstance();
41 
42         ~OhosWebDnsDataBaseAdapterImpl() override = default;
43 
44         bool ExistHostname(const std::string& hostname) const override;
45 
46         void InsertHostname(const std::string& hostname) override;
47 
48         void GetHostnames(std::vector<std::string>& hostnames) const override;
49 
50         void ClearAllHostname() override;
51 
52     private:
53         OhosWebDnsDataBaseAdapterImpl();
54 
55         OhosWebDnsDataBaseAdapterImpl(const OhosWebDnsDataBaseAdapterImpl& other) = delete;
56 
57         OhosWebDnsDataBaseAdapterImpl& operator=(const OhosWebDnsDataBaseAdapterImpl&) = delete;
58 
59         std::shared_ptr<OHOS::NativeRdb::RdbStore> CreateDataBase(const std::string& dataBeseName,
60                                                                   OHOS::NativeRdb::RdbOpenCallback& callBack);
61 
62         std::shared_ptr<OHOS::NativeRdb::RdbStore> rdbStore_;
63     };
64 } // namespace
65 #endif // OHOS_WEB_DNS_DATA_BASE_ADAPTER_IMPL_H