LCOV - code coverage report
Current view: directory - dom/indexedDB - IDBRequest.h (source / functions) Found Hit Coverage
Test: app.info Lines: 14 14 100.0 %
Date: 2012-06-02 Functions: 16 14 87.5 %

       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                 :  *   Shawn Wilsher <me@shawnwilsher.com>
      25                 :  *   Ben Turner <bent.mozilla@gmail.com>
      26                 :  *
      27                 :  * Alternatively, the contents of this file may be used under the terms of
      28                 :  * either the GNU General Public License Version 2 or later (the "GPL"), or
      29                 :  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
      30                 :  * in which case the provisions of the GPL or the LGPL are applicable instead
      31                 :  * of those above. If you wish to allow use of your version of this file only
      32                 :  * under the terms of either the GPL or the LGPL, and not to allow others to
      33                 :  * use your version of this file under the terms of the MPL, indicate your
      34                 :  * decision by deleting the provisions above and replace them with the notice
      35                 :  * and other provisions required by the GPL or the LGPL. If you do not delete
      36                 :  * the provisions above, a recipient may use your version of this file under
      37                 :  * the terms of any one of the MPL, the GPL or the LGPL.
      38                 :  *
      39                 :  * ***** END LICENSE BLOCK ***** */
      40                 : 
      41                 : #ifndef mozilla_dom_indexeddb_idbrequest_h__
      42                 : #define mozilla_dom_indexeddb_idbrequest_h__
      43                 : 
      44                 : #include "mozilla/dom/indexedDB/IndexedDatabase.h"
      45                 : 
      46                 : #include "nsIIDBRequest.h"
      47                 : #include "nsIIDBOpenDBRequest.h"
      48                 : #include "nsDOMEventTargetHelper.h"
      49                 : #include "mozilla/dom/indexedDB/IDBWrapperCache.h"
      50                 : 
      51                 : class nsIScriptContext;
      52                 : class nsPIDOMWindow;
      53                 : 
      54                 : BEGIN_INDEXEDDB_NAMESPACE
      55                 : 
      56                 : class HelperBase;
      57                 : class IDBTransaction;
      58                 : 
      59                 : class IDBRequest : public IDBWrapperCache,
      60                 :                    public nsIIDBRequest
      61                 : {
      62                 : public:
      63                 :   NS_DECL_ISUPPORTS_INHERITED
      64                 :   NS_DECL_NSIIDBREQUEST
      65            5691 :   NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_INHERITED(IDBRequest,
      66                 :                                                          IDBWrapperCache)
      67                 : 
      68                 :   static
      69                 :   already_AddRefed<IDBRequest> Create(nsISupports* aSource,
      70                 :                                       IDBWrapperCache* aOwnerCache,
      71                 :                                       IDBTransaction* aTransaction);
      72                 : 
      73                 :   // nsIDOMEventTarget
      74                 :   virtual nsresult PreHandleEvent(nsEventChainPreVisitor& aVisitor);
      75                 : 
      76                 :   nsISupports* Source()
      77                 :   {
      78                 :     return mSource;
      79                 :   }
      80                 : 
      81                 :   void Reset();
      82                 : 
      83                 :   nsresult NotifyHelperCompleted(HelperBase* aHelper);
      84                 : 
      85                 :   void SetError(nsresult rv)
      86                 :   {
      87                 :     NS_ASSERTION(NS_FAILED(rv), "Er, what?");
      88                 :     NS_ASSERTION(mErrorCode == NS_OK, "Already have an error?");
      89                 : 
      90                 :     mErrorCode = rv;
      91                 :   }
      92                 : 
      93                 : protected:
      94                 :   IDBRequest();
      95                 :   ~IDBRequest();
      96                 : 
      97                 :   virtual void RootResultValInternal();
      98                 :   virtual void UnrootResultValInternal();
      99                 : 
     100            4211 :   void RootResultVal()
     101                 :   {
     102            4211 :     if (!mRooted) {
     103            4211 :       RootResultValInternal();
     104            4211 :       mRooted = true;
     105                 :     }
     106            4211 :   }
     107                 : 
     108            4349 :   void UnrootResultVal()
     109                 :   {
     110            4349 :     if (mRooted) {
     111            4211 :       UnrootResultValInternal();
     112            4211 :       mRooted = false;
     113                 :     }
     114            4349 :   }
     115                 : 
     116                 :   nsCOMPtr<nsISupports> mSource;
     117                 :   nsRefPtr<IDBTransaction> mTransaction;
     118                 : 
     119                 :   NS_DECL_EVENT_HANDLER(success)
     120                 :   NS_DECL_EVENT_HANDLER(error)
     121                 : 
     122                 :   jsval mResultVal;
     123                 : 
     124                 :   PRUint16 mErrorCode;
     125                 :   bool mHaveResultOrErrorCode;
     126                 :   bool mRooted;
     127                 : };
     128                 : 
     129                 : class IDBOpenDBRequest : public IDBRequest,
     130                 :                          public nsIIDBOpenDBRequest
     131              76 : {
     132                 : public:
     133                 :   NS_DECL_ISUPPORTS_INHERITED
     134             466 :   NS_FORWARD_NSIIDBREQUEST(IDBRequest::)
     135                 :   NS_DECL_NSIIDBOPENDBREQUEST
     136            1472 :   NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(IDBOpenDBRequest, IDBRequest)
     137                 : 
     138                 :   static
     139                 :   already_AddRefed<IDBOpenDBRequest>
     140                 :   Create(nsPIDOMWindow* aOwner,
     141                 :          JSObject* aScriptOwner);
     142                 : 
     143                 :   static
     144                 :   already_AddRefed<IDBOpenDBRequest>
     145                 :   Create(IDBWrapperCache* aOwnerCache)
     146                 :   {
     147                 :     return Create(aOwnerCache->GetOwner(),
     148                 :                   aOwnerCache->GetScriptOwner());
     149                 :   }
     150                 : 
     151                 :   void SetTransaction(IDBTransaction* aTransaction);
     152                 : 
     153                 : protected:
     154                 :   ~IDBOpenDBRequest();
     155                 : 
     156                 :   virtual void RootResultValInternal();
     157                 :   virtual void UnrootResultValInternal();
     158                 : 
     159                 :   // Only touched on the main thread.
     160                 :   NS_DECL_EVENT_HANDLER(blocked)
     161                 :   NS_DECL_EVENT_HANDLER(upgradeneeded)
     162                 : };
     163                 : 
     164                 : END_INDEXEDDB_NAMESPACE
     165                 : 
     166                 : #endif // mozilla_dom_indexeddb_idbrequest_h__

Generated by: LCOV version 1.7