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_idbdatabase_h__
8 #define mozilla_dom_indexeddb_idbdatabase_h__
10 #include "mozilla/Attributes.h"
11 #include "mozilla/dom/IDBTransactionBinding.h"
12 #include "mozilla/dom/StorageTypeBinding.h"
13 #include "mozilla/dom/indexedDB/IDBWrapperCache.h"
14 #include "mozilla/dom/quota/PersistenceType.h"
15 #include "nsAutoPtr.h"
16 #include "nsDataHashtable.h"
17 #include "nsHashKeys.h"
19 #include "nsTHashtable.h"
22 class nsIWeakReference
;
28 class EventChainPostVisitor
;
34 struct IDBObjectStoreParameters
;
35 template <typename
> class Sequence
;
39 class BackgroundDatabaseChild
;
47 class PBackgroundIDBDatabaseFileChild
;
49 class IDBDatabase MOZ_FINAL
50 : public IDBWrapperCache
52 typedef mozilla::dom::StorageType StorageType
;
53 typedef mozilla::dom::quota::PersistenceType PersistenceType
;
55 class LogWarningRunnable
;
56 friend class LogWarningRunnable
;
59 friend class Observer
;
61 // The factory must be kept alive when IndexedDB is used in multiple
62 // processes. If it dies then the entire actor tree will be destroyed with it
63 // and the world will explode.
64 nsRefPtr
<IDBFactory
> mFactory
;
66 nsAutoPtr
<DatabaseSpec
> mSpec
;
68 // Normally null except during a versionchange transaction.
69 nsAutoPtr
<DatabaseSpec
> mPreviousSpec
;
71 nsRefPtr
<FileManager
> mFileManager
;
73 BackgroundDatabaseChild
* mBackgroundActor
;
75 nsTHashtable
<nsPtrHashKey
<IDBTransaction
>> mTransactions
;
77 nsDataHashtable
<nsISupportsHashKey
, PBackgroundIDBDatabaseFileChild
*>
80 nsTHashtable
<nsISupportsHashKey
> mReceivedBlobs
;
82 nsRefPtr
<Observer
> mObserver
;
84 // Weak refs, IDBMutableFile strongly owns this IDBDatabase object.
85 nsTArray
<IDBMutableFile
*> mLiveMutableFiles
;
91 static already_AddRefed
<IDBDatabase
>
92 Create(IDBWrapperCache
* aOwnerCache
,
94 BackgroundDatabaseChild
* aActor
,
98 AssertIsOnOwningThread() const
109 GetName(nsAString
& aName
) const
111 AssertIsOnOwningThread();
119 already_AddRefed
<nsIDocument
>
120 GetOwnerDocument() const;
125 AssertIsOnOwningThread();
133 AssertIsOnOwningThread();
141 // Whether or not the database has been invalidated. If it has then no further
142 // transactions for this database will be allowed to run.
144 IsInvalidated() const
146 AssertIsOnOwningThread();
152 EnterSetVersionTransaction(uint64_t aNewVersion
);
155 ExitSetVersionTransaction();
157 // Called when a versionchange transaction is aborted to reset the
160 RevertToPreviousState();
165 AssertIsOnOwningThread();
171 RegisterTransaction(IDBTransaction
* aTransaction
);
174 UnregisterTransaction(IDBTransaction
* aTransaction
);
177 AbortTransactions(bool aShouldWarn
);
179 PBackgroundIDBDatabaseFileChild
*
180 GetOrCreateFileActorForBlob(File
* aBlob
);
183 NoteFinishedFileActor(PBackgroundIDBDatabaseFileChild
* aFileActor
);
186 NoteReceivedBlob(File
* aBlob
);
189 DelayedMaybeExpireFileActors();
191 // XXX This doesn't really belong here... It's only needed for IDBMutableFile
192 // serialization and should be removed someday.
194 GetQuotaInfo(nsACString
& aOrigin
, PersistenceType
* aPersistenceType
);
197 NoteLiveMutableFile(IDBMutableFile
* aMutableFile
);
200 NoteFinishedMutableFile(IDBMutableFile
* aMutableFile
);
203 GetParentObject() const;
205 already_AddRefed
<DOMStringList
>
206 ObjectStoreNames() const;
208 already_AddRefed
<IDBObjectStore
>
209 CreateObjectStore(const nsAString
& aName
,
210 const IDBObjectStoreParameters
& aOptionalParameters
,
214 DeleteObjectStore(const nsAString
& name
, ErrorResult
& aRv
);
216 already_AddRefed
<IDBTransaction
>
217 Transaction(const nsAString
& aStoreName
,
218 IDBTransactionMode aMode
,
221 already_AddRefed
<IDBTransaction
>
222 Transaction(const Sequence
<nsString
>& aStoreNames
,
223 IDBTransactionMode aMode
,
229 IMPL_EVENT_HANDLER(abort
)
230 IMPL_EVENT_HANDLER(error
)
231 IMPL_EVENT_HANDLER(versionchange
)
233 already_AddRefed
<IDBRequest
>
234 CreateMutableFile(const nsAString
& aName
,
235 const Optional
<nsAString
>& aType
,
238 already_AddRefed
<IDBRequest
>
239 MozCreateFileHandle(const nsAString
& aName
,
240 const Optional
<nsAString
>& aType
,
243 return CreateMutableFile(aName
, aType
, aRv
);
247 ClearBackgroundActor()
249 AssertIsOnOwningThread();
251 mBackgroundActor
= nullptr;
260 NS_DECL_ISUPPORTS_INHERITED
261 NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(IDBDatabase
, IDBWrapperCache
)
265 LastRelease() MOZ_OVERRIDE
;
268 PostHandleEvent(EventChainPostVisitor
& aVisitor
) MOZ_OVERRIDE
;
272 WrapObject(JSContext
* aCx
) MOZ_OVERRIDE
;
275 IDBDatabase(IDBWrapperCache
* aOwnerCache
,
276 IDBFactory
* aFactory
,
277 BackgroundDatabaseChild
* aActor
,
278 DatabaseSpec
* aSpec
);
286 InvalidateInternal();
289 RunningVersionChangeTransaction() const
291 AssertIsOnOwningThread();
293 return !!mPreviousSpec
;
297 RefreshSpec(bool aMayDelete
);
300 ExpireFileActors(bool aExpireAll
);
303 InvalidateMutableFiles();
306 LogWarning(const char* aMessageName
,
307 const nsAString
& aFilename
,
308 uint32_t aLineNumber
);
311 } // namespace indexedDB
313 } // namespace mozilla
315 #endif // mozilla_dom_indexeddb_idbdatabase_h__