Bug 1886946: Remove incorrect assertion that buffer is not-pinned. r=sfink
[gecko.git] / dom / indexedDB / IndexedDatabaseManager.h
blob3d0f4673687e4cf6c9468fe597201e3bec3c58ce
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
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef mozilla_dom_indexeddatabasemanager_h__
8 #define mozilla_dom_indexeddatabasemanager_h__
10 #include "js/TypeDecls.h"
11 #include "mozilla/Atomics.h"
12 #include "mozilla/dom/quota/PersistenceType.h"
13 #include "mozilla/Logging.h"
14 #include "mozilla/Mutex.h"
15 #include "nsClassHashtable.h"
16 #include "nsHashKeys.h"
17 #include "SafeRefPtr.h"
19 namespace mozilla {
21 class EventChainPostVisitor;
23 namespace dom {
25 class IDBFactory;
27 namespace indexedDB {
29 class BackgroundUtilsChild;
30 class DatabaseFileManager;
31 class FileManagerInfo;
33 } // namespace indexedDB
35 class IndexedDatabaseManager final {
36 using PersistenceType = mozilla::dom::quota::PersistenceType;
37 using DatabaseFileManager = mozilla::dom::indexedDB::DatabaseFileManager;
38 using FileManagerInfo = mozilla::dom::indexedDB::FileManagerInfo;
40 public:
41 enum LoggingMode {
42 Logging_Disabled = 0,
43 Logging_Concise,
44 Logging_Detailed,
45 Logging_ConciseProfilerMarks,
46 Logging_DetailedProfilerMarks
49 NS_INLINE_DECL_REFCOUNTING_WITH_DESTROY(IndexedDatabaseManager, Destroy())
51 // Returns a non-owning reference.
52 static IndexedDatabaseManager* GetOrCreate();
54 // Returns a non-owning reference.
55 static IndexedDatabaseManager* Get();
57 static bool IsClosed();
59 static bool IsMainProcess()
60 #ifdef DEBUG
62 #else
64 return sIsMainProcess;
66 #endif
68 static bool FullSynchronous();
70 static LoggingMode GetLoggingMode()
71 #ifdef DEBUG
73 #else
75 return sLoggingMode;
77 #endif
79 static mozilla::LogModule* GetLoggingModule()
80 #ifdef DEBUG
82 #else
84 return sLoggingModule;
86 #endif
88 static uint32_t DataThreshold();
90 static uint32_t MaxSerializedMsgSize();
92 // The maximum number of extra entries to preload in an Cursor::OpenOp or
93 // Cursor::ContinueOp.
94 static int32_t MaxPreloadExtraRecords();
96 void ClearBackgroundActor();
98 [[nodiscard]] SafeRefPtr<DatabaseFileManager> GetFileManager(
99 PersistenceType aPersistenceType, const nsACString& aOrigin,
100 const nsAString& aDatabaseName);
102 [[nodiscard]] SafeRefPtr<DatabaseFileManager>
103 GetFileManagerByDatabaseFilePath(PersistenceType aPersistenceType,
104 const nsACString& aOrigin,
105 const nsAString& aDatabaseFilePath);
107 const nsTArray<SafeRefPtr<DatabaseFileManager>>& GetFileManagers(
108 PersistenceType aPersistenceType, const nsACString& aOrigin);
110 void AddFileManager(SafeRefPtr<DatabaseFileManager> aFileManager);
112 void InvalidateAllFileManagers();
114 void InvalidateFileManagers(PersistenceType aPersistenceType);
116 void InvalidateFileManagers(PersistenceType aPersistenceType,
117 const nsACString& aOrigin);
119 void InvalidateFileManager(PersistenceType aPersistenceType,
120 const nsACString& aOrigin,
121 const nsAString& aDatabaseName);
123 // Don't call this method in real code, it blocks the main thread!
124 // It is intended to be used by mochitests to test correctness of the special
125 // reference counting of stored blobs/files.
126 nsresult BlockAndGetFileReferences(PersistenceType aPersistenceType,
127 const nsACString& aOrigin,
128 const nsAString& aDatabaseName,
129 int64_t aFileId, int32_t* aRefCnt,
130 int32_t* aDBRefCnt, bool* aResult);
132 nsresult FlushPendingFileDeletions();
134 // XXX This extra explicit initialization should go away with bug 1730706.
135 nsresult EnsureLocale();
137 static const nsCString& GetLocale();
139 static bool ResolveSandboxBinding(JSContext* aCx);
141 static bool DefineIndexedDB(JSContext* aCx, JS::Handle<JSObject*> aGlobal);
143 private:
144 IndexedDatabaseManager();
145 ~IndexedDatabaseManager();
147 nsresult Init();
149 void Destroy();
151 static void LoggingModePrefChangedCallback(const char* aPrefName,
152 void* aClosure);
154 // Maintains a list of all DatabaseFileManager objects per origin. This list
155 // isn't protected by any mutex but it is only ever touched on the IO thread.
156 nsClassHashtable<nsCStringHashKey, FileManagerInfo> mFileManagerInfos;
158 nsClassHashtable<nsRefPtrHashKey<DatabaseFileManager>, nsTArray<int64_t>>
159 mPendingDeleteInfos;
161 nsCString mLocale;
163 indexedDB::BackgroundUtilsChild* mBackgroundActor;
165 static bool sIsMainProcess;
166 static bool sFullSynchronousMode;
167 static LazyLogModule sLoggingModule;
168 static Atomic<LoggingMode> sLoggingMode;
171 } // namespace dom
172 } // namespace mozilla
174 #endif // mozilla_dom_indexeddatabasemanager_h__