Bug 724878 - Make nsPermissionManager DB access (except init) async. r=jlebar

This commit is contained in:
Mounir Lamouri 2012-09-08 15:48:20 +02:00
Родитель df73e890dd
Коммит 0912706617
2 изменённых файлов: 39 добавлений и 36 удалений

Просмотреть файл

@ -498,18 +498,18 @@ nsPermissionManager::InitDB(bool aRemoveFile)
mDBConn->ExecuteSimpleSQL(NS_LITERAL_CSTRING("PRAGMA synchronous = OFF")); mDBConn->ExecuteSimpleSQL(NS_LITERAL_CSTRING("PRAGMA synchronous = OFF"));
// cache frequently used statements (for insertion, deletion, and updating) // cache frequently used statements (for insertion, deletion, and updating)
rv = mDBConn->CreateStatement(NS_LITERAL_CSTRING( rv = mDBConn->CreateAsyncStatement(NS_LITERAL_CSTRING(
"INSERT INTO moz_hosts " "INSERT INTO moz_hosts "
"(id, host, type, permission, expireType, expireTime, appId, isInBrowserElement) " "(id, host, type, permission, expireType, expireTime, appId, isInBrowserElement) "
"VALUES (?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8)"), getter_AddRefs(mStmtInsert)); "VALUES (?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8)"), getter_AddRefs(mStmtInsert));
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);
rv = mDBConn->CreateStatement(NS_LITERAL_CSTRING( rv = mDBConn->CreateAsyncStatement(NS_LITERAL_CSTRING(
"DELETE FROM moz_hosts " "DELETE FROM moz_hosts "
"WHERE id = ?1"), getter_AddRefs(mStmtDelete)); "WHERE id = ?1"), getter_AddRefs(mStmtDelete));
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);
rv = mDBConn->CreateStatement(NS_LITERAL_CSTRING( rv = mDBConn->CreateAsyncStatement(NS_LITERAL_CSTRING(
"UPDATE moz_hosts " "UPDATE moz_hosts "
"SET permission = ?2, expireType= ?3, expireTime = ?4 WHERE id = ?1"), "SET permission = ?2, expireType= ?3, expireTime = ?4 WHERE id = ?1"),
getter_AddRefs(mStmtUpdate)); getter_AddRefs(mStmtUpdate));
@ -1138,8 +1138,6 @@ nsPermissionManager::RemovePermissionsForApp(uint32_t aAppId)
NS_ENSURE_ARG(aAppId != nsIScriptSecurityManager::NO_APP_ID); NS_ENSURE_ARG(aAppId != nsIScriptSecurityManager::NO_APP_ID);
// We begin by removing all the permissions from the DB. // We begin by removing all the permissions from the DB.
// This is not using a mozIStorageStatement because removing an app should be
// rare enough to not have to worry too much about performance.
// After clearing the DB, we call AddInternal() to make sure that all // After clearing the DB, we call AddInternal() to make sure that all
// processes are aware of this change and the representation of the DB in // processes are aware of this change and the representation of the DB in
// memory is updated. // memory is updated.
@ -1151,7 +1149,12 @@ nsPermissionManager::RemovePermissionsForApp(uint32_t aAppId)
sql.AppendLiteral("DELETE FROM moz_hosts WHERE appId="); sql.AppendLiteral("DELETE FROM moz_hosts WHERE appId=");
sql.AppendInt(aAppId); sql.AppendInt(aAppId);
nsresult rv = mDBConn->ExecuteSimpleSQL(sql); nsCOMPtr<mozIStorageAsyncStatement> removeStmt;
nsresult rv = mDBConn->CreateAsyncStatement(sql, getter_AddRefs(removeStmt));
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<mozIStoragePendingStatement> pending;
rv = removeStmt->ExecuteAsync(nullptr, getter_AddRefs(pending));
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);
GetPermissionsForAppStruct data(aAppId); GetPermissionsForAppStruct data(aAppId);
@ -1428,7 +1431,7 @@ nsPermissionManager::NormalizeToACE(nsCString &aHost)
void void
nsPermissionManager::UpdateDB(OperationType aOp, nsPermissionManager::UpdateDB(OperationType aOp,
mozIStorageStatement* aStmt, mozIStorageAsyncStatement* aStmt,
int64_t aID, int64_t aID,
const nsACString &aHost, const nsACString &aHost,
const nsACString &aType, const nsACString &aType,
@ -1503,13 +1506,13 @@ nsPermissionManager::UpdateDB(OperationType aOp,
} }
} }
if (NS_SUCCEEDED(rv)) { if (NS_FAILED(rv)) {
bool hasResult;
rv = aStmt->ExecuteStep(&hasResult);
aStmt->Reset();
}
if (NS_FAILED(rv))
NS_WARNING("db change failed!"); NS_WARNING("db change failed!");
return;
}
nsCOMPtr<mozIStoragePendingStatement> pending;
rv = aStmt->ExecuteAsync(nullptr, getter_AddRefs(pending));
MOZ_ASSERT(NS_SUCCEEDED(rv));
} }

Просмотреть файл

@ -23,7 +23,7 @@
class nsIPermission; class nsIPermission;
class nsIIDNService; class nsIIDNService;
class mozIStorageConnection; class mozIStorageConnection;
class mozIStorageStatement; class mozIStorageAsyncStatement;
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@ -236,7 +236,7 @@ private:
nsresult RemoveAllFromMemory(); nsresult RemoveAllFromMemory();
nsresult NormalizeToACE(nsCString &aHost); nsresult NormalizeToACE(nsCString &aHost);
static void UpdateDB(OperationType aOp, static void UpdateDB(OperationType aOp,
mozIStorageStatement* aStmt, mozIStorageAsyncStatement* aStmt,
int64_t aID, int64_t aID,
const nsACString& aHost, const nsACString& aHost,
const nsACString& aType, const nsACString& aType,
@ -272,9 +272,9 @@ private:
nsCOMPtr<nsIIDNService> mIDNService; nsCOMPtr<nsIIDNService> mIDNService;
nsCOMPtr<mozIStorageConnection> mDBConn; nsCOMPtr<mozIStorageConnection> mDBConn;
nsCOMPtr<mozIStorageStatement> mStmtInsert; nsCOMPtr<mozIStorageAsyncStatement> mStmtInsert;
nsCOMPtr<mozIStorageStatement> mStmtDelete; nsCOMPtr<mozIStorageAsyncStatement> mStmtDelete;
nsCOMPtr<mozIStorageStatement> mStmtUpdate; nsCOMPtr<mozIStorageAsyncStatement> mStmtUpdate;
nsTHashtable<PermissionHashKey> mPermissionTable; nsTHashtable<PermissionHashKey> mPermissionTable;
// a unique, monotonically increasing id used to identify each database entry // a unique, monotonically increasing id used to identify each database entry