chromium/chrome/browser/web_applications/isolated_web_apps/isolated_web_app_reader_registry.cc

// Copyright 2022 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/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 {

// References to `SignedWebBundleReader`s that are not used for the provided
// time interval will be removed from the cache. This is important so that the
// cache doesn't grow forever, given that each `SignedWebBundleReader` requires
// some memory and an open file handle.
//
// Note: Depending on when during the interval a new `SignedWebBundleReader` is
// accessed, the worst-case time until it is cleaned up can be up to two times
// `kCleanupInterval`, since the logic for cleaning up `SignedWebBundleReader`s
// is as follows: Every `kCleanupInterval`, remove references to all
// `SignedWebBundleReader`s that haven't been accessed for at least
// `kCleanupInterval`.
// We could run a separate timer per `SignedWebBundleReader` to more accurately
// respect `kCleanupInterval`, but this feels like unnecessary overhead.
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) {}

}  // namespace

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) {}

// Processes a component update event and queues close requests for readers
// corresponding to bundles that might be affected by key rotation. These
// requests will be fulfilled once the app closes.
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) {}

// static
IsolatedWebAppReaderRegistry::ReadResponseError
IsolatedWebAppReaderRegistry::ReadResponseError::ForError(
    const UnusableSwbnFileError& error) {}

// static
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;

}  // namespace web_app