1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/indexedDB/FileManager.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,124 @@ 1.4 +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* vim: set ts=2 et sw=2 tw=80: */ 1.6 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.9 + 1.10 +#ifndef mozilla_dom_indexeddb_filemanager_h__ 1.11 +#define mozilla_dom_indexeddb_filemanager_h__ 1.12 + 1.13 +#include "IndexedDatabase.h" 1.14 + 1.15 +#include "nsIDOMFile.h" 1.16 +#include "nsIFile.h" 1.17 + 1.18 +#include "mozilla/dom/quota/PersistenceType.h" 1.19 +#include "mozilla/dom/quota/StoragePrivilege.h" 1.20 +#include "nsDataHashtable.h" 1.21 + 1.22 +class mozIStorageConnection; 1.23 + 1.24 +BEGIN_INDEXEDDB_NAMESPACE 1.25 + 1.26 +class FileInfo; 1.27 + 1.28 +class FileManager MOZ_FINAL 1.29 +{ 1.30 + friend class FileInfo; 1.31 + 1.32 + typedef mozilla::dom::quota::PersistenceType PersistenceType; 1.33 + typedef mozilla::dom::quota::StoragePrivilege StoragePrivilege; 1.34 + 1.35 +public: 1.36 + FileManager(PersistenceType aPersistenceType, const nsACString& aGroup, 1.37 + const nsACString& aOrigin, StoragePrivilege aPrivilege, 1.38 + const nsAString& aDatabaseName) 1.39 + : mPersistenceType(aPersistenceType), mGroup(aGroup), mOrigin(aOrigin), 1.40 + mPrivilege(aPrivilege), mDatabaseName(aDatabaseName), mLastFileId(0), 1.41 + mInvalidated(false) 1.42 + { } 1.43 + 1.44 + NS_INLINE_DECL_THREADSAFE_REFCOUNTING(FileManager) 1.45 + 1.46 + PersistenceType Type() 1.47 + { 1.48 + return mPersistenceType; 1.49 + } 1.50 + 1.51 + const nsACString& Group() const 1.52 + { 1.53 + return mGroup; 1.54 + } 1.55 + 1.56 + const nsACString& Origin() const 1.57 + { 1.58 + return mOrigin; 1.59 + } 1.60 + 1.61 + const StoragePrivilege& Privilege() const 1.62 + { 1.63 + return mPrivilege; 1.64 + } 1.65 + 1.66 + const nsAString& DatabaseName() const 1.67 + { 1.68 + return mDatabaseName; 1.69 + } 1.70 + 1.71 + bool Invalidated() const 1.72 + { 1.73 + return mInvalidated; 1.74 + } 1.75 + 1.76 + nsresult Init(nsIFile* aDirectory, 1.77 + mozIStorageConnection* aConnection); 1.78 + 1.79 + nsresult Invalidate(); 1.80 + 1.81 + already_AddRefed<nsIFile> GetDirectory(); 1.82 + 1.83 + already_AddRefed<nsIFile> GetJournalDirectory(); 1.84 + 1.85 + already_AddRefed<nsIFile> EnsureJournalDirectory(); 1.86 + 1.87 + already_AddRefed<FileInfo> GetFileInfo(int64_t aId); 1.88 + 1.89 + already_AddRefed<FileInfo> GetNewFileInfo(); 1.90 + 1.91 + static already_AddRefed<nsIFile> GetFileForId(nsIFile* aDirectory, 1.92 + int64_t aId); 1.93 + 1.94 + static nsresult InitDirectory(nsIFile* aDirectory, 1.95 + nsIFile* aDatabaseFile, 1.96 + PersistenceType aPersistenceType, 1.97 + const nsACString& aGroup, 1.98 + const nsACString& aOrigin); 1.99 + 1.100 + static nsresult GetUsage(nsIFile* aDirectory, uint64_t* aUsage); 1.101 + 1.102 +private: 1.103 + // Private destructor, to discourage deletion outside of Release(): 1.104 + ~FileManager() 1.105 + { 1.106 + } 1.107 + 1.108 + PersistenceType mPersistenceType; 1.109 + nsCString mGroup; 1.110 + nsCString mOrigin; 1.111 + StoragePrivilege mPrivilege; 1.112 + nsString mDatabaseName; 1.113 + 1.114 + nsString mDirectoryPath; 1.115 + nsString mJournalDirectoryPath; 1.116 + 1.117 + int64_t mLastFileId; 1.118 + 1.119 + // Protected by IndexedDatabaseManager::FileMutex() 1.120 + nsDataHashtable<nsUint64HashKey, FileInfo*> mFileInfos; 1.121 + 1.122 + bool mInvalidated; 1.123 +}; 1.124 + 1.125 +END_INDEXEDDB_NAMESPACE 1.126 + 1.127 +#endif // mozilla_dom_indexeddb_filemanager_h__