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

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

Issue 603913002: [ServiceWorker] Add was_fallback_required flag to ResourceResponseInfo. [2/2 chromium] (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: s/which/whose/ Created 6 years, 2 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 #include "content/browser/service_worker/service_worker_url_request_job.h" 5 #include "content/browser/service_worker/service_worker_url_request_job.h"
6 6
7 #include <map> 7 #include <map>
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 25 matching lines...) Expand all
36 base::WeakPtr<ServiceWorkerProviderHost> provider_host, 36 base::WeakPtr<ServiceWorkerProviderHost> provider_host,
37 base::WeakPtr<storage::BlobStorageContext> blob_storage_context, 37 base::WeakPtr<storage::BlobStorageContext> blob_storage_context,
38 FetchRequestMode request_mode, 38 FetchRequestMode request_mode,
39 scoped_refptr<ResourceRequestBody> body) 39 scoped_refptr<ResourceRequestBody> body)
40 : net::URLRequestJob(request, network_delegate), 40 : net::URLRequestJob(request, network_delegate),
41 provider_host_(provider_host), 41 provider_host_(provider_host),
42 response_type_(NOT_DETERMINED), 42 response_type_(NOT_DETERMINED),
43 is_started_(false), 43 is_started_(false),
44 blob_storage_context_(blob_storage_context), 44 blob_storage_context_(blob_storage_context),
45 request_mode_(request_mode), 45 request_mode_(request_mode),
46 fall_back_required_(false),
46 body_(body), 47 body_(body),
47 weak_factory_(this) { 48 weak_factory_(this) {
48 } 49 }
49 50
50 void ServiceWorkerURLRequestJob::FallbackToNetwork() { 51 void ServiceWorkerURLRequestJob::FallbackToNetwork() {
51 DCHECK_EQ(NOT_DETERMINED, response_type_); 52 DCHECK_EQ(NOT_DETERMINED, response_type_);
52 response_type_ = FALLBACK_TO_NETWORK; 53 response_type_ = FALLBACK_TO_NETWORK;
53 MaybeStartRequest(); 54 MaybeStartRequest();
54 } 55 }
55 56
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
188 const net::HttpResponseInfo* ServiceWorkerURLRequestJob::http_info() const { 189 const net::HttpResponseInfo* ServiceWorkerURLRequestJob::http_info() const {
189 if (!http_response_info_) 190 if (!http_response_info_)
190 return NULL; 191 return NULL;
191 if (range_response_info_) 192 if (range_response_info_)
192 return range_response_info_.get(); 193 return range_response_info_.get();
193 return http_response_info_.get(); 194 return http_response_info_.get();
194 } 195 }
195 196
196 void ServiceWorkerURLRequestJob::GetExtraResponseInfo( 197 void ServiceWorkerURLRequestJob::GetExtraResponseInfo(
197 bool* was_fetched_via_service_worker, 198 bool* was_fetched_via_service_worker,
199 bool* was_fallback_required_by_service_worker,
198 GURL* original_url_via_service_worker, 200 GURL* original_url_via_service_worker,
199 base::TimeTicks* fetch_start_time, 201 base::TimeTicks* fetch_start_time,
200 base::TimeTicks* fetch_ready_time, 202 base::TimeTicks* fetch_ready_time,
201 base::TimeTicks* fetch_end_time) const { 203 base::TimeTicks* fetch_end_time) const {
202 if (response_type_ != FORWARD_TO_SERVICE_WORKER) { 204 if (response_type_ != FORWARD_TO_SERVICE_WORKER) {
203 *was_fetched_via_service_worker = false; 205 *was_fetched_via_service_worker = false;
206 *was_fallback_required_by_service_worker = false;
204 *original_url_via_service_worker = GURL(); 207 *original_url_via_service_worker = GURL();
205 return; 208 return;
206 } 209 }
207 *was_fetched_via_service_worker = true; 210 *was_fetched_via_service_worker = true;
211 *was_fallback_required_by_service_worker = fall_back_required_;
208 *original_url_via_service_worker = response_url_; 212 *original_url_via_service_worker = response_url_;
209 *fetch_start_time = fetch_start_time_; 213 *fetch_start_time = fetch_start_time_;
210 *fetch_ready_time = fetch_ready_time_; 214 *fetch_ready_time = fetch_ready_time_;
211 *fetch_end_time = fetch_end_time_; 215 *fetch_end_time = fetch_end_time_;
212 } 216 }
213 217
214 218
215 ServiceWorkerURLRequestJob::~ServiceWorkerURLRequestJob() { 219 ServiceWorkerURLRequestJob::~ServiceWorkerURLRequestJob() {
216 } 220 }
217 221
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
366 // (Tentative behavior described on github) 370 // (Tentative behavior described on github)
367 // TODO(kinuko): consider returning error if we've come here because 371 // TODO(kinuko): consider returning error if we've come here because
368 // unexpected worker termination etc (so that we could fix bugs). 372 // unexpected worker termination etc (so that we could fix bugs).
369 // TODO(kinuko): Would be nice to log the error case. 373 // TODO(kinuko): Would be nice to log the error case.
370 response_type_ = FALLBACK_TO_NETWORK; 374 response_type_ = FALLBACK_TO_NETWORK;
371 NotifyRestartRequired(); 375 NotifyRestartRequired();
372 return; 376 return;
373 } 377 }
374 378
375 if (fetch_result == SERVICE_WORKER_FETCH_EVENT_RESULT_FALLBACK) { 379 if (fetch_result == SERVICE_WORKER_FETCH_EVENT_RESULT_FALLBACK) {
380 // When the request_mode is |CORS| or |CORS-with-forced-preflight| we can't
381 // simply fallback to the network in the browser process. It is because the
382 // CORS preflight logic is implemented in the renderer. So we returns a
383 // fall_back_required response to the renderer.
384 if (request_mode_ == FETCH_REQUEST_MODE_CORS ||
385 request_mode_ == FETCH_REQUEST_MODE_CORS_WITH_FORCED_PREFLIGHT) {
386 fall_back_required_ = true;
387 CreateResponseHeader(
388 400, "Service Worker Fallback Required", ServiceWorkerHeaderMap());
389 CommitResponseHeader();
390 return;
391 }
376 // Change the response type and restart the request to fallback to 392 // Change the response type and restart the request to fallback to
377 // the network. 393 // the network.
378 response_type_ = FALLBACK_TO_NETWORK; 394 response_type_ = FALLBACK_TO_NETWORK;
379 NotifyRestartRequired(); 395 NotifyRestartRequired();
380 return; 396 return;
381 } 397 }
382 398
383 // We should have a response now. 399 // We should have a response now.
384 DCHECK_EQ(SERVICE_WORKER_FETCH_EVENT_RESULT_RESPONSE, fetch_result); 400 DCHECK_EQ(SERVICE_WORKER_FETCH_EVENT_RESULT_RESPONSE, fetch_result);
385 401
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
445 461
446 void ServiceWorkerURLRequestJob::DeliverErrorResponse() { 462 void ServiceWorkerURLRequestJob::DeliverErrorResponse() {
447 // TODO(falken): Print an error to the console of the ServiceWorker and of 463 // TODO(falken): Print an error to the console of the ServiceWorker and of
448 // the requesting page. 464 // the requesting page.
449 CreateResponseHeader( 465 CreateResponseHeader(
450 500, "Service Worker Response Error", ServiceWorkerHeaderMap()); 466 500, "Service Worker Response Error", ServiceWorkerHeaderMap());
451 CommitResponseHeader(); 467 CommitResponseHeader();
452 } 468 }
453 469
454 } // namespace content 470 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/service_worker/service_worker_url_request_job.h ('k') | content/child/web_url_loader_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698