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 "nsIIndexedDatabaseManager.h"
18 #include "SafeRefPtr.h"
22 class EventChainPostVisitor
;
30 class BackgroundUtilsChild
;
31 class DatabaseFileManager
;
32 class FileManagerInfo
;
34 } // namespace indexedDB
36 class IndexedDatabaseManager final
: public nsIIndexedDatabaseManager
{
37 using PersistenceType
= mozilla::dom::quota::PersistenceType
;
38 using DatabaseFileManager
= mozilla::dom::indexedDB::DatabaseFileManager
;
39 using FileManagerInfo
= mozilla::dom::indexedDB::FileManagerInfo
;
46 Logging_ConciseProfilerMarks
,
47 Logging_DetailedProfilerMarks
51 NS_DECL_NSIINDEXEDDATABASEMANAGER
53 // Returns a non-owning reference.
54 static IndexedDatabaseManager
* GetOrCreate();
56 // Returns a non-owning reference.
57 static IndexedDatabaseManager
* Get();
59 // No one should call this but the factory.
60 static already_AddRefed
<IndexedDatabaseManager
> FactoryCreate();
62 static bool IsClosed();
64 static bool IsMainProcess()
69 return sIsMainProcess
;
73 static bool FullSynchronous();
75 static LoggingMode
GetLoggingMode()
84 static mozilla::LogModule
* GetLoggingModule()
89 return sLoggingModule
;
93 static uint32_t DataThreshold();
95 static uint32_t MaxSerializedMsgSize();
97 // The maximum number of extra entries to preload in an Cursor::OpenOp or
98 // Cursor::ContinueOp.
99 static int32_t MaxPreloadExtraRecords();
101 void ClearBackgroundActor();
103 [[nodiscard
]] SafeRefPtr
<DatabaseFileManager
> GetFileManager(
104 PersistenceType aPersistenceType
, const nsACString
& aOrigin
,
105 const nsAString
& aDatabaseName
);
107 [[nodiscard
]] SafeRefPtr
<DatabaseFileManager
>
108 GetFileManagerByDatabaseFilePath(PersistenceType aPersistenceType
,
109 const nsACString
& aOrigin
,
110 const nsAString
& aDatabaseFilePath
);
112 const nsTArray
<SafeRefPtr
<DatabaseFileManager
>>& GetFileManagers(
113 PersistenceType aPersistenceType
, const nsACString
& aOrigin
);
115 void AddFileManager(SafeRefPtr
<DatabaseFileManager
> aFileManager
);
117 void InvalidateAllFileManagers();
119 void InvalidateFileManagers(PersistenceType aPersistenceType
);
121 void InvalidateFileManagers(PersistenceType aPersistenceType
,
122 const nsACString
& aOrigin
);
124 void InvalidateFileManager(PersistenceType aPersistenceType
,
125 const nsACString
& aOrigin
,
126 const nsAString
& aDatabaseName
);
128 // Don't call this method in real code, it blocks the main thread!
129 // It is intended to be used by mochitests to test correctness of the special
130 // reference counting of stored blobs/files.
131 nsresult
BlockAndGetFileReferences(PersistenceType aPersistenceType
,
132 const nsACString
& aOrigin
,
133 const nsAString
& aDatabaseName
,
134 int64_t aFileId
, int32_t* aRefCnt
,
135 int32_t* aDBRefCnt
, bool* aResult
);
137 nsresult
FlushPendingFileDeletions();
139 // XXX This extra explicit initialization should go away with bug 1730706.
140 nsresult
EnsureLocale();
142 static const nsCString
& GetLocale();
144 static bool ResolveSandboxBinding(JSContext
* aCx
);
146 static bool DefineIndexedDB(JSContext
* aCx
, JS::Handle
<JSObject
*> aGlobal
);
149 IndexedDatabaseManager();
150 ~IndexedDatabaseManager();
156 nsresult
EnsureBackgroundActor();
158 static void LoggingModePrefChangedCallback(const char* aPrefName
,
161 // Maintains a list of all DatabaseFileManager objects per origin. This list
162 // isn't protected by any mutex but it is only ever touched on the IO thread.
163 nsClassHashtable
<nsCStringHashKey
, FileManagerInfo
> mFileManagerInfos
;
165 nsClassHashtable
<nsRefPtrHashKey
<DatabaseFileManager
>, nsTArray
<int64_t>>
170 indexedDB::BackgroundUtilsChild
* mBackgroundActor
;
172 static bool sIsMainProcess
;
173 static bool sFullSynchronousMode
;
174 static LazyLogModule sLoggingModule
;
175 static Atomic
<LoggingMode
> sLoggingMode
;
179 } // namespace mozilla
181 #endif // mozilla_dom_indexeddatabasemanager_h__