FileInfo.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /* This Source Code Form is subject to the terms of the Mozilla Public
  3. * License, v. 2.0. If a copy of the MPL was not distributed with this
  4. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  5. #ifndef mozilla_dom_indexeddb_fileinfo_h__
  6. #define mozilla_dom_indexeddb_fileinfo_h__
  7. #include "nsISupportsImpl.h"
  8. namespace mozilla {
  9. namespace dom {
  10. namespace indexedDB {
  11. class FileManager;
  12. class FileInfo
  13. {
  14. friend class FileManager;
  15. ThreadSafeAutoRefCnt mRefCnt;
  16. ThreadSafeAutoRefCnt mDBRefCnt;
  17. ThreadSafeAutoRefCnt mSliceRefCnt;
  18. RefPtr<FileManager> mFileManager;
  19. public:
  20. class CustomCleanupCallback;
  21. static
  22. FileInfo* Create(FileManager* aFileManager, int64_t aId);
  23. explicit FileInfo(FileManager* aFileManager);
  24. void
  25. AddRef()
  26. {
  27. UpdateReferences(mRefCnt, 1);
  28. }
  29. void
  30. Release(CustomCleanupCallback* aCustomCleanupCallback = nullptr)
  31. {
  32. UpdateReferences(mRefCnt, -1, aCustomCleanupCallback);
  33. }
  34. void
  35. UpdateDBRefs(int32_t aDelta)
  36. {
  37. UpdateReferences(mDBRefCnt, aDelta);
  38. }
  39. void
  40. UpdateSliceRefs(int32_t aDelta)
  41. {
  42. UpdateReferences(mSliceRefCnt, aDelta);
  43. }
  44. void
  45. GetReferences(int32_t* aRefCnt, int32_t* aDBRefCnt, int32_t* aSliceRefCnt);
  46. FileManager*
  47. Manager() const
  48. {
  49. return mFileManager;
  50. }
  51. virtual int64_t
  52. Id() const = 0;
  53. protected:
  54. virtual ~FileInfo();
  55. private:
  56. void
  57. UpdateReferences(ThreadSafeAutoRefCnt& aRefCount,
  58. int32_t aDelta,
  59. CustomCleanupCallback* aCustomCleanupCallback = nullptr);
  60. bool
  61. LockedClearDBRefs();
  62. void
  63. Cleanup();
  64. };
  65. class NS_NO_VTABLE FileInfo::CustomCleanupCallback
  66. {
  67. public:
  68. virtual nsresult
  69. Cleanup(FileManager* aFileManager, int64_t aId) = 0;
  70. protected:
  71. CustomCleanupCallback()
  72. { }
  73. };
  74. } // namespace indexedDB
  75. } // namespace dom
  76. } // namespace mozilla
  77. #endif // mozilla_dom_indexeddb_fileinfo_h__