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

Side by Side Diff: content/browser/service_worker/service_worker_url_job_wrapper.h

Issue 2897063002: Network service: Implement URLLoader chaining for interceptors (Closed)
Patch Set: documentation 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 unified diff | Download patch
OLDNEW
1 // Copyright 2017 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_JOB_WRAPPER_H_ 5 #ifndef CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_JOB_WRAPPER_H_
6 #define CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_JOB_WRAPPER_H_ 6 #define CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_JOB_WRAPPER_H_
7 7
8 #include "base/macros.h" 8 #include "base/macros.h"
9 #include "base/memory/weak_ptr.h"
10 #include "content/browser/loader/url_loader_request_handler.h"
11 #include "content/browser/service_worker/service_worker_response_type.h"
9 #include "content/browser/service_worker/service_worker_url_request_job.h" 12 #include "content/browser/service_worker/service_worker_url_request_job.h"
10 13
11 namespace content { 14 namespace content {
12 15
13 // TODO(scottmg): Not yet implemented. See https://crbug.com/715640.
14 class ServiceWorkerControlleeURLLoader;
15
16 // This class is a helper to support having 16 // This class is a helper to support having
17 // ServiceWorkerControlleeRequestHandler work with both URLRequestJobs and 17 // ServiceWorkerControlleeRequestHandler work with both URLRequestJobs and
18 // mojom::URLLoaderFactorys (that is, both with and without 18 // mojom::URLLoaderFactorys (that is, both with and without
19 // --enable-network-service). It wraps either a ServiceWorkerURLRequestJob or a 19 // --enable-network-service). It wraps either a ServiceWorkerURLRequestJob or a
20 // ServiceWorkerControlleeRequestHandler and forwards to the underlying 20 // callback for URLLoaderFactory and forwards to the underlying implementation.
21 // implementation.
22 class ServiceWorkerURLJobWrapper { 21 class ServiceWorkerURLJobWrapper {
23 public: 22 public:
24 // Non-network service case. 23 // Non-network service case.
25 explicit ServiceWorkerURLJobWrapper( 24 explicit ServiceWorkerURLJobWrapper(
26 base::WeakPtr<ServiceWorkerURLRequestJob> url_request_job); 25 base::WeakPtr<ServiceWorkerURLRequestJob> url_request_job);
27 26
28 // With --enable-network-service. 27 // With --enable-network-service.
29 explicit ServiceWorkerURLJobWrapper( 28 // TODO(kinuko): Implement this as a separate job class rather
30 ServiceWorkerControlleeURLLoader* url_loader); 29 // than in a wrapper.
30 ServiceWorkerURLJobWrapper(LoaderFactoryCallback loader_factory_callback);
31 31
32 ~ServiceWorkerURLJobWrapper(); 32 ~ServiceWorkerURLJobWrapper();
33 33
34 // Sets the response type. 34 // Sets the response type.
35 void FallbackToNetwork(); 35 void FallbackToNetwork();
36 void FallbackToNetworkOrRenderer(); 36 void FallbackToNetworkOrRenderer();
37 void ForwardToServiceWorker(); 37 void ForwardToServiceWorker();
38 38
39 // Returns true if this job should not be handled by a service worker, but 39 // Returns true if this job should not be handled by a service worker, but
40 // instead should fallback to the network. 40 // instead should fallback to the network.
41 bool ShouldFallbackToNetwork(); 41 bool ShouldFallbackToNetwork();
42 42
43 // Tells the job to abort with a start error. Currently this is only called 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 44 // because the controller was lost. This function could be made more generic
45 // if needed later. 45 // if needed later.
46 void FailDueToLostController(); 46 void FailDueToLostController();
47 47
48 // Determines from the ResourceRequestInfo (or similar) the type of page 48 // Determines from the ResourceRequestInfo (or similar) the type of page
49 // transition used (for metrics purposes). 49 // transition used (for metrics purposes).
50 ui::PageTransition GetPageTransition(); 50 ui::PageTransition GetPageTransition();
51 51
52 // Determines the number of redirects used to handle the job (for metrics 52 // Determines the number of redirects used to handle the job (for metrics
53 // purposes). 53 // purposes).
54 size_t GetURLChainSize() const; 54 size_t GetURLChainSize() const;
55 55
56 // Returns true if the underlying job has been canceled or destroyed. 56 // Returns true if the underlying job has been canceled or destroyed.
57 bool WasCanceled() const; 57 bool WasCanceled() const;
58 58
59 private: 59 private:
60 enum class JobType { kURLRequest, kURLLoader };
61
62 // Used only for URLLoader case.
63 // TODO(kinuko): Implement this in a separate job class rather
64 // than in a wrapper.
65 void StartRequest();
66
67 JobType job_type_;
68
69 ServiceWorkerResponseType response_type_ = NOT_DETERMINED;
70 LoaderFactoryCallback loader_factory_callback_;
71
60 base::WeakPtr<ServiceWorkerURLRequestJob> url_request_job_; 72 base::WeakPtr<ServiceWorkerURLRequestJob> url_request_job_;
61 ServiceWorkerControlleeURLLoader* url_loader_; 73
74 base::WeakPtrFactory<ServiceWorkerURLJobWrapper> weak_factory_;
62 75
63 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerURLJobWrapper); 76 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerURLJobWrapper);
64 }; 77 };
65 78
66 } // namespace content 79 } // namespace content
67 80
68 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_JOB_WRAPPER_H_ 81 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_JOB_WRAPPER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698