dom/indexedDB/DatabaseInfo.h

Wed, 31 Dec 2014 06:55:50 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:55:50 +0100
changeset 2
7e26c7da4463
permissions
-rw-r--r--

Added tag UPSTREAM_283F7C6 for changeset ca08bd8f51b2

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

mercurial