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_fileinfo_h__
8
#define mozilla_dom_indexeddb_fileinfo_h__
9
10
#include "nsISupportsImpl.h"
11
12
namespace mozilla {
13
namespace dom {
14
namespace indexedDB {
15
16
class FileManager;
17
18
class FileInfo {
19
friend class FileManager;
20
21
ThreadSafeAutoRefCnt mRefCnt;
22
ThreadSafeAutoRefCnt mDBRefCnt;
23
ThreadSafeAutoRefCnt mSliceRefCnt;
24
25
RefPtr<FileManager> mFileManager;
26
27
public:
28
class CustomCleanupCallback;
29
30
static FileInfo* Create(FileManager* aFileManager, int64_t aId);
31
32
explicit FileInfo(FileManager* aFileManager);
33
34
void AddRef() { UpdateReferences(mRefCnt, 1); }
35
36
void Release(CustomCleanupCallback* aCustomCleanupCallback = nullptr) {
37
UpdateReferences(mRefCnt, -1, aCustomCleanupCallback);
38
}
39
40
void UpdateDBRefs(int32_t aDelta) { UpdateReferences(mDBRefCnt, aDelta); }
41
42
void UpdateSliceRefs(int32_t aDelta) {
43
UpdateReferences(mSliceRefCnt, aDelta);
44
}
45
46
void GetReferences(int32_t* aRefCnt, int32_t* aDBRefCnt,
47
int32_t* aSliceRefCnt);
48
49
FileManager* Manager() const { return mFileManager; }
50
51
virtual int64_t Id() const = 0;
52
53
static already_AddRefed<nsIFile> GetFileForFileInfo(FileInfo* aFileInfo);
54
55
protected:
56
virtual ~FileInfo() = default;
57
58
private:
59
void UpdateReferences(
60
ThreadSafeAutoRefCnt& aRefCount, int32_t aDelta,
61
CustomCleanupCallback* aCustomCleanupCallback = nullptr);
62
63
bool LockedClearDBRefs();
64
65
void Cleanup();
66
};
67
68
class NS_NO_VTABLE FileInfo::CustomCleanupCallback {
69
public:
70
virtual nsresult Cleanup(FileManager* aFileManager, int64_t aId) = 0;
71
72
protected:
73
CustomCleanupCallback() = default;
74
};
75
76
} // namespace indexedDB
77
} // namespace dom
78
} // namespace mozilla
79
80
#endif // mozilla_dom_indexeddb_fileinfo_h__