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_context_wrapper.h" | 5 #include "content/browser/service_worker/service_worker_context_wrapper.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 #include <set> | 8 #include <set> |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
268 if (!context_core_.get()) { | 268 if (!context_core_.get()) { |
269 LOG(ERROR) << "ServiceWorkerContextCore is no longer alive."; | 269 LOG(ERROR) << "ServiceWorkerContextCore is no longer alive."; |
270 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 270 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
271 base::Bind(callback, SERVICE_WORKER_ERROR_ABORT)); | 271 base::Bind(callback, SERVICE_WORKER_ERROR_ABORT)); |
272 return; | 272 return; |
273 } | 273 } |
274 context_core_->storage()->FindRegistrationForPattern( | 274 context_core_->storage()->FindRegistrationForPattern( |
275 pattern, base::Bind(&StartActiveWorkerOnIO, callback)); | 275 pattern, base::Bind(&StartActiveWorkerOnIO, callback)); |
276 } | 276 } |
277 | 277 |
| 278 void ServiceWorkerContextWrapper::SimulateSkipWaiting(int64_t version_id) { |
| 279 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) { |
| 280 BrowserThread::PostTask( |
| 281 BrowserThread::IO, FROM_HERE, |
| 282 base::Bind(&ServiceWorkerContextWrapper::SimulateSkipWaiting, this, |
| 283 version_id)); |
| 284 return; |
| 285 } |
| 286 if (!context_core_.get()) { |
| 287 LOG(ERROR) << "ServiceWorkerContextCore is no longer alive."; |
| 288 return; |
| 289 } |
| 290 ServiceWorkerVersion* version = GetLiveVersion(version_id); |
| 291 if (!version || version->skip_waiting()) |
| 292 return; |
| 293 ServiceWorkerRegistration* registration = |
| 294 GetLiveRegistration(version->registration_id()); |
| 295 if (!registration || version != registration->waiting_version()) |
| 296 return; |
| 297 version->set_skip_waiting(true); |
| 298 registration->ActivateWaitingVersionWhenReady(); |
| 299 } |
| 300 |
278 static void DidFindRegistrationForDocument( | 301 static void DidFindRegistrationForDocument( |
279 const net::CompletionCallback& callback, | 302 const net::CompletionCallback& callback, |
280 ServiceWorkerStatusCode status, | 303 ServiceWorkerStatusCode status, |
281 const scoped_refptr<ServiceWorkerRegistration>& registration) { | 304 const scoped_refptr<ServiceWorkerRegistration>& registration) { |
282 int rv = registration ? net::OK : net::ERR_CACHE_MISS; | 305 int rv = registration ? net::OK : net::ERR_CACHE_MISS; |
283 // Use RunSoon here because FindRegistrationForDocument can complete | 306 // Use RunSoon here because FindRegistrationForDocument can complete |
284 // immediately but CanHandleMainResourceOffline must be async. | 307 // immediately but CanHandleMainResourceOffline must be async. |
285 RunSoon(base::Bind(callback, rv)); | 308 RunSoon(base::Bind(callback, rv)); |
286 } | 309 } |
287 | 310 |
(...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
610 observer_list_->Notify(FROM_HERE, | 633 observer_list_->Notify(FROM_HERE, |
611 &ServiceWorkerContextObserver::OnStorageWiped); | 634 &ServiceWorkerContextObserver::OnStorageWiped); |
612 } | 635 } |
613 | 636 |
614 ServiceWorkerContextCore* ServiceWorkerContextWrapper::context() { | 637 ServiceWorkerContextCore* ServiceWorkerContextWrapper::context() { |
615 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 638 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
616 return context_core_.get(); | 639 return context_core_.get(); |
617 } | 640 } |
618 | 641 |
619 } // namespace content | 642 } // namespace content |
OLD | NEW |