Chromium Code Reviews| Index: content/browser/service_worker/service_worker_job_wrapper.h | 
| diff --git a/content/browser/service_worker/service_worker_job_wrapper.h b/content/browser/service_worker/service_worker_job_wrapper.h | 
| new file mode 100644 | 
| index 0000000000000000000000000000000000000000..e9c6399b5d89f6805c7910c55ebb2e8c06d5cbdc | 
| --- /dev/null | 
| +++ b/content/browser/service_worker/service_worker_job_wrapper.h | 
| @@ -0,0 +1,68 @@ | 
| +// Copyright 2017 The Chromium Authors. All rights reserved. | 
| +// Use of this source code is governed by a BSD-style license that can be | 
| +// found in the LICENSE file. | 
| + | 
| +#ifndef CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_JOB_WRAPPER_H_ | 
| +#define CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_JOB_WRAPPER_H_ | 
| + | 
| +#include "base/macros.h" | 
| +#include "content/browser/service_worker/service_worker_url_request_job.h" | 
| + | 
| +namespace content { | 
| + | 
| +// TODO(scottmg): Not yet implemented. See https://crbug.com/715640. | 
| +class ServiceWorkerControlleeURLLoader; | 
| + | 
| +// This class is a helper to support having | 
| +// ServiceWorkerControlleeRequestHandler work with both URLRequestJobs and | 
| +// mojom::URLLoaderFactorys (that is, both with and without | 
| +// --enable-network-service). It wraps either a ServiceWorkerURLRequestJob or a | 
| +// ServiceWorkerControlleeRequestHandler and forwards to the underlying | 
| +// implementation. | 
| +class ServiceWorkerJobWrapper { | 
| 
 
falken
2017/05/17 01:29:05
nit: ServiceWorkerJobWrapper isn't a great name si
 
scottmg
2017/05/17 18:28:00
Agreed, the name is poor. How about ServiceWorkerU
 
 | 
| + public: | 
| + // Non-network service case. | 
| + explicit ServiceWorkerJobWrapper( | 
| + base::WeakPtr<ServiceWorkerURLRequestJob> url_request_job); | 
| + | 
| + // With --enable-network-service. | 
| + explicit ServiceWorkerJobWrapper( | 
| + ServiceWorkerControlleeURLLoader* url_loader); | 
| + | 
| + ~ServiceWorkerJobWrapper(); | 
| + | 
| + // Sets the response type. | 
| + void FallbackToNetwork(); | 
| + void FallbackToNetworkOrRenderer(); | 
| + void ForwardToServiceWorker(); | 
| + | 
| + // Returns true if this job should not be handled by a service worker, but | 
| + // instead should fallback to the network. | 
| + bool ShouldFallbackToNetwork(); | 
| + | 
| + // Tells the job to abort with a start error. Currently this is only called | 
| + // because the controller was lost. This function could be made more generic | 
| + // if needed later. | 
| + void FailDueToLostController(); | 
| + | 
| + // Determines from the ResourceRequestInfo (or similar) the type of page | 
| + // transition used (for metrics purposes). | 
| + ui::PageTransition GetPageTransition(); | 
| + | 
| + // Determines the number of redirects used to handle the job (for metrics | 
| + // purposes). | 
| + size_t GetURLChainSize() const; | 
| + | 
| + // Returns true if the underlying job has been canceled or destroyed. | 
| + bool WasCanceled() const; | 
| + | 
| + private: | 
| + base::WeakPtr<ServiceWorkerURLRequestJob> url_request_job_; | 
| + ServiceWorkerControlleeURLLoader* url_loader_; | 
| + | 
| + DISALLOW_COPY_AND_ASSIGN(ServiceWorkerJobWrapper); | 
| +}; | 
| + | 
| +} // namespace content | 
| + | 
| +#endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_JOB_WRAPPER_H_ |