Bug 1544526 - Copy the callback instead of moving r=mayhemer
authorKershaw Chang <kershaw@mozilla.com>
Fri, 26 Apr 2019 18:33:28 +0000
changeset 530534 6d240e54b7ce9e47eb6f65785c8506f9dec39c4a
parent 530533 fcb59a0c2c447b65a172a1caf52d0d5df40f4311
child 530535 c2d1f25ac62f416175d3a91bc2eca6ae42556e7c
push id11265
push userffxbld-merge
push dateMon, 13 May 2019 10:53:39 +0000
treeherdermozilla-beta@77e0fe8dbdd3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmayhemer
bugs1544526
milestone68.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 1544526 - Copy the callback instead of moving r=mayhemer Differential Revision: https://phabricator.services.mozilla.com/D27894
netwerk/ipc/NeckoParent.cpp
netwerk/protocol/http/nsHttpHandler.cpp
netwerk/protocol/http/nsHttpHandler.h
netwerk/protocol/http/nsIHttpProtocolHandler.idl
--- a/netwerk/ipc/NeckoParent.cpp
+++ b/netwerk/ipc/NeckoParent.cpp
@@ -975,15 +975,16 @@ mozilla::ipc::IPCResult NeckoParent::Rec
   return IPC_OK();
 }
 
 mozilla::ipc::IPCResult NeckoParent::RecvEnsureHSTSData(
     EnsureHSTSDataResolver&& aResolver) {
   auto callback = [aResolver{std::move(aResolver)}](bool aResult) {
     aResolver(aResult);
   };
-  gHttpHandler->EnsureHSTSDataReadyNative(
-      new HSTSDataCallbackWrapper(std::move(callback)));
+  RefPtr<HSTSDataCallbackWrapper> wrapper =
+      new HSTSDataCallbackWrapper(std::move(callback));
+  gHttpHandler->EnsureHSTSDataReadyNative(wrapper.forget());
   return IPC_OK();
 }
 
 }  // namespace net
 }  // namespace mozilla
