Bumping manifests a=b2g-bump
[gecko.git] / dom / indexedDB / FileInfo.h
blob9272bd16d7c1a66da4421f5436636f7acffdf4e7
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/. */
7 #ifndef mozilla_dom_indexeddb_fileinfo_h__
8 #define mozilla_dom_indexeddb_fileinfo_h__
10 #include "IndexedDatabase.h"
12 #include "FileManager.h"
13 #include "IndexedDatabaseManager.h"
15 BEGIN_INDEXEDDB_NAMESPACE
17 class FileInfo
19 friend class FileManager;
21 public:
22 explicit FileInfo(FileManager* aFileManager)
23 : mFileManager(aFileManager)
24 { }
26 virtual ~FileInfo()
27 { }
29 static
30 FileInfo* Create(FileManager* aFileManager, int64_t aId);
32 void AddRef()
34 if (IndexedDatabaseManager::IsClosed()) {
35 ++mRefCnt;
37 else {
38 UpdateReferences(mRefCnt, 1);
42 void Release()
44 if (IndexedDatabaseManager::IsClosed()) {
45 nsrefcnt count = --mRefCnt;
46 if (count == 0) {
47 mRefCnt = 1;
48 delete this;
51 else {
52 UpdateReferences(mRefCnt, -1);
56 void UpdateDBRefs(int32_t aDelta)
58 UpdateReferences(mDBRefCnt, aDelta);
61 void ClearDBRefs()
63 UpdateReferences(mDBRefCnt, 0, true);
66 void UpdateSliceRefs(int32_t aDelta)
68 UpdateReferences(mSliceRefCnt, aDelta);
71 void GetReferences(int32_t* aRefCnt, int32_t* aDBRefCnt,
72 int32_t* aSliceRefCnt);
74 FileManager* Manager() const
76 return mFileManager;
79 virtual int64_t Id() const = 0;
81 private:
82 void UpdateReferences(ThreadSafeAutoRefCnt& aRefCount, int32_t aDelta,
83 bool aClear = false);
84 void Cleanup();
86 ThreadSafeAutoRefCnt mRefCnt;
87 ThreadSafeAutoRefCnt mDBRefCnt;
88 ThreadSafeAutoRefCnt mSliceRefCnt;
90 nsRefPtr<FileManager> mFileManager;
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 { } \
101 virtual int64_t Id() const \
103 return mId; \
106 private: \
107 int##_bits##_t mId; \
110 FILEINFO_SUBCLASS(16)
111 FILEINFO_SUBCLASS(32)
112 FILEINFO_SUBCLASS(64)
114 #undef FILEINFO_SUBCLASS
116 END_INDEXEDDB_NAMESPACE
118 #endif // mozilla_dom_indexeddb_fileinfo_h__