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"
21 class EventChainPostVisitor
;
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
;
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()
64 return sIsMainProcess
;
68 static bool FullSynchronous();
70 static LoggingMode
GetLoggingMode()
79 static mozilla::LogModule
* GetLoggingModule()
84 return sLoggingModule
;
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 void AddFileManager(SafeRefPtr
<DatabaseFileManager
> aFileManager
);
104 void InvalidateAllFileManagers();
106 void InvalidateFileManagers(PersistenceType aPersistenceType
);
108 void InvalidateFileManagers(PersistenceType aPersistenceType
,
109 const nsACString
& aOrigin
);
111 void InvalidateFileManager(PersistenceType aPersistenceType
,
112 const nsACString
& aOrigin
,
113 const nsAString
& aDatabaseName
);
115 // Don't call this method in real code, it blocks the main thread!
116 // It is intended to be used by mochitests to test correctness of the special
117 // reference counting of stored blobs/files.
118 nsresult
BlockAndGetFileReferences(PersistenceType aPersistenceType
,
119 const nsACString
& aOrigin
,
120 const nsAString
& aDatabaseName
,
121 int64_t aFileId
, int32_t* aRefCnt
,
122 int32_t* aDBRefCnt
, bool* aResult
);
124 nsresult
FlushPendingFileDeletions();
126 static const nsCString
& GetLocale();
128 static bool ResolveSandboxBinding(JSContext
* aCx
);
130 static bool DefineIndexedDB(JSContext
* aCx
, JS::Handle
<JSObject
*> aGlobal
);
133 IndexedDatabaseManager();
134 ~IndexedDatabaseManager();
140 static void LoggingModePrefChangedCallback(const char* aPrefName
,
143 // Maintains a list of all DatabaseFileManager objects per origin. This list
144 // isn't protected by any mutex but it is only ever touched on the IO thread.
145 nsClassHashtable
<nsCStringHashKey
, FileManagerInfo
> mFileManagerInfos
;
147 nsClassHashtable
<nsRefPtrHashKey
<DatabaseFileManager
>, nsTArray
<int64_t>>
152 indexedDB::BackgroundUtilsChild
* mBackgroundActor
;
154 static bool sIsMainProcess
;
155 static bool sFullSynchronousMode
;
156 static LazyLogModule sLoggingModule
;
157 static Atomic
<LoggingMode
> sLoggingMode
;
161 } // namespace mozilla
163 #endif // mozilla_dom_indexeddatabasemanager_h__