Bug 1587365 - Allow multiple callers to wait for permissions r=asuth
authorPerry Jiang <perry@mozilla.com>
Sat, 12 Oct 2019 03:21:41 +0000
changeset 497357 1a7f07b833e14e8e667a405c0641200103185939
parent 497356 ed90ca2fb5a80c666487a2fb23fc0cb111974484
child 497358 06ea2371f897a70c083d1dba53bd3930da2e997b
push id97831
push userbugmail@asutherland.org
push dateSat, 12 Oct 2019 03:22:39 +0000
treeherderautoland@1a7f07b833e1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersasuth
bugs1587365
milestone71.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 1587365 - Allow multiple callers to wait for permissions r=asuth Differential Revision: https://phabricator.services.mozilla.com/D49043
extensions/permissions/nsPermissionManager.cpp
extensions/permissions/nsPermissionManager.h
--- a/extensions/permissions/nsPermissionManager.cpp
+++ b/extensions/permissions/nsPermissionManager.cpp
@@ -3144,17 +3144,17 @@ nsPermissionManager::GetPermissionsWithK
 
 NS_IMETHODIMP
 nsPermissionManager::SetPermissionsWithKey(const nsACString& aPermissionKey,
                                            nsTArray<IPC::Permission>& aPerms) {
   if (NS_WARN_IF(XRE_IsParentProcess())) {
     return NS_ERROR_NOT_AVAILABLE;
   }
 
-  RefPtr<GenericPromise::Private> promise;
+  RefPtr<GenericNonExclusivePromise::Private> promise;
   bool foundKey =
       mPermissionKeyPromiseMap.Get(aPermissionKey, getter_AddRefs(promise));
   if (promise) {
     MOZ_ASSERT(foundKey);
     // NOTE: This will resolve asynchronously, so we can mark it as resolved
     // now, and be confident that we will have filled in the database before any
     // callbacks run.
     promise->Resolve(true, __func__);
@@ -3305,17 +3305,17 @@ bool nsPermissionManager::PermissionAvai
                                               const nsACString& aType) {
   if (XRE_IsContentProcess()) {
     nsAutoCString permissionKey;
     // NOTE: GetKeyForPermission accepts a null aType.
     GetKeyForPermission(aPrincipal, aType, permissionKey);
 
     // If we have a pending promise for the permission key in question, we don't
     // have the permission available, so report a warning and return false.
-    RefPtr<GenericPromise::Private> promise;
+    RefPtr<GenericNonExclusivePromise::Private> promise;
     if (!mPermissionKeyPromiseMap.Get(permissionKey, getter_AddRefs(promise)) ||
         promise) {
       // Emit a useful diagnostic warning with the permissionKey for the process
       // which hasn't received permissions yet.
       NS_WARNING(nsPrintfCString("This content process hasn't received the "
                                  "permissions for %s yet",
                                  permissionKey.get())
                      .get());
@@ -3330,27 +3330,27 @@ nsPermissionManager::WhenPermissionsAvai
                                               nsIRunnable* aRunnable) {
   MOZ_ASSERT(aRunnable);
 
   if (!XRE_IsContentProcess()) {
     aRunnable->Run();
     return NS_OK;
   }
 
-  nsTArray<RefPtr<GenericPromise>> promises;
+  nsTArray<RefPtr<GenericNonExclusivePromise>> promises;
   for (auto& key : GetAllKeysForPrincipal(aPrincipal)) {
-    RefPtr<GenericPromise::Private> promise;
+    RefPtr<GenericNonExclusivePromise::Private> promise;
     if (!mPermissionKeyPromiseMap.Get(key, getter_AddRefs(promise))) {
       // In this case we have found a permission which isn't available in the
       // content process and hasn't been requested yet. We need to create a new
       // promise, and send the request to the parent (if we have not already
       // done so).
-      promise = new GenericPromise::Private(__func__);
+      promise = new GenericNonExclusivePromise::Private(__func__);
       mPermissionKeyPromiseMap.Put(
-          key, RefPtr<GenericPromise::Private>(promise).forget());
+          key, RefPtr<GenericNonExclusivePromise::Private>(promise).forget());
     }
 
     if (promise) {
       promises.AppendElement(std::move(promise));
     }
   }
 
   // If all of our permissions are available, immediately run the runnable. This
@@ -3359,17 +3359,17 @@ nsPermissionManager::WhenPermissionsAvai
   if (promises.IsEmpty()) {
     aRunnable->Run();
     return NS_OK;
   }
 
   auto* thread = SystemGroup::AbstractMainThreadFor(TaskCategory::Other);
 
   RefPtr<nsIRunnable> runnable = aRunnable;
-  GenericPromise::All(thread, promises)
+  GenericNonExclusivePromise::All(thread, promises)
       ->Then(
           thread, __func__, [runnable]() { runnable->Run(); },
           []() {
             NS_WARNING(
                 "nsPermissionManager permission promise rejected. We're "
                 "probably shutting down.");
           });
   return NS_OK;
--- a/extensions/permissions/nsPermissionManager.h
+++ b/extensions/permissions/nsPermissionManager.h
@@ -524,17 +524,18 @@ class nsPermissionManager final : public
    * Returns false if this permission manager wouldn't have the permission
    * requested available.
    *
    * If aType is nullptr, checks that the permission manager would have all
    * permissions available for the given principal.
    */
   bool PermissionAvailable(nsIPrincipal* aPrincipal, const nsACString& aType);
 
-  nsRefPtrHashtable<nsCStringHashKey, mozilla::GenericPromise::Private>
+  nsRefPtrHashtable<nsCStringHashKey,
+                    mozilla::GenericNonExclusivePromise::Private>
       mPermissionKeyPromiseMap;
 
   nsCOMPtr<mozIStorageConnection> mDBConn;
   nsCOMPtr<mozIStorageAsyncStatement> mStmtInsert;
   nsCOMPtr<mozIStorageAsyncStatement> mStmtDelete;
   nsCOMPtr<mozIStorageAsyncStatement> mStmtUpdate;
 
   bool mMemoryOnlyDB;