2011-10-20 09:10:56 -07:00
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
|
|
|
*
|
|
|
|
* The Original Code is Indexed Database.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is
|
|
|
|
* The Mozilla Foundation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 2010
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
* Ben Turner <bent.mozilla@gmail.com>
|
|
|
|
* Kyle Huey <me@kylehuey.com>
|
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
|
|
|
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
|
|
|
|
|
|
|
#ifndef mozilla_dom_indexeddb_opendatabasehelper_h__
|
|
|
|
#define mozilla_dom_indexeddb_opendatabasehelper_h__
|
|
|
|
|
|
|
|
#include "AsyncConnectionHelper.h"
|
|
|
|
#include "DatabaseInfo.h"
|
|
|
|
#include "IDBDatabase.h"
|
|
|
|
#include "IDBRequest.h"
|
|
|
|
|
|
|
|
#include "nsIRunnable.h"
|
|
|
|
|
|
|
|
class mozIStorageConnection;
|
|
|
|
|
|
|
|
BEGIN_INDEXEDDB_NAMESPACE
|
|
|
|
|
2012-05-16 15:08:18 -07:00
|
|
|
enum FactoryPrivilege {
|
|
|
|
Content,
|
|
|
|
Chrome
|
|
|
|
};
|
|
|
|
|
2011-10-20 09:10:56 -07:00
|
|
|
class OpenDatabaseHelper : public HelperBase
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
OpenDatabaseHelper(IDBOpenDBRequest* aRequest,
|
|
|
|
const nsAString& aName,
|
|
|
|
const nsACString& aASCIIOrigin,
|
2011-11-07 16:15:45 -08:00
|
|
|
PRUint64 aRequestedVersion,
|
2012-05-16 15:08:18 -07:00
|
|
|
bool aForDeletion,
|
|
|
|
FactoryPrivilege aPrivilege)
|
2011-10-20 09:10:56 -07:00
|
|
|
: HelperBase(aRequest), mOpenDBRequest(aRequest), mName(aName),
|
|
|
|
mASCIIOrigin(aASCIIOrigin), mRequestedVersion(aRequestedVersion),
|
2012-05-16 15:08:18 -07:00
|
|
|
mForDeletion(aForDeletion), mPrivilege(aPrivilege),
|
|
|
|
mDatabaseId(nsnull), mCurrentVersion(0),
|
2011-12-07 15:24:20 -08:00
|
|
|
mLastObjectStoreId(0), mLastIndexId(0), mState(eCreated),
|
2011-12-16 16:40:47 -08:00
|
|
|
mResultCode(NS_OK), mLoadDBMetadata(false)
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult GetResultCode()
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2011-12-15 23:34:24 -08:00
|
|
|
static
|
|
|
|
nsresult CreateDatabaseConnection(const nsAString& aName,
|
|
|
|
nsIFile* aDBFile,
|
|
|
|
nsIFile* aFileManagerDirectory,
|
|
|
|
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();
|
2011-10-20 09:10:56 -07:00
|
|
|
nsresult GetSuccessResult(JSContext* aCx,
|
|
|
|
jsval* aVal);
|
|
|
|
void DispatchSuccessEvent();
|
|
|
|
void DispatchErrorEvent();
|
2011-10-22 04:56:19 -07:00
|
|
|
void ReleaseMainThreadObjects();
|
2011-10-20 09:10:56 -07:00
|
|
|
|
|
|
|
// Methods only called on the DB thread
|
|
|
|
nsresult DoDatabaseWork();
|
|
|
|
|
|
|
|
private:
|
|
|
|
// In-params.
|
|
|
|
nsRefPtr<IDBOpenDBRequest> mOpenDBRequest;
|
|
|
|
nsString mName;
|
|
|
|
nsCString mASCIIOrigin;
|
|
|
|
PRUint64 mRequestedVersion;
|
2011-11-07 16:15:45 -08:00
|
|
|
bool mForDeletion;
|
2012-05-16 15:08:18 -07:00
|
|
|
FactoryPrivilege mPrivilege;
|
2011-11-02 05:53:12 -07:00
|
|
|
nsCOMPtr<nsIAtom> mDatabaseId;
|
2011-10-20 09:10:56 -07:00
|
|
|
|
|
|
|
// Out-params.
|
2011-12-16 16:40:47 -08:00
|
|
|
nsTArray<nsRefPtr<ObjectStoreInfo> > mObjectStores;
|
2011-10-20 09:10:56 -07:00
|
|
|
PRUint64 mCurrentVersion;
|
|
|
|
nsString mDatabaseFilePath;
|
|
|
|
PRInt64 mLastObjectStoreId;
|
|
|
|
PRInt64 mLastIndexId;
|
|
|
|
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;
|
2011-10-20 09:10:56 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
END_INDEXEDDB_NAMESPACE
|
|
|
|
|
|
|
|
#endif // mozilla_dom_indexeddb_opendatabasehelper_h__
|