dom/indexedDB/IndexedDatabaseManager.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_indexeddatabasemanager_h__
     8 #define mozilla_dom_indexeddb_indexeddatabasemanager_h__
    10 #include "mozilla/dom/indexedDB/IndexedDatabase.h"
    12 #include "nsIIndexedDatabaseManager.h"
    13 #include "nsIObserver.h"
    15 #include "js/TypeDecls.h"
    16 #include "mozilla/Atomics.h"
    17 #include "mozilla/dom/quota/PersistenceType.h"
    18 #include "mozilla/Mutex.h"
    19 #include "nsClassHashtable.h"
    20 #include "nsHashKeys.h"
    22 #define INDEXEDDB_MANAGER_CONTRACTID "@mozilla.org/dom/indexeddb/manager;1"
    24 class nsPIDOMWindow;
    26 namespace mozilla {
    27 class EventChainPostVisitor;
    28 namespace dom {
    29 class TabContext;
    30 namespace quota {
    31 class OriginOrPatternString;
    32 }
    33 }
    34 }
    36 BEGIN_INDEXEDDB_NAMESPACE
    38 class FileManager;
    39 class FileManagerInfo;
    41 class IndexedDatabaseManager MOZ_FINAL : public nsIIndexedDatabaseManager,
    42                                          public nsIObserver
    43 {
    44   typedef mozilla::dom::quota::OriginOrPatternString OriginOrPatternString;
    45   typedef mozilla::dom::quota::PersistenceType PersistenceType;
    47 public:
    48   NS_DECL_ISUPPORTS
    49   NS_DECL_NSIINDEXEDDATABASEMANAGER
    50   NS_DECL_NSIOBSERVER
    52   // Returns a non-owning reference.
    53   static IndexedDatabaseManager*
    54   GetOrCreate();
    56   // Returns a non-owning reference.
    57   static IndexedDatabaseManager*
    58   Get();
    60   // Returns an owning reference! No one should call this but the factory.
    61   static IndexedDatabaseManager*
    62   FactoryCreate();
    64   static bool
    65   IsClosed();
    67   static bool
    68   IsMainProcess()
    69 #ifdef DEBUG
    70   ;
    71 #else
    72   {
    73     return sIsMainProcess;
    74   }
    75 #endif
    77   static bool
    78   InLowDiskSpaceMode()
    79 #ifdef DEBUG
    80   ;
    81 #else
    82   {
    83     return !!sLowDiskSpaceMode;
    84   }
    85 #endif
    87   already_AddRefed<FileManager>
    88   GetFileManager(PersistenceType aPersistenceType,
    89                  const nsACString& aOrigin,
    90                  const nsAString& aDatabaseName);
    92   void
    93   AddFileManager(FileManager* aFileManager);
    95   void
    96   InvalidateAllFileManagers();
    98   void
    99   InvalidateFileManagers(PersistenceType aPersistenceType,
   100                          const OriginOrPatternString& aOriginOrPattern);
   102   void
   103   InvalidateFileManager(PersistenceType aPersistenceType,
   104                         const nsACString& aOrigin,
   105                         const nsAString& aDatabaseName);
   107   nsresult
   108   AsyncDeleteFile(FileManager* aFileManager,
   109                   int64_t aFileId);
   111   // Don't call this method in real code, it blocks the main thread!
   112   // It is intended to be used by mochitests to test correctness of the special
   113   // reference counting of stored blobs/files.
   114   nsresult
   115   BlockAndGetFileReferences(PersistenceType aPersistenceType,
   116                             const nsACString& aOrigin,
   117                             const nsAString& aDatabaseName,
   118                             int64_t aFileId,
   119                             int32_t* aRefCnt,
   120                             int32_t* aDBRefCnt,
   121                             int32_t* aSliceRefCnt,
   122                             bool* aResult);
   124   static mozilla::Mutex&
   125   FileMutex()
   126   {
   127     IndexedDatabaseManager* mgr = Get();
   128     NS_ASSERTION(mgr, "Must have a manager here!");
   130     return mgr->mFileMutex;
   131   }
   133   static nsresult
   134   FireWindowOnError(nsPIDOMWindow* aOwner,
   135                     EventChainPostVisitor& aVisitor);
   137   static bool
   138   TabContextMayAccessOrigin(const mozilla::dom::TabContext& aContext,
   139                             const nsACString& aOrigin);
   141   static bool
   142   DefineIndexedDB(JSContext* aCx, JS::Handle<JSObject*> aGlobal);
   144 private:
   145   IndexedDatabaseManager();
   146   ~IndexedDatabaseManager();
   148   nsresult
   149   Init();
   151   void
   152   Destroy();
   154   static PLDHashOperator
   155   InvalidateAndRemoveFileManagers(const nsACString& aKey,
   156                                   nsAutoPtr<FileManagerInfo>& aValue,
   157                                   void* aUserArg);
   159   // Maintains a list of all file managers per origin. This list isn't
   160   // protected by any mutex but it is only ever touched on the IO thread.
   161   nsClassHashtable<nsCStringHashKey, FileManagerInfo> mFileManagerInfos;
   163   // Lock protecting FileManager.mFileInfos and nsDOMFileBase.mFileInfos
   164   // It's s also used to atomically update FileInfo.mRefCnt, FileInfo.mDBRefCnt
   165   // and FileInfo.mSliceRefCnt
   166   mozilla::Mutex mFileMutex;
   168   static bool sIsMainProcess;
   169   static mozilla::Atomic<bool> sLowDiskSpaceMode;
   170 };
   172 END_INDEXEDDB_NAMESPACE
   174 #endif /* mozilla_dom_indexeddb_indexeddatabasemanager_h__ */

mercurial