Commit 3d297378 authored by David Bokan's avatar David Bokan Committed by Chromium LUCI CQ

Convert ExtensionWebRequestEventRouter to OnceCallback

This class keeps a list of callbacks to invoke on page load but clears
the list after invocation so they can only ever be invoked once.

Bug: 1152268
Change-Id: I97e43b14be743ef6798ce7281b6003e6d34c99cd
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2601228Reviewed-by: default avatarKaran Bhatia <karandeepb@chromium.org>
Commit-Queue: David Bokan <bokan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#839178}
parent 4a0045f2
...@@ -1780,8 +1780,8 @@ void ExtensionWebRequestEventRouter::OnOTRBrowserContextDestroyed( ...@@ -1780,8 +1780,8 @@ void ExtensionWebRequestEventRouter::OnOTRBrowserContextDestroyed(
} }
void ExtensionWebRequestEventRouter::AddCallbackForPageLoad( void ExtensionWebRequestEventRouter::AddCallbackForPageLoad(
const base::Closure& callback) { base::OnceClosure callback) {
callbacks_for_page_load_.push_back(callback); callbacks_for_page_load_.push_back(std::move(callback));
} }
bool ExtensionWebRequestEventRouter::HasExtraHeadersListenerForRequest( bool ExtensionWebRequestEventRouter::HasExtraHeadersListenerForRequest(
...@@ -1861,8 +1861,8 @@ bool ExtensionWebRequestEventRouter::IsPageLoad( ...@@ -1861,8 +1861,8 @@ bool ExtensionWebRequestEventRouter::IsPageLoad(
} }
void ExtensionWebRequestEventRouter::NotifyPageLoad() { void ExtensionWebRequestEventRouter::NotifyPageLoad() {
for (const auto& callback : callbacks_for_page_load_) for (auto& callback : callbacks_for_page_load_)
callback.Run(); std::move(callback).Run();
callbacks_for_page_load_.clear(); callbacks_for_page_load_.clear();
} }
...@@ -2537,9 +2537,8 @@ bool ClearCacheQuotaHeuristic::Apply(Bucket* bucket, ...@@ -2537,9 +2537,8 @@ bool ClearCacheQuotaHeuristic::Apply(Bucket* bucket,
// webRequest.handlerBehaviorChanged() clears the cache. // webRequest.handlerBehaviorChanged() clears the cache.
if (!callback_registered_) { if (!callback_registered_) {
ExtensionWebRequestEventRouter::GetInstance()->AddCallbackForPageLoad( ExtensionWebRequestEventRouter::GetInstance()->AddCallbackForPageLoad(
base::Bind(&ClearCacheQuotaHeuristic::OnPageLoad, base::BindOnce(&ClearCacheQuotaHeuristic::OnPageLoad,
weak_ptr_factory_.GetWeakPtr(), weak_ptr_factory_.GetWeakPtr(), bucket));
bucket));
callback_registered_ = true; callback_registered_ = true;
} }
......
...@@ -496,7 +496,7 @@ class ExtensionWebRequestEventRouter { ...@@ -496,7 +496,7 @@ class ExtensionWebRequestEventRouter {
// Registers a |callback| that is executed when the next page load happens. // Registers a |callback| that is executed when the next page load happens.
// The callback is then deleted. // The callback is then deleted.
void AddCallbackForPageLoad(const base::Closure& callback); void AddCallbackForPageLoad(base::OnceClosure callback);
// Whether there is a listener matching the request that has // Whether there is a listener matching the request that has
// ExtraInfoSpec::EXTRA_HEADERS set. // ExtraInfoSpec::EXTRA_HEADERS set.
...@@ -602,7 +602,7 @@ class ExtensionWebRequestEventRouter { ...@@ -602,7 +602,7 @@ class ExtensionWebRequestEventRouter {
using CrossBrowserContextMap = using CrossBrowserContextMap =
std::map<content::BrowserContext*, std::map<content::BrowserContext*,
std::pair<bool, content::BrowserContext*>>; std::pair<bool, content::BrowserContext*>>;
using CallbacksForPageLoad = std::list<base::Closure>; using CallbacksForPageLoad = std::list<base::OnceClosure>;
ExtensionWebRequestEventRouter(); ExtensionWebRequestEventRouter();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment