Commit 720483e8 authored by Matt Falkenhagen's avatar Matt Falkenhagen Committed by Commit Bot

service worker: Various code cleanup and documentation.

This splits out purely code health changes from the master patch at
https://chromium-review.googlesource.com/c/chromium/src/+/981845

Change-Id: I0a36ea4a69c38fdbf22b514f1ebc43f3ed70f827
Reviewed-on: https://chromium-review.googlesource.com/999215Reviewed-by: default avatarKinuko Yasuda <kinuko@chromium.org>
Commit-Queue: Matt Falkenhagen <falken@chromium.org>
Cr-Commit-Position: refs/heads/master@{#548661}
parent c85136a9
...@@ -366,6 +366,7 @@ void ServiceWorkerContextCore::AddProviderHost( ...@@ -366,6 +366,7 @@ void ServiceWorkerContextCore::AddProviderHost(
ServiceWorkerProviderHost* ServiceWorkerContextCore::GetProviderHost( ServiceWorkerProviderHost* ServiceWorkerContextCore::GetProviderHost(
int process_id, int process_id,
int provider_id) { int provider_id) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
ProviderMap* map = GetProviderMapForProcess(process_id); ProviderMap* map = GetProviderMapForProcess(process_id);
if (!map) if (!map)
return nullptr; return nullptr;
......
...@@ -288,7 +288,7 @@ void ServiceWorkerControlleeRequestHandler::PrepareForMainResource( ...@@ -288,7 +288,7 @@ void ServiceWorkerControlleeRequestHandler::PrepareForMainResource(
// in redirect case, unassociate it now. // in redirect case, unassociate it now.
provider_host_->DisassociateRegistration(); provider_host_->DisassociateRegistration();
// Also prevent a registrater job for establishing an association to a new // Also prevent a register job from establishing an association to a new
// registration while we're finding an existing registration. // registration while we're finding an existing registration.
provider_host_->SetAllowAssociation(false); provider_host_->SetAllowAssociation(false);
...@@ -355,9 +355,8 @@ void ServiceWorkerControlleeRequestHandler:: ...@@ -355,9 +355,8 @@ void ServiceWorkerControlleeRequestHandler::
return; return;
} }
// Initiate activation of a waiting version. // Initiate activation of a waiting version. Usually a register job initiates
// Usually a register job initiates activation but that // activation but that doesn't happen if the browser exits prior to activation
// doesn't happen if the browser exits prior to activation
// having occurred. This check handles that case. // having occurred. This check handles that case.
if (registration->waiting_version()) if (registration->waiting_version())
registration->ActivateWaitingVersionWhenReady(); registration->ActivateWaitingVersionWhenReady();
......
...@@ -264,8 +264,8 @@ void ServiceWorkerNavigationLoader::DidDispatchFetchEvent( ...@@ -264,8 +264,8 @@ void ServiceWorkerNavigationLoader::DidDispatchFetchEvent(
return; return;
} }
// Creates a new HttpResponseInfo using the the ServiceWorker script's // Get SSLInfo from the ServiceWorker script's HttpResponseInfo to show HTTPS
// HttpResponseInfo to show HTTPS padlock. // padlock.
// TODO(horo): When we support mixed-content (HTTP) no-cors requests from a // TODO(horo): When we support mixed-content (HTTP) no-cors requests from a
// ServiceWorker, we have to check the security level of the responses. // ServiceWorker, we have to check the security level of the responses.
const net::HttpResponseInfo* main_script_http_info = const net::HttpResponseInfo* main_script_http_info =
......
...@@ -114,10 +114,10 @@ void RemoveProviderHost(base::WeakPtr<ServiceWorkerContextCore> context, ...@@ -114,10 +114,10 @@ void RemoveProviderHost(base::WeakPtr<ServiceWorkerContextCore> context,
TRACE_EVENT0("ServiceWorker", TRACE_EVENT0("ServiceWorker",
"ServiceWorkerProviderHost::RemoveProviderHost"); "ServiceWorkerProviderHost::RemoveProviderHost");
if (!context || !context->GetProviderHost(process_id, provider_id)) { if (!context || !context->GetProviderHost(process_id, provider_id)) {
// In some cancellation of navigation cases, it is possible for the // In some cases, it is possible for the Mojo endpoint of a pre-created
// pre-created host, whose |provider_id| is assigned by the browser process, // host to be destroyed before being claimed by the renderer and
// to have been destroyed before being claimed by the renderer. The provider // becoming owned by ServiceWorkerContextCore. The owner of the host is
// is then destroyed in the renderer, and no matching host will be found. // responsible for deleting the host, so just return here.
return; return;
} }
context->RemoveProviderHost(process_id, provider_id); context->RemoveProviderHost(process_id, provider_id);
......
...@@ -109,6 +109,7 @@ class SharedWorkerHost : public mojom::SharedWorkerHost, ...@@ -109,6 +109,7 @@ class SharedWorkerHost : public mojom::SharedWorkerHost,
mojo::ScopedMessagePipeHandle interface_pipe) override; mojo::ScopedMessagePipeHandle interface_pipe) override;
mojo::Binding<mojom::SharedWorkerHost> binding_; mojo::Binding<mojom::SharedWorkerHost> binding_;
// |service_| owns |this|.
SharedWorkerServiceImpl* service_; SharedWorkerServiceImpl* service_;
std::unique_ptr<SharedWorkerInstance> instance_; std::unique_ptr<SharedWorkerInstance> instance_;
ClientList clients_; ClientList clients_;
......
...@@ -27,7 +27,7 @@ struct ServiceWorkerProviderInfoForStartWorker { ...@@ -27,7 +27,7 @@ struct ServiceWorkerProviderInfoForStartWorker {
associated ServiceWorkerContainerHost host_ptr_info; associated ServiceWorkerContainerHost host_ptr_info;
associated ServiceWorkerContainer& client_request; associated ServiceWorkerContainer& client_request;
// For servicified service worker only. // S13nServiceWorker:
// The loader to use for loading the worker's main script and // The loader to use for loading the worker's main script and
// importScripts(). // importScripts().
associated network.mojom.URLLoaderFactory? script_loader_factory_ptr_info; associated network.mojom.URLLoaderFactory? script_loader_factory_ptr_info;
......
...@@ -56,14 +56,14 @@ struct CONTENT_EXPORT ServiceWorkerProviderHostInfo { ...@@ -56,14 +56,14 @@ struct CONTENT_EXPORT ServiceWorkerProviderHostInfo {
// Mojo endpoint to send a message from the renderer to the browser. This // Mojo endpoint to send a message from the renderer to the browser. This
// will be associated with ServiceWorkerDisptacherHost. |host_request| should // will be associated with ServiceWorkerDisptacherHost. |host_request| should
// be valid when ServiceWorkerProviderHostInfo is passed to any Mojo methods. // be valid when ServiceWorkerProviderHostInfo is passed to any Mojo method.
// After used to create the ServiceWorkerProviderHost, this will be invalid. // After used to create the ServiceWorkerProviderHost, this will be invalid.
mojom::ServiceWorkerContainerHostAssociatedRequest host_request; mojom::ServiceWorkerContainerHostAssociatedRequest host_request;
// Mojo endpoint to send a message from the browser to the renderer. This // Mojo endpoint to send a message from the browser to the renderer. This
// will be associated with ServiceWorkerDisptacherHost. |client_ptr_info| // will be associated with ServiceWorkerDispatcherHost. |client_ptr_info|
// should be valid when ServiceWorkerProviderHostInfo is passed to any Mojo // should be valid when ServiceWorkerProviderHostInfo is passed to any Mojo
// methods. // method.
// After used to create the ServiceWorkerProviderHost, this will be invalid. // After used to create the ServiceWorkerProviderHost, this will be invalid.
mojom::ServiceWorkerContainerAssociatedPtrInfo client_ptr_info; mojom::ServiceWorkerContainerAssociatedPtrInfo client_ptr_info;
......
...@@ -115,7 +115,7 @@ class WebServiceWorkerNetworkProviderImpl ...@@ -115,7 +115,7 @@ class WebServiceWorkerNetworkProviderImpl
} }
std::unique_ptr<blink::WebURLLoader> CreateURLLoader( std::unique_ptr<blink::WebURLLoader> CreateURLLoader(
const blink::WebURLRequest& request, const WebURLRequest& request,
scoped_refptr<base::SingleThreadTaskRunner> task_runner) override { scoped_refptr<base::SingleThreadTaskRunner> task_runner) override {
RenderThreadImpl* render_thread = RenderThreadImpl::current(); RenderThreadImpl* render_thread = RenderThreadImpl::current();
if (render_thread && provider_->script_loader_factory() && if (render_thread && provider_->script_loader_factory() &&
......
...@@ -99,32 +99,26 @@ class WebServiceWorkerNetworkProviderForFrame ...@@ -99,32 +99,26 @@ class WebServiceWorkerNetworkProviderForFrame
return nullptr; return nullptr;
// S13nServiceWorker: // S13nServiceWorker:
// We only install our own URLLoader if Servicification is // We only install our own URLLoader if Servicification is enabled.
// enabled.
if (!ServiceWorkerUtils::IsServicificationEnabled()) if (!ServiceWorkerUtils::IsServicificationEnabled())
return nullptr; return nullptr;
// S13nServiceWorker: // We need SubresourceLoaderFactory populated in order to create our own
// We need SubresourceLoaderFactory populated in order to // URLLoader for subresource loading.
// create our own URLLoader for subresource loading.
if (!provider_->context() || if (!provider_->context() ||
!provider_->context()->GetSubresourceLoaderFactory()) !provider_->context()->GetSubresourceLoaderFactory())
return nullptr; return nullptr;
// S13nServiceWorker: // If it's not for HTTP or HTTPS, no need to intercept the request.
// If it's not for HTTP or HTTPS no need to intercept the
// request.
if (!GURL(request.Url()).SchemeIsHTTPOrHTTPS()) if (!GURL(request.Url()).SchemeIsHTTPOrHTTPS())
return nullptr; return nullptr;
// S13nServiceWorker: // If GetSkipServiceWorker() returns true, do not intercept the request.
// If GetSkipServiceWorker() returns true, no need to intercept the request.
if (request.GetSkipServiceWorker()) if (request.GetSkipServiceWorker())
return nullptr; return nullptr;
// S13nServiceWorker: // Create our own SubresourceLoader to route the request to the controller
// Create our own SubresourceLoader to route the request // ServiceWorker.
// to the controller ServiceWorker.
// TODO(crbug.com/796425): Temporarily wrap the raw mojom::URLLoaderFactory // TODO(crbug.com/796425): Temporarily wrap the raw mojom::URLLoaderFactory
// pointer into SharedURLLoaderFactory. // pointer into SharedURLLoaderFactory.
return std::make_unique<WebURLLoaderImpl>( return std::make_unique<WebURLLoaderImpl>(
......
...@@ -15,7 +15,6 @@ ...@@ -15,7 +15,6 @@
#include "content/renderer/service_worker/controller_service_worker_connector.h" #include "content/renderer/service_worker/controller_service_worker_connector.h"
#include "mojo/public/cpp/bindings/binding.h" #include "mojo/public/cpp/bindings/binding.h"
#include "mojo/public/cpp/bindings/strong_binding.h" #include "mojo/public/cpp/bindings/strong_binding.h"
#include "net/url_request/redirect_info.h"
#include "net/url_request/redirect_util.h" #include "net/url_request/redirect_util.h"
#include "net/url_request/url_request.h" #include "net/url_request/url_request.h"
#include "services/network/public/cpp/shared_url_loader_factory.h" #include "services/network/public/cpp/shared_url_loader_factory.h"
......
...@@ -71,10 +71,9 @@ class WebServiceWorkerNetworkProvider { ...@@ -71,10 +71,9 @@ class WebServiceWorkerNetworkProvider {
// associated with the WebDocumentLoader. // associated with the WebDocumentLoader.
virtual int64_t ControllerServiceWorkerID() { return -1; } virtual int64_t ControllerServiceWorkerID() { return -1; }
// S13nServiceWorker:
// Returns a URLLoader for the associated context. May return nullptr // Returns a URLLoader for the associated context. May return nullptr
// if this doesn't provide a ServiceWorker specific URLLoader. // if this doesn't provide a ServiceWorker specific URLLoader.
// Currently this returns non-null only for a controller worker case
// and only if servicification is enabled.
virtual std::unique_ptr<WebURLLoader> CreateURLLoader( virtual std::unique_ptr<WebURLLoader> CreateURLLoader(
const WebURLRequest& request, const WebURLRequest& request,
scoped_refptr<base::SingleThreadTaskRunner> task_runner) { scoped_refptr<base::SingleThreadTaskRunner> task_runner) {
......
...@@ -47,8 +47,7 @@ class WebServiceWorkerNetworkProvider; ...@@ -47,8 +47,7 @@ class WebServiceWorkerNetworkProvider;
// the Worker object, unless noted. // the Worker object, unless noted.
// //
// An instance of this class must outlive WebSharedWorker (i.e. must be kept // An instance of this class must outlive WebSharedWorker (i.e. must be kept
// alive until WorkerScriptLoadFailed() or WorkerContextDestroyed() is // alive until WorkerScriptLoadFailed() or WorkerContextDestroyed() is called).
// called).
class WebSharedWorkerClient { class WebSharedWorkerClient {
public: public:
virtual void CountFeature(mojom::WebFeature) = 0; virtual void CountFeature(mojom::WebFeature) = 0;
...@@ -68,16 +67,21 @@ class WebSharedWorkerClient { ...@@ -68,16 +67,21 @@ class WebSharedWorkerClient {
virtual std::unique_ptr<WebApplicationCacheHost> CreateApplicationCacheHost( virtual std::unique_ptr<WebApplicationCacheHost> CreateApplicationCacheHost(
WebApplicationCacheHostClient*) = 0; WebApplicationCacheHostClient*) = 0;
// Called on the main thread during initialization. // Called on the main thread during initialization, before requesting the main
// script resource. Creates the ServiceWorkerNetworkProvider which is used for
// script loading (i.e., the main script and importScripts). Other requests
// (e.g., fetch and XHR) go through WebWorkerFetchContext.
virtual std::unique_ptr<WebServiceWorkerNetworkProvider> virtual std::unique_ptr<WebServiceWorkerNetworkProvider>
CreateServiceWorkerNetworkProvider() = 0; CreateServiceWorkerNetworkProvider() = 0;
// Returns a new WebWorkerFetchContext for the shared worker. Ownership of the // Called on the main thread during initialization, after the main script
// returned object is transferred to the caller. // resource finished loading. Creates a new WebWorkerFetchContext for the
// shared worker. This is passed to the worker thread and used for non-script
// loading requests from the shared worker (e.g., fetch and XHR). Requests for
// script loading (i.e., the main script and importScripts) go through
// WebServiceWorkerNetworkProvider.
virtual std::unique_ptr<WebWorkerFetchContext> CreateWorkerFetchContext( virtual std::unique_ptr<WebWorkerFetchContext> CreateWorkerFetchContext(
WebServiceWorkerNetworkProvider*) { WebServiceWorkerNetworkProvider*) = 0;
return nullptr;
}
}; };
} // namespace blink } // namespace blink
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment