/work/obj-fuzz/dist/include/mozilla/dom/IndexedDatabaseManager.h
Line | Count | Source (jump to first uncovered line) |
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/. */ |
6 | | |
7 | | #ifndef mozilla_dom_indexeddatabasemanager_h__ |
8 | | #define mozilla_dom_indexeddatabasemanager_h__ |
9 | | |
10 | | #include "js/TypeDecls.h" |
11 | | #include "mozilla/Atomics.h" |
12 | | #include "mozilla/dom/quota/PersistenceType.h" |
13 | | #include "mozilla/Mutex.h" |
14 | | #include "nsClassHashtable.h" |
15 | | #include "nsCOMPtr.h" |
16 | | #include "nsHashKeys.h" |
17 | | #include "nsINamed.h" |
18 | | #include "nsITimer.h" |
19 | | |
20 | | class nsIEventTarget; |
21 | | |
22 | | namespace mozilla { |
23 | | |
24 | | class EventChainPostVisitor; |
25 | | |
26 | | namespace dom { |
27 | | |
28 | | class IDBFactory; |
29 | | |
30 | | namespace quota { |
31 | | |
32 | | class QuotaManager; |
33 | | |
34 | | } // namespace quota |
35 | | |
36 | | namespace indexedDB { |
37 | | |
38 | | class BackgroundUtilsChild; |
39 | | class FileManager; |
40 | | class FileManagerInfo; |
41 | | |
42 | | } // namespace indexedDB |
43 | | |
44 | | class IndexedDatabaseManager final |
45 | | : public nsITimerCallback |
46 | | , public nsINamed |
47 | | { |
48 | | typedef mozilla::dom::quota::PersistenceType PersistenceType; |
49 | | typedef mozilla::dom::quota::QuotaManager QuotaManager; |
50 | | typedef mozilla::dom::indexedDB::FileManager FileManager; |
51 | | typedef mozilla::dom::indexedDB::FileManagerInfo FileManagerInfo; |
52 | | |
53 | | public: |
54 | | enum LoggingMode |
55 | | { |
56 | | Logging_Disabled = 0, |
57 | | Logging_Concise, |
58 | | Logging_Detailed, |
59 | | Logging_ConciseProfilerMarks, |
60 | | Logging_DetailedProfilerMarks |
61 | | }; |
62 | | |
63 | | NS_DECL_ISUPPORTS |
64 | | NS_DECL_NSITIMERCALLBACK |
65 | | NS_DECL_NSINAMED |
66 | | |
67 | | // Returns a non-owning reference. |
68 | | static IndexedDatabaseManager* |
69 | | GetOrCreate(); |
70 | | |
71 | | // Returns a non-owning reference. |
72 | | static IndexedDatabaseManager* |
73 | | Get(); |
74 | | |
75 | | static bool |
76 | | IsClosed(); |
77 | | |
78 | | static bool |
79 | | IsMainProcess() |
80 | | #ifdef DEBUG |
81 | | ; |
82 | | #else |
83 | 0 | { |
84 | 0 | return sIsMainProcess; |
85 | 0 | } |
86 | | #endif |
87 | | |
88 | | static bool |
89 | | InTestingMode(); |
90 | | |
91 | | static bool |
92 | | FullSynchronous(); |
93 | | |
94 | | static LoggingMode |
95 | | GetLoggingMode() |
96 | | #ifdef DEBUG |
97 | | ; |
98 | | #else |
99 | 0 | { |
100 | 0 | return sLoggingMode; |
101 | 0 | } |
102 | | #endif |
103 | | |
104 | | static mozilla::LogModule* |
105 | | GetLoggingModule() |
106 | | #ifdef DEBUG |
107 | | ; |
108 | | #else |
109 | 0 | { |
110 | 0 | return sLoggingModule; |
111 | 0 | } |
112 | | #endif |
113 | | |
114 | | static bool |
115 | | ExperimentalFeaturesEnabled(); |
116 | | |
117 | | static bool |
118 | | ExperimentalFeaturesEnabled(JSContext* aCx, JSObject* aGlobal); |
119 | | |
120 | | static bool |
121 | | IsFileHandleEnabled(); |
122 | | |
123 | | static uint32_t |
124 | | DataThreshold(); |
125 | | |
126 | | static uint32_t |
127 | | MaxSerializedMsgSize(); |
128 | | |
129 | | void |
130 | | ClearBackgroundActor(); |
131 | | |
132 | | void |
133 | | NoteLiveQuotaManager(QuotaManager* aQuotaManager); |
134 | | |
135 | | void |
136 | | NoteShuttingDownQuotaManager(); |
137 | | |
138 | | already_AddRefed<FileManager> |
139 | | GetFileManager(PersistenceType aPersistenceType, |
140 | | const nsACString& aOrigin, |
141 | | const nsAString& aDatabaseName); |
142 | | |
143 | | void |
144 | | AddFileManager(FileManager* aFileManager); |
145 | | |
146 | | void |
147 | | InvalidateAllFileManagers(); |
148 | | |
149 | | void |
150 | | InvalidateFileManagers(PersistenceType aPersistenceType, |
151 | | const nsACString& aOrigin); |
152 | | |
153 | | void |
154 | | InvalidateFileManager(PersistenceType aPersistenceType, |
155 | | const nsACString& aOrigin, |
156 | | const nsAString& aDatabaseName); |
157 | | |
158 | | nsresult |
159 | | AsyncDeleteFile(FileManager* aFileManager, |
160 | | int64_t aFileId); |
161 | | |
162 | | // Don't call this method in real code, it blocks the main thread! |
163 | | // It is intended to be used by mochitests to test correctness of the special |
164 | | // reference counting of stored blobs/files. |
165 | | nsresult |
166 | | BlockAndGetFileReferences(PersistenceType aPersistenceType, |
167 | | const nsACString& aOrigin, |
168 | | const nsAString& aDatabaseName, |
169 | | int64_t aFileId, |
170 | | int32_t* aRefCnt, |
171 | | int32_t* aDBRefCnt, |
172 | | int32_t* aSliceRefCnt, |
173 | | bool* aResult); |
174 | | |
175 | | nsresult |
176 | | FlushPendingFileDeletions(); |
177 | | |
178 | | static const nsCString& |
179 | | GetLocale(); |
180 | | |
181 | | static mozilla::Mutex& |
182 | | FileMutex() |
183 | 0 | { |
184 | 0 | IndexedDatabaseManager* mgr = Get(); |
185 | 0 | NS_ASSERTION(mgr, "Must have a manager here!"); |
186 | 0 |
|
187 | 0 | return mgr->mFileMutex; |
188 | 0 | } |
189 | | |
190 | | static nsresult |
191 | | CommonPostHandleEvent(EventChainPostVisitor& aVisitor, IDBFactory* aFactory); |
192 | | |
193 | | static bool |
194 | | ResolveSandboxBinding(JSContext* aCx); |
195 | | |
196 | | static bool |
197 | | DefineIndexedDB(JSContext* aCx, JS::Handle<JSObject*> aGlobal); |
198 | | |
199 | | private: |
200 | | IndexedDatabaseManager(); |
201 | | ~IndexedDatabaseManager(); |
202 | | |
203 | | nsresult |
204 | | Init(); |
205 | | |
206 | | void |
207 | | Destroy(); |
208 | | |
209 | | static void |
210 | | LoggingModePrefChangedCallback(const char* aPrefName, void* aClosure); |
211 | | |
212 | | nsCOMPtr<nsIEventTarget> mBackgroundThread; |
213 | | |
214 | | nsCOMPtr<nsITimer> mDeleteTimer; |
215 | | |
216 | | // Maintains a list of all file managers per origin. This list isn't |
217 | | // protected by any mutex but it is only ever touched on the IO thread. |
218 | | nsClassHashtable<nsCStringHashKey, FileManagerInfo> mFileManagerInfos; |
219 | | |
220 | | nsClassHashtable<nsRefPtrHashKey<FileManager>, |
221 | | nsTArray<int64_t>> mPendingDeleteInfos; |
222 | | |
223 | | // Lock protecting FileManager.mFileInfos. |
224 | | // It's s also used to atomically update FileInfo.mRefCnt, FileInfo.mDBRefCnt |
225 | | // and FileInfo.mSliceRefCnt |
226 | | mozilla::Mutex mFileMutex; |
227 | | |
228 | | nsCString mLocale; |
229 | | |
230 | | indexedDB::BackgroundUtilsChild* mBackgroundActor; |
231 | | |
232 | | static bool sIsMainProcess; |
233 | | static bool sFullSynchronousMode; |
234 | | static LazyLogModule sLoggingModule; |
235 | | static Atomic<LoggingMode> sLoggingMode; |
236 | | }; |
237 | | |
238 | | } // namespace dom |
239 | | } // namespace mozilla |
240 | | |
241 | | #endif // mozilla_dom_indexeddatabasemanager_h__ |