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: */
|
|
|
|
/* ***** 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>
|
|
|
|
*
|
|
|
|
* 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_databaseinfo_h__
|
|
|
|
#define mozilla_dom_indexeddb_databaseinfo_h__
|
|
|
|
|
|
|
|
// Only meant to be included in IndexedDB source files, not exported.
|
|
|
|
#include "IndexedDatabase.h"
|
|
|
|
|
2011-11-03 08:57:30 -07:00
|
|
|
#include "Key.h"
|
2010-06-28 11:51:06 -07:00
|
|
|
#include "IDBObjectStore.h"
|
2010-06-23 12:46:08 -07:00
|
|
|
|
2011-12-16 16:40:47 -08:00
|
|
|
#include "nsRefPtrHashtable.h"
|
2011-11-07 15:20:20 -08:00
|
|
|
#include "nsHashKeys.h"
|
|
|
|
|
2010-06-23 12:46:08 -07:00
|
|
|
BEGIN_INDEXEDDB_NAMESPACE
|
|
|
|
|
2011-11-07 15:20:20 -08:00
|
|
|
struct ObjectStoreInfo;
|
|
|
|
|
2011-12-16 16:40:47 -08:00
|
|
|
typedef nsRefPtrHashtable<nsStringHashKey, ObjectStoreInfo>
|
2011-11-07 15:20:20 -08:00
|
|
|
ObjectStoreInfoHash;
|
|
|
|
|
2011-11-07 16:15:45 -08:00
|
|
|
class IDBDatabase;
|
|
|
|
class OpenDatabaseHelper;
|
|
|
|
|
2010-06-23 12:46:08 -07:00
|
|
|
struct DatabaseInfo
|
|
|
|
{
|
2011-11-07 16:15:45 -08:00
|
|
|
friend class IDBDatabase;
|
|
|
|
friend class OpenDatabaseHelper;
|
|
|
|
|
|
|
|
private:
|
2010-06-23 12:46:08 -07:00
|
|
|
DatabaseInfo()
|
2011-11-07 16:06:13 -08:00
|
|
|
: nextObjectStoreId(1),
|
|
|
|
nextIndexId(1),
|
2011-11-07 16:15:45 -08:00
|
|
|
cloned(false)
|
2011-10-25 05:49:31 -07:00
|
|
|
{ }
|
2011-11-07 16:06:13 -08:00
|
|
|
~DatabaseInfo();
|
2010-06-23 12:46:08 -07:00
|
|
|
|
2011-11-02 05:53:12 -07:00
|
|
|
static bool Get(nsIAtom* aId,
|
2010-06-23 12:46:08 -07:00
|
|
|
DatabaseInfo** aInfo);
|
|
|
|
|
|
|
|
static bool Put(DatabaseInfo* aInfo);
|
|
|
|
|
2011-12-16 16:40:47 -08:00
|
|
|
public:
|
2011-11-02 05:53:12 -07:00
|
|
|
static void Remove(nsIAtom* aId);
|
2010-06-23 12:46:08 -07:00
|
|
|
|
2011-12-16 16:40:47 -08:00
|
|
|
static void RemoveAllForOrigin(const nsACString& aOrigin);
|
|
|
|
|
2010-06-23 12:46:08 -07:00
|
|
|
bool GetObjectStoreNames(nsTArray<nsString>& aNames);
|
|
|
|
bool ContainsStoreName(const nsAString& aName);
|
2010-10-19 10:58:52 -07:00
|
|
|
|
2011-12-16 16:40:47 -08:00
|
|
|
ObjectStoreInfo* GetObjectStore(const nsAString& aName);
|
2011-11-07 16:15:43 -08:00
|
|
|
|
|
|
|
bool PutObjectStore(ObjectStoreInfo* aInfo);
|
|
|
|
|
|
|
|
void RemoveObjectStore(const nsAString& aName);
|
|
|
|
|
2011-11-07 16:15:45 -08:00
|
|
|
already_AddRefed<DatabaseInfo> Clone();
|
|
|
|
|
2010-10-19 10:58:52 -07:00
|
|
|
nsString name;
|
2011-12-16 16:40:47 -08:00
|
|
|
nsCString origin;
|
2011-10-20 09:10:56 -07:00
|
|
|
PRUint64 version;
|
2011-12-16 16:40:47 -08:00
|
|
|
nsCOMPtr<nsIAtom> id;
|
2010-10-19 10:58:52 -07:00
|
|
|
nsString filePath;
|
|
|
|
PRInt64 nextObjectStoreId;
|
|
|
|
PRInt64 nextIndexId;
|
2011-11-07 16:15:45 -08:00
|
|
|
bool cloned;
|
2010-10-19 10:58:52 -07:00
|
|
|
|
2011-11-07 15:20:20 -08:00
|
|
|
nsAutoPtr<ObjectStoreInfoHash> objectStoreHash;
|
|
|
|
|
2011-11-07 16:06:13 -08:00
|
|
|
NS_INLINE_DECL_REFCOUNTING(DatabaseInfo)
|
2010-06-23 12:46:08 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
struct IndexInfo
|
|
|
|
{
|
2010-10-19 10:58:42 -07:00
|
|
|
#ifdef NS_BUILD_REFCNT_LOGGING
|
|
|
|
IndexInfo();
|
2011-11-07 16:15:45 -08:00
|
|
|
IndexInfo(const IndexInfo& aOther);
|
2010-10-19 10:58:42 -07:00
|
|
|
~IndexInfo();
|
|
|
|
#else
|
2010-06-23 12:46:08 -07:00
|
|
|
IndexInfo()
|
2011-12-16 16:40:47 -08:00
|
|
|
: id(LL_MININT), unique(false), multiEntry(false) { }
|
2010-10-19 10:58:42 -07:00
|
|
|
#endif
|
2010-06-23 12:46:08 -07:00
|
|
|
|
|
|
|
PRInt64 id;
|
|
|
|
nsString name;
|
|
|
|
nsString keyPath;
|
|
|
|
bool unique;
|
2011-12-04 09:39:01 -08:00
|
|
|
bool multiEntry;
|
2010-06-23 12:46:08 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
struct ObjectStoreInfo
|
|
|
|
{
|
2010-10-19 10:58:42 -07:00
|
|
|
#ifdef NS_BUILD_REFCNT_LOGGING
|
|
|
|
ObjectStoreInfo();
|
2011-12-16 16:40:47 -08:00
|
|
|
#else
|
|
|
|
ObjectStoreInfo()
|
|
|
|
: id(0), nextAutoIncrementId(0), comittedAutoIncrementId(0) { }
|
|
|
|
#endif
|
|
|
|
|
2011-11-07 16:15:45 -08:00
|
|
|
ObjectStoreInfo(ObjectStoreInfo& aOther);
|
2011-12-16 16:40:47 -08:00
|
|
|
|
|
|
|
private:
|
|
|
|
#ifdef NS_BUILD_REFCNT_LOGGING
|
2010-10-19 10:58:42 -07:00
|
|
|
~ObjectStoreInfo();
|
|
|
|
#else
|
2011-12-16 16:40:47 -08:00
|
|
|
~ObjectStoreInfo() {}
|
2010-10-19 10:58:42 -07:00
|
|
|
#endif
|
2011-12-16 16:40:47 -08:00
|
|
|
public:
|
2010-06-23 12:46:08 -07:00
|
|
|
|
2011-12-16 16:40:47 -08:00
|
|
|
// Constant members, can be gotten on any thread
|
2010-10-19 10:58:52 -07:00
|
|
|
nsString name;
|
|
|
|
PRInt64 id;
|
|
|
|
nsString keyPath;
|
2011-12-16 16:40:47 -08:00
|
|
|
|
|
|
|
// Main-thread only members. This must *not* be touced on the database thread
|
2010-10-19 10:58:52 -07:00
|
|
|
nsTArray<IndexInfo> indexes;
|
2011-12-16 16:40:47 -08:00
|
|
|
|
|
|
|
// Database-thread members. After the ObjectStoreInfo has been initialized,
|
|
|
|
// these can *only* be touced on the database thread.
|
|
|
|
PRInt64 nextAutoIncrementId;
|
|
|
|
PRInt64 comittedAutoIncrementId;
|
|
|
|
|
|
|
|
// This is threadsafe since the ObjectStoreInfos are created on the database
|
|
|
|
// thread but then only used from the main thread. Ideal would be if we
|
|
|
|
// could transfer ownership from the database thread to the main thread, but
|
|
|
|
// we don't have that ability yet.
|
|
|
|
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(ObjectStoreInfo)
|
2010-06-23 12:46:08 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
struct IndexUpdateInfo
|
|
|
|
{
|
2010-10-19 10:58:42 -07:00
|
|
|
#ifdef NS_BUILD_REFCNT_LOGGING
|
|
|
|
IndexUpdateInfo();
|
|
|
|
~IndexUpdateInfo();
|
|
|
|
#endif
|
|
|
|
|
2011-12-04 09:39:01 -08:00
|
|
|
PRInt64 indexId;
|
|
|
|
bool indexUnique;
|
2010-06-23 12:46:08 -07:00
|
|
|
Key value;
|
|
|
|
};
|
|
|
|
|
|
|
|
END_INDEXEDDB_NAMESPACE
|
|
|
|
|
|
|
|
#endif // mozilla_dom_indexeddb_databaseinfo_h__
|