Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "content/browser/service_worker/service_worker_registration.h" | 5 #include "content/browser/service_worker/service_worker_registration.h" |
| 6 | 6 |
| 7 #include "content/browser/service_worker/service_worker_context_core.h" | 7 #include "content/browser/service_worker/service_worker_context_core.h" |
| 8 #include "content/browser/service_worker/service_worker_info.h" | 8 #include "content/browser/service_worker/service_worker_info.h" |
| 9 #include "content/browser/service_worker/service_worker_register_job.h" | 9 #include "content/browser/service_worker/service_worker_register_job.h" |
| 10 #include "content/browser/service_worker/service_worker_utils.h" | 10 #include "content/browser/service_worker/service_worker_utils.h" |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 23 } // namespace | 23 } // namespace |
| 24 | 24 |
| 25 ServiceWorkerRegistration::ServiceWorkerRegistration( | 25 ServiceWorkerRegistration::ServiceWorkerRegistration( |
| 26 const GURL& pattern, | 26 const GURL& pattern, |
| 27 const GURL& script_url, | 27 const GURL& script_url, |
| 28 int64 registration_id, | 28 int64 registration_id, |
| 29 base::WeakPtr<ServiceWorkerContextCore> context) | 29 base::WeakPtr<ServiceWorkerContextCore> context) |
| 30 : pattern_(pattern), | 30 : pattern_(pattern), |
| 31 script_url_(script_url), | 31 script_url_(script_url), |
| 32 registration_id_(registration_id), | 32 registration_id_(registration_id), |
| 33 is_uninstalling_(false), | |
| 33 context_(context) { | 34 context_(context) { |
| 34 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 35 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 35 DCHECK(context_); | 36 DCHECK(context_); |
| 36 context_->AddLiveRegistration(this); | 37 context_->AddLiveRegistration(this); |
| 37 } | 38 } |
| 38 | 39 |
| 39 ServiceWorkerRegistration::~ServiceWorkerRegistration() { | 40 ServiceWorkerRegistration::~ServiceWorkerRegistration() { |
| 40 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 41 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 41 if (context_) | 42 if (context_) |
| 42 context_->RemoveLiveRegistration(registration_id_); | 43 context_->RemoveLiveRegistration(registration_id_); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 84 return; | 85 return; |
| 85 ChangedVersionAttributesMask mask; | 86 ChangedVersionAttributesMask mask; |
| 86 UnsetVersionInternal(version, &mask); | 87 UnsetVersionInternal(version, &mask); |
| 87 if (mask.changed()) { | 88 if (mask.changed()) { |
| 88 ServiceWorkerRegistrationInfo info = GetInfo(); | 89 ServiceWorkerRegistrationInfo info = GetInfo(); |
| 89 FOR_EACH_OBSERVER(Listener, listeners_, | 90 FOR_EACH_OBSERVER(Listener, listeners_, |
| 90 OnVersionAttributesChanged(this, mask, info)); | 91 OnVersionAttributesChanged(this, mask, info)); |
| 91 } | 92 } |
| 92 } | 93 } |
| 93 | 94 |
| 95 void ServiceWorkerRegistration::OnNoControllees(ServiceWorkerVersion* version) { | |
| 96 DCHECK_EQ(active_version(), version); | |
| 97 version->RemoveListener(this); | |
| 98 if (is_uninstalling()) | |
| 99 Uninstall(); | |
| 100 } | |
| 101 | |
| 94 void ServiceWorkerRegistration::SetVersionInternal( | 102 void ServiceWorkerRegistration::SetVersionInternal( |
| 95 ServiceWorkerVersion* version, | 103 ServiceWorkerVersion* version, |
| 96 scoped_refptr<ServiceWorkerVersion>* data_member, | 104 scoped_refptr<ServiceWorkerVersion>* data_member, |
| 97 int change_flag) { | 105 int change_flag) { |
| 98 if (version == data_member->get()) | 106 if (version == data_member->get()) |
| 99 return; | 107 return; |
| 100 scoped_refptr<ServiceWorkerVersion> protect(version); | 108 scoped_refptr<ServiceWorkerVersion> protect(version); |
| 101 ChangedVersionAttributesMask mask; | 109 ChangedVersionAttributesMask mask; |
| 102 if (version) | 110 if (version) |
| 103 UnsetVersionInternal(version, &mask); | 111 UnsetVersionInternal(version, &mask); |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 157 activating_version->SetStatus(ServiceWorkerVersion::ACTIVATING); | 165 activating_version->SetStatus(ServiceWorkerVersion::ACTIVATING); |
| 158 | 166 |
| 159 // TODO(nhiroki): "8. Fire a simple event named controllerchange..." | 167 // TODO(nhiroki): "8. Fire a simple event named controllerchange..." |
| 160 | 168 |
| 161 // "9. Queue a task to fire an event named activate..." | 169 // "9. Queue a task to fire an event named activate..." |
| 162 activating_version->DispatchActivateEvent( | 170 activating_version->DispatchActivateEvent( |
| 163 base::Bind(&ServiceWorkerRegistration::OnActivateEventFinished, | 171 base::Bind(&ServiceWorkerRegistration::OnActivateEventFinished, |
| 164 this, activating_version, completion_callback)); | 172 this, activating_version, completion_callback)); |
| 165 } | 173 } |
| 166 | 174 |
| 175 void ServiceWorkerRegistration::StartUninstall() { | |
|
michaeln
2014/07/25 00:02:04
let's harmonize on naming, i'm using
ActivateWait
falken
2014/07/25 12:47:25
Sounds good.
| |
| 176 DCHECK(context_); | |
| 177 set_uninstalling(true); | |
| 178 // "11. Wait until no document is using registration as their Service Worker | |
| 179 // registration." | |
| 180 if (active_version() && active_version()->HasControllee()) | |
| 181 active_version()->AddListener(this); | |
| 182 else | |
| 183 Uninstall(); | |
| 184 } | |
| 185 | |
| 186 void ServiceWorkerRegistration::Uninstall() { | |
| 187 DCHECK(is_uninstalling()); | |
| 188 if (!context_) | |
| 189 return; | |
| 190 | |
| 191 // "12. If registration.activeWorker is not null, then:" | |
| 192 if (active_version()) { | |
| 193 // "1. Run the [[UpdateState]] algorithm passing registration.activeWorker | |
| 194 // and 'redundant' as the arguments." | |
| 195 active_version()->Doom(); | |
| 196 // "2. Set registration.activeWorker to null." | |
| 197 UnsetVersion(active_version()); | |
| 198 } | |
| 199 | |
| 200 // "13. Delete a Record {[[key]], [[value]]} entry of its | |
| 201 // [[ScopeToRegistrationMap]] where scope matches entry.[[key]]." | |
| 202 context_->storage()->DeleteRegistration( | |
| 203 id(), | |
| 204 script_url().GetOrigin(), | |
| 205 base::Bind(&ServiceWorkerUtils::NoOpStatusCallback)); | |
| 206 } | |
| 207 | |
| 167 void ServiceWorkerRegistration::OnActivateEventFinished( | 208 void ServiceWorkerRegistration::OnActivateEventFinished( |
| 168 ServiceWorkerVersion* activating_version, | 209 ServiceWorkerVersion* activating_version, |
| 169 const StatusCallback& completion_callback, | 210 const StatusCallback& completion_callback, |
| 170 ServiceWorkerStatusCode status) { | 211 ServiceWorkerStatusCode status) { |
| 171 if (activating_version != active_version()) | 212 if (activating_version != active_version()) |
| 172 return; | 213 return; |
| 173 // TODO(kinuko,falken): For some error cases (e.g. ServiceWorker is | 214 // TODO(kinuko,falken): For some error cases (e.g. ServiceWorker is |
| 174 // unexpectedly terminated) we may want to retry sending the event again. | 215 // unexpectedly terminated) we may want to retry sending the event again. |
| 175 if (status != SERVICE_WORKER_OK) { | 216 if (status != SERVICE_WORKER_OK) { |
| 176 // "11. If activateFailed is true, then:..." | 217 // "11. If activateFailed is true, then:..." |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 192 activating_version->SetStatus(ServiceWorkerVersion::ACTIVATED); | 233 activating_version->SetStatus(ServiceWorkerVersion::ACTIVATED); |
| 193 if (context_) { | 234 if (context_) { |
| 194 context_->storage()->UpdateToActiveState( | 235 context_->storage()->UpdateToActiveState( |
| 195 this, | 236 this, |
| 196 base::Bind(&ServiceWorkerUtils::NoOpStatusCallback)); | 237 base::Bind(&ServiceWorkerUtils::NoOpStatusCallback)); |
| 197 } | 238 } |
| 198 completion_callback.Run(SERVICE_WORKER_OK); | 239 completion_callback.Run(SERVICE_WORKER_OK); |
| 199 } | 240 } |
| 200 | 241 |
| 201 } // namespace content | 242 } // namespace content |
| OLD | NEW |