summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-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);