| 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 <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/trace_event/trace_event.h" |
| 9 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| 10 #include "base/location.h" | 11 #include "base/location.h" |
| 11 #include "base/metrics/histogram.h" | 12 #include "base/metrics/histogram.h" |
| 12 #include "base/profiler/scoped_tracker.h" | 13 #include "base/profiler/scoped_tracker.h" |
| 13 #include "base/single_thread_task_runner.h" | 14 #include "base/single_thread_task_runner.h" |
| 14 #include "base/thread_task_runner_handle.h" | 15 #include "base/thread_task_runner_handle.h" |
| 15 #include "base/time/time.h" | 16 #include "base/time/time.h" |
| 16 #include "content/browser/appcache/appcache_interceptor.h" | 17 #include "content/browser/appcache/appcache_interceptor.h" |
| 17 #include "content/browser/child_process_security_policy_impl.h" | 18 #include "content/browser/child_process_security_policy_impl.h" |
| 18 #include "content/browser/loader/cross_site_resource_handler.h" | 19 #include "content/browser/loader/cross_site_resource_handler.h" |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 59 const int sct_id(sct_store->Store(iter->sct.get(), process_id)); | 60 const int sct_id(sct_store->Store(iter->sct.get(), process_id)); |
| 60 sct_ids->push_back( | 61 sct_ids->push_back( |
| 61 SignedCertificateTimestampIDAndStatus(sct_id, iter->status)); | 62 SignedCertificateTimestampIDAndStatus(sct_id, iter->status)); |
| 62 } | 63 } |
| 63 } | 64 } |
| 64 | 65 |
| 65 void GetSSLStatusForRequest(const GURL& url, | 66 void GetSSLStatusForRequest(const GURL& url, |
| 66 const net::SSLInfo& ssl_info, | 67 const net::SSLInfo& ssl_info, |
| 67 int child_id, | 68 int child_id, |
| 68 SSLStatus* ssl_status) { | 69 SSLStatus* ssl_status) { |
| 70 TRACE_EVENT0("toplevel", "ResourceLoader::GetSSLStatusForRequest"); |
| 71 |
| 69 DCHECK(ssl_info.cert); | 72 DCHECK(ssl_info.cert); |
| 70 | 73 |
| 71 int cert_id = | 74 int cert_id = |
| 72 CertStore::GetInstance()->StoreCert(ssl_info.cert.get(), child_id); | 75 CertStore::GetInstance()->StoreCert(ssl_info.cert.get(), child_id); |
| 73 | 76 |
| 74 SignedCertificateTimestampIDStatusList signed_certificate_timestamp_ids; | 77 SignedCertificateTimestampIDStatusList signed_certificate_timestamp_ids; |
| 75 StoreSignedCertificateTimestamps(ssl_info.signed_certificate_timestamps, | 78 StoreSignedCertificateTimestamps(ssl_info.signed_certificate_timestamps, |
| 76 child_id, &signed_certificate_timestamp_ids); | 79 child_id, &signed_certificate_timestamp_ids); |
| 77 | 80 |
| 78 *ssl_status = SSLStatus(SSLPolicy::GetSecurityStyleForResource( | 81 *ssl_status = SSLStatus(SSLPolicy::GetSecurityStyleForResource( |
| 79 url, cert_id, ssl_info.cert_status), | 82 url, cert_id, ssl_info.cert_status), |
| 80 cert_id, signed_certificate_timestamp_ids, ssl_info); | 83 cert_id, signed_certificate_timestamp_ids, ssl_info); |
| 81 } | 84 } |
| 82 | 85 |
| 83 void PopulateResourceResponse(ResourceRequestInfoImpl* info, | 86 void PopulateResourceResponse(ResourceRequestInfoImpl* info, |
| 84 net::URLRequest* request, | 87 net::URLRequest* request, |
| 85 ResourceResponse* response) { | 88 ResourceResponse* response) { |
| 89 TRACE_EVENT0("toplevel", "ResourceLoader::PopulateResourceResponse"); |
| 86 response->head.request_time = request->request_time(); | 90 response->head.request_time = request->request_time(); |
| 87 response->head.response_time = request->response_time(); | 91 response->head.response_time = request->response_time(); |
| 88 response->head.headers = request->response_headers(); | 92 response->head.headers = request->response_headers(); |
| 89 request->GetCharset(&response->head.charset); | 93 request->GetCharset(&response->head.charset); |
| 90 response->head.content_length = request->GetExpectedContentSize(); | 94 response->head.content_length = request->GetExpectedContentSize(); |
| 91 request->GetMimeType(&response->head.mime_type); | 95 request->GetMimeType(&response->head.mime_type); |
| 92 net::HttpResponseInfo response_info = request->response_info(); | 96 net::HttpResponseInfo response_info = request->response_info(); |
| 93 response->head.was_fetched_via_spdy = response_info.was_fetched_via_spdy; | 97 response->head.was_fetched_via_spdy = response_info.was_fetched_via_spdy; |
| 94 response->head.was_npn_negotiated = response_info.was_npn_negotiated; | 98 response->head.was_npn_negotiated = response_info.was_npn_negotiated; |
| 95 response->head.npn_negotiated_protocol = | 99 response->head.npn_negotiated_protocol = |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 141 is_transferring_(false), | 145 is_transferring_(false), |
| 142 times_cancelled_before_request_start_(0), | 146 times_cancelled_before_request_start_(0), |
| 143 started_request_(false), | 147 started_request_(false), |
| 144 times_cancelled_after_request_start_(0), | 148 times_cancelled_after_request_start_(0), |
| 145 weak_ptr_factory_(this) { | 149 weak_ptr_factory_(this) { |
| 146 request_->set_delegate(this); | 150 request_->set_delegate(this); |
| 147 handler_->SetController(this); | 151 handler_->SetController(this); |
| 148 } | 152 } |
| 149 | 153 |
| 150 ResourceLoader::~ResourceLoader() { | 154 ResourceLoader::~ResourceLoader() { |
| 155 TRACE_EVENT0("toplevel", "ResourceLoader::~ResourceLoader"); |
| 156 |
| 151 if (login_delegate_.get()) | 157 if (login_delegate_.get()) |
| 152 login_delegate_->OnRequestCancelled(); | 158 login_delegate_->OnRequestCancelled(); |
| 153 ssl_client_auth_handler_.reset(); | 159 ssl_client_auth_handler_.reset(); |
| 154 | 160 |
| 155 // Run ResourceHandler destructor before we tear-down the rest of our state | 161 // Run ResourceHandler destructor before we tear-down the rest of our state |
| 156 // as the ResourceHandler may want to inspect the URLRequest and other state. | 162 // as the ResourceHandler may want to inspect the URLRequest and other state. |
| 157 handler_.reset(); | 163 { |
| 164 TRACE_EVENT0("toplevel", "ResourceLoader::~ResourceLoader::ResetHandlers"); |
| 165 handler_.reset(); |
| 166 } |
| 158 } | 167 } |
| 159 | 168 |
| 160 void ResourceLoader::StartRequest() { | 169 void ResourceLoader::StartRequest() { |
| 161 if (delegate_->HandleExternalProtocol(this, request_->url())) { | 170 TRACE_EVENT0("toplevel", "ResourceLoader::StartRequest"); |
| 162 CancelAndIgnore(); | 171 |
| 163 return; | 172 { |
| 173 TRACE_EVENT0("toplevel", "ResourceLoaderDelegate::HandleExternalProtocol"); |
| 174 if (delegate_->HandleExternalProtocol(this, request_->url())) { |
| 175 CancelAndIgnore(); |
| 176 return; |
| 177 } |
| 164 } | 178 } |
| 165 | 179 |
| 166 // Give the handler a chance to delay the URLRequest from being started. | 180 // Give the handler a chance to delay the URLRequest from being started. |
| 167 bool defer_start = false; | 181 bool defer_start = false; |
| 168 if (!handler_->OnWillStart(request_->url(), &defer_start)) { | 182 { |
| 169 Cancel(); | 183 TRACE_EVENT0("toplevel", "ResourceHandler::OnWillStart"); |
| 170 return; | 184 if (!handler_->OnWillStart(request_->url(), &defer_start)) { |
| 185 Cancel(); |
| 186 return; |
| 187 } |
| 171 } | 188 } |
| 172 | 189 |
| 173 if (defer_start) { | 190 if (defer_start) { |
| 174 deferred_stage_ = DEFERRED_START; | 191 deferred_stage_ = DEFERRED_START; |
| 175 } else { | 192 } else { |
| 176 StartRequestInternal(); | 193 StartRequestInternal(); |
| 177 } | 194 } |
| 178 } | 195 } |
| 179 | 196 |
| 180 void ResourceLoader::CancelRequest(bool from_renderer) { | 197 void ResourceLoader::CancelRequest(bool from_renderer) { |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 222 ServiceWorkerRequestHandler* handler = | 239 ServiceWorkerRequestHandler* handler = |
| 223 ServiceWorkerRequestHandler::GetHandler(request()); | 240 ServiceWorkerRequestHandler::GetHandler(request()); |
| 224 if (handler) | 241 if (handler) |
| 225 handler->MaybeCompleteCrossSiteTransferInOldProcess(child_id); | 242 handler->MaybeCompleteCrossSiteTransferInOldProcess(child_id); |
| 226 | 243 |
| 227 is_transferring_ = false; | 244 is_transferring_ = false; |
| 228 GetRequestInfo()->cross_site_handler()->ResumeResponse(); | 245 GetRequestInfo()->cross_site_handler()->ResumeResponse(); |
| 229 } | 246 } |
| 230 | 247 |
| 231 ResourceRequestInfoImpl* ResourceLoader::GetRequestInfo() { | 248 ResourceRequestInfoImpl* ResourceLoader::GetRequestInfo() { |
| 249 TRACE_EVENT0("toplevel", "ResourceLoader::GetRequestInfo"); |
| 232 return ResourceRequestInfoImpl::ForRequest(request_.get()); | 250 return ResourceRequestInfoImpl::ForRequest(request_.get()); |
| 233 } | 251 } |
| 234 | 252 |
| 235 void ResourceLoader::ClearLoginDelegate() { | 253 void ResourceLoader::ClearLoginDelegate() { |
| 236 login_delegate_ = NULL; | 254 login_delegate_ = NULL; |
| 237 } | 255 } |
| 238 | 256 |
| 239 void ResourceLoader::OnReceivedRedirect(net::URLRequest* unused, | 257 void ResourceLoader::OnReceivedRedirect(net::URLRequest* unused, |
| 240 const net::RedirectInfo& redirect_info, | 258 const net::RedirectInfo& redirect_info, |
| 241 bool* defer) { | 259 bool* defer) { |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 329 // Give the handler a chance to delay the URLRequest from using the network. | 347 // Give the handler a chance to delay the URLRequest from using the network. |
| 330 if (!handler_->OnBeforeNetworkStart(request_->url(), defer)) { | 348 if (!handler_->OnBeforeNetworkStart(request_->url(), defer)) { |
| 331 Cancel(); | 349 Cancel(); |
| 332 return; | 350 return; |
| 333 } else if (*defer) { | 351 } else if (*defer) { |
| 334 deferred_stage_ = DEFERRED_NETWORK_START; | 352 deferred_stage_ = DEFERRED_NETWORK_START; |
| 335 } | 353 } |
| 336 } | 354 } |
| 337 | 355 |
| 338 void ResourceLoader::OnResponseStarted(net::URLRequest* unused) { | 356 void ResourceLoader::OnResponseStarted(net::URLRequest* unused) { |
| 357 TRACE_EVENT0("toplevel", "ResourceLoader::OnResponseStarted"); |
| 339 DCHECK_EQ(request_.get(), unused); | 358 DCHECK_EQ(request_.get(), unused); |
| 340 | 359 |
| 341 DVLOG(1) << "OnResponseStarted: " << request_->url().spec(); | 360 DVLOG(1) << "OnResponseStarted: " << request_->url().spec(); |
| 342 | 361 |
| 343 if (!request_->status().is_success()) { | 362 if (!request_->status().is_success()) { |
| 344 ResponseCompleted(); | 363 ResponseCompleted(); |
| 345 return; | 364 return; |
| 346 } | 365 } |
| 347 | 366 |
| 348 CompleteResponseStarted(); | 367 CompleteResponseStarted(); |
| 349 | 368 |
| 350 if (is_deferred()) | 369 if (is_deferred()) |
| 351 return; | 370 return; |
| 352 | 371 |
| 353 if (request_->status().is_success()) | 372 if (request_->status().is_success()) |
| 354 StartReading(false); // Read the first chunk. | 373 StartReading(false); // Read the first chunk. |
| 355 else | 374 else |
| 356 ResponseCompleted(); | 375 ResponseCompleted(); |
| 357 } | 376 } |
| 358 | 377 |
| 359 void ResourceLoader::OnReadCompleted(net::URLRequest* unused, int bytes_read) { | 378 void ResourceLoader::OnReadCompleted(net::URLRequest* unused, int bytes_read) { |
| 379 TRACE_EVENT0("toplevel", "ResourceLoader::OnReadCompleted"); |
| 360 DCHECK_EQ(request_.get(), unused); | 380 DCHECK_EQ(request_.get(), unused); |
| 361 DVLOG(1) << "OnReadCompleted: \"" << request_->url().spec() << "\"" | 381 DVLOG(1) << "OnReadCompleted: \"" << request_->url().spec() << "\"" |
| 362 << " bytes_read = " << bytes_read; | 382 << " bytes_read = " << bytes_read; |
| 363 | 383 |
| 364 // bytes_read == -1 always implies an error. | 384 // bytes_read == -1 always implies an error. |
| 365 if (bytes_read == -1 || !request_->status().is_success()) { | 385 if (bytes_read == -1 || !request_->status().is_success()) { |
| 366 ResponseCompleted(); | 386 ResponseCompleted(); |
| 367 return; | 387 return; |
| 368 } | 388 } |
| 369 | 389 |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 470 weak_ptr_factory_.GetWeakPtr())); | 490 weak_ptr_factory_.GetWeakPtr())); |
| 471 break; | 491 break; |
| 472 } | 492 } |
| 473 } | 493 } |
| 474 | 494 |
| 475 void ResourceLoader::Cancel() { | 495 void ResourceLoader::Cancel() { |
| 476 CancelRequest(false); | 496 CancelRequest(false); |
| 477 } | 497 } |
| 478 | 498 |
| 479 void ResourceLoader::StartRequestInternal() { | 499 void ResourceLoader::StartRequestInternal() { |
| 500 TRACE_EVENT0("toplevel", "ResourceDispatcherHostImpl::StartRequestInternal"); |
| 480 DCHECK(!request_->is_pending()); | 501 DCHECK(!request_->is_pending()); |
| 481 | 502 |
| 482 if (!request_->status().is_success()) { | 503 if (!request_->status().is_success()) { |
| 483 return; | 504 return; |
| 484 } | 505 } |
| 485 | 506 |
| 486 started_request_ = true; | 507 started_request_ = true; |
| 487 request_->Start(); | 508 request_->Start(); |
| 488 | 509 |
| 489 delegate_->DidStartRequest(this); | 510 delegate_->DidStartRequest(this); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 529 // If the request isn't in flight, then we won't get an asynchronous | 550 // If the request isn't in flight, then we won't get an asynchronous |
| 530 // notification from the request, so we have to signal ourselves to finish | 551 // notification from the request, so we have to signal ourselves to finish |
| 531 // this request. | 552 // this request. |
| 532 base::ThreadTaskRunnerHandle::Get()->PostTask( | 553 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 533 FROM_HERE, base::Bind(&ResourceLoader::ResponseCompleted, | 554 FROM_HERE, base::Bind(&ResourceLoader::ResponseCompleted, |
| 534 weak_ptr_factory_.GetWeakPtr())); | 555 weak_ptr_factory_.GetWeakPtr())); |
| 535 } | 556 } |
| 536 } | 557 } |
| 537 | 558 |
| 538 void ResourceLoader::CompleteResponseStarted() { | 559 void ResourceLoader::CompleteResponseStarted() { |
| 560 TRACE_EVENT0("toplevel", "ResourceLoader::CompleteResponseStarted"); |
| 539 ResourceRequestInfoImpl* info = GetRequestInfo(); | 561 ResourceRequestInfoImpl* info = GetRequestInfo(); |
| 540 scoped_refptr<ResourceResponse> response(new ResourceResponse()); | 562 scoped_refptr<ResourceResponse> response(new ResourceResponse()); |
| 541 PopulateResourceResponse(info, request_.get(), response.get()); | 563 PopulateResourceResponse(info, request_.get(), response.get()); |
| 542 | 564 |
| 543 delegate_->DidReceiveResponse(this); | 565 delegate_->DidReceiveResponse(this); |
| 544 | 566 |
| 545 // TODO(darin): Remove ScopedTracker below once crbug.com/475761 is fixed. | 567 // TODO(darin): Remove ScopedTracker below once crbug.com/475761 is fixed. |
| 546 tracked_objects::ScopedTracker tracking_profile( | 568 tracked_objects::ScopedTracker tracking_profile( |
| 547 FROM_HERE_WITH_EXPLICIT_FUNCTION("475761 OnResponseStarted()")); | 569 FROM_HERE_WITH_EXPLICIT_FUNCTION("475761 OnResponseStarted()")); |
| 548 | 570 |
| 549 bool defer = false; | 571 bool defer = false; |
| 550 if (!handler_->OnResponseStarted(response.get(), &defer)) { | 572 bool ok; |
| 573 { |
| 574 TRACE_EVENT0("toplevel", "ResourceHandler::OnResponseStarted"); |
| 575 ok = handler_->OnResponseStarted(response.get(), &defer); |
| 576 } |
| 577 if (!ok) { |
| 551 Cancel(); | 578 Cancel(); |
| 552 } else if (defer) { | 579 } else if (defer) { |
| 553 read_deferral_start_time_ = base::TimeTicks::Now(); | 580 read_deferral_start_time_ = base::TimeTicks::Now(); |
| 554 deferred_stage_ = DEFERRED_READ; // Read first chunk when resumed. | 581 deferred_stage_ = DEFERRED_READ; // Read first chunk when resumed. |
| 555 } | 582 } |
| 556 } | 583 } |
| 557 | 584 |
| 558 void ResourceLoader::StartReading(bool is_continuation) { | 585 void ResourceLoader::StartReading(bool is_continuation) { |
| 586 TRACE_EVENT0("toplevel", "ResourceLoader::StartReading"); |
| 559 int bytes_read = 0; | 587 int bytes_read = 0; |
| 560 ReadMore(&bytes_read); | 588 ReadMore(&bytes_read); |
| 561 | 589 |
| 562 // If IO is pending, wait for the URLRequest to call OnReadCompleted. | 590 // If IO is pending, wait for the URLRequest to call OnReadCompleted. |
| 563 if (request_->status().is_io_pending()) | 591 if (request_->status().is_io_pending()) |
| 564 return; | 592 return; |
| 565 | 593 |
| 566 if (!is_continuation || bytes_read <= 0) { | 594 if (!is_continuation || bytes_read <= 0) { |
| 567 OnReadCompleted(request_.get(), bytes_read); | 595 OnReadCompleted(request_.get(), bytes_read); |
| 568 } else { | 596 } else { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 584 read_deferral_start_time_ = base::TimeTicks(); | 612 read_deferral_start_time_ = base::TimeTicks(); |
| 585 } | 613 } |
| 586 if (request_->status().is_success()) { | 614 if (request_->status().is_success()) { |
| 587 StartReading(false); // Read the next chunk (OK to complete synchronously). | 615 StartReading(false); // Read the next chunk (OK to complete synchronously). |
| 588 } else { | 616 } else { |
| 589 ResponseCompleted(); | 617 ResponseCompleted(); |
| 590 } | 618 } |
| 591 } | 619 } |
| 592 | 620 |
| 593 void ResourceLoader::ReadMore(int* bytes_read) { | 621 void ResourceLoader::ReadMore(int* bytes_read) { |
| 622 TRACE_EVENT0("toplevel", "ResourceLoader::ReadMore"); |
| 623 |
| 594 DCHECK(!is_deferred()); | 624 DCHECK(!is_deferred()); |
| 595 | 625 |
| 596 // Make sure we track the buffer in at least one place. This ensures it gets | 626 // Make sure we track the buffer in at least one place. This ensures it gets |
| 597 // deleted even in the case the request has already finished its job and | 627 // deleted even in the case the request has already finished its job and |
| 598 // doesn't use the buffer. | 628 // doesn't use the buffer. |
| 599 scoped_refptr<net::IOBuffer> buf; | 629 scoped_refptr<net::IOBuffer> buf; |
| 600 int buf_size; | 630 int buf_size; |
| 601 { | 631 { |
| 602 // TODO(darin): Remove ScopedTracker below once crbug.com/475761 is fixed. | 632 // TODO(darin): Remove ScopedTracker below once crbug.com/475761 is fixed. |
| 603 tracked_objects::ScopedTracker tracking_profile2( | 633 tracked_objects::ScopedTracker tracking_profile2( |
| 604 FROM_HERE_WITH_EXPLICIT_FUNCTION("475761 OnWillRead()")); | 634 FROM_HERE_WITH_EXPLICIT_FUNCTION("475761 OnWillRead()")); |
| 605 | 635 |
| 606 if (!handler_->OnWillRead(&buf, &buf_size, -1)) { | 636 { |
| 607 Cancel(); | 637 TRACE_EVENT0("toplevel", "ResourceHandler::OnWillRead"); |
| 608 return; | 638 |
| 639 if (!handler_->OnWillRead(&buf, &buf_size, -1)) { |
| 640 Cancel(); |
| 641 return; |
| 642 } |
| 609 } | 643 } |
| 610 } | 644 } |
| 611 | 645 |
| 612 DCHECK(buf.get()); | 646 DCHECK(buf.get()); |
| 613 DCHECK(buf_size > 0); | 647 DCHECK(buf_size > 0); |
| 614 | 648 |
| 615 request_->Read(buf.get(), buf_size, bytes_read); | 649 request_->Read(buf.get(), buf_size, bytes_read); |
| 616 | 650 |
| 617 // No need to check the return value here as we'll detect errors by | 651 // No need to check the return value here as we'll detect errors by |
| 618 // inspecting the URLRequest's status. | 652 // inspecting the URLRequest's status. |
| 619 } | 653 } |
| 620 | 654 |
| 621 void ResourceLoader::CompleteRead(int bytes_read) { | 655 void ResourceLoader::CompleteRead(int bytes_read) { |
| 656 TRACE_EVENT0("toplevel", "ResourceLoader::CompleteRead"); |
| 622 DCHECK(bytes_read >= 0); | 657 DCHECK(bytes_read >= 0); |
| 623 DCHECK(request_->status().is_success()); | 658 DCHECK(request_->status().is_success()); |
| 624 | 659 |
| 625 // TODO(darin): Remove ScopedTracker below once crbug.com/475761 is fixed. | 660 // TODO(darin): Remove ScopedTracker below once crbug.com/475761 is fixed. |
| 626 tracked_objects::ScopedTracker tracking_profile( | 661 tracked_objects::ScopedTracker tracking_profile( |
| 627 FROM_HERE_WITH_EXPLICIT_FUNCTION("475761 OnReadCompleted()")); | 662 FROM_HERE_WITH_EXPLICIT_FUNCTION("475761 OnReadCompleted()")); |
| 628 | 663 |
| 629 bool defer = false; | 664 bool defer = false; |
| 630 if (!handler_->OnReadCompleted(bytes_read, &defer)) { | 665 if (!handler_->OnReadCompleted(bytes_read, &defer)) { |
| 631 Cancel(); | 666 Cancel(); |
| 632 } else if (defer) { | 667 } else if (defer) { |
| 633 deferred_stage_ = | 668 deferred_stage_ = |
| 634 bytes_read > 0 ? DEFERRED_READ : DEFERRED_RESPONSE_COMPLETE; | 669 bytes_read > 0 ? DEFERRED_READ : DEFERRED_RESPONSE_COMPLETE; |
| 635 } | 670 } |
| 636 | 671 |
| 637 // Note: the request may still have been cancelled while OnReadCompleted | 672 // Note: the request may still have been cancelled while OnReadCompleted |
| 638 // returns true if OnReadCompleted caused request to get cancelled | 673 // returns true if OnReadCompleted caused request to get cancelled |
| 639 // out-of-band. (In AwResourceDispatcherHostDelegate::DownloadStarting, for | 674 // out-of-band. (In AwResourceDispatcherHostDelegate::DownloadStarting, for |
| 640 // instance.) | 675 // instance.) |
| 641 } | 676 } |
| 642 | 677 |
| 643 void ResourceLoader::ResponseCompleted() { | 678 void ResourceLoader::ResponseCompleted() { |
| 679 TRACE_EVENT0("toplevel", "ResourceLoader::ResponseCompleted"); |
| 644 DVLOG(1) << "ResponseCompleted: " << request_->url().spec(); | 680 DVLOG(1) << "ResponseCompleted: " << request_->url().spec(); |
| 645 RecordHistograms(); | 681 RecordHistograms(); |
| 646 ResourceRequestInfoImpl* info = GetRequestInfo(); | 682 ResourceRequestInfoImpl* info = GetRequestInfo(); |
| 647 | 683 |
| 648 std::string security_info; | 684 std::string security_info; |
| 649 const net::SSLInfo& ssl_info = request_->ssl_info(); | 685 const net::SSLInfo& ssl_info = request_->ssl_info(); |
| 650 if (ssl_info.cert.get() != NULL) { | 686 if (ssl_info.cert.get() != NULL) { |
| 651 SSLStatus ssl_status; | 687 SSLStatus ssl_status; |
| 652 GetSSLStatusForRequest(request_->url(), ssl_info, info->GetChildID(), | 688 GetSSLStatusForRequest(request_->url(), ssl_info, info->GetChildID(), |
| 653 &ssl_status); | 689 &ssl_status); |
| 654 | 690 |
| 655 security_info = SerializeSecurityInfo(ssl_status); | 691 security_info = SerializeSecurityInfo(ssl_status); |
| 656 } | 692 } |
| 657 | 693 |
| 658 bool defer = false; | 694 bool defer = false; |
| 659 { | 695 { |
| 660 // TODO(darin): Remove ScopedTracker below once crbug.com/475761 is fixed. | 696 // TODO(darin): Remove ScopedTracker below once crbug.com/475761 is fixed. |
| 661 tracked_objects::ScopedTracker tracking_profile( | 697 tracked_objects::ScopedTracker tracking_profile( |
| 662 FROM_HERE_WITH_EXPLICIT_FUNCTION("475761 OnResponseCompleted()")); | 698 FROM_HERE_WITH_EXPLICIT_FUNCTION("475761 OnResponseCompleted()")); |
| 663 | 699 |
| 664 handler_->OnResponseCompleted(request_->status(), security_info, &defer); | 700 { |
| 701 TRACE_EVENT0("toplevel", "ResourceHandler::OnResponseCompleted"); |
| 702 handler_->OnResponseCompleted(request_->status(), security_info, &defer); |
| 703 } |
| 665 } | 704 } |
| 666 if (defer) { | 705 if (defer) { |
| 667 // The handler is not ready to die yet. We will call DidFinishLoading when | 706 // The handler is not ready to die yet. We will call DidFinishLoading when |
| 668 // we resume. | 707 // we resume. |
| 669 deferred_stage_ = DEFERRED_FINISH; | 708 deferred_stage_ = DEFERRED_FINISH; |
| 670 } else { | 709 } else { |
| 671 // This will result in our destruction. | 710 // This will result in our destruction. |
| 672 CallDidFinishLoading(); | 711 CallDidFinishLoading(); |
| 673 } | 712 } |
| 674 } | 713 } |
| 675 | 714 |
| 676 void ResourceLoader::CallDidFinishLoading() { | 715 void ResourceLoader::CallDidFinishLoading() { |
| 716 TRACE_EVENT0("toplevel", "ResourceLoader::CallDidFinishLoading"); |
| 677 delegate_->DidFinishLoading(this); | 717 delegate_->DidFinishLoading(this); |
| 678 } | 718 } |
| 679 | 719 |
| 680 void ResourceLoader::RecordHistograms() { | 720 void ResourceLoader::RecordHistograms() { |
| 681 if (request_->response_info().network_accessed) { | 721 if (request_->response_info().network_accessed) { |
| 682 UMA_HISTOGRAM_ENUMERATION("Net.HttpResponseInfo.ConnectionInfo", | 722 UMA_HISTOGRAM_ENUMERATION("Net.HttpResponseInfo.ConnectionInfo", |
| 683 request_->response_info().connection_info, | 723 request_->response_info().connection_info, |
| 684 net::HttpResponseInfo::NUM_OF_CONNECTION_INFOS); | 724 net::HttpResponseInfo::NUM_OF_CONNECTION_INFOS); |
| 685 } | 725 } |
| 686 | 726 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 710 case net::URLRequestStatus::FAILED: | 750 case net::URLRequestStatus::FAILED: |
| 711 status = STATUS_UNDEFINED; | 751 status = STATUS_UNDEFINED; |
| 712 break; | 752 break; |
| 713 } | 753 } |
| 714 | 754 |
| 715 UMA_HISTOGRAM_ENUMERATION("Net.Prefetch.Pattern", status, STATUS_MAX); | 755 UMA_HISTOGRAM_ENUMERATION("Net.Prefetch.Pattern", status, STATUS_MAX); |
| 716 } | 756 } |
| 717 } | 757 } |
| 718 | 758 |
| 719 } // namespace content | 759 } // namespace content |
| OLD | NEW |