Bug 1658551 - Move preload usage timer creation to the common NotifyOpen implementation. r=heycam
authorEmilio Cobos Álvarez <emilio@crisal.io>
Thu, 20 Aug 2020 22:01:29 +0000
changeset 545586 c03de6bc26507e7e6bed6ff6f672376c4e0c4088
parent 545585 1539ac976b733bf45b256cc884fe31057fd19cac
child 545587 92a28b0098cf721515094640b487c294482d78aa
push id37716
push userapavel@mozilla.com
push dateFri, 21 Aug 2020 03:37:46 +0000
treeherdermozilla-central@c105f961424c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersheycam
bugs1658551
milestone81.0a1
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 1658551 - Move preload usage timer creation to the common NotifyOpen implementation. r=heycam Not just the one that takes a channel. This fixes the issue. Also, as an optimization, avoid creating a timer if we're used already or we have already one. Differential Revision: https://phabricator.services.mozilla.com/D87267
uriloader/preload/PreloaderBase.cpp
--- a/uriloader/preload/PreloaderBase.cpp
+++ b/uriloader/preload/PreloaderBase.cpp
@@ -104,27 +104,29 @@ void PreloaderBase::NotifyOpen(const Pre
     // Otherwise, this should never happen and is a suspected misuse of the API.
     MOZ_ASSERT(!aIsPreload);
     aDocument->Preloads().DeregisterPreload(aKey);
     aDocument->Preloads().RegisterPreload(aKey, this);
   }
 
   mKey = aKey;
   mIsUsed = !aIsPreload;
+
+  if (!mIsUsed && !mUsageTimer) {
+    auto callback = MakeRefPtr<UsageTimer>(this, aDocument);
+    NS_NewTimerWithCallback(getter_AddRefs(mUsageTimer), callback, 10000,
+                            nsITimer::TYPE_ONE_SHOT);
+  }
 }
 
 void PreloaderBase::NotifyOpen(const PreloadHashKey& aKey, nsIChannel* aChannel,
                                dom::Document* aDocument, bool aIsPreload) {
   NotifyOpen(aKey, aDocument, aIsPreload);
   mChannel = aChannel;
 
-  auto callback = MakeRefPtr<UsageTimer>(this, aDocument);
-  NS_NewTimerWithCallback(getter_AddRefs(mUsageTimer), callback, 10000,
-                          nsITimer::TYPE_ONE_SHOT);
-
   nsCOMPtr<nsIInterfaceRequestor> callbacks;
   mChannel->GetNotificationCallbacks(getter_AddRefs(callbacks));
   RefPtr<RedirectSink> sink(new RedirectSink(this, callbacks));
   mChannel->SetNotificationCallbacks(sink);
 }
 
 void PreloaderBase::NotifyUsage(LoadBackground aLoadBackground) {
   if (!mIsUsed && mChannel && aLoadBackground == LoadBackground::Drop) {