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

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

Issue 2943583002: [extension SW] Support lazy events from extension service workers. (Closed)
Patch Set: Address comments Created 3 years, 6 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 fbb00d4fc0fd42a3bd650f6ce2cb7cc28cbcfdd0..cc57f3fb214c7e3d20c90a78b4fb2f4679529f61 100644
--- a/content/browser/service_worker/service_worker_context_wrapper.cc
+++ b/content/browser/service_worker/service_worker_context_wrapper.cc
@@ -82,6 +82,38 @@ void SkipWaitingWorkerOnIO(
registration->ActivateWaitingVersionWhenReady();
}
+void OnServiceWorkerStartedForGetWorkerInfo(
+ scoped_refptr<ServiceWorkerRegistration> service_worker_registration,
+ ServiceWorkerContext::GetWorkerInfoCallback info_callback) {
+ EmbeddedWorkerInstance* instance =
+ service_worker_registration->active_version()->embedded_worker();
falken 2017/06/22 03:35:57 It'd be safer to pass the active_version directly
lazyboy 2017/06/23 02:18:30 Done.
+ std::move(info_callback).Run(instance->process_id(), instance->thread_id());
+}
+
+void OnServiceWorkerErrorForGetWorkerInfo(base::OnceClosure error_callback,
+ ServiceWorkerStatusCode code) {
+ std::move(error_callback).Run();
+}
+
+void FoundReadyRegistrationForGetWorkerInfo(
+ ServiceWorkerContext::GetWorkerInfoCallback info_callback,
+ base::OnceClosure failure_callback,
+ ServiceWorkerStatusCode service_worker_status,
+ scoped_refptr<ServiceWorkerRegistration> service_worker_registration) {
+ DCHECK_CURRENTLY_ON(BrowserThread::IO);
+ if (service_worker_status == SERVICE_WORKER_OK) {
+ DCHECK(service_worker_registration->active_version());
+ service_worker_registration->active_version()->RunAfterStartWorker(
+ ServiceWorkerMetrics::EventType::EXTERNAL_REQUEST,
+ base::Bind(&OnServiceWorkerStartedForGetWorkerInfo,
+ service_worker_registration, base::Passed(&info_callback)),
+ base::Bind(&OnServiceWorkerErrorForGetWorkerInfo,
+ base::Passed(&failure_callback)));
+ } else {
+ std::move(failure_callback).Run();
+ }
+}
+
} // namespace
void ServiceWorkerContext::AddExcludedHeadersForFetchEvent(
@@ -841,6 +873,17 @@ bool ServiceWorkerContextWrapper::FinishedExternalRequest(
return version->FinishExternalRequest(request_uuid);
}
+void ServiceWorkerContextWrapper::GetWorkerInfoAfterStartWorker(
+ const GURL& origin,
+ GetWorkerInfoCallback info_callback,
+ base::OnceClosure failure_callback) {
+ DCHECK_CURRENTLY_ON(BrowserThread::IO);
+ FindReadyRegistrationForPattern(
+ origin, base::Bind(&FoundReadyRegistrationForGetWorkerInfo,
+ base::Passed(&info_callback),
+ base::Passed(&failure_callback)));
+}
+
void ServiceWorkerContextWrapper::DidDeleteAndStartOver(
ServiceWorkerStatusCode status) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);

Powered by Google App Engine
This is Rietveld 408576698