| OLD | NEW |
| 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 Loading... |
| 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 needs 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 main resource |
| 110 // or foreign fetch cases, it's apparent that the request should go to the |
| 111 // network directly. |
| 112 // TODO(shimazu): Update the comment when what should we do at foreign fetch |
| 113 // fallback is determined: crbug.com/604084 |
| 106 void FallbackToNetwork(); | 114 void FallbackToNetwork(); |
| 115 void FallbackToNetworkOrRenderer(); |
| 107 void ForwardToServiceWorker(); | 116 void ForwardToServiceWorker(); |
| 108 | 117 |
| 109 bool ShouldFallbackToNetwork() const { | 118 bool ShouldFallbackToNetwork() const { |
| 110 return response_type_ == FALLBACK_TO_NETWORK; | 119 return response_type_ == FALLBACK_TO_NETWORK; |
| 111 } | 120 } |
| 112 bool ShouldForwardToServiceWorker() const { | 121 bool ShouldForwardToServiceWorker() const { |
| 113 return response_type_ == FORWARD_TO_SERVICE_WORKER; | 122 return response_type_ == FORWARD_TO_SERVICE_WORKER; |
| 114 } | 123 } |
| 115 | 124 |
| 116 // net::URLRequestJob overrides: | 125 // net::URLRequestJob overrides: |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 149 void OnStreamRegistered(Stream* stream) override; | 158 void OnStreamRegistered(Stream* stream) override; |
| 150 | 159 |
| 151 base::WeakPtr<ServiceWorkerURLRequestJob> GetWeakPtr(); | 160 base::WeakPtr<ServiceWorkerURLRequestJob> GetWeakPtr(); |
| 152 | 161 |
| 153 private: | 162 private: |
| 154 class BlobConstructionWaiter; | 163 class BlobConstructionWaiter; |
| 155 | 164 |
| 156 enum ResponseType { | 165 enum ResponseType { |
| 157 NOT_DETERMINED, | 166 NOT_DETERMINED, |
| 158 FALLBACK_TO_NETWORK, | 167 FALLBACK_TO_NETWORK, |
| 168 FALLBACK_TO_RENDERER, // Use this when falling back with CORS check |
| 159 FORWARD_TO_SERVICE_WORKER, | 169 FORWARD_TO_SERVICE_WORKER, |
| 160 }; | 170 }; |
| 161 | 171 |
| 162 enum ResponseBodyType { | 172 enum ResponseBodyType { |
| 163 UNKNOWN, | 173 UNKNOWN, |
| 164 BLOB, | 174 BLOB, |
| 165 STREAM, | 175 STREAM, |
| 166 }; | 176 }; |
| 167 | 177 |
| 168 // We start processing the request if Start() is called AND response_type_ | 178 // We start processing the request if Start() is called AND response_type_ |
| (...skipping 23 matching lines...) Expand all Loading... |
| 192 const std::string& status_text, | 202 const std::string& status_text, |
| 193 const ServiceWorkerHeaderMap& headers); | 203 const ServiceWorkerHeaderMap& headers); |
| 194 | 204 |
| 195 // Creates |http_response_info_| using |http_response_headers_| and calls | 205 // Creates |http_response_info_| using |http_response_headers_| and calls |
| 196 // NotifyHeadersComplete. | 206 // NotifyHeadersComplete. |
| 197 void CommitResponseHeader(); | 207 void CommitResponseHeader(); |
| 198 | 208 |
| 199 // Creates and commits a response header indicating error. | 209 // Creates and commits a response header indicating error. |
| 200 void DeliverErrorResponse(); | 210 void DeliverErrorResponse(); |
| 201 | 211 |
| 212 // Restarts this job to fallback to network. |
| 213 // This can be called after StartRequest. |
| 214 void FinalizeFallbackToNetwork(); |
| 215 |
| 216 // Sends back a response with fall_back_required set as true to trigger |
| 217 // subsequent network requests with CORS checking. |
| 218 // This can be called after StartRequest. |
| 219 void FinalizeFallbackToRenderer(); |
| 220 |
| 221 // True if need to send back a response with fall_back_required set as true to |
| 222 // trigger subsequent network requests with CORS checking. |
| 223 bool IsFallbackToRendererNeeded() const; |
| 224 |
| 202 // For UMA. | 225 // For UMA. |
| 203 void SetResponseBodyType(ResponseBodyType type); | 226 void SetResponseBodyType(ResponseBodyType type); |
| 204 bool ShouldRecordResult(); | 227 bool ShouldRecordResult(); |
| 205 void RecordResult(ServiceWorkerMetrics::URLRequestJobResult result); | 228 void RecordResult(ServiceWorkerMetrics::URLRequestJobResult result); |
| 206 void RecordStatusZeroResponseError( | 229 void RecordStatusZeroResponseError( |
| 207 blink::WebServiceWorkerResponseError error); | 230 blink::WebServiceWorkerResponseError error); |
| 208 | 231 |
| 209 // Releases the resources for streaming. | 232 // Releases the resources for streaming. |
| 210 void ClearStream(); | 233 void ClearStream(); |
| 211 | 234 |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 285 EmbeddedWorkerStatus initial_worker_status_ = EmbeddedWorkerStatus::STOPPED; | 308 EmbeddedWorkerStatus initial_worker_status_ = EmbeddedWorkerStatus::STOPPED; |
| 286 | 309 |
| 287 base::WeakPtrFactory<ServiceWorkerURLRequestJob> weak_factory_; | 310 base::WeakPtrFactory<ServiceWorkerURLRequestJob> weak_factory_; |
| 288 | 311 |
| 289 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerURLRequestJob); | 312 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerURLRequestJob); |
| 290 }; | 313 }; |
| 291 | 314 |
| 292 } // namespace content | 315 } // namespace content |
| 293 | 316 |
| 294 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_URL_REQUEST_JOB_H_ | 317 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_URL_REQUEST_JOB_H_ |
| OLD | NEW |