chromium/extensions/browser/updater/extension_downloader.cc

// Copyright 2012 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "extensions/browser/updater/extension_downloader.h"

#include <stddef.h>

#include <string_view>
#include <utility>

#include "base/command_line.h"
#include "base/files/file_path.h"
#include "base/functional/bind.h"
#include "base/location.h"
#include "base/logging.h"
#include "base/metrics/histogram.h"
#include "base/metrics/histogram_functions.h"
#include "base/metrics/histogram_macros.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_util.h"
#include "base/strings/stringprintf.h"
#include "base/time/time.h"
#include "base/version.h"
#include "components/crx_file/crx_verifier.h"
#include "components/signin/public/identity_manager/access_token_info.h"
#include "components/signin/public/identity_manager/identity_manager.h"
#include "components/signin/public/identity_manager/primary_account_access_token_fetcher.h"
#include "components/signin/public/identity_manager/scope_set.h"
#include "components/update_client/update_query_params.h"
#include "content/public/browser/file_url_loader.h"
#include "content/public/browser/shared_cors_origin_access_list.h"
#include "extensions/browser/extension_file_task_runner.h"
#include "extensions/browser/extensions_browser_client.h"
#include "extensions/browser/updater/extension_cache.h"
#include "extensions/browser/updater/extension_downloader_delegate.h"
#include "extensions/browser/updater/extension_downloader_test_delegate.h"
#include "extensions/browser/updater/request_queue_impl.h"
#include "extensions/common/extension_id.h"
#include "extensions/common/extension_updater_uma.h"
#include "extensions/common/extension_urls.h"
#include "extensions/common/verifier_formats.h"
#include "net/base/backoff_entry.h"
#include "net/base/load_flags.h"
#include "net/base/net_errors.h"
#include "net/http/http_status_code.h"
#include "net/traffic_annotation/network_traffic_annotation.h"
#include "services/network/public/cpp/resource_request.h"
#include "services/network/public/cpp/shared_url_loader_factory.h"
#include "services/network/public/cpp/simple_url_loader.h"
#include "services/network/public/mojom/url_response_head.mojom.h"

Time;
UpdateQueryParams;

