Skip to content

Commit

Permalink
WebAppUiManagerImpl: Register URLDataSource immediately
Browse files Browse the repository at this point in the history
We avoid the possibility of flakes in
ChromeURLDataManagerWebUITrustedTypesTest.NoTrustedTypesViolation/chrome___web_app_internals
if there is a delay in the web app database being loaded.

The source for chrome://web-app-internals now registers immediately.

The implementation in WebAppInternalsSource waits for the web app system
to signal it is ready.

Bug: 1257413
Change-Id: I0e2fd3c6d9d5d53e3ff07d9dc1f6bace2f6915af
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3223079
Auto-Submit: Eric Willigers <ericwilligers@chromium.org>
Reviewed-by: Alan Cutter <alancutter@chromium.org>
Commit-Queue: Eric Willigers <ericwilligers@chromium.org>
Cr-Commit-Position: refs/heads/main@{#931876}
  • Loading branch information
ericwilligers authored and Chromium LUCI CQ committed Oct 15, 2021
1 parent c7bd5eb commit b06047e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
10 changes: 5 additions & 5 deletions chrome/browser/ui/web_applications/web_app_ui_manager_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,11 @@ WebAppUiManagerImpl* WebAppUiManagerImpl::Get(

WebAppUiManagerImpl::WebAppUiManagerImpl(Profile* profile)
: dialog_manager_(std::make_unique<WebAppDialogManager>(profile)),
profile_(profile) {}
profile_(profile) {
// Register the source for the chrome://web-app-internals page.
content::URLDataSource::Add(
profile_, std::make_unique<WebAppInternalsSource>(profile_));
}

WebAppUiManagerImpl::~WebAppUiManagerImpl() = default;

Expand All @@ -148,10 +152,6 @@ void WebAppUiManagerImpl::Start() {
FROM_HERE, base::BindOnce(&WebAppUiManagerImpl::OnExtensionSystemReady,
weak_ptr_factory_.GetWeakPtr()));

// Register the source for the chrome://web-app-internals page.
content::URLDataSource::Add(
profile_, std::make_unique<WebAppInternalsSource>(profile_));

BrowserList::AddObserver(this);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,9 +228,6 @@ void BuildWebAppInternalsJson(
Profile* profile,
base::OnceCallback<void(base::Value root)> callback) {
auto* provider = web_app::WebAppProvider::GetForLocalAppsUnchecked(profile);
if (!provider)
return std::move(callback).Run(
base::Value("Web app system not enabled for profile."));

base::Value root(base::Value::Type::LIST);
root.Append(BuildIndexJson());
Expand All @@ -247,6 +244,19 @@ void BuildWebAppInternalsJson(
std::move(callback));
}

void BuildResponse(Profile* profile,
base::OnceCallback<void(base::Value root)> callback) {
auto* provider = web_app::WebAppProvider::GetForLocalAppsUnchecked(profile);
if (!provider) {
return std::move(callback).Run(
base::Value("Web app system not enabled for profile."));
}

provider->on_registry_ready().Post(
FROM_HERE,
base::BindOnce(&BuildWebAppInternalsJson, profile, std::move(callback)));
}

void ConvertValueToJsonData(content::URLDataSource::GotDataCallback callback,
base::Value value) {
std::string data = value.DebugString();
Expand All @@ -272,6 +282,6 @@ void WebAppInternalsSource::StartDataRequest(
const GURL& url,
const content::WebContents::Getter& wc_getter,
content::URLDataSource::GotDataCallback callback) {
BuildWebAppInternalsJson(
profile_, base::BindOnce(&ConvertValueToJsonData, std::move(callback)));
BuildResponse(profile_,
base::BindOnce(&ConvertValueToJsonData, std::move(callback)));
}

0 comments on commit b06047e

Please sign in to comment.