1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2 /* vim: set ts=8 sts=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/. */ 6 7 #ifndef mozilla_dom_cache_DBSchema_h 8 #define mozilla_dom_cache_DBSchema_h 9 10 #include "mozilla/Attributes.h" 11 #include "mozilla/dom/cache/Types.h" 12 #include "nsError.h" 13 #include "nsString.h" 14 #include "nsTArrayForwardDeclare.h" 15 16 class mozIStorageConnection; 17 struct nsID; 18 19 namespace mozilla { 20 namespace dom { 21 namespace cache { 22 23 class CacheQueryParams; 24 class CacheRequest; 25 class CacheResponse; 26 struct SavedRequest; 27 struct SavedResponse; 28 29 namespace db { 30 31 // Note, this cannot be executed within a transaction. 32 nsresult CreateOrMigrateSchema(mozIStorageConnection& aConn); 33 34 // Note, this cannot be executed within a transaction. 35 nsresult InitializeConnection(mozIStorageConnection& aConn); 36 37 Result<CacheId, nsresult> CreateCacheId(mozIStorageConnection& aConn); 38 39 Result<DeletionInfo, nsresult> DeleteCacheId(mozIStorageConnection& aConn, 40 CacheId aCacheId); 41 42 Result<AutoTArray<CacheId, 8>, nsresult> FindOrphanedCacheIds( 43 mozIStorageConnection& aConn); 44 45 Result<int64_t, nsresult> FindOverallPaddingSize(mozIStorageConnection& aConn); 46 47 Result<nsTArray<nsID>, nsresult> GetKnownBodyIds(mozIStorageConnection& aConn); 48 49 Result<Maybe<SavedResponse>, nsresult> CacheMatch( 50 mozIStorageConnection& aConn, CacheId aCacheId, 51 const CacheRequest& aRequest, const CacheQueryParams& aParams); 52 53 Result<nsTArray<SavedResponse>, nsresult> CacheMatchAll( 54 mozIStorageConnection& aConn, CacheId aCacheId, 55 const Maybe<CacheRequest>& aMaybeRequest, const CacheQueryParams& aParams); 56 57 Result<DeletionInfo, nsresult> CachePut(mozIStorageConnection& aConn, 58 CacheId aCacheId, 59 const CacheRequest& aRequest, 60 const nsID* aRequestBodyId, 61 const CacheResponse& aResponse, 62 const nsID* aResponseBodyId); 63 64 Result<Maybe<DeletionInfo>, nsresult> CacheDelete( 65 mozIStorageConnection& aConn, CacheId aCacheId, 66 const CacheRequest& aRequest, const CacheQueryParams& aParams); 67 68 Result<nsTArray<SavedRequest>, nsresult> CacheKeys( 69 mozIStorageConnection& aConn, CacheId aCacheId, 70 const Maybe<CacheRequest>& aMaybeRequest, const CacheQueryParams& aParams); 71 72 Result<Maybe<SavedResponse>, nsresult> StorageMatch( 73 mozIStorageConnection& aConn, Namespace aNamespace, 74 const CacheRequest& aRequest, const CacheQueryParams& aParams); 75 76 Result<Maybe<CacheId>, nsresult> StorageGetCacheId(mozIStorageConnection& aConn, 77 Namespace aNamespace, 78 const nsAString& aKey); 79 80 nsresult StoragePutCache(mozIStorageConnection& aConn, Namespace aNamespace, 81 const nsAString& aKey, CacheId aCacheId); 82 83 nsresult StorageForgetCache(mozIStorageConnection& aConn, Namespace aNamespace, 84 const nsAString& aKey); 85 86 Result<nsTArray<nsString>, nsresult> StorageGetKeys( 87 mozIStorageConnection& aConn, Namespace aNamespace); 88 89 // Note, this works best when its NOT executed within a transaction. 90 nsresult IncrementalVacuum(mozIStorageConnection& aConn); 91 92 // We will wipe out databases with a schema versions less than this. Newer 93 // versions will be migrated on open to the latest schema version. 94 extern const int32_t kFirstShippedSchemaVersion; 95 96 } // namespace db 97 } // namespace cache 98 } // namespace dom 99 } // namespace mozilla 100 101 #endif // mozilla_dom_cache_DBSchema_h 102