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

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

Issue 2108573002: ServiceWorker: Add an API to fallback to renderer for CORS preflight (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Update comment and move the check of foreign fetch Created 4 years, 5 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_URL_REQUEST_JOB_H_ 5 #ifndef CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_URL_REQUEST_JOB_H_
6 #define CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_URL_REQUEST_JOB_H_ 6 #define CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_URL_REQUEST_JOB_H_
7 7
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <map> 10 #include <map>
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 ResourceType resource_type, 96 ResourceType resource_type,
97 RequestContextType request_context_type, 97 RequestContextType request_context_type,
98 RequestContextFrameType frame_type, 98 RequestContextFrameType frame_type,
99 scoped_refptr<ResourceRequestBodyImpl> body, 99 scoped_refptr<ResourceRequestBodyImpl> body,
100 ServiceWorkerFetchType fetch_type, 100 ServiceWorkerFetchType fetch_type,
101 Delegate* delegate); 101 Delegate* delegate);
102 102
103 ~ServiceWorkerURLRequestJob() override; 103 ~ServiceWorkerURLRequestJob() override;
104 104
105 // Sets the response type. 105 // Sets the response type.
106 // When an in-flight request possibly need CORS check, use
107 // FallbackToNetworkOrRenderer. This method will decide whether the request
108 // can directly go to the network or should fallback to a renderer to send
109 // CORS preflight. You can use FallbackToNetwork only when, like error cases,
110 // it's apparent that the request should go to the network directly.
falken 2016/07/07 01:11:12 I don't understand the error case thing anymore to
shimazu 2016/07/07 05:02:32 I see, I misunderstood what it's doing. Updated th
106 void FallbackToNetwork(); 111 void FallbackToNetwork();
112 void FallbackToNetworkOrRenderer();
107 void ForwardToServiceWorker(); 113 void ForwardToServiceWorker();
108 114
109 bool ShouldFallbackToNetwork() const { 115 bool ShouldFallbackToNetwork() const {
110 return response_type_ == FALLBACK_TO_NETWORK; 116 return response_type_ == FALLBACK_TO_NETWORK;
111 } 117 }
112 bool ShouldForwardToServiceWorker() const { 118 bool ShouldForwardToServiceWorker() const {
113 return response_type_ == FORWARD_TO_SERVICE_WORKER; 119 return response_type_ == FORWARD_TO_SERVICE_WORKER;
114 } 120 }
115 121
116 // net::URLRequestJob overrides: 122 // net::URLRequestJob overrides:
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 void OnStreamRegistered(Stream* stream) override; 155 void OnStreamRegistered(Stream* stream) override;
150 156
151 base::WeakPtr<ServiceWorkerURLRequestJob> GetWeakPtr(); 157 base::WeakPtr<ServiceWorkerURLRequestJob> GetWeakPtr();
152 158
153 private: 159 private:
154 class BlobConstructionWaiter; 160 class BlobConstructionWaiter;
155 161
156 enum ResponseType { 162 enum ResponseType {
157 NOT_DETERMINED, 163 NOT_DETERMINED,
158 FALLBACK_TO_NETWORK, 164 FALLBACK_TO_NETWORK,
165 FALLBACK_TO_RENDERER, // Use this when falling back with CORS check
159 FORWARD_TO_SERVICE_WORKER, 166 FORWARD_TO_SERVICE_WORKER,
160 }; 167 };
161 168
162 enum ResponseBodyType { 169 enum ResponseBodyType {
163 UNKNOWN, 170 UNKNOWN,
164 BLOB, 171 BLOB,
165 STREAM, 172 STREAM,
166 }; 173 };
167 174
168 // We start processing the request if Start() is called AND response_type_ 175 // We start processing the request if Start() is called AND response_type_
(...skipping 23 matching lines...) Expand all
192 const std::string& status_text, 199 const std::string& status_text,
193 const ServiceWorkerHeaderMap& headers); 200 const ServiceWorkerHeaderMap& headers);
194 201
195 // Creates |http_response_info_| using |http_response_headers_| and calls 202 // Creates |http_response_info_| using |http_response_headers_| and calls
196 // NotifyHeadersComplete. 203 // NotifyHeadersComplete.
197 void CommitResponseHeader(); 204 void CommitResponseHeader();
198 205
199 // Creates and commits a response header indicating error. 206 // Creates and commits a response header indicating error.
200 void DeliverErrorResponse(); 207 void DeliverErrorResponse();
201 208
209 // Restarts this job to fallback to network.
210 // This can be called after StartRequest.
211 void FinalizeFallbackToNetwork();
212
213 // Sends back a response with fall_back_required set as true to trigger
214 // subsequent network requests with CORS checking.
215 // This can be called after StartRequest.
216 void FinalizeFallbackToRenderer();
217
218 // True if need to send back a response with fall_back_required set as true to
219 // trigger subsequent network requests with CORS checking.
220 bool IsFallbackToRendererNeeded() const;
221
202 // For UMA. 222 // For UMA.
203 void SetResponseBodyType(ResponseBodyType type); 223 void SetResponseBodyType(ResponseBodyType type);
204 bool ShouldRecordResult(); 224 bool ShouldRecordResult();
205 void RecordResult(ServiceWorkerMetrics::URLRequestJobResult result); 225 void RecordResult(ServiceWorkerMetrics::URLRequestJobResult result);
206 void RecordStatusZeroResponseError( 226 void RecordStatusZeroResponseError(
207 blink::WebServiceWorkerResponseError error); 227 blink::WebServiceWorkerResponseError error);
208 228
209 // Releases the resources for streaming. 229 // Releases the resources for streaming.
210 void ClearStream(); 230 void ClearStream();
211 231
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
285 EmbeddedWorkerStatus initial_worker_status_ = EmbeddedWorkerStatus::STOPPED; 305 EmbeddedWorkerStatus initial_worker_status_ = EmbeddedWorkerStatus::STOPPED;
286 306
287 base::WeakPtrFactory<ServiceWorkerURLRequestJob> weak_factory_; 307 base::WeakPtrFactory<ServiceWorkerURLRequestJob> weak_factory_;
288 308
289 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerURLRequestJob); 309 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerURLRequestJob);
290 }; 310 };
291 311
292 } // namespace content 312 } // namespace content
293 313
294 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_URL_REQUEST_JOB_H_ 314 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_URL_REQUEST_JOB_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698