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) { | |
michaeln
2014/07/29 03:33:39
our CL's collide on this method :(
so we'll have
| |
96 DCHECK_EQ(active_version(), version); | |
97 version->RemoveListener(this); | |
98 if (!is_uninstalling()) | |
99 return; | |
100 Clear(); | |
101 } | |
102 | |
94 void ServiceWorkerRegistration::SetVersionInternal( | 103 void ServiceWorkerRegistration::SetVersionInternal( |
95 ServiceWorkerVersion* version, | 104 ServiceWorkerVersion* version, |
96 scoped_refptr<ServiceWorkerVersion>* data_member, | 105 scoped_refptr<ServiceWorkerVersion>* data_member, |
97 int change_flag) { | 106 int change_flag) { |
98 if (version == data_member->get()) | 107 if (version == data_member->get()) |
99 return; | 108 return; |
100 scoped_refptr<ServiceWorkerVersion> protect(version); | 109 scoped_refptr<ServiceWorkerVersion> protect(version); |
101 ChangedVersionAttributesMask mask; | 110 ChangedVersionAttributesMask mask; |
102 if (version) | 111 if (version) |
103 UnsetVersionInternal(version, &mask); | 112 UnsetVersionInternal(version, &mask); |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
157 activating_version->SetStatus(ServiceWorkerVersion::ACTIVATING); | 166 activating_version->SetStatus(ServiceWorkerVersion::ACTIVATING); |
158 | 167 |
159 // TODO(nhiroki): "8. Fire a simple event named controllerchange..." | 168 // TODO(nhiroki): "8. Fire a simple event named controllerchange..." |
160 | 169 |
161 // "9. Queue a task to fire an event named activate..." | 170 // "9. Queue a task to fire an event named activate..." |
162 activating_version->DispatchActivateEvent( | 171 activating_version->DispatchActivateEvent( |
163 base::Bind(&ServiceWorkerRegistration::OnActivateEventFinished, | 172 base::Bind(&ServiceWorkerRegistration::OnActivateEventFinished, |
164 this, activating_version, completion_callback)); | 173 this, activating_version, completion_callback)); |
165 } | 174 } |
166 | 175 |
176 void ServiceWorkerRegistration::ClearWhenReady() { | |
177 DCHECK(context_); | |
178 if (is_uninstalling()) | |
179 return; | |
180 is_uninstalling_ = true; | |
181 context_->storage()->NotifyUninstallingRegistration(this); | |
182 | |
183 // Delete from DB in case browser dies before we're ready. | |
184 context_->storage()->DeleteRegistration( | |
185 id(), | |
186 script_url().GetOrigin(), | |
187 base::Bind(&ServiceWorkerUtils::NoOpStatusCallback)); | |
188 | |
189 if (active_version() && active_version()->HasControllee()) | |
190 active_version()->AddListener(this); | |
191 else | |
192 Clear(); | |
193 } | |
194 | |
195 void ServiceWorkerRegistration::AbortPendingClear() { | |
196 DCHECK(context_); | |
197 if (!is_uninstalling()) | |
198 return; | |
199 is_uninstalling_ = false; | |
200 context_->storage()->NotifyDoneUninstallingRegistration(this); | |
201 | |
202 if (waiting_version()) { | |
203 context_->storage()->StoreRegistration( | |
204 this, | |
205 waiting_version(), | |
206 base::Bind(&ServiceWorkerUtils::NoOpStatusCallback)); | |
207 return; | |
208 } | |
209 if (active_version()) { | |
210 context_->storage()->StoreRegistration( | |
211 this, | |
212 active_version(), | |
213 base::Bind(&ServiceWorkerUtils::NoOpStatusCallback)); | |
214 } | |
215 } | |
216 | |
167 void ServiceWorkerRegistration::OnActivateEventFinished( | 217 void ServiceWorkerRegistration::OnActivateEventFinished( |
168 ServiceWorkerVersion* activating_version, | 218 ServiceWorkerVersion* activating_version, |
169 const StatusCallback& completion_callback, | 219 const StatusCallback& completion_callback, |
170 ServiceWorkerStatusCode status) { | 220 ServiceWorkerStatusCode status) { |
171 if (activating_version != active_version()) | 221 if (activating_version != active_version()) |
172 return; | 222 return; |
173 // TODO(kinuko,falken): For some error cases (e.g. ServiceWorker is | 223 // TODO(kinuko,falken): For some error cases (e.g. ServiceWorker is |
174 // unexpectedly terminated) we may want to retry sending the event again. | 224 // unexpectedly terminated) we may want to retry sending the event again. |
175 if (status != SERVICE_WORKER_OK) { | 225 if (status != SERVICE_WORKER_OK) { |
176 // "11. If activateFailed is true, then:..." | 226 // "11. If activateFailed is true, then:..." |
(...skipping 14 matching lines...) Expand all Loading... | |
191 // and "activated" as the arguments." | 241 // and "activated" as the arguments." |
192 activating_version->SetStatus(ServiceWorkerVersion::ACTIVATED); | 242 activating_version->SetStatus(ServiceWorkerVersion::ACTIVATED); |
193 if (context_) { | 243 if (context_) { |
194 context_->storage()->UpdateToActiveState( | 244 context_->storage()->UpdateToActiveState( |
195 this, | 245 this, |
196 base::Bind(&ServiceWorkerUtils::NoOpStatusCallback)); | 246 base::Bind(&ServiceWorkerUtils::NoOpStatusCallback)); |
197 } | 247 } |
198 completion_callback.Run(SERVICE_WORKER_OK); | 248 completion_callback.Run(SERVICE_WORKER_OK); |
199 } | 249 } |
200 | 250 |
251 void ServiceWorkerRegistration::Clear() { | |
252 DCHECK(is_uninstalling()); | |
253 if (!context_) | |
254 return; | |
255 | |
256 context_->storage()->NotifyDoneUninstallingRegistration(this); | |
257 if (installing_version()) { | |
258 installing_version()->Doom(); | |
259 UnsetVersion(installing_version()); | |
260 } | |
261 | |
262 if (waiting_version()) { | |
263 waiting_version()->Doom(); | |
264 UnsetVersion(waiting_version()); | |
265 } | |
266 | |
267 if (active_version()) { | |
268 active_version()->Doom(); | |
269 UnsetVersion(active_version()); | |
270 } | |
271 } | |
272 | |
201 } // namespace content | 273 } // namespace content |
OLD | NEW |