Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(288)

Unified Diff: components/component_updater/component_updater_service.cc

Issue 2261533003: Provide a callback for Component Updater OnDemand calls. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: components/component_updater/component_updater_service.cc
diff --git a/components/component_updater/component_updater_service.cc b/components/component_updater/component_updater_service.cc
index 4964bb07c94339a094cbb3a7c2bf7da970990112..9d3d9c0512cd6e12a2bae5fc376f19cc8df5cebd 100644
--- a/components/component_updater/component_updater_service.cc
+++ b/components/component_updater/component_updater_service.cc
@@ -239,13 +239,19 @@ void CrxUpdateService::MaybeThrottle(const std::string& id,
callback.Run(); // Unblock the request if the request can't be throttled.
}
-bool CrxUpdateService::OnDemandUpdate(const std::string& id) {
+void CrxUpdateService::OnDemandUpdate(const std::string& id,
+ CompletionCallback callback) {
DCHECK(thread_checker_.CalledOnValidThread());
- if (!GetComponent(id))
- return false;
+ if (!GetComponent(id)) {
+ base::ThreadTaskRunnerHandle::Get()->PostTask(
+ FROM_HERE,
+ base::Bind(callback,
+ update_client::Error::ERROR_UPDATE_INVALID_ARGUMENT));
+ return;
+ }
- return OnDemandUpdateInternal(id);
+ OnDemandUpdateInternal(id, callback);
}
bool CrxUpdateService::OnDemandUpdateWithCooldown(const std::string& id) {
@@ -261,21 +267,20 @@ bool CrxUpdateService::OnDemandUpdateWithCooldown(const std::string& id) {
return false;
}
- return OnDemandUpdateInternal(id);
+ OnDemandUpdateInternal(id, CompletionCallback());
+ return true;
}
-bool CrxUpdateService::OnDemandUpdateInternal(const std::string& id) {
+void CrxUpdateService::OnDemandUpdateInternal(const std::string& id,
+ CompletionCallback callback) {
DCHECK(thread_checker_.CalledOnValidThread());
UMA_HISTOGRAM_ENUMERATION("ComponentUpdater.Calls", UPDATE_TYPE_MANUAL,
UPDATE_TYPE_COUNT);
-
update_client_->Install(
id, base::Bind(&CrxUpdateService::OnUpdate, base::Unretained(this)),
base::Bind(&CrxUpdateService::OnUpdateComplete, base::Unretained(this),
- base::TimeTicks::Now()));
-
- return true;
+ callback, base::TimeTicks::Now()));
}
bool CrxUpdateService::CheckForUpdates() {
@@ -301,7 +306,7 @@ bool CrxUpdateService::CheckForUpdates() {
unsecure_ids,
base::Bind(&CrxUpdateService::OnUpdate, base::Unretained(this)),
base::Bind(&CrxUpdateService::OnUpdateComplete, base::Unretained(this),
- base::TimeTicks::Now()));
+ CompletionCallback(), base::TimeTicks::Now()));
}
if (!secure_ids.empty()) {
@@ -309,7 +314,7 @@ bool CrxUpdateService::CheckForUpdates() {
secure_ids,
base::Bind(&CrxUpdateService::OnUpdate, base::Unretained(this)),
base::Bind(&CrxUpdateService::OnUpdateComplete, base::Unretained(this),
- base::TimeTicks::Now()));
+ CompletionCallback(), base::TimeTicks::Now()));
}
return true;
@@ -354,7 +359,8 @@ void CrxUpdateService::OnUpdate(const std::vector<std::string>& ids,
}
}
-void CrxUpdateService::OnUpdateComplete(const base::TimeTicks& start_time,
+void CrxUpdateService::OnUpdateComplete(CompletionCallback callback,
+ const base::TimeTicks& start_time,
int error) {
DCHECK(thread_checker_.CalledOnValidThread());
VLOG(1) << "Update completed with error " << error;
@@ -370,6 +376,11 @@ void CrxUpdateService::OnUpdateComplete(const base::TimeTicks& start_time,
DoUnregisterComponent(*component);
}
}
+
+ if (static_cast<bool>(callback)) {
Bernhard Bauer 2016/08/19 04:13:05 Just `if (callback)`? Or if you want to be explici
Sorin Jianu 2016/08/19 04:23:36 Callback has an explicit conversion to bool. Will
+ base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE,
+ base::Bind(callback, error));
+ }
}
void CrxUpdateService::OnEvent(Events event, const std::string& id) {

Powered by Google App Engine
This is Rietveld 408576698