| 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 <utility> | 10 #include <utility> |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 48 void WorkerStarted(const ServiceWorkerContextWrapper::StatusCallback& callback, | 48 void WorkerStarted(const ServiceWorkerContextWrapper::StatusCallback& callback, |
| 49 ServiceWorkerStatusCode status) { | 49 ServiceWorkerStatusCode status) { |
| 50 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 50 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 51 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 51 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
| 52 base::Bind(callback, status)); | 52 base::Bind(callback, status)); |
| 53 } | 53 } |
| 54 | 54 |
| 55 void StartActiveWorkerOnIO( | 55 void StartActiveWorkerOnIO( |
| 56 const ServiceWorkerContextWrapper::StatusCallback& callback, | 56 const ServiceWorkerContextWrapper::StatusCallback& callback, |
| 57 ServiceWorkerStatusCode status, | 57 ServiceWorkerStatusCode status, |
| 58 const scoped_refptr<ServiceWorkerRegistration>& registration) { | 58 scoped_refptr<ServiceWorkerRegistration> registration) { |
| 59 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 59 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 60 if (status == SERVICE_WORKER_OK) { | 60 if (status == SERVICE_WORKER_OK) { |
| 61 // Pass the reference of |registration| to WorkerStarted callback to prevent | 61 // Pass the reference of |registration| to WorkerStarted callback to prevent |
| 62 // it from being deleted while starting the worker. If the refcount of | 62 // it from being deleted while starting the worker. If the refcount of |
| 63 // |registration| is 1, it will be deleted after WorkerStarted is called. | 63 // |registration| is 1, it will be deleted after WorkerStarted is called. |
| 64 registration->active_version()->StartWorker( | 64 registration->active_version()->StartWorker( |
| 65 ServiceWorkerMetrics::EventType::UNKNOWN, | 65 ServiceWorkerMetrics::EventType::UNKNOWN, |
| 66 base::Bind(WorkerStarted, callback)); | 66 base::Bind(WorkerStarted, callback)); |
| 67 return; | 67 return; |
| 68 } | 68 } |
| 69 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 69 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
| 70 base::Bind(callback, SERVICE_WORKER_ERROR_NOT_FOUND)); | 70 base::Bind(callback, SERVICE_WORKER_ERROR_NOT_FOUND)); |
| 71 } | 71 } |
| 72 | 72 |
| 73 void SkipWaitingWorkerOnIO( | 73 void SkipWaitingWorkerOnIO( |
| 74 ServiceWorkerStatusCode status, | 74 ServiceWorkerStatusCode status, |
| 75 const scoped_refptr<ServiceWorkerRegistration>& registration) { | 75 scoped_refptr<ServiceWorkerRegistration> registration) { |
| 76 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 76 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 77 if (status != SERVICE_WORKER_OK || !registration->waiting_version()) | 77 if (status != SERVICE_WORKER_OK || !registration->waiting_version()) |
| 78 return; | 78 return; |
| 79 | 79 |
| 80 registration->waiting_version()->set_skip_waiting(true); | 80 registration->waiting_version()->set_skip_waiting(true); |
| 81 registration->ActivateWaitingVersionWhenReady(); | 81 registration->ActivateWaitingVersionWhenReady(); |
| 82 } | 82 } |
| 83 | 83 |
| 84 } // namespace | 84 } // namespace |
| 85 | 85 |
| (...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 393 std::vector<ServiceWorkerVersionInfo> live_versions = GetAllLiveVersionInfo(); | 393 std::vector<ServiceWorkerVersionInfo> live_versions = GetAllLiveVersionInfo(); |
| 394 for (const ServiceWorkerVersionInfo& info : live_versions) { | 394 for (const ServiceWorkerVersionInfo& info : live_versions) { |
| 395 ServiceWorkerVersion* version = GetLiveVersion(info.version_id); | 395 ServiceWorkerVersion* version = GetLiveVersion(info.version_id); |
| 396 if (version && version->scope().GetOrigin() == origin) | 396 if (version && version->scope().GetOrigin() == origin) |
| 397 version->StopWorker(base::Bind(&ServiceWorkerUtils::NoOpStatusCallback)); | 397 version->StopWorker(base::Bind(&ServiceWorkerUtils::NoOpStatusCallback)); |
| 398 } | 398 } |
| 399 } | 399 } |
| 400 | 400 |
| 401 void ServiceWorkerContextWrapper::DidFindRegistrationForUpdate( | 401 void ServiceWorkerContextWrapper::DidFindRegistrationForUpdate( |
| 402 ServiceWorkerStatusCode status, | 402 ServiceWorkerStatusCode status, |
| 403 const scoped_refptr<ServiceWorkerRegistration>& registration) { | 403 scoped_refptr<ServiceWorkerRegistration> registration) { |
| 404 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 404 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 405 | 405 |
| 406 if (status != SERVICE_WORKER_OK) | 406 if (status != SERVICE_WORKER_OK) |
| 407 return; | 407 return; |
| 408 if (!context_core_) | 408 if (!context_core_) |
| 409 return; | 409 return; |
| 410 DCHECK(registration); | 410 DCHECK(registration); |
| 411 // TODO(jungkees): |force_bypass_cache| is set to true because the call stack | 411 // TODO(jungkees): |force_bypass_cache| is set to true because the call stack |
| 412 // is initiated by an update button on DevTools that expects the cache is | 412 // is initiated by an update button on DevTools that expects the cache is |
| 413 // bypassed. However, in order to provide options for callers to choose the | 413 // bypassed. However, in order to provide options for callers to choose the |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 557 } | 557 } |
| 558 context_core_->storage()->FindRegistrationForId( | 558 context_core_->storage()->FindRegistrationForId( |
| 559 registration_id, origin.GetOrigin(), | 559 registration_id, origin.GetOrigin(), |
| 560 base::Bind(&ServiceWorkerContextWrapper::DidFindRegistrationForFindReady, | 560 base::Bind(&ServiceWorkerContextWrapper::DidFindRegistrationForFindReady, |
| 561 this, callback)); | 561 this, callback)); |
| 562 } | 562 } |
| 563 | 563 |
| 564 void ServiceWorkerContextWrapper::DidFindRegistrationForFindReady( | 564 void ServiceWorkerContextWrapper::DidFindRegistrationForFindReady( |
| 565 const FindRegistrationCallback& callback, | 565 const FindRegistrationCallback& callback, |
| 566 ServiceWorkerStatusCode status, | 566 ServiceWorkerStatusCode status, |
| 567 const scoped_refptr<ServiceWorkerRegistration>& registration) { | 567 scoped_refptr<ServiceWorkerRegistration> registration) { |
| 568 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 568 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 569 if (status != SERVICE_WORKER_OK) { | 569 if (status != SERVICE_WORKER_OK) { |
| 570 callback.Run(status, nullptr); | 570 callback.Run(status, nullptr); |
| 571 return; | 571 return; |
| 572 } | 572 } |
| 573 | 573 |
| 574 // Attempt to activate the waiting version because the registration retrieved | 574 // Attempt to activate the waiting version because the registration retrieved |
| 575 // from the disk might have only the waiting version. | 575 // from the disk might have only the waiting version. |
| 576 if (registration->waiting_version()) | 576 if (registration->waiting_version()) |
| 577 registration->ActivateWaitingVersionWhenReady(); | 577 registration->ActivateWaitingVersionWhenReady(); |
| 578 | 578 |
| 579 scoped_refptr<ServiceWorkerVersion> active_version = | 579 scoped_refptr<ServiceWorkerVersion> active_version = |
| 580 registration->active_version(); | 580 registration->active_version(); |
| 581 if (!active_version) { | 581 if (!active_version) { |
| 582 callback.Run(SERVICE_WORKER_ERROR_NOT_FOUND, nullptr); | 582 callback.Run(SERVICE_WORKER_ERROR_NOT_FOUND, nullptr); |
| 583 return; | 583 return; |
| 584 } | 584 } |
| 585 | 585 |
| 586 if (active_version->status() == ServiceWorkerVersion::ACTIVATING) { | 586 if (active_version->status() == ServiceWorkerVersion::ACTIVATING) { |
| 587 // Wait until the version is activated. | 587 // Wait until the version is activated. |
| 588 active_version->RegisterStatusChangeCallback(base::Bind( | 588 active_version->RegisterStatusChangeCallback(base::Bind( |
| 589 &ServiceWorkerContextWrapper::OnStatusChangedForFindReadyRegistration, | 589 &ServiceWorkerContextWrapper::OnStatusChangedForFindReadyRegistration, |
| 590 this, callback, registration)); | 590 this, callback, std::move(registration))); |
| 591 return; | 591 return; |
| 592 } | 592 } |
| 593 | 593 |
| 594 DCHECK_EQ(ServiceWorkerVersion::ACTIVATED, active_version->status()); | 594 DCHECK_EQ(ServiceWorkerVersion::ACTIVATED, active_version->status()); |
| 595 callback.Run(SERVICE_WORKER_OK, registration); | 595 callback.Run(SERVICE_WORKER_OK, std::move(registration)); |
| 596 } | 596 } |
| 597 | 597 |
| 598 void ServiceWorkerContextWrapper::OnStatusChangedForFindReadyRegistration( | 598 void ServiceWorkerContextWrapper::OnStatusChangedForFindReadyRegistration( |
| 599 const FindRegistrationCallback& callback, | 599 const FindRegistrationCallback& callback, |
| 600 const scoped_refptr<ServiceWorkerRegistration>& registration) { | 600 scoped_refptr<ServiceWorkerRegistration> registration) { |
| 601 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 601 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 602 scoped_refptr<ServiceWorkerVersion> active_version = | 602 scoped_refptr<ServiceWorkerVersion> active_version = |
| 603 registration->active_version(); | 603 registration->active_version(); |
| 604 if (!active_version || | 604 if (!active_version || |
| 605 active_version->status() != ServiceWorkerVersion::ACTIVATED) { | 605 active_version->status() != ServiceWorkerVersion::ACTIVATED) { |
| 606 callback.Run(SERVICE_WORKER_ERROR_NOT_FOUND, nullptr); | 606 callback.Run(SERVICE_WORKER_ERROR_NOT_FOUND, nullptr); |
| 607 return; | 607 return; |
| 608 } | 608 } |
| 609 callback.Run(SERVICE_WORKER_OK, registration); | 609 callback.Run(SERVICE_WORKER_OK, registration); |
| 610 } | 610 } |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 740 observer_list_->Notify(FROM_HERE, | 740 observer_list_->Notify(FROM_HERE, |
| 741 &ServiceWorkerContextObserver::OnStorageWiped); | 741 &ServiceWorkerContextObserver::OnStorageWiped); |
| 742 } | 742 } |
| 743 | 743 |
| 744 ServiceWorkerContextCore* ServiceWorkerContextWrapper::context() { | 744 ServiceWorkerContextCore* ServiceWorkerContextWrapper::context() { |
| 745 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 745 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 746 return context_core_.get(); | 746 return context_core_.get(); |
| 747 } | 747 } |
| 748 | 748 |
| 749 } // namespace content | 749 } // namespace content |
| OLD | NEW |