dom/indexedDB/DatabaseInfo.h

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
michael@0 2 /* vim: set ts=2 et sw=2 tw=80: */
michael@0 3 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 4 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 6
michael@0 7 #ifndef mozilla_dom_indexeddb_databaseinfo_h__
michael@0 8 #define mozilla_dom_indexeddb_databaseinfo_h__
michael@0 9
michael@0 10 #include "mozilla/dom/indexedDB/IndexedDatabase.h"
michael@0 11
michael@0 12 #include "mozilla/dom/quota/PersistenceType.h"
michael@0 13 #include "nsRefPtrHashtable.h"
michael@0 14 #include "nsHashKeys.h"
michael@0 15
michael@0 16 #include "mozilla/dom/indexedDB/Key.h"
michael@0 17 #include "mozilla/dom/indexedDB/KeyPath.h"
michael@0 18 #include "mozilla/dom/indexedDB/IDBObjectStore.h"
michael@0 19
michael@0 20 BEGIN_INDEXEDDB_NAMESPACE
michael@0 21
michael@0 22 class IndexedDBDatabaseChild;
michael@0 23 struct ObjectStoreInfo;
michael@0 24
michael@0 25 typedef nsRefPtrHashtable<nsStringHashKey, ObjectStoreInfo>
michael@0 26 ObjectStoreInfoHash;
michael@0 27
michael@0 28 struct DatabaseInfoGuts
michael@0 29 {
michael@0 30 typedef mozilla::dom::quota::PersistenceType PersistenceType;
michael@0 31
michael@0 32 DatabaseInfoGuts()
michael@0 33 : nextObjectStoreId(1), nextIndexId(1)
michael@0 34 { }
michael@0 35
michael@0 36 bool operator==(const DatabaseInfoGuts& aOther) const
michael@0 37 {
michael@0 38 return this->name == aOther.name &&
michael@0 39 this->group == aOther.group &&
michael@0 40 this->origin == aOther.origin &&
michael@0 41 this->version == aOther.version &&
michael@0 42 this->persistenceType == aOther.persistenceType &&
michael@0 43 this->nextObjectStoreId == aOther.nextObjectStoreId &&
michael@0 44 this->nextIndexId == aOther.nextIndexId;
michael@0 45 };
michael@0 46
michael@0 47 // Make sure to update ipc/SerializationHelpers.h when changing members here!
michael@0 48 nsString name;
michael@0 49 nsCString group;
michael@0 50 nsCString origin;
michael@0 51 uint64_t version;
michael@0 52 PersistenceType persistenceType;
michael@0 53 int64_t nextObjectStoreId;
michael@0 54 int64_t nextIndexId;
michael@0 55 };
michael@0 56
michael@0 57 struct DatabaseInfo MOZ_FINAL : public DatabaseInfoGuts
michael@0 58 {
michael@0 59 DatabaseInfo()
michael@0 60 : cloned(false)
michael@0 61 { }
michael@0 62
michael@0 63 private:
michael@0 64 // Private destructor, to discourage deletion outside of Release():
michael@0 65 ~DatabaseInfo();
michael@0 66
michael@0 67 public:
michael@0 68 static bool Get(const nsACString& aId,
michael@0 69 DatabaseInfo** aInfo);
michael@0 70
michael@0 71 static bool Put(DatabaseInfo* aInfo);
michael@0 72
michael@0 73 static void Remove(const nsACString& aId);
michael@0 74
michael@0 75 bool GetObjectStoreNames(nsTArray<nsString>& aNames);
michael@0 76 bool ContainsStoreName(const nsAString& aName);
michael@0 77
michael@0 78 ObjectStoreInfo* GetObjectStore(const nsAString& aName);
michael@0 79
michael@0 80 bool PutObjectStore(ObjectStoreInfo* aInfo);
michael@0 81
michael@0 82 void RemoveObjectStore(const nsAString& aName);
michael@0 83
michael@0 84 already_AddRefed<DatabaseInfo> Clone();
michael@0 85
michael@0 86 nsCString id;
michael@0 87 nsString filePath;
michael@0 88 bool cloned;
michael@0 89
michael@0 90 nsAutoPtr<ObjectStoreInfoHash> objectStoreHash;
michael@0 91
michael@0 92 NS_INLINE_DECL_REFCOUNTING(DatabaseInfo)
michael@0 93 };
michael@0 94
michael@0 95 struct IndexInfo
michael@0 96 {
michael@0 97 #ifdef NS_BUILD_REFCNT_LOGGING
michael@0 98 IndexInfo();
michael@0 99 IndexInfo(const IndexInfo& aOther);
michael@0 100 ~IndexInfo();
michael@0 101 #else
michael@0 102 IndexInfo()
michael@0 103 : id(INT64_MIN), keyPath(0), unique(false), multiEntry(false) { }
michael@0 104 #endif
michael@0 105
michael@0 106 bool operator==(const IndexInfo& aOther) const
michael@0 107 {
michael@0 108 return this->name == aOther.name &&
michael@0 109 this->id == aOther.id &&
michael@0 110 this->keyPath == aOther.keyPath &&
michael@0 111 this->unique == aOther.unique &&
michael@0 112 this->multiEntry == aOther.multiEntry;
michael@0 113 };
michael@0 114
michael@0 115 // Make sure to update ipc/SerializationHelpers.h when changing members here!
michael@0 116 nsString name;
michael@0 117 int64_t id;
michael@0 118 KeyPath keyPath;
michael@0 119 bool unique;
michael@0 120 bool multiEntry;
michael@0 121 };
michael@0 122
michael@0 123 struct ObjectStoreInfoGuts
michael@0 124 {
michael@0 125 ObjectStoreInfoGuts()
michael@0 126 : id(0), keyPath(0), autoIncrement(false)
michael@0 127 { }
michael@0 128
michael@0 129 bool operator==(const ObjectStoreInfoGuts& aOther) const
michael@0 130 {
michael@0 131 return this->name == aOther.name &&
michael@0 132 this->id == aOther.id;
michael@0 133 };
michael@0 134
michael@0 135 // Make sure to update ipc/SerializationHelpers.h when changing members here!
michael@0 136
michael@0 137 // Constant members, can be gotten on any thread
michael@0 138 nsString name;
michael@0 139 int64_t id;
michael@0 140 KeyPath keyPath;
michael@0 141 bool autoIncrement;
michael@0 142
michael@0 143 // Main-thread only members. This must *not* be touched on the database
michael@0 144 // thread.
michael@0 145 nsTArray<IndexInfo> indexes;
michael@0 146 };
michael@0 147
michael@0 148 struct ObjectStoreInfo MOZ_FINAL : public ObjectStoreInfoGuts
michael@0 149 {
michael@0 150 #ifdef NS_BUILD_REFCNT_LOGGING
michael@0 151 ObjectStoreInfo();
michael@0 152 #else
michael@0 153 ObjectStoreInfo()
michael@0 154 : nextAutoIncrementId(0), comittedAutoIncrementId(0) { }
michael@0 155 #endif
michael@0 156
michael@0 157 ObjectStoreInfo(ObjectStoreInfo& aOther);
michael@0 158
michael@0 159 private:
michael@0 160 // Private destructor, to discourage deletion outside of Release():
michael@0 161 #ifdef NS_BUILD_REFCNT_LOGGING
michael@0 162 ~ObjectStoreInfo();
michael@0 163 #else
michael@0 164 ~ObjectStoreInfo() {}
michael@0 165 #endif
michael@0 166 public:
michael@0 167
michael@0 168 // Database-thread members. After the ObjectStoreInfo has been initialized,
michael@0 169 // these can *only* be touced on the database thread.
michael@0 170 int64_t nextAutoIncrementId;
michael@0 171 int64_t comittedAutoIncrementId;
michael@0 172
michael@0 173 // This is threadsafe since the ObjectStoreInfos are created on the database
michael@0 174 // thread but then only used from the main thread. Ideal would be if we
michael@0 175 // could transfer ownership from the database thread to the main thread, but
michael@0 176 // we don't have that ability yet.
michael@0 177 NS_INLINE_DECL_THREADSAFE_REFCOUNTING(ObjectStoreInfo)
michael@0 178 };
michael@0 179
michael@0 180 struct IndexUpdateInfo
michael@0 181 {
michael@0 182 #ifdef NS_BUILD_REFCNT_LOGGING
michael@0 183 IndexUpdateInfo();
michael@0 184 IndexUpdateInfo(const IndexUpdateInfo& aOther);
michael@0 185 ~IndexUpdateInfo();
michael@0 186 #endif
michael@0 187
michael@0 188 bool operator==(const IndexUpdateInfo& aOther) const
michael@0 189 {
michael@0 190 return this->indexId == aOther.indexId &&
michael@0 191 this->indexUnique == aOther.indexUnique &&
michael@0 192 this->value == aOther.value;
michael@0 193 };
michael@0 194
michael@0 195 // Make sure to update ipc/SerializationHelpers.h when changing members here!
michael@0 196 int64_t indexId;
michael@0 197 bool indexUnique;
michael@0 198 Key value;
michael@0 199 };
michael@0 200
michael@0 201 END_INDEXEDDB_NAMESPACE
michael@0 202
michael@0 203 #endif // mozilla_dom_indexeddb_databaseinfo_h__

mercurial