Cast: Stop logging kVideoFrameSentToEncoder and rename a couple events.
[chromium-blink-merge.git] / content / browser / service_worker / service_worker_unregister_job.cc
blob5866c78022c91c8598f473ae5c2bf7c727aa4d47
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "content/browser/service_worker/service_worker_unregister_job.h"
7 #include "content/browser/service_worker/service_worker_context_core.h"
8 #include "content/browser/service_worker/service_worker_job_coordinator.h"
9 #include "content/browser/service_worker/service_worker_registration.h"
10 #include "content/browser/service_worker/service_worker_storage.h"
12 namespace content {
14 typedef ServiceWorkerRegisterJobBase::RegistrationJobType RegistrationJobType;
16 ServiceWorkerUnregisterJob::ServiceWorkerUnregisterJob(
17 base::WeakPtr<ServiceWorkerContextCore> context,
18 const GURL& pattern)
19 : context_(context),
20 pattern_(pattern),
21 weak_factory_(this) {}
23 ServiceWorkerUnregisterJob::~ServiceWorkerUnregisterJob() {}
25 void ServiceWorkerUnregisterJob::AddCallback(
26 const UnregistrationCallback& callback) {
27 callbacks_.push_back(callback);
30 void ServiceWorkerUnregisterJob::Start() {
31 context_->storage()->FindRegistrationForPattern(
32 pattern_,
33 base::Bind(&ServiceWorkerUnregisterJob::DeleteExistingRegistration,
34 weak_factory_.GetWeakPtr()));
37 bool ServiceWorkerUnregisterJob::Equals(ServiceWorkerRegisterJobBase* job) {
38 if (job->GetType() != GetType())
39 return false;
40 return static_cast<ServiceWorkerUnregisterJob*>(job)->pattern_ == pattern_;
43 RegistrationJobType ServiceWorkerUnregisterJob::GetType() {
44 return ServiceWorkerRegisterJobBase::UNREGISTRATION;
47 void ServiceWorkerUnregisterJob::DeleteExistingRegistration(
48 ServiceWorkerStatusCode status,
49 const scoped_refptr<ServiceWorkerRegistration>& registration) {
50 if (status == SERVICE_WORKER_OK) {
51 DCHECK(registration);
52 // TODO(michaeln): Deactivate the live registration object and
53 // eventually call storage->DeleteVersionResources()
54 // when the version no longer has any controllees.
55 context_->storage()->DeleteRegistration(
56 registration->id(),
57 base::Bind(&ServiceWorkerUnregisterJob::Complete,
58 weak_factory_.GetWeakPtr()));
59 return;
62 if (status == SERVICE_WORKER_ERROR_NOT_FOUND) {
63 DCHECK(!registration);
64 Complete(SERVICE_WORKER_OK);
65 return;
68 Complete(status);
71 void ServiceWorkerUnregisterJob::Complete(ServiceWorkerStatusCode status) {
72 for (std::vector<UnregistrationCallback>::iterator it = callbacks_.begin();
73 it != callbacks_.end();
74 ++it) {
75 it->Run(status);
77 context_->job_coordinator()->FinishJob(pattern_, this);
80 } // namespace content