Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#pragma once
#include "include/cef_app.h" // probably excessive
#include <map>
#include <string>
// simple memory-backed session storage
class FCHostSessionStorage
{
public:
virtual size_t size() const { return storage.size(); };
virtual CefRefPtr<CefV8Value> /* string array */ keys() const;
virtual bool has(const CefString& key) const { return (storage.find(key) != storage.cend()); };
virtual CefRefPtr<CefV8Value> get(const CefString& key) const
{
auto itr = storage.find(key);
if (itr == storage.cend())
return CefV8Value::CreateNull();
else
return itr->second;
};
virtual void set(const CefString& key, CefRefPtr<CefV8Value> val) { storage.insert_or_assign(key, val); };
virtual bool remove(const CefString& key) { return (storage.erase(key) > 0); };
virtual void clear() { storage.clear(); };
protected:
std::map<CefString, CefRefPtr<CefV8Value>> storage;
};
// memory-backed, disk-persistent local storage
class FCHostPersistentStorage : public FCHostSessionStorage
{
public:
FCHostPersistentStorage(const std::wstring& _path) : path(_path) { ensure_folder_exists(); load(); };
virtual void set(const CefString& key, CefRefPtr<CefV8Value> val) override;
virtual bool remove(const CefString& key) override;
virtual void clear() override;
private:
void load();
void ensure_folder_exists() const;
std::wstring get_filename(const CefString& key) const;
std::wstring path;
};