LCOV - code coverage report
Current view: top level - dom/indexedDB - IndexedDatabaseManager.h (source / functions) Hit Total Coverage
Test: output.info Lines: 0 4 0.0 %
Date: 2017-07-14 16:53:18 Functions: 0 1 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
       2             : /* vim: set ts=8 sts=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/. */
       6             : 
       7             : #ifndef mozilla_dom_indexeddatabasemanager_h__
       8             : #define mozilla_dom_indexeddatabasemanager_h__
       9             : 
      10             : #include "nsIObserver.h"
      11             : 
      12             : #include "js/TypeDecls.h"
      13             : #include "mozilla/Atomics.h"
      14             : #include "mozilla/dom/quota/PersistenceType.h"
      15             : #include "mozilla/Mutex.h"
      16             : #include "nsClassHashtable.h"
      17             : #include "nsCOMPtr.h"
      18             : #include "nsHashKeys.h"
      19             : #include "nsITimer.h"
      20             : 
      21             : class nsIEventTarget;
      22             : 
      23             : namespace mozilla {
      24             : 
      25             : class EventChainPostVisitor;
      26             : 
      27             : namespace dom {
      28             : 
      29             : class IDBFactory;
      30             : 
      31             : namespace quota {
      32             : 
      33             : class QuotaManager;
      34             : 
      35             : } // namespace quota
      36             : 
      37             : namespace indexedDB {
      38             : 
      39             : class BackgroundUtilsChild;
      40             : class FileManager;
      41             : class FileManagerInfo;
      42             : 
      43             : } // namespace indexedDB
      44             : 
      45             : class IndexedDatabaseManager final
      46             :   : public nsIObserver
      47             :   , public nsITimerCallback
      48             : {
      49             :   typedef mozilla::dom::quota::PersistenceType PersistenceType;
      50             :   typedef mozilla::dom::quota::QuotaManager QuotaManager;
      51             :   typedef mozilla::dom::indexedDB::FileManager FileManager;
      52             :   typedef mozilla::dom::indexedDB::FileManagerInfo FileManagerInfo;
      53             : 
      54             : public:
      55             :   enum LoggingMode
      56             :   {
      57             :     Logging_Disabled = 0,
      58             :     Logging_Concise,
      59             :     Logging_Detailed,
      60             :     Logging_ConciseProfilerMarks,
      61             :     Logging_DetailedProfilerMarks
      62             :   };
      63             : 
      64             :   NS_DECL_ISUPPORTS
      65             :   NS_DECL_NSIOBSERVER
      66             :   NS_DECL_NSITIMERCALLBACK
      67             : 
      68             :   // Returns a non-owning reference.
      69             :   static IndexedDatabaseManager*
      70             :   GetOrCreate();
      71             : 
      72             :   // Returns a non-owning reference.
      73             :   static IndexedDatabaseManager*
      74             :   Get();
      75             : 
      76             :   static bool
      77             :   IsClosed();
      78             : 
      79             :   static bool
      80             :   IsMainProcess()
      81             : #ifdef DEBUG
      82             :   ;
      83             : #else
      84             :   {
      85             :     return sIsMainProcess;
      86             :   }
      87             : #endif
      88             : 
      89             :   static bool
      90             :   InLowDiskSpaceMode()
      91             : #ifdef DEBUG
      92             :   ;
      93             : #else
      94             :   {
      95             :     return !!sLowDiskSpaceMode;
      96             :   }
      97             : #endif
      98             : 
      99             :   static bool
     100             :   InTestingMode();
     101             : 
     102             :   static bool
     103             :   FullSynchronous();
     104             : 
     105             :   static LoggingMode
     106             :   GetLoggingMode()
     107             : #ifdef DEBUG
     108             :   ;
     109             : #else
     110             :   {
     111             :     return sLoggingMode;
     112             :   }
     113             : #endif
     114             : 
     115             :   static mozilla::LogModule*
     116             :   GetLoggingModule()
     117             : #ifdef DEBUG
     118             :   ;
     119             : #else
     120             :   {
     121             :     return sLoggingModule;
     122             :   }
     123             : #endif
     124             : 
     125             :   static bool
     126             :   ExperimentalFeaturesEnabled();
     127             : 
     128             :   static bool
     129             :   ExperimentalFeaturesEnabled(JSContext* aCx, JSObject* aGlobal);
     130             : 
     131             :   static bool
     132             :   IsFileHandleEnabled();
     133             : 
     134             :   static uint32_t
     135             :   DataThreshold();
     136             : 
     137             :   static uint32_t
     138             :   MaxSerializedMsgSize();
     139             : 
     140             :   void
     141             :   ClearBackgroundActor();
     142             : 
     143             :   void
     144             :   NoteLiveQuotaManager(QuotaManager* aQuotaManager);
     145             : 
     146             :   void
     147             :   NoteShuttingDownQuotaManager();
     148             : 
     149             :   already_AddRefed<FileManager>
     150             :   GetFileManager(PersistenceType aPersistenceType,
     151             :                  const nsACString& aOrigin,
     152             :                  const nsAString& aDatabaseName);
     153             : 
     154             :   void
     155             :   AddFileManager(FileManager* aFileManager);
     156             : 
     157             :   void
     158             :   InvalidateAllFileManagers();
     159             : 
     160             :   void
     161             :   InvalidateFileManagers(PersistenceType aPersistenceType,
     162             :                          const nsACString& aOrigin);
     163             : 
     164             :   void
     165             :   InvalidateFileManager(PersistenceType aPersistenceType,
     166             :                         const nsACString& aOrigin,
     167             :                         const nsAString& aDatabaseName);
     168             : 
     169             :   nsresult
     170             :   AsyncDeleteFile(FileManager* aFileManager,
     171             :                   int64_t aFileId);
     172             : 
     173             :   // Don't call this method in real code, it blocks the main thread!
     174             :   // It is intended to be used by mochitests to test correctness of the special
     175             :   // reference counting of stored blobs/files.
     176             :   nsresult
     177             :   BlockAndGetFileReferences(PersistenceType aPersistenceType,
     178             :                             const nsACString& aOrigin,
     179             :                             const nsAString& aDatabaseName,
     180             :                             int64_t aFileId,
     181             :                             int32_t* aRefCnt,
     182             :                             int32_t* aDBRefCnt,
     183             :                             int32_t* aSliceRefCnt,
     184             :                             bool* aResult);
     185             : 
     186             :   nsresult
     187             :   FlushPendingFileDeletions();
     188             : 
     189             : #ifdef ENABLE_INTL_API
     190             :   static const nsCString&
     191             :   GetLocale();
     192             : #endif
     193             : 
     194             :   static mozilla::Mutex&
     195           0 :   FileMutex()
     196             :   {
     197           0 :     IndexedDatabaseManager* mgr = Get();
     198           0 :     NS_ASSERTION(mgr, "Must have a manager here!");
     199             : 
     200           0 :     return mgr->mFileMutex;
     201             :   }
     202             : 
     203             :   static nsresult
     204             :   CommonPostHandleEvent(EventChainPostVisitor& aVisitor, IDBFactory* aFactory);
     205             : 
     206             :   static bool
     207             :   ResolveSandboxBinding(JSContext* aCx);
     208             : 
     209             :   static bool
     210             :   DefineIndexedDB(JSContext* aCx, JS::Handle<JSObject*> aGlobal);
     211             : 
     212             : private:
     213             :   IndexedDatabaseManager();
     214             :   ~IndexedDatabaseManager();
     215             : 
     216             :   nsresult
     217             :   Init();
     218             : 
     219             :   void
     220             :   Destroy();
     221             : 
     222             :   static void
     223             :   LoggingModePrefChangedCallback(const char* aPrefName, void* aClosure);
     224             : 
     225             :   nsCOMPtr<nsIEventTarget> mBackgroundThread;
     226             : 
     227             :   nsCOMPtr<nsITimer> mDeleteTimer;
     228             : 
     229             :   // Maintains a list of all file managers per origin. This list isn't
     230             :   // protected by any mutex but it is only ever touched on the IO thread.
     231             :   nsClassHashtable<nsCStringHashKey, FileManagerInfo> mFileManagerInfos;
     232             : 
     233             :   nsClassHashtable<nsRefPtrHashKey<FileManager>,
     234             :                    nsTArray<int64_t>> mPendingDeleteInfos;
     235             : 
     236             :   // Lock protecting FileManager.mFileInfos.
     237             :   // It's s also used to atomically update FileInfo.mRefCnt, FileInfo.mDBRefCnt
     238             :   // and FileInfo.mSliceRefCnt
     239             :   mozilla::Mutex mFileMutex;
     240             : 
     241             : #ifdef ENABLE_INTL_API
     242             :   nsCString mLocale;
     243             : #endif
     244             : 
     245             :   indexedDB::BackgroundUtilsChild* mBackgroundActor;
     246             : 
     247             :   static bool sIsMainProcess;
     248             :   static bool sFullSynchronousMode;
     249             :   static LazyLogModule sLoggingModule;
     250             :   static Atomic<LoggingMode> sLoggingMode;
     251             :   static mozilla::Atomic<bool> sLowDiskSpaceMode;
     252             : };
     253             : 
     254             : } // namespace dom
     255             : } // namespace mozilla
     256             : 
     257             : #endif // mozilla_dom_indexeddatabasemanager_h__

Generated by: LCOV version 1.13