1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=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_indexeddb_indexeddatabasemanager_h__
8 #define mozilla_dom_indexeddb_indexeddatabasemanager_h__
10 #include "mozilla/dom/indexedDB/IndexedDatabase.h"
12 #include "nsIObserver.h"
14 #include "js/TypeDecls.h"
15 #include "mozilla/Atomics.h"
16 #include "mozilla/dom/quota/PersistenceType.h"
17 #include "mozilla/Mutex.h"
18 #include "nsClassHashtable.h"
19 #include "nsHashKeys.h"
24 class EventChainPostVisitor
;
28 class OriginOrPatternString
;
33 BEGIN_INDEXEDDB_NAMESPACE
36 class FileManagerInfo
;
38 class IndexedDatabaseManager MOZ_FINAL
: public nsIObserver
40 typedef mozilla::dom::quota::OriginOrPatternString OriginOrPatternString
;
41 typedef mozilla::dom::quota::PersistenceType PersistenceType
;
47 // Returns a non-owning reference.
48 static IndexedDatabaseManager
*
51 // Returns a non-owning reference.
52 static IndexedDatabaseManager
*
64 return sIsMainProcess
;
74 return !!sLowDiskSpaceMode
;
78 already_AddRefed
<FileManager
>
79 GetFileManager(PersistenceType aPersistenceType
,
80 const nsACString
& aOrigin
,
81 const nsAString
& aDatabaseName
);
84 AddFileManager(FileManager
* aFileManager
);
87 InvalidateAllFileManagers();
90 InvalidateFileManagers(PersistenceType aPersistenceType
,
91 const OriginOrPatternString
& aOriginOrPattern
);
94 InvalidateFileManager(PersistenceType aPersistenceType
,
95 const nsACString
& aOrigin
,
96 const nsAString
& aDatabaseName
);
99 AsyncDeleteFile(FileManager
* aFileManager
,
102 // Don't call this method in real code, it blocks the main thread!
103 // It is intended to be used by mochitests to test correctness of the special
104 // reference counting of stored blobs/files.
106 BlockAndGetFileReferences(PersistenceType aPersistenceType
,
107 const nsACString
& aOrigin
,
108 const nsAString
& aDatabaseName
,
112 int32_t* aSliceRefCnt
,
115 static mozilla::Mutex
&
118 IndexedDatabaseManager
* mgr
= Get();
119 NS_ASSERTION(mgr
, "Must have a manager here!");
121 return mgr
->mFileMutex
;
125 FireWindowOnError(nsPIDOMWindow
* aOwner
,
126 EventChainPostVisitor
& aVisitor
);
129 TabContextMayAccessOrigin(const mozilla::dom::TabContext
& aContext
,
130 const nsACString
& aOrigin
);
133 DefineIndexedDB(JSContext
* aCx
, JS::Handle
<JSObject
*> aGlobal
);
136 IndexedDatabaseManager();
137 ~IndexedDatabaseManager();
145 static PLDHashOperator
146 InvalidateAndRemoveFileManagers(const nsACString
& aKey
,
147 nsAutoPtr
<FileManagerInfo
>& aValue
,
150 // Maintains a list of all file managers per origin. This list isn't
151 // protected by any mutex but it is only ever touched on the IO thread.
152 nsClassHashtable
<nsCStringHashKey
, FileManagerInfo
> mFileManagerInfos
;
154 // Lock protecting FileManager.mFileInfos and nsDOMFileBase.mFileInfos
155 // It's s also used to atomically update FileInfo.mRefCnt, FileInfo.mDBRefCnt
156 // and FileInfo.mSliceRefCnt
157 mozilla::Mutex mFileMutex
;
159 static bool sIsMainProcess
;
160 static mozilla::Atomic
<bool> sLowDiskSpaceMode
;
163 END_INDEXEDDB_NAMESPACE
165 #endif /* mozilla_dom_indexeddb_indexeddatabasemanager_h__ */