[go: nahoru, domu]

Restore logic to unsubscribe from permission changes on frame change.

In r441491 I neglected to notice that the lifetime of the
PermissionManager is longer than that of PermissionServiceContext. On
frame changes existing subscriptions should be cleared as they were
before that patch.

PermissionServiceImpl::AddPermissionObserver removes redundant
early return logic checking that
browser_context->GetPermissionManager() is non null.
CreateSubscription already does that.

BUG=677774,678664
TBR=mlamouri@chromium.org

Review-Url: https://codereview.chromium.org/2617863003
Cr-Commit-Position: refs/heads/master@{#442042}
diff --git a/content/browser/permissions/permission_service_context.cc b/content/browser/permissions/permission_service_context.cc
index cffb065..9292a31 100644
--- a/content/browser/permissions/permission_service_context.cc
+++ b/content/browser/permissions/permission_service_context.cc
@@ -27,7 +27,15 @@
         &PermissionSubscription::OnConnectionError, base::Unretained(this)));
   }
 
-  ~PermissionSubscription() = default;
+  ~PermissionSubscription() {
+    DCHECK_NE(id_, 0);
+    BrowserContext* browser_context = context_->GetBrowserContext();
+    DCHECK(browser_context);
+    if (browser_context->GetPermissionManager()) {
+      browser_context->GetPermissionManager()
+          ->UnsubscribePermissionStatusChange(id_);
+    }
+  }
 
   void OnConnectionError() {
     DCHECK_NE(id_, 0);
@@ -105,13 +113,6 @@
 }
 
 void PermissionServiceContext::ObserverHadConnectionError(int subscription_id) {
-  BrowserContext* browser_context = GetBrowserContext();
-  DCHECK(browser_context);
-  if (browser_context->GetPermissionManager()) {
-    browser_context->GetPermissionManager()->UnsubscribePermissionStatusChange(
-        subscription_id);
-  }
-
   auto it = subscriptions_.find(subscription_id);
   DCHECK(it != subscriptions_.end());
   subscriptions_.erase(it);
@@ -139,13 +140,15 @@
 }
 
 void PermissionServiceContext::CancelPendingOperations(
-    RenderFrameHost* render_frame_host) const {
+    RenderFrameHost* render_frame_host) {
   DCHECK(render_frame_host_);
   if (render_frame_host != render_frame_host_)
     return;
 
   for (const auto& service : services_)
     service->CancelPendingOperations();
+
+  subscriptions_.clear();
 }
 
 BrowserContext* PermissionServiceContext::GetBrowserContext() const {