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"
|
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/IDBWrapperCache.h"
|
2014-09-26 16:21:57 -07:00
|
|
|
#include "nsAutoPtr.h"
|
|
|
|
#include "nsCycleCollectionParticipant.h"
|
|
|
|
#include "nsIRunnable.h"
|
|
|
|
#include "nsString.h"
|
|
|
|
#include "nsTArray.h"
|
2012-01-24 02:03:37 -08:00
|
|
|
|
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 {
|
2014-09-26 16:21:57 -07:00
|
|
|
|
|
|
|
class ErrorResult;
|
2014-03-17 21:48:19 -07:00
|
|
|
class EventChainPreVisitor;
|
|
|
|
|
2014-09-26 16:21:57 -07:00
|
|
|
namespace dom {
|
2010-06-23 12:46:08 -07:00
|
|
|
|
2014-09-26 16:21:57 -07:00
|
|
|
class DOMError;
|
|
|
|
class DOMStringList;
|
|
|
|
class PBlobChild;
|
2011-10-20 09:10:56 -07:00
|
|
|
|
2014-09-26 16:21:57 -07:00
|
|
|
namespace indexedDB {
|
2011-10-20 09:10:56 -07:00
|
|
|
|
2014-09-26 16:21:57 -07:00
|
|
|
class BackgroundCursorChild;
|
|
|
|
class BackgroundRequestChild;
|
|
|
|
class BackgroundTransactionChild;
|
|
|
|
class BackgroundVersionChangeTransactionChild;
|
|
|
|
class IDBDatabase;
|
|
|
|
class IDBObjectStore;
|
2014-11-13 18:20:38 -08:00
|
|
|
class IDBOpenDBRequest;
|
2014-09-26 16:21:57 -07:00
|
|
|
class IDBRequest;
|
|
|
|
class IndexMetadata;
|
|
|
|
class ObjectStoreSpec;
|
|
|
|
class OpenCursorParams;
|
|
|
|
class PBackgroundIDBDatabaseFileChild;
|
|
|
|
class RequestParams;
|
|
|
|
|
|
|
|
class IDBTransaction MOZ_FINAL
|
|
|
|
: public IDBWrapperCache
|
|
|
|
, public nsIRunnable
|
2010-06-23 12:46:08 -07:00
|
|
|
{
|
|
|
|
public:
|
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
|
|
|
|
};
|
|
|
|
|
2014-09-26 16:21:57 -07:00
|
|
|
private:
|
|
|
|
nsRefPtr<IDBDatabase> mDatabase;
|
|
|
|
nsRefPtr<DOMError> mError;
|
|
|
|
nsTArray<nsString> mObjectStoreNames;
|
|
|
|
nsTArray<nsRefPtr<IDBObjectStore>> mObjectStores;
|
|
|
|
nsTArray<nsRefPtr<IDBObjectStore>> mDeletedObjectStores;
|
2010-10-19 10:58:52 -07:00
|
|
|
|
2014-09-26 16:21:57 -07: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 12:46:08 -07:00
|
|
|
|
2014-09-13 09:12:19 -07:00
|
|
|
|
2014-09-26 16:21:57 -07:00
|
|
|
// Only used for VERSION_CHANGE transactions.
|
|
|
|
int64_t mNextObjectStoreId;
|
|
|
|
int64_t mNextIndexId;
|
2010-06-23 12:46:08 -07:00
|
|
|
|
2014-09-26 16:21:57 -07:00
|
|
|
#ifdef MOZ_ENABLE_PROFILER_SPS
|
|
|
|
uint64_t mSerialNumber;
|
|
|
|
#endif
|
2014-09-13 09:12:19 -07:00
|
|
|
|
2014-09-26 16:21:57 -07:00
|
|
|
nsresult mAbortCode;
|
|
|
|
uint32_t mPendingRequestCount;
|
2014-09-13 09:12:19 -07:00
|
|
|
|
2014-11-13 18:20:38 -08:00
|
|
|
nsString mFilename;
|
|
|
|
uint32_t mLineNo;
|
|
|
|
|
2014-09-26 16:21:57 -07:00
|
|
|
ReadyState mReadyState;
|
|
|
|
Mode mMode;
|
|
|
|
|
|
|
|
bool mCreating;
|
|
|
|
bool mAbortedByScript;
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
bool mSentCommitOrAbort;
|
|
|
|
bool mFiredCompleteOrAbort;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
public:
|
|
|
|
static already_AddRefed<IDBTransaction>
|
|
|
|
CreateVersionChange(IDBDatabase* aDatabase,
|
|
|
|
BackgroundVersionChangeTransactionChild* aActor,
|
2014-11-13 18:20:38 -08:00
|
|
|
IDBOpenDBRequest* aOpenRequest,
|
2014-09-26 16:21:57 -07: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 09:12:19 -07:00
|
|
|
|
2014-09-26 16:21:57 -07:00
|
|
|
void
|
|
|
|
SetBackgroundActor(BackgroundTransactionChild* aBackgroundActor);
|
2014-09-13 09:12:19 -07:00
|
|
|
|
2014-09-26 16:21:57 -07:00
|
|
|
void
|
|
|
|
ClearBackgroundActor()
|
2014-09-17 16:36:01 -07:00
|
|
|
{
|
2014-09-26 16:21:57 -07:00
|
|
|
AssertIsOnOwningThread();
|
|
|
|
|
|
|
|
if (mMode == VERSION_CHANGE) {
|
|
|
|
mBackgroundActor.mVersionChangeBackgroundActor = nullptr;
|
|
|
|
} else {
|
|
|
|
mBackgroundActor.mNormalBackgroundActor = nullptr;
|
|
|
|
}
|
2014-09-17 16:36:01 -07:00
|
|
|
}
|
2014-09-13 09:12:19 -07:00
|
|
|
|
2014-09-26 16:21:57 -07:00
|
|
|
void
|
|
|
|
StartRequest(BackgroundRequestChild* aBackgroundActor,
|
|
|
|
const RequestParams& aParams);
|
|
|
|
|
|
|
|
void
|
|
|
|
OpenCursor(BackgroundCursorChild* aBackgroundActor,
|
|
|
|
const OpenCursorParams& aParams);
|
|
|
|
|
|
|
|
void
|
|
|
|
RefreshSpec(bool aMayDelete);
|
|
|
|
|
|
|
|
void
|
|
|
|
OnNewRequest();
|
|
|
|
|
|
|
|
void
|
|
|
|
OnRequestFinished();
|
|
|
|
|
|
|
|
bool
|
|
|
|
IsOpen() const;
|
2010-06-23 12:46:08 -07:00
|
|
|
|
2014-09-26 16:21:57 -07:00
|
|
|
bool
|
|
|
|
IsFinished() const
|
2012-06-26 08:09:25 -07:00
|
|
|
{
|
2014-09-26 16:21:57 -07:00
|
|
|
AssertIsOnOwningThread();
|
2012-06-26 08:09:25 -07:00
|
|
|
return mReadyState > LOADING;
|
|
|
|
}
|
|
|
|
|
2014-09-26 16:21:57 -07:00
|
|
|
bool
|
|
|
|
IsWriteAllowed() const
|
2010-06-23 12:46:08 -07:00
|
|
|
{
|
2014-09-26 16:21:57 -07:00
|
|
|
AssertIsOnOwningThread();
|
2012-03-12 21:44:45 -07:00
|
|
|
return mMode == READ_WRITE || mMode == VERSION_CHANGE;
|
2010-06-23 12:46:08 -07:00
|
|
|
}
|
|
|
|
|
2014-09-26 16:21:57 -07:00
|
|
|
bool
|
|
|
|
IsAborted() const
|
2010-12-15 13:21:17 -08:00
|
|
|
{
|
2014-09-26 16:21:57 -07:00
|
|
|
AssertIsOnOwningThread();
|
2012-06-01 10:21:12 -07:00
|
|
|
return NS_FAILED(mAbortCode);
|
2010-12-15 13:21:17 -08:00
|
|
|
}
|
|
|
|
|
2014-11-13 18:20:38 -08:00
|
|
|
void
|
|
|
|
GetCallerLocation(nsAString& aFilename, uint32_t* aLineNo) const;
|
|
|
|
|
2012-03-12 21:44:45 -07:00
|
|
|
// 'Get' prefix is to avoid name collisions with the enum
|
2014-09-26 16:21:57 -07:00
|
|
|
Mode
|
|
|
|
GetMode() const
|
2010-10-19 10:58:52 -07:00
|
|
|
{
|
2014-09-26 16:21:57 -07:00
|
|
|
AssertIsOnOwningThread();
|
2010-10-19 10:58:52 -07:00
|
|
|
return mMode;
|
|
|
|
}
|
2010-06-23 12:46:08 -07:00
|
|
|
|
2014-09-26 16:21:57 -07:00
|
|
|
IDBDatabase*
|
|
|
|
Database() const
|
2010-08-26 13:57:25 -07:00
|
|
|
{
|
2014-09-26 16:21:57 -07:00
|
|
|
AssertIsOnOwningThread();
|
2010-09-09 15:15:38 -07:00
|
|
|
return mDatabase;
|
2010-08-26 13:57:25 -07:00
|
|
|
}
|
|
|
|
|
2014-09-26 16:21:57 -07:00
|
|
|
IDBDatabase*
|
|
|
|
Db() const
|
2011-12-16 16:40:47 -08:00
|
|
|
{
|
2014-09-26 16:21:57 -07:00
|
|
|
return Database();
|
2012-06-01 10:21:12 -07:00
|
|
|
}
|
|
|
|
|
2014-09-26 16:21:57 -07:00
|
|
|
const nsTArray<nsString>&
|
|
|
|
ObjectStoreNamesInternal() const
|
2014-09-17 16:36:01 -07:00
|
|
|
{
|
2014-09-26 16:21:57 -07:00
|
|
|
AssertIsOnOwningThread();
|
|
|
|
return mObjectStoreNames;
|
2014-09-17 16:36:01 -07:00
|
|
|
}
|
2012-11-09 19:29:07 -08:00
|
|
|
|
2014-09-26 16:21:57 -07:00
|
|
|
already_AddRefed<IDBObjectStore>
|
|
|
|
CreateObjectStore(const ObjectStoreSpec& aSpec);
|
|
|
|
|
2014-09-13 09:12:19 -07:00
|
|
|
void
|
2014-09-26 16:21:57 -07:00
|
|
|
DeleteObjectStore(int64_t aObjectStoreId);
|
2014-09-17 16:36:01 -07:00
|
|
|
|
2014-09-26 16:21:57 -07:00
|
|
|
void
|
|
|
|
CreateIndex(IDBObjectStore* aObjectStore, const IndexMetadata& aMetadata);
|
2014-09-17 16:36:01 -07:00
|
|
|
|
2014-09-26 16:21:57 -07:00
|
|
|
void
|
|
|
|
DeleteIndex(IDBObjectStore* aObjectStore, int64_t aIndexId);
|
2014-09-17 16:36:01 -07:00
|
|
|
|
2014-09-26 16:21:57 -07:00
|
|
|
void
|
2012-06-29 09:48:34 -07:00
|
|
|
Abort(IDBRequest* aRequest);
|
2012-06-01 10:21:12 -07:00
|
|
|
|
2014-09-26 16:21:57 -07:00
|
|
|
void
|
2012-06-29 09:48:34 -07:00
|
|
|
Abort(nsresult aAbortCode);
|
2012-06-25 12:15:17 -07:00
|
|
|
|
2013-03-15 23:58:50 -07:00
|
|
|
#ifdef MOZ_ENABLE_PROFILER_SPS
|
2014-09-26 16:21:57 -07:00
|
|
|
uint32_t
|
2013-03-15 23:58:50 -07:00
|
|
|
GetSerialNumber() const
|
|
|
|
{
|
2014-09-26 16:21:57 -07:00
|
|
|
AssertIsOnOwningThread();
|
2013-03-15 23:58:50 -07:00
|
|
|
return mSerialNumber;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2013-07-29 10:12:21 -07:00
|
|
|
nsPIDOMWindow*
|
2014-09-26 16:21:57 -07:00
|
|
|
GetParentObject() const;
|
2013-07-29 10:12:21 -07:00
|
|
|
|
|
|
|
IDBTransactionMode
|
|
|
|
GetMode(ErrorResult& aRv) const;
|
|
|
|
|
|
|
|
DOMError*
|
2014-05-20 10:39:31 -07:00
|
|
|
GetError() const;
|
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
|
2014-09-26 16:21:57 -07:00
|
|
|
Abort(ErrorResult& aRv);
|
2013-07-29 10:12:21 -07:00
|
|
|
|
|
|
|
IMPL_EVENT_HANDLER(abort)
|
|
|
|
IMPL_EVENT_HANDLER(complete)
|
|
|
|
IMPL_EVENT_HANDLER(error)
|
|
|
|
|
2013-07-09 10:54:21 -07:00
|
|
|
already_AddRefed<DOMStringList>
|
2014-09-26 16:21:57 -07:00
|
|
|
ObjectStoreNames();
|
2014-09-17 16:36:01 -07:00
|
|
|
|
2014-09-26 16:21:57 -07:00
|
|
|
void
|
|
|
|
FireCompleteOrAbortEvents(nsresult aResult);
|
2014-09-17 16:36:01 -07:00
|
|
|
|
2014-09-26 16:21:57 -07:00
|
|
|
// Only for VERSION_CHANGE transactions.
|
|
|
|
int64_t
|
|
|
|
NextObjectStoreId();
|
2014-09-17 16:36:01 -07:00
|
|
|
|
2014-09-26 16:21:57 -07:00
|
|
|
// Only for VERSION_CHANGE transactions.
|
|
|
|
int64_t
|
|
|
|
NextIndexId();
|
2014-09-17 16:36:01 -07:00
|
|
|
|
2014-09-26 16:21:57 -07:00
|
|
|
NS_DECL_ISUPPORTS_INHERITED
|
2010-06-23 12:46:08 -07:00
|
|
|
NS_DECL_NSIRUNNABLE
|
2014-09-26 16:21:57 -07:00
|
|
|
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(IDBTransaction, IDBWrapperCache)
|
2010-06-23 12:46:08 -07:00
|
|
|
|
2014-09-26 16:21:57 -07:00
|
|
|
// nsWrapperCache
|
|
|
|
virtual JSObject*
|
|
|
|
WrapObject(JSContext* aCx) MOZ_OVERRIDE;
|
2014-09-17 16:36:01 -07:00
|
|
|
|
2014-09-26 16:21:57 -07:00
|
|
|
// nsIDOMEventTarget
|
|
|
|
virtual nsresult
|
|
|
|
PreHandleEvent(EventChainPreVisitor& aVisitor) MOZ_OVERRIDE;
|
2014-09-17 16:36:01 -07:00
|
|
|
|
|
|
|
private:
|
2014-09-26 16:21:57 -07:00
|
|
|
IDBTransaction(IDBDatabase* aDatabase,
|
|
|
|
const nsTArray<nsString>& aObjectStoreNames,
|
|
|
|
Mode aMode);
|
|
|
|
~IDBTransaction();
|
2014-09-17 16:36:01 -07:00
|
|
|
|
2014-09-26 16:21:57 -07:00
|
|
|
void
|
|
|
|
AbortInternal(nsresult aAbortCode, already_AddRefed<DOMError> aError);
|
2014-09-17 16:36:01 -07:00
|
|
|
|
2014-09-26 16:21:57 -07:00
|
|
|
void
|
|
|
|
SendCommit();
|
2014-09-17 16:36:01 -07:00
|
|
|
|
2014-09-26 16:21:57 -07:00
|
|
|
void
|
|
|
|
SendAbort(nsresult aResultCode);
|
2014-09-17 16:36:01 -07:00
|
|
|
};
|
|
|
|
|
2014-09-26 16:21:57 -07:00
|
|
|
} // namespace indexedDB
|
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
2010-06-23 12:46:08 -07:00
|
|
|
|
2010-06-28 09:46:21 -07:00
|
|
|
#endif // mozilla_dom_indexeddb_idbtransaction_h__
|