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 NWEB_WEB_STORAGE_H 17 #define NWEB_WEB_STORAGE_H 18 19 #include <memory> 20 #include <string> 21 #include <vector> 22 23 #include "nweb_export.h" 24 #include "nweb_value_callback.h" 25 26 namespace OHOS::NWeb { 27 class NWebWebStorageOrigin; 28 using NWebGetOriginsCallback = NWebValueCallback<std::vector<NWebWebStorageOrigin>>; 29 class OHOS_NWEB_EXPORT NWebWebStorage { 30 public: 31 NWebWebStorage() = default; 32 33 virtual ~NWebWebStorage() = default; 34 35 virtual void DeleteAllData() = 0; 36 virtual int DeleteOrigin(const std::string& origin) = 0; 37 virtual void GetOrigins(std::shared_ptr<NWebGetOriginsCallback> callback) = 0; 38 virtual std::vector<NWebWebStorageOrigin> GetOrigins() = 0; 39 virtual void GetOriginQuota(const std::string& origin, 40 std::shared_ptr<NWebValueCallback<long>> callback) = 0; 41 virtual long GetOriginQuota(const std::string& origin) = 0; 42 virtual void GetOriginUsage(const std::string& origin, 43 std::shared_ptr<NWebValueCallback<long>> callback) = 0; 44 virtual long GetOriginUsage(const std::string& origin) = 0; 45 }; 46 47 class OHOS_NWEB_EXPORT NWebWebStorageOrigin { 48 public: 49 NWebWebStorageOrigin() = default; 50 ~NWebWebStorageOrigin() = default; SetOrigin(const std::string & origin)51 void SetOrigin(const std::string& origin) { origin_ = origin; } SetQuota(long quota)52 void SetQuota(long quota) { quota_ = quota; } SetUsage(long usage)53 void SetUsage(long usage) { usage_ = usage; } GetOrigin()54 std::string GetOrigin() { return origin_; } GetQuota()55 long GetQuota() { return quota_; } GetUsage()56 long GetUsage() { return usage_;} 57 58 private: 59 std::string origin_; 60 int64_t quota_; 61 int64_t usage_; 62 }; 63 } 64 65 #endif // NWebWebStorage 66