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(
}
void ExtensionWebRequestEventRouter::AddCallbackForPageLoad(
const base::Closure& callback) {
callbacks_for_page_load_.push_back(callback);
base::OnceClosure callback) {
callbacks_for_page_load_.push_back(std::move(callback));
}
bool ExtensionWebRequestEventRouter::HasExtraHeadersListenerForRequest(
......@@ -1861,8 +1861,8 @@ bool ExtensionWebRequestEventRouter::IsPageLoad(
}
void ExtensionWebRequestEventRouter::NotifyPageLoad() {
for (const auto& callback : callbacks_for_page_load_)
callback.Run();
for (auto& callback : callbacks_for_page_load_)
std::move(callback).Run();
callbacks_for_page_load_.clear();
}
......@@ -2537,9 +2537,8 @@ bool ClearCacheQuotaHeuristic::Apply(Bucket* bucket,
// webRequest.handlerBehaviorChanged() clears the cache.
if (!callback_registered_) {
ExtensionWebRequestEventRouter::GetInstance()->AddCallbackForPageLoad(
base::Bind(&ClearCacheQuotaHeuristic::OnPageLoad,
weak_ptr_factory_.GetWeakPtr(),
bucket));
base::BindOnce(&ClearCacheQuotaHeuristic::OnPageLoad,
weak_ptr_factory_.GetWeakPtr(), bucket));
callback_registered_ = true;
}
......
......@@ -496,7 +496,7 @@ class ExtensionWebRequestEventRouter {
// Registers a |callback| that is executed when the next page load happens.
// 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
// ExtraInfoSpec::EXTRA_HEADERS set.
......@@ -602,7 +602,7 @@ class ExtensionWebRequestEventRouter {
using CrossBrowserContextMap =
std::map<content::BrowserContext*,
std::pair<bool, content::BrowserContext*>>;
using CallbacksForPageLoad = std::list<base::Closure>;
using CallbacksForPageLoad = std::list<base::OnceClosure>;
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