--- a/netwerk/protocol/http/nsHttpHandler.cpp
+++ b/netwerk/protocol/http/nsHttpHandler.cpp
@@ -2596,37 +2596,36 @@ nsHttpsHandler::NewChannel(nsIURI *aURI,
 
 NS_IMETHODIMP
 nsHttpsHandler::AllowPort(int32_t aPort, const char *aScheme, bool *_retval) {
   // don't override anything.
   *_retval = false;
   return NS_OK;
 }
 
-NS_IMETHODIMP
-nsHttpHandler::EnsureHSTSDataReadyNative(HSTSDataCallbackWrapper *aCallback) {
+nsresult nsHttpHandler::EnsureHSTSDataReadyNative(
+    already_AddRefed<mozilla::net::HSTSDataCallbackWrapper> aCallback) {
   MOZ_ASSERT(NS_IsMainThread());
-  MOZ_ASSERT(aCallback);
 
   nsCOMPtr<nsIURI> uri;
   nsresult rv = NS_NewURI(getter_AddRefs(uri), "http://example.com");
   NS_ENSURE_SUCCESS(rv, rv);
 
   bool shouldUpgrade = false;
   bool willCallback = false;
   OriginAttributes originAttributes;
   RefPtr<HSTSDataCallbackWrapper> callback = aCallback;
-  auto func = [callback{std::move(callback)}](bool aResult, nsresult aStatus) {
+  auto func = [callback](bool aResult, nsresult aStatus) {
     callback->DoCallback(aResult);
   };
   rv = NS_ShouldSecureUpgrade(uri, nullptr, nullptr, false, false,
                               originAttributes, shouldUpgrade, std::move(func),
                               willCallback);
   if (NS_FAILED(rv) || !willCallback) {
-    aCallback->DoCallback(false);
+    callback->DoCallback(false);
     return rv;
   }
 
   return rv;
 }
 
 NS_IMETHODIMP
 nsHttpHandler::EnsureHSTSDataReady(JSContext *aCx, Promise **aPromise) {
@@ -2662,17 +2661,17 @@ nsHttpHandler::EnsureHSTSDataReady(JSCon
 
   auto callback = [promise(promise)](bool aResult) {
     promise->MaybeResolve(aResult);
   };
 
   RefPtr<HSTSDataCallbackWrapper> wrapper =
       new HSTSDataCallbackWrapper(std::move(callback));
   promise.forget(aPromise);
-  return EnsureHSTSDataReadyNative(wrapper);
+  return EnsureHSTSDataReadyNative(wrapper.forget());
 }
 
 void nsHttpHandler::ShutdownConnectionManager() {
   // ensure connection manager is shutdown
   if (mConnMgr) {
     nsresult rv = mConnMgr->Shutdown();
     if (NS_FAILED(rv)) {
       LOG(
--- a/netwerk/protocol/http/nsHttpHandler.h
+++ b/netwerk/protocol/http/nsHttpHandler.h
@@ -737,16 +737,20 @@ class nsHttpHandler final : public nsIHt
   TimeStamp mLastActiveTabLoadOptimizationHit;
 
  public:
   MOZ_MUST_USE nsresult NewChannelId(uint64_t &channelId);
 
   void BlacklistSpdy(const nsHttpConnectionInfo *ci);
   MOZ_MUST_USE bool IsSpdyBlacklisted(const nsHttpConnectionInfo *ci);
 
+  virtual nsresult EnsureHSTSDataReadyNative(
+      already_AddRefed<mozilla::net::HSTSDataCallbackWrapper> aCallback)
+      override;
+
  private:
   nsTHashtable<nsCStringHashKey> mBlacklistedSpdyOrigins;
 
   bool mThroughCaptivePortal;
 };
 
 extern StaticRefPtr<nsHttpHandler> gHttpHandler;
 
@@ -768,16 +772,21 @@ class nsHttpsHandler : public nsIHttpPro
   NS_DECL_NSIPROTOCOLHANDLER
   NS_FORWARD_NSIPROXIEDPROTOCOLHANDLER(gHttpHandler->)
   NS_FORWARD_NSIHTTPPROTOCOLHANDLER(gHttpHandler->)
   NS_FORWARD_NSISPECULATIVECONNECT(gHttpHandler->)
 
   nsHttpsHandler() = default;
 
   MOZ_MUST_USE nsresult Init();
+  virtual nsresult EnsureHSTSDataReadyNative(
+      already_AddRefed<mozilla::net::HSTSDataCallbackWrapper> aCallback)
+      override {
+    return gHttpHandler->EnsureHSTSDataReadyNative(std::move(aCallback));
+  }
 };
 
 //-----------------------------------------------------------------------------
 // HSTSDataCallbackWrapper - A threadsafe helper class to wrap the callback.
 //
 // We need this because dom::promise and EnsureHSTSDataResolver are not
 // threadsafe.
 //-----------------------------------------------------------------------------
--- a/netwerk/protocol/http/nsIHttpProtocolHandler.idl
+++ b/netwerk/protocol/http/nsIHttpProtocolHandler.idl
@@ -63,18 +63,20 @@ interface nsIHttpProtocolHandler : nsIPr
      * See bug 1521729 for more details.
      */
     [implicit_jscontext]
     Promise EnsureHSTSDataReady();
 
     /**
      * A C++ friendly version of EnsureHSTSDataReady
      */
-    [noscript]
-    void EnsureHSTSDataReadyNative(in HSTSDataCallbackWrapperPtr aCallback);
+    %{C++
+        virtual nsresult EnsureHSTSDataReadyNative(
+            already_AddRefed<mozilla::net::HSTSDataCallbackWrapper> aCallback) = 0;
+    %}
 };
 
 %{C++
 // ----------- Categories -----------
 /**
  * At initialization time, the HTTP handler will initialize each service
  * registered under this category:
  */