2011-12-16 11:34:24 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=2 et sw=2 tw=80: */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2011-12-16 11:34:24 +04:00
|
|
|
|
|
|
|
#ifndef mozilla_dom_indexeddb_fileinfo_h__
|
|
|
|
#define mozilla_dom_indexeddb_fileinfo_h__
|
|
|
|
|
|
|
|
#include "IndexedDatabase.h"
|
2012-06-20 05:50:39 +04:00
|
|
|
|
2011-12-16 11:34:24 +04:00
|
|
|
#include "nsThreadUtils.h"
|
2012-06-20 05:50:39 +04:00
|
|
|
|
2011-12-16 11:34:24 +04:00
|
|
|
#include "FileManager.h"
|
|
|
|
#include "IndexedDatabaseManager.h"
|
|
|
|
|
|
|
|
BEGIN_INDEXEDDB_NAMESPACE
|
|
|
|
|
|
|
|
class FileInfo
|
|
|
|
{
|
|
|
|
friend class FileManager;
|
|
|
|
|
|
|
|
public:
|
|
|
|
FileInfo(FileManager* aFileManager)
|
|
|
|
: mFileManager(aFileManager)
|
|
|
|
{ }
|
|
|
|
|
|
|
|
virtual ~FileInfo()
|
2013-06-05 12:11:23 +04:00
|
|
|
{ }
|
2011-12-16 11:34:24 +04:00
|
|
|
|
|
|
|
static
|
2012-08-22 19:56:38 +04:00
|
|
|
FileInfo* Create(FileManager* aFileManager, int64_t aId);
|
2011-12-16 11:34:24 +04:00
|
|
|
|
|
|
|
void AddRef()
|
|
|
|
{
|
|
|
|
if (IndexedDatabaseManager::IsClosed()) {
|
2013-07-19 06:21:20 +04:00
|
|
|
++mRefCnt;
|
2011-12-16 11:34:24 +04:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
UpdateReferences(mRefCnt, 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Release()
|
|
|
|
{
|
|
|
|
if (IndexedDatabaseManager::IsClosed()) {
|
2013-07-19 06:21:20 +04:00
|
|
|
nsrefcnt count = --mRefCnt;
|
2011-12-16 11:34:24 +04:00
|
|
|
if (count == 0) {
|
|
|
|
mRefCnt = 1;
|
|
|
|
delete this;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
UpdateReferences(mRefCnt, -1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
void UpdateDBRefs(int32_t aDelta)
|
2011-12-16 11:34:24 +04:00
|
|
|
{
|
|
|
|
UpdateReferences(mDBRefCnt, aDelta);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ClearDBRefs()
|
|
|
|
{
|
|
|
|
UpdateReferences(mDBRefCnt, 0, true);
|
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
void UpdateSliceRefs(int32_t aDelta)
|
2011-12-16 11:34:24 +04:00
|
|
|
{
|
|
|
|
UpdateReferences(mSliceRefCnt, aDelta);
|
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
void GetReferences(int32_t* aRefCnt, int32_t* aDBRefCnt,
|
|
|
|
int32_t* aSliceRefCnt);
|
2011-12-16 11:34:24 +04:00
|
|
|
|
|
|
|
FileManager* Manager() const
|
|
|
|
{
|
|
|
|
return mFileManager;
|
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
virtual int64_t Id() const = 0;
|
2011-12-16 11:34:24 +04:00
|
|
|
|
|
|
|
private:
|
2013-07-19 06:21:20 +04:00
|
|
|
void UpdateReferences(ThreadSafeAutoRefCnt& aRefCount, int32_t aDelta,
|
2011-12-16 11:34:24 +04:00
|
|
|
bool aClear = false);
|
|
|
|
void Cleanup();
|
|
|
|
|
2013-07-19 06:21:20 +04:00
|
|
|
ThreadSafeAutoRefCnt mRefCnt;
|
|
|
|
ThreadSafeAutoRefCnt mDBRefCnt;
|
|
|
|
ThreadSafeAutoRefCnt mSliceRefCnt;
|
2011-12-16 11:34:24 +04:00
|
|
|
|
|
|
|
nsRefPtr<FileManager> mFileManager;
|
|
|
|
};
|
|
|
|
|
|
|
|
#define FILEINFO_SUBCLASS(_bits) \
|
|
|
|
class FileInfo##_bits : public FileInfo \
|
|
|
|
{ \
|
|
|
|
public: \
|
2012-08-22 19:59:54 +04:00
|
|
|
FileInfo##_bits(FileManager* aFileManager, int##_bits##_t aId) \
|
2011-12-16 11:34:24 +04:00
|
|
|
: FileInfo(aFileManager), mId(aId) \
|
|
|
|
{ } \
|
|
|
|
\
|
2012-08-22 19:56:38 +04:00
|
|
|
virtual int64_t Id() const \
|
2011-12-16 11:34:24 +04:00
|
|
|
{ \
|
|
|
|
return mId; \
|
|
|
|
} \
|
|
|
|
\
|
|
|
|
private: \
|
2012-08-22 19:59:54 +04:00
|
|
|
int##_bits##_t mId; \
|
2011-12-16 11:34:24 +04:00
|
|
|
};
|
|
|
|
|
2011-12-18 14:14:46 +04:00
|
|
|
FILEINFO_SUBCLASS(16)
|
|
|
|
FILEINFO_SUBCLASS(32)
|
|
|
|
FILEINFO_SUBCLASS(64)
|
2011-12-16 11:34:24 +04:00
|
|
|
|
|
|
|
#undef FILEINFO_SUBCLASS
|
|
|
|
|
|
|
|
END_INDEXEDDB_NAMESPACE
|
|
|
|
|
|
|
|
#endif // mozilla_dom_indexeddb_fileinfo_h__
|