Commit 517d2965 authored by Esmael El-Moslimany's avatar Esmael El-Moslimany Committed by Chromium LUCI CQ

WebUI NTP: fix issue with additional callbacks not returning OGB

When a user opens multiple New Tabs rapidly, it's possible for multiple
callbacks to await a single OGB response.

When multiple callbacks have been collected, the OGB response should be
sent to each callback. Due to a bug uncovered when disabling caching,
only the first callback was getting the correct OGB response. All the
rest of the callbacks would get an empty string.

Bug: 1167526
Change-Id: I0d57aeb844251b222166bbc4d6236d7df73d9bdb
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2638928
Commit-Queue: Esmael Elmoslimany <aee@chromium.org>
Reviewed-by: default avatarTibor Goldschwendt <tiborg@chromium.org>
Auto-Submit: Esmael Elmoslimany <aee@chromium.org>
Cr-Commit-Position: refs/heads/master@{#845447}
parent d0d4212b
...@@ -121,8 +121,10 @@ void UntrustedSource::StartDataRequest( ...@@ -121,8 +121,10 @@ void UntrustedSource::StartDataRequest(
base::FeatureList::IsEnabled(ntp_features::kCacheOneGoogleBar)) { base::FeatureList::IsEnabled(ntp_features::kCacheOneGoogleBar)) {
OnOneGoogleBarDataUpdated(); OnOneGoogleBarDataUpdated();
} }
one_google_bar_load_start_time_ = base::TimeTicks::Now(); if (one_google_bar_callbacks_.size() == 1) {
one_google_bar_service_->Refresh(); one_google_bar_load_start_time_ = base::TimeTicks::Now();
one_google_bar_service_->Refresh();
}
return; return;
} }
if (path == "one_google_bar.js") { if (path == "one_google_bar.js") {
...@@ -263,8 +265,9 @@ void UntrustedSource::OnOneGoogleBarDataUpdated() { ...@@ -263,8 +265,9 @@ void UntrustedSource::OnOneGoogleBarDataUpdated() {
html = FormatTemplate(IDR_NEW_TAB_PAGE_UNTRUSTED_ONE_GOOGLE_BAR_HTML, html = FormatTemplate(IDR_NEW_TAB_PAGE_UNTRUSTED_ONE_GOOGLE_BAR_HTML,
replacements); replacements);
} }
auto html_ref_counted = base::RefCountedString::TakeString(&html);
for (auto& callback : one_google_bar_callbacks_) { for (auto& callback : one_google_bar_callbacks_) {
std::move(callback).Run(base::RefCountedString::TakeString(&html)); std::move(callback).Run(html_ref_counted);
} }
one_google_bar_callbacks_.clear(); one_google_bar_callbacks_.clear();
} }
......
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