summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsorin <sorin@chromium.org>2015-10-30 16:19:51 -0700
committerCommit bot <commit-bot@chromium.org>2015-10-30 23:20:39 +0000
commitb318cc84ac8b0d7d0d35c5248e8d9d2d9cb473f9 (patch)
tree7e6d9de87f7d458c3ef6afed260f33fd2cc269a0
parentfa705362defe8ba29f7ba93570ea5cb8a5df0981 (diff)
downloadchromium_src-b318cc84ac8b0d7d0d35c5248e8d9d2d9cb473f9.zip
chromium_src-b318cc84ac8b0d7d0d35c5248e8d9d2d9cb473f9.tar.gz
chromium_src-b318cc84ac8b0d7d0d35c5248e8d9d2d9cb473f9.tar.bz2
Fix a bug where a task dequeued from the pending tasks is not inserted in the running task set when the task is scheduled to run.
Also, delete the pending tasks when the UpdateClient is destroyed. BUG=548002 Review URL: https://codereview.chromium.org/1422623012 Cr-Commit-Position: refs/heads/master@{#357217}
-rw-r--r--components/update_client/update_client.cc19
-rw-r--r--components/update_client/update_client_internal.h4
2 files changed, 15 insertions, 8 deletions
diff --git a/components/update_client/update_client.cc b/components/update_client/update_client.cc
index 8b8e598..03c77db 100644
--- a/components/update_client/update_client.cc
+++ b/components/update_client/update_client.cc
@@ -81,6 +81,12 @@ UpdateClientImpl::UpdateClientImpl(
UpdateClientImpl::~UpdateClientImpl() {
DCHECK(thread_checker_.CalledOnValidThread());
+
+ while (!task_queue_.empty()) {
+ delete task_queue_.front();
+ task_queue_.pop();
+ }
+
config_ = nullptr;
}
@@ -105,8 +111,7 @@ void UpdateClientImpl::Install(const std::string& id,
crx_data_callback, callback));
// Install tasks are run concurrently and never queued up.
- auto it = tasks_.insert(task.release()).first;
- RunTask(*it);
+ RunTask(task.Pass());
}
void UpdateClientImpl::Update(const std::vector<std::string>& ids,
@@ -122,17 +127,17 @@ void UpdateClientImpl::Update(const std::vector<std::string>& ids,
// 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);
+ RunTask(task.Pass());
} else {
task_queue_.push(task.release());
}
}
-void UpdateClientImpl::RunTask(Task* task) {
+void UpdateClientImpl::RunTask(scoped_ptr<Task> task) {
DCHECK(thread_checker_.CalledOnValidThread());
base::ThreadTaskRunnerHandle::Get()->PostTask(
- FROM_HERE, base::Bind(&Task::Run, base::Unretained(task)));
+ FROM_HERE, base::Bind(&Task::Run, base::Unretained(task.get())));
+ tasks_.insert(task.release());
}
void UpdateClientImpl::OnTaskComplete(
@@ -151,7 +156,7 @@ void UpdateClientImpl::OnTaskComplete(
// 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());
+ RunTask(scoped_ptr<Task>(task_queue_.front()).Pass());
task_queue_.pop();
}
}
diff --git a/components/update_client/update_client_internal.h b/components/update_client/update_client_internal.h
index b74c696..0dc98be 100644
--- a/components/update_client/update_client_internal.h
+++ b/components/update_client/update_client_internal.h
@@ -13,6 +13,8 @@
#include <vector>
#include "base/macros.h"
+#include "base/memory/ref_counted.h"
+#include "base/memory/scoped_ptr.h"
#include "base/observer_list.h"
#include "base/threading/thread_checker.h"
#include "components/update_client/crx_downloader.h"
@@ -54,7 +56,7 @@ class UpdateClientImpl : public UpdateClient {
private:
~UpdateClientImpl() override;
- void RunTask(Task* task);
+ void RunTask(scoped_ptr<Task> task);
void OnTaskComplete(const CompletionCallback& completion_callback,
Task* task,
int error);