2010-06-23 23:46:08 +04: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 15:12:37 +04: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 23:46:08 +04:00
|
|
|
|
|
|
|
#ifndef mozilla_dom_indexeddb_databaseinfo_h__
|
|
|
|
#define mozilla_dom_indexeddb_databaseinfo_h__
|
|
|
|
|
2012-06-01 21:21:12 +04:00
|
|
|
#include "mozilla/dom/indexedDB/IndexedDatabase.h"
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2013-09-11 08:18:36 +04:00
|
|
|
#include "mozilla/dom/quota/PersistenceType.h"
|
|
|
|
#include "nsRefPtrHashtable.h"
|
|
|
|
#include "nsHashKeys.h"
|
|
|
|
|
2012-06-01 21:21:12 +04:00
|
|
|
#include "mozilla/dom/indexedDB/Key.h"
|
2012-06-22 02:27:13 +04:00
|
|
|
#include "mozilla/dom/indexedDB/KeyPath.h"
|
2012-06-01 21:21:12 +04:00
|
|
|
#include "mozilla/dom/indexedDB/IDBObjectStore.h"
|
2010-06-23 23:46:08 +04:00
|
|
|
|
|
|
|
BEGIN_INDEXEDDB_NAMESPACE
|
|
|
|
|
2012-06-01 21:21:12 +04:00
|
|
|
class IndexedDBDatabaseChild;
|
2011-11-08 03:20:20 +04:00
|
|
|
struct ObjectStoreInfo;
|
|
|
|
|
2011-12-17 04:40:47 +04:00
|
|
|
typedef nsRefPtrHashtable<nsStringHashKey, ObjectStoreInfo>
|
2011-11-08 03:20:20 +04:00
|
|
|
ObjectStoreInfoHash;
|
|
|
|
|
2012-06-01 21:21:12 +04:00
|
|
|
struct DatabaseInfoGuts
|
2010-06-23 23:46:08 +04:00
|
|
|
{
|
2013-09-11 08:18:36 +04:00
|
|
|
typedef mozilla::dom::quota::PersistenceType PersistenceType;
|
|
|
|
|
2012-06-01 21:21:12 +04:00
|
|
|
DatabaseInfoGuts()
|
|
|
|
: nextObjectStoreId(1), nextIndexId(1)
|
|
|
|
{ }
|
2011-11-08 04:15:45 +04:00
|
|
|
|
2012-06-01 21:21:12 +04:00
|
|
|
bool operator==(const DatabaseInfoGuts& aOther) const
|
|
|
|
{
|
|
|
|
return this->name == aOther.name &&
|
2013-09-11 08:18:36 +04:00
|
|
|
this->group == aOther.group &&
|
2012-06-01 21:21:12 +04:00
|
|
|
this->origin == aOther.origin &&
|
|
|
|
this->version == aOther.version &&
|
2013-09-11 08:18:36 +04:00
|
|
|
this->persistenceType == aOther.persistenceType &&
|
2012-06-01 21:21:12 +04:00
|
|
|
this->nextObjectStoreId == aOther.nextObjectStoreId &&
|
|
|
|
this->nextIndexId == aOther.nextIndexId;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Make sure to update ipc/SerializationHelpers.h when changing members here!
|
|
|
|
nsString name;
|
2013-09-11 08:18:36 +04:00
|
|
|
nsCString group;
|
2012-06-01 21:21:12 +04:00
|
|
|
nsCString origin;
|
2012-08-22 19:56:38 +04:00
|
|
|
uint64_t version;
|
2013-09-11 08:18:36 +04:00
|
|
|
PersistenceType persistenceType;
|
2012-08-22 19:56:38 +04:00
|
|
|
int64_t nextObjectStoreId;
|
|
|
|
int64_t nextIndexId;
|
2012-06-01 21:21:12 +04:00
|
|
|
};
|
|
|
|
|
2014-04-02 20:21:03 +04:00
|
|
|
struct DatabaseInfo MOZ_FINAL : public DatabaseInfoGuts
|
2012-06-01 21:21:12 +04:00
|
|
|
{
|
2010-06-23 23:46:08 +04:00
|
|
|
DatabaseInfo()
|
2012-06-01 21:21:12 +04:00
|
|
|
: cloned(false)
|
2011-10-25 16:49:31 +04:00
|
|
|
{ }
|
2012-06-01 21:21:12 +04:00
|
|
|
|
2014-04-02 20:21:03 +04:00
|
|
|
private:
|
|
|
|
// Private destructor, to discourage deletion outside of Release():
|
2011-11-08 04:06:13 +04:00
|
|
|
~DatabaseInfo();
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2014-04-02 20:21:03 +04:00
|
|
|
public:
|
2013-11-25 20:53:48 +04:00
|
|
|
static bool Get(const nsACString& aId,
|
2010-06-23 23:46:08 +04:00
|
|
|
DatabaseInfo** aInfo);
|
|
|
|
|
|
|
|
static bool Put(DatabaseInfo* aInfo);
|
|
|
|
|
2013-11-25 20:53:48 +04:00
|
|
|
static void Remove(const nsACString& aId);
|
2010-06-23 23:46:08 +04:00
|
|
|
|
|
|
|
bool GetObjectStoreNames(nsTArray<nsString>& aNames);
|
|
|
|
bool ContainsStoreName(const nsAString& aName);
|
2010-10-19 21:58:52 +04:00
|
|
|
|
2011-12-17 04:40:47 +04:00
|
|
|
ObjectStoreInfo* GetObjectStore(const nsAString& aName);
|
2011-11-08 04:15:43 +04:00
|
|
|
|
|
|
|
bool PutObjectStore(ObjectStoreInfo* aInfo);
|
|
|
|
|
|
|
|
void RemoveObjectStore(const nsAString& aName);
|
|
|
|
|
2011-11-08 04:15:45 +04:00
|
|
|
already_AddRefed<DatabaseInfo> Clone();
|
|
|
|
|
2013-11-25 20:53:48 +04:00
|
|
|
nsCString id;
|
2010-10-19 21:58:52 +04:00
|
|
|
nsString filePath;
|
2011-11-08 04:15:45 +04:00
|
|
|
bool cloned;
|
2010-10-19 21:58:52 +04:00
|
|
|
|
2011-11-08 03:20:20 +04:00
|
|
|
nsAutoPtr<ObjectStoreInfoHash> objectStoreHash;
|
|
|
|
|
2011-11-08 04:06:13 +04:00
|
|
|
NS_INLINE_DECL_REFCOUNTING(DatabaseInfo)
|
2010-06-23 23:46:08 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
struct IndexInfo
|
|
|
|
{
|
2010-10-19 21:58:42 +04:00
|
|
|
#ifdef NS_BUILD_REFCNT_LOGGING
|
|
|
|
IndexInfo();
|
2011-11-08 04:15:45 +04:00
|
|
|
IndexInfo(const IndexInfo& aOther);
|
2010-10-19 21:58:42 +04:00
|
|
|
~IndexInfo();
|
|
|
|
#else
|
2010-06-23 23:46:08 +04:00
|
|
|
IndexInfo()
|
2012-09-28 23:55:23 +04:00
|
|
|
: id(INT64_MIN), keyPath(0), unique(false), multiEntry(false) { }
|
2010-10-19 21:58:42 +04:00
|
|
|
#endif
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2012-06-01 21:21:12 +04:00
|
|
|
bool operator==(const IndexInfo& aOther) const
|
|
|
|
{
|
|
|
|
return this->name == aOther.name &&
|
|
|
|
this->id == aOther.id &&
|
|
|
|
this->keyPath == aOther.keyPath &&
|
|
|
|
this->unique == aOther.unique &&
|
|
|
|
this->multiEntry == aOther.multiEntry;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Make sure to update ipc/SerializationHelpers.h when changing members here!
|
2010-06-23 23:46:08 +04:00
|
|
|
nsString name;
|
2012-08-22 19:56:38 +04:00
|
|
|
int64_t id;
|
2012-06-22 02:27:13 +04:00
|
|
|
KeyPath keyPath;
|
2010-06-23 23:46:08 +04:00
|
|
|
bool unique;
|
2011-12-04 21:39:01 +04:00
|
|
|
bool multiEntry;
|
2010-06-23 23:46:08 +04:00
|
|
|
};
|
|
|
|
|
2012-06-01 21:21:12 +04:00
|
|
|
struct ObjectStoreInfoGuts
|
|
|
|
{
|
|
|
|
ObjectStoreInfoGuts()
|
2012-06-22 02:27:13 +04:00
|
|
|
: id(0), keyPath(0), autoIncrement(false)
|
2012-06-01 21:21:12 +04:00
|
|
|
{ }
|
|
|
|
|
|
|
|
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;
|
2012-08-22 19:56:38 +04:00
|
|
|
int64_t id;
|
2012-06-22 02:27:13 +04:00
|
|
|
KeyPath keyPath;
|
2012-06-01 21:21:12 +04:00
|
|
|
bool autoIncrement;
|
|
|
|
|
2012-06-29 20:48:34 +04:00
|
|
|
// Main-thread only members. This must *not* be touched on the database
|
|
|
|
// thread.
|
2012-06-01 21:21:12 +04:00
|
|
|
nsTArray<IndexInfo> indexes;
|
|
|
|
};
|
|
|
|
|
2014-04-02 20:21:03 +04:00
|
|
|
struct ObjectStoreInfo MOZ_FINAL : public ObjectStoreInfoGuts
|
2010-06-23 23:46:08 +04:00
|
|
|
{
|
2010-10-19 21:58:42 +04:00
|
|
|
#ifdef NS_BUILD_REFCNT_LOGGING
|
|
|
|
ObjectStoreInfo();
|
2011-12-17 04:40:47 +04:00
|
|
|
#else
|
|
|
|
ObjectStoreInfo()
|
2012-06-01 21:21:12 +04:00
|
|
|
: nextAutoIncrementId(0), comittedAutoIncrementId(0) { }
|
2011-12-17 04:40:47 +04:00
|
|
|
#endif
|
|
|
|
|
2011-11-08 04:15:45 +04:00
|
|
|
ObjectStoreInfo(ObjectStoreInfo& aOther);
|
2011-12-17 04:40:47 +04:00
|
|
|
|
|
|
|
private:
|
2014-04-02 20:21:03 +04:00
|
|
|
// Private destructor, to discourage deletion outside of Release():
|
2011-12-17 04:40:47 +04:00
|
|
|
#ifdef NS_BUILD_REFCNT_LOGGING
|
2010-10-19 21:58:42 +04:00
|
|
|
~ObjectStoreInfo();
|
|
|
|
#else
|
2011-12-17 04:40:47 +04:00
|
|
|
~ObjectStoreInfo() {}
|
2010-10-19 21:58:42 +04:00
|
|
|
#endif
|
2011-12-17 04:40:47 +04:00
|
|
|
public:
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2011-12-17 04:40:47 +04:00
|
|
|
// Database-thread members. After the ObjectStoreInfo has been initialized,
|
|
|
|
// these can *only* be touced on the database thread.
|
2012-08-22 19:56:38 +04:00
|
|
|
int64_t nextAutoIncrementId;
|
|
|
|
int64_t comittedAutoIncrementId;
|
2011-12-17 04:40:47 +04:00
|
|
|
|
|
|
|
// 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 23:46:08 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
struct IndexUpdateInfo
|
|
|
|
{
|
2010-10-19 21:58:42 +04:00
|
|
|
#ifdef NS_BUILD_REFCNT_LOGGING
|
|
|
|
IndexUpdateInfo();
|
2012-06-20 05:50:39 +04:00
|
|
|
IndexUpdateInfo(const IndexUpdateInfo& aOther);
|
2010-10-19 21:58:42 +04:00
|
|
|
~IndexUpdateInfo();
|
|
|
|
#endif
|
|
|
|
|
2012-06-01 21:21:12 +04: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!
|
2012-08-22 19:56:38 +04:00
|
|
|
int64_t indexId;
|
2011-12-04 21:39:01 +04:00
|
|
|
bool indexUnique;
|
2010-06-23 23:46:08 +04:00
|
|
|
Key value;
|
|
|
|
};
|
|
|
|
|
|
|
|
END_INDEXEDDB_NAMESPACE
|
|
|
|
|
|
|
|
#endif // mozilla_dom_indexeddb_databaseinfo_h__
|