Bug 1365513 - Remove the call to AbstractThread::GetCurrent() in nsPermissionManager.cpp. r?mystor draft
authorJW Wang <jwwang@mozilla.com>
Thu, 18 May 2017 14:14:27 +0800
changeset 582262 02b8a9a0586eccc29fc1fe8a5d55c73e05ded0ec
parent 582183 74566d5345f4cab06c5683d4b620124104801e65
child 582830 59509c690df8b505c8010ab466b69ea39a3800d3
push id60012
push userjwwang@mozilla.com
push dateMon, 22 May 2017 03:48:05 +0000
reviewersmystor
bugs1365513, 1365483
milestone55.0a1
Bug 1365513 - Remove the call to AbstractThread::GetCurrent() in nsPermissionManager.cpp. r?mystor See bug 1365483 for the rationale. MozReview-Commit-ID: 4sWodnP5MYZ
extensions/cookie/nsPermissionManager.cpp
netwerk/base/nsIPermissionManager.idl
--- a/extensions/cookie/nsPermissionManager.cpp
+++ b/extensions/cookie/nsPermissionManager.cpp
@@ -6,16 +6,17 @@
 
 #include "mozilla/Attributes.h"
 #include "mozilla/DebugOnly.h"
 
 #include "mozilla/dom/ContentParent.h"
 #include "mozilla/dom/ContentChild.h"
 #include "mozilla/BasePrincipal.h"
 #include "mozilla/Services.h"
+#include "mozilla/SystemGroup.h"
 #include "mozilla/Unused.h"
 #include "nsPermissionManager.h"
 #include "nsPermission.h"
 #include "nsCRT.h"
 #include "nsNetUtil.h"
 #include "nsCOMArray.h"
 #include "nsArrayEnumerator.h"
 #include "nsTArray.h"
@@ -3351,19 +3352,21 @@ nsPermissionManager::WhenPermissionsAvai
   // If all of our permissions are avaliable, immediately run the runnable. This
   // avoids any extra overhead during fetch interception which is performance
   // sensitive.
   if (promises.IsEmpty()) {
     aRunnable->Run();
     return NS_OK;
   }
 
+  auto* thread = SystemGroup::AbstractMainThreadFor(TaskCategory::Other);
+
   RefPtr<nsIRunnable> runnable = aRunnable;
-  GenericPromise::All(AbstractThread::GetCurrent(), promises)->Then(
-    AbstractThread::GetCurrent(), __func__,
+  GenericPromise::All(thread, promises)->Then(
+    thread, __func__,
     [runnable] () { runnable->Run(); },
     [] () {
       NS_WARNING("nsPermissionManager permission promise rejected. We're probably shutting down.");
     });
   return NS_OK;
 }
 
 NS_IMETHODIMP
--- a/netwerk/base/nsIPermissionManager.idl
+++ b/netwerk/base/nsIPermissionManager.idl
@@ -326,17 +326,19 @@ interface nsIPermissionManager : nsISupp
    *
    * @param aPrincipal The principal to broadcast permissions for.
    */
   void broadcastPermissionsForPrincipalToAllContentProcesses(in nsIPrincipal aPrincipal);
 
   /**
    * Add a callback which should be run when all permissions are available for
    * the given nsIPrincipal. This method invokes the callback runnable
-   * synchronously when the permissions are already available.
+   * synchronously when the permissions are already available. Otherwise the
+   * callback will be run asynchronously in SystemGroup when all permissions
+   * are available in the future.
    *
    * NOTE: This method will not request the permissions be sent by the parent
    * process. This should only be used to wait for permissions which may not
    * have arrived yet in order to ensure they are present.
    *
    * @param aPrincipal The principal to wait for permissions to be available for.
    * @param aRunnable  The runnable to run when permissions are available for the
    *                   given principal.