Index: trunk/src/chrome/browser/history/history_backend.cc |
=================================================================== |
--- trunk/src/chrome/browser/history/history_backend.cc (revision 285001) |
+++ trunk/src/chrome/browser/history/history_backend.cc (working copy) |
@@ -163,40 +163,35 @@ |
scoped_refptr<HistoryBackend> history_backend_; |
}; |
+// QueuedHistoryDBTask --------------------------------------------------------- |
QueuedHistoryDBTask::QueuedHistoryDBTask( |
- scoped_ptr<HistoryDBTask> task, |
+ scoped_refptr<HistoryDBTask> task, |
scoped_refptr<base::SingleThreadTaskRunner> origin_loop, |
const base::CancelableTaskTracker::IsCanceledCallback& is_canceled) |
- : task_(task.Pass()), origin_loop_(origin_loop), is_canceled_(is_canceled) { |
+ : task_(task), origin_loop_(origin_loop), is_canceled_(is_canceled) { |
DCHECK(task_); |
DCHECK(origin_loop_); |
DCHECK(!is_canceled_.is_null()); |
} |
QueuedHistoryDBTask::~QueuedHistoryDBTask() { |
- // Ensure that |task_| is destroyed on its origin thread. |
- origin_loop_->PostTask( |
- FROM_HERE, |
- base::Bind(&base::DeletePointer<HistoryDBTask>, |
- base::Unretained(task_.release()))); |
} |
bool QueuedHistoryDBTask::is_canceled() { |
return is_canceled_.Run(); |
} |
-bool QueuedHistoryDBTask::Run(HistoryBackend* backend, |
+bool QueuedHistoryDBTask::RunOnDBThread(HistoryBackend* backend, |
HistoryDatabase* db) { |
return task_->RunOnDBThread(backend, db); |
} |
-void QueuedHistoryDBTask::DoneRun() { |
+void QueuedHistoryDBTask::DoneRunOnMainThread() { |
origin_loop_->PostTask( |
FROM_HERE, |
base::Bind(&RunUnlessCanceled, |
- base::Bind(&HistoryDBTask::DoneRunOnMainThread, |
- base::Unretained(task_.get())), |
+ base::Bind(&HistoryDBTask::DoneRunOnMainThread, task_), |
is_canceled_)); |
} |
@@ -217,8 +212,6 @@ |
HistoryBackend::~HistoryBackend() { |
DCHECK(!scheduled_commit_.get()) << "Deleting without cleanup"; |
- STLDeleteContainerPointers(queued_history_db_tasks_.begin(), |
- queued_history_db_tasks_.end()); |
queued_history_db_tasks_.clear(); |
#if defined(OS_ANDROID) |
@@ -2337,34 +2330,31 @@ |
void HistoryBackend::ProcessDBTaskImpl() { |
if (!db_) { |
// db went away, release all the refs. |
- STLDeleteContainerPointers(queued_history_db_tasks_.begin(), |
- queued_history_db_tasks_.end()); |
queued_history_db_tasks_.clear(); |
return; |
} |
// Remove any canceled tasks. |
while (!queued_history_db_tasks_.empty()) { |
- QueuedHistoryDBTask* task = queued_history_db_tasks_.front(); |
- if (!task->is_canceled()) |
+ QueuedHistoryDBTask& task = queued_history_db_tasks_.front(); |
+ if (!task.is_canceled()) { |
break; |
- |
- delete task; |
+ } |
queued_history_db_tasks_.pop_front(); |
} |
if (queued_history_db_tasks_.empty()) |
return; |
// Run the first task. |
- scoped_ptr<QueuedHistoryDBTask> task(queued_history_db_tasks_.front()); |
+ QueuedHistoryDBTask task = queued_history_db_tasks_.front(); |
queued_history_db_tasks_.pop_front(); |
- if (task->Run(this, db_.get())) { |
+ if (task.RunOnDBThread(this, db_.get())) { |
// The task is done, notify the callback. |
- task->DoneRun(); |
+ task.DoneRunOnMainThread(); |
} else { |
// The task wants to run some more. Schedule it at the end of the current |
// tasks, and process it after an invoke later. |
- queued_history_db_tasks_.push_back(task.release()); |
+ queued_history_db_tasks_.insert(queued_history_db_tasks_.end(), task); |
base::MessageLoop::current()->PostTask( |
FROM_HERE, base::Bind(&HistoryBackend::ProcessDBTaskImpl, this)); |
} |
@@ -2550,12 +2540,13 @@ |
} |
void HistoryBackend::ProcessDBTask( |
- scoped_ptr<HistoryDBTask> task, |
+ scoped_refptr<HistoryDBTask> task, |
scoped_refptr<base::SingleThreadTaskRunner> origin_loop, |
const base::CancelableTaskTracker::IsCanceledCallback& is_canceled) { |
bool scheduled = !queued_history_db_tasks_.empty(); |
- queued_history_db_tasks_.push_back( |
- new QueuedHistoryDBTask(task.Pass(), origin_loop, is_canceled)); |
+ queued_history_db_tasks_.insert( |
+ queued_history_db_tasks_.end(), |
+ QueuedHistoryDBTask(task, origin_loop, is_canceled)); |
if (!scheduled) |
ProcessDBTaskImpl(); |
} |