From 1eb44373536a345f8502c2d9d1ffdee94bec34ae Mon Sep 17 00:00:00 2001 From: "mozilla.mano@sent.com" Date: Thu, 31 May 2007 17:35:49 -0700 Subject: [PATCH] Bug 380519 - Don't use the moz_bookmarks.folderType field for marking the toolbar folder. r=dietrich, a=mconnor. --- .../places/src/nsAnnotationService.h | 1 + .../components/places/src/nsNavBookmarks.cpp | 69 +++++++++++-------- 2 files changed, 40 insertions(+), 30 deletions(-) diff --git a/toolkit/components/places/src/nsAnnotationService.h b/toolkit/components/places/src/nsAnnotationService.h index 6fe59ade069..828aa9dff33 100644 --- a/toolkit/components/places/src/nsAnnotationService.h +++ b/toolkit/components/places/src/nsAnnotationService.h @@ -171,6 +171,7 @@ protected: void CallSetForPageObservers(nsIURI* aURI, const nsACString& aName); void CallSetForItemObservers(PRInt64 aItemId, const nsACString& aName); +public: nsresult GetPagesWithAnnotationCOMArray(const nsACString& aName, nsCOMArray* aResults); nsresult GetItemsWithAnnotationTArray(const nsACString& aName, diff --git a/toolkit/components/places/src/nsNavBookmarks.cpp b/toolkit/components/places/src/nsNavBookmarks.cpp index c09bf844396..26f350395c1 100644 --- a/toolkit/components/places/src/nsNavBookmarks.cpp +++ b/toolkit/components/places/src/nsNavBookmarks.cpp @@ -74,7 +74,7 @@ const PRInt32 nsNavBookmarks::kGetItemPropertiesIndex_LastModified = 9; nsNavBookmarks* nsNavBookmarks::sInstance = nsnull; #define BOOKMARKS_ANNO_PREFIX "bookmarks/" -#define ANNO_FOLDER_READONLY BOOKMARKS_ANNO_PREFIX "readonly" +#define BOOKMARKS_TOOLBAR_FOLDER_ANNO NS_LITERAL_CSTRING(BOOKMARKS_ANNO_PREFIX "toolbarFolder") nsNavBookmarks::nsNavBookmarks() : mRoot(0), mBookmarksRoot(0), mTagRoot(0), mToolbarFolder(0), mBatchLevel(0), @@ -419,20 +419,38 @@ nsNavBookmarks::InitDefaults() nsresult nsNavBookmarks::InitToolbarFolder() { - mozIStorageConnection *dbConn = DBConn(); + nsAnnotationService* annosvc = nsAnnotationService::GetAnnotationService(); + NS_ENSURE_TRUE(annosvc, NS_ERROR_OUT_OF_MEMORY); - nsCOMPtr statement; - nsresult rv = dbConn->CreateStatement(NS_LITERAL_CSTRING("SELECT id from moz_bookmarks WHERE folder_type = 'toolbar'"), - getter_AddRefs(statement)); - NS_ENSURE_SUCCESS(rv, rv); + nsTArray folders; + nsresult rv = annosvc->GetItemsWithAnnotationTArray(BOOKMARKS_TOOLBAR_FOLDER_ANNO, + &folders); + if (NS_FAILED(rv) || folders.Length() == 0) { + /** + * XXXmano: temporary migaration code, should be removed some time + * after alpha 5. + */ + mozIStorageConnection *dbConn = DBConn(); - PRBool hasResult; - rv = statement->ExecuteStep(&hasResult); - NS_ENSURE_SUCCESS(rv, rv); - if (hasResult) { - rv = statement->GetInt64(0, &mToolbarFolder); + nsCOMPtr statement; + rv = dbConn->CreateStatement(NS_LITERAL_CSTRING("SELECT id from moz_bookmarks WHERE folder_type = 'toolbar'"), + getter_AddRefs(statement)); NS_ENSURE_SUCCESS(rv, rv); + + PRBool hasResult; + rv = statement->ExecuteStep(&hasResult); + NS_ENSURE_SUCCESS(rv, rv); + if (hasResult) { + PRInt64 toolbarFolder; + rv = statement->GetInt64(0, &toolbarFolder); + NS_ENSURE_SUCCESS(rv, rv); + rv = SetToolbarFolder(toolbarFolder); + NS_ENSURE_SUCCESS(rv, rv); + } + return NS_OK; } + + mToolbarFolder = folders[0]; return NS_OK; } @@ -807,35 +825,26 @@ nsNavBookmarks::GetToolbarFolder(PRInt64 *aFolderId) NS_IMETHODIMP nsNavBookmarks::SetToolbarFolder(PRInt64 aFolderId) { - mozIStorageConnection *dbConn = DBConn(); - mozStorageTransaction transaction(dbConn, PR_FALSE); - // XXX - validate that input is a valid folder id - if (aFolderId < 0) { + if (aFolderId < 0) return NS_ERROR_INVALID_ARG; - } + if (aFolderId == mToolbarFolder) + return NS_OK; nsresult rv; - nsCAutoString buffer; + nsAnnotationService* annosvc = nsAnnotationService::GetAnnotationService(); + NS_ENSURE_TRUE(annosvc, NS_ERROR_OUT_OF_MEMORY); - // unset old toolbar folder - if (mToolbarFolder > 0) { - buffer.AssignLiteral("UPDATE moz_bookmarks SET folder_type = '' WHERE id = "); - buffer.AppendInt(mToolbarFolder); - rv = dbConn->ExecuteSimpleSQL(buffer); + if (mToolbarFolder != 0) { + rv = annosvc->RemoveItemAnnotation(mToolbarFolder, + BOOKMARKS_TOOLBAR_FOLDER_ANNO); NS_ENSURE_SUCCESS(rv, rv); } - // set new toolbar folder - buffer.AssignLiteral("UPDATE moz_bookmarks SET folder_type = 'toolbar' WHERE id = "); - buffer.AppendInt(aFolderId); - rv = dbConn->ExecuteSimpleSQL(buffer); + rv = annosvc->SetItemAnnotationInt32(aFolderId, BOOKMARKS_TOOLBAR_FOLDER_ANNO, + 1, 0, nsIAnnotationService::EXPIRE_NEVER); NS_ENSURE_SUCCESS(rv, rv); - // commit - rv = transaction.Commit(); - NS_ENSURE_SUCCESS(rv, rv); - // update local mToolbarFolder = aFolderId;