#include "chrome/browser/web_applications/isolated_web_apps/isolated_web_app_reader_registry.h"
#include <memory>
#include <utility>
#include "base/barrier_closure.h"
#include "base/functional/bind.h"
#include "base/functional/callback.h"
#include "base/functional/callback_helpers.h"
#include "base/functional/overloaded.h"
#include "base/metrics/histogram_functions.h"
#include "base/ranges/algorithm.h"
#include "base/strings/strcat.h"
#include "base/strings/stringprintf.h"
#include "base/time/time.h"
#include "base/types/expected.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/web_applications/isolated_web_apps/error/uma_logging.h"
#include "chrome/browser/web_applications/isolated_web_apps/isolated_web_app_install_command_helper.h"
#include "chrome/browser/web_applications/isolated_web_apps/isolated_web_app_response_reader.h"
#include "chrome/browser/web_applications/isolated_web_apps/isolated_web_app_response_reader_factory.h"
#include "chrome/browser/web_applications/isolated_web_apps/key_distribution/iwa_key_distribution_info_provider.h"
#include "chrome/browser/web_applications/isolated_web_apps/signed_web_bundle_reader.h"
#include "chrome/browser/web_applications/web_app.h"
#include "chrome/browser/web_applications/web_app_provider.h"
#include "chrome/browser/web_applications/web_app_registrar.h"
#include "chrome/browser/web_applications/web_app_ui_manager.h"
#include "chrome/common/url_constants.h"
#include "components/web_package/signed_web_bundles/signed_web_bundle_id.h"
#include "services/network/public/cpp/resource_request.h"
#include "url/url_constants.h"
namespace web_app {
namespace {
base::TimeDelta kCleanupInterval = …;
base::expected<void, IsolatedWebAppReaderRegistry::ReadResponseHeadError>
ToReadResponseHeadError(
const base::expected<IsolatedWebAppResponseReader::Response,
IsolatedWebAppResponseReader::Error>& response) { … }
void CloseReader(std::unique_ptr<IsolatedWebAppResponseReader> reader,
base::OnceClosure callback) { … }
}
IsolatedWebAppReaderRegistry::IsolatedWebAppReaderRegistry(
Profile& profile,
std::unique_ptr<IsolatedWebAppResponseReaderFactory> reader_factory)
: … { … }
IsolatedWebAppReaderRegistry::~IsolatedWebAppReaderRegistry() { … }
void IsolatedWebAppReaderRegistry::ReadResponse(
const base::FilePath& web_bundle_path,
bool dev_mode,
const web_package::SignedWebBundleId& web_bundle_id,
const network::ResourceRequest& resource_request,
ReadResponseCallback callback) { … }
void IsolatedWebAppReaderRegistry::OnComponentUpdateSuccess(
const base::Version& component_version) { … }
void IsolatedWebAppReaderRegistry::ClearCacheForPath(
const base::FilePath& web_bundle_path,
base::OnceClosure callback) { … }
void IsolatedWebAppReaderRegistry::ClearCacheForPathImpl(
const base::FilePath& web_bundle_path,
bool dev_mode,
base::OnceClosure callback) { … }
void IsolatedWebAppReaderRegistry::OnResponseReaderCreated(
const base::FilePath& web_bundle_path,
bool dev_mode,
const web_package::SignedWebBundleId& web_bundle_id,
base::expected<std::unique_ptr<IsolatedWebAppResponseReader>,
UnusableSwbnFileError> reader) { … }
void IsolatedWebAppReaderRegistry::DoReadResponse(
IsolatedWebAppResponseReader& reader,
network::ResourceRequest resource_request,
ReadResponseCallback callback) { … }
void IsolatedWebAppReaderRegistry::OnResponseRead(
ReadResponseCallback callback,
base::expected<IsolatedWebAppResponseReader::Response,
IsolatedWebAppResponseReader::Error> response) { … }
IsolatedWebAppReaderRegistry::ReadResponseError
IsolatedWebAppReaderRegistry::ReadResponseError::ForError(
const UnusableSwbnFileError& error) { … }
IsolatedWebAppReaderRegistry::ReadResponseError
IsolatedWebAppReaderRegistry::ReadResponseError::ForError(
const IsolatedWebAppResponseReader::Error& error) { … }
IsolatedWebAppReaderRegistry::Cache::Cache() = default;
IsolatedWebAppReaderRegistry::Cache::~Cache() = default;
base::flat_map<IsolatedWebAppReaderRegistry::Cache::Key,
IsolatedWebAppReaderRegistry::Cache::Entry>::iterator
IsolatedWebAppReaderRegistry::Cache::Find(const Key& key) { … }
base::flat_map<IsolatedWebAppReaderRegistry::Cache::Key,
IsolatedWebAppReaderRegistry::Cache::Entry>::iterator
IsolatedWebAppReaderRegistry::Cache::End() { … }
template <class... Args>
std::pair<base::flat_map<IsolatedWebAppReaderRegistry::Cache::Key,
IsolatedWebAppReaderRegistry::Cache::Entry>::iterator,
bool>
IsolatedWebAppReaderRegistry::Cache::Emplace(Args&&... args) { … }
void IsolatedWebAppReaderRegistry::Cache::Erase(
base::flat_map<IsolatedWebAppReaderRegistry::Cache::Key, Entry>::iterator
iterator) { … }
void IsolatedWebAppReaderRegistry::Cache::StartCleanupTimerIfNotRunning() { … }
void IsolatedWebAppReaderRegistry::Cache::StopCleanupTimerIfCacheIsEmpty() { … }
void IsolatedWebAppReaderRegistry::Cache::CleanupOldEntries() { … }
bool IsolatedWebAppReaderRegistry::Cache::Key::operator<(
const Key& other) const { … }
void IsolatedWebAppReaderRegistry::Cache::Entry::SetCloseReaderCallback(
base::OnceClosure callback) { … }
base::OnceClosure
IsolatedWebAppReaderRegistry::Cache::Entry::GetCloseReaderCallback() { … }
std::unique_ptr<IsolatedWebAppResponseReader>
IsolatedWebAppReaderRegistry::Cache::Entry::StealReader() { … }
bool IsolatedWebAppReaderRegistry::Cache::Entry::IsCloseReaderRequested()
const { … }
IsolatedWebAppReaderRegistry::Cache::Entry::Entry() = default;
IsolatedWebAppReaderRegistry::Cache::Entry::~Entry() = default;
IsolatedWebAppReaderRegistry::Cache::Entry::Entry(Entry&& other) = default;
IsolatedWebAppReaderRegistry::Cache::Entry&
IsolatedWebAppReaderRegistry::Cache::Entry::operator=(Entry&& other) = default;
}