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