|
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_fileinfo_h__ |
|
8 #define mozilla_dom_indexeddb_fileinfo_h__ |
|
9 |
|
10 #include "IndexedDatabase.h" |
|
11 |
|
12 #include "FileManager.h" |
|
13 #include "IndexedDatabaseManager.h" |
|
14 |
|
15 BEGIN_INDEXEDDB_NAMESPACE |
|
16 |
|
17 class FileInfo |
|
18 { |
|
19 friend class FileManager; |
|
20 |
|
21 public: |
|
22 FileInfo(FileManager* aFileManager) |
|
23 : mFileManager(aFileManager) |
|
24 { } |
|
25 |
|
26 virtual ~FileInfo() |
|
27 { } |
|
28 |
|
29 static |
|
30 FileInfo* Create(FileManager* aFileManager, int64_t aId); |
|
31 |
|
32 void AddRef() |
|
33 { |
|
34 if (IndexedDatabaseManager::IsClosed()) { |
|
35 ++mRefCnt; |
|
36 } |
|
37 else { |
|
38 UpdateReferences(mRefCnt, 1); |
|
39 } |
|
40 } |
|
41 |
|
42 void Release() |
|
43 { |
|
44 if (IndexedDatabaseManager::IsClosed()) { |
|
45 nsrefcnt count = --mRefCnt; |
|
46 if (count == 0) { |
|
47 mRefCnt = 1; |
|
48 delete this; |
|
49 } |
|
50 } |
|
51 else { |
|
52 UpdateReferences(mRefCnt, -1); |
|
53 } |
|
54 } |
|
55 |
|
56 void UpdateDBRefs(int32_t aDelta) |
|
57 { |
|
58 UpdateReferences(mDBRefCnt, aDelta); |
|
59 } |
|
60 |
|
61 void ClearDBRefs() |
|
62 { |
|
63 UpdateReferences(mDBRefCnt, 0, true); |
|
64 } |
|
65 |
|
66 void UpdateSliceRefs(int32_t aDelta) |
|
67 { |
|
68 UpdateReferences(mSliceRefCnt, aDelta); |
|
69 } |
|
70 |
|
71 void GetReferences(int32_t* aRefCnt, int32_t* aDBRefCnt, |
|
72 int32_t* aSliceRefCnt); |
|
73 |
|
74 FileManager* Manager() const |
|
75 { |
|
76 return mFileManager; |
|
77 } |
|
78 |
|
79 virtual int64_t Id() const = 0; |
|
80 |
|
81 private: |
|
82 void UpdateReferences(ThreadSafeAutoRefCnt& aRefCount, int32_t aDelta, |
|
83 bool aClear = false); |
|
84 void Cleanup(); |
|
85 |
|
86 ThreadSafeAutoRefCnt mRefCnt; |
|
87 ThreadSafeAutoRefCnt mDBRefCnt; |
|
88 ThreadSafeAutoRefCnt mSliceRefCnt; |
|
89 |
|
90 nsRefPtr<FileManager> mFileManager; |
|
91 }; |
|
92 |
|
93 #define FILEINFO_SUBCLASS(_bits) \ |
|
94 class FileInfo##_bits : public FileInfo \ |
|
95 { \ |
|
96 public: \ |
|
97 FileInfo##_bits(FileManager* aFileManager, int##_bits##_t aId) \ |
|
98 : FileInfo(aFileManager), mId(aId) \ |
|
99 { } \ |
|
100 \ |
|
101 virtual int64_t Id() const \ |
|
102 { \ |
|
103 return mId; \ |
|
104 } \ |
|
105 \ |
|
106 private: \ |
|
107 int##_bits##_t mId; \ |
|
108 }; |
|
109 |
|
110 FILEINFO_SUBCLASS(16) |
|
111 FILEINFO_SUBCLASS(32) |
|
112 FILEINFO_SUBCLASS(64) |
|
113 |
|
114 #undef FILEINFO_SUBCLASS |
|
115 |
|
116 END_INDEXEDDB_NAMESPACE |
|
117 |
|
118 #endif // mozilla_dom_indexeddb_fileinfo_h__ |