ActorsParentCommon.h (4322B)
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/. */ 6 7 #ifndef mozilla_dom_indexeddb_actorsparentcommon_h__ 8 #define mozilla_dom_indexeddb_actorsparentcommon_h__ 9 10 // Declares functions and types used locally within IndexedDB, which are defined 11 // in ActorsParent.cpp 12 13 #include <stdint.h> 14 15 #include <tuple> 16 #include <utility> 17 18 #include "ErrorList.h" 19 #include "mozilla/Result.h" 20 #include "mozilla/Span.h" 21 #include "mozilla/UniquePtrExtensions.h" 22 #include "mozilla/dom/indexedDB/Key.h" 23 #include "nsISupports.h" 24 #include "nsStringFwd.h" 25 #include "nsTArray.h" 26 #include "nscore.h" 27 28 struct JSContext; 29 class JSObject; 30 class mozIStorageConnection; 31 class mozIStorageStatement; 32 class mozIStorageValueArray; 33 34 namespace mozilla::dom::indexedDB { 35 36 class DatabaseFileManager; 37 struct StructuredCloneFileParent; 38 struct StructuredCloneReadInfoParent; 39 40 extern const nsLiteralString kJournalDirectoryName; 41 42 // At the moment, the encrypted stream block size is assumed to be unchangeable 43 // between encrypting and decrypting blobs. This assumptions holds as long as we 44 // only encrypt in private browsing mode, but when we support encryption for 45 // persistent storage, this needs to be changed. 46 constexpr uint32_t kEncryptedStreamBlockSize = 4096; 47 48 using IndexOrObjectStoreId = int64_t; 49 50 struct IndexDataValue final { 51 IndexOrObjectStoreId mIndexId; 52 Key mPosition; 53 Key mLocaleAwarePosition; 54 bool mUnique; 55 56 IndexDataValue(); 57 58 #if defined(DEBUG) || defined(NS_BUILD_REFCNT_LOGGING) 59 IndexDataValue(IndexDataValue&& aOther) noexcept; 60 #else 61 IndexDataValue(IndexDataValue&& aOther) = default; 62 #endif 63 64 IndexDataValue(IndexOrObjectStoreId aIndexId, bool aUnique, 65 const Key& aPosition); 66 67 IndexDataValue(IndexOrObjectStoreId aIndexId, bool aUnique, 68 const Key& aPosition, const Key& aLocaleAwarePosition); 69 70 #ifdef NS_BUILD_REFCNT_LOGGING 71 MOZ_COUNTED_DTOR(IndexDataValue) 72 #endif 73 74 IndexDataValue& operator=(IndexDataValue&& aOther) = default; 75 76 bool operator==(const IndexDataValue& aOther) const; 77 78 bool operator<(const IndexDataValue& aOther) const; 79 }; 80 81 JSObject* GetSandbox(JSContext* aCx); 82 83 // The success value of the Result is a a pair of a pointer to the compressed 84 // index data values buffer and its size. The function does not return a 85 // nsTArray because the result is typically passed to a function that acquires 86 // ownership of the pointer. 87 Result<std::pair<UniqueFreePtr<uint8_t>, uint32_t>, nsresult> 88 MakeCompressedIndexDataValues(const nsTArray<IndexDataValue>& aIndexValues); 89 90 // aOutIndexValues is an output parameter, since its storage is reused. 91 nsresult ReadCompressedIndexDataValues( 92 mozIStorageStatement& aStatement, uint32_t aColumnIndex, 93 nsTArray<IndexDataValue>& aOutIndexValues); 94 95 using IndexDataValuesAutoArray = AutoTArray<IndexDataValue, 32>; 96 97 template <typename T> 98 Result<IndexDataValuesAutoArray, nsresult> ReadCompressedIndexDataValues( 99 T& aValues, uint32_t aColumnIndex); 100 101 Result<std::tuple<IndexOrObjectStoreId, bool, Span<const uint8_t>>, nsresult> 102 ReadCompressedIndexId(Span<const uint8_t> aData); 103 104 Result<std::pair<uint64_t, mozilla::Span<const uint8_t>>, nsresult> 105 ReadCompressedNumber(Span<const uint8_t> aSpan); 106 107 Result<StructuredCloneReadInfoParent, nsresult> 108 GetStructuredCloneReadInfoFromValueArray( 109 mozIStorageValueArray* aValues, uint32_t aDataIndex, uint32_t aFileIdsIndex, 110 const DatabaseFileManager& aFileManager); 111 112 Result<StructuredCloneReadInfoParent, nsresult> 113 GetStructuredCloneReadInfoFromStatement( 114 mozIStorageStatement* aStatement, uint32_t aDataIndex, 115 uint32_t aFileIdsIndex, const DatabaseFileManager& aFileManager); 116 117 Result<nsTArray<StructuredCloneFileParent>, nsresult> 118 DeserializeStructuredCloneFiles(const DatabaseFileManager& aFileManager, 119 const nsAString& aText); 120 121 nsresult ExecuteSimpleSQLSequence(mozIStorageConnection& aConnection, 122 Span<const nsLiteralCString> aSQLCommands); 123 124 } // namespace mozilla::dom::indexedDB 125 126 #endif // mozilla_dom_indexeddb_actorsparent_h__