2010-06-23 23:46:08 +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-06-23 23:46:08 +04:00
|
|
|
|
|
|
|
#ifndef mozilla_dom_indexeddb_transactionthreadpool_h__
|
|
|
|
#define mozilla_dom_indexeddb_transactionthreadpool_h__
|
|
|
|
|
|
|
|
// Only meant to be included in IndexedDB source files, not exported.
|
|
|
|
#include "IndexedDatabase.h"
|
|
|
|
|
|
|
|
#include "nsIObserver.h"
|
2010-10-19 21:58:33 +04:00
|
|
|
#include "nsIRunnable.h"
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2011-11-18 19:21:04 +04:00
|
|
|
#include "mozilla/Monitor.h"
|
2010-06-23 23:46:08 +04:00
|
|
|
#include "nsClassHashtable.h"
|
|
|
|
#include "nsHashKeys.h"
|
|
|
|
#include "nsRefPtrHashtable.h"
|
|
|
|
|
2010-06-28 20:46:21 +04:00
|
|
|
#include "IDBTransaction.h"
|
2010-06-23 23:46:08 +04:00
|
|
|
|
|
|
|
class nsIThreadPool;
|
|
|
|
|
|
|
|
BEGIN_INDEXEDDB_NAMESPACE
|
|
|
|
|
|
|
|
class FinishTransactionRunnable;
|
|
|
|
class QueuedDispatchInfo;
|
|
|
|
|
2010-10-19 21:58:33 +04:00
|
|
|
class TransactionThreadPool
|
2010-06-23 23:46:08 +04:00
|
|
|
{
|
2010-10-19 21:58:33 +04:00
|
|
|
friend class nsAutoPtr<TransactionThreadPool>;
|
2010-06-23 23:46:08 +04:00
|
|
|
friend class FinishTransactionRunnable;
|
|
|
|
|
|
|
|
public:
|
|
|
|
// returns a non-owning ref!
|
|
|
|
static TransactionThreadPool* GetOrCreate();
|
2010-10-19 21:58:33 +04:00
|
|
|
|
|
|
|
// returns a non-owning ref!
|
2010-09-10 23:12:11 +04:00
|
|
|
static TransactionThreadPool* Get();
|
2010-10-19 21:58:33 +04:00
|
|
|
|
2010-06-23 23:46:08 +04:00
|
|
|
static void Shutdown();
|
|
|
|
|
2010-06-28 20:46:21 +04:00
|
|
|
nsresult Dispatch(IDBTransaction* aTransaction,
|
2010-06-23 23:46:08 +04:00
|
|
|
nsIRunnable* aRunnable,
|
|
|
|
bool aFinish,
|
|
|
|
nsIRunnable* aFinishRunnable);
|
|
|
|
|
2012-08-10 20:15:02 +04:00
|
|
|
bool WaitForAllDatabasesToComplete(nsTArray<IDBDatabase*>& aDatabases,
|
|
|
|
nsIRunnable* aCallback);
|
2010-09-10 23:12:11 +04:00
|
|
|
|
2011-01-28 00:47:36 +03:00
|
|
|
// Abort all transactions, unless they are already in the process of being
|
|
|
|
// committed, for aDatabase.
|
|
|
|
void AbortTransactionsForDatabase(IDBDatabase* aDatabase);
|
|
|
|
|
2011-12-16 11:34:24 +04:00
|
|
|
// Returns true if there are running or pending transactions for aDatabase.
|
2011-01-28 00:47:36 +03:00
|
|
|
bool HasTransactionsForDatabase(IDBDatabase* aDatabase);
|
|
|
|
|
2010-06-23 23:46:08 +04:00
|
|
|
protected:
|
2012-05-15 08:50:29 +04:00
|
|
|
class TransactionQueue MOZ_FINAL : public nsIRunnable
|
2010-06-23 23:46:08 +04:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
NS_DECL_NSIRUNNABLE
|
|
|
|
|
2010-06-28 20:46:21 +04:00
|
|
|
inline TransactionQueue(IDBTransaction* aTransaction,
|
2010-06-23 23:46:08 +04:00
|
|
|
nsIRunnable* aRunnable);
|
|
|
|
|
|
|
|
inline void Dispatch(nsIRunnable* aRunnable);
|
|
|
|
|
|
|
|
inline void Finish(nsIRunnable* aFinishRunnable);
|
|
|
|
|
|
|
|
private:
|
2011-11-18 19:21:04 +04:00
|
|
|
mozilla::Monitor mMonitor;
|
2010-06-28 20:46:21 +04:00
|
|
|
IDBTransaction* mTransaction;
|
2010-06-23 23:46:08 +04:00
|
|
|
nsAutoTArray<nsCOMPtr<nsIRunnable>, 10> mQueue;
|
|
|
|
nsCOMPtr<nsIRunnable> mFinishRunnable;
|
|
|
|
bool mShouldFinish;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct TransactionInfo
|
|
|
|
{
|
2010-06-28 20:46:21 +04:00
|
|
|
nsRefPtr<IDBTransaction> transaction;
|
2010-06-23 23:46:08 +04:00
|
|
|
nsRefPtr<TransactionQueue> queue;
|
2010-07-12 18:05:01 +04:00
|
|
|
nsTArray<nsString> objectStoreNames;
|
2010-06-23 23:46:08 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
struct DatabaseTransactionInfo
|
|
|
|
{
|
|
|
|
nsTArray<TransactionInfo> transactions;
|
2010-07-12 18:05:01 +04:00
|
|
|
nsTArray<nsString> storesReading;
|
|
|
|
nsTArray<nsString> storesWriting;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct QueuedDispatchInfo
|
|
|
|
{
|
|
|
|
QueuedDispatchInfo()
|
|
|
|
: finish(false)
|
|
|
|
{ }
|
|
|
|
|
|
|
|
nsRefPtr<IDBTransaction> transaction;
|
|
|
|
nsCOMPtr<nsIRunnable> runnable;
|
|
|
|
nsCOMPtr<nsIRunnable> finishRunnable;
|
|
|
|
bool finish;
|
2010-06-23 23:46:08 +04:00
|
|
|
};
|
|
|
|
|
2010-10-19 21:58:52 +04:00
|
|
|
struct DatabasesCompleteCallback
|
2010-10-19 21:58:33 +04:00
|
|
|
{
|
2012-08-10 20:15:02 +04:00
|
|
|
nsTArray<IDBDatabase*> mDatabases;
|
2010-10-19 21:58:52 +04:00
|
|
|
nsCOMPtr<nsIRunnable> mCallback;
|
2010-10-19 21:58:33 +04:00
|
|
|
};
|
|
|
|
|
2010-06-23 23:46:08 +04:00
|
|
|
TransactionThreadPool();
|
|
|
|
~TransactionThreadPool();
|
|
|
|
|
|
|
|
nsresult Init();
|
|
|
|
nsresult Cleanup();
|
|
|
|
|
2010-06-28 20:46:21 +04:00
|
|
|
void FinishTransaction(IDBTransaction* aTransaction);
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2010-07-12 18:05:01 +04:00
|
|
|
nsresult TransactionCanRun(IDBTransaction* aTransaction,
|
|
|
|
bool* aCanRun,
|
|
|
|
TransactionQueue** aExistingQueue);
|
|
|
|
|
|
|
|
nsresult Dispatch(const QueuedDispatchInfo& aInfo)
|
|
|
|
{
|
|
|
|
return Dispatch(aInfo.transaction, aInfo.runnable, aInfo.finish,
|
|
|
|
aInfo.finishRunnable);
|
|
|
|
}
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2012-06-03 20:33:52 +04:00
|
|
|
bool MaybeFireCallback(DatabasesCompleteCallback& aCallback);
|
2010-10-19 21:58:52 +04:00
|
|
|
|
2010-06-23 23:46:08 +04:00
|
|
|
nsCOMPtr<nsIThreadPool> mThreadPool;
|
|
|
|
|
2011-11-02 16:53:12 +04:00
|
|
|
nsClassHashtable<nsISupportsHashKey, DatabaseTransactionInfo>
|
2010-06-23 23:46:08 +04:00
|
|
|
mTransactionsInProgress;
|
|
|
|
|
|
|
|
nsTArray<QueuedDispatchInfo> mDelayedDispatchQueue;
|
2010-10-19 21:58:33 +04:00
|
|
|
|
2010-10-19 21:58:52 +04:00
|
|
|
nsTArray<DatabasesCompleteCallback> mCompleteCallbacks;
|
2010-06-23 23:46:08 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
END_INDEXEDDB_NAMESPACE
|
|
|
|
|
|
|
|
#endif // mozilla_dom_indexeddb_transactionthreadpool_h__
|