Source code

Revision control

Other Tools

1
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2
/* vim: set ts=8 sts=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 "mozilla/Attributes.h"
11
#include "mozilla/dom/quota/PersistenceType.h"
12
#include "nsDataHashtable.h"
13
#include "nsHashKeys.h"
14
#include "nsISupportsImpl.h"
15
16
class nsIFile;
17
class mozIStorageConnection;
18
19
namespace mozilla {
20
namespace dom {
21
namespace indexedDB {
22
23
class FileInfo;
24
25
// Implemented in ActorsParent.cpp.
26
class FileManager final {
27
friend class FileInfo;
28
29
typedef mozilla::dom::quota::PersistenceType PersistenceType;
30
31
PersistenceType mPersistenceType;
32
nsCString mGroup;
33
nsCString mOrigin;
34
nsString mDatabaseName;
35
36
nsString mDirectoryPath;
37
nsString mJournalDirectoryPath;
38
39
int64_t mLastFileId;
40
41
// Protected by IndexedDatabaseManager::FileMutex()
42
nsDataHashtable<nsUint64HashKey, FileInfo*> mFileInfos;
43
44
const bool mEnforcingQuota;
45
bool mInvalidated;
46
47
public:
48
static already_AddRefed<nsIFile> GetFileForId(nsIFile* aDirectory,
49
int64_t aId);
50
51
static already_AddRefed<nsIFile> GetCheckedFileForId(nsIFile* aDirectory,
52
int64_t aId);
53
54
static nsresult InitDirectory(nsIFile* aDirectory, nsIFile* aDatabaseFile,
55
const nsACString& aOrigin,
56
uint32_t aTelemetryId);
57
58
static nsresult GetUsage(nsIFile* aDirectory, Maybe<uint64_t>& aUsage);
59
60
static nsresult GetUsage(nsIFile* aDirectory, uint64_t& aUsage);
61
62
FileManager(PersistenceType aPersistenceType, const nsACString& aGroup,
63
const nsACString& aOrigin, const nsAString& aDatabaseName,
64
bool aEnforcingQuota);
65
66
PersistenceType Type() const { return mPersistenceType; }
67
68
const nsACString& Group() const { return mGroup; }
69
70
const nsACString& Origin() const { return mOrigin; }
71
72
const nsAString& DatabaseName() const { return mDatabaseName; }
73
74
bool EnforcingQuota() const { return mEnforcingQuota; }
75
76
bool Invalidated() const { return mInvalidated; }
77
78
nsresult Init(nsIFile* aDirectory, mozIStorageConnection* aConnection);
79
80
nsresult Invalidate();
81
82
already_AddRefed<nsIFile> GetDirectory();
83
84
already_AddRefed<nsIFile> GetCheckedDirectory();
85
86
already_AddRefed<nsIFile> GetJournalDirectory();
87
88
already_AddRefed<nsIFile> EnsureJournalDirectory();
89
90
already_AddRefed<FileInfo> GetFileInfo(int64_t aId) const;
91
92
already_AddRefed<FileInfo> GetNewFileInfo();
93
94
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(FileManager)
95
96
private:
97
~FileManager() = default;
98
};
99
100
} // namespace indexedDB
101
} // namespace dom
102
} // namespace mozilla
103
104
#endif // mozilla_dom_indexeddb_filemanager_h__