2010-09-10 12:12:11 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=2 et sw=2 tw=80: */
|
2012-05-21 04:12:37 -07:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2010-09-10 12:12:11 -07:00
|
|
|
|
|
|
|
#ifndef mozilla_dom_indexeddb_indexeddatabasemanager_h__
|
|
|
|
#define mozilla_dom_indexeddb_indexeddatabasemanager_h__
|
|
|
|
|
|
|
|
#include "mozilla/dom/indexedDB/IndexedDatabase.h"
|
|
|
|
|
|
|
|
#include "nsIIndexedDatabaseManager.h"
|
2013-05-10 14:22:01 -07:00
|
|
|
#include "nsIObserver.h"
|
2010-09-10 12:12:11 -07:00
|
|
|
|
2013-09-25 16:10:57 -07:00
|
|
|
#include "js/TypeDecls.h"
|
2013-08-12 02:51:49 -07:00
|
|
|
#include "mozilla/Atomics.h"
|
2013-09-10 21:18:36 -07:00
|
|
|
#include "mozilla/dom/quota/PersistenceType.h"
|
2013-03-26 04:13:17 -07:00
|
|
|
#include "mozilla/Mutex.h"
|
2010-09-10 12:12:11 -07:00
|
|
|
#include "nsClassHashtable.h"
|
|
|
|
#include "nsHashKeys.h"
|
|
|
|
|
2010-10-19 10:58:52 -07:00
|
|
|
#define INDEXEDDB_MANAGER_CONTRACTID "@mozilla.org/dom/indexeddb/manager;1"
|
2010-09-10 12:12:11 -07:00
|
|
|
|
2012-06-19 18:50:39 -07:00
|
|
|
class nsIAtom;
|
|
|
|
class nsPIDOMWindow;
|
2012-06-29 09:48:34 -07:00
|
|
|
class nsEventChainPostVisitor;
|
2010-09-10 12:12:11 -07:00
|
|
|
|
2012-11-10 10:32:37 -08:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
class TabContext;
|
2013-09-10 21:18:36 -07:00
|
|
|
namespace quota {
|
|
|
|
class OriginOrPatternString;
|
|
|
|
}
|
2012-11-10 10:32:37 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-09-10 12:12:11 -07:00
|
|
|
BEGIN_INDEXEDDB_NAMESPACE
|
|
|
|
|
2012-06-19 18:50:39 -07:00
|
|
|
class FileManager;
|
2013-09-10 21:18:36 -07:00
|
|
|
class FileManagerInfo;
|
2011-12-03 09:10:21 -08:00
|
|
|
|
2013-05-10 14:22:01 -07:00
|
|
|
class IndexedDatabaseManager MOZ_FINAL : public nsIIndexedDatabaseManager,
|
|
|
|
public nsIObserver
|
2010-09-10 12:12:11 -07:00
|
|
|
{
|
2013-09-10 21:18:36 -07:00
|
|
|
typedef mozilla::dom::quota::OriginOrPatternString OriginOrPatternString;
|
|
|
|
typedef mozilla::dom::quota::PersistenceType PersistenceType;
|
|
|
|
|
2010-09-10 12:12:11 -07:00
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
NS_DECL_NSIINDEXEDDATABASEMANAGER
|
2013-05-10 14:22:01 -07:00
|
|
|
NS_DECL_NSIOBSERVER
|
2010-10-19 10:58:42 -07:00
|
|
|
|
2013-03-26 04:13:17 -07:00
|
|
|
// Returns a non-owning reference.
|
|
|
|
static IndexedDatabaseManager*
|
|
|
|
GetOrCreate();
|
2011-08-26 01:21:35 -07:00
|
|
|
|
2013-03-26 04:13:17 -07:00
|
|
|
// Returns a non-owning reference.
|
|
|
|
static IndexedDatabaseManager*
|
|
|
|
Get();
|
2011-08-26 01:21:35 -07:00
|
|
|
|
2013-03-26 04:13:17 -07:00
|
|
|
// Returns an owning reference! No one should call this but the factory.
|
|
|
|
static IndexedDatabaseManager*
|
|
|
|
FactoryCreate();
|
2012-12-17 11:25:10 -08:00
|
|
|
|
2013-03-26 04:13:17 -07:00
|
|
|
static bool
|
|
|
|
IsClosed();
|
2011-12-03 09:10:21 -08:00
|
|
|
|
2012-06-01 10:21:12 -07:00
|
|
|
static bool
|
|
|
|
IsMainProcess()
|
|
|
|
#ifdef DEBUG
|
|
|
|
;
|
|
|
|
#else
|
|
|
|
{
|
|
|
|
return sIsMainProcess;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2013-05-10 14:22:01 -07:00
|
|
|
static bool
|
|
|
|
InLowDiskSpaceMode()
|
|
|
|
#ifdef DEBUG
|
|
|
|
;
|
|
|
|
#else
|
|
|
|
{
|
|
|
|
return !!sLowDiskSpaceMode;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2011-12-20 03:23:27 -08:00
|
|
|
already_AddRefed<FileManager>
|
2013-09-10 21:18:36 -07:00
|
|
|
GetFileManager(PersistenceType aPersistenceType,
|
|
|
|
const nsACString& aOrigin,
|
2011-12-20 03:23:27 -08:00
|
|
|
const nsAString& aDatabaseName);
|
|
|
|
|
2012-08-24 11:51:33 -07:00
|
|
|
void
|
2012-12-17 11:25:10 -08:00
|
|
|
AddFileManager(FileManager* aFileManager);
|
2012-08-24 11:51:33 -07:00
|
|
|
|
2013-03-26 04:13:17 -07:00
|
|
|
void
|
|
|
|
InvalidateAllFileManagers();
|
2011-12-15 23:34:24 -08:00
|
|
|
|
2013-03-26 04:13:17 -07:00
|
|
|
void
|
2013-09-10 21:18:36 -07:00
|
|
|
InvalidateFileManagers(PersistenceType aPersistenceType,
|
|
|
|
const OriginOrPatternString& aOriginOrPattern);
|
2011-12-15 23:34:24 -08:00
|
|
|
|
2013-03-26 04:13:17 -07:00
|
|
|
void
|
2013-09-10 21:18:36 -07:00
|
|
|
InvalidateFileManager(PersistenceType aPersistenceType,
|
|
|
|
const nsACString& aOrigin,
|
2013-03-26 04:13:17 -07:00
|
|
|
const nsAString& aDatabaseName);
|
2012-04-30 16:52:27 -07:00
|
|
|
|
|
|
|
nsresult
|
2013-03-26 04:13:17 -07:00
|
|
|
AsyncDeleteFile(FileManager* aFileManager,
|
|
|
|
int64_t aFileId);
|
2012-04-30 16:52:27 -07:00
|
|
|
|
2013-06-05 01:11:23 -07:00
|
|
|
// Don't call this method in real code, it blocks the main thread!
|
|
|
|
// It is intended to be used by mochitests to test correctness of the special
|
|
|
|
// reference counting of stored blobs/files.
|
|
|
|
nsresult
|
2013-09-10 21:18:36 -07:00
|
|
|
BlockAndGetFileReferences(PersistenceType aPersistenceType,
|
|
|
|
const nsACString& aOrigin,
|
2013-06-05 01:11:23 -07:00
|
|
|
const nsAString& aDatabaseName,
|
|
|
|
int64_t aFileId,
|
|
|
|
int32_t* aRefCnt,
|
|
|
|
int32_t* aDBRefCnt,
|
|
|
|
int32_t* aSliceRefCnt,
|
|
|
|
bool* aResult);
|
|
|
|
|
2013-03-26 04:13:17 -07:00
|
|
|
static mozilla::Mutex&
|
|
|
|
FileMutex()
|
2011-12-15 23:34:24 -08:00
|
|
|
{
|
|
|
|
IndexedDatabaseManager* mgr = Get();
|
|
|
|
NS_ASSERTION(mgr, "Must have a manager here!");
|
|
|
|
|
|
|
|
return mgr->mFileMutex;
|
|
|
|
}
|
|
|
|
|
2012-06-29 09:48:34 -07:00
|
|
|
static nsresult
|
2012-10-23 09:31:19 -07:00
|
|
|
FireWindowOnError(nsPIDOMWindow* aOwner,
|
|
|
|
nsEventChainPostVisitor& aVisitor);
|
|
|
|
|
|
|
|
static bool
|
2012-11-10 10:32:37 -08:00
|
|
|
TabContextMayAccessOrigin(const mozilla::dom::TabContext& aContext,
|
|
|
|
const nsACString& aOrigin);
|
2012-10-23 09:31:19 -07:00
|
|
|
|
2010-09-10 12:12:11 -07:00
|
|
|
private:
|
|
|
|
IndexedDatabaseManager();
|
|
|
|
~IndexedDatabaseManager();
|
|
|
|
|
2013-03-26 04:13:17 -07:00
|
|
|
nsresult
|
|
|
|
Init();
|
2011-11-02 05:53:12 -07:00
|
|
|
|
2013-03-26 04:13:17 -07:00
|
|
|
void
|
|
|
|
Destroy();
|
2010-09-10 12:12:11 -07:00
|
|
|
|
2013-09-10 21:18:36 -07:00
|
|
|
static PLDHashOperator
|
|
|
|
InvalidateAndRemoveFileManagers(const nsACString& aKey,
|
|
|
|
nsAutoPtr<FileManagerInfo>& aValue,
|
|
|
|
void* aUserArg);
|
|
|
|
|
2012-08-24 11:51:33 -07:00
|
|
|
// Maintains a list of all file managers per origin. This list isn't
|
|
|
|
// protected by any mutex but it is only ever touched on the IO thread.
|
2013-09-10 21:18:36 -07:00
|
|
|
nsClassHashtable<nsCStringHashKey, FileManagerInfo> mFileManagerInfos;
|
2011-12-15 23:34:24 -08:00
|
|
|
|
|
|
|
// Lock protecting FileManager.mFileInfos and nsDOMFileBase.mFileInfos
|
|
|
|
// It's s also used to atomically update FileInfo.mRefCnt, FileInfo.mDBRefCnt
|
|
|
|
// and FileInfo.mSliceRefCnt
|
|
|
|
mozilla::Mutex mFileMutex;
|
2012-04-30 16:52:27 -07:00
|
|
|
|
2012-06-01 10:21:12 -07:00
|
|
|
static bool sIsMainProcess;
|
2013-08-12 02:51:49 -07:00
|
|
|
static mozilla::Atomic<int32_t> sLowDiskSpaceMode;
|
2010-09-10 12:12:11 -07:00
|
|
|
};
|
|
|
|
|
2013-09-25 16:10:57 -07:00
|
|
|
bool
|
|
|
|
ResolveConstructors(JSContext* aCx, JS::HandleObject aObj, JS::HandleId aId,
|
|
|
|
JS::MutableHandleObject aObjp);
|
|
|
|
|
2010-09-10 12:12:11 -07:00
|
|
|
END_INDEXEDDB_NAMESPACE
|
|
|
|
|
|
|
|
#endif /* mozilla_dom_indexeddb_indexeddatabasemanager_h__ */
|