Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(22)

Unified Diff: content/browser/service_worker/service_worker_context_wrapper.cc

Issue 2166523003: Add ref count to service workers for extension API. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: address comments from falken@ Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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) {
Devlin 2016/10/05 17:02:25 drive-by nit: DCHECK(request_id)?
lazyboy 2016/10/06 01:02:06 Obsolete /w the recent change suggested by michael
+ 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;
michaeln 2016/10/05 19:22:53 where is .erase(iter)? i don't see where anything
lazyboy 2016/10/06 01:02:06 Good catch, I might have dropped removing when upl
+ 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)
Devlin 2016/10/05 17:02:25 Can this legitimately happen? If so, how? (Maybe
lazyboy 2016/10/06 01:02:06 Added comment.
+ return false;
+
+ int request_id = version->StartRequest(
michaeln 2016/10/05 19:22:53 version->StartExternalRequest(uuid); // no error
lazyboy 2016/10/06 01:02:06 OK. Moved the map inside ServiceWorkerVersion and
+ 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)
Devlin 2016/10/05 17:02:25 ditto
lazyboy 2016/10/06 01:02:06 Done.
+ return false;
+
+ return version->FinishRequest(request_id, true, base::Time::Now());
michaeln 2016/10/05 19:22:53 version->FinishExternalRequest(uuid);
lazyboy 2016/10/06 01:02:06 Done.
+}
+
void ServiceWorkerContextWrapper::DidDeleteAndStartOver(
ServiceWorkerStatusCode status) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);

Powered by Google App Engine
This is Rietveld 408576698