Bug 1425458 - Resource timing entries Workers - part 1 - PerformanceStorage on main-thread, r=smaug
authorAndrea Marchesini <amarchesini@mozilla.com>
Wed, 24 Jan 2018 17:17:31 +0100
changeset 400752 8101a66c3180397c79a8e9bb18f5ade2b19cf976
parent 400751 3758a68f961f153f82b643e6bf2727d5c5c63d67
child 400753 cd25cfc3defe1fe948e0d6b408d841bce491a631
push id99218
push useramarchesini@mozilla.com
push dateThu, 25 Jan 2018 11:12:22 +0000
treeherdermozilla-inbound@4f292fa4e4a3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs1425458
milestone60.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 1425458 - Resource timing entries Workers - part 1 - PerformanceStorage on main-thread, r=smaug
dom/performance/Performance.h
dom/performance/PerformanceMainThread.h
dom/performance/PerformanceWorker.h
netwerk/protocol/http/HttpBaseChannel.cpp
netwerk/protocol/http/HttpBaseChannel.h
netwerk/protocol/http/HttpChannelChild.cpp
netwerk/protocol/http/InterceptedHttpChannel.cpp
netwerk/protocol/http/nsHttpChannel.cpp
--- a/dom/performance/Performance.h
+++ b/dom/performance/Performance.h
@@ -8,28 +8,28 @@
 #define mozilla_dom_Performance_h
 
 #include "mozilla/Attributes.h"
 #include "mozilla/DOMEventTargetHelper.h"
 #include "nsCOMPtr.h"
 #include "nsDOMNavigationTiming.h"
 
 class nsITimedChannel;
