Chromium Code Reviews| Index: content/browser/service_worker/service_worker_job_coordinator.cc |
| diff --git a/content/browser/service_worker/service_worker_job_coordinator.cc b/content/browser/service_worker/service_worker_job_coordinator.cc |
| index 28d537dbca05662f9bf83bbd5b171f230c97e599..27957f17eb0aaafd82e35dcb7649064cc43bef81 100644 |
| --- a/content/browser/service_worker/service_worker_job_coordinator.cc |
| +++ b/content/browser/service_worker/service_worker_job_coordinator.cc |
| @@ -10,7 +10,6 @@ |
| #include <utility> |
| #include "base/memory/ptr_util.h" |
| -#include "base/stl_util.h" |
| #include "content/browser/service_worker/service_worker_register_job_base.h" |
| namespace content { |
| @@ -23,48 +22,46 @@ bool IsRegisterJob(const ServiceWorkerRegisterJobBase& job) { |
| } |
| -ServiceWorkerJobCoordinator::JobQueue::JobQueue() {} |
| +ServiceWorkerJobCoordinator::JobQueue::JobQueue() = default; |
|
falken
2016/10/31 01:40:34
Question for future reference: Is = default vs {}
Avi (use Gerrit)
2016/10/31 04:29:47
I don't know if they're preferred. "= default" is
|
| -ServiceWorkerJobCoordinator::JobQueue::JobQueue(const JobQueue& other) = |
| - default; |
| +ServiceWorkerJobCoordinator::JobQueue::JobQueue(JobQueue&&) = default; |
| ServiceWorkerJobCoordinator::JobQueue::~JobQueue() { |
| DCHECK(jobs_.empty()) << "Destroying JobQueue with " << jobs_.size() |
| << " unfinished jobs"; |
| - base::STLDeleteElements(&jobs_); |
| } |
| ServiceWorkerRegisterJobBase* ServiceWorkerJobCoordinator::JobQueue::Push( |
| std::unique_ptr<ServiceWorkerRegisterJobBase> job) { |
| if (jobs_.empty()) { |
| - jobs_.push_back(job.release()); |
| + jobs_.push_back(std::move(job)); |
| StartOneJob(); |
| - } else if (!job->Equals(jobs_.back())) { |
| - jobs_.push_back(job.release()); |
| + } else if (!job->Equals(jobs_.back().get())) { |
| + jobs_.push_back(std::move(job)); |
| DoomInstallingWorkerIfNeeded(); |
| } |
| - // Note we are releasing 'job' here. |
| + // Note we are releasing 'job' here in case neither of the two if() statements |
| + // above were true. |
|
falken
2016/10/31 01:40:34
Thanks for clarifying the comment.
Avi (use Gerrit)
2016/10/31 04:29:47
Acknowledged.
|
| DCHECK(!jobs_.empty()); |
| - return jobs_.back(); |
| + return jobs_.back().get(); |
| } |
| void ServiceWorkerJobCoordinator::JobQueue::Pop( |
| ServiceWorkerRegisterJobBase* job) { |
| - DCHECK(job == jobs_.front()); |
| + DCHECK(job == jobs_.front().get()); |
| jobs_.pop_front(); |
| - delete job; |
| if (!jobs_.empty()) |
| StartOneJob(); |
| } |
| void ServiceWorkerJobCoordinator::JobQueue::DoomInstallingWorkerIfNeeded() { |
| DCHECK(!jobs_.empty()); |
| - if (!IsRegisterJob(*jobs_.front())) |
| + if (!IsRegisterJob(*jobs_.front().get())) |
| return; |
| ServiceWorkerRegisterJob* job = |
| - static_cast<ServiceWorkerRegisterJob*>(jobs_.front()); |
| - std::deque<ServiceWorkerRegisterJobBase*>::iterator it = jobs_.begin(); |
| + static_cast<ServiceWorkerRegisterJob*>(jobs_.front().get()); |
| + auto it = jobs_.begin(); |
| for (++it; it != jobs_.end(); ++it) { |
| if (IsRegisterJob(**it)) { |
| job->DoomInstallingWorker(); |
| @@ -80,13 +77,13 @@ void ServiceWorkerJobCoordinator::JobQueue::StartOneJob() { |
| } |
| void ServiceWorkerJobCoordinator::JobQueue::AbortAll() { |
| - for (size_t i = 0; i < jobs_.size(); ++i) |
| - jobs_[i]->Abort(); |
| - base::STLDeleteElements(&jobs_); |
| + for (const auto& job : jobs_) |
| + job->Abort(); |
| + jobs_.clear(); |
| } |
| void ServiceWorkerJobCoordinator::JobQueue::ClearForShutdown() { |
| - base::STLDeleteElements(&jobs_); |
| + jobs_.clear(); |
| } |
| ServiceWorkerJobCoordinator::ServiceWorkerJobCoordinator( |
| @@ -96,10 +93,8 @@ ServiceWorkerJobCoordinator::ServiceWorkerJobCoordinator( |
| ServiceWorkerJobCoordinator::~ServiceWorkerJobCoordinator() { |
| if (!context_) { |
| - for (RegistrationJobMap::iterator it = job_queues_.begin(); |
| - it != job_queues_.end(); ++it) { |
| - it->second.ClearForShutdown(); |
| - } |
| + for (auto& job_pair : job_queues_) |
| + job_pair.second.ClearForShutdown(); |
| job_queues_.clear(); |
| } |
| DCHECK(job_queues_.empty()) << "Destroying ServiceWorkerJobCoordinator with " |
| @@ -157,16 +152,14 @@ void ServiceWorkerJobCoordinator::Update( |
| } |
| void ServiceWorkerJobCoordinator::AbortAll() { |
| - for (RegistrationJobMap::iterator it = job_queues_.begin(); |
| - it != job_queues_.end(); ++it) { |
| - it->second.AbortAll(); |
| - } |
| + for (auto& job_pair : job_queues_) |
| + job_pair.second.AbortAll(); |
| job_queues_.clear(); |
| } |
| void ServiceWorkerJobCoordinator::FinishJob(const GURL& pattern, |
| ServiceWorkerRegisterJobBase* job) { |
| - RegistrationJobMap::iterator pending_jobs = job_queues_.find(pattern); |
| + auto pending_jobs = job_queues_.find(pattern); |
| DCHECK(pending_jobs != job_queues_.end()) << "Deleting non-existent job."; |
| pending_jobs->second.Pop(job); |
| if (pending_jobs->second.empty()) |