-
Notifications
You must be signed in to change notification settings - Fork 6.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
iwa: Add InstallabilityChecker to IWA installer UI
InstallabilityChecker is a helper class that encapsulates IsolatedWebAppUrlInfo and SignedWebBundleMetadata creation, and the CheckIsolatedWebAppBundleInstallability call, and is called by the UI's ViewController when it is started. This has several other changes to the UI to make testing easier. In particular the ViewController can now be Start()ed without being Show()n to simulate running through the UI without creating the real View. Bug: 1479140 Change-Id: I90493212de48f794f907e5c8a60ac30655eb82af Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4977278 Reviewed-by: Zelin Liu <zelin@chromium.org> Commit-Queue: Robbie McElrath <rmcelrath@chromium.org> Cr-Commit-Position: refs/heads/main@{#1217254}
- Loading branch information
Showing
12 changed files
with
524 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
108 changes: 108 additions & 0 deletions
108
chrome/browser/ui/views/web_apps/isolated_web_apps/installability_checker.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
// Copyright 2023 The Chromium Authors | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#include "chrome/browser/ui/views/web_apps/isolated_web_apps/installability_checker.h" | ||
|
||
#include <memory> | ||
#include <string> | ||
|
||
#include "base/functional/callback.h" | ||
#include "base/memory/ptr_util.h" | ||
#include "base/types/expected.h" | ||
#include "chrome/browser/profiles/profile.h" | ||
#include "chrome/browser/web_applications/isolated_web_apps/check_isolated_web_app_bundle_installability_command.h" | ||
#include "chrome/browser/web_applications/isolated_web_apps/isolated_web_app_location.h" | ||
#include "chrome/browser/web_applications/isolated_web_apps/isolated_web_app_url_info.h" | ||
#include "chrome/browser/web_applications/isolated_web_apps/signed_web_bundle_metadata.h" | ||
#include "chrome/browser/web_applications/web_app_command_scheduler.h" | ||
#include "chrome/browser/web_applications/web_app_provider.h" | ||
#include "third_party/abseil-cpp/absl/types/optional.h" | ||
|
||
namespace web_app { | ||
|
||
namespace { | ||
using InstallabilityCheckResult = | ||
CheckIsolatedWebAppBundleInstallabilityCommand::InstallabilityCheckResult; | ||
} // namespace | ||
|
||
// static | ||
std::unique_ptr<InstallabilityChecker> InstallabilityChecker::CreateAndStart( | ||
Profile* profile, | ||
WebAppProvider* web_app_provider, | ||
const base::FilePath& bundle_path, | ||
Delegate* delegate) { | ||
std::unique_ptr<InstallabilityChecker> checker = base::WrapUnique( | ||
new InstallabilityChecker(profile, web_app_provider, delegate)); | ||
checker->Start(bundle_path); | ||
return checker; | ||
} | ||
|
||
InstallabilityChecker::~InstallabilityChecker() = default; | ||
|
||
InstallabilityChecker::InstallabilityChecker(Profile* profile, | ||
WebAppProvider* web_app_provider, | ||
Delegate* delegate) | ||
: profile_(profile), | ||
web_app_provider_(web_app_provider), | ||
delegate_(delegate) { | ||
CHECK(profile_); | ||
CHECK(web_app_provider_); | ||
CHECK(delegate_); | ||
} | ||
|
||
void InstallabilityChecker::Start(const base::FilePath& bundle_path) { | ||
IsolatedWebAppLocation location = DevModeBundle{bundle_path}; | ||
IsolatedWebAppUrlInfo::CreateFromIsolatedWebAppLocation( | ||
location, base::BindOnce(&InstallabilityChecker::OnLoadedUrlInfo, | ||
weak_ptr_factory_.GetWeakPtr(), location)); | ||
} | ||
|
||
void InstallabilityChecker::OnLoadedUrlInfo( | ||
IsolatedWebAppLocation location, | ||
base::expected<IsolatedWebAppUrlInfo, std::string> url_info) { | ||
if (!url_info.has_value()) { | ||
delegate_->OnBundleInvalid(url_info.error()); | ||
return; | ||
} | ||
SignedWebBundleMetadata::Create( | ||
profile_, web_app_provider_, url_info.value(), location, | ||
base::BindOnce(&InstallabilityChecker::OnLoadedMetadata, | ||
weak_ptr_factory_.GetWeakPtr())); | ||
} | ||
|
||
void InstallabilityChecker::OnLoadedMetadata( | ||
base::expected<SignedWebBundleMetadata, std::string> metadata) { | ||
if (!metadata.has_value()) { | ||
delegate_->OnBundleInvalid(metadata.error()); | ||
return; | ||
} | ||
web_app_provider_->scheduler().CheckIsolatedWebAppBundleInstallability( | ||
metadata.value(), | ||
base::BindOnce(&InstallabilityChecker::OnInstallabilityChecked, | ||
weak_ptr_factory_.GetWeakPtr(), metadata.value())); | ||
} | ||
|
||
void InstallabilityChecker::OnInstallabilityChecked( | ||
SignedWebBundleMetadata metadata, | ||
InstallabilityCheckResult installability_check_result, | ||
absl::optional<base::Version> installed_version) { | ||
switch (installability_check_result) { | ||
case InstallabilityCheckResult::kInstallable: | ||
delegate_->OnBundleInstallable(metadata); | ||
return; | ||
case InstallabilityCheckResult::kUpdatable: | ||
CHECK(installed_version.has_value()); | ||
delegate_->OnBundleUpdatable(metadata, installed_version.value()); | ||
return; | ||
case InstallabilityCheckResult::kOutdated: | ||
CHECK(installed_version.has_value()); | ||
delegate_->OnBundleOutdated(metadata, installed_version.value()); | ||
return; | ||
case InstallabilityCheckResult::kShutdown: | ||
delegate_->OnProfileShutdown(); | ||
return; | ||
} | ||
} | ||
|
||
} // namespace web_app |
77 changes: 77 additions & 0 deletions
77
chrome/browser/ui/views/web_apps/isolated_web_apps/installability_checker.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
// Copyright 2023 The Chromium Authors | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#ifndef CHROME_BROWSER_UI_VIEWS_WEB_APPS_ISOLATED_WEB_APPS_INSTALLABILITY_CHECKER_H_ | ||
#define CHROME_BROWSER_UI_VIEWS_WEB_APPS_ISOLATED_WEB_APPS_INSTALLABILITY_CHECKER_H_ | ||
|
||
#include <memory> | ||
#include <string> | ||
|
||
#include "base/memory/weak_ptr.h" | ||
#include "base/types/expected.h" | ||
#include "chrome/browser/web_applications/isolated_web_apps/check_isolated_web_app_bundle_installability_command.h" | ||
#include "chrome/browser/web_applications/isolated_web_apps/isolated_web_app_location.h" | ||
#include "third_party/abseil-cpp/absl/types/optional.h" | ||
|
||
class Profile; | ||
|
||
namespace base { | ||
class FilePath; | ||
class Version; | ||
} // namespace base | ||
|
||
namespace web_app { | ||
|
||
class IsolatedWebAppUrlInfo; | ||
class SignedWebBundleMetadata; | ||
class WebAppProvider; | ||
|
||
class InstallabilityChecker { | ||
public: | ||
class Delegate { | ||
public: | ||
virtual void OnProfileShutdown() = 0; | ||
virtual void OnBundleInvalid(const std::string& error) = 0; | ||
virtual void OnBundleInstallable( | ||
const SignedWebBundleMetadata& metadata) = 0; | ||
virtual void OnBundleUpdatable(const SignedWebBundleMetadata& metadata, | ||
const base::Version& installed_version) = 0; | ||
virtual void OnBundleOutdated(const SignedWebBundleMetadata& metadata, | ||
const base::Version& installed_version) = 0; | ||
}; | ||
|
||
static std::unique_ptr<InstallabilityChecker> CreateAndStart( | ||
Profile* profile, | ||
WebAppProvider* web_app_provider, | ||
const base::FilePath& bundle_path, | ||
Delegate* delegate); | ||
|
||
~InstallabilityChecker(); | ||
|
||
private: | ||
InstallabilityChecker(Profile* profile, | ||
WebAppProvider* web_app_provider, | ||
Delegate* delegate); | ||
|
||
void Start(const base::FilePath& bundle_path); | ||
void OnLoadedUrlInfo( | ||
IsolatedWebAppLocation location, | ||
base::expected<IsolatedWebAppUrlInfo, std::string> url_info); | ||
void OnLoadedMetadata( | ||
base::expected<SignedWebBundleMetadata, std::string> metadata); | ||
void OnInstallabilityChecked( | ||
SignedWebBundleMetadata metadata, | ||
CheckIsolatedWebAppBundleInstallabilityCommand::InstallabilityCheckResult | ||
installability_check_result, | ||
absl::optional<base::Version> installed_version); | ||
|
||
raw_ptr<Profile> profile_; | ||
raw_ptr<WebAppProvider> web_app_provider_; | ||
raw_ptr<Delegate> delegate_; | ||
base::WeakPtrFactory<InstallabilityChecker> weak_ptr_factory_{this}; | ||
}; | ||
|
||
} // namespace web_app | ||
|
||
#endif // CHROME_BROWSER_UI_VIEWS_WEB_APPS_ISOLATED_WEB_APPS_INSTALLABILITY_CHECKER_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.