2010-09-10 19:12:11 +00: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 11:12:37 +00: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 19:12:11 +00:00
|
|
|
|
|
|
|
#ifndef mozilla_dom_indexeddb_indexeddatabasemanager_h__
|
|
|
|
#define mozilla_dom_indexeddb_indexeddatabasemanager_h__
|
|
|
|
|
2013-05-10 21:22:01 +00:00
|
|
|
#include "nsIObserver.h"
|
2010-09-10 19:12:11 +00:00
|
|
|
|
2013-09-25 23:10:57 +00:00
|
|
|
#include "js/TypeDecls.h"
|
2013-08-12 09:51:49 +00:00
|
|
|
#include "mozilla/Atomics.h"
|
2013-09-11 04:18:36 +00:00
|
|
|
#include "mozilla/dom/quota/PersistenceType.h"
|
2013-03-26 11:13:17 +00:00
|
|
|
#include "mozilla/Mutex.h"
|
2010-09-10 19:12:11 +00:00
|
|
|
#include "nsClassHashtable.h"
|
|
|
|
#include "nsHashKeys.h"
|
|
|
|
|
2012-06-20 01:50:39 +00:00
|
|
|
class nsPIDOMWindow;
|
2010-09-10 19:12:11 +00:00
|
|
|
|
2012-11-10 18:32:37 +00:00
|
|
|
namespace mozilla {
|
2014-09-26 23:21:57 +00:00
|
|
|
|
2014-03-18 04:48:20 +00:00
|
|
|
class EventChainPostVisitor;
|
2014-09-26 23:21:57 +00:00
|
|
|
|
2012-11-10 18:32:37 +00:00
|
|
|
namespace dom {
|
2014-09-26 23:21:57 +00:00
|
|
|
|
2012-11-10 18:32:37 +00:00
|
|
|
class TabContext;
|
2014-09-26 23:21:57 +00:00
|
|
|
|
2013-09-11 04:18:36 +00:00
|
|
|
namespace quota {
|
2014-09-26 23:21:57 +00:00
|
|
|
|
2013-09-11 04:18:36 +00:00
|
|
|
class OriginOrPatternString;
|
2012-11-10 18:32:37 +00:00
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
} // namespace quota
|
|
|
|
|
|
|
|
namespace indexedDB {
|
2010-09-10 19:12:11 +00:00
|
|
|
|
2012-06-20 01:50:39 +00:00
|
|
|
class FileManager;
|
2013-09-11 04:18:36 +00:00
|
|
|
class FileManagerInfo;
|
2011-12-03 17:10:21 +00:00
|
|
|
|
2014-06-17 19:01:47 +00:00
|
|
|
class IndexedDatabaseManager MOZ_FINAL : public nsIObserver
|
2010-09-10 19:12:11 +00:00
|
|
|
{
|
2013-09-11 04:18:36 +00:00
|
|
|
typedef mozilla::dom::quota::OriginOrPatternString OriginOrPatternString;
|
|
|
|
typedef mozilla::dom::quota::PersistenceType PersistenceType;
|
|
|
|
|
2010-09-10 19:12:11 +00:00
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS
|
2013-05-10 21:22:01 +00:00
|
|
|
NS_DECL_NSIOBSERVER
|
2010-10-19 17:58:42 +00:00
|
|
|
|
2013-03-26 11:13:17 +00:00
|
|
|
// Returns a non-owning reference.
|
|
|
|
static IndexedDatabaseManager*
|
|
|
|
GetOrCreate();
|
2011-08-26 08:21:35 +00:00
|
|
|
|
2013-03-26 11:13:17 +00:00
|
|
|
// Returns a non-owning reference.
|
|
|
|
static IndexedDatabaseManager*
|
|
|
|
Get();
|
2011-08-26 08:21:35 +00:00
|
|
|
|
2013-03-26 11:13:17 +00:00
|
|
|
static bool
|
|
|
|
IsClosed();
|
2011-12-03 17:10:21 +00:00
|
|
|
|
2012-06-01 17:21:12 +00:00
|
|
|
static bool
|
|
|
|
IsMainProcess()
|
|
|
|
#ifdef DEBUG
|
|
|
|
;
|
|
|
|
#else
|
|
|
|
{
|
|
|
|
return sIsMainProcess;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2013-05-10 21:22:01 +00:00
|
|
|
static bool
|
|
|
|
InLowDiskSpaceMode()
|
|
|
|
#ifdef DEBUG
|
|
|
|
;
|
|
|
|
#else
|
|
|
|
{
|
|
|
|
return !!sLowDiskSpaceMode;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
static bool
|
|
|
|
InTestingMode();
|
|
|
|
|
2011-12-20 11:23:27 +00:00
|
|
|
already_AddRefed<FileManager>
|
2013-09-11 04:18:36 +00:00
|
|
|
GetFileManager(PersistenceType aPersistenceType,
|
|
|
|
const nsACString& aOrigin,
|
2011-12-20 11:23:27 +00:00
|
|
|
const nsAString& aDatabaseName);
|
|
|
|
|
2012-08-24 18:51:33 +00:00
|
|
|
void
|
2012-12-17 19:25:10 +00:00
|
|
|
AddFileManager(FileManager* aFileManager);
|
2012-08-24 18:51:33 +00:00
|
|
|
|
2013-03-26 11:13:17 +00:00
|
|
|
void
|
|
|
|
InvalidateAllFileManagers();
|
2011-12-16 07:34:24 +00:00
|
|
|
|
2013-03-26 11:13:17 +00:00
|
|
|
void
|
2013-09-11 04:18:36 +00:00
|
|
|
InvalidateFileManagers(PersistenceType aPersistenceType,
|
|
|
|
const OriginOrPatternString& aOriginOrPattern);
|
2011-12-16 07:34:24 +00:00
|
|
|
|
2013-03-26 11:13:17 +00:00
|
|
|
void
|
2013-09-11 04:18:36 +00:00
|
|
|
InvalidateFileManager(PersistenceType aPersistenceType,
|
|
|
|
const nsACString& aOrigin,
|
2013-03-26 11:13:17 +00:00
|
|
|
const nsAString& aDatabaseName);
|
2012-04-30 23:52:27 +00:00
|
|
|
|
|
|
|
nsresult
|
2013-03-26 11:13:17 +00:00
|
|
|
AsyncDeleteFile(FileManager* aFileManager,
|
|
|
|
int64_t aFileId);
|
2012-04-30 23:52:27 +00:00
|
|
|
|
2013-06-05 08:11:23 +00: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-11 04:18:36 +00:00
|
|
|
BlockAndGetFileReferences(PersistenceType aPersistenceType,
|
|
|
|
const nsACString& aOrigin,
|
2013-06-05 08:11:23 +00:00
|
|
|
const nsAString& aDatabaseName,
|
|
|
|
int64_t aFileId,
|
|
|
|
int32_t* aRefCnt,
|
|
|
|
int32_t* aDBRefCnt,
|
|
|
|
int32_t* aSliceRefCnt,
|
|
|
|
bool* aResult);
|
|
|
|
|
2013-03-26 11:13:17 +00:00
|
|
|
static mozilla::Mutex&
|
|
|
|
FileMutex()
|
2011-12-16 07:34:24 +00:00
|
|
|
{
|
|
|
|
IndexedDatabaseManager* mgr = Get();
|
|
|
|
NS_ASSERTION(mgr, "Must have a manager here!");
|
|
|
|
|
|
|
|
return mgr->mFileMutex;
|
|
|
|
}
|
|
|
|
|
2012-06-29 16:48:34 +00:00
|
|
|
static nsresult
|
2012-10-23 16:31:19 +00:00
|
|
|
FireWindowOnError(nsPIDOMWindow* aOwner,
|
2014-03-18 04:48:20 +00:00
|
|
|
EventChainPostVisitor& aVisitor);
|
2012-10-23 16:31:19 +00:00
|
|
|
|
|
|
|
static bool
|
2012-11-10 18:32:37 +00:00
|
|
|
TabContextMayAccessOrigin(const mozilla::dom::TabContext& aContext,
|
|
|
|
const nsACString& aOrigin);
|
2012-10-23 16:31:19 +00:00
|
|
|
|
2013-09-28 11:25:46 +00:00
|
|
|
static bool
|
2013-11-19 07:36:12 +00:00
|
|
|
DefineIndexedDB(JSContext* aCx, JS::Handle<JSObject*> aGlobal);
|
2013-09-28 11:25:46 +00:00
|
|
|
|
2010-09-10 19:12:11 +00:00
|
|
|
private:
|
|
|
|
IndexedDatabaseManager();
|
|
|
|
~IndexedDatabaseManager();
|
|
|
|
|
2013-03-26 11:13:17 +00:00
|
|
|
nsresult
|
|
|
|
Init();
|
2011-11-02 12:53:12 +00:00
|
|
|
|
2013-03-26 11:13:17 +00:00
|
|
|
void
|
|
|
|
Destroy();
|
2010-09-10 19:12:11 +00:00
|
|
|
|
2013-09-11 04:18:36 +00:00
|
|
|
static PLDHashOperator
|
|
|
|
InvalidateAndRemoveFileManagers(const nsACString& aKey,
|
|
|
|
nsAutoPtr<FileManagerInfo>& aValue,
|
|
|
|
void* aUserArg);
|
|
|
|
|
2012-08-24 18:51:33 +00: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-11 04:18:36 +00:00
|
|
|
nsClassHashtable<nsCStringHashKey, FileManagerInfo> mFileManagerInfos;
|
2011-12-16 07:34:24 +00: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 23:52:27 +00:00
|
|
|
|
2012-06-01 17:21:12 +00:00
|
|
|
static bool sIsMainProcess;
|
2014-02-07 06:17:07 +00:00
|
|
|
static mozilla::Atomic<bool> sLowDiskSpaceMode;
|
2010-09-10 19:12:11 +00:00
|
|
|
};
|
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
} // namespace indexedDB
|
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
2010-09-10 19:12:11 +00:00
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
#endif // mozilla_dom_indexeddb_indexeddatabasemanager_h__
|