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
|
|
|
|
|
|
|
#ifndef mozilla_dom_indexeddb_databaseinfo_h__
|
|
|
|
#define mozilla_dom_indexeddb_databaseinfo_h__
|
|
|
|
|
2012-06-01 10:21:12 -07:00
|
|
|
#include "mozilla/dom/indexedDB/IndexedDatabase.h"
|
2010-06-23 12:46:08 -07:00
|
|
|
|
2012-06-01 10:21:12 -07:00
|
|
|
#include "mozilla/dom/indexedDB/Key.h"
|
|
|
|
#include "mozilla/dom/indexedDB/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
|
|
|
|
|
2012-06-01 10:21:12 -07:00
|
|
|
class IndexedDBDatabaseChild;
|
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;
|
|
|
|
|
2012-06-01 10:21:12 -07:00
|
|
|
struct DatabaseInfoGuts
|
2010-06-23 12:46:08 -07:00
|
|
|
{
|
2012-06-01 10:21:12 -07:00
|
|
|
DatabaseInfoGuts()
|
|
|
|
: nextObjectStoreId(1), nextIndexId(1)
|
|
|
|
{ }
|
2011-11-07 16:15:45 -08:00
|
|
|
|
2012-06-01 10:21:12 -07:00
|
|
|
bool operator==(const DatabaseInfoGuts& aOther) const
|
|
|
|
{
|
|
|
|
return this->name == aOther.name &&
|
|
|
|
this->origin == aOther.origin &&
|
|
|
|
this->version == aOther.version &&
|
|
|
|
this->nextObjectStoreId == aOther.nextObjectStoreId &&
|
|
|
|
this->nextIndexId == aOther.nextIndexId;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Make sure to update ipc/SerializationHelpers.h when changing members here!
|
|
|
|
nsString name;
|
|
|
|
nsCString origin;
|
|
|
|
PRUint64 version;
|
|
|
|
PRInt64 nextObjectStoreId;
|
|
|
|
PRInt64 nextIndexId;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct DatabaseInfo : public DatabaseInfoGuts
|
|
|
|
{
|
2010-06-23 12:46:08 -07:00
|
|
|
DatabaseInfo()
|
2012-06-01 10:21:12 -07:00
|
|
|
: cloned(false)
|
2011-10-25 05:49:31 -07:00
|
|
|
{ }
|
2012-06-01 10:21:12 -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-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();
|
|
|
|
|
2011-12-16 16:40:47 -08:00
|
|
|
nsCOMPtr<nsIAtom> id;
|
2010-10-19 10:58:52 -07:00
|
|
|
nsString filePath;
|
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
|
|
|
|
2012-06-01 10:21:12 -07:00
|
|
|
bool operator==(const IndexInfo& aOther) const
|
|
|
|
{
|
|
|
|
return this->name == aOther.name &&
|
|
|
|
this->id == aOther.id &&
|
|
|
|
this->keyPath == aOther.keyPath &&
|
|
|
|
this->keyPathArray == aOther.keyPathArray &&
|
|
|
|
this->unique == aOther.unique &&
|
|
|
|
this->multiEntry == aOther.multiEntry;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Make sure to update ipc/SerializationHelpers.h when changing members here!
|
2010-06-23 12:46:08 -07:00
|
|
|
nsString name;
|
2012-06-01 10:21:12 -07:00
|
|
|
PRInt64 id;
|
2010-06-23 12:46:08 -07:00
|
|
|
nsString keyPath;
|
2011-12-20 02:59:07 -08:00
|
|
|
nsTArray<nsString> keyPathArray;
|
2010-06-23 12:46:08 -07:00
|
|
|
bool unique;
|
2011-12-04 09:39:01 -08:00
|
|
|
bool multiEntry;
|
2010-06-23 12:46:08 -07:00
|
|
|
};
|
|
|
|
|
2012-06-01 10:21:12 -07:00
|
|
|
struct ObjectStoreInfoGuts
|
|
|
|
{
|
|
|
|
ObjectStoreInfoGuts()
|
|
|
|
: id(0), autoIncrement(false)
|
|
|
|
{ }
|
|
|
|
|
|
|
|
bool operator==(const ObjectStoreInfoGuts& aOther) const
|
|
|
|
{
|
|
|
|
return this->name == aOther.name &&
|
|
|
|
this->id == aOther.id;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Make sure to update ipc/SerializationHelpers.h when changing members here!
|
|
|
|
|
|
|
|
// Constant members, can be gotten on any thread
|
|
|
|
nsString name;
|
|
|
|
PRInt64 id;
|
|
|
|
nsString keyPath;
|
|
|
|
nsTArray<nsString> keyPathArray;
|
|
|
|
bool autoIncrement;
|
|
|
|
|
|
|
|
// Main-thread only members. This must *not* be touced on the database thread
|
|
|
|
nsTArray<IndexInfo> indexes;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct ObjectStoreInfo : public ObjectStoreInfoGuts
|
2010-06-23 12:46:08 -07:00
|
|
|
{
|
2010-10-19 10:58:42 -07:00
|
|
|
#ifdef NS_BUILD_REFCNT_LOGGING
|
|
|
|
ObjectStoreInfo();
|
2011-12-16 16:40:47 -08:00
|
|
|
#else
|
|
|
|
ObjectStoreInfo()
|
2012-06-01 10:21:12 -07:00
|
|
|
: nextAutoIncrementId(0), comittedAutoIncrementId(0) { }
|
2011-12-16 16:40:47 -08:00
|
|
|
#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
|
|
|
// 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
|
|
|
|
|
2012-06-01 10:21:12 -07:00
|
|
|
bool operator==(const IndexUpdateInfo& aOther) const
|
|
|
|
{
|
|
|
|
return this->indexId == aOther.indexId &&
|
|
|
|
this->indexUnique == aOther.indexUnique &&
|
|
|
|
this->value == aOther.value;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Make sure to update ipc/SerializationHelpers.h when changing members here!
|
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__
|