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

Unified Diff: components/update_client/update_client.cc

Issue 1419473005: Fix task concurrency in components/update_client (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 2 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/update_client/update_client.cc
diff --git a/components/update_client/update_client.cc b/components/update_client/update_client.cc
index 55b096e67bc7330354b7580d32a3437389d310b8..8b8e598682e67757194e96f0186871264333b07e 100644
--- a/components/update_client/update_client.cc
+++ b/components/update_client/update_client.cc
@@ -89,7 +89,7 @@ void UpdateClientImpl::Install(const std::string& id,
const CompletionCallback& completion_callback) {
DCHECK(thread_checker_.CalledOnValidThread());
- if (update_engine_->IsUpdating(id)) {
+ if (IsUpdating(id)) {
completion_callback.Run(Error::ERROR_UPDATE_IN_PROGRESS);
return;
}
@@ -104,6 +104,7 @@ void UpdateClientImpl::Install(const std::string& id,
scoped_ptr<TaskUpdate> task(new TaskUpdate(update_engine_.get(), true, ids,
crx_data_callback, callback));
+ // Install tasks are run concurrently and never queued up.
auto it = tasks_.insert(task.release()).first;
RunTask(*it);
}
@@ -118,6 +119,8 @@ void UpdateClientImpl::Update(const std::vector<std::string>& ids,
scoped_ptr<TaskUpdate> task(new TaskUpdate(update_engine_.get(), false, ids,
crx_data_callback, callback));
+ // If no other tasks are running at the moment, run this update task.
+ // Otherwise, queue the task up.
if (tasks_.empty()) {
auto it = tasks_.insert(task.release()).first;
RunTask(*it);
@@ -145,7 +148,9 @@ void UpdateClientImpl::OnTaskComplete(
tasks_.erase(task);
delete task;
- if (!task_queue_.empty()) {
+ // Pick up a task from the queue if the queue has pending tasks and no other
+ // task is running.
+ if (tasks_.empty() && !task_queue_.empty()) {
RunTask(task_queue_.front());
task_queue_.pop();
}
@@ -173,7 +178,16 @@ bool UpdateClientImpl::GetCrxUpdateState(const std::string& id,
}
bool UpdateClientImpl::IsUpdating(const std::string& id) const {
- return update_engine_->IsUpdating(id);
+ DCHECK(thread_checker_.CalledOnValidThread());
+
+ for (const auto& task : tasks_) {
+ const auto ids(task->GetIds());
+ if (std::find(std::begin(ids), std::end(ids), id) != std::end(ids)) {
+ return true;
+ }
+ }
+
+ return false;
}
scoped_refptr<UpdateClient> UpdateClientFactory(

Powered by Google App Engine
This is Rietveld 408576698