Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/loader/resource_loader.h" | 5 #include "content/browser/loader/resource_loader.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/location.h" | 8 #include "base/location.h" |
| 9 #include "base/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
| 10 #include "base/profiler/scoped_tracker.h" | 10 #include "base/profiler/scoped_tracker.h" |
| (...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 273 !ChildProcessSecurityPolicyImpl::GetInstance()-> | 273 !ChildProcessSecurityPolicyImpl::GetInstance()-> |
| 274 CanRequestURL(info->GetChildID(), redirect_info.new_url)) { | 274 CanRequestURL(info->GetChildID(), redirect_info.new_url)) { |
| 275 DVLOG(1) << "Denied unauthorized request for " | 275 DVLOG(1) << "Denied unauthorized request for " |
| 276 << redirect_info.new_url.possibly_invalid_spec(); | 276 << redirect_info.new_url.possibly_invalid_spec(); |
| 277 | 277 |
| 278 // Tell the renderer that this request was disallowed. | 278 // Tell the renderer that this request was disallowed. |
| 279 Cancel(); | 279 Cancel(); |
| 280 return; | 280 return; |
| 281 } | 281 } |
| 282 | 282 |
| 283 if (info->fetch_redirect_mode() == FETCH_REDIRECT_MODE_ERROR) { | |
| 284 Cancel(); | |
| 285 return; | |
| 286 } else if (info->fetch_redirect_mode() == FETCH_REDIRECT_MODE_MANUAL) { | |
| 287 // TODO(horo): If we support upload progress events for Fetch API, we will | |
| 288 // have to call ReportUploadProgress(). | |
| 289 DCHECK(!GetRequestInfo()->is_upload_progress_enabled()); | |
| 290 | |
| 291 CompleteResponseStarted(true); | |
| 292 if (is_deferred()) | |
| 293 return; | |
| 294 | |
| 295 // There is no need to read the response body here because there is no way | |
| 296 // to read the body of opaque-redirect filtered response's internal | |
| 297 // response. | |
| 298 // TODO(horo): If we support any API which expose the internal body, we will | |
| 299 // have to read the body before calling ResponseCompleted(). And also Cache | |
| 300 // changes will be needed because it doesn't store the body of redirect | |
| 301 // responses. | |
| 302 ResponseCompleted(); | |
| 303 return; | |
| 304 } | |
| 305 | |
| 283 delegate_->DidReceiveRedirect(this, redirect_info.new_url); | 306 delegate_->DidReceiveRedirect(this, redirect_info.new_url); |
| 284 | 307 |
| 285 if (delegate_->HandleExternalProtocol(this, redirect_info.new_url)) { | 308 if (delegate_->HandleExternalProtocol(this, redirect_info.new_url)) { |
| 286 // The request is complete so we can remove it. | 309 // The request is complete so we can remove it. |
| 287 CancelAndIgnore(); | 310 CancelAndIgnore(); |
| 288 return; | 311 return; |
| 289 } | 312 } |
| 290 | 313 |
| 291 scoped_refptr<ResourceResponse> response(new ResourceResponse()); | 314 scoped_refptr<ResourceResponse> response(new ResourceResponse()); |
| 292 PopulateResourceResponse(info, request_.get(), response.get()); | 315 PopulateResourceResponse(info, request_.get(), response.get()); |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 382 | 405 |
| 383 // We want to send a final upload progress message prior to sending the | 406 // We want to send a final upload progress message prior to sending the |
| 384 // response complete message even if we're waiting for an ack to to a | 407 // response complete message even if we're waiting for an ack to to a |
| 385 // previous upload progress message. | 408 // previous upload progress message. |
| 386 ResourceRequestInfoImpl* info = GetRequestInfo(); | 409 ResourceRequestInfoImpl* info = GetRequestInfo(); |
| 387 if (info->is_upload_progress_enabled()) { | 410 if (info->is_upload_progress_enabled()) { |
| 388 waiting_for_upload_progress_ack_ = false; | 411 waiting_for_upload_progress_ack_ = false; |
| 389 ReportUploadProgress(); | 412 ReportUploadProgress(); |
| 390 } | 413 } |
| 391 | 414 |
| 392 CompleteResponseStarted(); | 415 CompleteResponseStarted(false); |
| 393 | 416 |
| 394 if (is_deferred()) | 417 if (is_deferred()) |
| 395 return; | 418 return; |
| 396 | 419 |
| 397 if (request_->status().is_success()) | 420 if (request_->status().is_success()) |
| 398 StartReading(false); // Read the first chunk. | 421 StartReading(false); // Read the first chunk. |
| 399 else | 422 else |
| 400 ResponseCompleted(); | 423 ResponseCompleted(); |
| 401 } | 424 } |
| 402 | 425 |
| (...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 575 if (!was_pending) { | 598 if (!was_pending) { |
| 576 // If the request isn't in flight, then we won't get an asynchronous | 599 // If the request isn't in flight, then we won't get an asynchronous |
| 577 // notification from the request, so we have to signal ourselves to finish | 600 // notification from the request, so we have to signal ourselves to finish |
| 578 // this request. | 601 // this request. |
| 579 base::ThreadTaskRunnerHandle::Get()->PostTask( | 602 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 580 FROM_HERE, base::Bind(&ResourceLoader::ResponseCompleted, | 603 FROM_HERE, base::Bind(&ResourceLoader::ResponseCompleted, |
| 581 weak_ptr_factory_.GetWeakPtr())); | 604 weak_ptr_factory_.GetWeakPtr())); |
| 582 } | 605 } |
| 583 } | 606 } |
| 584 | 607 |
| 585 void ResourceLoader::CompleteResponseStarted() { | 608 void ResourceLoader::CompleteResponseStarted(bool is_redirect_response) { |
| 586 ResourceRequestInfoImpl* info = GetRequestInfo(); | 609 ResourceRequestInfoImpl* info = GetRequestInfo(); |
| 587 scoped_refptr<ResourceResponse> response(new ResourceResponse()); | 610 scoped_refptr<ResourceResponse> response(new ResourceResponse()); |
| 588 PopulateResourceResponse(info, request_.get(), response.get()); | 611 PopulateResourceResponse(info, request_.get(), response.get()); |
| 589 | 612 |
| 590 if (request_->ssl_info().cert.get()) { | 613 if (request_->ssl_info().cert.get()) { |
| 591 SSLStatus ssl_status; | 614 SSLStatus ssl_status; |
| 592 GetSSLStatusForRequest(request_->url(), request_->ssl_info(), | 615 GetSSLStatusForRequest(request_->url(), request_->ssl_info(), |
| 593 info->GetChildID(), &ssl_status); | 616 info->GetChildID(), &ssl_status); |
| 594 | 617 |
| 595 response->head.security_info = SerializeSecurityInfo(ssl_status); | 618 response->head.security_info = SerializeSecurityInfo(ssl_status); |
| 596 } else { | 619 } else { |
| 597 // We should not have any SSL state. | 620 // We should not have any SSL state. |
| 598 DCHECK(!request_->ssl_info().cert_status && | 621 DCHECK(!request_->ssl_info().cert_status && |
| 599 request_->ssl_info().security_bits == -1 && | 622 request_->ssl_info().security_bits == -1 && |
| 600 !request_->ssl_info().connection_status); | 623 !request_->ssl_info().connection_status); |
| 601 } | 624 } |
| 602 | 625 |
| 603 delegate_->DidReceiveResponse(this); | 626 delegate_->DidReceiveResponse(this); |
| 604 | 627 |
| 605 // TODO(darin): Remove ScopedTracker below once crbug.com/475761 is fixed. | 628 // TODO(darin): Remove ScopedTracker below once crbug.com/475761 is fixed. |
| 606 tracked_objects::ScopedTracker tracking_profile( | 629 tracked_objects::ScopedTracker tracking_profile( |
| 607 FROM_HERE_WITH_EXPLICIT_FUNCTION("475761 OnResponseStarted()")); | 630 FROM_HERE_WITH_EXPLICIT_FUNCTION("475761 OnResponseStarted()")); |
| 608 | 631 |
| 609 bool defer = false; | 632 bool defer = false; |
| 610 if (!handler_->OnResponseStarted(response.get(), &defer)) { | 633 if (!handler_->OnResponseStarted(response.get(), &defer)) { |
| 611 Cancel(); | 634 Cancel(); |
| 612 } else if (defer) { | 635 } else if (defer) { |
| 613 read_deferral_start_time_ = base::TimeTicks::Now(); | 636 read_deferral_start_time_ = base::TimeTicks::Now(); |
| 614 deferred_stage_ = DEFERRED_READ; // Read first chunk when resumed. | 637 // Complete when resumed for redirect responses, otherwise read first chunk. |
| 638 deferred_stage_ = | |
| 639 is_redirect_response ? DEFERRED_RESPONSE_COMPLETE : DEFERRED_READ; | |
|
mmenke
2015/08/11 18:48:56
In this new path, we skip both OnWillRead and OnRe
| |
| 615 } | 640 } |
| 616 } | 641 } |
| 617 | 642 |
| 618 void ResourceLoader::StartReading(bool is_continuation) { | 643 void ResourceLoader::StartReading(bool is_continuation) { |
| 619 int bytes_read = 0; | 644 int bytes_read = 0; |
| 620 ReadMore(&bytes_read); | 645 ReadMore(&bytes_read); |
| 621 | 646 |
| 622 // If IO is pending, wait for the URLRequest to call OnReadCompleted. | 647 // If IO is pending, wait for the URLRequest to call OnReadCompleted. |
| 623 if (request_->status().is_io_pending()) | 648 if (request_->status().is_io_pending()) |
| 624 return; | 649 return; |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 764 case net::URLRequestStatus::FAILED: | 789 case net::URLRequestStatus::FAILED: |
| 765 status = STATUS_UNDEFINED; | 790 status = STATUS_UNDEFINED; |
| 766 break; | 791 break; |
| 767 } | 792 } |
| 768 | 793 |
| 769 UMA_HISTOGRAM_ENUMERATION("Net.Prefetch.Pattern", status, STATUS_MAX); | 794 UMA_HISTOGRAM_ENUMERATION("Net.Prefetch.Pattern", status, STATUS_MAX); |
| 770 } | 795 } |
| 771 } | 796 } |
| 772 | 797 |
| 773 } // namespace content | 798 } // namespace content |
| OLD | NEW |