Skip to content

Commit

Permalink
[Extensions] Move PingData and FetchPriority to a separate file
Browse files Browse the repository at this point in the history
PingData is a small struct which contains some info to return back to
the update service (most likely, Chrome Web Store backends). This struct
is used in ExtensionDownloaderDelegate (because ExtensionDownloader
doesn't have required data and has to ask delegate for it) and some
other places.

FetchPriority is a simple enum to denote priority for downloading or
updating an extension. Priority affects corresponding header when making
request to the update server and also priority ExtensionDownloader
assigns to requests for network layer.

Both of these are used widely outside of ManifestFetchData (where they
were defined), therefore it makes sense to move them into a separate
file.

Bug: b:223166166
Change-Id: I96d96c2d1290e69032302607ec2b42101b340eba
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3595826
Commit-Queue: Oleg Davydov <burunduk@chromium.org>
Reviewed-by: Devlin Cronin <rdevlin.cronin@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1001422}
  • Loading branch information
burunduk3 authored and Chromium LUCI CQ committed May 10, 2022
1 parent 91f5336 commit 25ac5db
Show file tree
Hide file tree
Showing 16 changed files with 257 additions and 268 deletions.
3 changes: 2 additions & 1 deletion chrome/browser/chromeos/extensions/external_cache_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include "content/public/browser/notification_source.h"
#include "extensions/browser/notification_types.h"
#include "extensions/browser/updater/extension_downloader.h"
#include "extensions/browser/updater/extension_downloader_types.h"
#include "extensions/common/extension.h"
#include "extensions/common/extension_urls.h"
#include "extensions/common/manifest.h"
Expand Down Expand Up @@ -282,7 +283,7 @@ void ExternalCacheImpl::CheckCache() {
downloader_->AddPendingExtension(extensions::ExtensionDownloaderTask(
entry.first, update_url,
extensions::mojom::ManifestLocation::kExternalPolicy, false, 0,
extensions::ManifestFetchData::FetchPriority::BACKGROUND,
extensions::DownloadFetchPriority::kBackground,
base::Version(version), extensions::Manifest::TYPE_UNKNOWN,
std::string()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
#include "extensions/browser/process_manager_factory.h"
#include "extensions/browser/renderer_startup_helper.h"
#include "extensions/browser/ui_util.h"
#include "extensions/browser/updater/extension_downloader_types.h"
#include "extensions/browser/warning_service.h"
#include "extensions/browser/warning_service_factory.h"
#include "extensions/browser/zipfile_installer.h"
Expand Down Expand Up @@ -752,7 +753,7 @@ ExtensionFunction::ResponseAction DeveloperPrivateAutoUpdateFunction::Run() {
ExtensionSystem::Get(browser_context())->extension_service()->updater();
if (updater) {
ExtensionUpdater::CheckParams params;
params.fetch_priority = ManifestFetchData::FetchPriority::FOREGROUND;
params.fetch_priority = DownloadFetchPriority::kForeground;
params.install_immediately = true;
params.callback =
base::BindOnce(&DeveloperPrivateAutoUpdateFunction::OnComplete,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "extensions/browser/updater/extension_downloader_delegate.h"
#include "extensions/browser/updater/safe_manifest_parser.h"
#include "extensions/common/extension_id.h"
#include "extensions/common/manifest.h"
#include "third_party/abseil-cpp/absl/types/optional.h"

#if BUILDFLAG(IS_CHROMEOS_ASH)
Expand Down
13 changes: 6 additions & 7 deletions chrome/browser/extensions/updater/extension_updater.cc
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ void ExtensionUpdater::AddToDownloader(
const ExtensionSet* extensions,
const std::set<ExtensionId>& pending_ids,
int request_id,
ManifestFetchData::FetchPriority fetch_priority,
DownloadFetchPriority fetch_priority,
ExtensionUpdateCheckParams* update_check_params) {
DCHECK(update_service_);

Expand Down Expand Up @@ -353,7 +353,7 @@ void ExtensionUpdater::AddToDownloader(
bool ExtensionUpdater::AddExtensionToDownloader(
const Extension& extension,
int request_id,
ManifestFetchData::FetchPriority fetch_priority) {
DownloadFetchPriority fetch_priority) {
ExtensionManagement* extension_management =
ExtensionManagementFactory::GetForBrowserContext(profile_);
GURL update_url = extension_management->GetEffectiveUpdateURL(extension);
Expand Down Expand Up @@ -476,7 +476,7 @@ void ExtensionUpdater::CheckNow(CheckParams params) {
pending_id, info->update_url(), info->install_source(),
is_corrupt_reinstall, request_id,
is_high_priority_extension_pending
? ManifestFetchData::FOREGROUND
? DownloadFetchPriority::kForeground
: params.fetch_priority))) {
request.in_progress_ids.insert(pending_id);
InstallStageTracker::Get(profile_)->ReportInstallationStage(
Expand Down Expand Up @@ -533,7 +533,7 @@ void ExtensionUpdater::CheckNow(CheckParams params) {

if (awaiting_update_service) {
update_check_params.priority =
params.fetch_priority == ManifestFetchData::FetchPriority::BACKGROUND
params.fetch_priority == DownloadFetchPriority::kBackground
? ExtensionUpdateCheckParams::UpdateCheckPriority::BACKGROUND
: ExtensionUpdateCheckParams::UpdateCheckPriority::FOREGROUND;
update_check_params.install_immediately = params.install_immediately;
Expand Down Expand Up @@ -646,9 +646,8 @@ void ExtensionUpdater::OnExtensionDownloadFinished(
InstallCRXFile(std::move(fetched));
}

bool ExtensionUpdater::GetPingDataForExtension(
const ExtensionId& id,
ManifestFetchData::PingData* ping_data) {
bool ExtensionUpdater::GetPingDataForExtension(const ExtensionId& id,
DownloadPingData* ping_data) {
DCHECK(alive_);
ping_data->rollcall_days =
CalculatePingDaysForExtension(extension_prefs_->LastPingDay(id));
Expand Down
16 changes: 7 additions & 9 deletions chrome/browser/extensions/updater/extension_updater.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#include "extensions/browser/extension_registry_observer.h"
#include "extensions/browser/updater/extension_downloader.h"
#include "extensions/browser/updater/extension_downloader_delegate.h"
#include "extensions/browser/updater/manifest_fetch_data.h"
#include "extensions/browser/updater/extension_downloader_types.h"
#include "extensions/browser/updater/update_service.h"
#include "extensions/common/extension_id.h"
#include "url/gurl.h"
Expand Down Expand Up @@ -83,8 +83,7 @@ class ExtensionUpdater : public ExtensionDownloaderDelegate,
// An extension update check can be originated by a user or by a scheduled
// task. When the value of |fetch_priority| is FOREGROUND, the update
// request was initiated by a user.
ManifestFetchData::FetchPriority fetch_priority =
ManifestFetchData::FetchPriority::BACKGROUND;
DownloadFetchPriority fetch_priority = DownloadFetchPriority::kBackground;

// Callback to call when the update check is complete. Can be null, if
// you're not interested in when this happens.
Expand Down Expand Up @@ -217,17 +216,16 @@ class ExtensionUpdater : public ExtensionDownloaderDelegate,
void AddToDownloader(const ExtensionSet* extensions,
const std::set<ExtensionId>& pending_ids,
int request_id,
ManifestFetchData::FetchPriority fetch_priority,
DownloadFetchPriority fetch_priority,
ExtensionUpdateCheckParams* update_check_params);

// Adds |extension| to the downloader, providing it with |fetch_priority|,
// |request_id| and data extracted from the extension object.
// |fetch_priority| parameter notifies the downloader the priority of this
// extension update (either foreground or background).
bool AddExtensionToDownloader(
const Extension& extension,
int request_id,
ManifestFetchData::FetchPriority fetch_priority);
bool AddExtensionToDownloader(const Extension& extension,
int request_id,
DownloadFetchPriority fetch_priority);

// Conduct a check as scheduled by ScheduleNextCheck.
void NextCheck();
Expand All @@ -254,7 +252,7 @@ class ExtensionUpdater : public ExtensionDownloaderDelegate,
const std::set<int>& request_id,
InstallCallback callback) override;
bool GetPingDataForExtension(const ExtensionId& id,
ManifestFetchData::PingData* ping_data) override;
DownloadPingData* ping_data) override;
bool IsExtensionPending(const ExtensionId& id) override;
bool GetExtensionExistingVersion(const ExtensionId& id,
std::string* version) override;
Expand Down

0 comments on commit 25ac5db

Please sign in to comment.