diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
commit | 36d22d82aa202bb199967e9512281e9a53db42c9 (patch) | |
tree | 105e8c98ddea1c1e4784a60a5a6410fa416be2de /dom/media/mediacapabilities/KeyValueStorage.h | |
parent | Initial commit. (diff) | |
download | firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip |
Adding upstream version 115.7.0esr.upstream/115.7.0esr
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'dom/media/mediacapabilities/KeyValueStorage.h')
-rw-r--r-- | dom/media/mediacapabilities/KeyValueStorage.h | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/dom/media/mediacapabilities/KeyValueStorage.h b/dom/media/mediacapabilities/KeyValueStorage.h new file mode 100644 index 0000000000..60d72a6c6d --- /dev/null +++ b/dom/media/mediacapabilities/KeyValueStorage.h @@ -0,0 +1,48 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim:set ts=2 sw=2 sts=2 et cindent: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef MOZILLA_KEY_VALUE_STORAGE_H +#define MOZILLA_KEY_VALUE_STORAGE_H + +#include "mozilla/MozPromise.h" +#include "nsIKeyValue.h" + +namespace mozilla { + +/* A wrapper class around kv store service, which allows storing a pair of key + * value permanently. The class must be used from the parent process, where + * there is no sandbox because it requires access to the directory that the + * database is located. */ +class KeyValueStorage final { + public: + NS_INLINE_DECL_THREADSAFE_REFCOUNTING(KeyValueStorage) + + /* Store permanently the value in the Key. */ + RefPtr<GenericPromise> Put(const nsACString& aName, const nsACString& aKey, + int32_t aValue); + /* Get the value stored in the aKey. If the aKey does not exist the promise is + * resolved with the value -1. */ + typedef MozPromise<int32_t, nsresult, true> GetPromise; + RefPtr<GetPromise> Get(const nsACString& aName, const nsACString& aKey); + + /* Clear all the key/value pairs from the aName database. */ + RefPtr<GenericPromise> Clear(const nsACString& aName); + + private: + /* Create, if doesn't exist, and initialize the database with a given name. */ + RefPtr<GenericPromise> Init(); + RefPtr<GenericPromise> Put(const nsACString& aKey, int32_t aValue); + RefPtr<GetPromise> Get(const nsACString& aKey); + RefPtr<GenericPromise> Clear(); + ~KeyValueStorage() = default; + + RefPtr<nsIKeyValueDatabase> mDatabase; + nsCString mDatabaseName; +}; + +} // namespace mozilla + +#endif // MOZILLA_KEY_VALUE_STORAGE_H |