Bug 1885602 - Part 5: Implement navigating to the SUMO help topic from the menu heade...
[gecko.git] / dom / indexedDB / ActorsParentCommon.h
blobe515e3ddda097289c1e57ef41311b40eb14386f0
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
5 * You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef mozilla_dom_indexeddb_actorsparentcommon_h__
8 #define mozilla_dom_indexeddb_actorsparentcommon_h__
10 // Declares functions and types used locally within IndexedDB, which are defined
11 // in ActorsParent.cpp
13 #include <stdint.h>
14 #include <tuple>
15 #include <utility>
16 #include "ErrorList.h"
17 #include "mozilla/Result.h"
18 #include "mozilla/Span.h"
19 #include "mozilla/UniquePtr.h"
20 #include "mozilla/UniquePtrExtensions.h"
21 #include "mozilla/dom/indexedDB/Key.h"
22 #include "nscore.h"
23 #include "nsISupports.h"
24 #include "nsStringFwd.h"
25 #include "nsTArray.h"
27 struct JSContext;
28 class JSObject;
29 class mozIStorageConnection;
30 class mozIStorageStatement;
31 class mozIStorageValueArray;
33 namespace mozilla::dom::indexedDB {
35 class DatabaseFileManager;
36 struct StructuredCloneFileParent;
37 struct StructuredCloneReadInfoParent;
39 extern const nsLiteralString kJournalDirectoryName;
41 // At the moment, the encrypted stream block size is assumed to be unchangeable
42 // between encrypting and decrypting blobs. This assumptions holds as long as we
43 // only encrypt in private browsing mode, but when we support encryption for
44 // persistent storage, this needs to be changed.
45 constexpr uint32_t kEncryptedStreamBlockSize = 4096;
47 using IndexOrObjectStoreId = int64_t;
49 struct IndexDataValue final {
50 IndexOrObjectStoreId mIndexId;
51 Key mPosition;
52 Key mLocaleAwarePosition;
53 bool mUnique;
55 IndexDataValue();
57 #if defined(DEBUG) || defined(NS_BUILD_REFCNT_LOGGING)
58 IndexDataValue(IndexDataValue&& aOther) noexcept;
59 #else
60 IndexDataValue(IndexDataValue&& aOther) = default;
61 #endif
63 IndexDataValue(IndexOrObjectStoreId aIndexId, bool aUnique,
64 const Key& aPosition);
66 IndexDataValue(IndexOrObjectStoreId aIndexId, bool aUnique,
67 const Key& aPosition, const Key& aLocaleAwarePosition);
69 #ifdef NS_BUILD_REFCNT_LOGGING
70 MOZ_COUNTED_DTOR(IndexDataValue)
71 #endif
73 IndexDataValue& operator=(IndexDataValue&& aOther) = default;
75 bool operator==(const IndexDataValue& aOther) const;
77 bool operator<(const IndexDataValue& aOther) const;
80 JSObject* GetSandbox(JSContext* aCx);
82 // The success value of the Result is a a pair of a pointer to the compressed
83 // index data values buffer and its size. The function does not return a
84 // nsTArray because the result is typically passed to a function that acquires
85 // ownership of the pointer.
86 Result<std::pair<UniqueFreePtr<uint8_t>, uint32_t>, nsresult>
87 MakeCompressedIndexDataValues(const nsTArray<IndexDataValue>& aIndexValues);
89 // aOutIndexValues is an output parameter, since its storage is reused.
90 nsresult ReadCompressedIndexDataValues(
91 mozIStorageStatement& aStatement, uint32_t aColumnIndex,
92 nsTArray<IndexDataValue>& aOutIndexValues);
94 using IndexDataValuesAutoArray = AutoTArray<IndexDataValue, 32>;
96 template <typename T>
97 Result<IndexDataValuesAutoArray, nsresult> ReadCompressedIndexDataValues(
98 T& aValues, uint32_t aColumnIndex);
100 Result<std::tuple<IndexOrObjectStoreId, bool, Span<const uint8_t>>, nsresult>
101 ReadCompressedIndexId(Span<const uint8_t> aData);
103 Result<std::pair<uint64_t, mozilla::Span<const uint8_t>>, nsresult>
104 ReadCompressedNumber(Span<const uint8_t> aSpan);
106 Result<StructuredCloneReadInfoParent, nsresult>
107 GetStructuredCloneReadInfoFromValueArray(
108 mozIStorageValueArray* aValues, uint32_t aDataIndex, uint32_t aFileIdsIndex,
109 const DatabaseFileManager& aFileManager);
111 Result<StructuredCloneReadInfoParent, nsresult>
112 GetStructuredCloneReadInfoFromStatement(
113 mozIStorageStatement* aStatement, uint32_t aDataIndex,
114 uint32_t aFileIdsIndex, const DatabaseFileManager& aFileManager);
116 Result<nsTArray<StructuredCloneFileParent>, nsresult>
117 DeserializeStructuredCloneFiles(const DatabaseFileManager& aFileManager,
118 const nsAString& aText);
120 nsresult ExecuteSimpleSQLSequence(mozIStorageConnection& aConnection,
121 Span<const nsLiteralCString> aSQLCommands);
123 } // namespace mozilla::dom::indexedDB
125 #endif // mozilla_dom_indexeddb_actorsparent_h__