Bug 1546723 - Part 3: Change GetSnapshotInitInfo to deal with load info only; r=asuth a=jcristau
authorJan Varga <jan.varga@gmail.com>
Wed, 15 May 2019 06:11:10 +0200
changeset 536839 1521249d7a0721872d481bfa99380e1a6e0962b5
parent 536838 4b55e5f016e61ba390b8fc32fdffb9eb08312728
child 536840 ac0e29e198c468325fb2d9bbe4ec9c684f6595c7
push id2082
push userffxbld-merge
push dateMon, 01 Jul 2019 08:34:18 +0000
treeherdermozilla-release@2fb19d0466d2 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersasuth, jcristau
bugs1546723
milestone68.0
Bug 1546723 - Part 3: Change GetSnapshotInitInfo to deal with load info only; r=asuth a=jcristau This patch renames GetSnapshotInitInfo to GetSnapshotLoadInfo and removes some arguments that are not directly related to load info. Differential Revision: https://phabricator.services.mozilla.com/D31198
dom/localstorage/ActorsParent.cpp
dom/localstorage/PBackgroundLSDatabase.ipdl
--- a/dom/localstorage/ActorsParent.cpp
+++ b/dom/localstorage/ActorsParent.cpp
@@ -1723,23 +1723,24 @@ class Datastore final
   void NoteLiveDatabase(Database* aDatabase);
 
   void NoteFinishedDatabase(Database* aDatabase);
 
   void NoteActiveDatabase(Database* aDatabase);
 
   void NoteInactiveDatabase(Database* aDatabase);
 
-  void GetSnapshotInitInfo(const nsString& aKey, bool& aAddKeyToUnknownItems,
+  void GetSnapshotLoadInfo(const nsString& aKey, bool& aAddKeyToUnknownItems,
                            nsTHashtable<nsStringHashKey>& aLoadedItems,
                            nsTArray<LSItemInfo>& aItemInfos,
-                           uint32_t& aNextLoadIndex, uint32_t& aTotalLength,
-                           int64_t& aInitialUsage, int64_t& aPeakUsage,
+                           uint32_t& aNextLoadIndex,
                            LSSnapshot::LoadState& aLoadState);
 
+  uint32_t GetLength() const { return mValues.Count(); }
+
   const nsTArray<LSItemInfo>& GetOrderedItems() const { return mOrderedItems; }
 
   void GetItem(const nsString& aKey, LSValue& aValue) const;
 
   void GetKeys(nsTArray<nsString>& aKeys) const;
 
   //////////////////////////////////////////////////////////////////////////////
   // Mutation Methods
@@ -1758,16 +1759,18 @@ class Datastore final
   void Clear(Database* aDatabase);
 
   void PrivateBrowsingClear();
 
   void BeginUpdateBatch(int64_t aSnapshotInitialUsage);
 
   int64_t EndUpdateBatch(int64_t aSnapshotPeakUsage);
 
+  int64_t GetUsage() const { return mUsage; }
+
   int64_t RequestUpdateUsage(int64_t aRequestedSize, int64_t aMinSize);
 
   void NotifyObservers(Database* aDatabase, const nsString& aDocumentURI,
                        const nsString& aKey, const LSValue& aOldValue,
                        const LSValue& aNewValue);
 
   NS_INLINE_DECL_REFCOUNTING(Datastore)
 
@@ -4925,23 +4928,21 @@ void Datastore::NoteInactiveDatabase(Dat
       DebugOnly<bool> ok = UpdateUsage(finalDelta);
       MOZ_ASSERT(ok);
     }
 
     mPendingUsageDeltas.Clear();
   }
 }
 
-void Datastore::GetSnapshotInitInfo(const nsString& aKey,
+void Datastore::GetSnapshotLoadInfo(const nsString& aKey,
                                     bool& aAddKeyToUnknownItems,
                                     nsTHashtable<nsStringHashKey>& aLoadedItems,
                                     nsTArray<LSItemInfo>& aItemInfos,
                                     uint32_t& aNextLoadIndex,
-                                    uint32_t& aTotalLength,
-                                    int64_t& aInitialUsage, int64_t& aPeakUsage,
                                     LSSnapshot::LoadState& aLoadState) {
   AssertIsOnBackgroundThread();
   MOZ_ASSERT(!mClosed);
   MOZ_ASSERT(!mInUpdateBatch);
 
 #ifdef DEBUG
   int64_t sizeOfKeys = 0;
   int64_t sizeOfItems = 0;
@@ -5124,21 +5125,16 @@ void Datastore::GetSnapshotInitInfo(cons
 
       break;
     }
 
     default:
       MOZ_CRASH("Bad load state value!");
   }
 
-  aTotalLength = mValues.Count();
-
-  aInitialUsage = mUsage;
-  aPeakUsage = aInitialUsage;
-
   aLoadState = loadState;
 }
 
 void Datastore::GetItem(const nsString& aKey, LSValue& aValue) const {
   AssertIsOnBackgroundThread();
   MOZ_ASSERT(!mClosed);
 
   if (!mValues.Get(aKey, &aValue)) {
@@ -5708,29 +5704,31 @@ mozilla::ipc::IPCResult Database::RecvPB
   MOZ_ASSERT(!mAllowedToClose);
 
   auto* snapshot = static_cast<Snapshot*>(aActor);
 
   bool addKeyToUnknownItems;
   nsTHashtable<nsStringHashKey> loadedItems;
   nsTArray<LSItemInfo> itemInfos;
   uint32_t nextLoadIndex;
-  uint32_t totalLength;
-  int64_t initialUsage;
-  int64_t peakUsage;
   LSSnapshot::LoadState loadState;
-  mDatastore->GetSnapshotInitInfo(aKey, addKeyToUnknownItems, loadedItems,
-                                  itemInfos, nextLoadIndex, totalLength,
-                                  initialUsage, peakUsage, loadState);
+  mDatastore->GetSnapshotLoadInfo(aKey, addKeyToUnknownItems, loadedItems,
+                                  itemInfos, nextLoadIndex, loadState);
 
   nsTHashtable<nsStringHashKey> unknownItems;
   if (addKeyToUnknownItems) {
     unknownItems.PutEntry(aKey);
   }
 
+  uint32_t totalLength = mDatastore->GetLength();
+
+  int64_t initialUsage = mDatastore->GetUsage();
+
+  int64_t peakUsage = initialUsage;
+
   if (aIncreasePeakUsage) {
     int64_t size = mDatastore->RequestUpdateUsage(aRequestedSize, aMinSize);
     peakUsage += size;
   }
 
   snapshot->Init(loadedItems, unknownItems, nextLoadIndex, totalLength,
                  initialUsage, peakUsage, loadState);
 
--- a/dom/localstorage/PBackgroundLSDatabase.ipdl
+++ b/dom/localstorage/PBackgroundLSDatabase.ipdl
@@ -11,17 +11,17 @@ include "mozilla/dom/localstorage/Serial
 
 using mozilla::dom::LSSnapshot::LoadState
   from "mozilla/dom/LSSnapshot.h";
 
 namespace mozilla {
 namespace dom {
 
 /**
- * Initial LSSnapshot state as produced by Datastore::GetSnapshotInitInfo.  See
+ * Initial LSSnapshot state as produced by Datastore::GetSnapshotLoadInfo.  See
  * `LSSnapshot::LoadState` for more details about the possible states and a
  * high level overview.
  */
 struct LSSnapshotInitInfo
 {
   /**
    * Boolean indicating whether the `key` provided as an argument to the
    * PBackgroundLSSnapshot constructor did not exist in the Datastore and should