2010-06-23 12:46:08 -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-06-23 12:46:08 -07:00
|
|
|
|
|
|
|
#ifndef mozilla_dom_indexeddb_transactionthreadpool_h__
|
|
|
|
#define mozilla_dom_indexeddb_transactionthreadpool_h__
|
|
|
|
|
2014-09-26 16:21:57 -07:00
|
|
|
#include "mozilla/Attributes.h"
|
|
|
|
#include "nsAutoPtr.h"
|
2010-06-23 12:46:08 -07:00
|
|
|
#include "nsClassHashtable.h"
|
2014-09-26 16:21:57 -07:00
|
|
|
#include "nsCOMPtr.h"
|
2010-06-23 12:46:08 -07:00
|
|
|
#include "nsHashKeys.h"
|
2014-09-26 16:21:57 -07:00
|
|
|
#include "nsISupportsImpl.h"
|
|
|
|
#include "nsTArray.h"
|
2010-06-23 12:46:08 -07:00
|
|
|
|
2014-09-26 16:21:57 -07:00
|
|
|
class nsIEventTarget;
|
|
|
|
class nsIRunnable;
|
2010-06-23 12:46:08 -07:00
|
|
|
class nsIThreadPool;
|
|
|
|
|
2014-09-26 16:21:57 -07:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
namespace indexedDB {
|
2010-06-23 12:46:08 -07:00
|
|
|
|
2014-09-26 16:21:57 -07:00
|
|
|
class TransactionThreadPool MOZ_FINAL
|
2010-06-23 12:46:08 -07:00
|
|
|
{
|
2014-09-26 16:21:57 -07:00
|
|
|
class FinishTransactionRunnable;
|
2010-06-23 12:46:08 -07:00
|
|
|
friend class FinishTransactionRunnable;
|
|
|
|
|
2014-09-26 16:21:57 -07:00
|
|
|
class TransactionQueue;
|
|
|
|
friend class TransactionQueue;
|
2010-10-19 10:58:33 -07:00
|
|
|
|
2014-09-26 16:21:57 -07:00
|
|
|
struct DatabaseTransactionInfo;
|
|
|
|
struct DatabasesCompleteCallback;
|
|
|
|
struct TransactionInfo;
|
|
|
|
struct TransactionInfoPair;
|
2010-10-19 10:58:33 -07:00
|
|
|
|
2014-09-26 16:21:57 -07:00
|
|
|
nsCOMPtr<nsIThreadPool> mThreadPool;
|
|
|
|
nsCOMPtr<nsIEventTarget> mOwningThread;
|
2010-06-23 12:46:08 -07:00
|
|
|
|
2014-09-26 16:21:57 -07:00
|
|
|
nsClassHashtable<nsCStringHashKey, DatabaseTransactionInfo>
|
|
|
|
mTransactionsInProgress;
|
2010-09-10 12:12:11 -07:00
|
|
|
|
2014-09-26 16:21:57 -07:00
|
|
|
nsTArray<nsAutoPtr<DatabasesCompleteCallback>> mCompleteCallbacks;
|
2011-01-27 13:47:36 -08:00
|
|
|
|
2014-09-26 16:21:57 -07:00
|
|
|
uint64_t mNextTransactionId;
|
|
|
|
bool mShutdownRequested;
|
|
|
|
bool mShutdownComplete;
|
2011-01-27 13:47:36 -08:00
|
|
|
|
2014-09-26 16:21:57 -07:00
|
|
|
public:
|
|
|
|
class FinishCallback;
|
2014-09-13 09:12:19 -07:00
|
|
|
|
2014-09-26 16:21:57 -07:00
|
|
|
static already_AddRefed<TransactionThreadPool> Create();
|
2010-06-23 12:46:08 -07:00
|
|
|
|
2014-09-26 16:21:57 -07:00
|
|
|
uint64_t NextTransactionId();
|
2010-06-23 12:46:08 -07:00
|
|
|
|
2014-09-26 16:21:57 -07:00
|
|
|
void Dispatch(uint64_t aTransactionId,
|
|
|
|
const nsACString& aDatabaseId,
|
|
|
|
const nsTArray<nsString>& aObjectStoreNames,
|
|
|
|
uint16_t aMode,
|
|
|
|
nsIRunnable* aRunnable,
|
|
|
|
bool aFinish,
|
|
|
|
FinishCallback* aFinishCallback);
|
2010-06-23 12:46:08 -07:00
|
|
|
|
2014-09-26 16:21:57 -07:00
|
|
|
void Dispatch(uint64_t aTransactionId,
|
|
|
|
const nsACString& aDatabaseId,
|
|
|
|
nsIRunnable* aRunnable,
|
|
|
|
bool aFinish,
|
|
|
|
FinishCallback* aFinishCallback);
|
2013-02-05 09:01:07 -08:00
|
|
|
|
2014-09-26 16:21:57 -07:00
|
|
|
void WaitForDatabasesToComplete(nsTArray<nsCString>& aDatabaseIds,
|
|
|
|
nsIRunnable* aCallback);
|
2010-06-23 12:46:08 -07:00
|
|
|
|
2014-09-26 16:21:57 -07:00
|
|
|
// Returns true if there are running or pending transactions for aDatabase.
|
|
|
|
bool HasTransactionsForDatabase(const nsACString& aDatabaseId);
|
2014-06-23 12:56:07 -07:00
|
|
|
|
2014-09-26 16:21:57 -07:00
|
|
|
NS_INLINE_DECL_REFCOUNTING(TransactionThreadPool)
|
2010-06-23 12:46:08 -07:00
|
|
|
|
2014-09-26 16:21:57 -07:00
|
|
|
void Shutdown();
|
2013-02-05 09:01:07 -08:00
|
|
|
|
2014-09-26 16:21:57 -07:00
|
|
|
void AssertIsOnOwningThread() const
|
|
|
|
#ifdef DEBUG
|
|
|
|
;
|
|
|
|
#else
|
|
|
|
{ }
|
|
|
|
#endif
|
2010-06-23 12:46:08 -07:00
|
|
|
|
2014-09-26 16:21:57 -07:00
|
|
|
private:
|
2013-02-05 09:01:07 -08:00
|
|
|
static PLDHashOperator
|
2014-09-26 16:21:57 -07:00
|
|
|
CollectTransactions(const uint64_t& aTransactionId,
|
2013-02-05 09:01:07 -08:00
|
|
|
TransactionInfo* aValue,
|
|
|
|
void* aUserArg);
|
|
|
|
|
|
|
|
static PLDHashOperator
|
2014-09-26 16:21:57 -07:00
|
|
|
FindTransaction(const uint64_t& aTransactionId,
|
2013-02-05 09:01:07 -08:00
|
|
|
TransactionInfo* aValue,
|
|
|
|
void* aUserArg);
|
|
|
|
|
|
|
|
static PLDHashOperator
|
|
|
|
MaybeUnblockTransaction(nsPtrHashKey<TransactionInfo>* aKey,
|
|
|
|
void* aUserArg);
|
|
|
|
|
2014-09-17 16:36:01 -07:00
|
|
|
TransactionThreadPool();
|
2014-09-26 16:21:57 -07:00
|
|
|
|
|
|
|
// Reference counted.
|
2010-06-23 12:46:08 -07:00
|
|
|
~TransactionThreadPool();
|
|
|
|
|
|
|
|
nsresult Init();
|
2014-09-26 16:21:57 -07:00
|
|
|
void Cleanup();
|
2010-06-23 12:46:08 -07:00
|
|
|
|
2014-09-26 16:21:57 -07:00
|
|
|
void FinishTransaction(uint64_t aTransactionId,
|
|
|
|
const nsACString& aDatabaseId,
|
|
|
|
const nsTArray<nsString>& aObjectStoreNames,
|
|
|
|
uint16_t aMode);
|
2010-06-23 12:46:08 -07:00
|
|
|
|
2014-09-26 16:21:57 -07:00
|
|
|
TransactionQueue* GetQueueForTransaction(uint64_t aTransactionId,
|
|
|
|
const nsACString& aDatabaseId);
|
2010-06-23 12:46:08 -07:00
|
|
|
|
2014-09-26 16:21:57 -07:00
|
|
|
TransactionQueue& GetQueueForTransaction(
|
|
|
|
uint64_t aTransactionId,
|
|
|
|
const nsACString& aDatabaseId,
|
|
|
|
const nsTArray<nsString>& aObjectStoreNames,
|
|
|
|
uint16_t aMode);
|
2010-10-19 10:58:52 -07:00
|
|
|
|
2014-09-26 16:21:57 -07:00
|
|
|
bool MaybeFireCallback(DatabasesCompleteCallback* aCallback);
|
2014-09-13 09:12:19 -07:00
|
|
|
|
2014-09-26 16:21:57 -07:00
|
|
|
void CleanupAsync();
|
|
|
|
};
|
2014-09-13 09:12:19 -07:00
|
|
|
|
2014-09-26 16:21:57 -07:00
|
|
|
class NS_NO_VTABLE TransactionThreadPool::FinishCallback
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
NS_IMETHOD_(MozExternalRefCountType)
|
|
|
|
AddRef() = 0;
|
|
|
|
|
|
|
|
NS_IMETHOD_(MozExternalRefCountType)
|
|
|
|
Release() = 0;
|
|
|
|
|
|
|
|
// Called on the owning thread before any additional transactions are
|
|
|
|
// unblocked.
|
|
|
|
virtual void
|
|
|
|
TransactionFinishedBeforeUnblock() = 0;
|
|
|
|
|
|
|
|
// Called on the owning thread after additional transactions may have been
|
|
|
|
// unblocked.
|
|
|
|
virtual void
|
|
|
|
TransactionFinishedAfterUnblock() = 0;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
FinishCallback()
|
|
|
|
{ }
|
2010-06-23 12:46:08 -07:00
|
|
|
};
|
|
|
|
|
2014-09-26 16:21:57 -07:00
|
|
|
} // namespace indexedDB
|
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
2010-06-23 12:46:08 -07:00
|
|
|
|
|
|
|
#endif // mozilla_dom_indexeddb_transactionthreadpool_h__
|