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

Side by Side Diff: content/browser/renderer_host/resource_dispatcher_host_impl.cc

Issue 11270027: Add a ResourceScheduler to ResourceDispatcherHost. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 1 month 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 | Annotate | Revision Log
OLDNEW
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 // See http://dev.chromium.org/developers/design-documents/multi-process-resourc e-loading 5 // See http://dev.chromium.org/developers/design-documents/multi-process-resourc e-loading
6 6
7 #include "content/browser/renderer_host/resource_dispatcher_host_impl.h" 7 #include "content/browser/renderer_host/resource_dispatcher_host_impl.h"
8 8
9 #include <set> 9 #include <set>
10 #include <vector> 10 #include <vector>
(...skipping 20 matching lines...) Expand all
31 #include "content/browser/fileapi/chrome_blob_storage_context.h" 31 #include "content/browser/fileapi/chrome_blob_storage_context.h"
32 #include "content/browser/plugin_service_impl.h" 32 #include "content/browser/plugin_service_impl.h"
33 #include "content/browser/renderer_host/async_resource_handler.h" 33 #include "content/browser/renderer_host/async_resource_handler.h"
34 #include "content/browser/renderer_host/buffered_resource_handler.h" 34 #include "content/browser/renderer_host/buffered_resource_handler.h"
35 #include "content/browser/renderer_host/cross_site_resource_handler.h" 35 #include "content/browser/renderer_host/cross_site_resource_handler.h"
36 #include "content/browser/renderer_host/redirect_to_file_resource_handler.h" 36 #include "content/browser/renderer_host/redirect_to_file_resource_handler.h"
37 #include "content/browser/renderer_host/render_view_host_delegate.h" 37 #include "content/browser/renderer_host/render_view_host_delegate.h"
38 #include "content/browser/renderer_host/render_view_host_impl.h" 38 #include "content/browser/renderer_host/render_view_host_impl.h"
39 #include "content/browser/renderer_host/resource_message_filter.h" 39 #include "content/browser/renderer_host/resource_message_filter.h"
40 #include "content/browser/renderer_host/resource_request_info_impl.h" 40 #include "content/browser/renderer_host/resource_request_info_impl.h"
41 #include "content/browser/renderer_host/resource_scheduler.h"
41 #include "content/browser/renderer_host/sync_resource_handler.h" 42 #include "content/browser/renderer_host/sync_resource_handler.h"
42 #include "content/browser/renderer_host/throttling_resource_handler.h" 43 #include "content/browser/renderer_host/throttling_resource_handler.h"
43 #include "content/browser/renderer_host/transfer_navigation_resource_throttle.h" 44 #include "content/browser/renderer_host/transfer_navigation_resource_throttle.h"
44 #include "content/browser/resource_context_impl.h" 45 #include "content/browser/resource_context_impl.h"
45 #include "content/browser/worker_host/worker_service_impl.h" 46 #include "content/browser/worker_host/worker_service_impl.h"
46 #include "content/common/resource_messages.h" 47 #include "content/common/resource_messages.h"
47 #include "content/common/ssl_status_serialization.h" 48 #include "content/common/ssl_status_serialization.h"
48 #include "content/common/view_messages.h" 49 #include "content/common/view_messages.h"
49 #include "content/public/browser/browser_thread.h" 50 #include "content/public/browser/browser_thread.h"
50 #include "content/public/browser/content_browser_client.h" 51 #include "content/public/browser/content_browser_client.h"
(...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after
351 } 352 }
352 353
353 ResourceDispatcherHostImpl::ResourceDispatcherHostImpl() 354 ResourceDispatcherHostImpl::ResourceDispatcherHostImpl()
354 : save_file_manager_(new SaveFileManager()), 355 : save_file_manager_(new SaveFileManager()),
355 request_id_(-1), 356 request_id_(-1),
356 is_shutdown_(false), 357 is_shutdown_(false),
357 max_outstanding_requests_cost_per_process_( 358 max_outstanding_requests_cost_per_process_(
358 kMaxOutstandingRequestsCostPerProcess), 359 kMaxOutstandingRequestsCostPerProcess),
359 filter_(NULL), 360 filter_(NULL),
360 delegate_(NULL), 361 delegate_(NULL),
361 allow_cross_origin_auth_prompt_(false) { 362 allow_cross_origin_auth_prompt_(false),
363 resource_scheduler_(new ResourceScheduler()) {
362 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 364 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
363 DCHECK(!g_resource_dispatcher_host); 365 DCHECK(!g_resource_dispatcher_host);
364 g_resource_dispatcher_host = this; 366 g_resource_dispatcher_host = this;
365 367
366 GetContentClient()->browser()->ResourceDispatcherHostCreated(); 368 GetContentClient()->browser()->ResourceDispatcherHostCreated();
367 369
368 ANNOTATE_BENIGN_RACE( 370 ANNOTATE_BENIGN_RACE(
369 &last_user_gesture_time_, 371 &last_user_gesture_time_,
370 "We don't care about the precise value, see http://crbug.com/92889"); 372 "We don't care about the precise value, see http://crbug.com/92889");
371 373
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
410 ResourceContext* context) { 412 ResourceContext* context) {
411 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 413 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
412 DCHECK(context); 414 DCHECK(context);
413 415
414 CHECK(ContainsKey(active_resource_contexts_, context)); 416 CHECK(ContainsKey(active_resource_contexts_, context));
415 417
416 // Note that request cancellation has side effects. Therefore, we gather all 418 // Note that request cancellation has side effects. Therefore, we gather all
417 // the requests to cancel first, and then we start cancelling. We assert at 419 // the requests to cancel first, and then we start cancelling. We assert at
418 // the end that there are no more to cancel since the context is about to go 420 // the end that there are no more to cancel since the context is about to go
419 // away. 421 // away.
420 typedef std::vector<linked_ptr<ResourceLoader> > LoaderList; 422 typedef std::vector<linked_ptr<ResourceLoaderImpl> > LoaderList;
421 LoaderList loaders_to_cancel; 423 LoaderList loaders_to_cancel;
422 424
423 for (LoaderMap::iterator i = pending_loaders_.begin(); 425 for (LoaderMap::iterator i = pending_loaders_.begin();
424 i != pending_loaders_.end();) { 426 i != pending_loaders_.end();) {
425 if (i->second->GetRequestInfo()->GetContext() == context) { 427 if (i->second->GetRequestInfo()->GetContext() == context) {
426 loaders_to_cancel.push_back(i->second); 428 loaders_to_cancel.push_back(i->second);
427 pending_loaders_.erase(i++); 429 pending_loaders_.erase(i++);
428 } else { 430 } else {
429 ++i; 431 ++i;
430 } 432 }
431 } 433 }
432 434
433 for (BlockedLoadersMap::iterator i = blocked_loaders_map_.begin(); 435 for (BlockedLoadersMap::iterator i = blocked_loaders_map_.begin();
434 i != blocked_loaders_map_.end();) { 436 i != blocked_loaders_map_.end();) {
435 BlockedLoadersList* loaders = i->second; 437 BlockedLoadersList* loaders = i->second;
436 if (loaders->empty()) { 438 if (loaders->empty()) {
437 // This can happen if BlockRequestsForRoute() has been called for a route, 439 // This can happen if BlockRequestsForRoute() has been called for a route,
438 // but we haven't blocked any matching requests yet. 440 // but we haven't blocked any matching requests yet.
439 ++i; 441 ++i;
440 continue; 442 continue;
441 } 443 }
442 ResourceRequestInfoImpl* info = loaders->front()->GetRequestInfo(); 444 ResourceRequestInfoImpl* info = loaders->front()->GetRequestInfo();
443 if (info->GetContext() == context) { 445 if (info->GetContext() == context) {
444 blocked_loaders_map_.erase(i++); 446 blocked_loaders_map_.erase(i++);
445 for (BlockedLoadersList::const_iterator it = loaders->begin(); 447 for (BlockedLoadersList::const_iterator it = loaders->begin();
446 it != loaders->end(); ++it) { 448 it != loaders->end(); ++it) {
447 linked_ptr<ResourceLoader> loader = *it; 449 linked_ptr<ResourceLoaderImpl> loader = *it;
448 info = loader->GetRequestInfo(); 450 info = loader->GetRequestInfo();
449 // We make the assumption that all requests on the list have the same 451 // We make the assumption that all requests on the list have the same
450 // ResourceContext. 452 // ResourceContext.
451 DCHECK_EQ(context, info->GetContext()); 453 DCHECK_EQ(context, info->GetContext());
452 IncrementOutstandingRequestsMemoryCost(-1 * info->memory_cost(), 454 IncrementOutstandingRequestsMemoryCost(-1 * info->memory_cost(),
453 info->GetChildID()); 455 info->GetChildID());
454 loaders_to_cancel.push_back(loader); 456 loaders_to_cancel.push_back(loader);
455 } 457 }
456 delete loaders; 458 delete loaders;
457 } else { 459 } else {
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
555 557
556 BeginRequestInternal(request.Pass(), handler.Pass()); 558 BeginRequestInternal(request.Pass(), handler.Pass());
557 559
558 return net::OK; 560 return net::OK;
559 } 561 }
560 562
561 void ResourceDispatcherHostImpl::ClearLoginDelegateForRequest( 563 void ResourceDispatcherHostImpl::ClearLoginDelegateForRequest(
562 net::URLRequest* request) { 564 net::URLRequest* request) {
563 ResourceRequestInfoImpl* info = ResourceRequestInfoImpl::ForRequest(request); 565 ResourceRequestInfoImpl* info = ResourceRequestInfoImpl::ForRequest(request);
564 if (info) { 566 if (info) {
565 ResourceLoader* loader = GetLoader(info->GetGlobalRequestID()); 567 ResourceLoaderImpl* loader = GetLoader(info->GetGlobalRequestID());
566 if (loader) 568 if (loader)
567 loader->ClearLoginDelegate(); 569 loader->ClearLoginDelegate();
568 } 570 }
569 } 571 }
570 572
571 void ResourceDispatcherHostImpl::Shutdown() { 573 void ResourceDispatcherHostImpl::Shutdown() {
572 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 574 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
573 BrowserThread::PostTask(BrowserThread::IO, 575 BrowserThread::PostTask(BrowserThread::IO,
574 FROM_HERE, 576 FROM_HERE,
575 base::Bind(&ResourceDispatcherHostImpl::OnShutdown, 577 base::Bind(&ResourceDispatcherHostImpl::OnShutdown,
(...skipping 24 matching lines...) Expand all
600 request_info->GetRequestID(), throttles.Pass())); 602 request_info->GetRequestID(), throttles.Pass()));
601 } 603 }
602 } 604 }
603 return handler.Pass(); 605 return handler.Pass();
604 } 606 }
605 607
606 void ResourceDispatcherHostImpl::ClearSSLClientAuthHandlerForRequest( 608 void ResourceDispatcherHostImpl::ClearSSLClientAuthHandlerForRequest(
607 net::URLRequest* request) { 609 net::URLRequest* request) {
608 ResourceRequestInfoImpl* info = ResourceRequestInfoImpl::ForRequest(request); 610 ResourceRequestInfoImpl* info = ResourceRequestInfoImpl::ForRequest(request);
609 if (info) { 611 if (info) {
610 ResourceLoader* loader = GetLoader(info->GetGlobalRequestID()); 612 ResourceLoaderImpl* loader = GetLoader(info->GetGlobalRequestID());
611 if (loader) 613 if (loader)
612 loader->ClearSSLClientAuthHandler(); 614 loader->ClearSSLClientAuthHandler();
613 } 615 }
614 } 616 }
615 617
616 ResourceDispatcherHostLoginDelegate* 618 ResourceDispatcherHostLoginDelegate*
617 ResourceDispatcherHostImpl::CreateLoginDelegate( 619 ResourceDispatcherHostImpl::CreateLoginDelegate(
618 ResourceLoader* loader, 620 ResourceLoaderImpl* loader,
619 net::AuthChallengeInfo* auth_info) { 621 net::AuthChallengeInfo* auth_info) {
620 if (!delegate_) 622 if (!delegate_)
621 return NULL; 623 return NULL;
622 624
623 return delegate_->CreateLoginDelegate(auth_info, loader->request()); 625 return delegate_->CreateLoginDelegate(auth_info, loader->request());
624 } 626 }
625 627
626 bool ResourceDispatcherHostImpl::AcceptAuthRequest( 628 bool ResourceDispatcherHostImpl::AcceptAuthRequest(
627 ResourceLoader* loader, 629 ResourceLoaderImpl* loader,
628 net::AuthChallengeInfo* auth_info) { 630 net::AuthChallengeInfo* auth_info) {
629 if (delegate_ && !delegate_->AcceptAuthRequest(loader->request(), auth_info)) 631 if (delegate_ && !delegate_->AcceptAuthRequest(loader->request(), auth_info))
630 return false; 632 return false;
631 633
632 // Prevent third-party content from prompting for login, unless it is 634 // Prevent third-party content from prompting for login, unless it is
633 // a proxy that is trying to authenticate. This is often the foundation 635 // a proxy that is trying to authenticate. This is often the foundation
634 // of a scam to extract credentials for another domain from the user. 636 // of a scam to extract credentials for another domain from the user.
635 if (!auth_info->is_proxy) { 637 if (!auth_info->is_proxy) {
636 HttpAuthResourceType resource_type = 638 HttpAuthResourceType resource_type =
637 HttpAuthResourceTypeOf(loader->request()); 639 HttpAuthResourceTypeOf(loader->request());
638 UMA_HISTOGRAM_ENUMERATION("Net.HttpAuthResource", 640 UMA_HISTOGRAM_ENUMERATION("Net.HttpAuthResource",
639 resource_type, 641 resource_type,
640 HTTP_AUTH_RESOURCE_LAST); 642 HTTP_AUTH_RESOURCE_LAST);
641 643
642 if (resource_type == HTTP_AUTH_RESOURCE_BLOCKED_CROSS) 644 if (resource_type == HTTP_AUTH_RESOURCE_BLOCKED_CROSS)
643 return false; 645 return false;
644 } 646 }
645 647
646 return true; 648 return true;
647 } 649 }
648 650
649 bool ResourceDispatcherHostImpl::AcceptSSLClientCertificateRequest( 651 bool ResourceDispatcherHostImpl::AcceptSSLClientCertificateRequest(
650 ResourceLoader* loader, 652 ResourceLoaderImpl* loader,
651 net::SSLCertRequestInfo* cert_info) { 653 net::SSLCertRequestInfo* cert_info) {
652 if (delegate_ && !delegate_->AcceptSSLClientCertificateRequest( 654 if (delegate_ && !delegate_->AcceptSSLClientCertificateRequest(
653 loader->request(), cert_info)) { 655 loader->request(), cert_info)) {
654 return false; 656 return false;
655 } 657 }
656 658
657 return true; 659 return true;
658 } 660 }
659 661
660 bool ResourceDispatcherHostImpl::HandleExternalProtocol(ResourceLoader* loader, 662 bool ResourceDispatcherHostImpl::HandleExternalProtocol(
661 const GURL& url) { 663 ResourceLoaderImpl* loader,
664 const GURL& url) {
662 if (!delegate_) 665 if (!delegate_)
663 return false; 666 return false;
664 667
665 ResourceRequestInfoImpl* info = loader->GetRequestInfo(); 668 ResourceRequestInfoImpl* info = loader->GetRequestInfo();
666 669
667 if (!ResourceType::IsFrame(info->GetResourceType())) 670 if (!ResourceType::IsFrame(info->GetResourceType()))
668 return false; 671 return false;
669 672
670 const net::URLRequestJobFactory* job_factory = 673 const net::URLRequestJobFactory* job_factory =
671 info->GetContext()->GetRequestContext()->job_factory(); 674 info->GetContext()->GetRequestContext()->job_factory();
672 if (job_factory->IsHandledURL(url)) 675 if (job_factory->IsHandledURL(url))
673 return false; 676 return false;
674 677
675 delegate_->HandleExternalProtocol(url, info->GetChildID(), 678 delegate_->HandleExternalProtocol(url, info->GetChildID(),
676 info->GetRouteID()); 679 info->GetRouteID());
677 return true; 680 return true;
678 } 681 }
679 682
680 void ResourceDispatcherHostImpl::DidStartRequest(ResourceLoader* loader) { 683 void ResourceDispatcherHostImpl::DidStartRequest(ResourceLoaderImpl* loader) {
681 // Make sure we have the load state monitor running 684 // Make sure we have the load state monitor running
682 if (!update_load_states_timer_->IsRunning()) { 685 if (!update_load_states_timer_->IsRunning()) {
683 update_load_states_timer_->Start(FROM_HERE, 686 update_load_states_timer_->Start(FROM_HERE,
684 TimeDelta::FromMilliseconds(kUpdateLoadStatesIntervalMsec), 687 TimeDelta::FromMilliseconds(kUpdateLoadStatesIntervalMsec),
685 this, &ResourceDispatcherHostImpl::UpdateLoadStates); 688 this, &ResourceDispatcherHostImpl::UpdateLoadStates);
686 } 689 }
687 } 690 }
688 691
689 void ResourceDispatcherHostImpl::DidReceiveRedirect(ResourceLoader* loader, 692 void ResourceDispatcherHostImpl::DidReceiveRedirect(ResourceLoaderImpl* loader,
690 const GURL& new_url) { 693 const GURL& new_url) {
691 ResourceRequestInfoImpl* info = loader->GetRequestInfo(); 694 ResourceRequestInfoImpl* info = loader->GetRequestInfo();
692 695
693 int render_process_id, render_view_id; 696 int render_process_id, render_view_id;
694 if (!info->GetAssociatedRenderView(&render_process_id, &render_view_id)) 697 if (!info->GetAssociatedRenderView(&render_process_id, &render_view_id))
695 return; 698 return;
696 699
697 // Notify the observers on the UI thread. 700 // Notify the observers on the UI thread.
698 scoped_ptr<ResourceRedirectDetails> detail(new ResourceRedirectDetails( 701 scoped_ptr<ResourceRedirectDetails> detail(new ResourceRedirectDetails(
699 loader->request(), 702 loader->request(),
700 GetCertID(loader->request(), info->GetChildID()), 703 GetCertID(loader->request(), info->GetChildID()),
701 new_url)); 704 new_url));
702 BrowserThread::PostTask( 705 BrowserThread::PostTask(
703 BrowserThread::UI, FROM_HERE, 706 BrowserThread::UI, FROM_HERE,
704 base::Bind( 707 base::Bind(
705 &NotifyOnUI<ResourceRedirectDetails>, 708 &NotifyOnUI<ResourceRedirectDetails>,
706 static_cast<int>(NOTIFICATION_RESOURCE_RECEIVED_REDIRECT), 709 static_cast<int>(NOTIFICATION_RESOURCE_RECEIVED_REDIRECT),
707 render_process_id, render_view_id, base::Passed(&detail))); 710 render_process_id, render_view_id, base::Passed(&detail)));
708 } 711 }
709 712
710 void ResourceDispatcherHostImpl::DidReceiveResponse(ResourceLoader* loader) { 713 void ResourceDispatcherHostImpl::DidReceiveResponse(
714 ResourceLoaderImpl* loader) {
711 ResourceRequestInfoImpl* info = loader->GetRequestInfo(); 715 ResourceRequestInfoImpl* info = loader->GetRequestInfo();
712 716
713 int render_process_id, render_view_id; 717 int render_process_id, render_view_id;
714 if (!info->GetAssociatedRenderView(&render_process_id, &render_view_id)) 718 if (!info->GetAssociatedRenderView(&render_process_id, &render_view_id))
715 return; 719 return;
716 720
717 // Notify the observers on the UI thread. 721 // Notify the observers on the UI thread.
718 scoped_ptr<ResourceRequestDetails> detail(new ResourceRequestDetails( 722 scoped_ptr<ResourceRequestDetails> detail(new ResourceRequestDetails(
719 loader->request(), 723 loader->request(),
720 GetCertID(loader->request(), info->GetChildID()))); 724 GetCertID(loader->request(), info->GetChildID())));
721 BrowserThread::PostTask( 725 BrowserThread::PostTask(
722 BrowserThread::UI, FROM_HERE, 726 BrowserThread::UI, FROM_HERE,
723 base::Bind( 727 base::Bind(
724 &NotifyOnUI<ResourceRequestDetails>, 728 &NotifyOnUI<ResourceRequestDetails>,
725 static_cast<int>(NOTIFICATION_RESOURCE_RESPONSE_STARTED), 729 static_cast<int>(NOTIFICATION_RESOURCE_RESPONSE_STARTED),
726 render_process_id, render_view_id, base::Passed(&detail))); 730 render_process_id, render_view_id, base::Passed(&detail)));
727 } 731 }
728 732
729 void ResourceDispatcherHostImpl::DidFinishLoading(ResourceLoader* loader) { 733 void ResourceDispatcherHostImpl::DidFinishLoading(ResourceLoaderImpl* loader) {
730 ResourceRequestInfo* info = loader->GetRequestInfo(); 734 ResourceRequestInfo* info = loader->GetRequestInfo();
731 735
732 // Record final result of all resource loads. 736 // Record final result of all resource loads.
733 if (info->GetResourceType() == ResourceType::MAIN_FRAME) { 737 if (info->GetResourceType() == ResourceType::MAIN_FRAME) {
734 // This enumeration has "3" appended to its name to distinguish it from 738 // This enumeration has "3" appended to its name to distinguish it from
735 // older versions. 739 // older versions.
736 UMA_HISTOGRAM_CUSTOM_ENUMERATION( 740 UMA_HISTOGRAM_CUSTOM_ENUMERATION(
737 "Net.ErrorCodesForMainFrame3", 741 "Net.ErrorCodesForMainFrame3",
738 -loader->request()->status().error(), 742 -loader->request()->status().error(),
739 base::CustomHistogram::ArrayToCustomRanges( 743 base::CustomHistogram::ArrayToCustomRanges(
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
869 int child_id = filter_->child_id(); 873 int child_id = filter_->child_id();
870 874
871 // If we crash here, figure out what URL the renderer was requesting. 875 // If we crash here, figure out what URL the renderer was requesting.
872 // http://crbug.com/91398 876 // http://crbug.com/91398
873 char url_buf[128]; 877 char url_buf[128];
874 base::strlcpy(url_buf, request_data.url.spec().c_str(), arraysize(url_buf)); 878 base::strlcpy(url_buf, request_data.url.spec().c_str(), arraysize(url_buf));
875 base::debug::Alias(url_buf); 879 base::debug::Alias(url_buf);
876 880
877 // If the request that's coming in is being transferred from another process, 881 // If the request that's coming in is being transferred from another process,
878 // we want to reuse and resume the old loader rather than start a new one. 882 // we want to reuse and resume the old loader rather than start a new one.
879 linked_ptr<ResourceLoader> deferred_loader; 883 linked_ptr<ResourceLoaderImpl> deferred_loader;
880 { 884 {
881 LoaderMap::iterator it = pending_loaders_.find( 885 LoaderMap::iterator it = pending_loaders_.find(
882 GlobalRequestID(request_data.transferred_request_child_id, 886 GlobalRequestID(request_data.transferred_request_child_id,
883 request_data.transferred_request_request_id)); 887 request_data.transferred_request_request_id));
884 if (it != pending_loaders_.end()) { 888 if (it != pending_loaders_.end()) {
885 if (it->second->is_transferring()) { 889 if (it->second->is_transferring()) {
886 deferred_loader = it->second; 890 deferred_loader = it->second;
887 pending_loaders_.erase(it); 891 pending_loaders_.erase(it);
888 } else { 892 } else {
889 RecordAction(UserMetricsAction("BadMessageTerminate_RDH")); 893 RecordAction(UserMetricsAction("BadMessageTerminate_RDH"));
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
1064 } else { 1068 } else {
1065 BeginRequestInternal(new_request.Pass(), handler.Pass()); 1069 BeginRequestInternal(new_request.Pass(), handler.Pass());
1066 } 1070 }
1067 } 1071 }
1068 1072
1069 void ResourceDispatcherHostImpl::OnReleaseDownloadedFile(int request_id) { 1073 void ResourceDispatcherHostImpl::OnReleaseDownloadedFile(int request_id) {
1070 UnregisterDownloadedTempFile(filter_->child_id(), request_id); 1074 UnregisterDownloadedTempFile(filter_->child_id(), request_id);
1071 } 1075 }
1072 1076
1073 void ResourceDispatcherHostImpl::OnDataReceivedACK(int request_id) { 1077 void ResourceDispatcherHostImpl::OnDataReceivedACK(int request_id) {
1074 ResourceLoader* loader = GetLoader(filter_->child_id(), request_id); 1078 ResourceLoaderImpl* loader = GetLoader(filter_->child_id(), request_id);
1075 if (!loader) 1079 if (!loader)
1076 return; 1080 return;
1077 1081
1078 ResourceRequestInfoImpl* info = loader->GetRequestInfo(); 1082 ResourceRequestInfoImpl* info = loader->GetRequestInfo();
1079 if (info->async_handler()) 1083 if (info->async_handler())
1080 info->async_handler()->OnDataReceivedACK(); 1084 info->async_handler()->OnDataReceivedACK();
1081 } 1085 }
1082 1086
1083 void ResourceDispatcherHostImpl::OnDataDownloadedACK(int request_id) { 1087 void ResourceDispatcherHostImpl::OnDataDownloadedACK(int request_id) {
1084 // TODO(michaeln): maybe throttle DataDownloaded messages 1088 // TODO(michaeln): maybe throttle DataDownloaded messages
(...skipping 30 matching lines...) Expand all
1115 // Note that we don't remove the security bits here. This will be done 1119 // Note that we don't remove the security bits here. This will be done
1116 // when all file refs are deleted (see RegisterDownloadedTempFile). 1120 // when all file refs are deleted (see RegisterDownloadedTempFile).
1117 } 1121 }
1118 1122
1119 bool ResourceDispatcherHostImpl::Send(IPC::Message* message) { 1123 bool ResourceDispatcherHostImpl::Send(IPC::Message* message) {
1120 delete message; 1124 delete message;
1121 return false; 1125 return false;
1122 } 1126 }
1123 1127
1124 void ResourceDispatcherHostImpl::OnUploadProgressACK(int request_id) { 1128 void ResourceDispatcherHostImpl::OnUploadProgressACK(int request_id) {
1125 ResourceLoader* loader = GetLoader(filter_->child_id(), request_id); 1129 ResourceLoaderImpl* loader = GetLoader(filter_->child_id(), request_id);
1126 if (loader) 1130 if (loader)
1127 loader->OnUploadProgressACK(); 1131 loader->OnUploadProgressACK();
1128 } 1132 }
1129 1133
1130 void ResourceDispatcherHostImpl::OnCancelRequest(int request_id) { 1134 void ResourceDispatcherHostImpl::OnCancelRequest(int request_id) {
1131 CancelRequest(filter_->child_id(), request_id, true); 1135 CancelRequest(filter_->child_id(), request_id, true);
1132 } 1136 }
1133 1137
1134 void ResourceDispatcherHostImpl::OnFollowRedirect( 1138 void ResourceDispatcherHostImpl::OnFollowRedirect(
1135 int request_id, 1139 int request_id,
1136 bool has_new_first_party_for_cookies, 1140 bool has_new_first_party_for_cookies,
1137 const GURL& new_first_party_for_cookies) { 1141 const GURL& new_first_party_for_cookies) {
1138 ResourceLoader* loader = GetLoader(filter_->child_id(), request_id); 1142 ResourceLoaderImpl* loader = GetLoader(filter_->child_id(), request_id);
1139 if (!loader) { 1143 if (!loader) {
1140 DVLOG(1) << "OnFollowRedirect for invalid request"; 1144 DVLOG(1) << "OnFollowRedirect for invalid request";
1141 return; 1145 return;
1142 } 1146 }
1143 1147
1144 ResourceRequestInfoImpl* info = loader->GetRequestInfo(); 1148 ResourceRequestInfoImpl* info = loader->GetRequestInfo();
1145 if (info->async_handler()) { 1149 if (info->async_handler()) {
1146 info->async_handler()->OnFollowRedirect( 1150 info->async_handler()->OnFollowRedirect(
1147 has_new_first_party_for_cookies, 1151 has_new_first_party_for_cookies,
1148 new_first_party_for_cookies); 1152 new_first_party_for_cookies);
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
1182 void ResourceDispatcherHostImpl::OnSimulateSwapOutACK( 1186 void ResourceDispatcherHostImpl::OnSimulateSwapOutACK(
1183 const ViewMsg_SwapOut_Params& params) { 1187 const ViewMsg_SwapOut_Params& params) {
1184 // Call the real implementation with true, which means that we timed out. 1188 // Call the real implementation with true, which means that we timed out.
1185 HandleSwapOutACK(params, true); 1189 HandleSwapOutACK(params, true);
1186 } 1190 }
1187 1191
1188 void ResourceDispatcherHostImpl::HandleSwapOutACK( 1192 void ResourceDispatcherHostImpl::HandleSwapOutACK(
1189 const ViewMsg_SwapOut_Params& params, bool timed_out) { 1193 const ViewMsg_SwapOut_Params& params, bool timed_out) {
1190 // Closes for cross-site transitions are handled such that the cross-site 1194 // Closes for cross-site transitions are handled such that the cross-site
1191 // transition continues. 1195 // transition continues.
1192 ResourceLoader* loader = GetLoader(params.new_render_process_host_id, 1196 ResourceLoaderImpl* loader = GetLoader(params.new_render_process_host_id,
1193 params.new_request_id); 1197 params.new_request_id);
1194 if (loader) { 1198 if (loader) {
1195 // The response we were meant to resume could have already been canceled. 1199 // The response we were meant to resume could have already been canceled.
1196 ResourceRequestInfoImpl* info = loader->GetRequestInfo(); 1200 ResourceRequestInfoImpl* info = loader->GetRequestInfo();
1197 if (info->cross_site_handler()) 1201 if (info->cross_site_handler())
1198 info->cross_site_handler()->ResumeResponse(); 1202 info->cross_site_handler()->ResumeResponse();
1199 } 1203 }
1200 1204
1201 // Update the RenderViewHost's internal state after the ACK. 1205 // Update the RenderViewHost's internal state after the ACK.
1202 BrowserThread::PostTask( 1206 BrowserThread::PostTask(
1203 BrowserThread::UI, 1207 BrowserThread::UI,
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
1375 1379
1376 void ResourceDispatcherHostImpl::RemovePendingLoader( 1380 void ResourceDispatcherHostImpl::RemovePendingLoader(
1377 const LoaderMap::iterator& iter) { 1381 const LoaderMap::iterator& iter) {
1378 ResourceRequestInfoImpl* info = iter->second->GetRequestInfo(); 1382 ResourceRequestInfoImpl* info = iter->second->GetRequestInfo();
1379 1383
1380 // Remove the memory credit that we added when pushing the request onto 1384 // Remove the memory credit that we added when pushing the request onto
1381 // the pending list. 1385 // the pending list.
1382 IncrementOutstandingRequestsMemoryCost(-1 * info->memory_cost(), 1386 IncrementOutstandingRequestsMemoryCost(-1 * info->memory_cost(),
1383 info->GetChildID()); 1387 info->GetChildID());
1384 1388
1389 resource_scheduler_->RemoveLoad(
1390 info->GetChildID(), info->GetRouteID(), info->GetRequestID());
1385 pending_loaders_.erase(iter); 1391 pending_loaders_.erase(iter);
1386 1392
1387 // If we have no more pending requests, then stop the load state monitor 1393 // If we have no more pending requests, then stop the load state monitor
1388 if (pending_loaders_.empty() && update_load_states_timer_.get()) 1394 if (pending_loaders_.empty() && update_load_states_timer_.get())
1389 update_load_states_timer_->Stop(); 1395 update_load_states_timer_->Stop();
1390 } 1396 }
1391 1397
1392 void ResourceDispatcherHostImpl::CancelRequest(int child_id, 1398 void ResourceDispatcherHostImpl::CancelRequest(int child_id,
1393 int request_id, 1399 int request_id,
1394 bool from_renderer) { 1400 bool from_renderer) {
1395 if (from_renderer) { 1401 if (from_renderer) {
1396 // When the old renderer dies, it sends a message to us to cancel its 1402 // When the old renderer dies, it sends a message to us to cancel its
1397 // requests. 1403 // requests.
1398 if (IsTransferredNavigation(GlobalRequestID(child_id, request_id))) 1404 if (IsTransferredNavigation(GlobalRequestID(child_id, request_id)))
1399 return; 1405 return;
1400 } 1406 }
1401 1407
1402 ResourceLoader* loader = GetLoader(child_id, request_id); 1408 ResourceLoaderImpl* loader = GetLoader(child_id, request_id);
1403 if (!loader) { 1409 if (!loader) {
1404 // We probably want to remove this warning eventually, but I wanted to be 1410 // We probably want to remove this warning eventually, but I wanted to be
1405 // able to notice when this happens during initial development since it 1411 // able to notice when this happens during initial development since it
1406 // should be rare and may indicate a bug. 1412 // should be rare and may indicate a bug.
1407 DVLOG(1) << "Canceling a request that wasn't found"; 1413 DVLOG(1) << "Canceling a request that wasn't found";
1408 return; 1414 return;
1409 } 1415 }
1410 1416
1411 loader->CancelRequest(from_renderer); 1417 loader->CancelRequest(from_renderer);
1412 } 1418 }
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
1480 } 1486 }
1481 1487
1482 IncrementOutstandingRequestsMemoryCost(-1 * info->memory_cost(), 1488 IncrementOutstandingRequestsMemoryCost(-1 * info->memory_cost(),
1483 info->GetChildID()); 1489 info->GetChildID());
1484 1490
1485 // A ResourceHandler must not outlive its associated URLRequest. 1491 // A ResourceHandler must not outlive its associated URLRequest.
1486 handler.reset(); 1492 handler.reset();
1487 return; 1493 return;
1488 } 1494 }
1489 1495
1490 linked_ptr<ResourceLoader> loader( 1496 linked_ptr<ResourceLoaderImpl> loader(
1491 new ResourceLoader(request.Pass(), handler.Pass(), this)); 1497 new ResourceLoaderImpl(request.Pass(), handler.Pass(), this));
1492 1498
1493 ProcessRouteIDs pair_id(info->GetChildID(), info->GetRouteID()); 1499 ProcessRouteIDs pair_id(info->GetChildID(), info->GetRouteID());
1494 BlockedLoadersMap::const_iterator iter = blocked_loaders_map_.find(pair_id); 1500 BlockedLoadersMap::const_iterator iter = blocked_loaders_map_.find(pair_id);
1495 if (iter != blocked_loaders_map_.end()) { 1501 if (iter != blocked_loaders_map_.end()) {
1496 // The request should be blocked. 1502 // The request should be blocked.
1497 iter->second->push_back(loader); 1503 iter->second->push_back(loader);
1498 return; 1504 return;
1499 } 1505 }
1500 1506
1501 StartLoading(info, loader); 1507 StartLoading(info, loader);
1502 } 1508 }
1503 1509
1504 void ResourceDispatcherHostImpl::StartLoading( 1510 void ResourceDispatcherHostImpl::StartLoading(
1505 ResourceRequestInfoImpl* info, 1511 ResourceRequestInfoImpl* info,
1506 const linked_ptr<ResourceLoader>& loader) { 1512 const linked_ptr<ResourceLoaderImpl>& loader) {
1507 pending_loaders_[info->GetGlobalRequestID()] = loader; 1513 pending_loaders_[info->GetGlobalRequestID()] = loader;
1508 1514 resource_scheduler_->ScheduleLoad(info->GetChildID(), info->GetRouteID(),
1509 loader->StartRequest(); 1515 info->GetRequestID(), loader.get());
1510 } 1516 }
1511 1517
1512 void ResourceDispatcherHostImpl::OnUserGesture(WebContentsImpl* contents) { 1518 void ResourceDispatcherHostImpl::OnUserGesture(WebContentsImpl* contents) {
1513 last_user_gesture_time_ = TimeTicks::Now(); 1519 last_user_gesture_time_ = TimeTicks::Now();
1514 } 1520 }
1515 1521
1516 net::URLRequest* ResourceDispatcherHostImpl::GetURLRequest( 1522 net::URLRequest* ResourceDispatcherHostImpl::GetURLRequest(
1517 const GlobalRequestID& id) { 1523 const GlobalRequestID& id) {
1518 ResourceLoader* loader = GetLoader(id); 1524 ResourceLoaderImpl* loader = GetLoader(id);
1519 if (!loader) 1525 if (!loader)
1520 return NULL; 1526 return NULL;
1521 1527
1522 return loader->request(); 1528 return loader->request();
1523 } 1529 }
1524 1530
1525 namespace { 1531 namespace {
1526 1532
1527 // This function attempts to return the "more interesting" load state of |a| 1533 // This function attempts to return the "more interesting" load state of |a|
1528 // and |b|. We don't have temporal information about these load states 1534 // and |b|. We don't have temporal information about these load states
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
1665 return; 1671 return;
1666 } 1672 }
1667 1673
1668 BlockedLoadersList* loaders = iter->second; 1674 BlockedLoadersList* loaders = iter->second;
1669 1675
1670 // Removing the vector from the map unblocks any subsequent requests. 1676 // Removing the vector from the map unblocks any subsequent requests.
1671 blocked_loaders_map_.erase(iter); 1677 blocked_loaders_map_.erase(iter);
1672 1678
1673 for (BlockedLoadersList::iterator loaders_iter = loaders->begin(); 1679 for (BlockedLoadersList::iterator loaders_iter = loaders->begin();
1674 loaders_iter != loaders->end(); ++loaders_iter) { 1680 loaders_iter != loaders->end(); ++loaders_iter) {
1675 linked_ptr<ResourceLoader> loader = *loaders_iter; 1681 linked_ptr<ResourceLoaderImpl> loader = *loaders_iter;
1676 ResourceRequestInfoImpl* info = loader->GetRequestInfo(); 1682 ResourceRequestInfoImpl* info = loader->GetRequestInfo();
1677 if (cancel_requests) { 1683 if (cancel_requests) {
1678 IncrementOutstandingRequestsMemoryCost(-1 * info->memory_cost(), 1684 IncrementOutstandingRequestsMemoryCost(-1 * info->memory_cost(),
1679 info->GetChildID()); 1685 info->GetChildID());
1680 } else { 1686 } else {
1681 StartLoading(info, loader); 1687 StartLoading(info, loader);
1682 } 1688 }
1683 } 1689 }
1684 1690
1685 delete loaders; 1691 delete loaders;
(...skipping 15 matching lines...) Expand all
1701 1707
1702 return HTTP_AUTH_RESOURCE_BLOCKED_CROSS; 1708 return HTTP_AUTH_RESOURCE_BLOCKED_CROSS;
1703 } 1709 }
1704 1710
1705 bool ResourceDispatcherHostImpl::allow_cross_origin_auth_prompt() { 1711 bool ResourceDispatcherHostImpl::allow_cross_origin_auth_prompt() {
1706 return allow_cross_origin_auth_prompt_; 1712 return allow_cross_origin_auth_prompt_;
1707 } 1713 }
1708 1714
1709 bool ResourceDispatcherHostImpl::IsTransferredNavigation( 1715 bool ResourceDispatcherHostImpl::IsTransferredNavigation(
1710 const GlobalRequestID& id) const { 1716 const GlobalRequestID& id) const {
1711 ResourceLoader* loader = GetLoader(id); 1717 ResourceLoaderImpl* loader = GetLoader(id);
1712 return loader ? loader->is_transferring() : false; 1718 return loader ? loader->is_transferring() : false;
1713 } 1719 }
1714 1720
1715 ResourceLoader* ResourceDispatcherHostImpl::GetLoader( 1721 ResourceLoaderImpl* ResourceDispatcherHostImpl::GetLoader(
1716 const GlobalRequestID& id) const { 1722 const GlobalRequestID& id) const {
1717 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 1723 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
1718 1724
1719 LoaderMap::const_iterator i = pending_loaders_.find(id); 1725 LoaderMap::const_iterator i = pending_loaders_.find(id);
1720 if (i == pending_loaders_.end()) 1726 if (i == pending_loaders_.end())
1721 return NULL; 1727 return NULL;
1722 1728
1723 return i->second.get(); 1729 return i->second.get();
1724 } 1730 }
1725 1731
1726 ResourceLoader* ResourceDispatcherHostImpl::GetLoader(int child_id, 1732 ResourceLoaderImpl* ResourceDispatcherHostImpl::GetLoader(
1727 int request_id) const { 1733 int child_id, int request_id) const {
1728 return GetLoader(GlobalRequestID(child_id, request_id)); 1734 return GetLoader(GlobalRequestID(child_id, request_id));
1729 } 1735 }
1730 1736
1731 } // namespace content 1737 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698