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
|
|
|
|
2016-02-17 00:46:08 +03:00
|
|
|
#ifndef mozilla_dom_indexeddatabasemanager_h__
|
|
|
|
#define mozilla_dom_indexeddatabasemanager_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"
|
2017-07-26 21:18:20 +03:00
|
|
|
#include "nsINamed.h"
|
2015-06-30 15:59:27 +03:00
|
|
|
#include "nsITimer.h"
|
2010-09-10 23:12:11 +04:00
|
|
|
|
2015-11-22 12:44:43 +03:00
|
|
|
class nsIEventTarget;
|
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
|
|
|
|
2016-02-17 00:46:08 +03:00
|
|
|
class IDBFactory;
|
|
|
|
|
2016-07-18 19:51:54 +03:00
|
|
|
namespace quota {
|
|
|
|
|
|
|
|
class QuotaManager;
|
|
|
|
|
|
|
|
} // namespace quota
|
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
namespace indexedDB {
|
2010-09-10 23:12:11 +04:00
|
|
|
|
2015-11-22 12:44:33 +03:00
|
|
|
class BackgroundUtilsChild;
|
2012-06-20 05:50:39 +04:00
|
|
|
class FileManager;
|
2013-09-11 08:18:36 +04:00
|
|
|
class FileManagerInfo;
|
2016-02-17 00:46:08 +03:00
|
|
|
|
|
|
|
} // namespace indexedDB
|
2011-12-03 21:10:21 +04:00
|
|
|
|
2015-06-30 15:59:27 +03:00
|
|
|
class IndexedDatabaseManager final
|
2018-09-13 09:40:51 +03:00
|
|
|
: public nsITimerCallback
|
2017-07-26 21:18:20 +03:00
|
|
|
, public nsINamed
|
2010-09-10 23:12:11 +04:00
|
|
|
{
|
2013-09-11 08:18:36 +04:00
|
|
|
typedef mozilla::dom::quota::PersistenceType PersistenceType;
|
2016-07-18 19:51:54 +03:00
|
|
|
typedef mozilla::dom::quota::QuotaManager QuotaManager;
|
2016-02-17 00:46:08 +03:00
|
|
|
typedef mozilla::dom::indexedDB::FileManager FileManager;
|
|
|
|
typedef mozilla::dom::indexedDB::FileManagerInfo FileManagerInfo;
|
2013-09-11 08:18:36 +04:00
|
|
|
|
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
|
2015-06-30 15:59:27 +03:00
|
|
|
NS_DECL_NSITIMERCALLBACK
|
2017-07-26 21:18:20 +03:00
|
|
|
NS_DECL_NSINAMED
|
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
|
|
|
|
|
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
|
|
|
|
|
2015-11-23 22:09:25 +03:00
|
|
|
static mozilla::LogModule*
|
2014-10-16 08:56:52 +04:00
|
|
|
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
|
2016-03-30 06:22:14 +03:00
|
|
|
ExperimentalFeaturesEnabled(JSContext* aCx, JSObject* aGlobal);
|
2014-12-17 09:26:15 +03:00
|
|
|
|
2015-09-09 14:15:05 +03:00
|
|
|
static bool
|
|
|
|
IsFileHandleEnabled();
|
|
|
|
|
2016-10-25 22:18:18 +03:00
|
|
|
static uint32_t
|
|
|
|
DataThreshold();
|
|
|
|
|
2016-10-17 06:45:03 +03:00
|
|
|
static uint32_t
|
|
|
|
MaxSerializedMsgSize();
|
|
|
|
|
2015-11-22 12:44:33 +03:00
|
|
|
void
|
|
|
|
ClearBackgroundActor();
|
|
|
|
|
2015-11-22 12:44:43 +03:00
|
|
|
void
|
2016-07-18 19:51:54 +03:00
|
|
|
NoteLiveQuotaManager(QuotaManager* aQuotaManager);
|
|
|
|
|
|
|
|
void
|
|
|
|
NoteShuttingDownQuotaManager();
|
2015-11-22 12:44:43 +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();
|
|
|
|
|
2014-08-05 00:59:57 +04:00
|
|
|
static const nsCString&
|
|
|
|
GetLocale();
|
|
|
|
|
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
|
|
|
|
2016-03-30 06:22:14 +03:00
|
|
|
static bool
|
2016-07-09 07:19:52 +03:00
|
|
|
ResolveSandboxBinding(JSContext* aCx);
|
2016-03-30 06:22:14 +03: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-11-22 12:44:43 +03:00
|
|
|
nsCOMPtr<nsIEventTarget> mBackgroundThread;
|
|
|
|
|
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-09-09 14:15:14 +03:00
|
|
|
// Lock protecting FileManager.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
|
|
|
|
2014-08-05 00:59:57 +04:00
|
|
|
nsCString mLocale;
|
|
|
|
|
2016-02-17 00:46:08 +03:00
|
|
|
indexedDB::BackgroundUtilsChild* mBackgroundActor;
|
2015-11-22 12:44:33 +03:00
|
|
|
|
2012-06-01 21:21:12 +04:00
|
|
|
static bool sIsMainProcess;
|
2014-10-30 23:18:33 +03:00
|
|
|
static bool sFullSynchronousMode;
|
2015-11-23 22:09:25 +03:00
|
|
|
static LazyLogModule sLoggingModule;
|
2014-10-16 08:56:52 +04:00
|
|
|
static Atomic<LoggingMode> sLoggingMode;
|
2010-09-10 23:12:11 +04:00
|
|
|
};
|
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
2010-09-10 23:12:11 +04:00
|
|
|
|
2016-02-17 00:46:08 +03:00
|
|
|
#endif // mozilla_dom_indexeddatabasemanager_h__
|