michael@0: /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* vim: set ts=2 et sw=2 tw=80: */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef mozilla_dom_indexeddb_filemanager_h__ michael@0: #define mozilla_dom_indexeddb_filemanager_h__ michael@0: michael@0: #include "IndexedDatabase.h" michael@0: michael@0: #include "nsIDOMFile.h" michael@0: #include "nsIFile.h" michael@0: michael@0: #include "mozilla/dom/quota/PersistenceType.h" michael@0: #include "mozilla/dom/quota/StoragePrivilege.h" michael@0: #include "nsDataHashtable.h" michael@0: michael@0: class mozIStorageConnection; michael@0: michael@0: BEGIN_INDEXEDDB_NAMESPACE michael@0: michael@0: class FileInfo; michael@0: michael@0: class FileManager MOZ_FINAL michael@0: { michael@0: friend class FileInfo; michael@0: michael@0: typedef mozilla::dom::quota::PersistenceType PersistenceType; michael@0: typedef mozilla::dom::quota::StoragePrivilege StoragePrivilege; michael@0: michael@0: public: michael@0: FileManager(PersistenceType aPersistenceType, const nsACString& aGroup, michael@0: const nsACString& aOrigin, StoragePrivilege aPrivilege, michael@0: const nsAString& aDatabaseName) michael@0: : mPersistenceType(aPersistenceType), mGroup(aGroup), mOrigin(aOrigin), michael@0: mPrivilege(aPrivilege), mDatabaseName(aDatabaseName), mLastFileId(0), michael@0: mInvalidated(false) michael@0: { } michael@0: michael@0: NS_INLINE_DECL_THREADSAFE_REFCOUNTING(FileManager) michael@0: michael@0: PersistenceType Type() michael@0: { michael@0: return mPersistenceType; michael@0: } michael@0: michael@0: const nsACString& Group() const michael@0: { michael@0: return mGroup; michael@0: } michael@0: michael@0: const nsACString& Origin() const michael@0: { michael@0: return mOrigin; michael@0: } michael@0: michael@0: const StoragePrivilege& Privilege() const michael@0: { michael@0: return mPrivilege; michael@0: } michael@0: michael@0: const nsAString& DatabaseName() const michael@0: { michael@0: return mDatabaseName; michael@0: } michael@0: michael@0: bool Invalidated() const michael@0: { michael@0: return mInvalidated; michael@0: } michael@0: michael@0: nsresult Init(nsIFile* aDirectory, michael@0: mozIStorageConnection* aConnection); michael@0: michael@0: nsresult Invalidate(); michael@0: michael@0: already_AddRefed GetDirectory(); michael@0: michael@0: already_AddRefed GetJournalDirectory(); michael@0: michael@0: already_AddRefed EnsureJournalDirectory(); michael@0: michael@0: already_AddRefed GetFileInfo(int64_t aId); michael@0: michael@0: already_AddRefed GetNewFileInfo(); michael@0: michael@0: static already_AddRefed GetFileForId(nsIFile* aDirectory, michael@0: int64_t aId); michael@0: michael@0: static nsresult InitDirectory(nsIFile* aDirectory, michael@0: nsIFile* aDatabaseFile, michael@0: PersistenceType aPersistenceType, michael@0: const nsACString& aGroup, michael@0: const nsACString& aOrigin); michael@0: michael@0: static nsresult GetUsage(nsIFile* aDirectory, uint64_t* aUsage); michael@0: michael@0: private: michael@0: // Private destructor, to discourage deletion outside of Release(): michael@0: ~FileManager() michael@0: { michael@0: } michael@0: michael@0: PersistenceType mPersistenceType; michael@0: nsCString mGroup; michael@0: nsCString mOrigin; michael@0: StoragePrivilege mPrivilege; michael@0: nsString mDatabaseName; michael@0: michael@0: nsString mDirectoryPath; michael@0: nsString mJournalDirectoryPath; michael@0: michael@0: int64_t mLastFileId; michael@0: michael@0: // Protected by IndexedDatabaseManager::FileMutex() michael@0: nsDataHashtable mFileInfos; michael@0: michael@0: bool mInvalidated; michael@0: }; michael@0: michael@0: END_INDEXEDDB_NAMESPACE michael@0: michael@0: #endif // mozilla_dom_indexeddb_filemanager_h__