dom/indexedDB/IndexedDatabaseManager.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/indexedDB/IndexedDatabaseManager.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,174 @@
     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_indexeddatabasemanager_h__
    1.11 +#define mozilla_dom_indexeddb_indexeddatabasemanager_h__
    1.12 +
    1.13 +#include "mozilla/dom/indexedDB/IndexedDatabase.h"
    1.14 +
    1.15 +#include "nsIIndexedDatabaseManager.h"
    1.16 +#include "nsIObserver.h"
    1.17 +
    1.18 +#include "js/TypeDecls.h"
    1.19 +#include "mozilla/Atomics.h"
    1.20 +#include "mozilla/dom/quota/PersistenceType.h"
    1.21 +#include "mozilla/Mutex.h"
    1.22 +#include "nsClassHashtable.h"
    1.23 +#include "nsHashKeys.h"
    1.24 +
    1.25 +#define INDEXEDDB_MANAGER_CONTRACTID "@mozilla.org/dom/indexeddb/manager;1"
    1.26 +
    1.27 +class nsPIDOMWindow;
    1.28 +
    1.29 +namespace mozilla {
    1.30 +class EventChainPostVisitor;
    1.31 +namespace dom {
    1.32 +class TabContext;
    1.33 +namespace quota {
    1.34 +class OriginOrPatternString;
    1.35 +}
    1.36 +}
    1.37 +}
    1.38 +
    1.39 +BEGIN_INDEXEDDB_NAMESPACE
    1.40 +
    1.41 +class FileManager;
    1.42 +class FileManagerInfo;
    1.43 +
    1.44 +class IndexedDatabaseManager MOZ_FINAL : public nsIIndexedDatabaseManager,
    1.45 +                                         public nsIObserver
    1.46 +{
    1.47 +  typedef mozilla::dom::quota::OriginOrPatternString OriginOrPatternString;
    1.48 +  typedef mozilla::dom::quota::PersistenceType PersistenceType;
    1.49 +
    1.50 +public:
    1.51 +  NS_DECL_ISUPPORTS
    1.52 +  NS_DECL_NSIINDEXEDDATABASEMANAGER
    1.53 +  NS_DECL_NSIOBSERVER
    1.54 +
    1.55 +  // Returns a non-owning reference.
    1.56 +  static IndexedDatabaseManager*
    1.57 +  GetOrCreate();
    1.58 +
    1.59 +  // Returns a non-owning reference.
    1.60 +  static IndexedDatabaseManager*
    1.61 +  Get();
    1.62 +
    1.63 +  // Returns an owning reference! No one should call this but the factory.
    1.64 +  static IndexedDatabaseManager*
    1.65 +  FactoryCreate();
    1.66 +
    1.67 +  static bool
    1.68 +  IsClosed();
    1.69 +
    1.70 +  static bool
    1.71 +  IsMainProcess()
    1.72 +#ifdef DEBUG
    1.73 +  ;
    1.74 +#else
    1.75 +  {
    1.76 +    return sIsMainProcess;
    1.77 +  }
    1.78 +#endif
    1.79 +
    1.80 +  static bool
    1.81 +  InLowDiskSpaceMode()
    1.82 +#ifdef DEBUG
    1.83 +  ;
    1.84 +#else
    1.85 +  {
    1.86 +    return !!sLowDiskSpaceMode;
    1.87 +  }
    1.88 +#endif
    1.89 +
    1.90 +  already_AddRefed<FileManager>
    1.91 +  GetFileManager(PersistenceType aPersistenceType,
    1.92 +                 const nsACString& aOrigin,
    1.93 +                 const nsAString& aDatabaseName);
    1.94 +
    1.95 +  void
    1.96 +  AddFileManager(FileManager* aFileManager);
    1.97 +
    1.98 +  void
    1.99 +  InvalidateAllFileManagers();
   1.100 +
   1.101 +  void
   1.102 +  InvalidateFileManagers(PersistenceType aPersistenceType,
   1.103 +                         const OriginOrPatternString& aOriginOrPattern);
   1.104 +
   1.105 +  void
   1.106 +  InvalidateFileManager(PersistenceType aPersistenceType,
   1.107 +                        const nsACString& aOrigin,
   1.108 +                        const nsAString& aDatabaseName);
   1.109 +
   1.110 +  nsresult
   1.111 +  AsyncDeleteFile(FileManager* aFileManager,
   1.112 +                  int64_t aFileId);
   1.113 +
   1.114 +  // Don't call this method in real code, it blocks the main thread!
   1.115 +  // It is intended to be used by mochitests to test correctness of the special
   1.116 +  // reference counting of stored blobs/files.
   1.117 +  nsresult
   1.118 +  BlockAndGetFileReferences(PersistenceType aPersistenceType,
   1.119 +                            const nsACString& aOrigin,
   1.120 +                            const nsAString& aDatabaseName,
   1.121 +                            int64_t aFileId,
   1.122 +                            int32_t* aRefCnt,
   1.123 +                            int32_t* aDBRefCnt,
   1.124 +                            int32_t* aSliceRefCnt,
   1.125 +                            bool* aResult);
   1.126 +
   1.127 +  static mozilla::Mutex&
   1.128 +  FileMutex()
   1.129 +  {
   1.130 +    IndexedDatabaseManager* mgr = Get();
   1.131 +    NS_ASSERTION(mgr, "Must have a manager here!");
   1.132 +
   1.133 +    return mgr->mFileMutex;
   1.134 +  }
   1.135 +
   1.136 +  static nsresult
   1.137 +  FireWindowOnError(nsPIDOMWindow* aOwner,
   1.138 +                    EventChainPostVisitor& aVisitor);
   1.139 +
   1.140 +  static bool
   1.141 +  TabContextMayAccessOrigin(const mozilla::dom::TabContext& aContext,
   1.142 +                            const nsACString& aOrigin);
   1.143 +
   1.144 +  static bool
   1.145 +  DefineIndexedDB(JSContext* aCx, JS::Handle<JSObject*> aGlobal);
   1.146 +
   1.147 +private:
   1.148 +  IndexedDatabaseManager();
   1.149 +  ~IndexedDatabaseManager();
   1.150 +
   1.151 +  nsresult
   1.152 +  Init();
   1.153 +
   1.154 +  void
   1.155 +  Destroy();
   1.156 +
   1.157 +  static PLDHashOperator
   1.158 +  InvalidateAndRemoveFileManagers(const nsACString& aKey,
   1.159 +                                  nsAutoPtr<FileManagerInfo>& aValue,
   1.160 +                                  void* aUserArg);
   1.161 +
   1.162 +  // Maintains a list of all file managers per origin. This list isn't
   1.163 +  // protected by any mutex but it is only ever touched on the IO thread.
   1.164 +  nsClassHashtable<nsCStringHashKey, FileManagerInfo> mFileManagerInfos;
   1.165 +
   1.166 +  // Lock protecting FileManager.mFileInfos and nsDOMFileBase.mFileInfos
   1.167 +  // It's s also used to atomically update FileInfo.mRefCnt, FileInfo.mDBRefCnt
   1.168 +  // and FileInfo.mSliceRefCnt
   1.169 +  mozilla::Mutex mFileMutex;
   1.170 +
   1.171 +  static bool sIsMainProcess;
   1.172 +  static mozilla::Atomic<bool> sLowDiskSpaceMode;
   1.173 +};
   1.174 +
   1.175 +END_INDEXEDDB_NAMESPACE
   1.176 +
   1.177 +#endif /* mozilla_dom_indexeddb_indexeddatabasemanager_h__ */

mercurial