diff options
author | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
---|---|---|
committer | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
commit | 5f8de423f190bbb79a62f804151bc24824fa32d8 (patch) | |
tree | 10027f336435511475e392454359edea8e25895d /dom/indexedDB/IndexedDatabaseManager.h | |
parent | 49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff) | |
download | UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip |
Add m-esr52 at 52.6.0
Diffstat (limited to 'dom/indexedDB/IndexedDatabaseManager.h')
-rw-r--r-- | dom/indexedDB/IndexedDatabaseManager.h | 257 |
1 files changed, 257 insertions, 0 deletions
diff --git a/dom/indexedDB/IndexedDatabaseManager.h b/dom/indexedDB/IndexedDatabaseManager.h new file mode 100644 index 000000000..8bb9d7003 --- /dev/null +++ b/dom/indexedDB/IndexedDatabaseManager.h @@ -0,0 +1,257 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef mozilla_dom_indexeddatabasemanager_h__ +#define mozilla_dom_indexeddatabasemanager_h__ + +#include "nsIObserver.h" + +#include "js/TypeDecls.h" +#include "mozilla/Atomics.h" +#include "mozilla/dom/quota/PersistenceType.h" +#include "mozilla/Mutex.h" +#include "nsClassHashtable.h" +#include "nsCOMPtr.h" +#include "nsHashKeys.h" +#include "nsITimer.h" + +class nsIEventTarget; + +namespace mozilla { + +class EventChainPostVisitor; + +namespace dom { + +class IDBFactory; + +namespace quota { + +class QuotaManager; + +} // namespace quota + +namespace indexedDB { + +class BackgroundUtilsChild; +class FileManager; +class FileManagerInfo; + +} // namespace indexedDB + +class IndexedDatabaseManager final + : public nsIObserver + , public nsITimerCallback +{ + typedef mozilla::dom::quota::PersistenceType PersistenceType; + typedef mozilla::dom::quota::QuotaManager QuotaManager; + typedef mozilla::dom::indexedDB::FileManager FileManager; + typedef mozilla::dom::indexedDB::FileManagerInfo FileManagerInfo; + +public: + enum LoggingMode + { + Logging_Disabled = 0, + Logging_Concise, + Logging_Detailed, + Logging_ConciseProfilerMarks, + Logging_DetailedProfilerMarks + }; + + NS_DECL_ISUPPORTS + NS_DECL_NSIOBSERVER + NS_DECL_NSITIMERCALLBACK + + // Returns a non-owning reference. + static IndexedDatabaseManager* + GetOrCreate(); + + // Returns a non-owning reference. + static IndexedDatabaseManager* + Get(); + + static bool + IsClosed(); + + static bool + IsMainProcess() +#ifdef DEBUG + ; +#else + { + return sIsMainProcess; + } +#endif + + static bool + InLowDiskSpaceMode() +#ifdef DEBUG + ; +#else + { + return !!sLowDiskSpaceMode; + } +#endif + + static bool + InTestingMode(); + + static bool + FullSynchronous(); + + static LoggingMode + GetLoggingMode() +#ifdef DEBUG + ; +#else + { + return sLoggingMode; + } +#endif + + static mozilla::LogModule* + GetLoggingModule() +#ifdef DEBUG + ; +#else + { + return sLoggingModule; + } +#endif + + static bool + ExperimentalFeaturesEnabled(); + + static bool + ExperimentalFeaturesEnabled(JSContext* aCx, JSObject* aGlobal); + + static bool + IsFileHandleEnabled(); + + static uint32_t + DataThreshold(); + + static uint32_t + MaxSerializedMsgSize(); + + void + ClearBackgroundActor(); + + void + NoteLiveQuotaManager(QuotaManager* aQuotaManager); + + void + NoteShuttingDownQuotaManager(); + + already_AddRefed<FileManager> + GetFileManager(PersistenceType aPersistenceType, + const nsACString& aOrigin, + const nsAString& aDatabaseName); + + void + AddFileManager(FileManager* aFileManager); + + void + InvalidateAllFileManagers(); + + void + InvalidateFileManagers(PersistenceType aPersistenceType, + const nsACString& aOrigin); + + void + InvalidateFileManager(PersistenceType aPersistenceType, + const nsACString& aOrigin, + const nsAString& aDatabaseName); + + nsresult + AsyncDeleteFile(FileManager* aFileManager, + int64_t aFileId); + + // Don't call this method in real code, it blocks the main thread! + // It is intended to be used by mochitests to test correctness of the special + // reference counting of stored blobs/files. + nsresult + BlockAndGetFileReferences(PersistenceType aPersistenceType, + const nsACString& aOrigin, + const nsAString& aDatabaseName, + int64_t aFileId, + int32_t* aRefCnt, + int32_t* aDBRefCnt, + int32_t* aSliceRefCnt, + bool* aResult); + + nsresult + FlushPendingFileDeletions(); + +#ifdef ENABLE_INTL_API + static const nsCString& + GetLocale(); +#endif + + static mozilla::Mutex& + FileMutex() + { + IndexedDatabaseManager* mgr = Get(); + NS_ASSERTION(mgr, "Must have a manager here!"); + + return mgr->mFileMutex; + } + + static nsresult + CommonPostHandleEvent(EventChainPostVisitor& aVisitor, IDBFactory* aFactory); + + static bool + ResolveSandboxBinding(JSContext* aCx); + + static bool + DefineIndexedDB(JSContext* aCx, JS::Handle<JSObject*> aGlobal); + +private: + IndexedDatabaseManager(); + ~IndexedDatabaseManager(); + + nsresult + Init(); + + void + Destroy(); + + static void + LoggingModePrefChangedCallback(const char* aPrefName, void* aClosure); + + nsCOMPtr<nsIEventTarget> mBackgroundThread; + + nsCOMPtr<nsITimer> mDeleteTimer; + + // Maintains a list of all file managers per origin. This list isn't + // protected by any mutex but it is only ever touched on the IO thread. + nsClassHashtable<nsCStringHashKey, FileManagerInfo> mFileManagerInfos; + + nsClassHashtable<nsRefPtrHashKey<FileManager>, + nsTArray<int64_t>> mPendingDeleteInfos; + + // Lock protecting FileManager.mFileInfos. + // It's s also used to atomically update FileInfo.mRefCnt, FileInfo.mDBRefCnt + // and FileInfo.mSliceRefCnt + mozilla::Mutex mFileMutex; + +#ifdef ENABLE_INTL_API + nsCString mLocale; +#endif + + indexedDB::BackgroundUtilsChild* mBackgroundActor; + + static bool sIsMainProcess; + static bool sFullSynchronousMode; + static LazyLogModule sLoggingModule; + static Atomic<LoggingMode> sLoggingMode; + static mozilla::Atomic<bool> sLowDiskSpaceMode; +}; + +} // namespace dom +} // namespace mozilla + +#endif // mozilla_dom_indexeddatabasemanager_h__ |