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
|
|
|
|
2010-06-28 09:46:21 -07:00
|
|
|
#ifndef mozilla_dom_indexeddb_idbtransaction_h__
|
|
|
|
#define mozilla_dom_indexeddb_idbtransaction_h__
|
2010-06-23 12:46:08 -07:00
|
|
|
|
2013-06-05 09:15:48 -07:00
|
|
|
#include "mozilla/Attributes.h"
|
2010-09-09 15:15:38 -07:00
|
|
|
#include "mozilla/dom/indexedDB/IndexedDatabase.h"
|
2010-06-23 12:46:08 -07:00
|
|
|
|
2011-12-15 23:34:24 -08:00
|
|
|
#include "mozIStorageConnection.h"
|
|
|
|
#include "mozIStorageStatement.h"
|
|
|
|
#include "mozIStorageFunction.h"
|
2013-05-18 10:52:06 -07:00
|
|
|
#include "mozilla/dom/DOMError.h"
|
2010-06-23 12:46:08 -07:00
|
|
|
#include "nsIRunnable.h"
|
|
|
|
|
|
|
|
#include "nsAutoPtr.h"
|
2011-12-15 23:34:24 -08:00
|
|
|
#include "nsClassHashtable.h"
|
2010-06-23 12:46:08 -07:00
|
|
|
#include "nsHashKeys.h"
|
|
|
|
#include "nsInterfaceHashtable.h"
|
2013-03-26 04:13:17 -07:00
|
|
|
#include "nsRefPtrHashtable.h"
|
2010-06-23 12:46:08 -07:00
|
|
|
|
2013-07-29 10:12:21 -07:00
|
|
|
#include "mozilla/dom/IDBTransactionBinding.h"
|
2012-01-24 02:03:37 -08:00
|
|
|
#include "mozilla/dom/indexedDB/IDBDatabase.h"
|
|
|
|
#include "mozilla/dom/indexedDB/IDBWrapperCache.h"
|
|
|
|
#include "mozilla/dom/indexedDB/FileInfo.h"
|
|
|
|
|
2010-06-23 12:46:08 -07:00
|
|
|
class nsIThread;
|
2013-07-29 10:12:21 -07:00
|
|
|
class nsPIDOMWindow;
|
2010-06-23 12:46:08 -07:00
|
|
|
|
2014-03-17 21:48:19 -07:00
|
|
|
namespace mozilla {
|
|
|
|
class EventChainPreVisitor;
|
|
|
|
} // namespace mozilla
|
|
|
|
|
2010-06-23 12:46:08 -07:00
|
|
|
BEGIN_INDEXEDDB_NAMESPACE
|
|
|
|
|
|
|
|
class AsyncConnectionHelper;
|
|
|
|
class CommitHelper;
|
2012-06-25 12:15:17 -07:00
|
|
|
class IDBRequest;
|
2012-06-01 10:21:12 -07:00
|
|
|
class IndexedDBDatabaseChild;
|
|
|
|
class IndexedDBTransactionChild;
|
|
|
|
class IndexedDBTransactionParent;
|
2010-06-23 12:46:08 -07:00
|
|
|
struct ObjectStoreInfo;
|
|
|
|
class TransactionThreadPool;
|
2011-12-15 23:34:24 -08:00
|
|
|
class UpdateRefcountFunction;
|
2010-06-23 12:46:08 -07:00
|
|
|
|
2011-10-20 09:10:56 -07:00
|
|
|
class IDBTransactionListener
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
NS_IMETHOD_(nsrefcnt) AddRef() = 0;
|
|
|
|
NS_IMETHOD_(nsrefcnt) Release() = 0;
|
|
|
|
|
2012-06-26 08:09:25 -07:00
|
|
|
// Called just before dispatching the final events on the transaction.
|
|
|
|
virtual nsresult NotifyTransactionPreComplete(IDBTransaction* aTransaction) = 0;
|
|
|
|
// Called just after dispatching the final events on the transaction.
|
|
|
|
virtual nsresult NotifyTransactionPostComplete(IDBTransaction* aTransaction) = 0;
|
2011-10-20 09:10:56 -07:00
|
|
|
};
|
|
|
|
|
2012-01-24 02:03:37 -08:00
|
|
|
class IDBTransaction : public IDBWrapperCache,
|
2012-04-06 13:40:10 -07:00
|
|
|
public nsIRunnable
|
2010-06-23 12:46:08 -07:00
|
|
|
{
|
|
|
|
friend class AsyncConnectionHelper;
|
|
|
|
friend class CommitHelper;
|
2012-06-01 10:21:12 -07:00
|
|
|
friend class IndexedDBDatabaseChild;
|
2010-11-15 13:49:49 -08:00
|
|
|
friend class ThreadObserver;
|
2010-06-23 12:46:08 -07:00
|
|
|
friend class TransactionThreadPool;
|
|
|
|
|
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS_INHERITED
|
2012-04-06 13:40:10 -07:00
|
|
|
NS_DECL_NSIRUNNABLE
|
2010-06-23 12:46:08 -07:00
|
|
|
|
2012-01-24 02:03:37 -08:00
|
|
|
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(IDBTransaction, IDBWrapperCache)
|
2010-06-23 12:46:08 -07:00
|
|
|
|
2012-03-12 21:44:45 -07:00
|
|
|
enum Mode
|
|
|
|
{
|
|
|
|
READ_ONLY = 0,
|
|
|
|
READ_WRITE,
|
2012-06-01 10:21:12 -07:00
|
|
|
VERSION_CHANGE,
|
|
|
|
|
|
|
|
// Only needed for IPC serialization helper, should never be used in code.
|
|
|
|
MODE_INVALID
|
2012-03-12 21:44:45 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
enum ReadyState
|
|
|
|
{
|
|
|
|
INITIAL = 0,
|
|
|
|
LOADING,
|
|
|
|
COMMITTING,
|
|
|
|
DONE
|
|
|
|
};
|
|
|
|
|
2010-06-28 09:46:21 -07:00
|
|
|
static already_AddRefed<IDBTransaction>
|
2010-09-09 15:15:38 -07:00
|
|
|
Create(IDBDatabase* aDatabase,
|
2013-07-31 08:48:46 -07:00
|
|
|
const Sequence<nsString>& aObjectStoreNames,
|
2012-03-12 21:44:45 -07:00
|
|
|
Mode aMode,
|
2012-06-01 10:21:12 -07:00
|
|
|
bool aDispatchDelayed)
|
|
|
|
{
|
|
|
|
return CreateInternal(aDatabase, aObjectStoreNames, aMode, aDispatchDelayed,
|
|
|
|
false);
|
|
|
|
}
|
2010-06-23 12:46:08 -07:00
|
|
|
|
2011-06-23 19:18:00 -07:00
|
|
|
// nsIDOMEventTarget
|
2014-03-17 21:48:19 -07:00
|
|
|
virtual nsresult PreHandleEvent(EventChainPreVisitor& aVisitor) MOZ_OVERRIDE;
|
2010-11-10 15:26:03 -08:00
|
|
|
|
2010-06-23 12:46:08 -07:00
|
|
|
void OnNewRequest();
|
|
|
|
void OnRequestFinished();
|
2012-11-09 19:29:07 -08:00
|
|
|
void OnRequestDisconnected();
|
2010-06-23 12:46:08 -07:00
|
|
|
|
2011-12-16 16:40:47 -08:00
|
|
|
void RemoveObjectStore(const nsAString& aName);
|
2011-12-04 09:39:01 -08:00
|
|
|
|
2011-10-20 09:10:56 -07:00
|
|
|
void SetTransactionListener(IDBTransactionListener* aListener);
|
|
|
|
|
2010-06-23 12:46:08 -07:00
|
|
|
bool StartSavepoint();
|
|
|
|
nsresult ReleaseSavepoint();
|
|
|
|
void RollbackSavepoint();
|
|
|
|
|
2010-10-19 10:58:52 -07:00
|
|
|
// Only meant to be called on mStorageThread!
|
|
|
|
nsresult GetOrCreateConnection(mozIStorageConnection** aConnection);
|
|
|
|
|
2010-06-23 12:46:08 -07:00
|
|
|
already_AddRefed<mozIStorageStatement>
|
|
|
|
GetCachedStatement(const nsACString& aQuery);
|
|
|
|
|
|
|
|
template<int N>
|
|
|
|
already_AddRefed<mozIStorageStatement>
|
|
|
|
GetCachedStatement(const char (&aQuery)[N])
|
|
|
|
{
|
2011-12-16 16:40:47 -08:00
|
|
|
return GetCachedStatement(NS_LITERAL_CSTRING(aQuery));
|
2010-06-23 12:46:08 -07:00
|
|
|
}
|
|
|
|
|
2010-12-15 13:21:17 -08:00
|
|
|
bool IsOpen() const;
|
2010-06-23 12:46:08 -07:00
|
|
|
|
2012-06-26 08:09:25 -07:00
|
|
|
bool IsFinished() const
|
|
|
|
{
|
|
|
|
return mReadyState > LOADING;
|
|
|
|
}
|
|
|
|
|
2010-06-23 12:46:08 -07:00
|
|
|
bool IsWriteAllowed() const
|
|
|
|
{
|
2012-03-12 21:44:45 -07:00
|
|
|
return mMode == READ_WRITE || mMode == VERSION_CHANGE;
|
2010-06-23 12:46:08 -07:00
|
|
|
}
|
|
|
|
|
2010-12-15 13:21:17 -08:00
|
|
|
bool IsAborted() const
|
|
|
|
{
|
2012-06-01 10:21:12 -07:00
|
|
|
return NS_FAILED(mAbortCode);
|
2010-12-15 13:21:17 -08:00
|
|
|
}
|
|
|
|
|
2012-03-12 21:44:45 -07:00
|
|
|
// 'Get' prefix is to avoid name collisions with the enum
|
|
|
|
Mode GetMode()
|
2010-10-19 10:58:52 -07:00
|
|
|
{
|
|
|
|
return mMode;
|
|
|
|
}
|
2010-06-23 12:46:08 -07:00
|
|
|
|
2010-09-09 15:15:38 -07:00
|
|
|
IDBDatabase* Database()
|
2010-08-26 13:57:25 -07:00
|
|
|
{
|
2010-09-09 15:15:38 -07:00
|
|
|
NS_ASSERTION(mDatabase, "This should never be null!");
|
|
|
|
return mDatabase;
|
2010-08-26 13:57:25 -07:00
|
|
|
}
|
|
|
|
|
2011-12-16 16:40:47 -08:00
|
|
|
DatabaseInfo* DBInfo() const
|
|
|
|
{
|
|
|
|
return mDatabaseInfo;
|
|
|
|
}
|
|
|
|
|
2010-11-10 15:25:40 -08:00
|
|
|
already_AddRefed<IDBObjectStore>
|
|
|
|
GetOrCreateObjectStore(const nsAString& aName,
|
2012-06-01 10:21:12 -07:00
|
|
|
ObjectStoreInfo* aObjectStoreInfo,
|
|
|
|
bool aCreating);
|
2010-11-10 15:25:40 -08:00
|
|
|
|
2012-06-03 09:33:52 -07:00
|
|
|
already_AddRefed<FileInfo> GetFileInfo(nsIDOMBlob* aBlob);
|
|
|
|
void AddFileInfo(nsIDOMBlob* aBlob, FileInfo* aFileInfo);
|
2011-12-15 23:34:24 -08:00
|
|
|
|
|
|
|
void ClearCreatedFileInfos();
|
|
|
|
|
2012-06-01 10:21:12 -07:00
|
|
|
void
|
|
|
|
SetActor(IndexedDBTransactionChild* aActorChild)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(!aActorChild || !mActorChild, "Shouldn't have more than one!");
|
|
|
|
mActorChild = aActorChild;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SetActor(IndexedDBTransactionParent* aActorParent)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(!aActorParent || !mActorParent,
|
|
|
|
"Shouldn't have more than one!");
|
|
|
|
mActorParent = aActorParent;
|
|
|
|
}
|
|
|
|
|
|
|
|
IndexedDBTransactionChild*
|
|
|
|
GetActorChild() const
|
|
|
|
{
|
|
|
|
return mActorChild;
|
|
|
|
}
|
|
|
|
|
2012-11-09 19:29:07 -08:00
|
|
|
IndexedDBTransactionParent*
|
|
|
|
GetActorParent() const
|
|
|
|
{
|
|
|
|
return mActorParent;
|
|
|
|
}
|
|
|
|
|
2012-06-01 10:21:12 -07:00
|
|
|
nsresult
|
2012-06-29 09:48:34 -07:00
|
|
|
Abort(IDBRequest* aRequest);
|
2012-06-01 10:21:12 -07:00
|
|
|
|
2012-06-25 12:15:17 -07:00
|
|
|
nsresult
|
2012-06-29 09:48:34 -07:00
|
|
|
Abort(nsresult aAbortCode);
|
2012-06-25 12:15:17 -07:00
|
|
|
|
2012-06-01 10:21:12 -07:00
|
|
|
nsresult
|
|
|
|
GetAbortCode() const
|
|
|
|
{
|
|
|
|
return mAbortCode;
|
|
|
|
}
|
|
|
|
|
2013-03-15 23:58:50 -07:00
|
|
|
#ifdef MOZ_ENABLE_PROFILER_SPS
|
|
|
|
uint64_t
|
|
|
|
GetSerialNumber() const
|
|
|
|
{
|
|
|
|
return mSerialNumber;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2013-07-29 10:12:21 -07:00
|
|
|
// nsWrapperCache
|
|
|
|
virtual JSObject*
|
|
|
|
WrapObject(JSContext* aCx, JS::Handle<JSObject*> aScope) MOZ_OVERRIDE;
|
|
|
|
|
|
|
|
// WebIDL
|
|
|
|
nsPIDOMWindow*
|
|
|
|
GetParentObject() const
|
|
|
|
{
|
|
|
|
return GetOwner();
|
|
|
|
}
|
|
|
|
|
|
|
|
IDBTransactionMode
|
|
|
|
GetMode(ErrorResult& aRv) const;
|
|
|
|
|
2013-07-31 08:48:46 -07:00
|
|
|
IDBDatabase*
|
2013-07-29 10:12:21 -07:00
|
|
|
Db() const
|
|
|
|
{
|
|
|
|
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
|
|
|
|
return mDatabase;
|
|
|
|
}
|
|
|
|
|
|
|
|
DOMError*
|
2013-11-14 10:58:05 -08:00
|
|
|
GetError(ErrorResult& aRv);
|
2013-07-29 10:12:21 -07:00
|
|
|
|
2013-07-31 08:48:36 -07:00
|
|
|
already_AddRefed<IDBObjectStore>
|
2013-07-29 10:12:21 -07:00
|
|
|
ObjectStore(const nsAString& aName, ErrorResult& aRv);
|
|
|
|
|
|
|
|
void
|
|
|
|
Abort(ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
|
|
|
|
aRv = AbortInternal(NS_ERROR_DOM_INDEXEDDB_ABORT_ERR, nullptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
IMPL_EVENT_HANDLER(abort)
|
|
|
|
IMPL_EVENT_HANDLER(complete)
|
|
|
|
IMPL_EVENT_HANDLER(error)
|
|
|
|
|
2013-07-09 10:54:21 -07:00
|
|
|
already_AddRefed<DOMStringList>
|
2013-07-29 10:12:21 -07:00
|
|
|
GetObjectStoreNames(ErrorResult& aRv);
|
|
|
|
|
2010-06-23 12:46:08 -07:00
|
|
|
private:
|
2012-06-29 09:48:34 -07:00
|
|
|
nsresult
|
2013-05-18 10:52:06 -07:00
|
|
|
AbortInternal(nsresult aAbortCode,
|
|
|
|
already_AddRefed<mozilla::dom::DOMError> aError);
|
2012-06-29 09:48:34 -07:00
|
|
|
|
2012-06-01 10:21:12 -07:00
|
|
|
// Should only be called directly through IndexedDBDatabaseChild.
|
|
|
|
static already_AddRefed<IDBTransaction>
|
|
|
|
CreateInternal(IDBDatabase* aDatabase,
|
2013-07-31 08:48:46 -07:00
|
|
|
const Sequence<nsString>& aObjectStoreNames,
|
2012-06-01 10:21:12 -07:00
|
|
|
Mode aMode,
|
|
|
|
bool aDispatchDelayed,
|
|
|
|
bool aIsVersionChangeTransactionChild);
|
|
|
|
|
2014-01-06 21:32:20 -08:00
|
|
|
IDBTransaction(IDBDatabase* aDatabase);
|
2010-06-28 09:46:21 -07:00
|
|
|
~IDBTransaction();
|
2010-06-23 12:46:08 -07:00
|
|
|
|
|
|
|
nsresult CommitOrRollback();
|
|
|
|
|
2010-06-28 09:46:49 -07:00
|
|
|
nsRefPtr<IDBDatabase> mDatabase;
|
2011-12-16 16:40:47 -08:00
|
|
|
nsRefPtr<DatabaseInfo> mDatabaseInfo;
|
2013-05-18 10:52:06 -07:00
|
|
|
nsRefPtr<DOMError> mError;
|
2010-06-23 12:46:08 -07:00
|
|
|
nsTArray<nsString> mObjectStoreNames;
|
2012-03-12 21:44:45 -07:00
|
|
|
ReadyState mReadyState;
|
|
|
|
Mode mMode;
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t mPendingRequests;
|
2010-06-23 12:46:08 -07:00
|
|
|
|
|
|
|
nsInterfaceHashtable<nsCStringHashKey, mozIStorageStatement>
|
|
|
|
mCachedStatements;
|
|
|
|
|
2011-10-20 09:10:56 -07:00
|
|
|
nsRefPtr<IDBTransactionListener> mListener;
|
|
|
|
|
2010-06-23 12:46:08 -07:00
|
|
|
// Only touched on the database thread.
|
|
|
|
nsCOMPtr<mozIStorageConnection> mConnection;
|
|
|
|
|
|
|
|
// Only touched on the database thread.
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t mSavepointCount;
|
2010-06-23 12:46:08 -07:00
|
|
|
|
2010-11-10 15:25:40 -08:00
|
|
|
nsTArray<nsRefPtr<IDBObjectStore> > mCreatedObjectStores;
|
2012-06-29 09:48:34 -07:00
|
|
|
nsTArray<nsRefPtr<IDBObjectStore> > mDeletedObjectStores;
|
2010-11-10 15:25:40 -08:00
|
|
|
|
2012-06-01 10:21:12 -07:00
|
|
|
nsRefPtr<UpdateRefcountFunction> mUpdateFileRefcountFunction;
|
2012-06-03 09:33:52 -07:00
|
|
|
nsRefPtrHashtable<nsISupportsHashKey, FileInfo> mCreatedFileInfos;
|
2012-06-01 10:21:12 -07:00
|
|
|
|
|
|
|
IndexedDBTransactionChild* mActorChild;
|
|
|
|
IndexedDBTransactionParent* mActorParent;
|
|
|
|
|
|
|
|
nsresult mAbortCode;
|
2013-03-15 23:58:50 -07:00
|
|
|
#ifdef MOZ_ENABLE_PROFILER_SPS
|
|
|
|
uint64_t mSerialNumber;
|
|
|
|
#endif
|
2010-11-15 13:49:49 -08:00
|
|
|
bool mCreating;
|
2010-12-15 13:21:17 -08:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
bool mFiredCompleteOrAbort;
|
|
|
|
#endif
|
2010-06-23 12:46:08 -07:00
|
|
|
};
|
|
|
|
|
2012-05-14 21:50:29 -07:00
|
|
|
class CommitHelper MOZ_FINAL : public nsIRunnable
|
2010-06-23 12:46:08 -07:00
|
|
|
{
|
|
|
|
public:
|
2013-07-18 19:21:20 -07:00
|
|
|
NS_DECL_THREADSAFE_ISUPPORTS
|
2010-06-23 12:46:08 -07:00
|
|
|
NS_DECL_NSIRUNNABLE
|
|
|
|
|
2011-10-20 09:10:56 -07:00
|
|
|
CommitHelper(IDBTransaction* aTransaction,
|
2011-12-16 16:40:47 -08:00
|
|
|
IDBTransactionListener* aListener,
|
|
|
|
const nsTArray<nsRefPtr<IDBObjectStore> >& mUpdatedObjectStores);
|
2012-06-01 10:21:12 -07:00
|
|
|
CommitHelper(IDBTransaction* aTransaction,
|
|
|
|
nsresult aAbortCode);
|
2010-10-19 10:58:52 -07:00
|
|
|
~CommitHelper();
|
2010-06-23 12:46:08 -07:00
|
|
|
|
|
|
|
template<class T>
|
|
|
|
bool AddDoomedObject(nsCOMPtr<T>& aCOMPtr)
|
|
|
|
{
|
|
|
|
if (aCOMPtr) {
|
|
|
|
if (!mDoomedObjects.AppendElement(do_QueryInterface(aCOMPtr))) {
|
|
|
|
NS_ERROR("Out of memory!");
|
|
|
|
return false;
|
|
|
|
}
|
2012-07-30 07:20:58 -07:00
|
|
|
aCOMPtr = nullptr;
|
2010-06-23 12:46:08 -07:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2011-12-16 16:40:47 -08:00
|
|
|
// Writes new autoincrement counts to database
|
|
|
|
nsresult WriteAutoIncrementCounts();
|
|
|
|
|
|
|
|
// Updates counts after a successful commit
|
|
|
|
void CommitAutoIncrementCounts();
|
|
|
|
|
|
|
|
// Reverts counts when a transaction is aborted
|
|
|
|
void RevertAutoIncrementCounts();
|
|
|
|
|
2010-06-28 09:46:21 -07:00
|
|
|
nsRefPtr<IDBTransaction> mTransaction;
|
2011-10-20 09:10:56 -07:00
|
|
|
nsRefPtr<IDBTransactionListener> mListener;
|
2010-06-23 12:46:08 -07:00
|
|
|
nsCOMPtr<mozIStorageConnection> mConnection;
|
2011-12-15 23:34:24 -08:00
|
|
|
nsRefPtr<UpdateRefcountFunction> mUpdateFileRefcountFunction;
|
2010-06-23 12:46:08 -07:00
|
|
|
nsAutoTArray<nsCOMPtr<nsISupports>, 10> mDoomedObjects;
|
2011-12-16 16:40:47 -08:00
|
|
|
nsAutoTArray<nsRefPtr<IDBObjectStore>, 10> mAutoIncrementObjectStores;
|
2010-10-19 10:58:52 -07:00
|
|
|
|
2012-06-01 10:21:12 -07:00
|
|
|
nsresult mAbortCode;
|
2010-06-23 12:46:08 -07:00
|
|
|
};
|
|
|
|
|
2012-05-14 21:50:29 -07:00
|
|
|
class UpdateRefcountFunction MOZ_FINAL : public mozIStorageFunction
|
2011-12-15 23:34:24 -08:00
|
|
|
{
|
|
|
|
public:
|
2013-07-18 19:21:20 -07:00
|
|
|
NS_DECL_THREADSAFE_ISUPPORTS
|
2011-12-15 23:34:24 -08:00
|
|
|
NS_DECL_MOZISTORAGEFUNCTION
|
|
|
|
|
|
|
|
UpdateRefcountFunction(FileManager* aFileManager)
|
2014-01-31 10:53:37 -08:00
|
|
|
: mFileManager(aFileManager), mInSavepoint(false)
|
2011-12-15 23:34:24 -08:00
|
|
|
{ }
|
|
|
|
|
|
|
|
~UpdateRefcountFunction()
|
|
|
|
{ }
|
|
|
|
|
2014-01-31 10:53:37 -08:00
|
|
|
void StartSavepoint()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(!mInSavepoint);
|
|
|
|
MOZ_ASSERT(!mSavepointEntriesIndex.Count());
|
|
|
|
|
|
|
|
mInSavepoint = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ReleaseSavepoint()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(mInSavepoint);
|
|
|
|
|
|
|
|
mSavepointEntriesIndex.Clear();
|
|
|
|
|
|
|
|
mInSavepoint = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void RollbackSavepoint()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(mInSavepoint);
|
|
|
|
|
|
|
|
mInSavepoint = false;
|
|
|
|
|
|
|
|
mSavepointEntriesIndex.EnumerateRead(RollbackSavepointCallback, nullptr);
|
|
|
|
|
|
|
|
mSavepointEntriesIndex.Clear();
|
|
|
|
}
|
|
|
|
|
2011-12-15 23:34:24 -08:00
|
|
|
void ClearFileInfoEntries()
|
|
|
|
{
|
|
|
|
mFileInfoEntries.Clear();
|
|
|
|
}
|
|
|
|
|
2012-08-24 11:51:33 -07:00
|
|
|
nsresult WillCommit(mozIStorageConnection* aConnection);
|
|
|
|
void DidCommit();
|
|
|
|
void DidAbort();
|
2011-12-15 23:34:24 -08:00
|
|
|
|
|
|
|
private:
|
|
|
|
class FileInfoEntry
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
FileInfoEntry(FileInfo* aFileInfo)
|
2014-01-31 10:53:37 -08:00
|
|
|
: mFileInfo(aFileInfo), mDelta(0), mSavepointDelta(0)
|
2011-12-15 23:34:24 -08:00
|
|
|
{ }
|
|
|
|
|
|
|
|
~FileInfoEntry()
|
|
|
|
{ }
|
|
|
|
|
|
|
|
nsRefPtr<FileInfo> mFileInfo;
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t mDelta;
|
2014-01-31 10:53:37 -08:00
|
|
|
int32_t mSavepointDelta;
|
2011-12-15 23:34:24 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
enum UpdateType {
|
|
|
|
eIncrement,
|
|
|
|
eDecrement
|
|
|
|
};
|
|
|
|
|
|
|
|
class DatabaseUpdateFunction
|
|
|
|
{
|
|
|
|
public:
|
2012-08-24 11:51:33 -07:00
|
|
|
DatabaseUpdateFunction(mozIStorageConnection* aConnection,
|
|
|
|
UpdateRefcountFunction* aFunction)
|
|
|
|
: mConnection(aConnection), mFunction(aFunction), mErrorCode(NS_OK)
|
2011-12-15 23:34:24 -08:00
|
|
|
{ }
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
bool Update(int64_t aId, int32_t aDelta);
|
2011-12-15 23:34:24 -08:00
|
|
|
nsresult ErrorCode()
|
|
|
|
{
|
|
|
|
return mErrorCode;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2012-08-22 08:56:38 -07:00
|
|
|
nsresult UpdateInternal(int64_t aId, int32_t aDelta);
|
2011-12-15 23:34:24 -08:00
|
|
|
|
|
|
|
nsCOMPtr<mozIStorageConnection> mConnection;
|
|
|
|
nsCOMPtr<mozIStorageStatement> mUpdateStatement;
|
2012-08-24 11:51:33 -07:00
|
|
|
nsCOMPtr<mozIStorageStatement> mSelectStatement;
|
2011-12-15 23:34:24 -08:00
|
|
|
nsCOMPtr<mozIStorageStatement> mInsertStatement;
|
|
|
|
|
2012-08-24 11:51:33 -07:00
|
|
|
UpdateRefcountFunction* mFunction;
|
|
|
|
|
2011-12-15 23:34:24 -08:00
|
|
|
nsresult mErrorCode;
|
|
|
|
};
|
|
|
|
|
|
|
|
nsresult ProcessValue(mozIStorageValueArray* aValues,
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t aIndex,
|
2011-12-15 23:34:24 -08:00
|
|
|
UpdateType aUpdateType);
|
|
|
|
|
2012-08-24 11:51:33 -07:00
|
|
|
nsresult CreateJournals();
|
|
|
|
|
|
|
|
nsresult RemoveJournals(const nsTArray<int64_t>& aJournals);
|
|
|
|
|
2011-12-15 23:34:24 -08:00
|
|
|
static PLDHashOperator
|
2012-08-22 08:56:38 -07:00
|
|
|
DatabaseUpdateCallback(const uint64_t& aKey,
|
2011-12-15 23:34:24 -08:00
|
|
|
FileInfoEntry* aValue,
|
|
|
|
void* aUserArg);
|
|
|
|
|
|
|
|
static PLDHashOperator
|
2012-08-22 08:56:38 -07:00
|
|
|
FileInfoUpdateCallback(const uint64_t& aKey,
|
2011-12-15 23:34:24 -08:00
|
|
|
FileInfoEntry* aValue,
|
|
|
|
void* aUserArg);
|
|
|
|
|
2014-01-31 10:53:37 -08:00
|
|
|
static PLDHashOperator
|
|
|
|
RollbackSavepointCallback(const uint64_t& aKey,
|
|
|
|
FileInfoEntry* aValue,
|
|
|
|
void* aUserArg);
|
|
|
|
|
2011-12-15 23:34:24 -08:00
|
|
|
FileManager* mFileManager;
|
|
|
|
nsClassHashtable<nsUint64HashKey, FileInfoEntry> mFileInfoEntries;
|
2014-01-31 10:53:37 -08:00
|
|
|
nsDataHashtable<nsUint64HashKey, FileInfoEntry*> mSavepointEntriesIndex;
|
2012-08-24 11:51:33 -07:00
|
|
|
|
|
|
|
nsTArray<int64_t> mJournalsToCreateBeforeCommit;
|
|
|
|
nsTArray<int64_t> mJournalsToRemoveAfterCommit;
|
|
|
|
nsTArray<int64_t> mJournalsToRemoveAfterAbort;
|
2014-01-31 10:53:37 -08:00
|
|
|
|
|
|
|
bool mInSavepoint;
|
2011-12-15 23:34:24 -08:00
|
|
|
};
|
|
|
|
|
2010-06-23 12:46:08 -07:00
|
|
|
END_INDEXEDDB_NAMESPACE
|
|
|
|
|
2010-06-28 09:46:21 -07:00
|
|
|
#endif // mozilla_dom_indexeddb_idbtransaction_h__
|