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

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: . 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"
13 #include "content/common/url_loader.mojom.h"
10 14
11 namespace content { 15 namespace content {
12 16
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 // This class is a helper to support having
17 // ServiceWorkerControlleeRequestHandler work with both URLRequestJobs and 18 // ServiceWorkerControlleeRequestHandler work with both URLRequestJobs and
18 // mojom::URLLoaderFactorys (that is, both with and without 19 // mojom::URLLoaderFactorys (that is, both with and without
19 // --enable-network-service). It wraps either a ServiceWorkerURLRequestJob or a 20 // --enable-network-service). It wraps either a ServiceWorkerURLRequestJob or a
20 // ServiceWorkerControlleeRequestHandler and forwards to the underlying 21 // ServiceWorkerControlleeRequestHandler and forwards to the underlying
21 // implementation. 22 // implementation.
22 class ServiceWorkerURLJobWrapper { 23 class ServiceWorkerURLJobWrapper {
23 public: 24 public:
24 // Non-network service case. 25 // Non-network service case.
25 explicit ServiceWorkerURLJobWrapper( 26 explicit ServiceWorkerURLJobWrapper(
26 base::WeakPtr<ServiceWorkerURLRequestJob> url_request_job); 27 base::WeakPtr<ServiceWorkerURLRequestJob> url_request_job);
27 28
28 // With --enable-network-service. 29 // With --enable-network-service.
29 explicit ServiceWorkerURLJobWrapper( 30 // TODO(kinuko): Implement this as a separate job class rather
30 ServiceWorkerControlleeURLLoader* url_loader); 31 // than in a wrapper.
32 ServiceWorkerURLJobWrapper(
33 URLLoaderRequestHandler::Controller* controller,
34 mojom::URLLoaderAssociatedRequest url_loader_request,
35 mojom::URLLoaderClientPtr url_loader_client_ptr);
31 36
32 ~ServiceWorkerURLJobWrapper(); 37 ~ServiceWorkerURLJobWrapper();
33 38
34 // Sets the response type. 39 // Sets the response type.
35 void FallbackToNetwork(); 40 void FallbackToNetwork();
36 void FallbackToNetworkOrRenderer(); 41 void FallbackToNetworkOrRenderer();
37 void ForwardToServiceWorker(); 42 void ForwardToServiceWorker();
38 43
39 // Returns true if this job should not be handled by a service worker, but 44 // Returns true if this job should not be handled by a service worker, but
40 // instead should fallback to the network. 45 // instead should fallback to the network.
41 bool ShouldFallbackToNetwork(); 46 bool ShouldFallbackToNetwork();
42 47
43 // Tells the job to abort with a start error. Currently this is only called 48 // 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 49 // because the controller was lost. This function could be made more generic
45 // if needed later. 50 // if needed later.
46 void FailDueToLostController(); 51 void FailDueToLostController();
47 52
48 // Determines from the ResourceRequestInfo (or similar) the type of page 53 // Determines from the ResourceRequestInfo (or similar) the type of page
49 // transition used (for metrics purposes). 54 // transition used (for metrics purposes).
50 ui::PageTransition GetPageTransition(); 55 ui::PageTransition GetPageTransition();
51 56
52 // Determines the number of redirects used to handle the job (for metrics 57 // Determines the number of redirects used to handle the job (for metrics
53 // purposes). 58 // purposes).
54 size_t GetURLChainSize() const; 59 size_t GetURLChainSize() const;
55 60
56 // Returns true if the underlying job has been canceled or destroyed. 61 // Returns true if the underlying job has been canceled or destroyed.
57 bool WasCanceled() const; 62 bool WasCanceled() const;
58 63
59 private: 64 private:
65 // Used only for URLLoader case.
66 // TODO(kinuko): Implement this in a separate job class rather
67 // than in a wrapper.
68 void StartRequest();
69
70 URLLoaderRequestHandler::Controller* controller_;
71 mojom::URLLoaderAssociatedRequest url_loader_request_;
72 mojom::URLLoaderClientPtr url_loader_client_ptr_;
73 ServiceWorkerResponseType response_type_ = NOT_DETERMINED;
74
60 base::WeakPtr<ServiceWorkerURLRequestJob> url_request_job_; 75 base::WeakPtr<ServiceWorkerURLRequestJob> url_request_job_;
61 ServiceWorkerControlleeURLLoader* url_loader_; 76
77 base::WeakPtrFactory<ServiceWorkerURLJobWrapper> weak_factory_;
62 78
63 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerURLJobWrapper); 79 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerURLJobWrapper);
64 }; 80 };
65 81
66 } // namespace content 82 } // namespace content
67 83
68 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_JOB_WRAPPER_H_ 84 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_JOB_WRAPPER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698