1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/indexedDB/DatabaseInfo.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,203 @@ 1.4 +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* vim: set ts=2 et sw=2 tw=80: */ 1.6 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.9 + 1.10 +#ifndef mozilla_dom_indexeddb_databaseinfo_h__ 1.11 +#define mozilla_dom_indexeddb_databaseinfo_h__ 1.12 + 1.13 +#include "mozilla/dom/indexedDB/IndexedDatabase.h" 1.14 + 1.15 +#include "mozilla/dom/quota/PersistenceType.h" 1.16 +#include "nsRefPtrHashtable.h" 1.17 +#include "nsHashKeys.h" 1.18 + 1.19 +#include "mozilla/dom/indexedDB/Key.h" 1.20 +#include "mozilla/dom/indexedDB/KeyPath.h" 1.21 +#include "mozilla/dom/indexedDB/IDBObjectStore.h" 1.22 + 1.23 +BEGIN_INDEXEDDB_NAMESPACE 1.24 + 1.25 +class IndexedDBDatabaseChild; 1.26 +struct ObjectStoreInfo; 1.27 + 1.28 +typedef nsRefPtrHashtable<nsStringHashKey, ObjectStoreInfo> 1.29 + ObjectStoreInfoHash; 1.30 + 1.31 +struct DatabaseInfoGuts 1.32 +{ 1.33 + typedef mozilla::dom::quota::PersistenceType PersistenceType; 1.34 + 1.35 + DatabaseInfoGuts() 1.36 + : nextObjectStoreId(1), nextIndexId(1) 1.37 + { } 1.38 + 1.39 + bool operator==(const DatabaseInfoGuts& aOther) const 1.40 + { 1.41 + return this->name == aOther.name && 1.42 + this->group == aOther.group && 1.43 + this->origin == aOther.origin && 1.44 + this->version == aOther.version && 1.45 + this->persistenceType == aOther.persistenceType && 1.46 + this->nextObjectStoreId == aOther.nextObjectStoreId && 1.47 + this->nextIndexId == aOther.nextIndexId; 1.48 + }; 1.49 + 1.50 + // Make sure to update ipc/SerializationHelpers.h when changing members here! 1.51 + nsString name; 1.52 + nsCString group; 1.53 + nsCString origin; 1.54 + uint64_t version; 1.55 + PersistenceType persistenceType; 1.56 + int64_t nextObjectStoreId; 1.57 + int64_t nextIndexId; 1.58 +}; 1.59 + 1.60 +struct DatabaseInfo MOZ_FINAL : public DatabaseInfoGuts 1.61 +{ 1.62 + DatabaseInfo() 1.63 + : cloned(false) 1.64 + { } 1.65 + 1.66 +private: 1.67 + // Private destructor, to discourage deletion outside of Release(): 1.68 + ~DatabaseInfo(); 1.69 + 1.70 +public: 1.71 + static bool Get(const nsACString& aId, 1.72 + DatabaseInfo** aInfo); 1.73 + 1.74 + static bool Put(DatabaseInfo* aInfo); 1.75 + 1.76 + static void Remove(const nsACString& aId); 1.77 + 1.78 + bool GetObjectStoreNames(nsTArray<nsString>& aNames); 1.79 + bool ContainsStoreName(const nsAString& aName); 1.80 + 1.81 + ObjectStoreInfo* GetObjectStore(const nsAString& aName); 1.82 + 1.83 + bool PutObjectStore(ObjectStoreInfo* aInfo); 1.84 + 1.85 + void RemoveObjectStore(const nsAString& aName); 1.86 + 1.87 + already_AddRefed<DatabaseInfo> Clone(); 1.88 + 1.89 + nsCString id; 1.90 + nsString filePath; 1.91 + bool cloned; 1.92 + 1.93 + nsAutoPtr<ObjectStoreInfoHash> objectStoreHash; 1.94 + 1.95 + NS_INLINE_DECL_REFCOUNTING(DatabaseInfo) 1.96 +}; 1.97 + 1.98 +struct IndexInfo 1.99 +{ 1.100 +#ifdef NS_BUILD_REFCNT_LOGGING 1.101 + IndexInfo(); 1.102 + IndexInfo(const IndexInfo& aOther); 1.103 + ~IndexInfo(); 1.104 +#else 1.105 + IndexInfo() 1.106 + : id(INT64_MIN), keyPath(0), unique(false), multiEntry(false) { } 1.107 +#endif 1.108 + 1.109 + bool operator==(const IndexInfo& aOther) const 1.110 + { 1.111 + return this->name == aOther.name && 1.112 + this->id == aOther.id && 1.113 + this->keyPath == aOther.keyPath && 1.114 + this->unique == aOther.unique && 1.115 + this->multiEntry == aOther.multiEntry; 1.116 + }; 1.117 + 1.118 + // Make sure to update ipc/SerializationHelpers.h when changing members here! 1.119 + nsString name; 1.120 + int64_t id; 1.121 + KeyPath keyPath; 1.122 + bool unique; 1.123 + bool multiEntry; 1.124 +}; 1.125 + 1.126 +struct ObjectStoreInfoGuts 1.127 +{ 1.128 + ObjectStoreInfoGuts() 1.129 + : id(0), keyPath(0), autoIncrement(false) 1.130 + { } 1.131 + 1.132 + bool operator==(const ObjectStoreInfoGuts& aOther) const 1.133 + { 1.134 + return this->name == aOther.name && 1.135 + this->id == aOther.id; 1.136 + }; 1.137 + 1.138 + // Make sure to update ipc/SerializationHelpers.h when changing members here! 1.139 + 1.140 + // Constant members, can be gotten on any thread 1.141 + nsString name; 1.142 + int64_t id; 1.143 + KeyPath keyPath; 1.144 + bool autoIncrement; 1.145 + 1.146 + // Main-thread only members. This must *not* be touched on the database 1.147 + // thread. 1.148 + nsTArray<IndexInfo> indexes; 1.149 +}; 1.150 + 1.151 +struct ObjectStoreInfo MOZ_FINAL : public ObjectStoreInfoGuts 1.152 +{ 1.153 +#ifdef NS_BUILD_REFCNT_LOGGING 1.154 + ObjectStoreInfo(); 1.155 +#else 1.156 + ObjectStoreInfo() 1.157 + : nextAutoIncrementId(0), comittedAutoIncrementId(0) { } 1.158 +#endif 1.159 + 1.160 + ObjectStoreInfo(ObjectStoreInfo& aOther); 1.161 + 1.162 +private: 1.163 + // Private destructor, to discourage deletion outside of Release(): 1.164 +#ifdef NS_BUILD_REFCNT_LOGGING 1.165 + ~ObjectStoreInfo(); 1.166 +#else 1.167 + ~ObjectStoreInfo() {} 1.168 +#endif 1.169 +public: 1.170 + 1.171 + // Database-thread members. After the ObjectStoreInfo has been initialized, 1.172 + // these can *only* be touced on the database thread. 1.173 + int64_t nextAutoIncrementId; 1.174 + int64_t comittedAutoIncrementId; 1.175 + 1.176 + // This is threadsafe since the ObjectStoreInfos are created on the database 1.177 + // thread but then only used from the main thread. Ideal would be if we 1.178 + // could transfer ownership from the database thread to the main thread, but 1.179 + // we don't have that ability yet. 1.180 + NS_INLINE_DECL_THREADSAFE_REFCOUNTING(ObjectStoreInfo) 1.181 +}; 1.182 + 1.183 +struct IndexUpdateInfo 1.184 +{ 1.185 +#ifdef NS_BUILD_REFCNT_LOGGING 1.186 + IndexUpdateInfo(); 1.187 + IndexUpdateInfo(const IndexUpdateInfo& aOther); 1.188 + ~IndexUpdateInfo(); 1.189 +#endif 1.190 + 1.191 + bool operator==(const IndexUpdateInfo& aOther) const 1.192 + { 1.193 + return this->indexId == aOther.indexId && 1.194 + this->indexUnique == aOther.indexUnique && 1.195 + this->value == aOther.value; 1.196 + }; 1.197 + 1.198 + // Make sure to update ipc/SerializationHelpers.h when changing members here! 1.199 + int64_t indexId; 1.200 + bool indexUnique; 1.201 + Key value; 1.202 +}; 1.203 + 1.204 +END_INDEXEDDB_NAMESPACE 1.205 + 1.206 +#endif // mozilla_dom_indexeddb_databaseinfo_h__