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

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 from falken@ 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 a25c00c647cd139db23e0cf12f4e43595da06f10..597da59a5cbcf78205cd282deaddac49171f9b78 100644
--- a/content/browser/service_worker/service_worker_context_wrapper.cc
+++ b/content/browser/service_worker/service_worker_context_wrapper.cc
@@ -83,6 +83,41 @@ void SkipWaitingWorkerOnIO(
registration->ActivateWaitingVersionWhenReady();
}
+void DidStartWorker(
+ scoped_refptr<ServiceWorkerVersion> active_version,
+ ServiceWorkerContext::StartActiveWorkerCallback info_callback) {
+ EmbeddedWorkerInstance* instance = active_version->embedded_worker();
falken 2017/06/23 03:45:46 nit: Since this function doesn't care about the ve
lazyboy 2017/06/23 07:44:56 Done.
+ std::move(info_callback).Run(instance->process_id(), instance->thread_id());
+}
+
+void DidFailStartWorker(base::OnceClosure error_callback,
+ ServiceWorkerStatusCode code) {
+ std::move(error_callback).Run();
+}
+
+void FoundReadyRegistrationForStartActiveWorker(
+ ServiceWorkerContext::StartActiveWorkerCallback 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) {
+ // Note: There might be a remote possibility that
+ // |service_worker_registration|'s active version might change between here
+ // and OnServiceWorkerStartedForStartActiveWorker, so use |active_version|.
falken 2017/06/23 03:45:46 This comment is a little confusing because at firs
lazyboy 2017/06/23 07:44:56 Done.
+ scoped_refptr<ServiceWorkerVersion> active_version =
+ service_worker_registration->active_version();
+ DCHECK(active_version.get());
+ active_version->RunAfterStartWorker(
+ ServiceWorkerMetrics::EventType::EXTERNAL_REQUEST,
+ base::Bind(&DidStartWorker, active_version,
+ base::Passed(&info_callback)),
+ base::Bind(&DidFailStartWorker, base::Passed(&failure_callback)));
+ } else {
+ std::move(failure_callback).Run();
+ }
+}
+
} // namespace
void ServiceWorkerContext::AddExcludedHeadersForFetchEvent(
@@ -854,6 +889,17 @@ bool ServiceWorkerContextWrapper::FinishedExternalRequest(
return version->FinishExternalRequest(request_uuid);
}
+void ServiceWorkerContextWrapper::StartActiveWorkerForPattern(
+ const GURL& pattern,
+ StartActiveWorkerCallback info_callback,
+ base::OnceClosure failure_callback) {
+ DCHECK_CURRENTLY_ON(BrowserThread::IO);
+ FindReadyRegistrationForPattern(
+ pattern, base::Bind(&FoundReadyRegistrationForStartActiveWorker,
+ 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