2010-06-23 19:46:08 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2015-05-03 19:32:37 +00:00
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2012-05-21 11:12:37 +00: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 19:46:08 +00:00
|
|
|
|
2016-02-16 21:46:08 +00:00
|
|
|
#ifndef mozilla_dom_idbtransaction_h__
|
|
|
|
#define mozilla_dom_idbtransaction_h__
|
2010-06-23 19:46:08 +00:00
|
|
|
|
2013-06-05 16:15:48 +00:00
|
|
|
#include "mozilla/Attributes.h"
|
2013-07-29 17:12:21 +00:00
|
|
|
#include "mozilla/dom/IDBTransactionBinding.h"
|
2016-02-16 21:46:08 +00:00
|
|
|
#include "mozilla/dom/IDBWrapperCache.h"
|
2014-09-26 23:21:57 +00:00
|
|
|
#include "nsAutoPtr.h"
|
|
|
|
#include "nsCycleCollectionParticipant.h"
|
|
|
|
#include "nsIRunnable.h"
|
|
|
|
#include "nsString.h"
|
|
|
|
#include "nsTArray.h"
|
2012-01-24 10:03:37 +00:00
|
|
|
|
2016-01-30 17:05:36 +00:00
|
|
|
class nsPIDOMWindowInner;
|
2010-06-23 19:46:08 +00:00
|
|
|
|
2014-03-18 04:48:19 +00:00
|
|
|
namespace mozilla {
|
2014-09-26 23:21:57 +00:00
|
|
|
|
|
|
|
class ErrorResult;
|
2014-03-18 04:48:19 +00:00
|
|
|
class EventChainPreVisitor;
|
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
namespace dom {
|
2010-06-23 19:46:08 +00:00
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
class DOMError;
|
|
|
|
class DOMStringList;
|
2016-02-16 21:46:08 +00:00
|
|
|
class IDBDatabase;
|
|
|
|
class IDBObjectStore;
|
|
|
|
class IDBOpenDBRequest;
|
|
|
|
class IDBRequest;
|
2011-10-20 16:10:56 +00:00
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
namespace indexedDB {
|
|
|
|
class BackgroundCursorChild;
|
|
|
|
class BackgroundRequestChild;
|
|
|
|
class BackgroundTransactionChild;
|
|
|
|
class BackgroundVersionChangeTransactionChild;
|
|
|
|
class IndexMetadata;
|
|
|
|
class ObjectStoreSpec;
|
|
|
|
class OpenCursorParams;
|
|
|
|
class RequestParams;
|
2016-02-16 21:46:08 +00:00
|
|
|
}
|
2014-09-26 23:21:57 +00:00
|
|
|
|
2015-03-21 16:28:04 +00:00
|
|
|
class IDBTransaction final
|
2014-09-26 23:21:57 +00:00
|
|
|
: public IDBWrapperCache
|
|
|
|
, public nsIRunnable
|
2010-06-23 19:46:08 +00:00
|
|
|
{
|
2016-02-16 21:46:08 +00:00
|
|
|
friend class indexedDB::BackgroundCursorChild;
|
|
|
|
friend class indexedDB::BackgroundRequestChild;
|
2015-03-18 21:20:59 +00:00
|
|
|
|
2016-06-23 08:53:14 +00:00
|
|
|
class WorkerHolder;
|
|
|
|
friend class WorkerHolder;
|
2014-12-17 06:26:15 +00:00
|
|
|
|
2010-06-23 19:46:08 +00:00
|
|
|
public:
|
2012-03-13 04:44:45 +00:00
|
|
|
enum Mode
|
|
|
|
{
|
|
|
|
READ_ONLY = 0,
|
|
|
|
READ_WRITE,
|
2015-01-26 06:30:09 +00:00
|
|
|
READ_WRITE_FLUSH,
|
2016-03-15 06:00:37 +00:00
|
|
|
CLEANUP,
|
2012-06-01 17:21:12 +00:00
|
|
|
VERSION_CHANGE,
|
|
|
|
|
|
|
|
// Only needed for IPC serialization helper, should never be used in code.
|
|
|
|
MODE_INVALID
|
2012-03-13 04:44:45 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
enum ReadyState
|
|
|
|
{
|
|
|
|
INITIAL = 0,
|
|
|
|
LOADING,
|
|
|
|
COMMITTING,
|
|
|
|
DONE
|
|
|
|
};
|
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
private:
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<IDBDatabase> mDatabase;
|
|
|
|
RefPtr<DOMError> mError;
|
2014-09-26 23:21:57 +00:00
|
|
|
nsTArray<nsString> mObjectStoreNames;
|
2015-10-18 05:24:48 +00:00
|
|
|
nsTArray<RefPtr<IDBObjectStore>> mObjectStores;
|
|
|
|
nsTArray<RefPtr<IDBObjectStore>> mDeletedObjectStores;
|
2016-06-23 08:53:14 +00:00
|
|
|
nsAutoPtr<WorkerHolder> mWorkerHolder;
|
2010-10-19 17:58:52 +00:00
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
// Tagged with mMode. If mMode is VERSION_CHANGE then mBackgroundActor will be
|
|
|
|
// a BackgroundVersionChangeTransactionChild. Otherwise it will be a
|
|
|
|
// BackgroundTransactionChild.
|
|
|
|
union {
|
2016-02-16 21:46:08 +00:00
|
|
|
indexedDB::BackgroundTransactionChild* mNormalBackgroundActor;
|
|
|
|
indexedDB::BackgroundVersionChangeTransactionChild* mVersionChangeBackgroundActor;
|
2014-09-26 23:21:57 +00:00
|
|
|
} mBackgroundActor;
|
2010-06-23 19:46:08 +00:00
|
|
|
|
2014-10-16 04:56:52 +00:00
|
|
|
const int64_t mLoggingSerialNumber;
|
2014-09-13 16:12:19 +00:00
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
// Only used for VERSION_CHANGE transactions.
|
|
|
|
int64_t mNextObjectStoreId;
|
|
|
|
int64_t mNextIndexId;
|
2010-06-23 19:46:08 +00:00
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
nsresult mAbortCode;
|
|
|
|
uint32_t mPendingRequestCount;
|
2014-09-13 16:12:19 +00:00
|
|
|
|
2014-11-14 02:20:38 +00:00
|
|
|
nsString mFilename;
|
|
|
|
uint32_t mLineNo;
|
2015-09-02 01:01:02 +00:00
|
|
|
uint32_t mColumn;
|
2014-11-14 02:20:38 +00:00
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
ReadyState mReadyState;
|
|
|
|
Mode mMode;
|
|
|
|
|
|
|
|
bool mCreating;
|
2014-12-17 06:26:15 +00:00
|
|
|
bool mRegistered;
|
2014-09-26 23:21:57 +00:00
|
|
|
bool mAbortedByScript;
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
bool mSentCommitOrAbort;
|
|
|
|
bool mFiredCompleteOrAbort;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
public:
|
|
|
|
static already_AddRefed<IDBTransaction>
|
|
|
|
CreateVersionChange(IDBDatabase* aDatabase,
|
2016-02-16 21:46:08 +00:00
|
|
|
indexedDB::BackgroundVersionChangeTransactionChild* aActor,
|
2014-11-14 02:20:38 +00:00
|
|
|
IDBOpenDBRequest* aOpenRequest,
|
2014-09-26 23:21:57 +00:00
|
|
|
int64_t aNextObjectStoreId,
|
|
|
|
int64_t aNextIndexId);
|
|
|
|
|
|
|
|
static already_AddRefed<IDBTransaction>
|
2016-03-23 15:02:57 +00:00
|
|
|
Create(JSContext* aCx, IDBDatabase* aDatabase,
|
2014-09-26 23:21:57 +00:00
|
|
|
const nsTArray<nsString>& aObjectStoreNames,
|
|
|
|
Mode aMode);
|
|
|
|
|
|
|
|
static IDBTransaction*
|
|
|
|
GetCurrent();
|
|
|
|
|
|
|
|
void
|
|
|
|
AssertIsOnOwningThread() const
|
|
|
|
#ifdef DEBUG
|
|
|
|
;
|
|
|
|
#else
|
|
|
|
{ }
|
|
|
|
#endif
|
2014-09-13 16:12:19 +00:00
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
void
|
2016-02-16 21:46:08 +00:00
|
|
|
SetBackgroundActor(indexedDB::BackgroundTransactionChild* aBackgroundActor);
|
2014-09-13 16:12:19 +00:00
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
void
|
|
|
|
ClearBackgroundActor()
|
2014-09-17 23:36:01 +00:00
|
|
|
{
|
2014-09-26 23:21:57 +00:00
|
|
|
AssertIsOnOwningThread();
|
|
|
|
|
|
|
|
if (mMode == VERSION_CHANGE) {
|
|
|
|
mBackgroundActor.mVersionChangeBackgroundActor = nullptr;
|
|
|
|
} else {
|
|
|
|
mBackgroundActor.mNormalBackgroundActor = nullptr;
|
|
|
|
}
|
2014-09-17 23:36:01 +00:00
|
|
|
}
|
2014-09-13 16:12:19 +00:00
|
|
|
|
2016-02-16 21:46:08 +00:00
|
|
|
indexedDB::BackgroundRequestChild*
|
|
|
|
StartRequest(IDBRequest* aRequest, const indexedDB::RequestParams& aParams);
|
2014-09-26 23:21:57 +00:00
|
|
|
|
|
|
|
void
|
2016-02-16 21:46:08 +00:00
|
|
|
OpenCursor(indexedDB::BackgroundCursorChild* aBackgroundActor,
|
|
|
|
const indexedDB::OpenCursorParams& aParams);
|
2014-09-26 23:21:57 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
RefreshSpec(bool aMayDelete);
|
|
|
|
|
|
|
|
bool
|
|
|
|
IsOpen() const;
|
2010-06-23 19:46:08 +00:00
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
bool
|
2015-06-25 22:22:59 +00:00
|
|
|
IsCommittingOrDone() const
|
2012-06-26 15:09:25 +00:00
|
|
|
{
|
2014-09-26 23:21:57 +00:00
|
|
|
AssertIsOnOwningThread();
|
2015-06-25 22:22:59 +00:00
|
|
|
|
|
|
|
return mReadyState == COMMITTING || mReadyState == DONE;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
IsDone() const
|
|
|
|
{
|
|
|
|
AssertIsOnOwningThread();
|
|
|
|
|
|
|
|
return mReadyState == DONE;
|
2012-06-26 15:09:25 +00:00
|
|
|
}
|
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
bool
|
|
|
|
IsWriteAllowed() const
|
2010-06-23 19:46:08 +00:00
|
|
|
{
|
2014-09-26 23:21:57 +00:00
|
|
|
AssertIsOnOwningThread();
|
2015-01-26 06:30:09 +00:00
|
|
|
return mMode == READ_WRITE ||
|
|
|
|
mMode == READ_WRITE_FLUSH ||
|
2016-03-15 06:00:37 +00:00
|
|
|
mMode == CLEANUP ||
|
2015-01-26 06:30:09 +00:00
|
|
|
mMode == VERSION_CHANGE;
|
2010-06-23 19:46:08 +00:00
|
|
|
}
|
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
bool
|
|
|
|
IsAborted() const
|
2010-12-15 21:21:17 +00:00
|
|
|
{
|
2014-09-26 23:21:57 +00:00
|
|
|
AssertIsOnOwningThread();
|
2012-06-01 17:21:12 +00:00
|
|
|
return NS_FAILED(mAbortCode);
|
2010-12-15 21:21:17 +00:00
|
|
|
}
|
|
|
|
|
2014-11-20 03:03:01 +00:00
|
|
|
nsresult
|
|
|
|
AbortCode() const
|
|
|
|
{
|
|
|
|
AssertIsOnOwningThread();
|
|
|
|
return mAbortCode;
|
|
|
|
}
|
|
|
|
|
2014-11-14 02:20:38 +00:00
|
|
|
void
|
2015-09-02 01:01:02 +00:00
|
|
|
GetCallerLocation(nsAString& aFilename, uint32_t* aLineNo,
|
|
|
|
uint32_t* aColumn) const;
|
2014-11-14 02:20:38 +00:00
|
|
|
|
2012-03-13 04:44:45 +00:00
|
|
|
// 'Get' prefix is to avoid name collisions with the enum
|
2014-09-26 23:21:57 +00:00
|
|
|
Mode
|
|
|
|
GetMode() const
|
2010-10-19 17:58:52 +00:00
|
|
|
{
|
2014-09-26 23:21:57 +00:00
|
|
|
AssertIsOnOwningThread();
|
2010-10-19 17:58:52 +00:00
|
|
|
return mMode;
|
|
|
|
}
|
2010-06-23 19:46:08 +00:00
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
IDBDatabase*
|
|
|
|
Database() const
|
2010-08-26 20:57:25 +00:00
|
|
|
{
|
2014-09-26 23:21:57 +00:00
|
|
|
AssertIsOnOwningThread();
|
2010-09-09 22:15:38 +00:00
|
|
|
return mDatabase;
|
2010-08-26 20:57:25 +00:00
|
|
|
}
|
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
IDBDatabase*
|
|
|
|
Db() const
|
2011-12-17 00:40:47 +00:00
|
|
|
{
|
2014-09-26 23:21:57 +00:00
|
|
|
return Database();
|
2012-06-01 17:21:12 +00:00
|
|
|
}
|
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
const nsTArray<nsString>&
|
|
|
|
ObjectStoreNamesInternal() const
|
2014-09-17 23:36:01 +00:00
|
|
|
{
|
2014-09-26 23:21:57 +00:00
|
|
|
AssertIsOnOwningThread();
|
|
|
|
return mObjectStoreNames;
|
2014-09-17 23:36:01 +00:00
|
|
|
}
|
2012-11-10 03:29:07 +00:00
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
already_AddRefed<IDBObjectStore>
|
2016-02-16 21:46:08 +00:00
|
|
|
CreateObjectStore(const indexedDB::ObjectStoreSpec& aSpec);
|
2014-09-26 23:21:57 +00:00
|
|
|
|
2014-09-13 16:12:19 +00:00
|
|
|
void
|
2014-09-26 23:21:57 +00:00
|
|
|
DeleteObjectStore(int64_t aObjectStoreId);
|
2014-09-17 23:36:01 +00:00
|
|
|
|
2016-03-30 03:04:56 +00:00
|
|
|
void
|
|
|
|
RenameObjectStore(int64_t aObjectStoreId, const nsAString& aName);
|
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
void
|
2016-02-16 21:46:08 +00:00
|
|
|
CreateIndex(IDBObjectStore* aObjectStore, const indexedDB::IndexMetadata& aMetadata);
|
2014-09-17 23:36:01 +00:00
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
void
|
|
|
|
DeleteIndex(IDBObjectStore* aObjectStore, int64_t aIndexId);
|
2014-09-17 23:36:01 +00:00
|
|
|
|
2016-03-30 03:04:56 +00:00
|
|
|
void
|
|
|
|
RenameIndex(IDBObjectStore* aObjectStore, int64_t aIndexId, const nsAString& aName);
|
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
void
|
2012-06-29 16:48:34 +00:00
|
|
|
Abort(IDBRequest* aRequest);
|
2012-06-01 17:21:12 +00:00
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
void
|
2012-06-29 16:48:34 +00:00
|
|
|
Abort(nsresult aAbortCode);
|
2012-06-25 19:15:17 +00:00
|
|
|
|
2014-10-16 04:56:52 +00:00
|
|
|
int64_t
|
|
|
|
LoggingSerialNumber() const
|
2013-03-16 06:58:50 +00:00
|
|
|
{
|
2014-09-26 23:21:57 +00:00
|
|
|
AssertIsOnOwningThread();
|
2014-10-16 04:56:52 +00:00
|
|
|
|
|
|
|
return mLoggingSerialNumber;
|
2013-03-16 06:58:50 +00:00
|
|
|
}
|
|
|
|
|
2016-01-30 17:05:36 +00:00
|
|
|
nsPIDOMWindowInner*
|
2014-09-26 23:21:57 +00:00
|
|
|
GetParentObject() const;
|
2013-07-29 17:12:21 +00:00
|
|
|
|
|
|
|
IDBTransactionMode
|
|
|
|
GetMode(ErrorResult& aRv) const;
|
|
|
|
|
|
|
|
DOMError*
|
2014-05-20 17:39:31 +00:00
|
|
|
GetError() const;
|
2013-07-29 17:12:21 +00:00
|
|
|
|
2013-07-31 15:48:36 +00:00
|
|
|
already_AddRefed<IDBObjectStore>
|
2013-07-29 17:12:21 +00:00
|
|
|
ObjectStore(const nsAString& aName, ErrorResult& aRv);
|
|
|
|
|
|
|
|
void
|
2014-09-26 23:21:57 +00:00
|
|
|
Abort(ErrorResult& aRv);
|
2013-07-29 17:12:21 +00:00
|
|
|
|
|
|
|
IMPL_EVENT_HANDLER(abort)
|
|
|
|
IMPL_EVENT_HANDLER(complete)
|
|
|
|
IMPL_EVENT_HANDLER(error)
|
|
|
|
|
2013-07-09 17:54:21 +00:00
|
|
|
already_AddRefed<DOMStringList>
|
2015-08-25 20:30:18 +00:00
|
|
|
ObjectStoreNames() const;
|
2014-09-17 23:36:01 +00:00
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
void
|
|
|
|
FireCompleteOrAbortEvents(nsresult aResult);
|
2014-09-17 23:36:01 +00:00
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
// Only for VERSION_CHANGE transactions.
|
|
|
|
int64_t
|
|
|
|
NextObjectStoreId();
|
2014-09-17 23:36:01 +00:00
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
// Only for VERSION_CHANGE transactions.
|
|
|
|
int64_t
|
|
|
|
NextIndexId();
|
2014-09-17 23:36:01 +00:00
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
NS_DECL_ISUPPORTS_INHERITED
|
2010-06-23 19:46:08 +00:00
|
|
|
NS_DECL_NSIRUNNABLE
|
2014-09-26 23:21:57 +00:00
|
|
|
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(IDBTransaction, IDBWrapperCache)
|
2010-06-23 19:46:08 +00:00
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
// nsWrapperCache
|
|
|
|
virtual JSObject*
|
2015-03-21 16:28:04 +00:00
|
|
|
WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
|
2014-09-17 23:36:01 +00:00
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
// nsIDOMEventTarget
|
|
|
|
virtual nsresult
|
2015-03-21 16:28:04 +00:00
|
|
|
PreHandleEvent(EventChainPreVisitor& aVisitor) override;
|
2014-09-17 23:36:01 +00:00
|
|
|
|
|
|
|
private:
|
2014-09-26 23:21:57 +00:00
|
|
|
IDBTransaction(IDBDatabase* aDatabase,
|
|
|
|
const nsTArray<nsString>& aObjectStoreNames,
|
|
|
|
Mode aMode);
|
|
|
|
~IDBTransaction();
|
2014-09-17 23:36:01 +00:00
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
void
|
|
|
|
AbortInternal(nsresult aAbortCode, already_AddRefed<DOMError> aError);
|
2014-09-17 23:36:01 +00:00
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
void
|
|
|
|
SendCommit();
|
2014-09-17 23:36:01 +00:00
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
void
|
|
|
|
SendAbort(nsresult aResultCode);
|
2015-03-18 21:20:59 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
OnNewRequest();
|
|
|
|
|
|
|
|
void
|
|
|
|
OnRequestFinished(bool aActorDestroyedNormally);
|
2014-09-17 23:36:01 +00:00
|
|
|
};
|
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
2010-06-23 19:46:08 +00:00
|
|
|
|
2016-02-16 21:46:08 +00:00
|
|
|
#endif // mozilla_dom_idbtransaction_h__
|