Bug 1368754 - Change `NodeHistoryDetailsChanged` to be called with old time and old access count, r?mak draft
authormilindl <i.milind.luthra@gmail.com>
Tue, 30 May 2017 23:46:59 +0530
changeset 586548 ce742d48e84f239ac3839a6235545b1553693b39
parent 586049 34ac1a5d6576d6775491c8a882710a1520551da6
child 586549 b6ffd6278523fa2dc536ac49980bcd4be4176ede
push id61457
push userbmo:i.milind.luthra@gmail.com
push dateTue, 30 May 2017 18:59:43 +0000
reviewersmak
bugs1368754
milestone55.0a1
Bug 1368754 - Change `NodeHistoryDetailsChanged` to be called with old time and old access count, r?mak Update interface and all instances where the method is called to be called with the old values, since the new values are already there as a part of the node, and thus redundant. MozReview-Commit-ID: 5pcfJbg9tej
toolkit/components/places/nsINavHistoryService.idl
toolkit/components/places/nsLivemarkService.js
toolkit/components/places/nsNavHistoryResult.cpp
--- a/toolkit/components/places/nsINavHistoryService.idl
+++ b/toolkit/components/places/nsINavHistoryService.idl
@@ -392,24 +392,24 @@ interface nsINavHistoryResultObserver : 
   void nodeIconChanged(in nsINavHistoryResultNode aNode);
 
   /**
    * Called right after aNode's time property or accessCount property, or both,
    * have changed.
    *
    * @param aNode
    *        a uri result node
-   * @param aNewVisitDate
-   *        the new visit date
-   * @param aNewAccessCount
-   *        the new access-count
+   * @param aOldVisitDate
+   *        the old visit date
+   * @param aOldAccessCount
+   *        the old access-count
    */
   void nodeHistoryDetailsChanged(in nsINavHistoryResultNode aNode,
-                                 in PRTime aNewVisitDate,
-                                 in unsigned long aNewAccessCount);
+                                 in PRTime aOldVisitDate,
+                                 in unsigned long aOldAccessCount);
 
   /**
    * Called when the tags set on the uri represented by aNode have changed.
    *
    * @param aNode
    *        a uri result node
    *
    * @note: The new tags list is accessible through aNode.tags.
--- a/toolkit/components/places/nsLivemarkService.js
+++ b/toolkit/components/places/nsLivemarkService.js
@@ -669,18 +669,23 @@ Livemark.prototype = {
       }
     }
 
     for (let [ container, observer ] of this._resultObservers) {
       if (this._nodes.has(container)) {
         let nodes = this._nodes.get(container);
         for (let node of nodes) {
           if (!aURI || node.uri == aURI.spec) {
+            let oldAccessCount = node.accessCount;
+            if (aVisitedStatus && node.accessCount === 0) {
+              // This is the first time we are visiting it.
+              node.accessCount = 1;
+            }
             Services.tm.dispatchToMainThread(() => {
-              observer.nodeHistoryDetailsChanged(node, 0, aVisitedStatus);
+              observer.nodeHistoryDetailsChanged(node, 0, oldAccessCount);
             });
           }
         }
       }
     }
   },
 
   /**
--- a/toolkit/components/places/nsNavHistoryResult.cpp
+++ b/toolkit/components/places/nsNavHistoryResult.cpp
@@ -653,28 +653,31 @@ nsNavHistoryContainerResultNode::FillSta
 nsresult
 nsNavHistoryContainerResultNode::ReverseUpdateStats(int32_t aAccessCountChange)
 {
   if (mParent) {
     nsNavHistoryResult* result = GetResult();
     bool shouldNotify = result && mParent->mParent &&
                           mParent->mParent->AreChildrenVisible();
 
+    uint32_t oldAccessCount = mParent->mAccessCount;
+    PRTime oldTime = mParent->mTime;
+
     mParent->mAccessCount += aAccessCountChange;
     bool timeChanged = false;
     if (mTime > mParent->mTime) {
       timeChanged = true;
       mParent->mTime = mTime;
     }
 
     if (shouldNotify) {
       NOTIFY_RESULT_OBSERVERS(result,
                               NodeHistoryDetailsChanged(TO_ICONTAINER(mParent),
-                                                        mParent->mTime,
-                                                        mParent->mAccessCount));
+                                                        oldTime,
+                                                        oldAccessCount));
     }
 
     // check sorting, the stats may have caused this node to move if the
     // sorting depended on something we are changing.
     uint16_t sortMode = mParent->GetSortType();
     bool sortingByVisitCount =
       sortMode == nsINavHistoryQueryOptions::SORT_BY_VISITCOUNT_ASCENDING ||
       sortMode == nsINavHistoryQueryOptions::SORT_BY_VISITCOUNT_DESCENDING;
@@ -1336,24 +1339,27 @@ nsNavHistoryContainerResultNode::InsertC
     container->mResult = result;
     container->FillStats();
   }
 
   if (!mChildren.InsertObjectAt(aNode, aIndex))
     return NS_ERROR_OUT_OF_MEMORY;
 
   // Update our stats and notify the result's observers.
+  uint32_t oldAccessCount = mAccessCount;
+  PRTime oldTime = mTime;
+
   mAccessCount += aNode->mAccessCount;
   if (mTime < aNode->mTime)
     mTime = aNode->mTime;
   if (!mParent || mParent->AreChildrenVisible()) {
     NOTIFY_RESULT_OBSERVERS(result,
                             NodeHistoryDetailsChanged(TO_ICONTAINER(this),
-                                                      mTime,
-                                                      mAccessCount));
+                                                      oldTime,
+                                                      oldAccessCount));
   }
 
   nsresult rv = ReverseUpdateStats(aNode->mAccessCount);
   NS_ENSURE_SUCCESS(rv, rv);
 
   // Update tree if we are visible.  Note that we could be here and not
   // expanded, like when there is a bookmark folder being updated because its
   // parent is visible.
@@ -1562,28 +1568,31 @@ nsNavHistoryContainerResultNode::UpdateU
     nsNavHistoryContainerResultNode* parent = node->mParent;
     if (!parent) {
       MOZ_ASSERT(false, "All URI nodes being updated must have parents");
       continue;
     }
 
     uint32_t oldAccessCount = node->mAccessCount;
     PRTime oldTime = node->mTime;
+
+    uint32_t parentOldAccessCount = parent->mAccessCount;
+    PRTime parentOldTime = parent->mTime;
     aCallback(node, aClosure, result);
 
     if (oldAccessCount != node->mAccessCount || oldTime != node->mTime) {
       parent->mAccessCount += node->mAccessCount - oldAccessCount;
       if (node->mTime > parent->mTime)
         parent->mTime = node->mTime;
       if (parent->AreChildrenVisible()) {
         NOTIFY_RESULT_OBSERVERS_RET(result,
                                     NodeHistoryDetailsChanged(
                                       TO_ICONTAINER(parent),
-                                      parent->mTime,
-                                      parent->mAccessCount),
+                                      parentOldTime,
+                                      parentOldAccessCount),
                                     true);
       }
       DebugOnly<nsresult> rv = parent->ReverseUpdateStats(node->mAccessCount - oldAccessCount);
       MOZ_ASSERT(NS_SUCCEEDED(rv), "should be able to ReverseUpdateStats");
     }
 
     if (aUpdateSort) {
       int32_t childIndex = parent->FindChild(node);
@@ -3755,20 +3764,21 @@ nsNavHistoryResultNode::OnItemChanged(in
     if (shouldNotify)
       NOTIFY_RESULT_OBSERVERS(result, NodeURIChanged(this, mURI));
   }
   else if (aProperty.EqualsLiteral("favicon")) {
     if (shouldNotify)
       NOTIFY_RESULT_OBSERVERS(result, NodeIconChanged(this));
   }
   else if (aProperty.EqualsLiteral("cleartime")) {
+    PRTime oldTime = mTime;
     mTime = 0;
     if (shouldNotify) {
       NOTIFY_RESULT_OBSERVERS(result,
-                              NodeHistoryDetailsChanged(this, 0, mAccessCount));
+                              NodeHistoryDetailsChanged(this, oldTime, mAccessCount));
     }
   }
   else if (aProperty.EqualsLiteral("tags")) {
     mTags.SetIsVoid(true);
     if (shouldNotify)
       NOTIFY_RESULT_OBSERVERS(result, NodeTagsChanged(this));
   }
   else if (aProperty.EqualsLiteral("dateAdded")) {
@@ -3853,16 +3863,18 @@ nsNavHistoryFolderResultNode::OnItemVisi
     return NS_OK;
 
   uint32_t nodeIndex;
   nsNavHistoryResultNode* node = FindChildById(aItemId, &nodeIndex);
   if (!node)
     return NS_ERROR_FAILURE;
 
   // Update node.
+  uint32_t nodeOldAccessCount = node->mAccessCount;
+  PRTime nodeOldTime = node->mTime;
   node->mTime = aTime;
   ++node->mAccessCount;
 
   // Update us.
   int32_t oldAccessCount = mAccessCount;
   ++mAccessCount;
   if (aTime > mTime)
     mTime = aTime;
@@ -3880,17 +3892,17 @@ nsNavHistoryFolderResultNode::OnItemVisi
   NS_ENSURE_SUCCESS(rv, rv);
   NS_ENSURE_STATE(visitNode);
   node->mFrecency = visitNode->mFrecency;
 
   if (AreChildrenVisible()) {
     // Sorting has not changed, just redraw the row if it's visible.
     nsNavHistoryResult* result = GetResult();
     NOTIFY_RESULT_OBSERVERS(result,
-                            NodeHistoryDetailsChanged(node, mTime, mAccessCount));
+                            NodeHistoryDetailsChanged(node, nodeOldTime, nodeOldAccessCount));
   }
 
   // Update sorting if necessary.
   uint32_t sortType = GetSortType();
   if (sortType == nsINavHistoryQueryOptions::SORT_BY_VISITCOUNT_ASCENDING ||
       sortType == nsINavHistoryQueryOptions::SORT_BY_VISITCOUNT_DESCENDING ||
       sortType == nsINavHistoryQueryOptions::SORT_BY_DATE_ASCENDING ||
       sortType == nsINavHistoryQueryOptions::SORT_BY_DATE_DESCENDING ||