1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/indexedDB/FileInfo.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,118 @@ 1.4 +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* vim: set ts=2 et sw=2 tw=80: */ 1.6 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.9 + 1.10 +#ifndef mozilla_dom_indexeddb_fileinfo_h__ 1.11 +#define mozilla_dom_indexeddb_fileinfo_h__ 1.12 + 1.13 +#include "IndexedDatabase.h" 1.14 + 1.15 +#include "FileManager.h" 1.16 +#include "IndexedDatabaseManager.h" 1.17 + 1.18 +BEGIN_INDEXEDDB_NAMESPACE 1.19 + 1.20 +class FileInfo 1.21 +{ 1.22 + friend class FileManager; 1.23 + 1.24 +public: 1.25 + FileInfo(FileManager* aFileManager) 1.26 + : mFileManager(aFileManager) 1.27 + { } 1.28 + 1.29 + virtual ~FileInfo() 1.30 + { } 1.31 + 1.32 + static 1.33 + FileInfo* Create(FileManager* aFileManager, int64_t aId); 1.34 + 1.35 + void AddRef() 1.36 + { 1.37 + if (IndexedDatabaseManager::IsClosed()) { 1.38 + ++mRefCnt; 1.39 + } 1.40 + else { 1.41 + UpdateReferences(mRefCnt, 1); 1.42 + } 1.43 + } 1.44 + 1.45 + void Release() 1.46 + { 1.47 + if (IndexedDatabaseManager::IsClosed()) { 1.48 + nsrefcnt count = --mRefCnt; 1.49 + if (count == 0) { 1.50 + mRefCnt = 1; 1.51 + delete this; 1.52 + } 1.53 + } 1.54 + else { 1.55 + UpdateReferences(mRefCnt, -1); 1.56 + } 1.57 + } 1.58 + 1.59 + void UpdateDBRefs(int32_t aDelta) 1.60 + { 1.61 + UpdateReferences(mDBRefCnt, aDelta); 1.62 + } 1.63 + 1.64 + void ClearDBRefs() 1.65 + { 1.66 + UpdateReferences(mDBRefCnt, 0, true); 1.67 + } 1.68 + 1.69 + void UpdateSliceRefs(int32_t aDelta) 1.70 + { 1.71 + UpdateReferences(mSliceRefCnt, aDelta); 1.72 + } 1.73 + 1.74 + void GetReferences(int32_t* aRefCnt, int32_t* aDBRefCnt, 1.75 + int32_t* aSliceRefCnt); 1.76 + 1.77 + FileManager* Manager() const 1.78 + { 1.79 + return mFileManager; 1.80 + } 1.81 + 1.82 + virtual int64_t Id() const = 0; 1.83 + 1.84 +private: 1.85 + void UpdateReferences(ThreadSafeAutoRefCnt& aRefCount, int32_t aDelta, 1.86 + bool aClear = false); 1.87 + void Cleanup(); 1.88 + 1.89 + ThreadSafeAutoRefCnt mRefCnt; 1.90 + ThreadSafeAutoRefCnt mDBRefCnt; 1.91 + ThreadSafeAutoRefCnt mSliceRefCnt; 1.92 + 1.93 + nsRefPtr<FileManager> mFileManager; 1.94 +}; 1.95 + 1.96 +#define FILEINFO_SUBCLASS(_bits) \ 1.97 +class FileInfo##_bits : public FileInfo \ 1.98 +{ \ 1.99 +public: \ 1.100 + FileInfo##_bits(FileManager* aFileManager, int##_bits##_t aId) \ 1.101 + : FileInfo(aFileManager), mId(aId) \ 1.102 + { } \ 1.103 + \ 1.104 + virtual int64_t Id() const \ 1.105 + { \ 1.106 + return mId; \ 1.107 + } \ 1.108 + \ 1.109 +private: \ 1.110 + int##_bits##_t mId; \ 1.111 +}; 1.112 + 1.113 +FILEINFO_SUBCLASS(16) 1.114 +FILEINFO_SUBCLASS(32) 1.115 +FILEINFO_SUBCLASS(64) 1.116 + 1.117 +#undef FILEINFO_SUBCLASS 1.118 + 1.119 +END_INDEXEDDB_NAMESPACE 1.120 + 1.121 +#endif // mozilla_dom_indexeddb_fileinfo_h__