Backed out changeset 55723c780549 (bug 1110485)

This commit is contained in:
Wes Kocher 2015-04-14 15:27:40 -07:00
parent 2d1c8c4766
commit 4d33d0dc41
4 changed files with 238 additions and 232 deletions

View File

@ -147,7 +147,7 @@ DBAction::OpenConnection(const QuotaInfo& aQuotaInfo, nsIFile* aDBDir,
int32_t schemaVersion = 0;
rv = conn->GetSchemaVersion(&schemaVersion);
if (NS_WARN_IF(NS_FAILED(rv))) { return rv; }
if (schemaVersion > 0 && schemaVersion < db::kMaxWipeSchemaVersion) {
if (schemaVersion > 0 && schemaVersion < DBSchema::kMaxWipeSchemaVersion) {
conn = nullptr;
rv = WipeDatabase(dbFile, aDBDir);
if (NS_WARN_IF(NS_FAILED(rv))) { return rv; }
@ -155,7 +155,7 @@ DBAction::OpenConnection(const QuotaInfo& aQuotaInfo, nsIFile* aDBDir,
rv = ss->OpenDatabaseWithFileURL(dbFileUrl, getter_AddRefs(conn));
}
rv = db::InitializeConnection(conn);
rv = DBSchema::InitializeConnection(conn);
if (NS_WARN_IF(NS_FAILED(rv))) { return rv; }
conn.forget(aConnOut);

235
dom/cache/DBSchema.cpp vendored
View File

@ -26,16 +26,10 @@
namespace mozilla {
namespace dom {
namespace cache {
namespace db {
const int32_t kMaxWipeSchemaVersion = 6;
namespace {
const int32_t kLatestSchemaVersion = 6;
const int32_t kMaxEntriesPerStatement = 255;
} // anonymous namespace
const int32_t DBSchema::kMaxWipeSchemaVersion = 6;
const int32_t DBSchema::kLatestSchemaVersion = 6;
const int32_t DBSchema::kMaxEntriesPerStatement = 255;
// If any of the static_asserts below fail, it means that you have changed
// the corresponding WebIDL enum in a way that may be incompatible with the
@ -147,48 +141,11 @@ static_assert(nsIContentPolicy::TYPE_INVALID == 0 &&
nsIContentPolicy::TYPE_IMAGESET == 21,
"nsContentPolicytType values are as expected");
namespace {
typedef int32_t EntryId;
static nsresult QueryAll(mozIStorageConnection* aConn, CacheId aCacheId,
nsTArray<EntryId>& aEntryIdListOut);
static nsresult QueryCache(mozIStorageConnection* aConn, CacheId aCacheId,
const CacheRequest& aRequest,
const CacheQueryParams& aParams,
nsTArray<EntryId>& aEntryIdListOut,
uint32_t aMaxResults = UINT32_MAX);
static nsresult MatchByVaryHeader(mozIStorageConnection* aConn,
const CacheRequest& aRequest,
EntryId entryId, bool* aSuccessOut);
static nsresult DeleteEntries(mozIStorageConnection* aConn,
const nsTArray<EntryId>& aEntryIdList,
nsTArray<nsID>& aDeletedBodyIdListOut,
uint32_t aPos=0, int32_t aLen=-1);
static nsresult InsertEntry(mozIStorageConnection* aConn, CacheId aCacheId,
const CacheRequest& aRequest,
const nsID* aRequestBodyId,
const CacheResponse& aResponse,
const nsID* aResponseBodyId);
static nsresult ReadResponse(mozIStorageConnection* aConn, EntryId aEntryId,
SavedResponse* aSavedResponseOut);
static nsresult ReadRequest(mozIStorageConnection* aConn, EntryId aEntryId,
SavedRequest* aSavedRequestOut);
static void AppendListParamsToQuery(nsACString& aQuery,
const nsTArray<EntryId>& aEntryIdList,
uint32_t aPos, int32_t aLen);
static nsresult BindListParamsToQuery(mozIStorageStatement* aState,
const nsTArray<EntryId>& aEntryIdList,
uint32_t aPos, int32_t aLen);
static nsresult BindId(mozIStorageStatement* aState, uint32_t aPos,
const nsID* aId);
static nsresult ExtractId(mozIStorageStatement* aState, uint32_t aPos,
nsID* aIdOut);
} // anonymous namespace
using mozilla::void_t;
// static
nsresult
CreateSchema(mozIStorageConnection* aConn)
DBSchema::CreateSchema(mozIStorageConnection* aConn)
{
MOZ_ASSERT(!NS_IsMainThread());
MOZ_ASSERT(aConn);
@ -328,8 +285,9 @@ CreateSchema(mozIStorageConnection* aConn)
return rv;
}
// static
nsresult
InitializeConnection(mozIStorageConnection* aConn)
DBSchema::InitializeConnection(mozIStorageConnection* aConn)
{
MOZ_ASSERT(!NS_IsMainThread());
MOZ_ASSERT(aConn);
@ -358,8 +316,9 @@ InitializeConnection(mozIStorageConnection* aConn)
return NS_OK;
}
// static
nsresult
CreateCache(mozIStorageConnection* aConn, CacheId* aCacheIdOut)
DBSchema::CreateCache(mozIStorageConnection* aConn, CacheId* aCacheIdOut)
{
MOZ_ASSERT(!NS_IsMainThread());
MOZ_ASSERT(aConn);
@ -387,9 +346,10 @@ CreateCache(mozIStorageConnection* aConn, CacheId* aCacheIdOut)
return rv;
}
// static
nsresult
DeleteCache(mozIStorageConnection* aConn, CacheId aCacheId,
nsTArray<nsID>& aDeletedBodyIdListOut)
DBSchema::DeleteCache(mozIStorageConnection* aConn, CacheId aCacheId,
nsTArray<nsID>& aDeletedBodyIdListOut)
{
MOZ_ASSERT(!NS_IsMainThread());
MOZ_ASSERT(aConn);
@ -420,9 +380,10 @@ DeleteCache(mozIStorageConnection* aConn, CacheId aCacheId,
return rv;
}
// static
nsresult
IsCacheOrphaned(mozIStorageConnection* aConn, CacheId aCacheId,
bool* aOrphanedOut)
DBSchema::IsCacheOrphaned(mozIStorageConnection* aConn,
CacheId aCacheId, bool* aOrphanedOut)
{
MOZ_ASSERT(!NS_IsMainThread());
MOZ_ASSERT(aConn);
@ -454,12 +415,13 @@ IsCacheOrphaned(mozIStorageConnection* aConn, CacheId aCacheId,
return rv;
}
// static
nsresult
CacheMatch(mozIStorageConnection* aConn, CacheId aCacheId,
const CacheRequest& aRequest,
const CacheQueryParams& aParams,
bool* aFoundResponseOut,
SavedResponse* aSavedResponseOut)
DBSchema::CacheMatch(mozIStorageConnection* aConn, CacheId aCacheId,
const CacheRequest& aRequest,
const CacheQueryParams& aParams,
bool* aFoundResponseOut,
SavedResponse* aSavedResponseOut)
{
MOZ_ASSERT(!NS_IsMainThread());
MOZ_ASSERT(aConn);
@ -485,11 +447,12 @@ CacheMatch(mozIStorageConnection* aConn, CacheId aCacheId,
return rv;
}
// static
nsresult
CacheMatchAll(mozIStorageConnection* aConn, CacheId aCacheId,
const CacheRequestOrVoid& aRequestOrVoid,
const CacheQueryParams& aParams,
nsTArray<SavedResponse>& aSavedResponsesOut)
DBSchema::CacheMatchAll(mozIStorageConnection* aConn, CacheId aCacheId,
const CacheRequestOrVoid& aRequestOrVoid,
const CacheQueryParams& aParams,
nsTArray<SavedResponse>& aSavedResponsesOut)
{
MOZ_ASSERT(!NS_IsMainThread());
MOZ_ASSERT(aConn);
@ -516,13 +479,14 @@ CacheMatchAll(mozIStorageConnection* aConn, CacheId aCacheId,
return rv;
}
// static
nsresult
CachePut(mozIStorageConnection* aConn, CacheId aCacheId,
const CacheRequest& aRequest,
const nsID* aRequestBodyId,
const CacheResponse& aResponse,
const nsID* aResponseBodyId,
nsTArray<nsID>& aDeletedBodyIdListOut)
DBSchema::CachePut(mozIStorageConnection* aConn, CacheId aCacheId,
const CacheRequest& aRequest,
const nsID* aRequestBodyId,
const CacheResponse& aResponse,
const nsID* aResponseBodyId,
nsTArray<nsID>& aDeletedBodyIdListOut)
{
MOZ_ASSERT(!NS_IsMainThread());
MOZ_ASSERT(aConn);
@ -543,11 +507,12 @@ CachePut(mozIStorageConnection* aConn, CacheId aCacheId,
return rv;
}
// static
nsresult
CacheDelete(mozIStorageConnection* aConn, CacheId aCacheId,
const CacheRequest& aRequest,
const CacheQueryParams& aParams,
nsTArray<nsID>& aDeletedBodyIdListOut, bool* aSuccessOut)
DBSchema::CacheDelete(mozIStorageConnection* aConn, CacheId aCacheId,
const CacheRequest& aRequest,
const CacheQueryParams& aParams,
nsTArray<nsID>& aDeletedBodyIdListOut, bool* aSuccessOut)
{
MOZ_ASSERT(!NS_IsMainThread());
MOZ_ASSERT(aConn);
@ -571,11 +536,12 @@ CacheDelete(mozIStorageConnection* aConn, CacheId aCacheId,
return rv;
}
// static
nsresult
CacheKeys(mozIStorageConnection* aConn, CacheId aCacheId,
const CacheRequestOrVoid& aRequestOrVoid,
const CacheQueryParams& aParams,
nsTArray<SavedRequest>& aSavedRequestsOut)
DBSchema::CacheKeys(mozIStorageConnection* aConn, CacheId aCacheId,
const CacheRequestOrVoid& aRequestOrVoid,
const CacheQueryParams& aParams,
nsTArray<SavedRequest>& aSavedRequestsOut)
{
MOZ_ASSERT(!NS_IsMainThread());
MOZ_ASSERT(aConn);
@ -602,13 +568,14 @@ CacheKeys(mozIStorageConnection* aConn, CacheId aCacheId,
return rv;
}
// static
nsresult
StorageMatch(mozIStorageConnection* aConn,
Namespace aNamespace,
const CacheRequest& aRequest,
const CacheQueryParams& aParams,
bool* aFoundResponseOut,
SavedResponse* aSavedResponseOut)
DBSchema::StorageMatch(mozIStorageConnection* aConn,
Namespace aNamespace,
const CacheRequest& aRequest,
const CacheQueryParams& aParams,
bool* aFoundResponseOut,
SavedResponse* aSavedResponseOut)
{
MOZ_ASSERT(!NS_IsMainThread());
MOZ_ASSERT(aConn);
@ -673,10 +640,11 @@ StorageMatch(mozIStorageConnection* aConn,
return NS_OK;
}
// static
nsresult
StorageGetCacheId(mozIStorageConnection* aConn, Namespace aNamespace,
const nsAString& aKey, bool* aFoundCacheOut,
CacheId* aCacheIdOut)
DBSchema::StorageGetCacheId(mozIStorageConnection* aConn, Namespace aNamespace,
const nsAString& aKey, bool* aFoundCacheOut,
CacheId* aCacheIdOut)
{
MOZ_ASSERT(!NS_IsMainThread());
MOZ_ASSERT(aConn);
@ -712,9 +680,10 @@ StorageGetCacheId(mozIStorageConnection* aConn, Namespace aNamespace,
return rv;
}
// static
nsresult
StoragePutCache(mozIStorageConnection* aConn, Namespace aNamespace,
const nsAString& aKey, CacheId aCacheId)
DBSchema::StoragePutCache(mozIStorageConnection* aConn, Namespace aNamespace,
const nsAString& aKey, CacheId aCacheId)
{
MOZ_ASSERT(!NS_IsMainThread());
MOZ_ASSERT(aConn);
@ -740,9 +709,10 @@ StoragePutCache(mozIStorageConnection* aConn, Namespace aNamespace,
return rv;
}
// static
nsresult
StorageForgetCache(mozIStorageConnection* aConn, Namespace aNamespace,
const nsAString& aKey)
DBSchema::StorageForgetCache(mozIStorageConnection* aConn, Namespace aNamespace,
const nsAString& aKey)
{
MOZ_ASSERT(!NS_IsMainThread());
MOZ_ASSERT(aConn);
@ -765,9 +735,10 @@ StorageForgetCache(mozIStorageConnection* aConn, Namespace aNamespace,
return rv;
}
// static
nsresult
StorageGetKeys(mozIStorageConnection* aConn, Namespace aNamespace,
nsTArray<nsString>& aKeysOut)
DBSchema::StorageGetKeys(mozIStorageConnection* aConn, Namespace aNamespace,
nsTArray<nsString>& aKeysOut)
{
MOZ_ASSERT(!NS_IsMainThread());
MOZ_ASSERT(aConn);
@ -792,11 +763,10 @@ StorageGetKeys(mozIStorageConnection* aConn, Namespace aNamespace,
return rv;
}
namespace {
// static
nsresult
QueryAll(mozIStorageConnection* aConn, CacheId aCacheId,
nsTArray<EntryId>& aEntryIdListOut)
DBSchema::QueryAll(mozIStorageConnection* aConn, CacheId aCacheId,
nsTArray<EntryId>& aEntryIdListOut)
{
MOZ_ASSERT(!NS_IsMainThread());
MOZ_ASSERT(aConn);
@ -821,12 +791,13 @@ QueryAll(mozIStorageConnection* aConn, CacheId aCacheId,
return rv;
}
// static
nsresult
QueryCache(mozIStorageConnection* aConn, CacheId aCacheId,
const CacheRequest& aRequest,
const CacheQueryParams& aParams,
nsTArray<EntryId>& aEntryIdListOut,
uint32_t aMaxResults)
DBSchema::QueryCache(mozIStorageConnection* aConn, CacheId aCacheId,
const CacheRequest& aRequest,
const CacheQueryParams& aParams,
nsTArray<EntryId>& aEntryIdListOut,
uint32_t aMaxResults)
{
MOZ_ASSERT(!NS_IsMainThread());
MOZ_ASSERT(aConn);
@ -898,10 +869,11 @@ QueryCache(mozIStorageConnection* aConn, CacheId aCacheId,
return rv;
}
// static
nsresult
MatchByVaryHeader(mozIStorageConnection* aConn,
const CacheRequest& aRequest,
EntryId entryId, bool* aSuccessOut)
DBSchema::MatchByVaryHeader(mozIStorageConnection* aConn,
const CacheRequest& aRequest,
EntryId entryId, bool* aSuccessOut)
{
MOZ_ASSERT(!NS_IsMainThread());
MOZ_ASSERT(aConn);
@ -1010,11 +982,12 @@ MatchByVaryHeader(mozIStorageConnection* aConn,
return rv;
}
// static
nsresult
DeleteEntries(mozIStorageConnection* aConn,
const nsTArray<EntryId>& aEntryIdList,
nsTArray<nsID>& aDeletedBodyIdListOut,
uint32_t aPos, int32_t aLen)
DBSchema::DeleteEntries(mozIStorageConnection* aConn,
const nsTArray<EntryId>& aEntryIdList,
nsTArray<nsID>& aDeletedBodyIdListOut,
uint32_t aPos, int32_t aLen)
{
MOZ_ASSERT(!NS_IsMainThread());
MOZ_ASSERT(aConn);
@ -1098,12 +1071,13 @@ DeleteEntries(mozIStorageConnection* aConn,
return rv;
}
// static
nsresult
InsertEntry(mozIStorageConnection* aConn, CacheId aCacheId,
const CacheRequest& aRequest,
const nsID* aRequestBodyId,
const CacheResponse& aResponse,
const nsID* aResponseBodyId)
DBSchema::InsertEntry(mozIStorageConnection* aConn, CacheId aCacheId,
const CacheRequest& aRequest,
const nsID* aRequestBodyId,
const CacheResponse& aResponse,
const nsID* aResponseBodyId)
{
MOZ_ASSERT(!NS_IsMainThread());
MOZ_ASSERT(aConn);
@ -1266,9 +1240,10 @@ InsertEntry(mozIStorageConnection* aConn, CacheId aCacheId,
return rv;
}
// static
nsresult
ReadResponse(mozIStorageConnection* aConn, EntryId aEntryId,
SavedResponse* aSavedResponseOut)
DBSchema::ReadResponse(mozIStorageConnection* aConn, EntryId aEntryId,
SavedResponse* aSavedResponseOut)
{
MOZ_ASSERT(!NS_IsMainThread());
MOZ_ASSERT(aConn);
@ -1362,9 +1337,10 @@ ReadResponse(mozIStorageConnection* aConn, EntryId aEntryId,
return rv;
}
// static
nsresult
ReadRequest(mozIStorageConnection* aConn, EntryId aEntryId,
SavedRequest* aSavedRequestOut)
DBSchema::ReadRequest(mozIStorageConnection* aConn, EntryId aEntryId,
SavedRequest* aSavedRequestOut)
{
MOZ_ASSERT(!NS_IsMainThread());
MOZ_ASSERT(aConn);
@ -1480,10 +1456,11 @@ ReadRequest(mozIStorageConnection* aConn, EntryId aEntryId,
return rv;
}
// static
void
AppendListParamsToQuery(nsACString& aQuery,
const nsTArray<EntryId>& aEntryIdList,
uint32_t aPos, int32_t aLen)
DBSchema::AppendListParamsToQuery(nsACString& aQuery,
const nsTArray<EntryId>& aEntryIdList,
uint32_t aPos, int32_t aLen)
{
MOZ_ASSERT(!NS_IsMainThread());
MOZ_ASSERT((aPos + aLen) <= aEntryIdList.Length());
@ -1496,10 +1473,11 @@ AppendListParamsToQuery(nsACString& aQuery,
}
}
// static
nsresult
BindListParamsToQuery(mozIStorageStatement* aState,
const nsTArray<EntryId>& aEntryIdList,
uint32_t aPos, int32_t aLen)
DBSchema::BindListParamsToQuery(mozIStorageStatement* aState,
const nsTArray<EntryId>& aEntryIdList,
uint32_t aPos, int32_t aLen)
{
MOZ_ASSERT(!NS_IsMainThread());
MOZ_ASSERT((aPos + aLen) <= aEntryIdList.Length());
@ -1510,8 +1488,9 @@ BindListParamsToQuery(mozIStorageStatement* aState,
return NS_OK;
}
// static
nsresult
BindId(mozIStorageStatement* aState, uint32_t aPos, const nsID* aId)
DBSchema::BindId(mozIStorageStatement* aState, uint32_t aPos, const nsID* aId)
{
MOZ_ASSERT(!NS_IsMainThread());
MOZ_ASSERT(aState);
@ -1531,8 +1510,9 @@ BindId(mozIStorageStatement* aState, uint32_t aPos, const nsID* aId)
return rv;
}
// static
nsresult
ExtractId(mozIStorageStatement* aState, uint32_t aPos, nsID* aIdOut)
DBSchema::ExtractId(mozIStorageStatement* aState, uint32_t aPos, nsID* aIdOut)
{
MOZ_ASSERT(!NS_IsMainThread());
MOZ_ASSERT(aState);
@ -1548,9 +1528,6 @@ ExtractId(mozIStorageStatement* aState, uint32_t aPos, nsID* aIdOut)
return rv;
}
} // anonymouns namespace
} // namespace db
} // namespace cache
} // namespace dom
} // namespace mozilla

170
dom/cache/DBSchema.h vendored
View File

@ -14,6 +14,7 @@
#include "nsTArrayForwardDeclare.h"
class mozIStorageConnection;
class mozIStorageStatement;
struct nsID;
namespace mozilla {
@ -27,88 +28,115 @@ class CacheResponse;
struct SavedRequest;
struct SavedResponse;
namespace db {
// TODO: remove static class and use functions in cache namespace (bug 1110485)
class DBSchema final
{
public:
static nsresult CreateSchema(mozIStorageConnection* aConn);
static nsresult InitializeConnection(mozIStorageConnection* aConn);
nsresult
CreateSchema(mozIStorageConnection* aConn);
static nsresult CreateCache(mozIStorageConnection* aConn,
CacheId* aCacheIdOut);
// TODO: improve naming (confusing with CacheDelete) (bug 1110485)
static nsresult DeleteCache(mozIStorageConnection* aConn, CacheId aCacheId,
nsTArray<nsID>& aDeletedBodyIdListOut);
nsresult
InitializeConnection(mozIStorageConnection* aConn);
// TODO: Consider removing unused IsCacheOrphaned after writing cleanup code. (bug 1110446)
static nsresult IsCacheOrphaned(mozIStorageConnection* aConn,
CacheId aCacheId, bool* aOrphanedOut);
nsresult
CreateCache(mozIStorageConnection* aConn, CacheId* aCacheIdOut);
static nsresult CacheMatch(mozIStorageConnection* aConn, CacheId aCacheId,
const CacheRequest& aRequest,
const CacheQueryParams& aParams,
bool* aFoundResponseOut,
SavedResponse* aSavedResponseOut);
static nsresult CacheMatchAll(mozIStorageConnection* aConn, CacheId aCacheId,
const CacheRequestOrVoid& aRequestOrVoid,
const CacheQueryParams& aParams,
nsTArray<SavedResponse>& aSavedResponsesOut);
static nsresult CachePut(mozIStorageConnection* aConn, CacheId aCacheId,
const CacheRequest& aRequest,
const nsID* aRequestBodyId,
const CacheResponse& aResponse,
const nsID* aResponseBodyId,
nsTArray<nsID>& aDeletedBodyIdListOut);
static nsresult CacheDelete(mozIStorageConnection* aConn, CacheId aCacheId,
const CacheRequest& aRequest,
const CacheQueryParams& aParams,
nsTArray<nsID>& aDeletedBodyIdListOut,
bool* aSuccessOut);
static nsresult CacheKeys(mozIStorageConnection* aConn, CacheId aCacheId,
const CacheRequestOrVoid& aRequestOrVoid,
const CacheQueryParams& aParams,
nsTArray<SavedRequest>& aSavedRequestsOut);
// TODO: improve naming (confusing with CacheDelete) (bug 1110485)
nsresult
DeleteCache(mozIStorageConnection* aConn, CacheId aCacheId,
nsTArray<nsID>& aDeletedBodyIdListOut);
static nsresult StorageMatch(mozIStorageConnection* aConn,
Namespace aNamespace,
const CacheRequest& aRequest,
const CacheQueryParams& aParams,
bool* aFoundResponseOut,
SavedResponse* aSavedResponseOut);
static nsresult StorageGetCacheId(mozIStorageConnection* aConn,
Namespace aNamespace, const nsAString& aKey,
bool* aFoundCacheOut, CacheId* aCacheIdOut);
static nsresult StoragePutCache(mozIStorageConnection* aConn,
Namespace aNamespace, const nsAString& aKey,
CacheId aCacheId);
static nsresult StorageForgetCache(mozIStorageConnection* aConn,
Namespace aNamespace,
const nsAString& aKey);
static nsresult StorageGetKeys(mozIStorageConnection* aConn,
Namespace aNamespace,
nsTArray<nsString>& aKeysOut);
// TODO: Consider removing unused IsCacheOrphaned after writing cleanup code. (bug 1110446)
nsresult
IsCacheOrphaned(mozIStorageConnection* aConn, CacheId aCacheId,
bool* aOrphanedOut);
// We will wipe out databases with a schema versions less than this.
static const int32_t kMaxWipeSchemaVersion;
nsresult
CacheMatch(mozIStorageConnection* aConn, CacheId aCacheId,
const CacheRequest& aRequest, const CacheQueryParams& aParams,
bool* aFoundResponseOut, SavedResponse* aSavedResponseOut);
private:
typedef int32_t EntryId;
nsresult
CacheMatchAll(mozIStorageConnection* aConn, CacheId aCacheId,
const CacheRequestOrVoid& aRequestOrVoid,
const CacheQueryParams& aParams,
nsTArray<SavedResponse>& aSavedResponsesOut);
static nsresult QueryAll(mozIStorageConnection* aConn, CacheId aCacheId,
nsTArray<EntryId>& aEntryIdListOut);
static nsresult QueryCache(mozIStorageConnection* aConn, CacheId aCacheId,
const CacheRequest& aRequest,
const CacheQueryParams& aParams,
nsTArray<EntryId>& aEntryIdListOut,
uint32_t aMaxResults = UINT32_MAX);
static nsresult MatchByVaryHeader(mozIStorageConnection* aConn,
const CacheRequest& aRequest,
EntryId entryId, bool* aSuccessOut);
static nsresult DeleteEntries(mozIStorageConnection* aConn,
const nsTArray<EntryId>& aEntryIdList,
nsTArray<nsID>& aDeletedBodyIdListOut,
uint32_t aPos=0, int32_t aLen=-1);
static nsresult InsertEntry(mozIStorageConnection* aConn, CacheId aCacheId,
const CacheRequest& aRequest,
const nsID* aRequestBodyId,
const CacheResponse& aResponse,
const nsID* aResponseBodyId);
static nsresult ReadResponse(mozIStorageConnection* aConn, EntryId aEntryId,
SavedResponse* aSavedResponseOut);
static nsresult ReadRequest(mozIStorageConnection* aConn, EntryId aEntryId,
SavedRequest* aSavedRequestOut);
nsresult
CachePut(mozIStorageConnection* aConn, CacheId aCacheId,
const CacheRequest& aRequest,
const nsID* aRequestBodyId,
const CacheResponse& aResponse,
const nsID* aResponseBodyId,
nsTArray<nsID>& aDeletedBodyIdListOut);
static void AppendListParamsToQuery(nsACString& aQuery,
const nsTArray<EntryId>& aEntryIdList,
uint32_t aPos, int32_t aLen);
static nsresult BindListParamsToQuery(mozIStorageStatement* aState,
const nsTArray<EntryId>& aEntryIdList,
uint32_t aPos, int32_t aLen);
static nsresult BindId(mozIStorageStatement* aState, uint32_t aPos,
const nsID* aId);
static nsresult ExtractId(mozIStorageStatement* aState, uint32_t aPos,
nsID* aIdOut);
nsresult
CacheDelete(mozIStorageConnection* aConn, CacheId aCacheId,
const CacheRequest& aRequest,
const CacheQueryParams& aParams,
nsTArray<nsID>& aDeletedBodyIdListOut,
bool* aSuccessOut);
DBSchema() = delete;
~DBSchema() = delete;
nsresult
CacheKeys(mozIStorageConnection* aConn, CacheId aCacheId,
const CacheRequestOrVoid& aRequestOrVoid,
const CacheQueryParams& aParams,
nsTArray<SavedRequest>& aSavedRequestsOut);
static const int32_t kLatestSchemaVersion;
static const int32_t kMaxEntriesPerStatement;
};
nsresult
StorageMatch(mozIStorageConnection* aConn,
Namespace aNamespace,
const CacheRequest& aRequest,
const CacheQueryParams& aParams,
bool* aFoundResponseOut,
SavedResponse* aSavedResponseOut);
nsresult
StorageGetCacheId(mozIStorageConnection* aConn, Namespace aNamespace,
const nsAString& aKey, bool* aFoundCacheOut,
CacheId* aCacheIdOut);
nsresult
StoragePutCache(mozIStorageConnection* aConn, Namespace aNamespace,
const nsAString& aKey, CacheId aCacheId);
nsresult
StorageForgetCache(mozIStorageConnection* aConn, Namespace aNamespace,
const nsAString& aKey);
nsresult
StorageGetKeys(mozIStorageConnection* aConn, Namespace aNamespace,
nsTArray<nsString>& aKeysOut);
// We will wipe out databases with a schema versions less than this.
extern const int32_t kMaxWipeSchemaVersion;
} // namespace db
} // namespace cache
} // namespace dom
} // namespace mozilla

61
dom/cache/Manager.cpp vendored
View File

@ -34,10 +34,10 @@ namespace {
using mozilla::unused;
using mozilla::dom::cache::Action;
using mozilla::dom::cache::DBSchema;
using mozilla::dom::cache::FileUtils;
using mozilla::dom::cache::QuotaInfo;
using mozilla::dom::cache::SyncDBAction;
using mozilla::dom::cache::db::CreateSchema;
// An Action that is executed when a Context is first created. It ensures that
// the directory and database are setup properly. This lets other actions
@ -65,7 +65,7 @@ public:
mozStorageTransaction trans(aConn, false,
mozIStorageConnection::TRANSACTION_IMMEDIATE);
rv = CreateSchema(aConn);
rv = DBSchema::CreateSchema(aConn);
if (NS_WARN_IF(NS_FAILED(rv))) { return rv; }
rv = trans.Commit();
@ -456,7 +456,7 @@ public:
mozStorageTransaction trans(aConn, false,
mozIStorageConnection::TRANSACTION_IMMEDIATE);
nsresult rv = db::DeleteCache(aConn, mCacheId, mDeletedBodyIdList);
nsresult rv = DBSchema::DeleteCache(aConn, mCacheId, mDeletedBodyIdList);
if (NS_WARN_IF(NS_FAILED(rv))) { return rv; }
rv = trans.Commit();
@ -499,8 +499,9 @@ public:
RunSyncWithDBOnTarget(const QuotaInfo& aQuotaInfo, nsIFile* aDBDir,
mozIStorageConnection* aConn) override
{
nsresult rv = db::CacheMatch(aConn, mCacheId, mArgs.request(),
mArgs.params(), &mFoundResponse, &mResponse);
nsresult rv = DBSchema::CacheMatch(aConn, mCacheId, mArgs.request(),
mArgs.params(), &mFoundResponse,
&mResponse);
if (NS_WARN_IF(NS_FAILED(rv))) { return rv; }
if (!mFoundResponse || !mResponse.mHasBodyId) {
@ -562,8 +563,8 @@ public:
RunSyncWithDBOnTarget(const QuotaInfo& aQuotaInfo, nsIFile* aDBDir,
mozIStorageConnection* aConn) override
{
nsresult rv = db::CacheMatchAll(aConn, mCacheId, mArgs.requestOrVoid(),
mArgs.params(), mSavedResponses);
nsresult rv = DBSchema::CacheMatchAll(aConn, mCacheId, mArgs.requestOrVoid(),
mArgs.params(), mSavedResponses);
if (NS_WARN_IF(NS_FAILED(rv))) { return rv; }
for (uint32_t i = 0; i < mSavedResponses.Length(); ++i) {
@ -773,11 +774,11 @@ private:
}
}
rv = db::CachePut(mConn, mCacheId, e.mRequest,
e.mRequestStream ? &e.mRequestBodyId : nullptr,
e.mResponse,
e.mResponseStream ? &e.mResponseBodyId : nullptr,
mDeletedBodyIdList);
rv = DBSchema::CachePut(mConn, mCacheId, e.mRequest,
e.mRequestStream ? &e.mRequestBodyId : nullptr,
e.mResponse,
e.mResponseStream ? &e.mResponseBodyId : nullptr,
mDeletedBodyIdList);
if (NS_WARN_IF(NS_FAILED(rv))) {
DoResolve(rv);
return;
@ -1002,9 +1003,9 @@ public:
mozStorageTransaction trans(aConn, false,
mozIStorageConnection::TRANSACTION_IMMEDIATE);
nsresult rv = db::CacheDelete(aConn, mCacheId, mArgs.request(),
mArgs.params(), mDeletedBodyIdList,
&mSuccess);
nsresult rv = DBSchema::CacheDelete(aConn, mCacheId, mArgs.request(),
mArgs.params(), mDeletedBodyIdList,
&mSuccess);
if (NS_WARN_IF(NS_FAILED(rv))) { return rv; }
rv = trans.Commit();
@ -1053,8 +1054,8 @@ public:
RunSyncWithDBOnTarget(const QuotaInfo& aQuotaInfo, nsIFile* aDBDir,
mozIStorageConnection* aConn) override
{
nsresult rv = db::CacheKeys(aConn, mCacheId, mArgs.requestOrVoid(),
mArgs.params(), mSavedRequests);
nsresult rv = DBSchema::CacheKeys(aConn, mCacheId, mArgs.requestOrVoid(),
mArgs.params(), mSavedRequests);
if (NS_WARN_IF(NS_FAILED(rv))) { return rv; }
for (uint32_t i = 0; i < mSavedRequests.Length(); ++i) {
@ -1116,9 +1117,9 @@ public:
RunSyncWithDBOnTarget(const QuotaInfo& aQuotaInfo, nsIFile* aDBDir,
mozIStorageConnection* aConn) override
{
nsresult rv = db::StorageMatch(aConn, mNamespace, mArgs.request(),
mArgs.params(), &mFoundResponse,
&mSavedResponse);
nsresult rv = DBSchema::StorageMatch(aConn, mNamespace, mArgs.request(),
mArgs.params(), &mFoundResponse,
&mSavedResponse);
if (NS_WARN_IF(NS_FAILED(rv))) { return rv; }
if (!mFoundResponse || !mSavedResponse.mHasBodyId) {
@ -1175,8 +1176,8 @@ public:
mozIStorageConnection* aConn) override
{
CacheId cacheId;
return db::StorageGetCacheId(aConn, mNamespace, mArgs.key(),
&mCacheFound, &cacheId);
return DBSchema::StorageGetCacheId(aConn, mNamespace, mArgs.key(),
&mCacheFound, &cacheId);
}
virtual void
@ -1214,17 +1215,17 @@ public:
// Look for existing cache
bool cacheFound;
nsresult rv = db::StorageGetCacheId(aConn, mNamespace, mArgs.key(),
&cacheFound, &mCacheId);
nsresult rv = DBSchema::StorageGetCacheId(aConn, mNamespace, mArgs.key(),
&cacheFound, &mCacheId);
if (NS_WARN_IF(NS_FAILED(rv))) { return rv; }
if (cacheFound) {
return rv;
}
rv = db::CreateCache(aConn, &mCacheId);
rv = DBSchema::CreateCache(aConn, &mCacheId);
if (NS_WARN_IF(NS_FAILED(rv))) { return rv; }
rv = db::StoragePutCache(aConn, mNamespace, mArgs.key(), mCacheId);
rv = DBSchema::StoragePutCache(aConn, mNamespace, mArgs.key(), mCacheId);
if (NS_WARN_IF(NS_FAILED(rv))) { return rv; }
rv = trans.Commit();
@ -1267,8 +1268,8 @@ public:
mozIStorageConnection::TRANSACTION_IMMEDIATE);
bool exists;
nsresult rv = db::StorageGetCacheId(aConn, mNamespace, mArgs.key(),
&exists, &mCacheId);
nsresult rv = DBSchema::StorageGetCacheId(aConn, mNamespace, mArgs.key(),
&exists, &mCacheId);
if (NS_WARN_IF(NS_FAILED(rv))) { return rv; }
if (!exists) {
@ -1276,7 +1277,7 @@ public:
return NS_OK;
}
rv = db::StorageForgetCache(aConn, mNamespace, mArgs.key());
rv = DBSchema::StorageForgetCache(aConn, mNamespace, mArgs.key());
if (NS_WARN_IF(NS_FAILED(rv))) { return rv; }
rv = trans.Commit();
@ -1328,7 +1329,7 @@ public:
RunSyncWithDBOnTarget(const QuotaInfo& aQuotaInfo, nsIFile* aDBDir,
mozIStorageConnection* aConn) override
{
return db::StorageGetKeys(aConn, mNamespace, mKeys);
return DBSchema::StorageGetKeys(aConn, mNamespace, mKeys);
}
virtual void