component_updater::OnDemandUpdater should allow foreground and background calls.
This change introduces a Priority parameter for
component_updater::OnDemandUpdater::OnDemandUpdate.
The change is mechanical for the existing implementation.
Bug: 857215
Change-Id: I736b2ece704a8dda8d8f2d5a0d6d6419ceb22402
Reviewed-on: https://chromium-review.googlesource.com/1111558
Reviewed-by: Joshua Pawlicki <[email protected]>
Reviewed-by: Julian Pastarmov <[email protected]>
Reviewed-by: Tommy Li <[email protected]>
Commit-Queue: Sorin Jianu <[email protected]>
Cr-Commit-Position: refs/heads/master@{#571176}
diff --git a/components/component_updater/component_updater_service.cc b/components/component_updater/component_updater_service.cc
index 3e7d543..5833ba3e 100644
--- a/components/component_updater/component_updater_service.cc
+++ b/components/component_updater/component_updater_service.cc
@@ -255,6 +255,7 @@
}
void CrxUpdateService::OnDemandUpdate(const std::string& id,
+ Priority priority,
Callback callback) {
DCHECK(thread_checker_.CalledOnValidThread());
@@ -267,7 +268,7 @@
return;
}
- OnDemandUpdateInternal(id, std::move(callback));
+ OnDemandUpdateInternal(id, priority, std::move(callback));
}
bool CrxUpdateService::OnDemandUpdateWithCooldown(const std::string& id) {
@@ -284,23 +285,32 @@
return false;
}
- OnDemandUpdateInternal(id, Callback());
+ OnDemandUpdateInternal(id, Priority::FOREGROUND, Callback());
return true;
}
void CrxUpdateService::OnDemandUpdateInternal(const std::string& id,
+ Priority priority,
Callback callback) {
DCHECK(thread_checker_.CalledOnValidThread());
UMA_HISTOGRAM_ENUMERATION("ComponentUpdater.Calls", UPDATE_TYPE_MANUAL,
UPDATE_TYPE_COUNT);
- update_client_->Install(
- id,
- base::BindOnce(&CrxUpdateService::GetCrxComponents,
- base::Unretained(this)),
- base::BindOnce(&CrxUpdateService::OnUpdateComplete,
- base::Unretained(this), std::move(callback),
- base::TimeTicks::Now()));
+
+ auto crx_data_callback = base::BindOnce(&CrxUpdateService::GetCrxComponents,
+ base::Unretained(this));
+ auto update_complete_callback = base::BindOnce(
+ &CrxUpdateService::OnUpdateComplete, base::Unretained(this),
+ std::move(callback), base::TimeTicks::Now());
+
+ if (priority == Priority::FOREGROUND)
+ update_client_->Install(id, std::move(crx_data_callback),
+ std::move(update_complete_callback));
+ else if (priority == Priority::BACKGROUND)
+ update_client_->Update({id}, std::move(crx_data_callback), false,
+ std::move(update_complete_callback));
+ else
+ NOTREACHED();
}
bool CrxUpdateService::CheckForUpdates(