LCOV - code coverage report
Current view: directory - dom/src/storage - nsDOMStoragePersistentDB.h (source / functions) Found Hit Coverage
Test: app.info Lines: 1 1 100.0 %
Date: 2012-06-02 Functions: 2 1 50.0 %

       1                 : /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
       2                 : /* ***** BEGIN LICENSE BLOCK *****
       3                 :  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
       4                 :  *
       5                 :  * The contents of this file are subject to the Mozilla Public License Version
       6                 :  * 1.1 (the "License"); you may not use this file except in compliance with
       7                 :  * the License. You may obtain a copy of the License at
       8                 :  * http://www.mozilla.org/MPL/
       9                 :  *
      10                 :  * Software distributed under the License is distributed on an "AS IS" basis,
      11                 :  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
      12                 :  * for the specific language governing rights and limitations under the
      13                 :  * License.
      14                 :  *
      15                 :  * The Original Code is mozilla.org code.
      16                 :  *
      17                 :  * The Initial Developer of the Original Code is
      18                 :  * Mozilla Corporation.
      19                 :  * Portions created by the Initial Developer are Copyright (C) 2006
      20                 :  * the Initial Developer. All Rights Reserved.
      21                 :  *
      22                 :  * Contributor(s):
      23                 :  *   Neil Deakin <enndeakin@sympatico.ca>
      24                 :  *
      25                 :  * Alternatively, the contents of this file may be used under the terms of
      26                 :  * either of the GNU General Public License Version 2 or later (the "GPL"),
      27                 :  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
      28                 :  * in which case the provisions of the GPL or the LGPL are applicable instead
      29                 :  * of those above. If you wish to allow use of your version of this file only
      30                 :  * under the terms of either the GPL or the LGPL, and not to allow others to
      31                 :  * use your version of this file under the terms of the MPL, indicate your
      32                 :  * decision by deleting the provisions above and replace them with the notice
      33                 :  * and other provisions required by the GPL or the LGPL. If you do not delete
      34                 :  * the provisions above, a recipient may use your version of this file under
      35                 :  * the terms of any one of the MPL, the GPL or the LGPL.
      36                 :  *
      37                 :  * ***** END LICENSE BLOCK ***** */
      38                 : 
      39                 : #ifndef nsDOMStoragePersistentDB_h___
      40                 : #define nsDOMStoragePersistentDB_h___
      41                 : 
      42                 : #include "nscore.h"
      43                 : #include "nsDOMStorageBaseDB.h"
      44                 : #include "mozIStorageConnection.h"
      45                 : #include "mozIStorageStatement.h"
      46                 : #include "nsTHashtable.h"
      47                 : #include "nsDataHashtable.h"
      48                 : #include "mozilla/TimeStamp.h"
      49                 : #include "mozilla/storage/StatementCache.h"
      50                 : 
      51                 : class DOMStorageImpl;
      52                 : class nsSessionStorageEntry;
      53                 : 
      54                 : using mozilla::TimeStamp;
      55                 : using mozilla::TimeDuration;
      56                 : 
      57                 : class nsDOMStoragePersistentDB : public nsDOMStorageBaseDB
      58                 : {
      59                 :   typedef mozilla::storage::StatementCache<mozIStorageStatement> StatementCache;
      60                 : 
      61                 : public:
      62                 :   nsDOMStoragePersistentDB();
      63             308 :   ~nsDOMStoragePersistentDB() {}
      64                 : 
      65                 :   nsresult
      66                 :   Init(const nsString& aDatabaseName);
      67                 : 
      68                 :   /**
      69                 :    * Close the connection, finalizing all the cached statements.
      70                 :    */
      71                 :   void
      72                 :   Close();
      73                 : 
      74                 :   /**
      75                 :    * Retrieve a list of all the keys associated with a particular domain.
      76                 :    */
      77                 :   nsresult
      78                 :   GetAllKeys(DOMStorageImpl* aStorage,
      79                 :              nsTHashtable<nsSessionStorageEntry>* aKeys);
      80                 : 
      81                 :   /**
      82                 :    * Retrieve a value and secure flag for a key from storage.
      83                 :    *
      84                 :    * @throws NS_ERROR_DOM_NOT_FOUND_ERR if key not found
      85                 :    */
      86                 :   nsresult
      87                 :   GetKeyValue(DOMStorageImpl* aStorage,
      88                 :               const nsAString& aKey,
      89                 :               nsAString& aValue,
      90                 :               bool* aSecure);
      91                 : 
      92                 :   /**
      93                 :    * Set the value and secure flag for a key in storage.
      94                 :    */
      95                 :   nsresult
      96                 :   SetKey(DOMStorageImpl* aStorage,
      97                 :          const nsAString& aKey,
      98                 :          const nsAString& aValue,
      99                 :          bool aSecure,
     100                 :          PRInt32 aQuota,
     101                 :          bool aExcludeOfflineFromUsage,
     102                 :          PRInt32* aNewUsage);
     103                 : 
     104                 :   /**
     105                 :    * Set the secure flag for a key in storage. Does nothing if the key was
     106                 :    * not found.
     107                 :    */
     108                 :   nsresult
     109                 :   SetSecure(DOMStorageImpl* aStorage,
     110                 :             const nsAString& aKey,
     111                 :             const bool aSecure);
     112                 : 
     113                 :   /**
     114                 :    * Removes a key from storage.
     115                 :    */
     116                 :   nsresult
     117                 :   RemoveKey(DOMStorageImpl* aStorage,
     118                 :             const nsAString& aKey,
     119                 :             bool aExcludeOfflineFromUsage,
     120                 :             PRInt32 aKeyUsage);
     121                 : 
     122                 :   /**
     123                 :     * Remove all keys belonging to this storage.
     124                 :     */
     125                 :   nsresult ClearStorage(DOMStorageImpl* aStorage);
     126                 : 
     127                 :   /**
     128                 :    * Removes all keys added by a given domain.
     129                 :    */
     130                 :   nsresult
     131                 :   RemoveOwner(const nsACString& aOwner, bool aIncludeSubDomains);
     132                 : 
     133                 :   /**
     134                 :    * Removes keys owned by domains that either match or don't match the
     135                 :    * list.
     136                 :    */
     137                 :   nsresult
     138                 :   RemoveOwners(const nsTArray<nsString>& aOwners,
     139                 :                bool aIncludeSubDomains, bool aMatch);
     140                 : 
     141                 :   /**
     142                 :    * Removes all keys from storage. Used when clearing storage.
     143                 :    */
     144                 :   nsresult
     145                 :   RemoveAll();
     146                 : 
     147                 :   /**
     148                 :     * Returns usage for a storage using its GetQuotaDomainDBKey() as a key.
     149                 :     */
     150                 :   nsresult
     151                 :   GetUsage(DOMStorageImpl* aStorage, bool aExcludeOfflineFromUsage, PRInt32 *aUsage);
     152                 : 
     153                 :   /**
     154                 :     * Returns usage of the domain and optionaly by any subdomain.
     155                 :     */
     156                 :   nsresult
     157                 :   GetUsage(const nsACString& aDomain, bool aIncludeSubDomains, PRInt32 *aUsage);
     158                 : 
     159                 :   /**
     160                 :    * Clears all in-memory data from private browsing mode
     161                 :    */
     162                 :   nsresult ClearAllPrivateBrowsingData();
     163                 : 
     164                 :   /**
     165                 :    * We process INSERTs in a transaction because of performance.
     166                 :    * If there is currently no transaction in progress, start one.
     167                 :    */
     168                 :   nsresult EnsureInsertTransaction();
     169                 : 
     170                 :   /**
     171                 :    * If there is an INSERT transaction in progress, commit it now.
     172                 :    */
     173                 :   nsresult MaybeCommitInsertTransaction();
     174                 : 
     175                 :   /**
     176                 :    * Flushes all temporary tables based on time or forcibly during shutdown. 
     177                 :    */
     178                 :   nsresult FlushTemporaryTables(bool force);
     179                 : 
     180                 : protected:
     181                 :   /**
     182                 :    * Ensures that a temporary table is correctly filled for the scope of
     183                 :    * the given storage.
     184                 :    */
     185                 :   nsresult EnsureLoadTemporaryTableForStorage(DOMStorageImpl* aStorage);
     186                 : 
     187                 :   struct FlushTemporaryTableData {
     188                 :     nsDOMStoragePersistentDB* mDB;
     189                 :     bool mForce;
     190                 :     nsresult mRV;
     191                 :   };
     192                 :   static PLDHashOperator FlushTemporaryTable(nsCStringHashKey::KeyType aKey,
     193                 :                                              TimeStamp& aData,
     194                 :                                              void* aUserArg);       
     195                 : 
     196                 :   nsCOMPtr<mozIStorageConnection> mConnection;
     197                 :   StatementCache mStatements;
     198                 : 
     199                 :   nsCString mCachedOwner;
     200                 :   PRInt32 mCachedUsage;
     201                 : 
     202                 :   // Maps ScopeDBKey to time of the temporary table load for that scope.
     203                 :   // If a record is present, the temp table has been loaded. If it is not
     204                 :   // present, the table has not yet been loaded or has alrady been flushed.
     205                 :   nsDataHashtable<nsCStringHashKey, TimeStamp> mTempTableLoads; 
     206                 : 
     207                 :   friend class nsDOMStorageDBWrapper;
     208                 :   friend class nsDOMStorageMemoryDB;
     209                 :   nsresult
     210                 :   GetUsageInternal(const nsACString& aQuotaDomainDBKey, bool aExcludeOfflineFromUsage, PRInt32 *aUsage);
     211                 : 
     212                 :   // Compares aDomain with the mCachedOwner and returns false if changes
     213                 :   // in aDomain don't affect mCachedUsage.
     214                 :   bool DomainMaybeCached(const nsACString& aDomain);
     215                 : 
     216                 : };
     217                 : 
     218                 : #endif /* nsDOMStorageDB_h___ */

Generated by: LCOV version 1.7