Bug 629285 - Crash at AsyncGetBookmarksForURI.
authorMarco Bonardo <mbonardo@mozilla.com>
Sat, 05 Feb 2011 13:22:10 +0100
changeset 61984 7cb3e9795d040dc8ef9718a09735bd2f4fe322da
parent 61983 3088ca1e27bfc9ad9cc06154fec890c96bec79bd
child 61985 9d810f5ea61c88ed1a9b38c971a70f01424bd6a3
push id18567
push usermak77@bonardo.net
push dateSat, 05 Feb 2011 12:23:12 +0000
treeherderautoland@7cb3e9795d04 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs629285
milestone2.0b12pre
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 629285 - Crash at AsyncGetBookmarksForURI. r=sdwilsh a=blocker
toolkit/components/places/src/nsNavBookmarks.cpp
toolkit/components/places/src/nsNavBookmarks.h
--- a/toolkit/components/places/src/nsNavBookmarks.cpp
+++ b/toolkit/components/places/src/nsNavBookmarks.cpp
@@ -119,25 +119,29 @@ SearchBookmarkForKeyword(nsTrimInt64Hash
 }
 
 template<typename Method, typename DataType>
 class AsyncGetBookmarksForURI : public AsyncStatementCallback
 {
 public:
   AsyncGetBookmarksForURI(nsNavBookmarks* aBookmarksSvc,
                           Method aCallback,
-                          DataType aData)
+                          const DataType& aData)
   : mBookmarksSvc(aBookmarksSvc)
   , mCallback(aCallback)
   , mData(aData)
   {
+  }
+
+  void Init()
+  {
     nsCOMPtr<mozIStorageStatement> stmt =
-      aBookmarksSvc->GetStatementById(DB_GET_BOOKMARKS_FOR_URI);
+      mBookmarksSvc->GetStatementById(DB_GET_BOOKMARKS_FOR_URI);
     if (stmt) {
-      (void)URIBinder::Bind(stmt, NS_LITERAL_CSTRING("page_url"), aData.uri);
+      (void)URIBinder::Bind(stmt, NS_LITERAL_CSTRING("page_url"), mData.uri);
       nsCOMPtr<mozIStoragePendingStatement> pendingStmt;
       (void)stmt->ExecuteAsync(this, getter_AddRefs(pendingStmt));
     }
   }
 
   NS_IMETHOD HandleResult(mozIStorageResultSet* aResultSet)
   {
     nsCOMPtr<mozIStorageRow> row;
@@ -2911,24 +2915,24 @@ nsNavBookmarks::AddObserver(nsINavBookma
 
 NS_IMETHODIMP
 nsNavBookmarks::RemoveObserver(nsINavBookmarkObserver* aObserver)
 {
   return mObservers.RemoveWeakElement(aObserver);
 }
 
 void
-nsNavBookmarks::NotifyItemVisited(ItemVisitData aData)
+nsNavBookmarks::NotifyItemVisited(const ItemVisitData& aData)
 {
   NOTIFY_OBSERVERS(mCanNotify, mCacheObservers, mObservers, nsINavBookmarkObserver,
                    OnItemVisited(aData.itemId, aData.visitId, aData.time));
 }
 
 void
-nsNavBookmarks::NotifyItemChanged(ItemChangeData aData)
+nsNavBookmarks::NotifyItemChanged(const ItemChangeData& aData)
 {
   NOTIFY_OBSERVERS(mCanNotify, mCacheObservers, mObservers, nsINavBookmarkObserver,
                    OnItemChanged(aData.itemId, aData.property,
                                  aData.isAnnotation, aData.newValue,
                                  aData.lastModified, aData.itemType));
 }
 
 ////////////////////////////////////////////////////////////////////////////////
@@ -2965,16 +2969,17 @@ nsNavBookmarks::OnVisit(nsIURI* aURI, PR
   // If the page is bookmarked, notify observers for each associated bookmark.
   ItemVisitData visitData;
   visitData.uri = aURI;
   visitData.visitId = aVisitId;
   visitData.time = aTime;
 
   nsRefPtr< AsyncGetBookmarksForURI<ItemVisitMethod, ItemVisitData> > notifier =
     new AsyncGetBookmarksForURI<ItemVisitMethod, ItemVisitData>(this, &nsNavBookmarks::NotifyItemVisited, visitData);
+  notifier->Init();
   return NS_OK;
 }
 
 
 NS_IMETHODIMP
 nsNavBookmarks::OnBeforeDeleteURI(nsIURI* aURI)
 {
   return NS_OK;
@@ -2989,16 +2994,17 @@ nsNavBookmarks::OnDeleteURI(nsIURI* aURI
   changeData.uri = aURI;
   changeData.property = NS_LITERAL_CSTRING("cleartime");
   changeData.isAnnotation = PR_FALSE;
   changeData.lastModified = 0;
   changeData.itemType = TYPE_BOOKMARK;
 
   nsRefPtr< AsyncGetBookmarksForURI<ItemChangeMethod, ItemChangeData> > notifier =
     new AsyncGetBookmarksForURI<ItemChangeMethod, ItemChangeData>(this, &nsNavBookmarks::NotifyItemChanged, changeData);
+  notifier->Init();
   return NS_OK;
 }
 
 
 NS_IMETHODIMP
 nsNavBookmarks::OnClearHistory()
 {
   // TODO(bryner): we should notify on visited-time change for all URIs
@@ -3049,16 +3055,17 @@ nsNavBookmarks::OnPageChanged(nsIURI* aU
       if (queries.Count() == 1 && queries[0]->Folders().Length() == 1) {
         changeData.itemId = queries[0]->Folders()[0];
         NotifyItemChanged(changeData);
       }
     }
     else {
       nsRefPtr< AsyncGetBookmarksForURI<ItemChangeMethod, ItemChangeData> > notifier =
         new AsyncGetBookmarksForURI<ItemChangeMethod, ItemChangeData>(this, &nsNavBookmarks::NotifyItemChanged, changeData);
+      notifier->Init();
     }
   }
   return NS_OK;
 }
 
 
 NS_IMETHODIMP
 nsNavBookmarks::OnDeleteVisits(nsIURI* aURI, PRTime aVisitTime)
--- a/toolkit/components/places/src/nsNavBookmarks.h
+++ b/toolkit/components/places/src/nsNavBookmarks.h
@@ -69,18 +69,18 @@ namespace places {
     nsCOMPtr<nsIURI> uri;
     nsCString property;
     PRBool isAnnotation;
     nsCString newValue;
     PRTime lastModified;
     PRUint16 itemType;
   };
 
-  typedef void (nsNavBookmarks::*ItemVisitMethod)(ItemVisitData);
-  typedef void (nsNavBookmarks::*ItemChangeMethod)(ItemChangeData);
+  typedef void (nsNavBookmarks::*ItemVisitMethod)(const ItemVisitData&);
+  typedef void (nsNavBookmarks::*ItemChangeMethod)(const ItemChangeData&);
 
 } // namespace places
 } // namespace mozilla
 
 
 class nsIOutputStream;
 
 class nsNavBookmarks : public nsINavBookmarksService,
@@ -206,27 +206,27 @@ public:
   /**
    * Notifies that a bookmark has been visited.
    *
    * @param aItemId
    *        The visited item id.
    * @param aData
    *        Details about the new visit.
    */
-  void NotifyItemVisited(mozilla::places::ItemVisitData aData);
+  void NotifyItemVisited(const mozilla::places::ItemVisitData& aData);
 
   /**
    * Notifies that a bookmark has changed.
    *
    * @param aItemId
    *        The changed item id.
    * @param aData
    *        Details about the change.
    */
-  void NotifyItemChanged(mozilla::places::ItemChangeData aData);
+  void NotifyItemChanged(const mozilla::places::ItemChangeData& aData);
 
 private:
   static nsNavBookmarks* gBookmarksService;
 
   ~nsNavBookmarks();
 
   /**
    * Locates the root items in the bookmarks folder hierarchy assigning folder