Bug 380317 - crash on shutdown in nsPlacesImportExportService::WriteContainerContents(), mLivemarkService is null. r=sspitzer.

This commit is contained in:
mozilla.mano@sent.com 2007-05-10 16:52:47 -07:00
parent a5ca50ca0e
commit 72de7137c4
4 changed files with 34 additions and 11 deletions

View File

@ -1820,6 +1820,9 @@ nsPlacesImportExportService::ImportHTMLFromFileInternal(nsILocalFile* aFile,
PRInt64 aFolder,
PRBool aIsImportDefaults)
{
nsresult rv = EnsureServiceState();
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIFile> file(do_QueryInterface(aFile));
#ifdef DEBUG_IMPORT
nsAutoString path;
@ -1828,7 +1831,6 @@ nsPlacesImportExportService::ImportHTMLFromFileInternal(nsILocalFile* aFile,
#endif
// wrap the import in a transaction to make it faster
nsresult rv;
mBookmarksService->BeginUpdateBatch();
nsCOMPtr<nsIParser> parser = do_CreateInstance(kParserCID, &rv);
@ -1906,14 +1908,17 @@ nsPlacesImportExportService::ExportHTMLToFile(nsILocalFile* aBookmarksFile)
if (!aBookmarksFile)
return NS_ERROR_NULL_POINTER;
nsresult rv = EnsureServiceState();
NS_ENSURE_SUCCESS(rv, rv);
// get a safe output stream, so we don't clobber the bookmarks file unless
// all the writes succeeded.
nsCOMPtr<nsIOutputStream> out;
nsresult rv = NS_NewSafeLocalFileOutputStream(getter_AddRefs(out),
aBookmarksFile,
PR_WRONLY | PR_CREATE_FILE,
/*octal*/ 0600,
0);
rv = NS_NewSafeLocalFileOutputStream(getter_AddRefs(out),
aBookmarksFile,
PR_WRONLY | PR_CREATE_FILE,
/*octal*/ 0600,
0);
NS_ENSURE_SUCCESS(rv, rv);
// We need a buffered output stream for performance.
@ -1978,10 +1983,14 @@ nsPlacesImportExportService::ExportHTMLToFile(nsILocalFile* aBookmarksFile)
NS_IMETHODIMP
nsPlacesImportExportService::BackupBookmarksFile()
{
nsresult rv = EnsureServiceState();
NS_ENSURE_SUCCESS(rv, rv);
// get bookmarks file
nsCOMPtr<nsIFile> bookmarksFileDir;
nsresult rv = NS_GetSpecialDirectory(NS_APP_BOOKMARKS_50_FILE,
getter_AddRefs(bookmarksFileDir));
rv = NS_GetSpecialDirectory(NS_APP_BOOKMARKS_50_FILE,
getter_AddRefs(bookmarksFileDir));
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsILocalFile> bookmarksFile(do_QueryInterface(bookmarksFileDir));

View File

@ -43,6 +43,15 @@ class nsPlacesImportExportService : public nsIPlacesImportExportService
nsresult WriteContainerContents(PRInt64 aFolder, const nsACString& aIndent, nsIOutputStream* aOutput);
nsresult ArchiveBookmarksFile(PRInt32 aNumberOfBackups, PRBool aForceArchive);
inline nsresult EnsureServiceState() {
NS_ENSURE_STATE(mHistoryService);
NS_ENSURE_STATE(mFaviconService);
NS_ENSURE_STATE(mAnnotationService);
NS_ENSURE_STATE(mBookmarksService);
NS_ENSURE_STATE(mLivemarkService);
return NS_OK;
};
};
#endif // nsPlacesImportExportService_h__

View File

@ -976,8 +976,8 @@ nsAnnotationService::GetPagesWithAnnotationCOMArray(
nsCOMPtr<mozIStorageStatement> statement;
nsresult rv = mDBConn->CreateStatement(NS_LITERAL_CSTRING(
"SELECT h.url FROM moz_anno_attributes n "
"LEFT JOIN moz_annos a ON n.id = a.anno_attribute_id "
"LEFT JOIN moz_places h ON a.place_id = h.id "
"INNER JOIN moz_annos a ON n.id = a.anno_attribute_id "
"INNER JOIN moz_places h ON a.place_id = h.id "
"WHERE n.name = ?1"),
getter_AddRefs(statement));
NS_ENSURE_SUCCESS(rv, rv);
@ -1043,7 +1043,7 @@ nsAnnotationService::GetItemsWithAnnotationTArray(const nsACString& aName,
nsCOMPtr<mozIStorageStatement> statement;
nsresult rv = mDBConn->CreateStatement(NS_LITERAL_CSTRING(
"SELECT a.item_id FROM moz_anno_attributes n "
"LEFT JOIN moz_items_annos a ON n.id = a.anno_attribute_id "
"INNER JOIN moz_items_annos a ON n.id = a.anno_attribute_id "
"WHERE n.name = ?1"),
getter_AddRefs(statement));
NS_ENSURE_SUCCESS(rv, rv);

View File

@ -324,5 +324,10 @@ function run_test() {
do_check_eq(annoObserver.ITEM_lastRemoved_Id, testItemId);
do_check_eq(annoObserver.ITEM_lastRemoved_AnnoName, int32Key);
// test that getItems/PagesWithAnnotation returns an empty array after
// removing all items/pages which had the annotation set, see bug 380317.
do_check_eq(annosvc.getItemsWithAnnotation(int32Key, { }).length, 0);
do_check_eq(annosvc.getPagesWithAnnotation(int32Key, { }).length, 0);
annosvc.removeObserver(annoObserver);
}