2010-06-23 23:46:08 +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-06-23 23:46:08 +04:00
|
|
|
|
2016-02-17 00:46:08 +03:00
|
|
|
#ifndef mozilla_dom_idbtransaction_h__
|
|
|
|
#define mozilla_dom_idbtransaction_h__
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2013-06-05 20:15:48 +04:00
|
|
|
#include "mozilla/Attributes.h"
|
2013-07-29 21:12:21 +04:00
|
|
|
#include "mozilla/dom/IDBTransactionBinding.h"
|
2019-03-29 21:05:11 +03:00
|
|
|
#include "mozilla/DOMEventTargetHelper.h"
|
2014-09-27 03:21:57 +04:00
|
|
|
#include "nsAutoPtr.h"
|
|
|
|
#include "nsCycleCollectionParticipant.h"
|
|
|
|
#include "nsIRunnable.h"
|
|
|
|
#include "nsString.h"
|
|
|
|
#include "nsTArray.h"
|
2012-01-24 14:03:37 +04:00
|
|
|
|
2014-03-18 08:48:19 +04:00
|
|
|
namespace mozilla {
|
2014-09-27 03:21:57 +04:00
|
|
|
|
|
|
|
class ErrorResult;
|
2014-03-18 08:48:19 +04:00
|
|
|
class EventChainPreVisitor;
|
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
namespace dom {
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2017-08-06 20:47:00 +03:00
|
|
|
class DOMException;
|
2014-09-27 03:21:57 +04:00
|
|
|
class DOMStringList;
|
2019-11-05 17:40:37 +03:00
|
|
|
class IDBCursor;
|
2016-02-17 00:46:08 +03:00
|
|
|
class IDBDatabase;
|
|
|
|
class IDBObjectStore;
|
|
|
|
class IDBOpenDBRequest;
|
|
|
|
class IDBRequest;
|
2018-06-18 23:37:21 +03:00
|
|
|
class StrongWorkerRef;
|
2011-10-20 20:10:56 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
namespace indexedDB {
|
|
|
|
class BackgroundCursorChild;
|
|
|
|
class BackgroundRequestChild;
|
|
|
|
class BackgroundTransactionChild;
|
|
|
|
class BackgroundVersionChangeTransactionChild;
|
|
|
|
class IndexMetadata;
|
|
|
|
class ObjectStoreSpec;
|
|
|
|
class OpenCursorParams;
|
|
|
|
class RequestParams;
|
2016-02-17 00:46:08 +03:00
|
|
|
} // namespace indexedDB
|
2014-09-27 03:21:57 +04:00
|
|
|
|
2019-03-29 21:05:11 +03:00
|
|
|
class IDBTransaction final : public DOMEventTargetHelper, public nsIRunnable {
|
2016-02-17 00:46:08 +03:00
|
|
|
friend class indexedDB::BackgroundCursorChild;
|
|
|
|
friend class indexedDB::BackgroundRequestChild;
|
2015-03-19 00:20:59 +03:00
|
|
|
|
2010-06-23 23:46:08 +04:00
|
|
|
public:
|
2012-03-13 08:44:45 +04:00
|
|
|
enum Mode {
|
|
|
|
READ_ONLY = 0,
|
|
|
|
READ_WRITE,
|
2015-01-26 09:30:09 +03:00
|
|
|
READ_WRITE_FLUSH,
|
2016-03-15 09:00:37 +03:00
|
|
|
CLEANUP,
|
2012-06-01 21:21:12 +04:00
|
|
|
VERSION_CHANGE,
|
|
|
|
|
|
|
|
// Only needed for IPC serialization helper, should never be used in code.
|
|
|
|
MODE_INVALID
|
2012-03-13 08:44:45 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
enum ReadyState { INITIAL = 0, LOADING, COMMITTING, DONE };
|
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
private:
|
2019-11-11 11:24:25 +03:00
|
|
|
// TODO: Only non-const because of Bug 1575173.
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<IDBDatabase> mDatabase;
|
2017-08-06 20:47:00 +03:00
|
|
|
RefPtr<DOMException> mError;
|
2019-11-11 11:24:25 +03:00
|
|
|
const nsTArray<nsString> mObjectStoreNames;
|
2015-10-18 08:24:48 +03:00
|
|
|
nsTArray<RefPtr<IDBObjectStore>> mObjectStores;
|
|
|
|
nsTArray<RefPtr<IDBObjectStore>> mDeletedObjectStores;
|
2018-06-18 23:37:21 +03:00
|
|
|
RefPtr<StrongWorkerRef> mWorkerRef;
|
2019-11-05 17:40:37 +03:00
|
|
|
nsTArray<IDBCursor*> mCursors;
|
2010-10-19 21:58:52 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
// Tagged with mMode. If mMode is VERSION_CHANGE then mBackgroundActor will be
|
|
|
|
// a BackgroundVersionChangeTransactionChild. Otherwise it will be a
|
|
|
|
// BackgroundTransactionChild.
|
|
|
|
union {
|
2016-02-17 00:46:08 +03:00
|
|
|
indexedDB::BackgroundTransactionChild* mNormalBackgroundActor;
|
|
|
|
indexedDB::BackgroundVersionChangeTransactionChild*
|
|
|
|
mVersionChangeBackgroundActor;
|
2014-09-27 03:21:57 +04:00
|
|
|
} mBackgroundActor;
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2014-10-16 08:56:52 +04:00
|
|
|
const int64_t mLoggingSerialNumber;
|
2014-09-13 20:12:19 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
// Only used for VERSION_CHANGE transactions.
|
|
|
|
int64_t mNextObjectStoreId;
|
|
|
|
int64_t mNextIndexId;
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2019-11-11 11:25:20 +03:00
|
|
|
nsresult mAbortCode; ///< The result that caused the transaction to be
|
|
|
|
///< aborted, or NS_OK if not aborted.
|
|
|
|
///< NS_ERROR_DOM_INDEXEDDB_ABORT_ERR indicates that the
|
|
|
|
///< user explicitly requested aborting. Should be
|
|
|
|
///< renamed to mResult or so, because it is actually
|
|
|
|
///< used to check if the transaction has been aborted.
|
|
|
|
uint32_t mPendingRequestCount; ///< Counted via OnNewRequest and
|
|
|
|
///< OnRequestFinished, so that the
|
|
|
|
///< transaction can auto-commit when the last
|
|
|
|
///< pending request finished.
|
2019-11-08 17:28:53 +03:00
|
|
|
|
2019-11-11 11:24:25 +03:00
|
|
|
const nsString mFilename;
|
|
|
|
const uint32_t mLineNo;
|
|
|
|
const uint32_t mColumn;
|
2014-11-14 05:20:38 +03:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
ReadyState mReadyState;
|
2019-11-11 11:24:25 +03:00
|
|
|
const Mode mMode;
|
2014-09-27 03:21:57 +04:00
|
|
|
|
2019-11-11 11:25:20 +03:00
|
|
|
bool mCreating; ///< Set between successful creation until the transaction
|
|
|
|
///< has run on the event-loop.
|
|
|
|
bool mRegistered; ///< Whether mDatabase->RegisterTransaction() has been
|
|
|
|
///< called (which may not be the case if construction was
|
|
|
|
///< incomplete).
|
2014-09-27 03:21:57 +04:00
|
|
|
bool mAbortedByScript;
|
2017-06-16 14:06:36 +03:00
|
|
|
bool mNotedActiveTransaction;
|
2014-09-27 03:21:57 +04:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
bool mSentCommitOrAbort;
|
|
|
|
bool mFiredCompleteOrAbort;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
public:
|
|
|
|
static already_AddRefed<IDBTransaction> CreateVersionChange(
|
|
|
|
IDBDatabase* aDatabase,
|
2016-02-17 00:46:08 +03:00
|
|
|
indexedDB::BackgroundVersionChangeTransactionChild* aActor,
|
2014-11-14 05:20:38 +03:00
|
|
|
IDBOpenDBRequest* aOpenRequest, int64_t aNextObjectStoreId,
|
2014-09-27 03:21:57 +04:00
|
|
|
int64_t aNextIndexId);
|
|
|
|
|
|
|
|
static already_AddRefed<IDBTransaction> Create(
|
2016-03-23 18:02:57 +03:00
|
|
|
JSContext* aCx, IDBDatabase* aDatabase,
|
2014-09-27 03:21:57 +04:00
|
|
|
const nsTArray<nsString>& aObjectStoreNames, Mode aMode);
|
|
|
|
|
|
|
|
static IDBTransaction* GetCurrent();
|
|
|
|
|
|
|
|
void AssertIsOnOwningThread() const
|
|
|
|
#ifdef DEBUG
|
|
|
|
;
|
|
|
|
#else
|
|
|
|
{
|
|
|
|
}
|
|
|
|
#endif
|
2014-09-13 20:12:19 +04:00
|
|
|
|
2016-02-17 00:46:08 +03:00
|
|
|
void SetBackgroundActor(
|
|
|
|
indexedDB::BackgroundTransactionChild* aBackgroundActor);
|
2014-09-13 20:12:19 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
void ClearBackgroundActor() {
|
|
|
|
AssertIsOnOwningThread();
|
|
|
|
|
|
|
|
if (mMode == VERSION_CHANGE) {
|
|
|
|
mBackgroundActor.mVersionChangeBackgroundActor = nullptr;
|
|
|
|
} else {
|
|
|
|
mBackgroundActor.mNormalBackgroundActor = nullptr;
|
|
|
|
}
|
2017-06-16 14:06:36 +03:00
|
|
|
|
|
|
|
// Note inactive transaction here if we didn't receive the Complete message
|
|
|
|
// from the parent.
|
|
|
|
MaybeNoteInactiveTransaction();
|
2014-09-18 03:36:01 +04:00
|
|
|
}
|
2014-09-13 20:12:19 +04:00
|
|
|
|
2016-02-17 00:46:08 +03:00
|
|
|
indexedDB::BackgroundRequestChild* StartRequest(
|
|
|
|
IDBRequest* aRequest, const indexedDB::RequestParams& aParams);
|
2014-09-27 03:21:57 +04:00
|
|
|
|
2016-02-17 00:46:08 +03:00
|
|
|
void OpenCursor(indexedDB::BackgroundCursorChild* aBackgroundActor,
|
|
|
|
const indexedDB::OpenCursorParams& aParams);
|
2014-09-27 03:21:57 +04:00
|
|
|
|
|
|
|
void RefreshSpec(bool aMayDelete);
|
|
|
|
|
|
|
|
bool IsOpen() const;
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2015-06-26 01:22:59 +03:00
|
|
|
bool IsCommittingOrDone() const {
|
2014-09-27 03:21:57 +04:00
|
|
|
AssertIsOnOwningThread();
|
2015-06-26 01:22:59 +03:00
|
|
|
|
|
|
|
return mReadyState == COMMITTING || mReadyState == DONE;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool IsDone() const {
|
|
|
|
AssertIsOnOwningThread();
|
|
|
|
|
|
|
|
return mReadyState == DONE;
|
2012-06-26 19:09:25 +04:00
|
|
|
}
|
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
bool IsWriteAllowed() const {
|
|
|
|
AssertIsOnOwningThread();
|
2015-01-26 09:30:09 +03:00
|
|
|
return mMode == READ_WRITE || mMode == READ_WRITE_FLUSH ||
|
|
|
|
mMode == CLEANUP || mMode == VERSION_CHANGE;
|
2010-06-23 23:46:08 +04:00
|
|
|
}
|
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
bool IsAborted() const {
|
|
|
|
AssertIsOnOwningThread();
|
2012-06-01 21:21:12 +04:00
|
|
|
return NS_FAILED(mAbortCode);
|
2010-12-16 00:21:17 +03:00
|
|
|
}
|
|
|
|
|
2014-11-20 06:03:01 +03:00
|
|
|
nsresult AbortCode() const {
|
|
|
|
AssertIsOnOwningThread();
|
|
|
|
return mAbortCode;
|
|
|
|
}
|
|
|
|
|
2015-09-02 04:01:02 +03:00
|
|
|
void GetCallerLocation(nsAString& aFilename, uint32_t* aLineNo,
|
|
|
|
uint32_t* aColumn) const;
|
2014-11-14 05:20:38 +03:00
|
|
|
|
2012-03-13 08:44:45 +04:00
|
|
|
// 'Get' prefix is to avoid name collisions with the enum
|
2014-09-27 03:21:57 +04:00
|
|
|
Mode GetMode() const {
|
|
|
|
AssertIsOnOwningThread();
|
2010-10-19 21:58:52 +04:00
|
|
|
return mMode;
|
|
|
|
}
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
IDBDatabase* Database() const {
|
|
|
|
AssertIsOnOwningThread();
|
2010-09-10 02:15:38 +04:00
|
|
|
return mDatabase;
|
2010-08-27 00:57:25 +04:00
|
|
|
}
|
|
|
|
|
2019-11-11 11:25:20 +03:00
|
|
|
// Only for use by ProfilerHelpers.h
|
2014-09-27 03:21:57 +04:00
|
|
|
const nsTArray<nsString>& ObjectStoreNamesInternal() const {
|
|
|
|
AssertIsOnOwningThread();
|
|
|
|
return mObjectStoreNames;
|
2014-09-18 03:36:01 +04:00
|
|
|
}
|
2012-11-10 07:29:07 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
already_AddRefed<IDBObjectStore> CreateObjectStore(
|
2016-02-17 00:46:08 +03:00
|
|
|
const indexedDB::ObjectStoreSpec& aSpec);
|
2014-09-27 03:21:57 +04:00
|
|
|
|
|
|
|
void DeleteObjectStore(int64_t aObjectStoreId);
|
2014-09-18 03:36:01 +04:00
|
|
|
|
2016-03-30 06:04:56 +03:00
|
|
|
void RenameObjectStore(int64_t aObjectStoreId, const nsAString& aName);
|
|
|
|
|
2016-02-17 00:46:08 +03:00
|
|
|
void CreateIndex(IDBObjectStore* aObjectStore,
|
|
|
|
const indexedDB::IndexMetadata& aMetadata);
|
2014-09-18 03:36:01 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
void DeleteIndex(IDBObjectStore* aObjectStore, int64_t aIndexId);
|
2014-09-18 03:36:01 +04:00
|
|
|
|
2016-03-30 06:04:56 +03:00
|
|
|
void RenameIndex(IDBObjectStore* aObjectStore, int64_t aIndexId,
|
|
|
|
const nsAString& aName);
|
|
|
|
|
2012-06-29 20:48:34 +04:00
|
|
|
void Abort(IDBRequest* aRequest);
|
2012-06-01 21:21:12 +04:00
|
|
|
|
2019-11-08 16:22:28 +03:00
|
|
|
void Abort(nsresult aErrorCode);
|
2012-06-25 23:15:17 +04:00
|
|
|
|
2014-10-16 08:56:52 +04:00
|
|
|
int64_t LoggingSerialNumber() const {
|
2014-09-27 03:21:57 +04:00
|
|
|
AssertIsOnOwningThread();
|
2014-10-16 08:56:52 +04:00
|
|
|
|
|
|
|
return mLoggingSerialNumber;
|
2013-03-16 10:58:50 +04:00
|
|
|
}
|
|
|
|
|
2019-03-29 21:05:11 +03:00
|
|
|
nsIGlobalObject* GetParentObject() const;
|
2013-07-29 21:12:21 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
void FireCompleteOrAbortEvents(nsresult aResult);
|
2014-09-18 03:36:01 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
// Only for VERSION_CHANGE transactions.
|
|
|
|
int64_t NextObjectStoreId();
|
2014-09-18 03:36:01 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
// Only for VERSION_CHANGE transactions.
|
|
|
|
int64_t NextIndexId();
|
2014-09-18 03:36:01 +04:00
|
|
|
|
2019-11-05 17:40:37 +03:00
|
|
|
void InvalidateCursorCaches();
|
|
|
|
void RegisterCursor(IDBCursor* aCursor);
|
|
|
|
void UnregisterCursor(IDBCursor* aCursor);
|
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
NS_DECL_ISUPPORTS_INHERITED
|
2010-06-23 23:46:08 +04:00
|
|
|
NS_DECL_NSIRUNNABLE
|
2019-03-29 21:05:11 +03:00
|
|
|
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(IDBTransaction, DOMEventTargetHelper)
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
// nsWrapperCache
|
2019-11-11 11:25:20 +03:00
|
|
|
JSObject* WrapObject(JSContext* aCx,
|
|
|
|
JS::Handle<JSObject*> aGivenProto) override;
|
2019-11-08 16:33:56 +03:00
|
|
|
|
2019-11-11 11:25:33 +03:00
|
|
|
// Methods bound via WebIDL.
|
|
|
|
IDBDatabase* Db() const { return Database(); }
|
|
|
|
|
|
|
|
IDBTransactionMode GetMode(ErrorResult& aRv) const;
|
|
|
|
|
|
|
|
DOMException* GetError() const;
|
|
|
|
|
|
|
|
already_AddRefed<IDBObjectStore> ObjectStore(const nsAString& aName,
|
|
|
|
ErrorResult& aRv);
|
|
|
|
|
|
|
|
void Abort(ErrorResult& aRv);
|
|
|
|
|
|
|
|
IMPL_EVENT_HANDLER(abort)
|
|
|
|
IMPL_EVENT_HANDLER(complete)
|
|
|
|
IMPL_EVENT_HANDLER(error)
|
|
|
|
|
|
|
|
already_AddRefed<DOMStringList> ObjectStoreNames() const;
|
|
|
|
|
2018-04-05 20:42:41 +03:00
|
|
|
// EventTarget
|
|
|
|
void GetEventTargetParent(EventChainPreVisitor& aVisitor) override;
|
2014-09-18 03:36:01 +04:00
|
|
|
|
|
|
|
private:
|
2014-09-27 03:21:57 +04:00
|
|
|
IDBTransaction(IDBDatabase* aDatabase,
|
2019-11-11 11:24:25 +03:00
|
|
|
const nsTArray<nsString>& aObjectStoreNames, Mode aMode,
|
|
|
|
nsString aFilename, uint32_t aLineNo, uint32_t aColumn);
|
2014-09-27 03:21:57 +04:00
|
|
|
~IDBTransaction();
|
2014-09-18 03:36:01 +04:00
|
|
|
|
2017-08-06 20:47:00 +03:00
|
|
|
void AbortInternal(nsresult aAbortCode,
|
|
|
|
already_AddRefed<DOMException> aError);
|
2014-09-18 03:36:01 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
void SendCommit();
|
2014-09-18 03:36:01 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
void SendAbort(nsresult aResultCode);
|
2015-03-19 00:20:59 +03:00
|
|
|
|
2017-06-16 14:06:36 +03:00
|
|
|
void NoteActiveTransaction();
|
|
|
|
|
|
|
|
void MaybeNoteInactiveTransaction();
|
|
|
|
|
2015-03-19 00:20:59 +03:00
|
|
|
void OnNewRequest();
|
|
|
|
|
2019-11-05 17:40:37 +03:00
|
|
|
void OnRequestFinished(bool aRequestCompletedSuccessfully);
|
2019-11-11 11:24:32 +03:00
|
|
|
|
|
|
|
template <typename Func>
|
|
|
|
auto DoWithTransactionChild(const Func& aFunc) const;
|
|
|
|
|
|
|
|
bool HasTransactionChild() const;
|
2014-09-18 03:36:01 +04:00
|
|
|
};
|
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2016-02-17 00:46:08 +03:00
|
|
|
#endif // mozilla_dom_idbtransaction_h__
|