#include "chrome/browser/extensions/updater/extension_updater.h"
#include <stdint.h>
#include <algorithm>
#include <optional>
#include <set>
#include <string>
#include <utility>
#include <vector>
#include "base/containers/contains.h"
#include "base/files/file_path.h"
#include "base/files/file_util.h"
#include "base/functional/bind.h"
#include "base/logging.h"
#include "base/metrics/histogram_macros.h"
#include "base/not_fatal_until.h"
#include "base/rand_util.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_split.h"
#include "build/chromeos_buildflags.h"
#include "chrome/browser/extensions/crx_installer.h"
#include "chrome/browser/extensions/extension_management.h"
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/extensions/forced_extensions/install_stage_tracker.h"
#include "chrome/browser/extensions/pending_extension_manager.h"
#include "chrome/browser/profiles/keep_alive/profile_keep_alive_types.h"
#include "chrome/browser/profiles/keep_alive/scoped_profile_keep_alive.h"
#include "chrome/browser/profiles/profile.h"
#include "components/prefs/pref_service.h"
#include "components/update_client/update_query_params.h"
#include "content/public/browser/browser_task_traits.h"
#include "content/public/browser/browser_thread.h"
#include "crypto/sha2.h"
#include "extensions/browser/blocklist_extension_prefs.h"
#include "extensions/browser/extension_file_task_runner.h"
#include "extensions/browser/extension_prefs.h"
#include "extensions/browser/extension_registry.h"
#include "extensions/browser/install/crx_install_error.h"
#include "extensions/browser/pref_names.h"
#include "extensions/browser/updater/extension_cache.h"
#include "extensions/browser/updater/extension_update_data.h"
#include "extensions/common/constants.h"
#include "extensions/common/extension.h"
#include "extensions/common/extension_set.h"
#include "extensions/common/extension_updater_uma.h"
#include "extensions/common/extension_urls.h"
#include "extensions/common/manifest.h"
#include "extensions/common/manifest_constants.h"
#include "extensions/common/manifest_url_handlers.h"
#if BUILDFLAG(IS_CHROMEOS_ASH)
#include "chromeos/ash/components/settings/cros_settings.h"
#include "chromeos/ash/components/settings/cros_settings_names.h"
#include "components/user_manager/user_manager.h"
#endif
RandDouble;
UnguessableToken;
Error;
PingResult;
namespace {
bool g_should_immediately_update = …;
#if defined(NDEBUG)
const int kMinUpdateFrequencySeconds = 30;
#endif
const int kMaxUpdateFrequencySeconds = …;
bool g_skip_scheduled_checks_for_tests = …;
bool g_force_use_update_service_for_tests = …;
int SanitizeDays(int days) { … }
int CalculatePingDaysForExtension(const base::Time& last_ping_day) { … }
int CalculateActivePingDays(const base::Time& last_active_ping_day,
bool hasActiveBit) { … }
std::string GetUpdateURLData(const extensions::ExtensionPrefs* prefs,
const std::string& extension_id) { … }
}
namespace extensions {
ExtensionUpdater::CheckParams::CheckParams() = default;
ExtensionUpdater::CheckParams::~CheckParams() = default;
ExtensionUpdater::CheckParams::CheckParams(
ExtensionUpdater::CheckParams&& other) = default;
ExtensionUpdater::CheckParams& ExtensionUpdater::CheckParams::operator=(
ExtensionUpdater::CheckParams&& other) = default;
ExtensionUpdater::FetchedCRXFile::FetchedCRXFile(
const CRXFileInfo& file,
bool file_ownership_passed,
const std::set<int>& request_ids,
InstallCallback callback)
: … { … }
ExtensionUpdater::FetchedCRXFile::FetchedCRXFile()
: … { … }
ExtensionUpdater::FetchedCRXFile::FetchedCRXFile(FetchedCRXFile&& other) =
default;
ExtensionUpdater::FetchedCRXFile& ExtensionUpdater::FetchedCRXFile::operator=(
FetchedCRXFile&& other) = default;
ExtensionUpdater::FetchedCRXFile::~FetchedCRXFile() = default;
ExtensionUpdater::InProgressCheck::InProgressCheck() = default;
ExtensionUpdater::InProgressCheck::~InProgressCheck() = default;
ExtensionUpdater::ExtensionUpdater(
ExtensionServiceInterface* service,
ExtensionPrefs* extension_prefs,
PrefService* prefs,
Profile* profile,
int frequency_seconds,
ExtensionCache* cache,
const ExtensionDownloader::Factory& downloader_factory)
: … { … }
ExtensionUpdater::~ExtensionUpdater() { … }
void ExtensionUpdater::EnsureDownloaderCreated() { … }
void ExtensionUpdater::Start() { … }
void ExtensionUpdater::Stop() { … }
void ExtensionUpdater::ScheduleNextCheck() { … }
void ExtensionUpdater::NextCheck() { … }
void ExtensionUpdater::CheckSoon() { … }
bool ExtensionUpdater::WillCheckSoon() const { … }
void ExtensionUpdater::SetExtensionCacheForTesting(
ExtensionCache* extension_cache) { … }
void ExtensionUpdater::SetExtensionDownloaderForTesting(
std::unique_ptr<ExtensionDownloader> downloader) { … }
void ExtensionUpdater::UpdateImmediatelyForFirstRun() { … }
void ExtensionUpdater::SetBackoffPolicyForTesting(
const net::BackoffEntry::Policy& backoff_policy) { … }
base::AutoReset<bool> ExtensionUpdater::GetScopedUseUpdateServiceForTesting() { … }
void ExtensionUpdater::SetUpdatingStartedCallbackForTesting(
base::RepeatingClosure callback) { … }
void ExtensionUpdater::SetCrxInstallerResultCallbackForTesting(
CrxInstaller::InstallerResultCallback callback) { … }
void ExtensionUpdater::DoCheckSoon() { … }
void ExtensionUpdater::AddToDownloader(
const ExtensionSet* extensions,
const std::set<ExtensionId>& pending_ids,
int request_id,
DownloadFetchPriority fetch_priority,
ExtensionUpdateCheckParams* update_check_params) { … }
bool ExtensionUpdater::AddExtensionToDownloader(
const Extension& extension,
int request_id,
DownloadFetchPriority fetch_priority) { … }
void ExtensionUpdater::CheckNow(CheckParams params) { … }
void ExtensionUpdater::OnExtensionDownloadStageChanged(const ExtensionId& id,
Stage stage) { … }
void ExtensionUpdater::OnExtensionUpdateFound(const ExtensionId& id,
const std::set<int>& request_ids,
const base::Version& version) { … }
void ExtensionUpdater::OnExtensionDownloadCacheStatusRetrieved(
const ExtensionId& id,
CacheStatus cache_status) { … }
void ExtensionUpdater::OnExtensionDownloadFailed(
const ExtensionId& id,
Error error,
const PingResult& ping,
const std::set<int>& request_ids,
const FailureData& data) { … }
void ExtensionUpdater::OnExtensionDownloadRetry(const ExtensionId& id,
const FailureData& data) { … }
void ExtensionUpdater::OnExtensionDownloadFinished(
const CRXFileInfo& file,
bool file_ownership_passed,
const GURL& download_url,
const PingResult& ping,
const std::set<int>& request_ids,
InstallCallback callback) { … }
bool ExtensionUpdater::GetPingDataForExtension(const ExtensionId& id,
DownloadPingData* ping_data) { … }
bool ExtensionUpdater::IsExtensionPending(const ExtensionId& id) { … }
bool ExtensionUpdater::GetExtensionExistingVersion(const ExtensionId& id,
std::string* version) { … }
ExtensionUpdateData ExtensionUpdater::GetExtensionUpdateData(
const ExtensionId& id) { … }
void ExtensionUpdater::UpdatePingData(const ExtensionId& id,
const PingResult& ping_result) { … }
void ExtensionUpdater::PutExtensionInCache(const CRXFileInfo& crx_info) { … }
void ExtensionUpdater::CleanUpCrxFileIfNeeded(const base::FilePath& crx_path,
bool file_ownership_passed) { … }
bool ExtensionUpdater::CanUseUpdateService(
const ExtensionId& extension_id) const { … }
void ExtensionUpdater::InstallCRXFile(FetchedCRXFile crx_file) { … }
void ExtensionUpdater::OnInstallerDone(
const UnguessableToken& token,
const std::optional<CrxInstallError>& error) { … }
void ExtensionUpdater::NotifyStarted() { … }
void ExtensionUpdater::OnUpdateServiceFinished(int request_id) { … }
void ExtensionUpdater::NotifyIfFinished(int request_id) { … }
ExtensionUpdater::ScopedSkipScheduledCheckForTest::
ScopedSkipScheduledCheckForTest() { … }
ExtensionUpdater::ScopedSkipScheduledCheckForTest::
~ScopedSkipScheduledCheckForTest() { … }
}