Bug 555218 - 5 (AsyncFaviconsHelpers.cpp) Fix Places usage of deprecated Storage APIs. r=dietrich

This commit is contained in:
Marco Bonardo 2010-04-27 13:25:03 +02:00
parent 14f79b02cb
commit d5f9ccc641
4 changed files with 46 additions and 37 deletions

View File

@ -293,12 +293,13 @@ GetEffectivePageStep::Run()
// favicons if the page is bookmarked.
if (!canAddToHistory || history->IsHistoryDisabled()) {
// Get place id associated with this page.
mozIStorageStatement* stmt = history->GetStatementById(DB_GET_PAGE_INFO);
mozIStorageStatement* stmt = history->GetStatementById(DB_GET_PAGE_INFO_BY_URL);
// Statement is null if we are shutting down.
FAVICONSTEP_CANCEL_IF_TRUE(!stmt, PR_FALSE);
mozStorageStatementScoper scoper(stmt);
nsresult rv = BindStatementURI(stmt, 0, mStepper->mPageURI);
nsresult rv = URIBinder::Bind(stmt, NS_LITERAL_CSTRING("page_url"),
mStepper->mPageURI);
FAVICONSTEP_FAIL_IF_FALSE(NS_SUCCEEDED(rv));
nsCOMPtr<mozIStoragePendingStatement> ps;
@ -360,7 +361,8 @@ GetEffectivePageStep::HandleCompletion(PRUint16 aReason)
FAVICONSTEP_CANCEL_IF_TRUE_RV(!stmt, PR_FALSE, NS_OK);
mozStorageStatementScoper scoper(stmt);
nsresult rv = stmt->BindInt64Parameter(0, mStepper->mPageId);
nsresult rv = stmt->BindInt64ByName(NS_LITERAL_CSTRING("page_id"),
mStepper->mPageId);
FAVICONSTEP_FAIL_IF_FALSE_RV(NS_SUCCEEDED(rv), rv);
nsCOMPtr<mozIStoragePendingStatement> ps;
@ -434,13 +436,15 @@ FetchDatabaseIconStep::Run()
FAVICONSTEP_CANCEL_IF_TRUE(!stmt, PR_FALSE);
mozStorageStatementScoper scoper(stmt);
nsresult rv = BindStatementURI(stmt, 0, mStepper->mIconURI);
nsresult rv = URIBinder::Bind(stmt, NS_LITERAL_CSTRING("icon_url"),
mStepper->mIconURI);
FAVICONSTEP_FAIL_IF_FALSE(NS_SUCCEEDED(rv));
if (mStepper->mPageURI) {
rv = BindStatementURI(stmt, 1, mStepper->mPageURI);
rv = URIBinder::Bind(stmt, NS_LITERAL_CSTRING("page_url"),
mStepper->mPageURI);
}
else {
rv = stmt->BindNullParameter(1);
rv = stmt->BindNullByName(NS_LITERAL_CSTRING("page_url"));
}
FAVICONSTEP_FAIL_IF_FALSE(NS_SUCCEEDED(rv));
@ -533,9 +537,10 @@ EnsureDatabaseEntryStep::Run()
// Statement is null if we are shutting down.
FAVICONSTEP_CANCEL_IF_TRUE(!stmt, PR_FALSE);
mozStorageStatementScoper scoper(stmt);
rv = stmt->BindNullParameter(0);
rv = stmt->BindNullByName(NS_LITERAL_CSTRING("icon_id"));
FAVICONSTEP_FAIL_IF_FALSE(NS_SUCCEEDED(rv));
rv = BindStatementURI(stmt, 1, mStepper->mIconURI);
rv = URIBinder::Bind(stmt, NS_LITERAL_CSTRING("icon_url"),
mStepper->mIconURI);
FAVICONSTEP_FAIL_IF_FALSE(NS_SUCCEEDED(rv));
nsCOMPtr<mozIStoragePendingStatement> ps;
rv = stmt->ExecuteAsync(this, getter_AddRefs(ps));
@ -820,20 +825,25 @@ SetFaviconDataStep::Run()
mozStorageStatementScoper scoper(stmt);
if (!mStepper->mIconId) {
rv = stmt->BindNullParameter(0);
rv = stmt->BindNullByName(NS_LITERAL_CSTRING("icon_id"));
}
else {
rv = stmt->BindInt64Parameter(0, mStepper->mIconId);
rv = stmt->BindInt64ByName(NS_LITERAL_CSTRING("icon_id"),
mStepper->mIconId);
}
FAVICONSTEP_FAIL_IF_FALSE(NS_SUCCEEDED(rv));
rv = BindStatementURI(stmt, 1, mStepper->mIconURI);
rv = URIBinder::Bind(stmt, NS_LITERAL_CSTRING("icon_url"),
mStepper->mIconURI);
FAVICONSTEP_FAIL_IF_FALSE(NS_SUCCEEDED(rv));
rv = stmt->BindBlobParameter(2, TO_INTBUFFER(mStepper->mData),
mStepper->mData.Length());
rv = stmt->BindBlobByName(NS_LITERAL_CSTRING("data"),
TO_INTBUFFER(mStepper->mData),
mStepper->mData.Length());
FAVICONSTEP_FAIL_IF_FALSE(NS_SUCCEEDED(rv));
rv = stmt->BindUTF8StringParameter(3, mStepper->mMimeType);
rv = stmt->BindUTF8StringByName(NS_LITERAL_CSTRING("mime_type"),
mStepper->mMimeType);
FAVICONSTEP_FAIL_IF_FALSE(NS_SUCCEEDED(rv));
rv = stmt->BindInt64Parameter(4, mStepper->mExpiration);
rv = stmt->BindInt64ByName(NS_LITERAL_CSTRING("expiration"),
mStepper->mExpiration);
FAVICONSTEP_FAIL_IF_FALSE(NS_SUCCEEDED(rv));
nsCOMPtr<mozIStoragePendingStatement> ps;
@ -902,9 +912,11 @@ AssociateIconWithPageStep::Run() {
FAVICONSTEP_CANCEL_IF_TRUE(!stmt, PR_FALSE);
mozStorageStatementScoper scoper(stmt);
nsresult rv = BindStatementURI(stmt, 0, mStepper->mIconURI);
nsresult rv = URIBinder::Bind(stmt, NS_LITERAL_CSTRING("icon_url"),
mStepper->mIconURI);
FAVICONSTEP_FAIL_IF_FALSE(NS_SUCCEEDED(rv));
rv = BindStatementURI(stmt, 1, mStepper->mPageURI);
rv = URIBinder::Bind(stmt, NS_LITERAL_CSTRING("page_url"),
mStepper->mPageURI);
FAVICONSTEP_FAIL_IF_FALSE(NS_SUCCEEDED(rv));
nsCOMPtr<mozIStoragePendingStatement> ps;

View File

@ -433,11 +433,11 @@ nsNavBookmarks::GetStatement(const nsCOMPtr<mozIStorageStatement>& aStmt)
RETURN_IF_STMT(mDBFindRedirectedBookmark, NS_LITERAL_CSTRING(
"SELECT IFNULL( "
"(SELECT url FROM moz_places_temp WHERE id = ?1), "
"(SELECT url FROM moz_places WHERE id = ?1) "
"(SELECT url FROM moz_places_temp WHERE id = :page_id), "
"(SELECT url FROM moz_places WHERE id = :page_id) "
") "
"FROM moz_bookmarks b "
"WHERE b.fk = ?1 "
"WHERE b.fk = :page_id "
"UNION ALL " // Not directly bookmarked.
"SELECT IFNULL( "
"(SELECT url FROM moz_places_temp WHERE id = " COALESCE_PLACEID "), "
@ -451,7 +451,7 @@ nsNavBookmarks::GetStatement(const nsCOMPtr<mozIStorageStatement>& aStmt)
"LEFT JOIN moz_historyvisits_temp greatgrandparent ON grandparent.from_visit = greatgrandparent.id "
"AND grandparent.visit_type IN (") + redirectsFragment + NS_LITERAL_CSTRING(") "
"WHERE self.visit_type IN (") + redirectsFragment + NS_LITERAL_CSTRING(") "
"AND self.place_id = ?1 "
"AND self.place_id = :page_id "
"UNION ALL " // Not in the temp table.
"SELECT IFNULL( "
"(SELECT url FROM moz_places_temp WHERE id = " COALESCE_PLACEID "), "
@ -465,7 +465,7 @@ nsNavBookmarks::GetStatement(const nsCOMPtr<mozIStorageStatement>& aStmt)
"LEFT JOIN moz_historyvisits greatgrandparent ON grandparent.from_visit = greatgrandparent.id "
"AND grandparent.visit_type IN (") + redirectsFragment + NS_LITERAL_CSTRING(") "
"WHERE self.visit_type IN (") + redirectsFragment + NS_LITERAL_CSTRING(") "
"AND self.place_id = ?1 "
"AND self.place_id = :page_id "
"LIMIT 1 " // Stop at the first result.
));
#undef COALESCE_PLACEID
@ -2482,7 +2482,7 @@ nsNavBookmarks::GetBookmarkedURIFor(nsIURI* aURI, nsIURI** _retval)
// the first found bookmark in case. The check is directly on moz_bookmarks
// without special filtering.
DECLARE_AND_ASSIGN_SCOPED_LAZY_STMT(stmt, mDBFindRedirectedBookmark);
rv = stmt->BindInt64Parameter(0, placeId);
rv = stmt->BindInt64ByName(NS_LITERAL_CSTRING("page_id"), placeId);
NS_ENSURE_SUCCESS(rv, rv);
PRBool hasBookmarkedOrigin;
if (NS_SUCCEEDED(stmt->ExecuteStep(&hasBookmarkedOrigin)) &&

View File

@ -1058,11 +1058,11 @@ nsNavHistory::InitStatements()
nsresult rv = mDBConn->CreateStatement(NS_LITERAL_CSTRING(
"SELECT id, url, title, rev_host, visit_count "
"FROM moz_places_temp "
"WHERE url = ?1 "
"WHERE url = :page_url "
"UNION ALL "
"SELECT id, url, title, rev_host, visit_count "
"FROM moz_places "
"WHERE url = ?1 "
"WHERE url = :page_url "
"LIMIT 1"),
getter_AddRefs(mDBGetURLPageInfo));
NS_ENSURE_SUCCESS(rv, rv);
@ -1074,11 +1074,11 @@ nsNavHistory::InitStatements()
rv = mDBConn->CreateStatement(NS_LITERAL_CSTRING(
"SELECT id, url, title, rev_host, visit_count "
"FROM moz_places_temp "
"WHERE id = ?1 "
"WHERE id = :page_id "
"UNION ALL "
"SELECT id, url, title, rev_host, visit_count "
"FROM moz_places "
"WHERE id = ?1 "
"WHERE id = :page_id "
"LIMIT 1"),
getter_AddRefs(mDBGetIdPageInfo));
NS_ENSURE_SUCCESS(rv, rv);
@ -1816,7 +1816,7 @@ nsNavHistory::GetUrlIdFor(nsIURI* aURI, PRInt64* aEntryID,
*aEntryID = 0;
mozStorageStatementScoper statementResetter(mDBGetURLPageInfo);
nsresult rv = BindStatementURI(mDBGetURLPageInfo, 0, aURI);
nsresult rv = URIBinder::Bind(mDBGetURLPageInfo, NS_LITERAL_CSTRING("page_url"), aURI);
NS_ENSURE_SUCCESS(rv, rv);
PRBool hasEntry = PR_FALSE;
@ -1912,7 +1912,7 @@ nsNavHistory::InternalAddNewPage(nsIURI* aURI,
if (aPageID) {
mozStorageStatementScoper scoper(mDBGetURLPageInfo);
rv = BindStatementURI(mDBGetURLPageInfo, 0, aURI);
rv = URIBinder::Bind(mDBGetURLPageInfo, NS_LITERAL_CSTRING("page_url"), aURI);
NS_ENSURE_SUCCESS(rv, rv);
PRBool hasResult = PR_FALSE;
@ -5493,7 +5493,7 @@ nsNavHistory::GetPageTitle(nsIURI* aURI, nsAString& aTitle)
aTitle.Truncate(0);
mozStorageStatementScoper scope(mDBGetURLPageInfo);
nsresult rv = BindStatementURI(mDBGetURLPageInfo, 0, aURI);
nsresult rv = URIBinder::Bind(mDBGetURLPageInfo, NS_LITERAL_CSTRING("page_url"), aURI);
NS_ENSURE_SUCCESS(rv, rv);
PRBool hasResults = PR_FALSE;
@ -7224,7 +7224,7 @@ nsNavHistory::SetPageTitleInternal(nsIURI* aURI, const nsAString& aTitle)
nsAutoString title;
{ // scope for statement
mozStorageStatementScoper infoScoper(mDBGetURLPageInfo);
rv = BindStatementURI(mDBGetURLPageInfo, 0, aURI);
rv = URIBinder::Bind(mDBGetURLPageInfo, NS_LITERAL_CSTRING("page_url"), aURI);
NS_ENSURE_SUCCESS(rv, rv);
PRBool hasURL = PR_FALSE;
rv = mDBGetURLPageInfo->ExecuteStep(&hasURL);
@ -7837,7 +7837,7 @@ nsNavHistory::CalculateFrecencyInternal(PRInt64 aPlaceId,
// frecency to -visit_count, so they're still shown in autocomplete.
PRInt32 visitCount = 0;
mozStorageStatementScoper scoper(mDBGetIdPageInfo);
rv = mDBGetIdPageInfo->BindInt64Parameter(0, aPlaceId);
rv = mDBGetIdPageInfo->BindInt64ByName(NS_LITERAL_CSTRING("page_id"), aPlaceId);
NS_ENSURE_SUCCESS(rv, rv);
PRBool hasVisits = PR_TRUE;

View File

@ -105,7 +105,7 @@ namespace mozilla {
namespace places {
enum HistoryStatementId {
DB_GET_PAGE_INFO = 0
DB_GET_PAGE_INFO_BY_URL = 0
, DB_GET_TAGS = 1
, DB_IS_PAGE_VISITED = 2
};
@ -257,9 +257,6 @@ public:
static const PRInt32 kGetInfoIndex_ItemTags;
static const PRInt32 kGetInfoIndex_ItemParentId;
// select a history row by id
mozIStorageStatement *DBGetIdPageInfo() { return mDBGetIdPageInfo; }
PRInt64 GetTagsFolder();
// Constants for the columns returned by the above statement
@ -399,7 +396,7 @@ public:
{
using namespace mozilla::places;
switch(aStatementId) {
case DB_GET_PAGE_INFO:
case DB_GET_PAGE_INFO_BY_URL:
return mDBGetURLPageInfo;
case DB_GET_TAGS:
return mDBGetTags;