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

Unified Diff: content/browser/service_worker/service_worker_version.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 Devlin & MichaelN 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_version.cc
diff --git a/content/browser/service_worker/service_worker_version.cc b/content/browser/service_worker/service_worker_version.cc
index 337e676375282f1ea3cf4ccee6738d735cd5aef8..05dbaccf276a7637b29e9e257ea0deea7522497d 100644
--- a/content/browser/service_worker/service_worker_version.cc
+++ b/content/browser/service_worker/service_worker_version.cc
@@ -564,6 +564,21 @@ int ServiceWorkerVersion::StartRequestWithCustomTimeout(
return request_id;
}
+bool ServiceWorkerVersion::StartExternalRequest(
+ const std::string& request_uuid) {
+ // It's possible that the renderer is lying or the version started stopping
+ // right around the time of the IPC.
+ if (running_status() != EmbeddedWorkerStatus::RUNNING)
+ return false;
+
+ int request_id =
+ StartRequest(ServiceWorkerMetrics::EventType::EXTERNAL_REQUEST,
+ base::Bind(&ServiceWorkerVersion::CleanUpExternalRequest,
+ this, request_uuid));
+ external_request_uuid_to_request_id_[request_uuid] = request_id;
+ return true;
+}
+
bool ServiceWorkerVersion::FinishRequest(int request_id,
bool was_handled,
base::Time dispatch_event_time) {
@@ -589,6 +604,27 @@ bool ServiceWorkerVersion::FinishRequest(int request_id,
return true;
}
+bool ServiceWorkerVersion::FinishExternalRequest(
+ const std::string& request_uuid) {
+ // It's possible that the renderer is lying or the version started stopping
+ // right around the time of the IPC.
+ if (running_status() != EmbeddedWorkerStatus::RUNNING)
+ return false;
+
+ RequestUUIDToRequestIDMap::iterator iter =
+ external_request_uuid_to_request_id_.find(request_uuid);
+ if (iter != external_request_uuid_to_request_id_.end()) {
+ int request_id = iter->second;
+ external_request_uuid_to_request_id_.erase(iter);
+ return FinishRequest(request_id, true, base::Time::Now());
+ }
+
+ // It is possible that the request was cancelled or timed out before and we
+ // won't find it in |external_request_uuid_to_request_id_|.
+ // Return true so we don't kill the process.
+ return true;
+}
+
void ServiceWorkerVersion::RunAfterStartWorker(
ServiceWorkerMetrics::EventType purpose,
const base::Closure& task,
@@ -1765,6 +1801,7 @@ void ServiceWorkerVersion::OnStoppedInternal(EmbeddedWorkerStatus old_status) {
iter.Advance();
}
pending_requests_.Clear();
+ external_request_uuid_to_request_id_.clear();
Devlin 2016/10/07 15:13:22 For my own edification, how can the SW be stopped
falken 2016/10/07 15:22:03 It could be intentional: the browser process kills
Devlin 2016/10/07 15:46:37 Couple of thoughts here (not necessarily ones that
lazyboy 2016/10/07 18:50:10 Interesting, we definitely need to tackle this 5 m
Devlin 2016/10/07 19:06:44 Yeah, I think it's fine to land this part, since t
// Close all mojo services. This will also fire and clear all callbacks
// for messages that are still outstanding for those services.
@@ -1801,4 +1838,12 @@ void ServiceWorkerVersion::FinishStartWorker(ServiceWorkerStatusCode status) {
RunCallbacks(this, &start_callbacks_, status);
}
+void ServiceWorkerVersion::CleanUpExternalRequest(
+ const std::string& request_uuid,
+ ServiceWorkerStatusCode status) {
+ if (status == SERVICE_WORKER_OK)
+ return;
+ external_request_uuid_to_request_id_.erase(request_uuid);
+}
+
} // namespace content

Powered by Google App Engine
This is Rietveld 408576698