Fix nits in PermissionServiceContext.
Modernize the code and fix lint errors.
Change-Id: Id258594a62be1fc8467028fbbca008184174d314
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1843511
Reviewed-by: Mounir Lamouri <mlamouri@chromium.org>
Commit-Queue: Lei Zhang <thestig@chromium.org>
Cr-Commit-Position: refs/heads/master@{#703842}
diff --git a/content/browser/permissions/permission_service_context.cc b/content/browser/permissions/permission_service_context.cc
index 921cc41..c3ab8129 100644
--- a/content/browser/permissions/permission_service_context.cc
+++ b/content/browser/permissions/permission_service_context.cc
@@ -28,6 +28,8 @@
observer_.set_disconnect_handler(base::BindOnce(
&PermissionSubscription::OnConnectionError, base::Unretained(this)));
}
+ PermissionSubscription(const PermissionSubscription&) = delete;
+ PermissionSubscription& operator=(const PermissionSubscription&) = delete;
~PermissionSubscription() {
DCHECK_NE(id_, 0);
@@ -50,7 +52,7 @@
void set_id(int id) { id_ = id; }
private:
- PermissionServiceContext* context_;
+ PermissionServiceContext* const context_;
mojo::Remote<blink::mojom::PermissionObserver> observer_;
int id_ = 0;
};
@@ -110,16 +112,16 @@
PermissionControllerImpl::FromBrowserContext(browser_context)
->SubscribePermissionStatusChange(
permission_type, render_frame_host_, requesting_origin,
- base::Bind(&PermissionSubscription::OnPermissionStatusChanged,
- base::Unretained(subscription.get())));
+ base::BindRepeating(
+ &PermissionSubscription::OnPermissionStatusChanged,
+ base::Unretained(subscription.get())));
subscription->set_id(subscription_id);
subscriptions_[subscription_id] = std::move(subscription);
}
void PermissionServiceContext::ObserverHadConnectionError(int subscription_id) {
- auto it = subscriptions_.find(subscription_id);
- DCHECK(it != subscriptions_.end());
- subscriptions_.erase(it);
+ size_t erased = subscriptions_.erase(subscription_id);
+ DCHECK_EQ(1u, erased);
}
void PermissionServiceContext::RenderFrameHostChanged(
@@ -168,8 +170,4 @@
: GURL();
}
-RenderFrameHost* PermissionServiceContext::render_frame_host() const {
- return render_frame_host_;
-}
-
-} // namespace content
+} // namespace content
diff --git a/content/browser/permissions/permission_service_context.h b/content/browser/permissions/permission_service_context.h
index c54f763f..4f93be5 100644
--- a/content/browser/permissions/permission_service_context.h
+++ b/content/browser/permissions/permission_service_context.h
@@ -5,7 +5,9 @@
#ifndef CONTENT_BROWSER_PERMISSIONS_PERMISSION_SERVICE_CONTEXT_H_
#define CONTENT_BROWSER_PERMISSIONS_PERMISSION_SERVICE_CONTEXT_H_
-#include "base/macros.h"
+#include <memory>
+#include <unordered_map>
+
#include "content/common/content_export.h"
#include "content/public/browser/permission_type.h"
#include "content/public/browser/web_contents_observer.h"
@@ -32,6 +34,8 @@
public:
explicit PermissionServiceContext(RenderFrameHost* render_frame_host);
explicit PermissionServiceContext(RenderProcessHost* render_process_host);
+ PermissionServiceContext(const PermissionServiceContext&) = delete;
+ PermissionServiceContext& operator=(const PermissionServiceContext&) = delete;
~PermissionServiceContext() override;
void CreateService(
@@ -55,7 +59,7 @@
GURL GetEmbeddingOrigin() const;
- RenderFrameHost* render_frame_host() const;
+ RenderFrameHost* render_frame_host() const { return render_frame_host_; }
RenderProcessHost* render_process_host() const {
return render_process_host_;
}
@@ -69,15 +73,13 @@
void FrameDeleted(RenderFrameHost* render_frame_host) override;
void DidFinishNavigation(NavigationHandle* navigation_handle) override;
- void CloseBindings(RenderFrameHost*);
+ void CloseBindings(RenderFrameHost* render_frame_host);
- RenderFrameHost* render_frame_host_;
- RenderProcessHost* render_process_host_;
+ RenderFrameHost* const render_frame_host_;
+ RenderProcessHost* const render_process_host_;
mojo::UniqueReceiverSet<blink::mojom::PermissionService> services_;
std::unordered_map<int, std::unique_ptr<PermissionSubscription>>
subscriptions_;
-
- DISALLOW_COPY_AND_ASSIGN(PermissionServiceContext);
};
} // namespace content