Bug 786301 - 1/3 - Add RemoveAllForApp on nsDOMStorageDBWrapper and nsDOMStoragePersistentDB. r=honza

This commit is contained in:
Mounir Lamouri 2012-09-27 16:28:01 +01:00
parent b7e92a6866
commit 6a5b33a1f6
4 changed files with 60 additions and 0 deletions

View File

@ -202,6 +202,15 @@ nsDOMStorageDBWrapper::RemoveAll()
return rv;
}
nsresult
nsDOMStorageDBWrapper::RemoveAllForApp(uint32_t aAppId, bool aOnlyBrowserElement)
{
// We only care about removing the permament storage. Temporary storage such
// as session storage or private browsing storage will not be re-used anyway
// and will be automatically deleted at some point.
return mPersistentDB.RemoveAllForApp(aAppId, aOnlyBrowserElement);
}
nsresult
nsDOMStorageDBWrapper::GetUsage(DOMStorageImpl* aStorage, int32_t *aUsage)
{

View File

@ -137,6 +137,15 @@ public:
nsresult
RemoveAll();
/**
* Removes all keys from storage for a specific app.
* If aOnlyBrowserElement is true, it will remove only keys with the
* browserElement flag set.
* aAppId has to be a valid app id. It can't be NO_APP_ID or UNKNOWN_APP_ID.
*/
nsresult
RemoveAllForApp(uint32_t aAppId, bool aOnlyBrowserElement);
/**
* Returns usage for a storage using its GetQuotaDBKey() as a key.
*/

View File

@ -664,6 +664,39 @@ nsDOMStoragePersistentDB::RemoveAll()
return NS_OK;
}
nsresult
nsDOMStoragePersistentDB::RemoveAllForApp(uint32_t aAppId, bool aOnlyBrowserElement)
{
nsresult rv;
rv = MaybeCommitInsertTransaction();
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<mozIStorageStatement> stmt = mStatements.GetCachedStatement(
"DELETE FROM webappsstore2_view "
"WHERE scope LIKE :scope"
);
NS_ENSURE_STATE(stmt);
mozStorageStatementScoper scopeStmt(stmt);
nsAutoCString scope;
scope.AppendInt(aAppId);
if (aOnlyBrowserElement) {
scope.Append(NS_LITERAL_CSTRING(":t:%"));
} else {
scope.Append(NS_LITERAL_CSTRING(":_:%"));
}
rv = stmt->BindUTF8StringByName(NS_LITERAL_CSTRING("scope"), scope);
NS_ENSURE_SUCCESS(rv, rv);
rv = stmt->Execute();
NS_ENSURE_SUCCESS(rv, rv);
MarkAllScopesDirty();
return NS_OK;
}
nsresult
nsDOMStoragePersistentDB::GetUsage(DOMStorageImpl* aStorage,
int32_t *aUsage)

View File

@ -98,6 +98,15 @@ public:
nsresult
RemoveAll();
/**
* Removes all keys from storage for a specific app.
* If aOnlyBrowserElement is true, it will remove only keys with the
* browserElement flag set.
* aAppId has to be a valid app id. It can't be NO_APP_ID or UNKNOWN_APP_ID.
*/
nsresult
RemoveAllForApp(uint32_t aAppId, bool aOnlyBrowserElement);
/**
* Returns usage for a storage using its GetQuotaDBKey() as a key.
*/