namespace extensions {

namespace {

const net::BackoffEntry::Policy kDefaultBackoffPolicy =;

const char kAuthUserQueryKey[] =;

const int kMaxAuthUserValue =;
const int kMaxOAuth2Attempts =;

const char kNotFromWebstoreInstallSource[] =;
const char kDefaultInstallSource[] =;
const char kReinstallInstallSource[] =;

const char kGoogleDotCom[] =;
const char kTokenServiceConsumerId[] =;
const char kWebstoreOAuth2Scope[] =;

ExtensionDownloader::TestObserver* g_test_observer =;
ExtensionDownloaderTestDelegate* g_test_delegate =;

#define RETRY_HISTOGRAM(name, retry_count, url)

bool ShouldRetryRequest(const network::SimpleURLLoader* loader) {}

// This parses and updates a URL query such that the value of the |authuser|
// query parameter is incremented by 1. If parameter was not present in the URL,
// it will be added with a value of 1. All other query keys and values are
// preserved as-is. Returns |false| if the user index exceeds a hard-coded
// maximum.
bool IncrementAuthUserIndex(GURL* url) {}

// This sanitizes update urls used to fetch update manifests for extensions.
std::optional<GURL> SanitizeUpdateURL(const ExtensionId& extension_id,
                                      const GURL& update_url) {}

}  // namespace

const char ExtensionDownloader::kUpdateInteractivityHeader[] =;
const char ExtensionDownloader::kUpdateAppIdHeader[] =;
const char ExtensionDownloader::kUpdateUpdaterHeader[] =;

const char ExtensionDownloader::kUpdateInteractivityForeground[] =;
const char ExtensionDownloader::kUpdateInteractivityBackground[] =;

DownloadFailure::DownloadFailure(
    ExtensionDownloaderDelegate::Error error,
    ExtensionDownloaderDelegate::FailureData failure_data)
    :{}
DownloadFailure::DownloadFailure(DownloadFailure&&) = default;
DownloadFailure::~DownloadFailure() = default;

ExtensionDownloader::ExtensionFetch::ExtensionFetch(
    ExtensionDownloaderTask task,
    const GURL& url,
    const std::string& package_hash,
    const std::string& version,
    const DownloadFetchPriority fetch_priority)
    :{}

ExtensionDownloader::ExtensionFetch::~ExtensionFetch() = default;

std::set<int> ExtensionDownloader::ExtensionFetch::GetRequestIds() const {}

ExtensionDownloader::FetchDataGroupKey::FetchDataGroupKey() = default;

ExtensionDownloader::FetchDataGroupKey::FetchDataGroupKey(
    const FetchDataGroupKey& other) = default;

ExtensionDownloader::FetchDataGroupKey::FetchDataGroupKey(
    const int request_id,
    const GURL& update_url,
    const bool is_force_installed)
    :{}

ExtensionDownloader::FetchDataGroupKey::~FetchDataGroupKey() = default;

bool ExtensionDownloader::FetchDataGroupKey::operator<(
    const FetchDataGroupKey& other) const {}

ExtensionDownloader::ExtensionDownloader(
    ExtensionDownloaderDelegate* delegate,
    scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory,
    const crx_file::VerifierFormat crx_format_requirement,
    const base::FilePath& profile_path)
    :{}

ExtensionDownloader::~ExtensionDownloader() = default;

bool ExtensionDownloader::AddPendingExtension(ExtensionDownloaderTask task) {}

void ExtensionDownloader::StartAllPending(ExtensionCache* cache) {}

void ExtensionDownloader::AddToFetches(
    std::map<FetchDataGroupKey,
             std::vector<std::unique_ptr<ManifestFetchData>>>&
        fetches_preparing,
    ExtensionDownloaderTask task) {}

void ExtensionDownloader::DoStartAllPending() {}

void ExtensionDownloader::SetIdentityManager(
    signin::IdentityManager* identity_manager) {}

ExtensionDownloader::TestObserver::TestObserver() = default;
ExtensionDownloader::TestObserver::~TestObserver() = default;

// static
void ExtensionDownloader::set_test_observer(TestObserver* observer) {}

// static
ExtensionDownloader::TestObserver* ExtensionDownloader::test_observer() {}

// static
void ExtensionDownloader::set_test_delegate(
    ExtensionDownloaderTestDelegate* delegate) {}

void ExtensionDownloader::SetBackoffPolicy(
    std::optional<net::BackoffEntry::Policy> backoff_policy) {}

bool ExtensionDownloader::HasActiveManifestRequestForTesting() {}

ManifestFetchData* ExtensionDownloader::GetActiveManifestFetchForTesting() {}

bool ExtensionDownloader::AddExtensionData(ExtensionDownloaderTask task) {}

void ExtensionDownloader::StartUpdateCheck(
    std::unique_ptr<ManifestFetchData> fetch_data) {}

network::mojom::URLLoaderFactory* ExtensionDownloader::GetURLLoaderFactoryToUse(
    const GURL& url) {}

void ExtensionDownloader::CreateManifestLoader() {}

void ExtensionDownloader::RetryManifestFetchRequest(
    RequestQueue<ManifestFetchData>::Request request,
    int network_error_code,
    int response_code) {}

void ExtensionDownloader::ReportManifestFetchFailure(
    ManifestFetchData* fetch_data,
    ExtensionDownloaderDelegate::Error error,
    const ExtensionDownloaderDelegate::FailureData& data) {}

bool ExtensionDownloader::TryFetchingExtensionsFromCache(
    ManifestFetchData* fetch_data) {}

void ExtensionDownloader::RetryRequestOrHandleFailureOnManifestFetchFailure(
    RequestQueue<ManifestFetchData>::Request request,
    const network::SimpleURLLoader& loader,
    const int response_code) {}

void ExtensionDownloader::OnManifestLoadComplete(
    std::unique_ptr<network::SimpleURLLoader> loader,
    std::unique_ptr<std::string> response_body) {}

void ExtensionDownloader::HandleManifestResults(
    std::unique_ptr<ManifestFetchData> fetch_data,
    std::unique_ptr<UpdateManifestResults> results,
    const std::optional<ManifestParseFailure>& error) {}

ExtensionDownloader::UpdateAvailability
ExtensionDownloader::GetUpdateAvailability(
    const ExtensionId& extension_id,
    const std::vector<const UpdateManifestResult*>& possible_candidates,
    UpdateManifestResult** update_result_out) const {}

void ExtensionDownloader::DetermineUpdates(
    std::vector<ExtensionDownloaderTask> tasks,
    const UpdateManifestResults& possible_updates,
    std::vector<std::pair<ExtensionDownloaderTask, UpdateManifestResult*>>*
        to_update,
    std::vector<std::pair<ExtensionDownloaderTask, DownloadFailure>>*
        failures) {}

std::optional<base::FilePath> ExtensionDownloader::GetCachedExtension(
    const ExtensionId& id,
    const std::string& package_hash,
    const base::Version& expected_version,
    bool manifest_fetch_failed) {}

// Begins (or queues up) download of an updated extension.
void ExtensionDownloader::FetchUpdatedExtension(
    std::unique_ptr<ExtensionFetch> fetch_data,
    std::optional<std::string> info) {}

void ExtensionDownloader::NotifyDelegateDownloadFinished(
    std::unique_ptr<ExtensionFetch> fetch_data,
    bool from_cache,
    const base::FilePath& crx_path,
    bool file_ownership_passed) {}

void ExtensionDownloader::CacheInstallDone(
    std::unique_ptr<ExtensionFetch> fetch_data,
    bool should_download) {}

void ExtensionDownloader::CreateExtensionLoader() {}

void ExtensionDownloader::StartExtensionLoader() {}

void ExtensionDownloader::OnExtensionLoadComplete(base::FilePath crx_path) {}

void ExtensionDownloader::NotifyExtensionsDownloadStageChanged(
    ExtensionIdSet extension_ids,
    ExtensionDownloaderDelegate::Stage stage) {}

void ExtensionDownloader::NotifyExtensionsDownloadFailed(
    ExtensionIdSet extension_ids,
    std::set<int> request_ids,
    ExtensionDownloaderDelegate::Error error) {}

void ExtensionDownloader::NotifyExtensionsDownloadFailedWithFailureData(
    ExtensionIdSet extension_ids,
    std::set<int> request_ids,
    ExtensionDownloaderDelegate::Error error,
    const ExtensionDownloaderDelegate::FailureData& data) {}

void ExtensionDownloader::NotifyExtensionsDownloadFailedWithList(
    std::vector<std::pair<ExtensionDownloaderTask, DownloadFailure>> failures,
    std::set<int> request_ids) {}

bool ExtensionDownloader::IterateFetchCredentialsAfterFailure(
    ExtensionFetch* fetch,
    int response_code) {}

void ExtensionDownloader::OnAccessTokenFetchComplete(
    GoogleServiceAuthError error,
    signin::AccessTokenInfo token_info) {}

ManifestFetchData* ExtensionDownloader::CreateManifestFetchData(
    const GURL& update_url,
    int request_id,
    DownloadFetchPriority fetch_priority) {}

}  // namespace extensions