Bug 1539539 - Add main thread assertion and fix a clang warning r=mayhemer
authorKershaw Chang <kershaw@mozilla.com>
Thu, 28 Mar 2019 15:03:46 +0000
changeset 466724 447f58b42b72d5f54f09d301ec1fe5ff03d3fd43
parent 466723 beed1b214c4fbb4c7695a9ea75b06cf9e18517f8
child 466725 bd16a067d3b83e0f855df857ce7037c44bb862d9
push id35780
push useropoprus@mozilla.com
push dateFri, 29 Mar 2019 21:53:01 +0000
treeherdermozilla-central@414f37afbe07 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmayhemer
bugs1539539
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 1539539 - Add main thread assertion and fix a clang warning r=mayhemer The resultCallback at [1] should be always executed on main thread, so adding an assertion to enforce this. This patch also fixes a warning at [2]. This is about moving a const captured variable. [1] https://searchfox.org/mozilla-central/rev/3d469329a42644b41e66944d8da22d78d8c0f5ec/netwerk/protocol/http/nsHttpChannel.cpp#551-558 [2] https://searchfox.org/mozilla-central/rev/3d469329a42644b41e66944d8da22d78d8c0f5ec/netwerk/base/nsNetUtil.cpp#2808 Differential Revision: https://phabricator.services.mozilla.com/D25219
netwerk/base/nsNetUtil.cpp
netwerk/protocol/http/nsHttpChannel.cpp
--- a/netwerk/base/nsNetUtil.cpp
+++ b/netwerk/base/nsNetUtil.cpp
@@ -2785,17 +2785,17 @@ nsresult NS_ShouldSecureUpgrade(
       nsCOMPtr<nsIURI> uri = aURI;
       nsCOMPtr<nsISiteSecurityService> service = sss;
       rv = gSocketTransportService->Dispatch(
           NS_NewRunnableFunction(
               "net::NS_ShouldSecureUpgrade",
               [service{std::move(service)}, uri{std::move(uri)}, flags(flags),
                originAttributes(aOriginAttributes),
                handleResultFunc{std::move(handleResultFunc)},
-               resultCallback{std::move(aResultCallback)}]() {
+               resultCallback{std::move(aResultCallback)}]() mutable {
                 uint32_t hstsSource = 0;
                 bool isStsHost = false;
                 nsresult rv = service->IsSecureURI(
                     nsISiteSecurityService::HEADER_HSTS, uri, flags,
                     originAttributes, nullptr, &hstsSource, &isStsHost);
 
                 // Successfully get the result from |IsSecureURI| implies that
                 // the storage is ready to read.
--- a/netwerk/protocol/http/nsHttpChannel.cpp
+++ b/netwerk/protocol/http/nsHttpChannel.cpp
@@ -548,16 +548,18 @@ nsresult nsHttpChannel::OnBeforeConnect(
   if (isHttp) {
     if (!shouldUpgrade) {
       // Make sure http channel is released on main thread.
       // See bug 1539148 for details.
       nsMainThreadPtrHandle<nsHttpChannel> self(
           new nsMainThreadPtrHolder<nsHttpChannel>(
               "nsHttpChannel::OnBeforeConnect::self", this));
       auto resultCallback = [self(self)](bool aResult, nsresult aStatus) {
+        MOZ_ASSERT(NS_IsMainThread());
+
         nsresult rv = self->ContinueOnBeforeConnect(aResult, aStatus);
         if (NS_FAILED(rv)) {
           self->CloseCacheEntry(false);
           Unused << self->AsyncAbort(rv);
         }
       };
 
       bool willCallback = false;