LCOV - code coverage report
Current view: directory - dom/indexedDB - IDBObjectStore.h (source / functions) Found Hit Coverage
Test: app.info Lines: 23 16 69.6 %
Date: 2012-06-02 Functions: 15 12 80.0 %

       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                 : /* ***** BEGIN LICENSE BLOCK *****
       4                 :  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
       5                 :  *
       6                 :  * The contents of this file are subject to the Mozilla Public License Version
       7                 :  * 1.1 (the "License"); you may not use this file except in compliance with
       8                 :  * the License. You may obtain a copy of the License at
       9                 :  * http://www.mozilla.org/MPL/
      10                 :  *
      11                 :  * Software distributed under the License is distributed on an "AS IS" basis,
      12                 :  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
      13                 :  * for the specific language governing rights and limitations under the
      14                 :  * License.
      15                 :  *
      16                 :  * The Original Code is Indexed Database.
      17                 :  *
      18                 :  * The Initial Developer of the Original Code is
      19                 :  * The Mozilla Foundation.
      20                 :  * Portions created by the Initial Developer are Copyright (C) 2010
      21                 :  * the Initial Developer. All Rights Reserved.
      22                 :  *
      23                 :  * Contributor(s):
      24                 :  *   Ben Turner <bent.mozilla@gmail.com>
      25                 :  *
      26                 :  * Alternatively, the contents of this file may be used under the terms of
      27                 :  * either the GNU General Public License Version 2 or later (the "GPL"), or
      28                 :  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
      29                 :  * in which case the provisions of the GPL or the LGPL are applicable instead
      30                 :  * of those above. If you wish to allow use of your version of this file only
      31                 :  * under the terms of either the GPL or the LGPL, and not to allow others to
      32                 :  * use your version of this file under the terms of the MPL, indicate your
      33                 :  * decision by deleting the provisions above and replace them with the notice
      34                 :  * and other provisions required by the GPL or the LGPL. If you do not delete
      35                 :  * the provisions above, a recipient may use your version of this file under
      36                 :  * the terms of any one of the MPL, the GPL or the LGPL.
      37                 :  *
      38                 :  * ***** END LICENSE BLOCK ***** */
      39                 : 
      40                 : #ifndef mozilla_dom_indexeddb_idbobjectstore_h__
      41                 : #define mozilla_dom_indexeddb_idbobjectstore_h__
      42                 : 
      43                 : #include "mozilla/dom/indexedDB/IndexedDatabase.h"
      44                 : 
      45                 : #include "nsIIDBObjectStore.h"
      46                 : #include "nsIIDBTransaction.h"
      47                 : 
      48                 : #include "nsCycleCollectionParticipant.h"
      49                 : 
      50                 : #include "mozilla/dom/indexedDB/IDBTransaction.h"
      51                 : 
      52                 : class nsIScriptContext;
      53                 : class nsPIDOMWindow;
      54                 : 
      55                 : BEGIN_INDEXEDDB_NAMESPACE
      56                 : 
      57                 : class AsyncConnectionHelper;
      58                 : class Key;
      59                 : 
      60                 : struct ObjectStoreInfo;
      61                 : struct IndexInfo;
      62                 : struct IndexUpdateInfo;
      63                 : struct StructuredCloneReadInfo;
      64                 : struct StructuredCloneWriteInfo;
      65                 : 
      66                 : class IDBObjectStore : public nsIIDBObjectStore
      67                 : {
      68                 : public:
      69             544 :   NS_DECL_CYCLE_COLLECTING_ISUPPORTS
      70                 :   NS_DECL_NSIIDBOBJECTSTORE
      71                 : 
      72           30353 :   NS_DECL_CYCLE_COLLECTION_CLASS(IDBObjectStore)
      73                 : 
      74                 :   static already_AddRefed<IDBObjectStore>
      75                 :   Create(IDBTransaction* aTransaction,
      76                 :          ObjectStoreInfo* aInfo,
      77                 :          nsIAtom* aDatabaseId);
      78                 : 
      79                 :   static bool
      80                 :   IsValidKeyPath(JSContext* aCx, const nsAString& aKeyPath);
      81                 : 
      82                 :   static nsresult
      83                 :   AppendIndexUpdateInfo(PRInt64 aIndexID,
      84                 :                         const nsAString& aKeyPath,
      85                 :                         const nsTArray<nsString>& aKeyPathArray,
      86                 :                         bool aUnique,
      87                 :                         bool aMultiEntry,
      88                 :                         JSContext* aCx,
      89                 :                         jsval aObject,
      90                 :                         nsTArray<IndexUpdateInfo>& aUpdateInfoArray);
      91                 : 
      92                 :   static nsresult
      93                 :   UpdateIndexes(IDBTransaction* aTransaction,
      94                 :                 PRInt64 aObjectStoreId,
      95                 :                 const Key& aObjectStoreKey,
      96                 :                 bool aOverwrite,
      97                 :                 PRInt64 aObjectDataId,
      98                 :                 const nsTArray<IndexUpdateInfo>& aUpdateInfoArray);
      99                 : 
     100                 :   static nsresult
     101                 :   GetStructuredCloneReadInfoFromStatement(mozIStorageStatement* aStatement,
     102                 :                                           PRUint32 aDataIndex,
     103                 :                                           PRUint32 aFileIdsIndex,
     104                 :                                           FileManager* aFileManager,
     105                 :                                           StructuredCloneReadInfo& aInfo);
     106                 : 
     107                 :   static void
     108                 :   ClearStructuredCloneBuffer(JSAutoStructuredCloneBuffer& aBuffer);
     109                 : 
     110                 :   static bool
     111                 :   DeserializeValue(JSContext* aCx,
     112                 :                    StructuredCloneReadInfo& aCloneReadInfo,
     113                 :                    jsval* aValue);
     114                 : 
     115                 :   static bool
     116                 :   SerializeValue(JSContext* aCx,
     117                 :                  StructuredCloneWriteInfo& aCloneWriteInfo,
     118                 :                  jsval aValue);
     119                 : 
     120                 :   static JSObject*
     121                 :   StructuredCloneReadCallback(JSContext* aCx,
     122                 :                               JSStructuredCloneReader* aReader,
     123                 :                               uint32_t aTag,
     124                 :                               uint32_t aData,
     125                 :                               void* aClosure);
     126                 :   static JSBool
     127                 :   StructuredCloneWriteCallback(JSContext* aCx,
     128                 :                                JSStructuredCloneWriter* aWriter,
     129                 :                                JSObject* aObj,
     130                 :                                void* aClosure);
     131                 : 
     132                 :   static nsresult
     133                 :   ConvertFileIdsToArray(const nsAString& aFileIds,
     134                 :                         nsTArray<PRInt64>& aResult);
     135                 : 
     136             448 :   const nsString& Name() const
     137                 :   {
     138             448 :     return mName;
     139                 :   }
     140                 : 
     141            3345 :   bool IsAutoIncrement() const
     142                 :   {
     143            3345 :     return mAutoIncrement;
     144                 :   }
     145                 : 
     146            1996 :   bool IsWriteAllowed() const
     147                 :   {
     148            1996 :     return mTransaction->IsWriteAllowed();
     149                 :   }
     150                 : 
     151               0 :   PRInt64 Id() const
     152                 :   {
     153               0 :     NS_ASSERTION(mId != LL_MININT, "Don't ask for this yet!");
     154               0 :     return mId;
     155                 :   }
     156                 : 
     157               0 :   const nsString& KeyPath() const
     158                 :   {
     159               0 :     return mKeyPath;
     160                 :   }
     161                 : 
     162            3808 :   const bool HasKeyPath() const
     163                 :   {
     164            3808 :     return !mKeyPath.IsVoid() || !mKeyPathArray.IsEmpty();
     165                 :   }
     166                 : 
     167             481 :   bool UsesKeyPathArray() const
     168                 :   {
     169             481 :     return !mKeyPathArray.IsEmpty();
     170                 :   }
     171                 :   
     172               0 :   const nsTArray<nsString>& KeyPathArray() const
     173                 :   {
     174               0 :     return mKeyPathArray;
     175                 :   }
     176                 : 
     177            4780 :   IDBTransaction* Transaction()
     178                 :   {
     179            4780 :     return mTransaction;
     180                 :   }
     181                 : 
     182            3841 :   ObjectStoreInfo* Info()
     183                 :   {
     184            3841 :     return mInfo;
     185                 :   }
     186                 : 
     187                 : protected:
     188                 :   IDBObjectStore();
     189                 :   ~IDBObjectStore();
     190                 : 
     191                 :   nsresult GetAddInfo(JSContext* aCx,
     192                 :                       jsval aValue,
     193                 :                       jsval aKeyVal,
     194                 :                       StructuredCloneWriteInfo& aCloneWriteInfo,
     195                 :                       Key& aKey,
     196                 :                       nsTArray<IndexUpdateInfo>& aUpdateInfoArray);
     197                 : 
     198                 :   nsresult AddOrPut(const jsval& aValue,
     199                 :                     const jsval& aKey,
     200                 :                     JSContext* aCx,
     201                 :                     PRUint8 aOptionalArgCount,
     202                 :                     nsIIDBRequest** _retval,
     203                 :                     bool aOverwrite);
     204                 : 
     205                 : private:
     206                 :   nsRefPtr<IDBTransaction> mTransaction;
     207                 : 
     208                 :   PRInt64 mId;
     209                 :   nsString mName;
     210                 :   nsString mKeyPath;
     211                 :   nsTArray<nsString> mKeyPathArray;
     212                 :   bool mAutoIncrement;
     213                 :   nsCOMPtr<nsIAtom> mDatabaseId;
     214                 :   nsRefPtr<ObjectStoreInfo> mInfo;
     215                 :   PRUint32 mStructuredCloneVersion;
     216                 : 
     217                 :   nsTArray<nsRefPtr<IDBIndex> > mCreatedIndexes;
     218                 : };
     219                 : 
     220                 : END_INDEXEDDB_NAMESPACE
     221                 : 
     222                 : #endif // mozilla_dom_indexeddb_idbobjectstore_h__

Generated by: LCOV version 1.7