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
|
|
|
|
2010-06-28 20:46:21 +04:00
|
|
|
#ifndef mozilla_dom_indexeddb_idbtransaction_h__
|
|
|
|
#define mozilla_dom_indexeddb_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"
|
2012-01-24 14:03:37 +04:00
|
|
|
#include "mozilla/dom/indexedDB/IDBWrapperCache.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
|
|
|
|
2013-07-29 21:12:21 +04:00
|
|
|
class nsPIDOMWindow;
|
2010-06-23 23:46:08 +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
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
class DOMError;
|
|
|
|
class DOMStringList;
|
|
|
|
class PBlobChild;
|
2011-10-20 20:10:56 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
namespace indexedDB {
|
2011-10-20 20:10:56 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
class BackgroundCursorChild;
|
|
|
|
class BackgroundRequestChild;
|
|
|
|
class BackgroundTransactionChild;
|
|
|
|
class BackgroundVersionChangeTransactionChild;
|
|
|
|
class IDBDatabase;
|
|
|
|
class IDBObjectStore;
|
2014-11-14 05:20:38 +03:00
|
|
|
class IDBOpenDBRequest;
|
2014-09-27 03:21:57 +04:00
|
|
|
class IDBRequest;
|
|
|
|
class IndexMetadata;
|
|
|
|
class ObjectStoreSpec;
|
|
|
|
class OpenCursorParams;
|
|
|
|
class PBackgroundIDBDatabaseFileChild;
|
|
|
|
class RequestParams;
|
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
class IDBTransaction final
|
2014-09-27 03:21:57 +04:00
|
|
|
: public IDBWrapperCache
|
|
|
|
, public nsIRunnable
|
2010-06-23 23:46:08 +04:00
|
|
|
{
|
2015-03-19 00:20:59 +03:00
|
|
|
friend class BackgroundCursorChild;
|
|
|
|
friend class BackgroundRequestChild;
|
|
|
|
|
2014-12-17 09:26:15 +03:00
|
|
|
class WorkerFeature;
|
|
|
|
friend class WorkerFeature;
|
|
|
|
|
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,
|
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:
|
|
|
|
nsRefPtr<IDBDatabase> mDatabase;
|
|
|
|
nsRefPtr<DOMError> mError;
|
|
|
|
nsTArray<nsString> mObjectStoreNames;
|
|
|
|
nsTArray<nsRefPtr<IDBObjectStore>> mObjectStores;
|
|
|
|
nsTArray<nsRefPtr<IDBObjectStore>> mDeletedObjectStores;
|
2014-12-17 09:26:15 +03:00
|
|
|
nsAutoPtr<WorkerFeature> mWorkerFeature;
|
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 {
|
|
|
|
BackgroundTransactionChild* mNormalBackgroundActor;
|
|
|
|
BackgroundVersionChangeTransactionChild* mVersionChangeBackgroundActor;
|
|
|
|
} 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
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
nsresult mAbortCode;
|
|
|
|
uint32_t mPendingRequestCount;
|
2014-09-13 20:12:19 +04:00
|
|
|
|
2014-11-14 05:20:38 +03:00
|
|
|
nsString mFilename;
|
|
|
|
uint32_t mLineNo;
|
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
ReadyState mReadyState;
|
|
|
|
Mode mMode;
|
|
|
|
|
|
|
|
bool mCreating;
|
2014-12-17 09:26:15 +03:00
|
|
|
bool mRegistered;
|
2014-09-27 03:21:57 +04:00
|
|
|
bool mAbortedByScript;
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
bool mSentCommitOrAbort;
|
|
|
|
bool mFiredCompleteOrAbort;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
public:
|
|
|
|
static already_AddRefed<IDBTransaction>
|
|
|
|
CreateVersionChange(IDBDatabase* aDatabase,
|
|
|
|
BackgroundVersionChangeTransactionChild* aActor,
|
2014-11-14 05:20:38 +03:00
|
|
|
IDBOpenDBRequest* aOpenRequest,
|
2014-09-27 03:21:57 +04:00
|
|
|
int64_t aNextObjectStoreId,
|
|
|
|
int64_t aNextIndexId);
|
|
|
|
|
|
|
|
static already_AddRefed<IDBTransaction>
|
|
|
|
Create(IDBDatabase* aDatabase,
|
|
|
|
const nsTArray<nsString>& aObjectStoreNames,
|
|
|
|
Mode aMode);
|
|
|
|
|
|
|
|
static IDBTransaction*
|
|
|
|
GetCurrent();
|
|
|
|
|
|
|
|
void
|
|
|
|
AssertIsOnOwningThread() const
|
|
|
|
#ifdef DEBUG
|
|
|
|
;
|
|
|
|
#else
|
|
|
|
{ }
|
|
|
|
#endif
|
2014-09-13 20:12:19 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
void
|
|
|
|
SetBackgroundActor(BackgroundTransactionChild* aBackgroundActor);
|
2014-09-13 20:12:19 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
void
|
|
|
|
ClearBackgroundActor()
|
2014-09-18 03:36:01 +04:00
|
|
|
{
|
2014-09-27 03:21:57 +04:00
|
|
|
AssertIsOnOwningThread();
|
|
|
|
|
|
|
|
if (mMode == VERSION_CHANGE) {
|
|
|
|
mBackgroundActor.mVersionChangeBackgroundActor = nullptr;
|
|
|
|
} else {
|
|
|
|
mBackgroundActor.mNormalBackgroundActor = nullptr;
|
|
|
|
}
|
2014-09-18 03:36:01 +04:00
|
|
|
}
|
2014-09-13 20:12:19 +04:00
|
|
|
|
2015-03-19 00:20:59 +03:00
|
|
|
BackgroundRequestChild*
|
|
|
|
StartRequest(IDBRequest* aRequest, const RequestParams& aParams);
|
2014-09-27 03:21:57 +04:00
|
|
|
|
|
|
|
void
|
|
|
|
OpenCursor(BackgroundCursorChild* aBackgroundActor,
|
|
|
|
const OpenCursorParams& aParams);
|
|
|
|
|
|
|
|
void
|
|
|
|
RefreshSpec(bool aMayDelete);
|
|
|
|
|
|
|
|
bool
|
|
|
|
IsOpen() const;
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
bool
|
|
|
|
IsFinished() const
|
2012-06-26 19:09:25 +04:00
|
|
|
{
|
2014-09-27 03:21:57 +04:00
|
|
|
AssertIsOnOwningThread();
|
2012-06-26 19:09:25 +04:00
|
|
|
return mReadyState > LOADING;
|
|
|
|
}
|
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
bool
|
|
|
|
IsWriteAllowed() const
|
2010-06-23 23:46:08 +04:00
|
|
|
{
|
2014-09-27 03:21:57 +04:00
|
|
|
AssertIsOnOwningThread();
|
2015-01-26 09:30:09 +03:00
|
|
|
return mMode == READ_WRITE ||
|
|
|
|
mMode == READ_WRITE_FLUSH ||
|
|
|
|
mMode == VERSION_CHANGE;
|
2010-06-23 23:46:08 +04:00
|
|
|
}
|
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
bool
|
|
|
|
IsAborted() const
|
2010-12-16 00:21:17 +03:00
|
|
|
{
|
2014-09-27 03:21:57 +04:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2014-11-14 05:20:38 +03:00
|
|
|
void
|
|
|
|
GetCallerLocation(nsAString& aFilename, uint32_t* aLineNo) const;
|
|
|
|
|
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
|
2010-10-19 21:58:52 +04:00
|
|
|
{
|
2014-09-27 03:21:57 +04:00
|
|
|
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
|
2010-08-27 00:57:25 +04:00
|
|
|
{
|
2014-09-27 03:21:57 +04:00
|
|
|
AssertIsOnOwningThread();
|
2010-09-10 02:15:38 +04:00
|
|
|
return mDatabase;
|
2010-08-27 00:57:25 +04:00
|
|
|
}
|
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
IDBDatabase*
|
|
|
|
Db() const
|
2011-12-17 04:40:47 +04:00
|
|
|
{
|
2014-09-27 03:21:57 +04:00
|
|
|
return Database();
|
2012-06-01 21:21:12 +04:00
|
|
|
}
|
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
const nsTArray<nsString>&
|
|
|
|
ObjectStoreNamesInternal() const
|
2014-09-18 03:36:01 +04:00
|
|
|
{
|
2014-09-27 03:21:57 +04:00
|
|
|
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(const ObjectStoreSpec& aSpec);
|
|
|
|
|
2014-09-13 20:12:19 +04:00
|
|
|
void
|
2014-09-27 03:21:57 +04:00
|
|
|
DeleteObjectStore(int64_t aObjectStoreId);
|
2014-09-18 03:36:01 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
void
|
|
|
|
CreateIndex(IDBObjectStore* aObjectStore, const 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
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
void
|
2012-06-29 20:48:34 +04:00
|
|
|
Abort(IDBRequest* aRequest);
|
2012-06-01 21:21:12 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
void
|
2012-06-29 20:48:34 +04:00
|
|
|
Abort(nsresult aAbortCode);
|
2012-06-25 23:15:17 +04:00
|
|
|
|
2014-10-16 08:56:52 +04:00
|
|
|
int64_t
|
|
|
|
LoggingSerialNumber() const
|
2013-03-16 10:58:50 +04:00
|
|
|
{
|
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
|
|
|
}
|
|
|
|
|
2013-07-29 21:12:21 +04:00
|
|
|
nsPIDOMWindow*
|
2014-09-27 03:21:57 +04:00
|
|
|
GetParentObject() const;
|
2013-07-29 21:12:21 +04:00
|
|
|
|
|
|
|
IDBTransactionMode
|
|
|
|
GetMode(ErrorResult& aRv) const;
|
|
|
|
|
|
|
|
DOMError*
|
2014-05-20 21:39:31 +04:00
|
|
|
GetError() const;
|
2013-07-29 21:12:21 +04:00
|
|
|
|
2013-07-31 19:48:36 +04:00
|
|
|
already_AddRefed<IDBObjectStore>
|
2013-07-29 21:12:21 +04:00
|
|
|
ObjectStore(const nsAString& aName, ErrorResult& aRv);
|
|
|
|
|
|
|
|
void
|
2014-09-27 03:21:57 +04:00
|
|
|
Abort(ErrorResult& aRv);
|
2013-07-29 21:12:21 +04:00
|
|
|
|
|
|
|
IMPL_EVENT_HANDLER(abort)
|
|
|
|
IMPL_EVENT_HANDLER(complete)
|
|
|
|
IMPL_EVENT_HANDLER(error)
|
|
|
|
|
2013-07-09 21:54:21 +04:00
|
|
|
already_AddRefed<DOMStringList>
|
2014-09-27 03:21:57 +04:00
|
|
|
ObjectStoreNames();
|
2014-09-18 03:36:01 +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
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
NS_DECL_ISUPPORTS_INHERITED
|
2010-06-23 23:46:08 +04:00
|
|
|
NS_DECL_NSIRUNNABLE
|
2014-09-27 03:21:57 +04:00
|
|
|
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(IDBTransaction, IDBWrapperCache)
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
// nsWrapperCache
|
|
|
|
virtual JSObject*
|
2015-03-21 19:28:04 +03:00
|
|
|
WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
|
2014-09-18 03:36:01 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
// nsIDOMEventTarget
|
|
|
|
virtual nsresult
|
2015-03-21 19:28:04 +03:00
|
|
|
PreHandleEvent(EventChainPreVisitor& aVisitor) override;
|
2014-09-18 03:36:01 +04:00
|
|
|
|
|
|
|
private:
|
2014-09-27 03:21:57 +04:00
|
|
|
IDBTransaction(IDBDatabase* aDatabase,
|
|
|
|
const nsTArray<nsString>& aObjectStoreNames,
|
|
|
|
Mode aMode);
|
|
|
|
~IDBTransaction();
|
2014-09-18 03:36:01 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
void
|
|
|
|
AbortInternal(nsresult aAbortCode, already_AddRefed<DOMError> 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
|
|
|
|
|
|
|
void
|
|
|
|
OnNewRequest();
|
|
|
|
|
|
|
|
void
|
|
|
|
OnRequestFinished(bool aActorDestroyedNormally);
|
2014-09-18 03:36:01 +04:00
|
|
|
};
|
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
} // namespace indexedDB
|
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2010-06-28 20:46:21 +04:00
|
|
|
#endif // mozilla_dom_indexeddb_idbtransaction_h__
|