-class nsIHttpChannel;
 
 namespace mozilla {
 
 class ErrorResult;
 
 namespace dom {
 
 class PerformanceEntry;
 class PerformanceNavigation;
 class PerformanceObserver;
 class PerformanceService;
+class PerformanceStorage;
 class PerformanceTiming;
 
 namespace workers {
 class WorkerPrivate;
 }
 
 // Base class for main-thread and worker Performance API
 class Performance : public DOMEventTargetHelper
@@ -56,18 +56,17 @@ public:
 
   virtual void GetEntriesByType(const nsAString& aEntryType,
                                 nsTArray<RefPtr<PerformanceEntry>>& aRetval);
 
   virtual void GetEntriesByName(const nsAString& aName,
                                 const Optional<nsAString>& aEntryType,
                                 nsTArray<RefPtr<PerformanceEntry>>& aRetval);
 
-  virtual void AddEntry(nsIHttpChannel* channel,
-                        nsITimedChannel* timedChannel) = 0;
+  virtual PerformanceStorage* AsPerformanceStorage() = 0;
 
   void ClearResourceTimings();
 
   DOMHighResTimeStamp Now() const;
 
   DOMHighResTimeStamp TimeOrigin();
 
   void Mark(const nsAString& aName, ErrorResult& aRv);
--- a/dom/performance/PerformanceMainThread.h
+++ b/dom/performance/PerformanceMainThread.h
@@ -3,31 +3,38 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef mozilla_dom_PerformanceMainThread_h
 #define mozilla_dom_PerformanceMainThread_h
 
 #include "Performance.h"
+#include "PerformanceStorage.h"
 
 namespace mozilla {
 namespace dom {
 
 class PerformanceMainThread final : public Performance
+                                  , public PerformanceStorage
 {
 public:
   PerformanceMainThread(nsPIDOMWindowInner* aWindow,
                         nsDOMNavigationTiming* aDOMTiming,
                         nsITimedChannel* aChannel);
 
   NS_DECL_ISUPPORTS_INHERITED
   NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_INHERITED(PerformanceMainThread,
                                                          Performance)
 
+  PerformanceStorage* AsPerformanceStorage() override
+  {
+    return this;
+  }
+
   virtual PerformanceTiming* Timing() override;
 
   virtual PerformanceNavigation* Navigation() override;
 
   virtual void AddEntry(nsIHttpChannel* channel,
                         nsITimedChannel* timedChannel) override;
 
   TimeStamp CreationTimeStamp() const override;
--- a/dom/performance/PerformanceWorker.h
+++ b/dom/performance/PerformanceWorker.h
@@ -16,34 +16,34 @@ namespace workers {
 class WorkerPrivate;
 }
 
 class PerformanceWorker final : public Performance
 {
 public:
   explicit PerformanceWorker(workers::WorkerPrivate* aWorkerPrivate);
 
+  PerformanceStorage* AsPerformanceStorage() override
+  {
+    MOZ_CRASH("This should not be called on workers.");
+    return nullptr;
+  }
+
   virtual PerformanceTiming* Timing() override
   {
     MOZ_CRASH("This should not be called on workers.");
     return nullptr;
   }
 
   virtual PerformanceNavigation* Navigation() override
   {
     MOZ_CRASH("This should not be called on workers.");
     return nullptr;
   }
 
-  virtual void AddEntry(nsIHttpChannel* channel,
-                        nsITimedChannel* timedChannel) override
-  {
-    MOZ_CRASH("This should not be called on workers.");
-  }
-
   TimeStamp CreationTimeStamp() const override;
 
   DOMHighResTimeStamp CreationTime() const override;
 
   virtual void GetMozMemory(JSContext *aCx,
                             JS::MutableHandle<JSObject*> aObj) override
   {
     MOZ_CRASH("This should not be called on workers.");
--- a/netwerk/protocol/http/HttpBaseChannel.cpp
+++ b/netwerk/protocol/http/HttpBaseChannel.cpp
@@ -37,16 +37,17 @@
 #include "nsIMutableArray.h"
 #include "nsIScriptSecurityManager.h"
 #include "nsIObserverService.h"
 #include "nsProxyRelease.h"
 #include "nsPIDOMWindow.h"
 #include "nsIDocShell.h"
 #include "nsINetworkInterceptController.h"
 #include "mozilla/dom/Performance.h"
+#include "mozilla/dom/PerformanceStorage.h"
 #include "mozIThirdPartyUtil.h"
 #include "nsStreamUtils.h"
 #include "nsThreadUtils.h"
 #include "nsContentSecurityManager.h"
 #include "nsIChannelEventSink.h"
 #include "nsILoadGroupChild.h"
 #include "mozilla/ConsoleReportCollector.h"
 #include "LoadInfo.h"
@@ -4150,18 +4151,18 @@ IMPL_TIMING_ATTR(ResponseStart)
 IMPL_TIMING_ATTR(ResponseEnd)
 IMPL_TIMING_ATTR(CacheReadStart)
 IMPL_TIMING_ATTR(CacheReadEnd)
 IMPL_TIMING_ATTR(RedirectStart)
 IMPL_TIMING_ATTR(RedirectEnd)
 
 #undef IMPL_TIMING_ATTR
 
-mozilla::dom::Performance*
-HttpBaseChannel::GetPerformance()
+mozilla::dom::PerformanceStorage*
+HttpBaseChannel::GetPerformanceStorage()
 {
   // If performance timing is disabled, there is no need for the Performance
   // object anymore.
   if (!mTimingEnabled) {
     return nullptr;
   }
 
   // There is no point in continuing, since the performance object in the parent
@@ -4169,16 +4170,22 @@ HttpBaseChannel::GetPerformance()
   if (XRE_IsE10sParentProcess()) {
     return nullptr;
   }
 
   if (!mLoadInfo) {
     return nullptr;
   }
 
+  // If a custom performance storage is set, let's use it.
+  mozilla::dom::PerformanceStorage* performanceStorage = mLoadInfo->GetPerformanceStorage();
+  if (performanceStorage) {
+    return performanceStorage;
+  }
+
   // We don't need to report the resource timing entry for a TYPE_DOCUMENT load.
   if (mLoadInfo->GetExternalContentPolicyType() == nsIContentPolicy::TYPE_DOCUMENT) {
     return nullptr;
   }
 
   nsCOMPtr<nsIDOMDocument> domDocument;
   mLoadInfo->GetLoadingDocument(getter_AddRefs(domDocument));
   if (!domDocument) {
@@ -4198,22 +4205,22 @@ HttpBaseChannel::GetPerformance()
     return nullptr;
   }
 
   nsCOMPtr<nsPIDOMWindowInner> innerWindow = loadingDocument->GetInnerWindow();
   if (!innerWindow) {
     return nullptr;
   }
 
-  mozilla::dom::Performance* docPerformance = innerWindow->GetPerformance();
-  if (!docPerformance) {
+  mozilla::dom::Performance* performance = innerWindow->GetPerformance();
+  if (!performance) {
     return nullptr;
   }
 
-  return docPerformance;
+  return performance->AsPerformanceStorage();
 }
 
 NS_IMETHODIMP
 HttpBaseChannel::SetReportResourceTiming(bool enabled) {
   mReportTiming = enabled;
   return NS_OK;
 }
 
--- a/netwerk/protocol/http/HttpBaseChannel.h
+++ b/netwerk/protocol/http/HttpBaseChannel.h
@@ -57,17 +57,17 @@
 
 
 class nsISecurityConsoleMessage;
 class nsIPrincipal;
 
 namespace mozilla {
 
 namespace dom {
-class Performance;
+class PerformanceStorage;
 }
 
 class LogCollector;
 
 namespace net {
 extern mozilla::LazyLogModule gHttpLog;
 
 /*
@@ -420,17 +420,17 @@ protected:
   virtual void ReleaseListeners();
 
   // This is fired only when a cookie is created due to the presence of
   // Set-Cookie header in the response header of any network request.
   // This notification will come only after the "http-on-examine-response"
   // was fired.
   void NotifySetCookie(char const *aCookie);
 
-  mozilla::dom::Performance* GetPerformance();
+  mozilla::dom::PerformanceStorage* GetPerformanceStorage();
   nsIURI* GetReferringPage();
   nsPIDOMWindowInner* GetInnerDOMWindow();
 
   void AddCookiesToRequest();
   virtual MOZ_MUST_USE nsresult
   SetupReplacementChannel(nsIURI *, nsIChannel *, bool preserveMethod,
                           uint32_t redirectFlags);
 
--- a/netwerk/protocol/http/HttpChannelChild.cpp
+++ b/netwerk/protocol/http/HttpChannelChild.cpp
@@ -30,17 +30,17 @@
 #include "nsContentPolicyUtils.h"
 #include "nsGlobalWindow.h"
 #include "nsStringStream.h"
 #include "nsHttpChannel.h"
 #include "nsHttpHandler.h"
 #include "nsNetUtil.h"
 #include "nsSerializationHelper.h"
 #include "mozilla/Attributes.h"
-#include "mozilla/dom/Performance.h"
+#include "mozilla/dom/PerformanceStorage.h"
 #include "mozilla/ipc/InputStreamUtils.h"
 #include "mozilla/ipc/URIUtils.h"
 #include "mozilla/ipc/BackgroundUtils.h"
 #include "mozilla/net/ChannelDiverterChild.h"
 #include "mozilla/net/DNS.h"
 #include "SerializedLoadContext.h"
 #include "nsInputStreamPump.h"
 #include "InterceptedChannel.h"
@@ -1209,19 +1209,19 @@ void
 HttpChannelChild::DoPreOnStopRequest(nsresult aStatus)
 {
   LOG(("HttpChannelChild::DoPreOnStopRequest [this=%p status=%" PRIx32 "]\n",
        this, static_cast<uint32_t>(aStatus)));
   mIsPending = false;
 
   MaybeCallSynthesizedCallback();
 
-  Performance* documentPerformance = GetPerformance();
-  if (documentPerformance) {
-      documentPerformance->AddEntry(this, this);
+  PerformanceStorage* performanceStorage = GetPerformanceStorage();
+  if (performanceStorage) {
+      performanceStorage->AddEntry(this, this);
   }
 
   if (!mCanceled && NS_SUCCEEDED(mStatus)) {
     mStatus = aStatus;
   }
 
   CollectOMTTelemetry();
 }
--- a/netwerk/protocol/http/InterceptedHttpChannel.cpp
+++ b/netwerk/protocol/http/InterceptedHttpChannel.cpp
@@ -2,17 +2,17 @@
 /* vim: set sw=2 ts=8 et tw=80 : */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  *  License, v. 2.0. If a copy of the MPL was not distributed with this
  *  file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "InterceptedHttpChannel.h"
 #include "nsContentSecurityManager.h"
 #include "nsEscape.h"
-#include "mozilla/dom/Performance.h"
+#include "mozilla/dom/PerformanceStorage.h"
 
 namespace mozilla {
 namespace net {
 
 NS_IMPL_ISUPPORTS_INHERITED(InterceptedHttpChannel,
                             HttpBaseChannel,
                             nsIInterceptedChannel,
                             nsICacheInfoChannel,
@@ -1072,20 +1072,20 @@ InterceptedHttpChannel::OnStopRequest(ns
   // Its possible that we have any async runnable queued to report some
   // progress when OnStopRequest() is triggered.  Report any left over
   // progress immediately.  The extra runnable will then do nothing thanks
   // to the ReleaseListeners() call below.
   MaybeCallStatusAndProgress();
 
   mIsPending = false;
 
-  // Register entry to the Performance resource timing
-  mozilla::dom::Performance* documentPerformance = GetPerformance();
-  if (documentPerformance) {
-    documentPerformance->AddEntry(this, this);
+  // Register entry to the PerformanceStorage resource timing
+  mozilla::dom::PerformanceStorage* performanceStorage = GetPerformanceStorage();
+  if (performanceStorage) {
+    performanceStorage->AddEntry(this, this);
   }
 
   if (mListener) {
     mListener->OnStopRequest(this, mListenerContext, mStatus);
   }
 
   gHttpHandler->OnStopRequest(this);
 
--- a/netwerk/protocol/http/nsHttpChannel.cpp
+++ b/netwerk/protocol/http/nsHttpChannel.cpp
@@ -80,17 +80,17 @@
 #include "nsInputStreamPump.h"
 #include "nsURLHelper.h"
 #include "nsISocketTransport.h"
 #include "nsIStreamConverterService.h"
 #include "nsISiteSecurityService.h"
 #include "nsString.h"
 #include "nsCRT.h"
 #include "CacheObserver.h"
-#include "mozilla/dom/Performance.h"
+#include "mozilla/dom/PerformanceStorage.h"
 #include "mozilla/Telemetry.h"
 #include "AlternateServices.h"
 #include "InterceptedChannel.h"
 #include "nsIHttpPushListener.h"
 #include "nsIX509Cert.h"
 #include "ScopedNSSTypes.h"
 #include "NullPrincipal.h"
 #include "nsIDeprecationWarner.h"
@@ -7327,20 +7327,20 @@ nsHttpChannel::OnStopRequest(nsIRequest 
                 LOG(("FinalizeCacheEntry failed (%08x)",
                      static_cast<uint32_t>(rv)));
             }
         }
     }
 
     ReportRcwnStats(isFromNet);
 
-    // Register entry to the Performance resource timing
-    mozilla::dom::Performance* documentPerformance = GetPerformance();
-    if (documentPerformance) {
-        documentPerformance->AddEntry(this, this);
+    // Register entry to the PerformanceStorage resource timing
+    mozilla::dom::PerformanceStorage* performanceStorage = GetPerformanceStorage();
+    if (performanceStorage) {
+        performanceStorage->AddEntry(this, this);
     }
 
     if (mListener) {
         LOG(("nsHttpChannel %p calling OnStopRequest\n", this));
         MOZ_ASSERT(mOnStartRequestCalled,
                    "OnStartRequest should be called before OnStopRequest");
         MOZ_ASSERT(!mOnStopRequestCalled,
                    "We should not call OnStopRequest twice");