| Index: content/browser/service_worker/service_worker_context_wrapper.cc
|
| diff --git a/content/browser/service_worker/service_worker_context_wrapper.cc b/content/browser/service_worker/service_worker_context_wrapper.cc
|
| index 64ae3ea762f36fabfff18ff825a3dd97d0accf63..a083b06bef10045d1602e963fb752ed2af1d7ff8 100644
|
| --- a/content/browser/service_worker/service_worker_context_wrapper.cc
|
| +++ b/content/browser/service_worker/service_worker_context_wrapper.cc
|
| @@ -22,6 +22,7 @@
|
| #include "base/threading/sequenced_worker_pool.h"
|
| #include "base/threading/thread_task_runner_handle.h"
|
| #include "content/browser/renderer_host/render_process_host_impl.h"
|
| +#include "content/browser/service_worker/embedded_worker_status.h"
|
| #include "content/browser/service_worker/service_worker_context_core.h"
|
| #include "content/browser/service_worker/service_worker_context_observer.h"
|
| #include "content/browser/service_worker/service_worker_process_manager.h"
|
| @@ -377,6 +378,30 @@ void ServiceWorkerContextWrapper::DidFinishNavigationHintTaskOnUI(
|
| callback.Run(result);
|
| }
|
|
|
| +void ServiceWorkerContextWrapper::ExternalRequestErrorCallback(
|
| + int64_t service_worker_version_id,
|
| + const std::string& request_uuid,
|
| + ServiceWorkerStatusCode status) {
|
| + if (status != SERVICE_WORKER_OK) {
|
| + int request_id_not_used;
|
| + RemovePendingExternalRequest(service_worker_version_id, request_uuid,
|
| + &request_id_not_used);
|
| + }
|
| +}
|
| +
|
| +bool ServiceWorkerContextWrapper::RemovePendingExternalRequest(
|
| + int64_t service_worker_version_id,
|
| + const std::string& request_uuid,
|
| + int* request_id) {
|
| + RequestUUIDToRequestID& map_iter =
|
| + pending_external_requests_[service_worker_version_id];
|
| + RequestUUIDToRequestID::iterator iter = map_iter.find(request_uuid);
|
| + if (iter == map_iter.end())
|
| + return false;
|
| + *request_id = iter->second;
|
| + return true;
|
| +}
|
| +
|
| bool ServiceWorkerContextWrapper::IsRunningNavigationHintTask(
|
| int render_process_id) const {
|
| DCHECK_CURRENTLY_ON(BrowserThread::UI);
|
| @@ -825,6 +850,50 @@ void ServiceWorkerContextWrapper::ShutdownOnIO() {
|
| context_core_.reset();
|
| }
|
|
|
| +bool ServiceWorkerContextWrapper::IncrementPendingActivity(
|
| + int64_t service_worker_version_id,
|
| + const std::string& request_uuid) {
|
| + DCHECK_CURRENTLY_ON(BrowserThread::IO);
|
| + ServiceWorkerVersion* version =
|
| + context()->GetLiveVersion(service_worker_version_id);
|
| + if (!version)
|
| + return false;
|
| +
|
| + if (version->running_status() != EmbeddedWorkerStatus::RUNNING)
|
| + return false;
|
| +
|
| + int request_id = version->StartRequest(
|
| + ServiceWorkerMetrics::EventType::EXTERNAL_REQUEST,
|
| + base::Bind(&ServiceWorkerContextWrapper::ExternalRequestErrorCallback,
|
| + this, service_worker_version_id, request_uuid));
|
| + pending_external_requests_[service_worker_version_id].insert(
|
| + std::make_pair(request_uuid, request_id));
|
| + return true;
|
| +}
|
| +
|
| +bool ServiceWorkerContextWrapper::DecrementPendingActivity(
|
| + int64_t service_worker_version_id,
|
| + const std::string& request_uuid) {
|
| + DCHECK_CURRENTLY_ON(BrowserThread::IO);
|
| + int request_id = -1;
|
| + bool had_request = RemovePendingExternalRequest(service_worker_version_id,
|
| + request_uuid, &request_id);
|
| + if (!had_request) {
|
| + // It is possible that the request was cancelled or timed out before and we
|
| + // won't find it in |worker_requests|.
|
| + return true; // Return true so we don't kill the process.
|
| + }
|
| +
|
| + ServiceWorkerVersion* version =
|
| + context()->GetLiveVersion(service_worker_version_id);
|
| +
|
| + // The service worker should be present and running.
|
| + if (!version || version->running_status() != EmbeddedWorkerStatus::RUNNING)
|
| + return false;
|
| +
|
| + return version->FinishRequest(request_id, true, base::Time::Now());
|
| +}
|
| +
|
| void ServiceWorkerContextWrapper::DidDeleteAndStartOver(
|
| ServiceWorkerStatusCode status) {
|
| DCHECK_CURRENTLY_ON(BrowserThread::IO);
|
|
|