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

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

Issue 2843043002: network service: Create URLLoader for service worker navigation case
Patch Set: network fallback in simple cases Created 3 years, 7 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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_CONTROLLEE_REQUEST_HANDLER _H_ 5 #ifndef CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_CONTROLLEE_REQUEST_HANDLER _H_
6 #define CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_CONTROLLEE_REQUEST_HANDLER _H_ 6 #define CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_CONTROLLEE_REQUEST_HANDLER _H_
7 7
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include "base/gtest_prod_util.h" 10 #include "base/gtest_prod_util.h"
11 #include "base/macros.h" 11 #include "base/macros.h"
12 #include "base/memory/ref_counted.h" 12 #include "base/memory/ref_counted.h"
13 #include "base/memory/weak_ptr.h" 13 #include "base/memory/weak_ptr.h"
14 #include "base/time/time.h" 14 #include "base/time/time.h"
15 #include "content/browser/service_worker/service_worker_controllee_url_loader_fa ctory.h"
15 #include "content/browser/service_worker/service_worker_request_handler.h" 16 #include "content/browser/service_worker/service_worker_request_handler.h"
16 #include "content/browser/service_worker/service_worker_url_request_job.h" 17 #include "content/browser/service_worker/service_worker_url_request_job.h"
17 #include "content/common/service_worker/service_worker_types.h" 18 #include "content/common/service_worker/service_worker_types.h"
18 #include "content/public/common/request_context_frame_type.h" 19 #include "content/public/common/request_context_frame_type.h"
19 #include "content/public/common/request_context_type.h" 20 #include "content/public/common/request_context_type.h"
20 #include "content/public/common/resource_type.h" 21 #include "content/public/common/resource_type.h"
21 #include "third_party/WebKit/public/platform/modules/serviceworker/WebServiceWor kerResponseType.h" 22 #include "third_party/WebKit/public/platform/modules/serviceworker/WebServiceWor kerResponseType.h"
22 #include "url/gurl.h" 23 #include "url/gurl.h"
23 24
24 namespace net { 25 namespace net {
25 class NetworkDelegate; 26 class NetworkDelegate;
26 class URLRequest; 27 class URLRequest;
27 } 28 }
28 29
29 namespace content { 30 namespace content {
30 31
32 class JobWrapper;
31 class ResourceRequestBodyImpl; 33 class ResourceRequestBodyImpl;
32 class ServiceWorkerRegistration; 34 class ServiceWorkerRegistration;
33 class ServiceWorkerVersion; 35 class ServiceWorkerVersion;
34 36
35 // A request handler derivative used to handle requests from 37 // A request handler derivative used to handle requests from
36 // controlled documents. 38 // controlled documents.
37 class CONTENT_EXPORT ServiceWorkerControlleeRequestHandler 39 class CONTENT_EXPORT ServiceWorkerControlleeRequestHandler
38 : public ServiceWorkerRequestHandler, 40 : public ServiceWorkerRequestHandler,
39 public ServiceWorkerURLRequestJob::Delegate { 41 public ServiceWorkerURLRequestJob::Delegate,
42 public ServiceWorkerControlleeURLLoaderFactory::Delegate {
40 public: 43 public:
41 ServiceWorkerControlleeRequestHandler( 44 ServiceWorkerControlleeRequestHandler(
42 base::WeakPtr<ServiceWorkerContextCore> context, 45 base::WeakPtr<ServiceWorkerContextCore> context,
43 base::WeakPtr<ServiceWorkerProviderHost> provider_host, 46 base::WeakPtr<ServiceWorkerProviderHost> provider_host,
44 base::WeakPtr<storage::BlobStorageContext> blob_storage_context, 47 base::WeakPtr<storage::BlobStorageContext> blob_storage_context,
45 FetchRequestMode request_mode, 48 FetchRequestMode request_mode,
46 FetchCredentialsMode credentials_mode, 49 FetchCredentialsMode credentials_mode,
47 FetchRedirectMode redirect_mode, 50 FetchRedirectMode redirect_mode,
48 ResourceType resource_type, 51 ResourceType resource_type,
49 RequestContextType request_context_type, 52 RequestContextType request_context_type,
50 RequestContextFrameType frame_type, 53 RequestContextFrameType frame_type,
51 scoped_refptr<ResourceRequestBodyImpl> body); 54 scoped_refptr<ResourceRequestBodyImpl> body);
52 ~ServiceWorkerControlleeRequestHandler() override; 55 ~ServiceWorkerControlleeRequestHandler() override;
53 56
54 // Called via custom URLRequestJobFactory. 57 // Called via custom URLRequestJobFactory.
55 net::URLRequestJob* MaybeCreateJob( 58 net::URLRequestJob* MaybeCreateJob(
56 net::URLRequest* request, 59 net::URLRequest* request,
57 net::NetworkDelegate* network_delegate, 60 net::NetworkDelegate* network_delegate,
58 ResourceContext* resource_context) override; 61 ResourceContext* resource_context) override;
59 62
63 mojom::URLLoaderFactoryPtrInfo MaybeCreateURLLoader(
64 const ResourceRequest& resource_request,
65 ResourceContext* resource_context,
66 std::unique_ptr<ServiceWorkerRequestHandler> request_handler) override;
67
60 private: 68 private:
61 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerControlleeRequestHandlerTest, 69 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerControlleeRequestHandlerTest,
62 ActivateWaitingVersion); 70 ActivateWaitingVersion);
63 typedef ServiceWorkerControlleeRequestHandler self; 71 typedef ServiceWorkerControlleeRequestHandler self;
64 72
65 // For main resource case. 73 // For main resource case.
66 void PrepareForMainResource(const net::URLRequest* request); 74 void PrepareForMainResource(const GURL& url,
75 const GURL& first_party_for_cookies);
67 void DidLookupRegistrationForMainResource( 76 void DidLookupRegistrationForMainResource(
68 ServiceWorkerStatusCode status, 77 ServiceWorkerStatusCode status,
69 scoped_refptr<ServiceWorkerRegistration> registration); 78 scoped_refptr<ServiceWorkerRegistration> registration);
70 void OnVersionStatusChanged( 79 void OnVersionStatusChanged(
71 ServiceWorkerRegistration* registration, 80 ServiceWorkerRegistration* registration,
72 ServiceWorkerVersion* version); 81 ServiceWorkerVersion* version);
73 82
74 void DidUpdateRegistration( 83 void DidUpdateRegistration(
75 const scoped_refptr<ServiceWorkerRegistration>& original_registration, 84 const scoped_refptr<ServiceWorkerRegistration>& original_registration,
76 ServiceWorkerStatusCode status, 85 ServiceWorkerStatusCode status,
(...skipping 17 matching lines...) Expand all
94 bool RequestStillValid( 103 bool RequestStillValid(
95 ServiceWorkerMetrics::URLRequestJobResult* result) override; 104 ServiceWorkerMetrics::URLRequestJobResult* result) override;
96 void MainResourceLoadFailed() override; 105 void MainResourceLoadFailed() override;
97 106
98 // Sets |job_| to nullptr, and clears all extra response info associated with 107 // Sets |job_| to nullptr, and clears all extra response info associated with
99 // that job, except for timing information. 108 // that job, except for timing information.
100 void ClearJob(); 109 void ClearJob();
101 110
102 const bool is_main_resource_load_; 111 const bool is_main_resource_load_;
103 const bool is_main_frame_load_; 112 const bool is_main_frame_load_;
104 base::WeakPtr<ServiceWorkerURLRequestJob> job_; 113 std::unique_ptr<JobWrapper> job_;
105 FetchRequestMode request_mode_; 114 FetchRequestMode request_mode_;
106 FetchCredentialsMode credentials_mode_; 115 FetchCredentialsMode credentials_mode_;
107 FetchRedirectMode redirect_mode_; 116 FetchRedirectMode redirect_mode_;
108 RequestContextType request_context_type_; 117 RequestContextType request_context_type_;
109 RequestContextFrameType frame_type_; 118 RequestContextFrameType frame_type_;
110 scoped_refptr<ResourceRequestBodyImpl> body_; 119 scoped_refptr<ResourceRequestBodyImpl> body_;
111 ResourceContext* resource_context_; 120 ResourceContext* resource_context_;
112 GURL stripped_url_; 121 GURL stripped_url_;
113 bool force_update_started_; 122 bool force_update_started_;
114 123
115 // True if the next time this request is started, the response should be 124 // True if the next time this request is started, the response should be
116 // delivered from the network, bypassing the ServiceWorker. Cleared after the 125 // delivered from the network, bypassing the ServiceWorker. Cleared after the
117 // next intercept opportunity, for main frame requests. 126 // next intercept opportunity, for main frame requests.
118 bool use_network_; 127 bool use_network_;
119 128
120 base::WeakPtrFactory<ServiceWorkerControlleeRequestHandler> weak_factory_; 129 base::WeakPtrFactory<ServiceWorkerControlleeRequestHandler> weak_factory_;
121 130
122 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerControlleeRequestHandler); 131 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerControlleeRequestHandler);
123 }; 132 };
124 133
125 } // namespace content 134 } // namespace content
126 135
127 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_CONTROLLEE_REQUEST_HAND LER_H_ 136 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_CONTROLLEE_REQUEST_HAND LER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698