dom/indexedDB/FileManager.h

branch
TOR_BUG_9701
changeset 15
b8a032363ba2
equal deleted inserted replaced
-1:000000000000 0:030bf323580a
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/. */
6
7 #ifndef mozilla_dom_indexeddb_filemanager_h__
8 #define mozilla_dom_indexeddb_filemanager_h__
9
10 #include "IndexedDatabase.h"
11
12 #include "nsIDOMFile.h"
13 #include "nsIFile.h"
14
15 #include "mozilla/dom/quota/PersistenceType.h"
16 #include "mozilla/dom/quota/StoragePrivilege.h"
17 #include "nsDataHashtable.h"
18
19 class mozIStorageConnection;
20
21 BEGIN_INDEXEDDB_NAMESPACE
22
23 class FileInfo;
24
25 class FileManager MOZ_FINAL
26 {
27 friend class FileInfo;
28
29 typedef mozilla::dom::quota::PersistenceType PersistenceType;
30 typedef mozilla::dom::quota::StoragePrivilege StoragePrivilege;
31
32 public:
33 FileManager(PersistenceType aPersistenceType, const nsACString& aGroup,
34 const nsACString& aOrigin, StoragePrivilege aPrivilege,
35 const nsAString& aDatabaseName)
36 : mPersistenceType(aPersistenceType), mGroup(aGroup), mOrigin(aOrigin),
37 mPrivilege(aPrivilege), mDatabaseName(aDatabaseName), mLastFileId(0),
38 mInvalidated(false)
39 { }
40
41 NS_INLINE_DECL_THREADSAFE_REFCOUNTING(FileManager)
42
43 PersistenceType Type()
44 {
45 return mPersistenceType;
46 }
47
48 const nsACString& Group() const
49 {
50 return mGroup;
51 }
52
53 const nsACString& Origin() const
54 {
55 return mOrigin;
56 }
57
58 const StoragePrivilege& Privilege() const
59 {
60 return mPrivilege;
61 }
62
63 const nsAString& DatabaseName() const
64 {
65 return mDatabaseName;
66 }
67
68 bool Invalidated() const
69 {
70 return mInvalidated;
71 }
72
73 nsresult Init(nsIFile* aDirectory,
74 mozIStorageConnection* aConnection);
75
76 nsresult Invalidate();
77
78 already_AddRefed<nsIFile> GetDirectory();
79
80 already_AddRefed<nsIFile> GetJournalDirectory();
81
82 already_AddRefed<nsIFile> EnsureJournalDirectory();
83
84 already_AddRefed<FileInfo> GetFileInfo(int64_t aId);
85
86 already_AddRefed<FileInfo> GetNewFileInfo();
87
88 static already_AddRefed<nsIFile> GetFileForId(nsIFile* aDirectory,
89 int64_t aId);
90
91 static nsresult InitDirectory(nsIFile* aDirectory,
92 nsIFile* aDatabaseFile,
93 PersistenceType aPersistenceType,
94 const nsACString& aGroup,
95 const nsACString& aOrigin);
96
97 static nsresult GetUsage(nsIFile* aDirectory, uint64_t* aUsage);
98
99 private:
100 // Private destructor, to discourage deletion outside of Release():
101 ~FileManager()
102 {
103 }
104
105 PersistenceType mPersistenceType;
106 nsCString mGroup;
107 nsCString mOrigin;
108 StoragePrivilege mPrivilege;
109 nsString mDatabaseName;
110
111 nsString mDirectoryPath;
112 nsString mJournalDirectoryPath;
113
114 int64_t mLastFileId;
115
116 // Protected by IndexedDatabaseManager::FileMutex()
117 nsDataHashtable<nsUint64HashKey, FileInfo*> mFileInfos;
118
119 bool mInvalidated;
120 };
121
122 END_INDEXEDDB_NAMESPACE
123
124 #endif // mozilla_dom_indexeddb_filemanager_h__

mercurial