2010-09-10 23:12:11 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2015-05-03 22:32:37 +03:00
|
|
|
/* vim: set ts=8 sts=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"
|
2015-06-30 15:59:27 +03:00
|
|
|
#include "nsCOMPtr.h"
|
2010-09-10 23:12:11 +04:00
|
|
|
#include "nsHashKeys.h"
|
2015-06-30 15:59:27 +03:00
|
|
|
#include "nsITimer.h"
|
2010-09-10 23:12:11 +04:00
|
|
|
|
2014-10-16 08:56:52 +04:00
|
|
|
struct PRLogModuleInfo;
|
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
|
|
|
|
|
|
|
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;
|
2014-12-17 09:26:15 +03:00
|
|
|
class IDBFactory;
|
2011-12-03 21:10:21 +04:00
|
|
|
|
2015-06-30 15:59:27 +03:00
|
|
|
class IndexedDatabaseManager final
|
|
|
|
: public nsIObserver
|
|
|
|
, public nsITimerCallback
|
2010-09-10 23:12:11 +04:00
|
|
|
{
|
2013-09-11 08:18:36 +04:00
|
|
|
typedef mozilla::dom::quota::PersistenceType PersistenceType;
|
|
|
|
|
2010-09-10 23:12:11 +04:00
|
|
|
public:
|
2014-10-16 08:56:52 +04:00
|
|
|
enum LoggingMode
|
|
|
|
{
|
|
|
|
Logging_Disabled = 0,
|
|
|
|
Logging_Concise,
|
|
|
|
Logging_Detailed,
|
|
|
|
Logging_ConciseProfilerMarks,
|
|
|
|
Logging_DetailedProfilerMarks
|
|
|
|
};
|
|
|
|
|
2010-09-10 23:12:11 +04:00
|
|
|
NS_DECL_ISUPPORTS
|
2013-05-11 01:22:01 +04:00
|
|
|
NS_DECL_NSIOBSERVER
|
2015-06-30 15:59:27 +03:00
|
|
|
NS_DECL_NSITIMERCALLBACK
|
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();
|
|
|
|
|
2014-10-16 08:56:52 +04:00
|
|
|
static LoggingMode
|
|
|
|
GetLoggingMode()
|
|
|
|
#ifdef DEBUG
|
|
|
|
;
|
|
|
|
#else
|
|
|
|
{
|
|
|
|
return sLoggingMode;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static PRLogModuleInfo*
|
|
|
|
GetLoggingModule()
|
|
|
|
#ifdef DEBUG
|
|
|
|
;
|
|
|
|
#else
|
|
|
|
{
|
|
|
|
return sLoggingModule;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2014-12-17 09:26:15 +03:00
|
|
|
static bool
|
2015-01-26 09:30:09 +03:00
|
|
|
ExperimentalFeaturesEnabled();
|
|
|
|
|
|
|
|
static bool
|
|
|
|
ExperimentalFeaturesEnabled(JSContext* /* aCx */, JSObject* /* aGlobal */)
|
|
|
|
{
|
|
|
|
return ExperimentalFeaturesEnabled();
|
|
|
|
}
|
2014-12-17 09:26:15 +03:00
|
|
|
|
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,
|
2014-11-28 11:44:12 +03:00
|
|
|
const nsACString& aOrigin);
|
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);
|
|
|
|
|
2015-06-30 15:59:27 +03:00
|
|
|
nsresult
|
|
|
|
FlushPendingFileDeletions();
|
|
|
|
|
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
|
2015-03-20 07:42:37 +03:00
|
|
|
CommonPostHandleEvent(EventChainPostVisitor& aVisitor, IDBFactory* aFactory);
|
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
|
|
|
|
2014-10-16 08:56:52 +04:00
|
|
|
static void
|
|
|
|
LoggingModePrefChangedCallback(const char* aPrefName, void* aClosure);
|
|
|
|
|
2015-06-30 15:59:27 +03:00
|
|
|
nsCOMPtr<nsITimer> mDeleteTimer;
|
|
|
|
|
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
|
|
|
|
2015-06-30 15:59:27 +03:00
|
|
|
nsClassHashtable<nsRefPtrHashKey<FileManager>,
|
|
|
|
nsTArray<int64_t>> mPendingDeleteInfos;
|
|
|
|
|
2015-05-12 15:11:03 +03:00
|
|
|
// Lock protecting FileManager.mFileInfos and BlobImplBase.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-10-16 08:56:52 +04:00
|
|
|
static PRLogModuleInfo* sLoggingModule;
|
|
|
|
static Atomic<LoggingMode> sLoggingMode;
|
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__
|