OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_JOB_WRAPPER_H_ | |
6 #define CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_JOB_WRAPPER_H_ | |
7 | |
8 #include "base/macros.h" | |
9 #include "content/browser/service_worker/service_worker_url_request_job.h" | |
10 | |
11 namespace content { | |
12 | |
13 // TODO(scottmg): Not yet implemented. See https://crbug.com/715640. | |
14 class ServiceWorkerControlleeURLLoader; | |
15 | |
16 // This class is a helper to support having | |
17 // ServiceWorkerControlleeRequestHandler work with both URLRequestJobs and | |
18 // mojom::URLLoaderFactorys (that is, both with and without | |
19 // --enable-network-service). It wraps either a ServiceWorkerURLRequestJob or a | |
20 // ServiceWorkerControlleeRequestHandler and forwards to the underlying | |
21 // implementation. | |
22 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
| |
23 public: | |
24 // Non-network service case. | |
25 explicit ServiceWorkerJobWrapper( | |
26 base::WeakPtr<ServiceWorkerURLRequestJob> url_request_job); | |
27 | |
28 // With --enable-network-service. | |
29 explicit ServiceWorkerJobWrapper( | |
30 ServiceWorkerControlleeURLLoader* url_loader); | |
31 | |
32 ~ServiceWorkerJobWrapper(); | |
33 | |
34 // Sets the response type. | |
35 void FallbackToNetwork(); | |
36 void FallbackToNetworkOrRenderer(); | |
37 void ForwardToServiceWorker(); | |
38 | |
39 // Returns true if this job should not be handled by a service worker, but | |
40 // instead should fallback to the network. | |
41 bool ShouldFallbackToNetwork(); | |
42 | |
43 // Tells the job to abort with a start error. Currently this is only called | |
44 // because the controller was lost. This function could be made more generic | |
45 // if needed later. | |
46 void FailDueToLostController(); | |
47 | |
48 // Determines from the ResourceRequestInfo (or similar) the type of page | |
49 // transition used (for metrics purposes). | |
50 ui::PageTransition GetPageTransition(); | |
51 | |
52 // Determines the number of redirects used to handle the job (for metrics | |
53 // purposes). | |
54 size_t GetURLChainSize() const; | |
55 | |
56 // Returns true if the underlying job has been canceled or destroyed. | |
57 bool WasCanceled() const; | |
58 | |
59 private: | |
60 base::WeakPtr<ServiceWorkerURLRequestJob> url_request_job_; | |
61 ServiceWorkerControlleeURLLoader* url_loader_; | |
62 | |
63 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerJobWrapper); | |
64 }; | |
65 | |
66 } // namespace content | |
67 | |
68 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_JOB_WRAPPER_H_ | |
OLD | NEW |