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"
|
|
|
|
|
2011-12-03 09:10:21 -08:00
|
|
|
#include "mozilla/Mutex.h"
|
|
|
|
|
2010-09-10 12:12:11 -07:00
|
|
|
#include "nsIIndexedDatabaseManager.h"
|
|
|
|
#include "nsIObserver.h"
|
2010-10-19 10:58:33 -07:00
|
|
|
#include "nsIRunnable.h"
|
|
|
|
#include "nsIThread.h"
|
|
|
|
#include "nsIURI.h"
|
2010-09-10 12:12:11 -07:00
|
|
|
|
|
|
|
#include "nsClassHashtable.h"
|
2011-12-03 09:10:21 -08:00
|
|
|
#include "nsRefPtrHashtable.h"
|
2010-09-10 12:12:11 -07:00
|
|
|
#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
|
|
|
|
2011-08-26 01:21:35 -07:00
|
|
|
class mozIStorageQuotaCallback;
|
2012-06-19 18:50:39 -07:00
|
|
|
class nsIAtom;
|
2012-04-30 16:52:27 -07:00
|
|
|
class nsIFile;
|
2010-10-19 10:58:33 -07:00
|
|
|
class nsITimer;
|
2012-06-19 18:50:39 -07:00
|
|
|
class nsPIDOMWindow;
|
2012-06-29 09:48:34 -07:00
|
|
|
class nsEventChainPostVisitor;
|
2010-09-10 12:12:11 -07:00
|
|
|
|
|
|
|
BEGIN_INDEXEDDB_NAMESPACE
|
|
|
|
|
2010-10-19 10:58:52 -07:00
|
|
|
class AsyncConnectionHelper;
|
2011-12-03 09:10:21 -08:00
|
|
|
class CheckQuotaHelper;
|
2012-06-19 18:50:39 -07:00
|
|
|
class FileManager;
|
|
|
|
class IDBDatabase;
|
2011-12-03 09:10:21 -08:00
|
|
|
|
2012-05-14 21:50:29 -07:00
|
|
|
class IndexedDatabaseManager MOZ_FINAL : public nsIIndexedDatabaseManager,
|
|
|
|
public nsIObserver
|
2010-09-10 12:12:11 -07:00
|
|
|
{
|
|
|
|
friend class IDBDatabase;
|
|
|
|
|
|
|
|
public:
|
2010-10-19 10:58:33 -07:00
|
|
|
static already_AddRefed<IndexedDatabaseManager> GetOrCreate();
|
2010-09-10 12:12:11 -07:00
|
|
|
|
|
|
|
// Returns a non-owning reference.
|
2010-10-19 10:58:33 -07:00
|
|
|
static IndexedDatabaseManager* Get();
|
|
|
|
|
|
|
|
// Returns an owning reference! No one should call this but the factory.
|
|
|
|
static IndexedDatabaseManager* FactoryCreate();
|
2010-09-10 12:12:11 -07:00
|
|
|
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
NS_DECL_NSIINDEXEDDATABASEMANAGER
|
|
|
|
NS_DECL_NSIOBSERVER
|
|
|
|
|
2010-10-19 10:58:52 -07:00
|
|
|
// Waits for databases to be cleared and for version change transactions to
|
2011-11-02 05:53:12 -07:00
|
|
|
// complete before dispatching the given runnable.
|
|
|
|
nsresult WaitForOpenAllowed(const nsACString& aOrigin,
|
|
|
|
nsIAtom* aId,
|
2010-10-19 10:58:52 -07:00
|
|
|
nsIRunnable* aRunnable);
|
2010-09-10 12:12:11 -07:00
|
|
|
|
2011-11-02 05:53:12 -07:00
|
|
|
void AllowNextSynchronizedOp(const nsACString& aOrigin,
|
|
|
|
nsIAtom* aId);
|
|
|
|
|
2010-10-19 10:58:42 -07:00
|
|
|
nsIThread* IOThread()
|
|
|
|
{
|
|
|
|
NS_ASSERTION(mIOThread, "This should never be null!");
|
|
|
|
return mIOThread;
|
|
|
|
}
|
|
|
|
|
2010-10-19 10:58:52 -07:00
|
|
|
// Returns true if we've begun the shutdown process.
|
2010-10-19 10:58:42 -07:00
|
|
|
static bool IsShuttingDown();
|
|
|
|
|
2011-12-15 23:34:24 -08:00
|
|
|
static bool IsClosed();
|
|
|
|
|
2012-06-19 18:50:39 -07:00
|
|
|
typedef void
|
|
|
|
(*WaitingOnDatabasesCallback)(nsTArray<nsRefPtr<IDBDatabase> >&, void*);
|
2011-11-02 05:53:12 -07:00
|
|
|
|
|
|
|
// Acquire exclusive access to the database given (waits for all others to
|
|
|
|
// close). If databases need to close first, the callback will be invoked
|
|
|
|
// with an array of said databases.
|
|
|
|
nsresult AcquireExclusiveAccess(IDBDatabase* aDatabase,
|
2012-06-19 18:50:39 -07:00
|
|
|
const nsACString& aOrigin,
|
2011-11-02 05:53:12 -07:00
|
|
|
AsyncConnectionHelper* aHelper,
|
|
|
|
WaitingOnDatabasesCallback aCallback,
|
|
|
|
void* aClosure)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(aDatabase, "Need a DB here!");
|
2012-07-30 07:20:58 -07:00
|
|
|
return AcquireExclusiveAccess(aOrigin, aDatabase, aHelper, nullptr,
|
2011-11-02 05:53:12 -07:00
|
|
|
aCallback, aClosure);
|
|
|
|
}
|
2012-06-19 18:50:39 -07:00
|
|
|
|
|
|
|
nsresult AcquireExclusiveAccess(const nsACString& aOrigin,
|
|
|
|
nsIRunnable* aRunnable,
|
2011-11-02 05:53:12 -07:00
|
|
|
WaitingOnDatabasesCallback aCallback,
|
|
|
|
void* aClosure)
|
|
|
|
{
|
2012-07-30 07:20:58 -07:00
|
|
|
return AcquireExclusiveAccess(aOrigin, nullptr, nullptr, aRunnable, aCallback,
|
2011-11-02 05:53:12 -07:00
|
|
|
aClosure);
|
|
|
|
}
|
2010-10-19 10:58:52 -07:00
|
|
|
|
2011-01-27 13:47:36 -08:00
|
|
|
// Called when a window is being purged from the bfcache or the user leaves
|
|
|
|
// a page which isn't going into the bfcache. Forces any live database
|
|
|
|
// objects to close themselves and aborts any running transactions.
|
|
|
|
void AbortCloseDatabasesForWindow(nsPIDOMWindow* aWindow);
|
2010-10-19 10:58:52 -07:00
|
|
|
|
2011-01-27 13:47:36 -08:00
|
|
|
// Used to check if there are running transactions in a given window.
|
|
|
|
bool HasOpenTransactions(nsPIDOMWindow* aWindow);
|
|
|
|
|
2011-12-03 09:10:21 -08:00
|
|
|
// Set the Window that the current thread is doing operations for.
|
|
|
|
// The caller is responsible for ensuring that aWindow is held alive.
|
|
|
|
static inline void
|
|
|
|
SetCurrentWindow(nsPIDOMWindow* aWindow)
|
|
|
|
{
|
|
|
|
IndexedDatabaseManager* mgr = Get();
|
|
|
|
NS_ASSERTION(mgr, "Must have a manager here!");
|
|
|
|
|
|
|
|
return mgr->SetCurrentWindowInternal(aWindow);
|
|
|
|
}
|
2011-08-26 01:21:35 -07:00
|
|
|
|
|
|
|
static PRUint32
|
|
|
|
GetIndexedDBQuotaMB();
|
|
|
|
|
2011-12-15 23:34:24 -08:00
|
|
|
nsresult EnsureOriginIsInitialized(const nsACString& aOrigin,
|
2012-08-01 14:09:23 -07:00
|
|
|
FactoryPrivilege aPrivilege,
|
2011-12-15 23:34:24 -08:00
|
|
|
nsIFile** aDirectory);
|
2011-08-26 01:21:35 -07:00
|
|
|
|
2011-12-03 09:10:21 -08:00
|
|
|
// Determine if the quota is lifted for the Window the current thread is
|
|
|
|
// using.
|
|
|
|
static inline bool
|
|
|
|
QuotaIsLifted()
|
|
|
|
{
|
|
|
|
IndexedDatabaseManager* mgr = Get();
|
|
|
|
NS_ASSERTION(mgr, "Must have a manager here!");
|
|
|
|
|
|
|
|
return mgr->QuotaIsLiftedInternal();
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
CancelPromptsForWindow(nsPIDOMWindow* aWindow)
|
|
|
|
{
|
|
|
|
IndexedDatabaseManager* mgr = Get();
|
|
|
|
NS_ASSERTION(mgr, "Must have a manager here!");
|
|
|
|
|
|
|
|
mgr->CancelPromptsForWindowInternal(aWindow);
|
|
|
|
}
|
|
|
|
|
|
|
|
static nsresult
|
|
|
|
GetASCIIOriginFromWindow(nsPIDOMWindow* aWindow, nsCString& aASCIIOrigin);
|
|
|
|
|
2012-06-01 10:21:12 -07:00
|
|
|
static bool
|
|
|
|
IsMainProcess()
|
|
|
|
#ifdef DEBUG
|
|
|
|
;
|
|
|
|
#else
|
|
|
|
{
|
|
|
|
return sIsMainProcess;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2011-12-15 23:34:24 -08:00
|
|
|
already_AddRefed<FileManager>
|
|
|
|
GetOrCreateFileManager(const nsACString& aOrigin,
|
|
|
|
const nsAString& aDatabaseName);
|
|
|
|
|
2011-12-20 03:23:27 -08:00
|
|
|
already_AddRefed<FileManager>
|
|
|
|
GetFileManager(const nsACString& aOrigin,
|
|
|
|
const nsAString& aDatabaseName);
|
|
|
|
|
2011-12-15 23:34:24 -08:00
|
|
|
void InvalidateFileManagersForOrigin(const nsACString& aOrigin);
|
|
|
|
|
|
|
|
void InvalidateFileManager(const nsACString& aOrigin,
|
|
|
|
const nsAString& aDatabaseName);
|
|
|
|
|
|
|
|
nsresult AsyncDeleteFile(FileManager* aFileManager,
|
|
|
|
PRInt64 aFileId);
|
|
|
|
|
2012-04-30 16:52:27 -07:00
|
|
|
const nsString&
|
|
|
|
GetBaseDirectory() const
|
|
|
|
{
|
|
|
|
return mDatabaseBasePath;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
GetDirectoryForOrigin(const nsACString& aASCIIOrigin,
|
|
|
|
nsIFile** aDirectory) const;
|
|
|
|
|
2011-12-15 23:34:24 -08:00
|
|
|
static mozilla::Mutex& FileMutex()
|
|
|
|
{
|
|
|
|
IndexedDatabaseManager* mgr = Get();
|
|
|
|
NS_ASSERTION(mgr, "Must have a manager here!");
|
|
|
|
|
|
|
|
return mgr->mFileMutex;
|
|
|
|
}
|
|
|
|
|
2012-06-01 10:21:12 -07:00
|
|
|
static already_AddRefed<nsIAtom>
|
|
|
|
GetDatabaseId(const nsACString& aOrigin,
|
|
|
|
const nsAString& aName);
|
|
|
|
|
2012-06-29 09:48:34 -07:00
|
|
|
static nsresult
|
|
|
|
FireWindowOnError(nsPIDOMWindow* aOwner, nsEventChainPostVisitor& aVisitor);
|
2010-09-10 12:12:11 -07:00
|
|
|
private:
|
|
|
|
IndexedDatabaseManager();
|
|
|
|
~IndexedDatabaseManager();
|
|
|
|
|
2012-06-19 18:50:39 -07:00
|
|
|
nsresult AcquireExclusiveAccess(const nsACString& aOrigin,
|
2011-11-02 05:53:12 -07:00
|
|
|
IDBDatabase* aDatabase,
|
|
|
|
AsyncConnectionHelper* aHelper,
|
2012-06-19 18:50:39 -07:00
|
|
|
nsIRunnable* aRunnable,
|
2011-11-02 05:53:12 -07:00
|
|
|
WaitingOnDatabasesCallback aCallback,
|
|
|
|
void* aClosure);
|
|
|
|
|
2011-12-03 09:10:21 -08:00
|
|
|
void SetCurrentWindowInternal(nsPIDOMWindow* aWindow);
|
|
|
|
bool QuotaIsLiftedInternal();
|
|
|
|
void CancelPromptsForWindowInternal(nsPIDOMWindow* aWindow);
|
|
|
|
|
2010-10-19 10:58:52 -07:00
|
|
|
// Called when a database is created.
|
2010-09-10 12:12:11 -07:00
|
|
|
bool RegisterDatabase(IDBDatabase* aDatabase);
|
2010-10-19 10:58:52 -07:00
|
|
|
|
|
|
|
// Called when a database is being unlinked or destroyed.
|
2010-09-10 12:12:11 -07:00
|
|
|
void UnregisterDatabase(IDBDatabase* aDatabase);
|
|
|
|
|
2010-10-19 10:58:52 -07:00
|
|
|
// Called when a database has been closed.
|
|
|
|
void OnDatabaseClosed(IDBDatabase* aDatabase);
|
|
|
|
|
2010-10-19 10:58:33 -07:00
|
|
|
// Responsible for clearing the database files for a particular origin on the
|
2010-10-19 10:58:52 -07:00
|
|
|
// IO thread. Created when nsIIDBIndexedDatabaseManager::ClearDatabasesForURI
|
|
|
|
// is called. Runs three times, first on the main thread, next on the IO
|
|
|
|
// thread, and then finally again on the main thread. While on the IO thread
|
|
|
|
// the runnable will actually remove the origin's database files and the
|
|
|
|
// directory that contains them before dispatching itself back to the main
|
2011-11-02 05:53:12 -07:00
|
|
|
// thread. When back on the main thread the runnable will notify the
|
|
|
|
// IndexedDatabaseManager that the job has been completed.
|
2012-05-14 21:50:29 -07:00
|
|
|
class OriginClearRunnable MOZ_FINAL : public nsIRunnable
|
2010-09-10 12:12:11 -07:00
|
|
|
{
|
2012-06-19 18:50:39 -07:00
|
|
|
enum CallbackState {
|
|
|
|
// Not yet run.
|
|
|
|
Pending = 0,
|
|
|
|
|
|
|
|
// Running on the main thread in the callback for OpenAllowed.
|
|
|
|
OpenAllowed,
|
|
|
|
|
|
|
|
// Running on the IO thread.
|
|
|
|
IO,
|
|
|
|
|
|
|
|
// Running on the main thread after all work is done.
|
|
|
|
Complete
|
|
|
|
};
|
|
|
|
|
2010-10-19 10:58:33 -07:00
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
NS_DECL_NSIRUNNABLE
|
|
|
|
|
2012-06-19 18:50:39 -07:00
|
|
|
OriginClearRunnable(const nsACString& aOrigin)
|
2010-10-19 10:58:33 -07:00
|
|
|
: mOrigin(aOrigin),
|
2012-06-19 18:50:39 -07:00
|
|
|
mCallbackState(Pending)
|
2010-10-19 10:58:52 -07:00
|
|
|
{ }
|
2010-10-19 10:58:33 -07:00
|
|
|
|
2012-06-19 18:50:39 -07:00
|
|
|
void AdvanceState()
|
|
|
|
{
|
|
|
|
switch (mCallbackState) {
|
|
|
|
case Pending:
|
|
|
|
mCallbackState = OpenAllowed;
|
|
|
|
return;
|
|
|
|
case OpenAllowed:
|
|
|
|
mCallbackState = IO;
|
|
|
|
return;
|
|
|
|
case IO:
|
|
|
|
mCallbackState = Complete;
|
|
|
|
return;
|
|
|
|
default:
|
|
|
|
NS_NOTREACHED("Can't advance past Complete!");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void InvalidateOpenedDatabases(
|
|
|
|
nsTArray<nsRefPtr<IDBDatabase> >& aDatabases,
|
|
|
|
void* aClosure);
|
|
|
|
|
|
|
|
private:
|
2010-10-19 10:58:33 -07:00
|
|
|
nsCString mOrigin;
|
2012-06-19 18:50:39 -07:00
|
|
|
CallbackState mCallbackState;
|
2010-09-10 12:12:11 -07:00
|
|
|
};
|
|
|
|
|
2010-10-19 10:58:33 -07:00
|
|
|
// Responsible for calculating the amount of space taken up by databases of a
|
2010-10-19 10:58:52 -07:00
|
|
|
// certain origin. Created when nsIIDBIndexedDatabaseManager::GetUsageForURI
|
|
|
|
// is called. May be canceled with
|
|
|
|
// nsIIDBIndexedDatabaseManager::CancelGetUsageForURI. Runs twice, first on
|
|
|
|
// the IO thread, then again on the main thread. While on the IO thread the
|
|
|
|
// runnable will calculate the size of all files in the origin's directory
|
|
|
|
// before dispatching itself back to the main thread. When on the main thread
|
|
|
|
// the runnable will call the callback and then notify the
|
|
|
|
// IndexedDatabaseManager that the job has been completed.
|
2012-05-14 21:50:29 -07:00
|
|
|
class AsyncUsageRunnable MOZ_FINAL : public nsIRunnable
|
2010-10-19 10:58:33 -07:00
|
|
|
{
|
2012-06-22 11:47:05 -07:00
|
|
|
enum CallbackState {
|
|
|
|
// Not yet run.
|
|
|
|
Pending = 0,
|
|
|
|
|
|
|
|
// Running on the main thread in the callback for OpenAllowed.
|
|
|
|
OpenAllowed,
|
|
|
|
|
|
|
|
// Running on the IO thread.
|
|
|
|
IO,
|
|
|
|
|
|
|
|
// Running on the main thread after all work is done.
|
|
|
|
Complete,
|
|
|
|
|
|
|
|
// Running on the main thread after skipping the work
|
|
|
|
Shortcut
|
|
|
|
};
|
2010-10-19 10:58:33 -07:00
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
NS_DECL_NSIRUNNABLE
|
|
|
|
|
|
|
|
AsyncUsageRunnable(nsIURI* aURI,
|
|
|
|
const nsACString& aOrigin,
|
|
|
|
nsIIndexedDatabaseUsageCallback* aCallback);
|
|
|
|
|
2010-10-19 10:58:52 -07:00
|
|
|
// Sets the canceled flag so that the callback is never called.
|
2010-10-19 10:58:33 -07:00
|
|
|
void Cancel();
|
|
|
|
|
2012-06-22 11:47:05 -07:00
|
|
|
void AdvanceState()
|
|
|
|
{
|
|
|
|
switch (mCallbackState) {
|
|
|
|
case Pending:
|
|
|
|
mCallbackState = OpenAllowed;
|
|
|
|
return;
|
|
|
|
case OpenAllowed:
|
|
|
|
mCallbackState = IO;
|
|
|
|
return;
|
|
|
|
case IO:
|
|
|
|
mCallbackState = Complete;
|
|
|
|
return;
|
|
|
|
default:
|
|
|
|
NS_NOTREACHED("Can't advance past Complete!");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult TakeShortcut();
|
|
|
|
|
2010-10-19 10:58:52 -07:00
|
|
|
// Run calls the RunInternal method and makes sure that we always dispatch
|
|
|
|
// to the main thread in case of an error.
|
2010-10-19 10:58:33 -07:00
|
|
|
inline nsresult RunInternal();
|
|
|
|
|
2011-12-15 23:34:24 -08:00
|
|
|
nsresult GetUsageForDirectory(nsIFile* aDirectory,
|
|
|
|
PRUint64* aUsage);
|
|
|
|
|
2010-10-19 10:58:33 -07:00
|
|
|
nsCOMPtr<nsIURI> mURI;
|
|
|
|
nsCString mOrigin;
|
2012-06-22 11:47:05 -07:00
|
|
|
|
2010-10-19 10:58:33 -07:00
|
|
|
nsCOMPtr<nsIIndexedDatabaseUsageCallback> mCallback;
|
|
|
|
PRUint64 mUsage;
|
2011-12-15 23:34:24 -08:00
|
|
|
PRUint64 mFileUsage;
|
2010-10-19 10:58:33 -07:00
|
|
|
PRInt32 mCanceled;
|
2012-06-22 11:47:05 -07:00
|
|
|
CallbackState mCallbackState;
|
2010-10-19 10:58:33 -07:00
|
|
|
};
|
|
|
|
|
2010-10-19 10:58:52 -07:00
|
|
|
// Called when AsyncUsageRunnable has finished its Run() method.
|
2010-10-19 10:58:33 -07:00
|
|
|
inline void OnUsageCheckComplete(AsyncUsageRunnable* aRunnable);
|
|
|
|
|
2011-11-02 05:53:12 -07:00
|
|
|
// A struct that contains the information corresponding to a pending or
|
|
|
|
// running operation that requires synchronization (e.g. opening a db,
|
|
|
|
// clearing dbs for an origin, etc).
|
|
|
|
struct SynchronizedOp
|
2010-10-19 10:58:52 -07:00
|
|
|
{
|
2011-11-02 05:53:12 -07:00
|
|
|
SynchronizedOp(const nsACString& aOrigin, nsIAtom* aId);
|
|
|
|
~SynchronizedOp();
|
2010-10-19 10:58:52 -07:00
|
|
|
|
2011-11-02 05:53:12 -07:00
|
|
|
// Test whether the second SynchronizedOp needs to get behind this one.
|
|
|
|
bool MustWaitFor(const SynchronizedOp& aRhs) const;
|
2010-10-19 10:58:52 -07:00
|
|
|
|
2011-11-02 05:53:12 -07:00
|
|
|
void DelayRunnable(nsIRunnable* aRunnable);
|
|
|
|
void DispatchDelayedRunnables();
|
|
|
|
|
|
|
|
const nsCString mOrigin;
|
|
|
|
nsCOMPtr<nsIAtom> mId;
|
2010-10-19 10:58:52 -07:00
|
|
|
nsRefPtr<AsyncConnectionHelper> mHelper;
|
2012-06-19 18:50:39 -07:00
|
|
|
nsCOMPtr<nsIRunnable> mRunnable;
|
2010-10-19 10:58:52 -07:00
|
|
|
nsTArray<nsCOMPtr<nsIRunnable> > mDelayedRunnables;
|
2012-08-10 09:15:02 -07:00
|
|
|
nsTArray<IDBDatabase*> mDatabases;
|
2010-10-19 10:58:52 -07:00
|
|
|
};
|
|
|
|
|
2011-10-25 05:49:31 -07:00
|
|
|
// A callback runnable used by the TransactionPool when it's safe to proceed
|
|
|
|
// with a SetVersion/DeleteDatabase/etc.
|
2012-05-14 21:50:29 -07:00
|
|
|
class WaitForTransactionsToFinishRunnable MOZ_FINAL : public nsIRunnable
|
2011-10-25 05:49:31 -07:00
|
|
|
{
|
|
|
|
public:
|
2012-06-03 09:33:52 -07:00
|
|
|
WaitForTransactionsToFinishRunnable(SynchronizedOp* aOp,
|
|
|
|
PRUint32 aCountdown)
|
|
|
|
: mOp(aOp), mCountdown(aCountdown)
|
2011-10-25 05:49:31 -07:00
|
|
|
{
|
2011-11-02 05:53:12 -07:00
|
|
|
NS_ASSERTION(mOp, "Why don't we have a runnable?");
|
|
|
|
NS_ASSERTION(mOp->mDatabases.IsEmpty(), "We're here too early!");
|
2012-06-19 18:50:39 -07:00
|
|
|
NS_ASSERTION(mOp->mHelper || mOp->mRunnable,
|
|
|
|
"What are we supposed to do when we're done?");
|
2012-06-03 09:33:52 -07:00
|
|
|
NS_ASSERTION(mCountdown, "Wrong countdown!");
|
2011-10-25 05:49:31 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
NS_DECL_NSIRUNNABLE
|
|
|
|
|
|
|
|
private:
|
2011-11-02 05:53:12 -07:00
|
|
|
// The IndexedDatabaseManager holds this alive.
|
|
|
|
SynchronizedOp* mOp;
|
2012-06-03 09:33:52 -07:00
|
|
|
PRUint32 mCountdown;
|
|
|
|
};
|
|
|
|
|
|
|
|
class WaitForLockedFilesToFinishRunnable MOZ_FINAL : public nsIRunnable
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
WaitForLockedFilesToFinishRunnable()
|
|
|
|
: mBusy(true)
|
|
|
|
{ }
|
|
|
|
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
NS_DECL_NSIRUNNABLE
|
|
|
|
|
|
|
|
bool IsBusy() const
|
|
|
|
{
|
|
|
|
return mBusy;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
bool mBusy;
|
2011-10-25 05:49:31 -07:00
|
|
|
};
|
|
|
|
|
2012-05-14 21:50:29 -07:00
|
|
|
class AsyncDeleteFileRunnable MOZ_FINAL : public nsIRunnable
|
2011-12-15 23:34:24 -08:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
NS_DECL_NSIRUNNABLE
|
|
|
|
AsyncDeleteFileRunnable(const nsAString& aFilePath)
|
|
|
|
: mFilePath(aFilePath)
|
|
|
|
{ }
|
|
|
|
|
|
|
|
private:
|
|
|
|
nsString mFilePath;
|
|
|
|
};
|
|
|
|
|
2012-06-19 18:50:39 -07:00
|
|
|
static nsresult RunSynchronizedOp(IDBDatabase* aDatabase,
|
|
|
|
SynchronizedOp* aOp);
|
|
|
|
|
|
|
|
SynchronizedOp* FindSynchronizedOp(const nsACString& aOrigin,
|
|
|
|
nsIAtom* aId)
|
|
|
|
{
|
|
|
|
for (PRUint32 index = 0; index < mSynchronizedOps.Length(); index++) {
|
|
|
|
const nsAutoPtr<SynchronizedOp>& currentOp = mSynchronizedOps[index];
|
|
|
|
if (currentOp->mOrigin == aOrigin &&
|
|
|
|
(!currentOp->mId || currentOp->mId == aId)) {
|
|
|
|
return currentOp;
|
|
|
|
}
|
|
|
|
}
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2012-06-19 18:50:39 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
bool IsClearOriginPending(const nsACString& aOrigin)
|
|
|
|
{
|
2012-07-30 07:20:58 -07:00
|
|
|
return !!FindSynchronizedOp(aOrigin, nullptr);
|
2012-06-19 18:50:39 -07:00
|
|
|
}
|
2011-11-02 05:53:12 -07:00
|
|
|
|
2010-09-10 12:12:11 -07:00
|
|
|
// Maintains a list of live databases per origin.
|
|
|
|
nsClassHashtable<nsCStringHashKey, nsTArray<IDBDatabase*> > mLiveDatabases;
|
|
|
|
|
2011-12-03 09:10:21 -08:00
|
|
|
// TLS storage index for the current thread's window
|
|
|
|
PRUintn mCurrentWindowIndex;
|
|
|
|
|
|
|
|
// Lock protecting mQuotaHelperHash
|
|
|
|
mozilla::Mutex mQuotaHelperMutex;
|
|
|
|
|
|
|
|
// A map of Windows to the corresponding quota helper.
|
|
|
|
nsRefPtrHashtable<nsPtrHashKey<nsPIDOMWindow>, CheckQuotaHelper> mQuotaHelperHash;
|
|
|
|
|
2011-12-15 23:34:24 -08:00
|
|
|
// Maintains a list of all file managers per origin. The list is actually also
|
|
|
|
// a list of all origins that were successfully initialized. This list
|
|
|
|
// isn't protected by any mutex but it is only ever touched on the IO thread.
|
|
|
|
nsClassHashtable<nsCStringHashKey,
|
|
|
|
nsTArray<nsRefPtr<FileManager> > > mFileManagers;
|
|
|
|
|
2010-10-19 10:58:33 -07:00
|
|
|
// Maintains a list of origins that we're currently enumerating to gather
|
|
|
|
// usage statistics.
|
|
|
|
nsAutoTArray<nsRefPtr<AsyncUsageRunnable>, 1> mUsageRunnables;
|
|
|
|
|
2011-11-02 05:53:12 -07:00
|
|
|
// Maintains a list of synchronized operatons that are in progress or queued.
|
|
|
|
nsAutoTArray<nsAutoPtr<SynchronizedOp>, 5> mSynchronizedOps;
|
2010-10-19 10:58:52 -07:00
|
|
|
|
|
|
|
// Thread on which IO is performed.
|
2010-10-19 10:58:33 -07:00
|
|
|
nsCOMPtr<nsIThread> mIOThread;
|
2010-10-19 10:58:52 -07:00
|
|
|
|
|
|
|
// A timer that gets activated at shutdown to ensure we close all databases.
|
2010-10-19 10:58:33 -07:00
|
|
|
nsCOMPtr<nsITimer> mShutdownTimer;
|
2011-08-26 01:21:35 -07:00
|
|
|
|
|
|
|
// A single threadsafe instance of our quota callback. Created on the main
|
|
|
|
// thread during GetOrCreate().
|
|
|
|
nsCOMPtr<mozIStorageQuotaCallback> mQuotaCallbackSingleton;
|
|
|
|
|
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
|
|
|
|
|
|
|
nsString mDatabaseBasePath;
|
2012-06-01 10:21:12 -07:00
|
|
|
|
|
|
|
static bool sIsMainProcess;
|
2010-09-10 12:12:11 -07:00
|
|
|
};
|
|
|
|
|
2011-12-03 09:18:38 -08:00
|
|
|
class AutoEnterWindow
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
AutoEnterWindow(nsPIDOMWindow* aWindow)
|
|
|
|
{
|
|
|
|
IndexedDatabaseManager::SetCurrentWindow(aWindow);
|
|
|
|
}
|
|
|
|
|
|
|
|
~AutoEnterWindow()
|
|
|
|
{
|
2012-07-30 07:20:58 -07:00
|
|
|
IndexedDatabaseManager::SetCurrentWindow(nullptr);
|
2011-12-03 09:18:38 -08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2010-09-10 12:12:11 -07:00
|
|
|
END_INDEXEDDB_NAMESPACE
|
|
|
|
|
|
|
|
#endif /* mozilla_dom_indexeddb_indexeddatabasemanager_h__ */
|