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/. */
|
2011-10-20 09:10:56 -07:00
|
|
|
|
|
|
|
#ifndef mozilla_dom_indexeddb_opendatabasehelper_h__
|
|
|
|
#define mozilla_dom_indexeddb_opendatabasehelper_h__
|
|
|
|
|
|
|
|
#include "AsyncConnectionHelper.h"
|
2013-03-31 17:10:27 -07:00
|
|
|
|
|
|
|
#include "nsIRunnable.h"
|
|
|
|
|
|
|
|
#include "mozilla/dom/quota/StoragePrivilege.h"
|
|
|
|
|
2011-10-20 09:10:56 -07:00
|
|
|
#include "DatabaseInfo.h"
|
|
|
|
#include "IDBDatabase.h"
|
|
|
|
#include "IDBRequest.h"
|
|
|
|
|
|
|
|
class mozIStorageConnection;
|
|
|
|
|
2012-08-01 23:02:29 -07:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
class ContentParent;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-10-20 09:10:56 -07:00
|
|
|
BEGIN_INDEXEDDB_NAMESPACE
|
|
|
|
|
2013-03-31 17:10:27 -07:00
|
|
|
class CheckPermissionsHelper;
|
|
|
|
|
2011-10-20 09:10:56 -07:00
|
|
|
class OpenDatabaseHelper : public HelperBase
|
|
|
|
{
|
2013-03-31 17:10:27 -07:00
|
|
|
friend class CheckPermissionsHelper;
|
|
|
|
|
2013-03-26 04:13:17 -07:00
|
|
|
typedef mozilla::dom::quota::StoragePrivilege StoragePrivilege;
|
|
|
|
|
2011-10-20 09:10:56 -07:00
|
|
|
public:
|
|
|
|
OpenDatabaseHelper(IDBOpenDBRequest* aRequest,
|
|
|
|
const nsAString& aName,
|
|
|
|
const nsACString& aASCIIOrigin,
|
2012-08-22 08:56:38 -07:00
|
|
|
uint64_t aRequestedVersion,
|
2012-08-01 14:09:23 -07:00
|
|
|
bool aForDeletion,
|
2012-08-01 23:02:29 -07:00
|
|
|
mozilla::dom::ContentParent* aContentParent,
|
2013-03-26 04:13:17 -07:00
|
|
|
StoragePrivilege aPrivilege)
|
2011-10-20 09:10:56 -07:00
|
|
|
: HelperBase(aRequest), mOpenDBRequest(aRequest), mName(aName),
|
|
|
|
mASCIIOrigin(aASCIIOrigin), mRequestedVersion(aRequestedVersion),
|
2012-08-01 14:09:23 -07:00
|
|
|
mForDeletion(aForDeletion), mPrivilege(aPrivilege), mDatabaseId(nullptr),
|
2012-08-01 23:02:29 -07:00
|
|
|
mContentParent(aContentParent), mCurrentVersion(0), mLastObjectStoreId(0),
|
|
|
|
mLastIndexId(0), mState(eCreated), mResultCode(NS_OK),
|
2013-03-31 17:10:27 -07:00
|
|
|
mLoadDBMetadata(false),
|
|
|
|
mTrackingQuota(aPrivilege != mozilla::dom::quota::Chrome)
|
2011-11-07 16:15:45 -08:00
|
|
|
{
|
|
|
|
NS_ASSERTION(!aForDeletion || !aRequestedVersion,
|
|
|
|
"Can't be for deletion and request a version!");
|
|
|
|
}
|
2011-10-20 09:10:56 -07:00
|
|
|
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
NS_DECL_NSIRUNNABLE
|
|
|
|
|
2011-11-02 05:53:12 -07:00
|
|
|
nsresult Init();
|
|
|
|
|
2011-10-20 09:10:56 -07:00
|
|
|
nsresult Dispatch(nsIEventTarget* aDatabaseThread);
|
|
|
|
nsresult RunImmediately();
|
|
|
|
|
|
|
|
void SetError(nsresult rv)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(NS_FAILED(rv), "Why are you telling me?");
|
|
|
|
mResultCode = rv;
|
|
|
|
}
|
|
|
|
|
2012-06-01 10:21:12 -07:00
|
|
|
virtual nsresult GetResultCode() MOZ_OVERRIDE
|
2011-10-20 09:10:56 -07:00
|
|
|
{
|
|
|
|
return mResultCode;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult NotifySetVersionFinished();
|
2011-11-07 16:15:45 -08:00
|
|
|
nsresult NotifyDeleteFinished();
|
2011-10-25 05:49:31 -07:00
|
|
|
void BlockDatabase();
|
2011-10-20 09:10:56 -07:00
|
|
|
|
2011-11-02 05:53:12 -07:00
|
|
|
nsIAtom* Id() const
|
|
|
|
{
|
|
|
|
return mDatabaseId.get();
|
|
|
|
}
|
|
|
|
|
|
|
|
IDBDatabase* Database() const
|
|
|
|
{
|
|
|
|
NS_ASSERTION(mDatabase, "Calling at the wrong time!");
|
|
|
|
return mDatabase;
|
|
|
|
}
|
|
|
|
|
2013-03-26 04:13:17 -07:00
|
|
|
const StoragePrivilege& Privilege() const
|
2012-12-17 11:25:10 -08:00
|
|
|
{
|
|
|
|
return mPrivilege;
|
|
|
|
}
|
|
|
|
|
2011-12-15 23:34:24 -08:00
|
|
|
static
|
2012-12-17 11:25:10 -08:00
|
|
|
nsresult CreateDatabaseConnection(nsIFile* aDBFile,
|
|
|
|
nsIFile* aFMDirectory,
|
|
|
|
const nsAString& aName,
|
|
|
|
const nsACString& aOrigin,
|
2011-12-15 23:34:24 -08:00
|
|
|
mozIStorageConnection** aConnection);
|
|
|
|
|
2011-10-20 09:10:56 -07:00
|
|
|
protected:
|
|
|
|
// Methods only called on the main thread
|
|
|
|
nsresult EnsureSuccessResult();
|
|
|
|
nsresult StartSetVersion();
|
2011-11-07 16:15:45 -08:00
|
|
|
nsresult StartDelete();
|
2012-06-01 10:21:12 -07:00
|
|
|
virtual nsresult GetSuccessResult(JSContext* aCx,
|
|
|
|
jsval* aVal) MOZ_OVERRIDE;
|
2011-10-20 09:10:56 -07:00
|
|
|
void DispatchSuccessEvent();
|
|
|
|
void DispatchErrorEvent();
|
2012-06-01 10:21:12 -07:00
|
|
|
virtual void ReleaseMainThreadObjects() MOZ_OVERRIDE;
|
2011-10-20 09:10:56 -07:00
|
|
|
|
2013-03-31 17:10:27 -07:00
|
|
|
// Called by CheckPermissionsHelper on the main thread before dispatch.
|
|
|
|
void SetUnlimitedQuotaAllowed()
|
|
|
|
{
|
|
|
|
mTrackingQuota = false;
|
|
|
|
}
|
|
|
|
|
2011-10-20 09:10:56 -07:00
|
|
|
// Methods only called on the DB thread
|
|
|
|
nsresult DoDatabaseWork();
|
|
|
|
|
|
|
|
// In-params.
|
|
|
|
nsRefPtr<IDBOpenDBRequest> mOpenDBRequest;
|
|
|
|
nsString mName;
|
|
|
|
nsCString mASCIIOrigin;
|
2012-08-22 08:56:38 -07:00
|
|
|
uint64_t mRequestedVersion;
|
2011-11-07 16:15:45 -08:00
|
|
|
bool mForDeletion;
|
2013-03-26 04:13:17 -07:00
|
|
|
StoragePrivilege mPrivilege;
|
2011-11-02 05:53:12 -07:00
|
|
|
nsCOMPtr<nsIAtom> mDatabaseId;
|
2012-08-01 23:02:29 -07:00
|
|
|
mozilla::dom::ContentParent* mContentParent;
|
2011-10-20 09:10:56 -07:00
|
|
|
|
|
|
|
// Out-params.
|
2011-12-16 16:40:47 -08:00
|
|
|
nsTArray<nsRefPtr<ObjectStoreInfo> > mObjectStores;
|
2012-08-22 08:56:38 -07:00
|
|
|
uint64_t mCurrentVersion;
|
2011-10-20 09:10:56 -07:00
|
|
|
nsString mDatabaseFilePath;
|
2012-08-22 08:56:38 -07:00
|
|
|
int64_t mLastObjectStoreId;
|
|
|
|
int64_t mLastIndexId;
|
2011-10-20 09:10:56 -07:00
|
|
|
nsRefPtr<IDBDatabase> mDatabase;
|
|
|
|
|
|
|
|
// State variables
|
|
|
|
enum OpenDatabaseState {
|
|
|
|
eCreated = 0, // Not yet dispatched to the DB thread
|
|
|
|
eDBWork, // Waiting to do/doing work on the DB thread
|
|
|
|
eFiringEvents, // Waiting to fire/firing events on the main thread
|
|
|
|
eSetVersionPending, // Waiting on a SetVersionHelper
|
|
|
|
eSetVersionCompleted, // SetVersionHelper is done
|
2011-11-07 16:15:45 -08:00
|
|
|
eDeletePending, // Waiting on a DeleteDatabaseHelper
|
|
|
|
eDeleteCompleted, // DeleteDatabaseHelper is done
|
2011-10-20 09:10:56 -07:00
|
|
|
};
|
|
|
|
OpenDatabaseState mState;
|
|
|
|
nsresult mResultCode;
|
2011-12-15 23:34:24 -08:00
|
|
|
|
|
|
|
nsRefPtr<FileManager> mFileManager;
|
2011-12-16 16:40:47 -08:00
|
|
|
|
|
|
|
nsRefPtr<DatabaseInfo> mDBInfo;
|
|
|
|
bool mLoadDBMetadata;
|
2013-03-31 17:10:27 -07:00
|
|
|
bool mTrackingQuota;
|
2011-10-20 09:10:56 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
END_INDEXEDDB_NAMESPACE
|
|
|
|
|
2012-08-01 23:02:29 -07:00
|
|
|
#endif // mozilla_dom_indexeddb_opendatabasehelper_h__
|