rm_places_sync_methods draft
authorMasatoshi Kimura <VYV03354@nifty.ne.jp>
Sat, 12 Aug 2017 20:11:12 +0900
changeset 645583 665c02f28d39d026bcd6cbca6ed937e3dd0ad707
parent 645582 a06895eac65fe4269aba4595b690a3941c3c8318
child 645584 d14fc750b32ca30e5173baf247aa39215fb3418d
push id73785
push userVYV03354@nifty.ne.jp
push dateSun, 13 Aug 2017 12:06:51 +0000
milestone57.0a1
rm_places_sync_methods MozReview-Commit-ID: GPYd8Nm1Cra
browser/base/content/browser-places.js
browser/components/places/content/bookmarkProperties.js
toolkit/components/places/PlacesUtils.jsm
toolkit/components/places/nsIBrowserHistory.idl
toolkit/components/places/nsINavHistoryService.idl
toolkit/components/places/nsNavHistory.cpp
--- a/browser/base/content/browser-places.js
+++ b/browser/base/content/browser-places.js
@@ -455,17 +455,17 @@ var PlacesCommandHook = {
       // Bug 1148838 - Make this code work for full page plugins.
       var title;
       var description;
       var charset;
 
       let docInfo = await this._getPageDetails(aBrowser);
 
       try {
-        title = docInfo.isErrorPage ? PlacesUtils.history.getPageTitle(uri)
+        title = docInfo.isErrorPage ? (await PlacesUtils.history.fetch(uri)).title
                                     : aBrowser.contentTitle;
         title = title || uri.displaySpec;
         description = docInfo.description;
         charset = aBrowser.characterSet;
       } catch (e) { }
 
       if (aShowEditUI) {
         // If we bookmark the page here but open right into a cancelable
--- a/browser/components/places/content/bookmarkProperties.js
+++ b/browser/components/places/content/bookmarkProperties.js
@@ -145,17 +145,17 @@ var BookmarkPropertiesPanel = {
       return this._strings.getFormattedString("dialogTitleEdit", [this._title]);
     }
     return "";
   },
 
   /**
    * Determines the initial data for the item edited or added by this dialog
    */
-  _determineItemInfo() {
+  async _determineItemInfo() {
     let dialogInfo = window.arguments[0];
     this._action = dialogInfo.action == "add" ? ACTION_ADD : ACTION_EDIT;
     this._hiddenRows = dialogInfo.hiddenRows ? dialogInfo.hiddenRows : [];
     if (this._action == ACTION_ADD) {
       NS_ASSERT("type" in dialogInfo, "missing type property for add action");
 
       if ("title" in dialogInfo)
         this._title = dialogInfo.title;
@@ -173,17 +173,17 @@ var BookmarkPropertiesPanel = {
       switch (dialogInfo.type) {
         case "bookmark":
           this._itemType = BOOKMARK_ITEM;
           if ("uri" in dialogInfo) {
             NS_ASSERT(dialogInfo.uri instanceof Ci.nsIURI,
                       "uri property should be a uri object");
             this._uri = dialogInfo.uri;
             if (typeof(this._title) != "string") {
-              this._title = this._getURITitleFromHistory(this._uri) ||
+              this._title = (await this._getURITitleFromHistory(this._uri)).title ||
                             this._uri.spec;
             }
           } else {
             this._uri = PlacesUtils._uri("about:blank");
             this._title = this._strings.getString("newBookmarkDefault");
             this._dummyItem = true;
           }
 
@@ -216,17 +216,17 @@ var BookmarkPropertiesPanel = {
           this._itemType = LIVEMARK_CONTAINER;
           if ("feedURI" in dialogInfo)
             this._feedURI = dialogInfo.feedURI;
           if ("siteURI" in dialogInfo)
             this._siteURI = dialogInfo.siteURI;
 
           if (!this._title) {
             if (this._feedURI) {
-              this._title = this._getURITitleFromHistory(this._feedURI) ||
+              this._title = (await this._getURITitleFromHistory(this._feedURI)).title ||
                             this._feedURI.spec;
             } else
               this._title = this._strings.getString("newLivemarkDefault");
           }
       }
 
       if ("description" in dialogInfo)
         this._description = dialogInfo.description;
@@ -246,29 +246,29 @@ var BookmarkPropertiesPanel = {
    * the given URI doesn't appear in bookmarks or history), we synthesize
    * a title from the first 100 characters of the URI.
    *
    * @param aURI
    *        nsIURI object for which we want the title
    *
    * @returns a title string
    */
-  _getURITitleFromHistory: function BPP__getURITitleFromHistory(aURI) {
+  async _getURITitleFromHistory(aURI) {
     NS_ASSERT(aURI instanceof Ci.nsIURI);
 
     // get the title from History
-    return PlacesUtils.history.getPageTitle(aURI);
+    return (await PlacesUtils.history.fetch(aURI)).title;
   },
 
   /**
    * This method should be called by the onload of the Bookmark Properties
    * dialog to initialize the state of the panel.
    */
   async onDialogLoad() {
-    this._determineItemInfo();
+    await this._determineItemInfo();
 
     document.title = this._getDialogTitle();
     var acceptButton = document.documentElement.getButton("accept");
     acceptButton.label = this._getAcceptLabel();
 
     // Do not use sizeToContent, otherwise, due to bug 90276, the dialog will
     // grow at every opening.
     // Since elements can be uncollapsed asynchronously, we must observe their
--- a/toolkit/components/places/PlacesUtils.jsm
+++ b/toolkit/components/places/PlacesUtils.jsm
@@ -3709,27 +3709,34 @@ this.PlacesTagURITransaction =
   this.item.uri = aURI;
   this.item.tags = aTags;
 }
 
 PlacesTagURITransaction.prototype = {
   __proto__: BaseTransaction.prototype,
 
   doTransaction: function TUTXN_doTransaction() {
-    if (PlacesUtils.getMostRecentBookmarkForURI(this.item.uri) == -1) {
-      // There is no bookmark for this uri, but we only allow to tag bookmarks.
-      // Force an unfiled bookmark first.
-      this.item.id =
-        PlacesUtils.bookmarks
-                   .insertBookmark(PlacesUtils.unfiledBookmarksFolderId,
-                                   this.item.uri,
-                                   PlacesUtils.bookmarks.DEFAULT_INDEX,
-                                   PlacesUtils.history.getPageTitle(this.item.uri));
-    }
-    PlacesUtils.tagging.tagURI(this.item.uri, this.item.tags);
+    let done = false;
+    (async () => {
+      if (PlacesUtils.getMostRecentBookmarkForURI(this.item.uri) == -1) {
+        // There is no bookmark for this uri, but we only allow to tag bookmarks.
+        // Force an unfiled bookmark first.
+        this.item.id =
+          PlacesUtils.bookmarks
+                     .insertBookmark(PlacesUtils.unfiledBookmarksFolderId,
+                                     this.item.uri,
+                                     PlacesUtils.bookmarks.DEFAULT_INDEX,
+                                     (await PlacesUtils.history.fetch(this.item.uri)).title);
+      }
+      PlacesUtils.tagging.tagURI(this.item.uri, this.item.tags);
+    })().catch(Cu.reportError)
+                 .then(() => done = true);
+    // TODO: Until we can move to PlacesTransactions.jsm, we must spin the
+    // events loop :(
+    Services.tm.spinEventLoopUntil(() => done);
   },
 
   undoTransaction: function TUTXN_undoTransaction() {
     if (this.item.id != -1) {
       PlacesUtils.bookmarks.removeItem(this.item.id);
       this.item.id = -1;
     }
     PlacesUtils.tagging.untagURI(this.item.uri, this.item.tags);
--- a/toolkit/components/places/nsIBrowserHistory.idl
+++ b/toolkit/components/places/nsIBrowserHistory.idl
@@ -9,40 +9,16 @@
 
 #include "nsISupports.idl"
 #include "nsIGlobalHistory2.idl"
 
 [scriptable, uuid(20d31479-38de-49f4-9300-566d6e834c66)]
 interface nsIBrowserHistory : nsISupports
 {
     /**
-     * Removes a page from global history.
-     *
-     * @note It is preferrable to use this one rather then RemovePages when
-     *       removing less than 10 pages, since it won't start a full batch
-     *       operation.
-     * @deprecated Use PlacesUtils.history.remove() API instead.
-     */
-    void removePage(in nsIURI aURI);
-
-    /**
-     * Removes a list of pages from global history.
-     *
-     * @param aURIs
-     *        Array of URIs to be removed.
-     * @param aLength
-     *        Length of the array.
-     *
-     * @note the removal happens in a batch.
-     * @deprecated Use PlacesUtils.history.remove() API instead.
-     */
-    void removePages([array, size_is(aLength)] in nsIURI aURIs,
-                     in unsigned long aLength);
-
-    /**
      * Removes all global history information about pages for a given host.
      *
      * @param aHost
      *        Hostname to be removed.
      *        An empty host name means local files and anything else with no
      *        hostname.  You can also pass in the localized "(local files)"
      *        title given to you from a history query to remove all
      *        history information from local files.
--- a/toolkit/components/places/nsINavHistoryService.idl
+++ b/toolkit/components/places/nsINavHistoryService.idl
@@ -1293,22 +1293,16 @@ interface nsINavHistoryService : nsISupp
    * True if there is any history. This can be used in UI to determine whether
    * the "clear history" button should be enabled or not. This is much better
    * than using BrowserHistory.count since that can be very slow if there is
    * a lot of history (it must enumerate each item). This is pretty fast.
    */
   readonly attribute boolean hasHistoryEntries;
 
   /**
-   * Gets the original title of the page.
-   * @deprecated use PlacesUtils.history.fetch instead.
-   */
-  AString getPageTitle(in nsIURI aURI);
-
-  /**
    * This is just like markPageAsTyped (in nsIBrowserHistory, also implemented
    * by the history service), but for bookmarks. It declares that the given URI
    * is being opened as a result of following a bookmark. If this URI is loaded
    * soon after this message has been received, that transition will be marked
    * as following a bookmark.
    */
   void markPageAsFollowedBookmark(in nsIURI aURI);
 
--- a/toolkit/components/places/nsNavHistory.cpp
+++ b/toolkit/components/places/nsNavHistory.cpp
@@ -2534,91 +2534,16 @@ nsNavHistory::CleanupPlacesOnVisitsDelet
                      nsINavHistoryObserver,
                      OnDeleteURI(URIs[i], GUIDs[i], nsINavHistoryObserver::REASON_DELETED));
   }
 
   return NS_OK;
 }
 
 
-// nsNavHistory::RemovePages
-//
-//    Removes a bunch of uris from history.
-//    Has better performance than RemovePage when deleting a lot of history.
-//    We don't do duplicates removal, URIs array should be cleaned-up before.
-
-NS_IMETHODIMP
-nsNavHistory::RemovePages(nsIURI **aURIs, uint32_t aLength)
-{
-  PLACES_WARN_DEPRECATED();
-  NS_ASSERTION(NS_IsMainThread(), "This can only be called on the main thread");
-  NS_ENSURE_ARG(aURIs);
-
-  nsresult rv;
-  // build a list of place ids to delete
-  nsCString deletePlaceIdsQueryString;
-  for (uint32_t i = 0; i < aLength; i++) {
-    int64_t placeId;
-    nsAutoCString guid;
-    if (!aURIs[i])
-      continue;
-    rv = GetIdForPage(aURIs[i], &placeId, guid);
-    NS_ENSURE_SUCCESS(rv, rv);
-    if (placeId != 0) {
-      if (!deletePlaceIdsQueryString.IsEmpty())
-        deletePlaceIdsQueryString.Append(',');
-      deletePlaceIdsQueryString.AppendInt(placeId);
-    }
-  }
-
-  UpdateBatchScoper batch(*this); // sends Begin/EndUpdateBatch to observers
-
-  rv = RemovePagesInternal(deletePlaceIdsQueryString);
-  NS_ENSURE_SUCCESS(rv, rv);
-
-  // Clear the registered embed visits.
-  clearEmbedVisits();
-
-  return NS_OK;
-}
-
-
-// nsNavHistory::RemovePage
-//
-//    Removes all visits and the main history entry for the given URI.
-//    Silently fails if we have no knowledge of the page.
-
-NS_IMETHODIMP
-nsNavHistory::RemovePage(nsIURI *aURI)
-{
-  PLACES_WARN_DEPRECATED();
-  NS_ASSERTION(NS_IsMainThread(), "This can only be called on the main thread");
-  NS_ENSURE_ARG(aURI);
-
-  // Build a list of place ids to delete.
-  int64_t placeId;
-  nsAutoCString guid;
-  nsresult rv = GetIdForPage(aURI, &placeId, guid);
-  NS_ENSURE_SUCCESS(rv, rv);
-  if (placeId == 0) {
-    return NS_OK;
-  }
-  nsAutoCString deletePlaceIdQueryString;
-  deletePlaceIdQueryString.AppendInt(placeId);
-
-  rv = RemovePagesInternal(deletePlaceIdQueryString);
-  NS_ENSURE_SUCCESS(rv, rv);
-
-  // Clear the registered embed visits.
-  clearEmbedVisits();
-
-  return NS_OK;
-}
-
-
 // nsNavHistory::RemovePagesFromHost
 //
 //    This function will delete all history information about pages from a
 //    given host. If aEntireDomain is set, we will also delete pages from
 //    sub hosts (so if we are passed in "microsoft.com" we delete
 //    "www.microsoft.com", "msdn.microsoft.com", etc.). An empty host name
 //    means local files and anything else with no host name. You can also pass
 //    in the localized "(local files)" title given to you from a history query.
@@ -2808,53 +2733,16 @@ nsNavHistory::MarkPageAsFollowedLink(nsI
 
   if (mRecentLink.Count() > RECENT_EVENT_QUEUE_MAX_LENGTH)
     ExpireNonrecentEvents(&mRecentLink);
 
   return NS_OK;
 }
 
 
-NS_IMETHODIMP
-nsNavHistory::GetPageTitle(nsIURI* aURI, nsAString& aTitle)
-{
-  PLACES_WARN_DEPRECATED();
-
-  NS_ASSERTION(NS_IsMainThread(), "This can only be called on the main thread");
-  NS_ENSURE_ARG(aURI);
-
-  aTitle.Truncate(0);
-
-  nsCOMPtr<mozIStorageStatement> stmt = mDB->GetStatement(
-    "SELECT id, url, title, rev_host, visit_count, guid "
-    "FROM moz_places "
-    "WHERE url_hash = hash(:page_url) AND url = :page_url "
-  );
-  NS_ENSURE_STATE(stmt);
-  mozStorageStatementScoper scoper(stmt);
-
-  nsresult rv = URIBinder::Bind(stmt, NS_LITERAL_CSTRING("page_url"), aURI);
-  NS_ENSURE_SUCCESS(rv, rv);
-
-  bool hasResults = false;
-  rv = stmt->ExecuteStep(&hasResults);
-  NS_ENSURE_SUCCESS(rv, rv);
-
-  if (!hasResults) {
-    aTitle.SetIsVoid(true);
-    return NS_OK; // Not found, return a void string.
-  }
-
-  rv = stmt->GetString(2, aTitle);
-  NS_ENSURE_SUCCESS(rv, rv);
-
-  return NS_OK;
-}
-
-
 ////////////////////////////////////////////////////////////////////////////////
 //// mozIStorageVacuumParticipant
 
 NS_IMETHODIMP
 nsNavHistory::GetDatabaseConnection(mozIStorageConnection** _DBConnection)
 {
   return GetDBConnection(_DBConnection);
 }