dom/indexedDB/FileInfo.h

Wed, 31 Dec 2014 06:55:50 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:55:50 +0100
changeset 2
7e26c7da4463
permissions
-rw-r--r--

Added tag UPSTREAM_283F7C6 for changeset ca08bd8f51b2

     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
    18 {
    19   friend class FileManager;
    21 public:
    22   FileInfo(FileManager* aFileManager)
    23   : mFileManager(aFileManager)
    24   { }
    26   virtual ~FileInfo()
    27   { }
    29   static
    30   FileInfo* Create(FileManager* aFileManager, int64_t aId);
    32   void AddRef()
    33   {
    34     if (IndexedDatabaseManager::IsClosed()) {
    35       ++mRefCnt;
    36     }
    37     else {
    38       UpdateReferences(mRefCnt, 1);
    39     }
    40   }
    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   }
    56   void UpdateDBRefs(int32_t aDelta)
    57   {
    58     UpdateReferences(mDBRefCnt, aDelta);
    59   }
    61   void ClearDBRefs()
    62   {
    63     UpdateReferences(mDBRefCnt, 0, true);
    64   }
    66   void UpdateSliceRefs(int32_t aDelta)
    67   {
    68     UpdateReferences(mSliceRefCnt, aDelta);
    69   }
    71   void GetReferences(int32_t* aRefCnt, int32_t* aDBRefCnt,
    72                      int32_t* aSliceRefCnt);
    74   FileManager* Manager() const
    75   {
    76     return mFileManager;
    77   }
    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;
    91 };
    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 };
   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__

mercurial