Bug 1755316 - Add audio tests with simultaneous processes r=alwu
[gecko.git] / dom / indexedDB / ActorsParentCommon.h
blob8102292d65b8c816e72a4d8289c7760989214810
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 "mozilla/dom/quota/IPCStreamCipherStrategy.h"
23 #include "nscore.h"
24 #include "nsISupports.h"
25 #include "nsStringFwd.h"
26 #include "nsTArray.h"
28 struct JSContext;
29 class JSObject;
30 class mozIStorageConnection;
31 class mozIStorageStatement;
32 class mozIStorageValueArray;
34 namespace mozilla {
35 namespace dom {
36 namespace indexedDB {
38 class DatabaseFileManager;
39 struct StructuredCloneFileParent;
40 struct StructuredCloneReadInfoParent;
42 extern const nsLiteralString kJournalDirectoryName;
44 using IndexedDBCipherStrategy = quota::IPCStreamCipherStrategy;
45 using CipherKey = IndexedDBCipherStrategy::KeyType;
47 // At the moment, the encrypted stream block size is assumed to be unchangeable
48 // between encrypting and decrypting blobs. This assumptions holds as long as we
49 // only encrypt in private browsing mode, but when we support encryption for
50 // persistent storage, this needs to be changed.
51 constexpr uint32_t kEncryptedStreamBlockSize = 4096;
53 using IndexOrObjectStoreId = int64_t;
55 struct IndexDataValue final {
56 IndexOrObjectStoreId mIndexId;
57 Key mPosition;
58 Key mLocaleAwarePosition;
59 bool mUnique;
61 IndexDataValue();
63 #ifdef NS_BUILD_REFCNT_LOGGING
64 IndexDataValue(IndexDataValue&& aOther);
66 MOZ_COUNTED_DTOR(IndexDataValue)
67 #endif
69 IndexDataValue(IndexOrObjectStoreId aIndexId, bool aUnique,
70 const Key& aPosition);
72 IndexDataValue(IndexOrObjectStoreId aIndexId, bool aUnique,
73 const Key& aPosition, const Key& aLocaleAwarePosition);
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, const Maybe<CipherKey>& aMaybeKey);
111 Result<StructuredCloneReadInfoParent, nsresult>
112 GetStructuredCloneReadInfoFromStatement(mozIStorageStatement* aStatement,
113 uint32_t aDataIndex,
114 uint32_t aFileIdsIndex,
115 const DatabaseFileManager& aFileManager,
116 const Maybe<CipherKey>& aMaybeKey);
118 Result<nsTArray<StructuredCloneFileParent>, nsresult>
119 DeserializeStructuredCloneFiles(const DatabaseFileManager& aFileManager,
120 const nsAString& aText);
122 nsresult ExecuteSimpleSQLSequence(mozIStorageConnection& aConnection,
123 Span<const nsLiteralCString> aSQLCommands);
125 } // namespace indexedDB
126 } // namespace dom
127 } // namespace mozilla
129 #endif // mozilla_dom_indexeddb_actorsparent_h__