| 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 // 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.h" | 7 #include "content/browser/renderer_host/resource_dispatcher_host.h" |
| 8 | 8 |
| 9 #include <set> | 9 #include <set> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 20 matching lines...) Expand all Loading... |
| 31 #include "content/browser/download/save_file_manager.h" | 31 #include "content/browser/download/save_file_manager.h" |
| 32 #include "content/browser/download/save_file_resource_handler.h" | 32 #include "content/browser/download/save_file_resource_handler.h" |
| 33 #include "content/browser/fileapi/chrome_blob_storage_context.h" | 33 #include "content/browser/fileapi/chrome_blob_storage_context.h" |
| 34 #include "content/browser/plugin_service_impl.h" | 34 #include "content/browser/plugin_service_impl.h" |
| 35 #include "content/browser/renderer_host/async_resource_handler.h" | 35 #include "content/browser/renderer_host/async_resource_handler.h" |
| 36 #include "content/browser/renderer_host/buffered_resource_handler.h" | 36 #include "content/browser/renderer_host/buffered_resource_handler.h" |
| 37 #include "content/browser/renderer_host/cross_site_resource_handler.h" | 37 #include "content/browser/renderer_host/cross_site_resource_handler.h" |
| 38 #include "content/browser/renderer_host/doomed_resource_handler.h" | 38 #include "content/browser/renderer_host/doomed_resource_handler.h" |
| 39 #include "content/browser/renderer_host/redirect_to_file_resource_handler.h" | 39 #include "content/browser/renderer_host/redirect_to_file_resource_handler.h" |
| 40 #include "content/browser/renderer_host/render_view_host.h" | 40 #include "content/browser/renderer_host/render_view_host.h" |
| 41 #include "content/browser/renderer_host/resource_dispatcher_host_request_info.h" | 41 #include "content/browser/renderer_host/resource_request_info_impl.h" |
| 42 #include "content/browser/renderer_host/resource_message_filter.h" | 42 #include "content/browser/renderer_host/resource_message_filter.h" |
| 43 #include "content/browser/renderer_host/resource_request_details.h" | 43 #include "content/browser/renderer_host/resource_request_details.h" |
| 44 #include "content/browser/renderer_host/sync_resource_handler.h" | 44 #include "content/browser/renderer_host/sync_resource_handler.h" |
| 45 #include "content/browser/renderer_host/throttling_resource_handler.h" | 45 #include "content/browser/renderer_host/throttling_resource_handler.h" |
| 46 #include "content/browser/ssl/ssl_client_auth_handler.h" | 46 #include "content/browser/ssl/ssl_client_auth_handler.h" |
| 47 #include "content/browser/ssl/ssl_manager.h" | 47 #include "content/browser/ssl/ssl_manager.h" |
| 48 #include "content/browser/worker_host/worker_service_impl.h" | 48 #include "content/browser/worker_host/worker_service_impl.h" |
| 49 #include "content/common/resource_messages.h" | 49 #include "content/common/resource_messages.h" |
| 50 #include "content/common/ssl_status_serialization.h" | 50 #include "content/common/ssl_status_serialization.h" |
| 51 #include "content/common/view_messages.h" | 51 #include "content/common/view_messages.h" |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 #include "webkit/appcache/appcache_interfaces.h" | 83 #include "webkit/appcache/appcache_interfaces.h" |
| 84 #include "webkit/blob/blob_storage_controller.h" | 84 #include "webkit/blob/blob_storage_controller.h" |
| 85 #include "webkit/blob/shareable_file_reference.h" | 85 #include "webkit/blob/shareable_file_reference.h" |
| 86 | 86 |
| 87 using base::Time; | 87 using base::Time; |
| 88 using base::TimeDelta; | 88 using base::TimeDelta; |
| 89 using base::TimeTicks; | 89 using base::TimeTicks; |
| 90 using content::BrowserThread; | 90 using content::BrowserThread; |
| 91 using content::GlobalRequestID; | 91 using content::GlobalRequestID; |
| 92 using content::ResourceContext; | 92 using content::ResourceContext; |
| 93 using content::ResourceRequestInfo; |
| 94 using content::ResourceRequestInfoImpl; |
| 93 using content::ResourceResponse; | 95 using content::ResourceResponse; |
| 94 using content::ResourceThrottle; | 96 using content::ResourceThrottle; |
| 95 using content::ThrottlingResourceHandler; | 97 using content::ThrottlingResourceHandler; |
| 96 using content::WebContents; | 98 using content::WebContents; |
| 97 using content::WorkerServiceImpl; | 99 using content::WorkerServiceImpl; |
| 98 using webkit_blob::ShareableFileReference; | 100 using webkit_blob::ShareableFileReference; |
| 99 | 101 |
| 100 // ---------------------------------------------------------------------------- | 102 // ---------------------------------------------------------------------------- |
| 101 | 103 |
| 102 namespace { | 104 namespace { |
| (...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 373 delegate_->DownloadStarting(request, context, child_id, route_id, | 375 delegate_->DownloadStarting(request, context, child_id, route_id, |
| 374 request_id, !request->is_pending(), &throttles); | 376 request_id, !request->is_pending(), &throttles); |
| 375 if (!throttles.empty()) { | 377 if (!throttles.empty()) { |
| 376 handler = new ThrottlingResourceHandler(this, handler, child_id, | 378 handler = new ThrottlingResourceHandler(this, handler, child_id, |
| 377 request_id, throttles.Pass()); | 379 request_id, throttles.Pass()); |
| 378 } | 380 } |
| 379 } | 381 } |
| 380 return handler; | 382 return handler; |
| 381 } | 383 } |
| 382 | 384 |
| 385 // static |
| 386 void ResourceDispatcherHost::ClearLoginDelegate(net::URLRequest* request) { |
| 387 ResourceRequestInfoImpl* info = |
| 388 ResourceDispatcherHost::InfoForRequest(request); |
| 389 if (!info) |
| 390 return; |
| 391 |
| 392 info->set_login_delegate(NULL); |
| 393 } |
| 394 |
| 383 void ResourceDispatcherHost::SetRequestInfo( | 395 void ResourceDispatcherHost::SetRequestInfo( |
| 384 net::URLRequest* request, | 396 net::URLRequest* request, |
| 385 ResourceDispatcherHostRequestInfo* info) { | 397 ResourceRequestInfoImpl* info) { |
| 386 request->SetUserData(NULL, info); | 398 request->SetUserData(NULL, info); |
| 387 } | 399 } |
| 388 | 400 |
| 389 void ResourceDispatcherHost::OnShutdown() { | 401 void ResourceDispatcherHost::OnShutdown() { |
| 390 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 402 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 391 is_shutdown_ = true; | 403 is_shutdown_ = true; |
| 392 for (PendingRequestList::const_iterator i = pending_requests_.begin(); | 404 for (PendingRequestList::const_iterator i = pending_requests_.begin(); |
| 393 i != pending_requests_.end(); ++i) { | 405 i != pending_requests_.end(); ++i) { |
| 394 transferred_navigations_.erase(i->first); | 406 transferred_navigations_.erase(i->first); |
| 395 } | 407 } |
| (...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 673 route_id, | 685 route_id, |
| 674 is_continuation_of_transferred_request, | 686 is_continuation_of_transferred_request, |
| 675 &throttles); | 687 &throttles); |
| 676 if (!throttles.empty()) { | 688 if (!throttles.empty()) { |
| 677 handler = new ThrottlingResourceHandler(this, handler, child_id, | 689 handler = new ThrottlingResourceHandler(this, handler, child_id, |
| 678 request_id, throttles.Pass()); | 690 request_id, throttles.Pass()); |
| 679 } | 691 } |
| 680 } | 692 } |
| 681 | 693 |
| 682 // Make extra info and read footer (contains request ID). | 694 // Make extra info and read footer (contains request ID). |
| 683 ResourceDispatcherHostRequestInfo* extra_info = | 695 ResourceRequestInfoImpl* extra_info = |
| 684 new ResourceDispatcherHostRequestInfo( | 696 new ResourceRequestInfoImpl( |
| 685 handler, | 697 handler, |
| 686 process_type, | 698 process_type, |
| 687 child_id, | 699 child_id, |
| 688 route_id, | 700 route_id, |
| 689 request_data.origin_pid, | 701 request_data.origin_pid, |
| 690 request_id, | 702 request_id, |
| 691 request_data.is_main_frame, | 703 request_data.is_main_frame, |
| 692 request_data.frame_id, | 704 request_data.frame_id, |
| 693 request_data.parent_is_main_frame, | 705 request_data.parent_is_main_frame, |
| 694 request_data.parent_frame_id, | 706 request_data.parent_frame_id, |
| (...skipping 18 matching lines...) Expand all Loading... |
| 713 | 725 |
| 714 // Have the appcache associate its extra info with the request. | 726 // Have the appcache associate its extra info with the request. |
| 715 appcache::AppCacheInterceptor::SetExtraRequestInfo( | 727 appcache::AppCacheInterceptor::SetExtraRequestInfo( |
| 716 request, ResourceContext::GetAppCacheService(resource_context), child_id, | 728 request, ResourceContext::GetAppCacheService(resource_context), child_id, |
| 717 request_data.appcache_host_id, request_data.resource_type); | 729 request_data.appcache_host_id, request_data.resource_type); |
| 718 | 730 |
| 719 if (deferred_request) { | 731 if (deferred_request) { |
| 720 // This is a request that has been transferred from another process, so | 732 // This is a request that has been transferred from another process, so |
| 721 // resume it rather than continuing the regular procedure for starting a | 733 // resume it rather than continuing the regular procedure for starting a |
| 722 // request. Currently this is only done for redirects. | 734 // request. Currently this is only done for redirects. |
| 723 GlobalRequestID global_id(extra_info->child_id(), extra_info->request_id()); | 735 GlobalRequestID global_id(extra_info->GetChildID(), |
| 736 extra_info->GetRequestID()); |
| 724 pending_requests_[global_id] = request; | 737 pending_requests_[global_id] = request; |
| 725 request->FollowDeferredRedirect(); | 738 request->FollowDeferredRedirect(); |
| 726 } else { | 739 } else { |
| 727 BeginRequestInternal(request); | 740 BeginRequestInternal(request); |
| 728 } | 741 } |
| 729 } | 742 } |
| 730 | 743 |
| 731 void ResourceDispatcherHost::OnReleaseDownloadedFile(int request_id) { | 744 void ResourceDispatcherHost::OnReleaseDownloadedFile(int request_id) { |
| 732 DCHECK(pending_requests_.end() == | 745 DCHECK(pending_requests_.end() == |
| 733 pending_requests_.find( | 746 pending_requests_.find( |
| 734 GlobalRequestID(filter_->child_id(), request_id))); | 747 GlobalRequestID(filter_->child_id(), request_id))); |
| 735 UnregisterDownloadedTempFile(filter_->child_id(), request_id); | 748 UnregisterDownloadedTempFile(filter_->child_id(), request_id); |
| 736 } | 749 } |
| 737 | 750 |
| 738 void ResourceDispatcherHost::OnDataReceivedACK(int request_id) { | 751 void ResourceDispatcherHost::OnDataReceivedACK(int request_id) { |
| 739 DataReceivedACK(filter_->child_id(), request_id); | 752 DataReceivedACK(filter_->child_id(), request_id); |
| 740 } | 753 } |
| 741 | 754 |
| 742 void ResourceDispatcherHost::DataReceivedACK(int child_id, | 755 void ResourceDispatcherHost::DataReceivedACK(int child_id, |
| 743 int request_id) { | 756 int request_id) { |
| 744 PendingRequestList::iterator i = pending_requests_.find( | 757 PendingRequestList::iterator i = pending_requests_.find( |
| 745 GlobalRequestID(child_id, request_id)); | 758 GlobalRequestID(child_id, request_id)); |
| 746 if (i == pending_requests_.end()) | 759 if (i == pending_requests_.end()) |
| 747 return; | 760 return; |
| 748 | 761 |
| 749 ResourceDispatcherHostRequestInfo* info = InfoForRequest(i->second); | 762 ResourceRequestInfoImpl* info = InfoForRequest(i->second); |
| 750 | 763 |
| 751 // Decrement the number of pending data messages. | 764 // Decrement the number of pending data messages. |
| 752 info->DecrementPendingDataCount(); | 765 info->DecrementPendingDataCount(); |
| 753 | 766 |
| 754 // If the pending data count was higher than the max, resume the request. | 767 // If the pending data count was higher than the max, resume the request. |
| 755 if (info->pending_data_count() == kMaxPendingDataMessages) { | 768 if (info->pending_data_count() == kMaxPendingDataMessages) { |
| 756 // Decrement the pending data count one more time because we also | 769 // Decrement the pending data count one more time because we also |
| 757 // incremented it before pausing the request. | 770 // incremented it before pausing the request. |
| 758 info->DecrementPendingDataCount(); | 771 info->DecrementPendingDataCount(); |
| 759 | 772 |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 803 return false; | 816 return false; |
| 804 } | 817 } |
| 805 | 818 |
| 806 void ResourceDispatcherHost::OnUploadProgressACK(int request_id) { | 819 void ResourceDispatcherHost::OnUploadProgressACK(int request_id) { |
| 807 int child_id = filter_->child_id(); | 820 int child_id = filter_->child_id(); |
| 808 PendingRequestList::iterator i = pending_requests_.find( | 821 PendingRequestList::iterator i = pending_requests_.find( |
| 809 GlobalRequestID(child_id, request_id)); | 822 GlobalRequestID(child_id, request_id)); |
| 810 if (i == pending_requests_.end()) | 823 if (i == pending_requests_.end()) |
| 811 return; | 824 return; |
| 812 | 825 |
| 813 ResourceDispatcherHostRequestInfo* info = InfoForRequest(i->second); | 826 ResourceRequestInfoImpl* info = InfoForRequest(i->second); |
| 814 info->set_waiting_for_upload_progress_ack(false); | 827 info->set_waiting_for_upload_progress_ack(false); |
| 815 } | 828 } |
| 816 | 829 |
| 817 void ResourceDispatcherHost::OnCancelRequest(int request_id) { | 830 void ResourceDispatcherHost::OnCancelRequest(int request_id) { |
| 818 CancelRequest(filter_->child_id(), request_id, true); | 831 CancelRequest(filter_->child_id(), request_id, true); |
| 819 } | 832 } |
| 820 | 833 |
| 821 // Assigns the pending request a new routing_id because it was transferred | 834 // Assigns the pending request a new routing_id because it was transferred |
| 822 // to a new page. | 835 // to a new page. |
| 823 void ResourceDispatcherHost::OnTransferRequestToNewPage(int new_routing_id, | 836 void ResourceDispatcherHost::OnTransferRequestToNewPage(int new_routing_id, |
| 824 int request_id) { | 837 int request_id) { |
| 825 PendingRequestList::iterator i = pending_requests_.find( | 838 PendingRequestList::iterator i = pending_requests_.find( |
| 826 GlobalRequestID(filter_->child_id(), request_id)); | 839 GlobalRequestID(filter_->child_id(), request_id)); |
| 827 if (i == pending_requests_.end()) { | 840 if (i == pending_requests_.end()) { |
| 828 // We probably want to remove this warning eventually, but I wanted to be | 841 // We probably want to remove this warning eventually, but I wanted to be |
| 829 // able to notice when this happens during initial development since it | 842 // able to notice when this happens during initial development since it |
| 830 // should be rare and may indicate a bug. | 843 // should be rare and may indicate a bug. |
| 831 DVLOG(1) << "Updating a request that wasn't found"; | 844 DVLOG(1) << "Updating a request that wasn't found"; |
| 832 return; | 845 return; |
| 833 } | 846 } |
| 834 net::URLRequest* request = i->second; | 847 net::URLRequest* request = i->second; |
| 835 ResourceDispatcherHostRequestInfo* info = InfoForRequest(request); | 848 ResourceRequestInfoImpl* info = InfoForRequest(request); |
| 836 info->set_route_id(new_routing_id); | 849 info->set_route_id(new_routing_id); |
| 837 } | 850 } |
| 838 | 851 |
| 839 void ResourceDispatcherHost::OnFollowRedirect( | 852 void ResourceDispatcherHost::OnFollowRedirect( |
| 840 int request_id, | 853 int request_id, |
| 841 bool has_new_first_party_for_cookies, | 854 bool has_new_first_party_for_cookies, |
| 842 const GURL& new_first_party_for_cookies) { | 855 const GURL& new_first_party_for_cookies) { |
| 843 FollowDeferredRedirect(filter_->child_id(), request_id, | 856 FollowDeferredRedirect(filter_->child_id(), request_id, |
| 844 has_new_first_party_for_cookies, | 857 has_new_first_party_for_cookies, |
| 845 new_first_party_for_cookies); | 858 new_first_party_for_cookies); |
| 846 } | 859 } |
| 847 | 860 |
| 848 ResourceDispatcherHostRequestInfo* ResourceDispatcherHost::CreateRequestInfo( | 861 ResourceRequestInfoImpl* ResourceDispatcherHost::CreateRequestInfo( |
| 849 ResourceHandler* handler, | 862 ResourceHandler* handler, |
| 850 int child_id, | 863 int child_id, |
| 851 int route_id, | 864 int route_id, |
| 852 bool download, | 865 bool download, |
| 853 content::ResourceContext* context) { | 866 content::ResourceContext* context) { |
| 854 return new ResourceDispatcherHostRequestInfo( | 867 return new ResourceRequestInfoImpl( |
| 855 handler, | 868 handler, |
| 856 content::PROCESS_TYPE_RENDERER, | 869 content::PROCESS_TYPE_RENDERER, |
| 857 child_id, | 870 child_id, |
| 858 route_id, | 871 route_id, |
| 859 0, | 872 0, |
| 860 request_id_, | 873 request_id_, |
| 861 false, // is_main_frame | 874 false, // is_main_frame |
| 862 -1, // frame_id | 875 -1, // frame_id |
| 863 false, // parent_is_main_frame | 876 false, // parent_is_main_frame |
| 864 -1, // parent_frame_id | 877 -1, // parent_frame_id |
| 865 ResourceType::SUB_RESOURCE, | 878 ResourceType::SUB_RESOURCE, |
| 866 content::PAGE_TRANSITION_LINK, | 879 content::PAGE_TRANSITION_LINK, |
| 867 0, // upload_size | 880 0, // upload_size |
| 868 download, // is_download | 881 download, // is_download |
| 869 download, // allow_download | 882 download, // allow_download |
| 870 false, // has_user_gesture | 883 false, // has_user_gesture |
| 871 WebKit::WebReferrerPolicyDefault, | 884 WebKit::WebReferrerPolicyDefault, |
| 872 context); | 885 context); |
| 873 } | 886 } |
| 874 | 887 |
| 875 void ResourceDispatcherHost::OnSwapOutACK( | 888 void ResourceDispatcherHost::OnSwapOutACK( |
| 876 const ViewMsg_SwapOut_Params& params) { | 889 const ViewMsg_SwapOut_Params& params) { |
| 877 // Closes for cross-site transitions are handled such that the cross-site | 890 // Closes for cross-site transitions are handled such that the cross-site |
| 878 // transition continues. | 891 // transition continues. |
| 879 GlobalRequestID global_id(params.new_render_process_host_id, | 892 GlobalRequestID global_id(params.new_render_process_host_id, |
| 880 params.new_request_id); | 893 params.new_request_id); |
| 881 PendingRequestList::iterator i = pending_requests_.find(global_id); | 894 PendingRequestList::iterator i = pending_requests_.find(global_id); |
| 882 if (i != pending_requests_.end()) { | 895 if (i != pending_requests_.end()) { |
| 883 // The response we were meant to resume could have already been canceled. | 896 // The response we were meant to resume could have already been canceled. |
| 884 ResourceDispatcherHostRequestInfo* info = InfoForRequest(i->second); | 897 ResourceRequestInfoImpl* info = InfoForRequest(i->second); |
| 885 if (info->cross_site_handler()) | 898 if (info->cross_site_handler()) |
| 886 info->cross_site_handler()->ResumeResponse(); | 899 info->cross_site_handler()->ResumeResponse(); |
| 887 } | 900 } |
| 888 // Update the RenderViewHost's internal state after the ACK. | 901 // Update the RenderViewHost's internal state after the ACK. |
| 889 content::BrowserThread::PostTask( | 902 content::BrowserThread::PostTask( |
| 890 content::BrowserThread::UI, | 903 content::BrowserThread::UI, |
| 891 FROM_HERE, | 904 FROM_HERE, |
| 892 base::Bind(&OnSwapOutACKHelper, | 905 base::Bind(&OnSwapOutACKHelper, |
| 893 params.closing_process_id, | 906 params.closing_process_id, |
| 894 params.closing_route_id)); | 907 params.closing_route_id)); |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 950 CreateResourceHandlerForDownload(request.get(), context, child_id, | 963 CreateResourceHandlerForDownload(request.get(), context, child_id, |
| 951 route_id, request_id_, save_info, | 964 route_id, request_id_, save_info, |
| 952 started_cb)); | 965 started_cb)); |
| 953 | 966 |
| 954 if (!request_context->job_factory()->IsHandledURL(url)) { | 967 if (!request_context->job_factory()->IsHandledURL(url)) { |
| 955 VLOG(1) << "Download request for unsupported protocol: " | 968 VLOG(1) << "Download request for unsupported protocol: " |
| 956 << url.possibly_invalid_spec(); | 969 << url.possibly_invalid_spec(); |
| 957 return net::ERR_ACCESS_DENIED; | 970 return net::ERR_ACCESS_DENIED; |
| 958 } | 971 } |
| 959 | 972 |
| 960 ResourceDispatcherHostRequestInfo* extra_info = | 973 ResourceRequestInfoImpl* extra_info = |
| 961 CreateRequestInfo(handler, child_id, route_id, true, context); | 974 CreateRequestInfo(handler, child_id, route_id, true, context); |
| 962 SetRequestInfo(request.get(), extra_info); // Request takes ownership. | 975 SetRequestInfo(request.get(), extra_info); // Request takes ownership. |
| 963 | 976 |
| 964 BeginRequestInternal(request.release()); | 977 BeginRequestInternal(request.release()); |
| 965 | 978 |
| 966 return net::OK; | 979 return net::OK; |
| 967 } | 980 } |
| 968 | 981 |
| 969 // This function is only used for saving feature. | 982 // This function is only used for saving feature. |
| 970 void ResourceDispatcherHost::BeginSaveFile( | 983 void ResourceDispatcherHost::BeginSaveFile( |
| (...skipping 25 matching lines...) Expand all Loading... |
| 996 | 1009 |
| 997 net::URLRequest* request = new net::URLRequest(url, this); | 1010 net::URLRequest* request = new net::URLRequest(url, this); |
| 998 request->set_method("GET"); | 1011 request->set_method("GET"); |
| 999 request->set_referrer(MaybeStripReferrer(referrer).spec()); | 1012 request->set_referrer(MaybeStripReferrer(referrer).spec()); |
| 1000 // So far, for saving page, we need fetch content from cache, in the | 1013 // So far, for saving page, we need fetch content from cache, in the |
| 1001 // future, maybe we can use a configuration to configure this behavior. | 1014 // future, maybe we can use a configuration to configure this behavior. |
| 1002 request->set_load_flags(net::LOAD_PREFERRING_CACHE); | 1015 request->set_load_flags(net::LOAD_PREFERRING_CACHE); |
| 1003 request->set_context(context->GetRequestContext()); | 1016 request->set_context(context->GetRequestContext()); |
| 1004 | 1017 |
| 1005 // Since we're just saving some resources we need, disallow downloading. | 1018 // Since we're just saving some resources we need, disallow downloading. |
| 1006 ResourceDispatcherHostRequestInfo* extra_info = | 1019 ResourceRequestInfoImpl* extra_info = |
| 1007 CreateRequestInfo(handler, child_id, route_id, false, context); | 1020 CreateRequestInfo(handler, child_id, route_id, false, context); |
| 1008 SetRequestInfo(request, extra_info); // Request takes ownership. | 1021 SetRequestInfo(request, extra_info); // Request takes ownership. |
| 1009 | 1022 |
| 1010 BeginRequestInternal(request); | 1023 BeginRequestInternal(request); |
| 1011 } | 1024 } |
| 1012 | 1025 |
| 1013 void ResourceDispatcherHost::FollowDeferredRedirect( | 1026 void ResourceDispatcherHost::FollowDeferredRedirect( |
| 1014 int child_id, | 1027 int child_id, |
| 1015 int request_id, | 1028 int request_id, |
| 1016 bool has_new_first_party_for_cookies, | 1029 bool has_new_first_party_for_cookies, |
| (...skipping 29 matching lines...) Expand all Loading... |
| 1046 | 1059 |
| 1047 bool ResourceDispatcherHost::WillSendData(int child_id, | 1060 bool ResourceDispatcherHost::WillSendData(int child_id, |
| 1048 int request_id) { | 1061 int request_id) { |
| 1049 PendingRequestList::iterator i = pending_requests_.find( | 1062 PendingRequestList::iterator i = pending_requests_.find( |
| 1050 GlobalRequestID(child_id, request_id)); | 1063 GlobalRequestID(child_id, request_id)); |
| 1051 if (i == pending_requests_.end()) { | 1064 if (i == pending_requests_.end()) { |
| 1052 NOTREACHED() << "WillSendData for invalid request"; | 1065 NOTREACHED() << "WillSendData for invalid request"; |
| 1053 return false; | 1066 return false; |
| 1054 } | 1067 } |
| 1055 | 1068 |
| 1056 ResourceDispatcherHostRequestInfo* info = InfoForRequest(i->second); | 1069 ResourceRequestInfoImpl* info = InfoForRequest(i->second); |
| 1057 | 1070 |
| 1058 info->IncrementPendingDataCount(); | 1071 info->IncrementPendingDataCount(); |
| 1059 if (info->pending_data_count() > kMaxPendingDataMessages) { | 1072 if (info->pending_data_count() > kMaxPendingDataMessages) { |
| 1060 // We reached the max number of data messages that can be sent to | 1073 // We reached the max number of data messages that can be sent to |
| 1061 // the renderer for a given request. Pause the request and wait for | 1074 // the renderer for a given request. Pause the request and wait for |
| 1062 // the renderer to start processing them before resuming it. | 1075 // the renderer to start processing them before resuming it. |
| 1063 PauseRequest(child_id, request_id, true); | 1076 PauseRequest(child_id, request_id, true); |
| 1064 return false; | 1077 return false; |
| 1065 } | 1078 } |
| 1066 | 1079 |
| 1067 return true; | 1080 return true; |
| 1068 } | 1081 } |
| 1069 | 1082 |
| 1070 void ResourceDispatcherHost::PauseRequest(int child_id, | 1083 void ResourceDispatcherHost::PauseRequest(int child_id, |
| 1071 int request_id, | 1084 int request_id, |
| 1072 bool pause) { | 1085 bool pause) { |
| 1073 GlobalRequestID global_id(child_id, request_id); | 1086 GlobalRequestID global_id(child_id, request_id); |
| 1074 PendingRequestList::iterator i = pending_requests_.find(global_id); | 1087 PendingRequestList::iterator i = pending_requests_.find(global_id); |
| 1075 if (i == pending_requests_.end()) { | 1088 if (i == pending_requests_.end()) { |
| 1076 DVLOG(1) << "Pausing a request that wasn't found"; | 1089 DVLOG(1) << "Pausing a request that wasn't found"; |
| 1077 return; | 1090 return; |
| 1078 } | 1091 } |
| 1079 | 1092 |
| 1080 ResourceDispatcherHostRequestInfo* info = InfoForRequest(i->second); | 1093 ResourceRequestInfoImpl* info = InfoForRequest(i->second); |
| 1081 int pause_count = info->pause_count() + (pause ? 1 : -1); | 1094 int pause_count = info->pause_count() + (pause ? 1 : -1); |
| 1082 if (pause_count < 0) { | 1095 if (pause_count < 0) { |
| 1083 NOTREACHED(); // Unbalanced call to pause. | 1096 NOTREACHED(); // Unbalanced call to pause. |
| 1084 return; | 1097 return; |
| 1085 } | 1098 } |
| 1086 info->set_pause_count(pause_count); | 1099 info->set_pause_count(pause_count); |
| 1087 | 1100 |
| 1088 VLOG(1) << "To pause (" << pause << "): " << i->second->url().spec(); | 1101 VLOG(1) << "To pause (" << pause << "): " << i->second->url().spec(); |
| 1089 | 1102 |
| 1090 // If we're resuming, kick the request to start reading again. Run the read | 1103 // If we're resuming, kick the request to start reading again. Run the read |
| (...skipping 27 matching lines...) Expand all Loading... |
| 1118 // Since pending_requests_ is a map, we first build up a list of all of the | 1131 // Since pending_requests_ is a map, we first build up a list of all of the |
| 1119 // matching requests to be cancelled, and then we cancel them. Since there | 1132 // matching requests to be cancelled, and then we cancel them. Since there |
| 1120 // may be more than one request to cancel, we cannot simply hold onto the map | 1133 // may be more than one request to cancel, we cannot simply hold onto the map |
| 1121 // iterators found in the first loop. | 1134 // iterators found in the first loop. |
| 1122 | 1135 |
| 1123 // Find the global ID of all matching elements. | 1136 // Find the global ID of all matching elements. |
| 1124 std::vector<GlobalRequestID> matching_requests; | 1137 std::vector<GlobalRequestID> matching_requests; |
| 1125 for (PendingRequestList::const_iterator i = pending_requests_.begin(); | 1138 for (PendingRequestList::const_iterator i = pending_requests_.begin(); |
| 1126 i != pending_requests_.end(); ++i) { | 1139 i != pending_requests_.end(); ++i) { |
| 1127 if (i->first.child_id == child_id) { | 1140 if (i->first.child_id == child_id) { |
| 1128 ResourceDispatcherHostRequestInfo* info = InfoForRequest(i->second); | 1141 ResourceRequestInfoImpl* info = InfoForRequest(i->second); |
| 1129 GlobalRequestID id(child_id, i->first.request_id); | 1142 GlobalRequestID id(child_id, i->first.request_id); |
| 1130 DCHECK(id == i->first); | 1143 DCHECK(id == i->first); |
| 1131 // Don't cancel navigations that are transferring to another process, | 1144 // Don't cancel navigations that are transferring to another process, |
| 1132 // since they belong to another process now. | 1145 // since they belong to another process now. |
| 1133 if (!info->is_download() && | 1146 if (!info->is_download() && |
| 1134 (transferred_navigations_.find(id) == | 1147 (transferred_navigations_.find(id) == |
| 1135 transferred_navigations_.end()) && | 1148 transferred_navigations_.end()) && |
| 1136 (route_id == -1 || route_id == info->route_id())) { | 1149 (route_id == -1 || route_id == info->GetRouteID())) { |
| 1137 matching_requests.push_back( | 1150 matching_requests.push_back( |
| 1138 GlobalRequestID(child_id, i->first.request_id)); | 1151 GlobalRequestID(child_id, i->first.request_id)); |
| 1139 } | 1152 } |
| 1140 } | 1153 } |
| 1141 } | 1154 } |
| 1142 | 1155 |
| 1143 // Remove matches. | 1156 // Remove matches. |
| 1144 for (size_t i = 0; i < matching_requests.size(); ++i) { | 1157 for (size_t i = 0; i < matching_requests.size(); ++i) { |
| 1145 PendingRequestList::iterator iter = | 1158 PendingRequestList::iterator iter = |
| 1146 pending_requests_.find(matching_requests[i]); | 1159 pending_requests_.find(matching_requests[i]); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1186 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 1199 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 1187 DCHECK(context); | 1200 DCHECK(context); |
| 1188 | 1201 |
| 1189 // Note that request cancellation has side effects. Therefore, we gather all | 1202 // Note that request cancellation has side effects. Therefore, we gather all |
| 1190 // the requests to cancel first, and then we start cancelling. We assert at | 1203 // the requests to cancel first, and then we start cancelling. We assert at |
| 1191 // the end that there are no more to cancel since the context is about to go | 1204 // the end that there are no more to cancel since the context is about to go |
| 1192 // away. | 1205 // away. |
| 1193 std::vector<net::URLRequest*> requests_to_cancel; | 1206 std::vector<net::URLRequest*> requests_to_cancel; |
| 1194 for (PendingRequestList::iterator i = pending_requests_.begin(); | 1207 for (PendingRequestList::iterator i = pending_requests_.begin(); |
| 1195 i != pending_requests_.end();) { | 1208 i != pending_requests_.end();) { |
| 1196 ResourceDispatcherHostRequestInfo* info = InfoForRequest(i->second); | 1209 ResourceRequestInfoImpl* info = InfoForRequest(i->second); |
| 1197 if (info->context() == context) { | 1210 if (info->GetContext() == context) { |
| 1198 requests_to_cancel.push_back(i->second); | 1211 requests_to_cancel.push_back(i->second); |
| 1199 pending_requests_.erase(i++); | 1212 pending_requests_.erase(i++); |
| 1200 } else { | 1213 } else { |
| 1201 ++i; | 1214 ++i; |
| 1202 } | 1215 } |
| 1203 } | 1216 } |
| 1204 | 1217 |
| 1205 for (BlockedRequestMap::iterator i = blocked_requests_map_.begin(); | 1218 for (BlockedRequestMap::iterator i = blocked_requests_map_.begin(); |
| 1206 i != blocked_requests_map_.end();) { | 1219 i != blocked_requests_map_.end();) { |
| 1207 BlockedRequestsList* requests = i->second; | 1220 BlockedRequestsList* requests = i->second; |
| 1208 if (requests->empty()) { | 1221 if (requests->empty()) { |
| 1209 // This can happen if BlockRequestsForRoute() has been called for a route, | 1222 // This can happen if BlockRequestsForRoute() has been called for a route, |
| 1210 // but we haven't blocked any matching requests yet. | 1223 // but we haven't blocked any matching requests yet. |
| 1211 ++i; | 1224 ++i; |
| 1212 continue; | 1225 continue; |
| 1213 } | 1226 } |
| 1214 ResourceDispatcherHostRequestInfo* info = | 1227 ResourceRequestInfoImpl* info = |
| 1215 InfoForRequest(requests->front()); | 1228 InfoForRequest(requests->front()); |
| 1216 if (info->context() == context) { | 1229 if (info->GetContext() == context) { |
| 1217 blocked_requests_map_.erase(i++); | 1230 blocked_requests_map_.erase(i++); |
| 1218 for (BlockedRequestsList::const_iterator it = requests->begin(); | 1231 for (BlockedRequestsList::const_iterator it = requests->begin(); |
| 1219 it != requests->end(); ++it) { | 1232 it != requests->end(); ++it) { |
| 1220 net::URLRequest* request = *it; | 1233 net::URLRequest* request = *it; |
| 1221 info = InfoForRequest(request); | 1234 info = InfoForRequest(request); |
| 1222 // We make the assumption that all requests on the list have the same | 1235 // We make the assumption that all requests on the list have the same |
| 1223 // ResourceContext. | 1236 // ResourceContext. |
| 1224 DCHECK_EQ(context, info->context()); | 1237 DCHECK_EQ(context, info->GetContext()); |
| 1225 IncrementOutstandingRequestsMemoryCost(-1 * info->memory_cost(), | 1238 IncrementOutstandingRequestsMemoryCost(-1 * info->memory_cost(), |
| 1226 info->child_id()); | 1239 info->GetChildID()); |
| 1227 requests_to_cancel.push_back(request); | 1240 requests_to_cancel.push_back(request); |
| 1228 } | 1241 } |
| 1229 delete requests; | 1242 delete requests; |
| 1230 } else { | 1243 } else { |
| 1231 ++i; | 1244 ++i; |
| 1232 } | 1245 } |
| 1233 } | 1246 } |
| 1234 | 1247 |
| 1235 for (std::vector<net::URLRequest*>::iterator i = requests_to_cancel.begin(); | 1248 for (std::vector<net::URLRequest*>::iterator i = requests_to_cancel.begin(); |
| 1236 i != requests_to_cancel.end(); ++i) { | 1249 i != requests_to_cancel.end(); ++i) { |
| 1237 net::URLRequest* request = *i; | 1250 net::URLRequest* request = *i; |
| 1238 ResourceDispatcherHostRequestInfo* info = InfoForRequest(request); | 1251 ResourceRequestInfoImpl* info = InfoForRequest(request); |
| 1239 // There is no strict requirement that this be the case, but currently | 1252 // There is no strict requirement that this be the case, but currently |
| 1240 // downloads and transferred requests are the only requests that aren't | 1253 // downloads and transferred requests are the only requests that aren't |
| 1241 // cancelled when the associated processes go away. It may be OK for this | 1254 // cancelled when the associated processes go away. It may be OK for this |
| 1242 // invariant to change in the future, but if this assertion fires without | 1255 // invariant to change in the future, but if this assertion fires without |
| 1243 // the invariant changing, then it's indicative of a leak. | 1256 // the invariant changing, then it's indicative of a leak. |
| 1244 GlobalRequestID request_id(info->child_id(), info->request_id()); | 1257 GlobalRequestID request_id(info->GetChildID(), info->GetRequestID()); |
| 1245 bool is_transferred = IsTransferredNavigation(request_id); | 1258 bool is_transferred = IsTransferredNavigation(request_id); |
| 1246 DCHECK(info->is_download() || is_transferred); | 1259 DCHECK(info->is_download() || is_transferred); |
| 1247 if (is_transferred) | 1260 if (is_transferred) |
| 1248 transferred_navigations_.erase(request_id); | 1261 transferred_navigations_.erase(request_id); |
| 1249 delete request; | 1262 delete request; |
| 1250 } | 1263 } |
| 1251 | 1264 |
| 1252 // Validate that no more requests for this context were added. | 1265 // Validate that no more requests for this context were added. |
| 1253 for (PendingRequestList::const_iterator i = pending_requests_.begin(); | 1266 for (PendingRequestList::const_iterator i = pending_requests_.begin(); |
| 1254 i != pending_requests_.end(); ++i) { | 1267 i != pending_requests_.end(); ++i) { |
| 1255 ResourceDispatcherHostRequestInfo* info = InfoForRequest(i->second); | 1268 ResourceRequestInfoImpl* info = InfoForRequest(i->second); |
| 1256 DCHECK_NE(info->context(), context); | 1269 DCHECK_NE(info->GetContext(), context); |
| 1257 } | 1270 } |
| 1258 | 1271 |
| 1259 for (BlockedRequestMap::const_iterator i = blocked_requests_map_.begin(); | 1272 for (BlockedRequestMap::const_iterator i = blocked_requests_map_.begin(); |
| 1260 i != blocked_requests_map_.end(); ++i) { | 1273 i != blocked_requests_map_.end(); ++i) { |
| 1261 BlockedRequestsList* requests = i->second; | 1274 BlockedRequestsList* requests = i->second; |
| 1262 if (!requests->empty()) { | 1275 if (!requests->empty()) { |
| 1263 ResourceDispatcherHostRequestInfo* info = | 1276 ResourceRequestInfoImpl* info = |
| 1264 InfoForRequest(requests->front()); | 1277 InfoForRequest(requests->front()); |
| 1265 DCHECK_NE(info->context(), context); | 1278 DCHECK_NE(info->GetContext(), context); |
| 1266 } | 1279 } |
| 1267 } | 1280 } |
| 1268 } | 1281 } |
| 1269 | 1282 |
| 1270 // Cancels the request and removes it from the list. | 1283 // Cancels the request and removes it from the list. |
| 1271 void ResourceDispatcherHost::RemovePendingRequest(int child_id, | 1284 void ResourceDispatcherHost::RemovePendingRequest(int child_id, |
| 1272 int request_id) { | 1285 int request_id) { |
| 1273 PendingRequestList::iterator i = pending_requests_.find( | 1286 PendingRequestList::iterator i = pending_requests_.find( |
| 1274 GlobalRequestID(child_id, request_id)); | 1287 GlobalRequestID(child_id, request_id)); |
| 1275 if (i == pending_requests_.end()) { | 1288 if (i == pending_requests_.end()) { |
| 1276 NOTREACHED() << "Trying to remove a request that's not here"; | 1289 NOTREACHED() << "Trying to remove a request that's not here"; |
| 1277 return; | 1290 return; |
| 1278 } | 1291 } |
| 1279 RemovePendingRequest(i); | 1292 RemovePendingRequest(i); |
| 1280 } | 1293 } |
| 1281 | 1294 |
| 1282 void ResourceDispatcherHost::RemovePendingRequest( | 1295 void ResourceDispatcherHost::RemovePendingRequest( |
| 1283 const PendingRequestList::iterator& iter) { | 1296 const PendingRequestList::iterator& iter) { |
| 1284 ResourceDispatcherHostRequestInfo* info = InfoForRequest(iter->second); | 1297 ResourceRequestInfoImpl* info = InfoForRequest(iter->second); |
| 1285 | 1298 |
| 1286 // Remove the memory credit that we added when pushing the request onto | 1299 // Remove the memory credit that we added when pushing the request onto |
| 1287 // the pending list. | 1300 // the pending list. |
| 1288 IncrementOutstandingRequestsMemoryCost(-1 * info->memory_cost(), | 1301 IncrementOutstandingRequestsMemoryCost(-1 * info->memory_cost(), |
| 1289 info->child_id()); | 1302 info->GetChildID()); |
| 1290 | 1303 |
| 1291 // Notify interested parties that the request object is going away. | 1304 // Notify interested parties that the request object is going away. |
| 1292 if (info->login_delegate()) | 1305 if (info->login_delegate()) |
| 1293 info->login_delegate()->OnRequestCancelled(); | 1306 info->login_delegate()->OnRequestCancelled(); |
| 1294 if (info->ssl_client_auth_handler()) | 1307 if (info->ssl_client_auth_handler()) |
| 1295 info->ssl_client_auth_handler()->OnRequestCancelled(); | 1308 info->ssl_client_auth_handler()->OnRequestCancelled(); |
| 1296 transferred_navigations_.erase( | 1309 transferred_navigations_.erase( |
| 1297 GlobalRequestID(info->child_id(), info->request_id())); | 1310 GlobalRequestID(info->GetChildID(), info->GetRequestID())); |
| 1298 | 1311 |
| 1299 delete iter->second; | 1312 delete iter->second; |
| 1300 pending_requests_.erase(iter); | 1313 pending_requests_.erase(iter); |
| 1301 | 1314 |
| 1302 // If we have no more pending requests, then stop the load state monitor | 1315 // If we have no more pending requests, then stop the load state monitor |
| 1303 if (pending_requests_.empty()) | 1316 if (pending_requests_.empty()) |
| 1304 update_load_states_timer_.Stop(); | 1317 update_load_states_timer_.Stop(); |
| 1305 } | 1318 } |
| 1306 | 1319 |
| 1307 // net::URLRequest::Delegate --------------------------------------------------- | 1320 // net::URLRequest::Delegate --------------------------------------------------- |
| 1308 | 1321 |
| 1309 void ResourceDispatcherHost::OnReceivedRedirect(net::URLRequest* request, | 1322 void ResourceDispatcherHost::OnReceivedRedirect(net::URLRequest* request, |
| 1310 const GURL& new_url, | 1323 const GURL& new_url, |
| 1311 bool* defer_redirect) { | 1324 bool* defer_redirect) { |
| 1312 VLOG(1) << "OnReceivedRedirect: " << request->url().spec(); | 1325 VLOG(1) << "OnReceivedRedirect: " << request->url().spec(); |
| 1313 ResourceDispatcherHostRequestInfo* info = InfoForRequest(request); | 1326 ResourceRequestInfoImpl* info = InfoForRequest(request); |
| 1314 | 1327 |
| 1315 DCHECK(request->status().is_success()); | 1328 DCHECK(request->status().is_success()); |
| 1316 | 1329 |
| 1317 if (info->process_type() != content::PROCESS_TYPE_PLUGIN && | 1330 if (info->process_type() != content::PROCESS_TYPE_PLUGIN && |
| 1318 !ChildProcessSecurityPolicyImpl::GetInstance()-> | 1331 !ChildProcessSecurityPolicyImpl::GetInstance()-> |
| 1319 CanRequestURL(info->child_id(), new_url)) { | 1332 CanRequestURL(info->GetChildID(), new_url)) { |
| 1320 VLOG(1) << "Denied unauthorized request for " | 1333 VLOG(1) << "Denied unauthorized request for " |
| 1321 << new_url.possibly_invalid_spec(); | 1334 << new_url.possibly_invalid_spec(); |
| 1322 | 1335 |
| 1323 // Tell the renderer that this request was disallowed. | 1336 // Tell the renderer that this request was disallowed. |
| 1324 CancelRequestInternal(request, false); | 1337 CancelRequestInternal(request, false); |
| 1325 return; | 1338 return; |
| 1326 } | 1339 } |
| 1327 | 1340 |
| 1328 NotifyReceivedRedirect(request, info->child_id(), new_url); | 1341 NotifyReceivedRedirect(request, info->GetChildID(), new_url); |
| 1329 | 1342 |
| 1330 if (HandleExternalProtocol(info->request_id(), info->child_id(), | 1343 if (HandleExternalProtocol(info->GetRequestID(), info->GetChildID(), |
| 1331 info->route_id(), new_url, | 1344 info->GetRouteID(), new_url, |
| 1332 info->resource_type(), | 1345 info->GetResourceType(), |
| 1333 *request->context()->job_factory(), | 1346 *request->context()->job_factory(), |
| 1334 info->resource_handler())) { | 1347 info->resource_handler())) { |
| 1335 // The request is complete so we can remove it. | 1348 // The request is complete so we can remove it. |
| 1336 RemovePendingRequest(info->child_id(), info->request_id()); | 1349 RemovePendingRequest(info->GetChildID(), info->GetRequestID()); |
| 1337 return; | 1350 return; |
| 1338 } | 1351 } |
| 1339 | 1352 |
| 1340 scoped_refptr<ResourceResponse> response(new ResourceResponse); | 1353 scoped_refptr<ResourceResponse> response(new ResourceResponse); |
| 1341 PopulateResourceResponse(request, response); | 1354 PopulateResourceResponse(request, response); |
| 1342 if (!info->resource_handler()->OnRequestRedirected(info->request_id(), | 1355 if (!info->resource_handler()->OnRequestRedirected(info->GetRequestID(), |
| 1343 new_url, | 1356 new_url, |
| 1344 response, defer_redirect)) | 1357 response, defer_redirect)) |
| 1345 CancelRequestInternal(request, false); | 1358 CancelRequestInternal(request, false); |
| 1346 } | 1359 } |
| 1347 | 1360 |
| 1348 void ResourceDispatcherHost::OnAuthRequired( | 1361 void ResourceDispatcherHost::OnAuthRequired( |
| 1349 net::URLRequest* request, | 1362 net::URLRequest* request, |
| 1350 net::AuthChallengeInfo* auth_info) { | 1363 net::AuthChallengeInfo* auth_info) { |
| 1351 if (request->load_flags() & net::LOAD_DO_NOT_PROMPT_FOR_LOGIN) { | 1364 if (request->load_flags() & net::LOAD_DO_NOT_PROMPT_FOR_LOGIN) { |
| 1352 request->CancelAuth(); | 1365 request->CancelAuth(); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 1373 } | 1386 } |
| 1374 } | 1387 } |
| 1375 | 1388 |
| 1376 | 1389 |
| 1377 // Create a login dialog on the UI thread to get authentication data, | 1390 // Create a login dialog on the UI thread to get authentication data, |
| 1378 // or pull from cache and continue on the IO thread. | 1391 // or pull from cache and continue on the IO thread. |
| 1379 // TODO(mpcomplete): We should block the parent tab while waiting for | 1392 // TODO(mpcomplete): We should block the parent tab while waiting for |
| 1380 // authentication. | 1393 // authentication. |
| 1381 // That would also solve the problem of the net::URLRequest being cancelled | 1394 // That would also solve the problem of the net::URLRequest being cancelled |
| 1382 // before we receive authentication. | 1395 // before we receive authentication. |
| 1383 ResourceDispatcherHostRequestInfo* info = InfoForRequest(request); | 1396 ResourceRequestInfoImpl* info = InfoForRequest(request); |
| 1384 DCHECK(!info->login_delegate()) << | 1397 DCHECK(!info->login_delegate()) << |
| 1385 "OnAuthRequired called with login_delegate pending"; | 1398 "OnAuthRequired called with login_delegate pending"; |
| 1386 if (delegate_) { | 1399 if (delegate_) { |
| 1387 info->set_login_delegate(delegate_->CreateLoginDelegate( | 1400 info->set_login_delegate(delegate_->CreateLoginDelegate( |
| 1388 auth_info, request)); | 1401 auth_info, request)); |
| 1389 } | 1402 } |
| 1390 if (!info->login_delegate()) | 1403 if (!info->login_delegate()) |
| 1391 request->CancelAuth(); | 1404 request->CancelAuth(); |
| 1392 } | 1405 } |
| 1393 | 1406 |
| 1394 void ResourceDispatcherHost::OnCertificateRequested( | 1407 void ResourceDispatcherHost::OnCertificateRequested( |
| 1395 net::URLRequest* request, | 1408 net::URLRequest* request, |
| 1396 net::SSLCertRequestInfo* cert_request_info) { | 1409 net::SSLCertRequestInfo* cert_request_info) { |
| 1397 DCHECK(request); | 1410 DCHECK(request); |
| 1398 if (delegate_ && !delegate_->AcceptSSLClientCertificateRequest( | 1411 if (delegate_ && !delegate_->AcceptSSLClientCertificateRequest( |
| 1399 request, cert_request_info)) { | 1412 request, cert_request_info)) { |
| 1400 request->Cancel(); | 1413 request->Cancel(); |
| 1401 return; | 1414 return; |
| 1402 } | 1415 } |
| 1403 | 1416 |
| 1404 if (cert_request_info->client_certs.empty()) { | 1417 if (cert_request_info->client_certs.empty()) { |
| 1405 // No need to query the user if there are no certs to choose from. | 1418 // No need to query the user if there are no certs to choose from. |
| 1406 request->ContinueWithCertificate(NULL); | 1419 request->ContinueWithCertificate(NULL); |
| 1407 return; | 1420 return; |
| 1408 } | 1421 } |
| 1409 | 1422 |
| 1410 ResourceDispatcherHostRequestInfo* info = InfoForRequest(request); | 1423 ResourceRequestInfoImpl* info = InfoForRequest(request); |
| 1411 DCHECK(!info->ssl_client_auth_handler()) << | 1424 DCHECK(!info->ssl_client_auth_handler()) << |
| 1412 "OnCertificateRequested called with ssl_client_auth_handler pending"; | 1425 "OnCertificateRequested called with ssl_client_auth_handler pending"; |
| 1413 info->set_ssl_client_auth_handler( | 1426 info->set_ssl_client_auth_handler( |
| 1414 new SSLClientAuthHandler(request, cert_request_info)); | 1427 new SSLClientAuthHandler(request, cert_request_info)); |
| 1415 info->ssl_client_auth_handler()->SelectCertificate(); | 1428 info->ssl_client_auth_handler()->SelectCertificate(); |
| 1416 } | 1429 } |
| 1417 | 1430 |
| 1418 void ResourceDispatcherHost::OnSSLCertificateError( | 1431 void ResourceDispatcherHost::OnSSLCertificateError( |
| 1419 net::URLRequest* request, | 1432 net::URLRequest* request, |
| 1420 const net::SSLInfo& ssl_info, | 1433 const net::SSLInfo& ssl_info, |
| 1421 bool is_hsts_host) { | 1434 bool is_hsts_host) { |
| 1422 DCHECK(request); | 1435 DCHECK(request); |
| 1423 SSLManager::OnSSLCertificateError(this, request, ssl_info, is_hsts_host); | 1436 SSLManager::OnSSLCertificateError(this, request, ssl_info, is_hsts_host); |
| 1424 } | 1437 } |
| 1425 | 1438 |
| 1426 bool ResourceDispatcherHost::CanGetCookies( | 1439 bool ResourceDispatcherHost::CanGetCookies( |
| 1427 const net::URLRequest* request, | 1440 const net::URLRequest* request, |
| 1428 const net::CookieList& cookie_list) const { | 1441 const net::CookieList& cookie_list) const { |
| 1429 VLOG(1) << "OnGetCookies: " << request->url().spec(); | 1442 VLOG(1) << "OnGetCookies: " << request->url().spec(); |
| 1430 int render_process_id, render_view_id; | 1443 int render_process_id, render_view_id; |
| 1431 if (!RenderViewForRequest(request, &render_process_id, &render_view_id)) | 1444 if (!RenderViewForRequest(request, &render_process_id, &render_view_id)) |
| 1432 return false; | 1445 return false; |
| 1433 | 1446 |
| 1434 const ResourceDispatcherHostRequestInfo* info = InfoForRequest(request); | 1447 const ResourceRequestInfoImpl* info = InfoForRequest(request); |
| 1435 | 1448 |
| 1436 return content::GetContentClient()->browser()->AllowGetCookie( | 1449 return content::GetContentClient()->browser()->AllowGetCookie( |
| 1437 request->url(), request->first_party_for_cookies(), cookie_list, | 1450 request->url(), request->first_party_for_cookies(), cookie_list, |
| 1438 info->context(), render_process_id, render_view_id); | 1451 info->GetContext(), render_process_id, render_view_id); |
| 1439 } | 1452 } |
| 1440 | 1453 |
| 1441 bool ResourceDispatcherHost::CanSetCookie(const net::URLRequest* request, | 1454 bool ResourceDispatcherHost::CanSetCookie(const net::URLRequest* request, |
| 1442 const std::string& cookie_line, | 1455 const std::string& cookie_line, |
| 1443 net::CookieOptions* options) const { | 1456 net::CookieOptions* options) const { |
| 1444 VLOG(1) << "OnSetCookie: " << request->url().spec(); | 1457 VLOG(1) << "OnSetCookie: " << request->url().spec(); |
| 1445 | 1458 |
| 1446 int render_process_id, render_view_id; | 1459 int render_process_id, render_view_id; |
| 1447 if (!RenderViewForRequest(request, &render_process_id, &render_view_id)) | 1460 if (!RenderViewForRequest(request, &render_process_id, &render_view_id)) |
| 1448 return false; | 1461 return false; |
| 1449 | 1462 |
| 1450 const ResourceDispatcherHostRequestInfo* info = InfoForRequest(request); | 1463 const ResourceRequestInfoImpl* info = InfoForRequest(request); |
| 1451 return content::GetContentClient()->browser()->AllowSetCookie( | 1464 return content::GetContentClient()->browser()->AllowSetCookie( |
| 1452 request->url(), request->first_party_for_cookies(), cookie_line, | 1465 request->url(), request->first_party_for_cookies(), cookie_line, |
| 1453 info->context(), render_process_id, render_view_id, options); | 1466 info->GetContext(), render_process_id, render_view_id, options); |
| 1454 } | 1467 } |
| 1455 | 1468 |
| 1456 void ResourceDispatcherHost::OnResponseStarted(net::URLRequest* request) { | 1469 void ResourceDispatcherHost::OnResponseStarted(net::URLRequest* request) { |
| 1457 VLOG(1) << "OnResponseStarted: " << request->url().spec(); | 1470 VLOG(1) << "OnResponseStarted: " << request->url().spec(); |
| 1458 ResourceDispatcherHostRequestInfo* info = InfoForRequest(request); | 1471 ResourceRequestInfoImpl* info = InfoForRequest(request); |
| 1459 | 1472 |
| 1460 if (request->status().is_success()) { | 1473 if (request->status().is_success()) { |
| 1461 if (PauseRequestIfNeeded(info)) { | 1474 if (PauseRequestIfNeeded(info)) { |
| 1462 VLOG(1) << "OnResponseStarted pausing: " << request->url().spec(); | 1475 VLOG(1) << "OnResponseStarted pausing: " << request->url().spec(); |
| 1463 return; | 1476 return; |
| 1464 } | 1477 } |
| 1465 | 1478 |
| 1466 // We want to send a final upload progress message prior to sending | 1479 // We want to send a final upload progress message prior to sending |
| 1467 // the response complete message even if we're waiting for an ack to | 1480 // the response complete message even if we're waiting for an ack to |
| 1468 // to a previous upload progress message. | 1481 // to a previous upload progress message. |
| (...skipping 10 matching lines...) Expand all Loading... |
| 1479 } | 1492 } |
| 1480 | 1493 |
| 1481 StartReading(request); | 1494 StartReading(request); |
| 1482 } | 1495 } |
| 1483 } else { | 1496 } else { |
| 1484 ResponseCompleted(request); | 1497 ResponseCompleted(request); |
| 1485 } | 1498 } |
| 1486 } | 1499 } |
| 1487 | 1500 |
| 1488 bool ResourceDispatcherHost::CompleteResponseStarted(net::URLRequest* request) { | 1501 bool ResourceDispatcherHost::CompleteResponseStarted(net::URLRequest* request) { |
| 1489 ResourceDispatcherHostRequestInfo* info = InfoForRequest(request); | 1502 ResourceRequestInfoImpl* info = InfoForRequest(request); |
| 1490 | 1503 |
| 1491 scoped_refptr<ResourceResponse> response(new ResourceResponse); | 1504 scoped_refptr<ResourceResponse> response(new ResourceResponse); |
| 1492 PopulateResourceResponse(request, response); | 1505 PopulateResourceResponse(request, response); |
| 1493 | 1506 |
| 1494 if (request->ssl_info().cert) { | 1507 if (request->ssl_info().cert) { |
| 1495 int cert_id = | 1508 int cert_id = |
| 1496 CertStore::GetInstance()->StoreCert(request->ssl_info().cert, | 1509 CertStore::GetInstance()->StoreCert(request->ssl_info().cert, |
| 1497 info->child_id()); | 1510 info->GetChildID()); |
| 1498 response->security_info = content::SerializeSecurityInfo( | 1511 response->security_info = content::SerializeSecurityInfo( |
| 1499 cert_id, request->ssl_info().cert_status, | 1512 cert_id, request->ssl_info().cert_status, |
| 1500 request->ssl_info().security_bits, | 1513 request->ssl_info().security_bits, |
| 1501 request->ssl_info().connection_status); | 1514 request->ssl_info().connection_status); |
| 1502 } else { | 1515 } else { |
| 1503 // We should not have any SSL state. | 1516 // We should not have any SSL state. |
| 1504 DCHECK(!request->ssl_info().cert_status && | 1517 DCHECK(!request->ssl_info().cert_status && |
| 1505 request->ssl_info().security_bits == -1 && | 1518 request->ssl_info().security_bits == -1 && |
| 1506 !request->ssl_info().connection_status); | 1519 !request->ssl_info().connection_status); |
| 1507 } | 1520 } |
| 1508 | 1521 |
| 1509 NotifyResponseStarted(request, info->child_id()); | 1522 NotifyResponseStarted(request, info->GetChildID()); |
| 1510 info->set_called_on_response_started(true); | 1523 info->set_called_on_response_started(true); |
| 1511 return info->resource_handler()->OnResponseStarted(info->request_id(), | 1524 return info->resource_handler()->OnResponseStarted(info->GetRequestID(), |
| 1512 response.get()); | 1525 response.get()); |
| 1513 } | 1526 } |
| 1514 | 1527 |
| 1515 void ResourceDispatcherHost::CancelRequest(int child_id, | 1528 void ResourceDispatcherHost::CancelRequest(int child_id, |
| 1516 int request_id, | 1529 int request_id, |
| 1517 bool from_renderer) { | 1530 bool from_renderer) { |
| 1518 GlobalRequestID id(child_id, request_id); | 1531 GlobalRequestID id(child_id, request_id); |
| 1519 if (from_renderer) { | 1532 if (from_renderer) { |
| 1520 // When the old renderer dies, it sends a message to us to cancel its | 1533 // When the old renderer dies, it sends a message to us to cancel its |
| 1521 // requests. | 1534 // requests. |
| (...skipping 25 matching lines...) Expand all Loading... |
| 1547 request_id)); | 1560 request_id)); |
| 1548 } | 1561 } |
| 1549 } | 1562 } |
| 1550 | 1563 |
| 1551 bool ResourceDispatcherHost::CancelRequestInternal(net::URLRequest* request, | 1564 bool ResourceDispatcherHost::CancelRequestInternal(net::URLRequest* request, |
| 1552 bool from_renderer) { | 1565 bool from_renderer) { |
| 1553 VLOG(1) << "CancelRequest: " << request->url().spec(); | 1566 VLOG(1) << "CancelRequest: " << request->url().spec(); |
| 1554 | 1567 |
| 1555 // WebKit will send us a cancel for downloads since it no longer handles them. | 1568 // WebKit will send us a cancel for downloads since it no longer handles them. |
| 1556 // In this case, ignore the cancel since we handle downloads in the browser. | 1569 // In this case, ignore the cancel since we handle downloads in the browser. |
| 1557 ResourceDispatcherHostRequestInfo* info = InfoForRequest(request); | 1570 ResourceRequestInfoImpl* info = InfoForRequest(request); |
| 1558 if (!from_renderer || !info->is_download()) { | 1571 if (!from_renderer || !info->is_download()) { |
| 1559 if (info->login_delegate()) { | 1572 if (info->login_delegate()) { |
| 1560 info->login_delegate()->OnRequestCancelled(); | 1573 info->login_delegate()->OnRequestCancelled(); |
| 1561 info->set_login_delegate(NULL); | 1574 info->set_login_delegate(NULL); |
| 1562 } | 1575 } |
| 1563 if (info->ssl_client_auth_handler()) { | 1576 if (info->ssl_client_auth_handler()) { |
| 1564 info->ssl_client_auth_handler()->OnRequestCancelled(); | 1577 info->ssl_client_auth_handler()->OnRequestCancelled(); |
| 1565 info->set_ssl_client_auth_handler(NULL); | 1578 info->set_ssl_client_auth_handler(NULL); |
| 1566 } | 1579 } |
| 1567 request->Cancel(); | 1580 request->Cancel(); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1608 request->referrer().size() + | 1621 request->referrer().size() + |
| 1609 request->method().size(); | 1622 request->method().size(); |
| 1610 | 1623 |
| 1611 // Note that this expression will typically be dominated by: | 1624 // Note that this expression will typically be dominated by: |
| 1612 // |kAvgBytesPerOutstandingRequest|. | 1625 // |kAvgBytesPerOutstandingRequest|. |
| 1613 return kAvgBytesPerOutstandingRequest + strings_cost; | 1626 return kAvgBytesPerOutstandingRequest + strings_cost; |
| 1614 } | 1627 } |
| 1615 | 1628 |
| 1616 void ResourceDispatcherHost::BeginRequestInternal(net::URLRequest* request) { | 1629 void ResourceDispatcherHost::BeginRequestInternal(net::URLRequest* request) { |
| 1617 DCHECK(!request->is_pending()); | 1630 DCHECK(!request->is_pending()); |
| 1618 ResourceDispatcherHostRequestInfo* info = InfoForRequest(request); | 1631 ResourceRequestInfoImpl* info = InfoForRequest(request); |
| 1619 | 1632 |
| 1620 if ((TimeTicks::Now() - last_user_gesture_time_) < | 1633 if ((TimeTicks::Now() - last_user_gesture_time_) < |
| 1621 TimeDelta::FromMilliseconds(kUserGestureWindowMs)) { | 1634 TimeDelta::FromMilliseconds(kUserGestureWindowMs)) { |
| 1622 request->set_load_flags( | 1635 request->set_load_flags( |
| 1623 request->load_flags() | net::LOAD_MAYBE_USER_GESTURE); | 1636 request->load_flags() | net::LOAD_MAYBE_USER_GESTURE); |
| 1624 } | 1637 } |
| 1625 | 1638 |
| 1626 // Add the memory estimate that starting this request will consume. | 1639 // Add the memory estimate that starting this request will consume. |
| 1627 info->set_memory_cost(CalculateApproximateMemoryCost(request)); | 1640 info->set_memory_cost(CalculateApproximateMemoryCost(request)); |
| 1628 int memory_cost = IncrementOutstandingRequestsMemoryCost(info->memory_cost(), | 1641 int memory_cost = IncrementOutstandingRequestsMemoryCost(info->memory_cost(), |
| 1629 info->child_id()); | 1642 info->GetChildID()); |
| 1630 | 1643 |
| 1631 // If enqueing/starting this request will exceed our per-process memory | 1644 // If enqueing/starting this request will exceed our per-process memory |
| 1632 // bound, abort it right away. | 1645 // bound, abort it right away. |
| 1633 if (memory_cost > max_outstanding_requests_cost_per_process_) { | 1646 if (memory_cost > max_outstanding_requests_cost_per_process_) { |
| 1634 // We call "SimulateError()" as a way of setting the net::URLRequest's | 1647 // We call "SimulateError()" as a way of setting the net::URLRequest's |
| 1635 // status -- it has no effect beyond this, since the request hasn't started. | 1648 // status -- it has no effect beyond this, since the request hasn't started. |
| 1636 request->SimulateError(net::ERR_INSUFFICIENT_RESOURCES); | 1649 request->SimulateError(net::ERR_INSUFFICIENT_RESOURCES); |
| 1637 | 1650 |
| 1638 // TODO(eroman): this is kinda funky -- we insert the unstarted request into | 1651 // TODO(eroman): this is kinda funky -- we insert the unstarted request into |
| 1639 // |pending_requests_| simply to please ResponseCompleted(). | 1652 // |pending_requests_| simply to please ResponseCompleted(). |
| 1640 GlobalRequestID global_id(info->child_id(), info->request_id()); | 1653 GlobalRequestID global_id(info->GetChildID(), info->GetRequestID()); |
| 1641 pending_requests_[global_id] = request; | 1654 pending_requests_[global_id] = request; |
| 1642 ResponseCompleted(request); | 1655 ResponseCompleted(request); |
| 1643 return; | 1656 return; |
| 1644 } | 1657 } |
| 1645 | 1658 |
| 1646 std::pair<int, int> pair_id(info->child_id(), info->route_id()); | 1659 std::pair<int, int> pair_id(info->GetChildID(), info->GetRouteID()); |
| 1647 BlockedRequestMap::const_iterator iter = blocked_requests_map_.find(pair_id); | 1660 BlockedRequestMap::const_iterator iter = blocked_requests_map_.find(pair_id); |
| 1648 if (iter != blocked_requests_map_.end()) { | 1661 if (iter != blocked_requests_map_.end()) { |
| 1649 // The request should be blocked. | 1662 // The request should be blocked. |
| 1650 iter->second->push_back(request); | 1663 iter->second->push_back(request); |
| 1651 return; | 1664 return; |
| 1652 } | 1665 } |
| 1653 | 1666 |
| 1654 GlobalRequestID global_id(info->child_id(), info->request_id()); | 1667 GlobalRequestID global_id(info->GetChildID(), info->GetRequestID()); |
| 1655 pending_requests_[global_id] = request; | 1668 pending_requests_[global_id] = request; |
| 1656 | 1669 |
| 1657 // Give the resource handlers an opportunity to delay the net::URLRequest from | 1670 // Give the resource handlers an opportunity to delay the net::URLRequest from |
| 1658 // being started. | 1671 // being started. |
| 1659 // | 1672 // |
| 1660 // There are three cases: | 1673 // There are three cases: |
| 1661 // | 1674 // |
| 1662 // (1) if OnWillStart() returns false, the request is cancelled (regardless | 1675 // (1) if OnWillStart() returns false, the request is cancelled (regardless |
| 1663 // of whether |defer_start| was set). | 1676 // of whether |defer_start| was set). |
| 1664 // (2) If |defer_start| was set to true, then the request is not added | 1677 // (2) If |defer_start| was set to true, then the request is not added |
| 1665 // into the resource queue, and will only be started in response to | 1678 // into the resource queue, and will only be started in response to |
| 1666 // calling StartDeferredRequest(). | 1679 // calling StartDeferredRequest(). |
| 1667 // (3) If |defer_start| is not set, then the request is inserted into | 1680 // (3) If |defer_start| is not set, then the request is inserted into |
| 1668 // the resource_queue_ (which may pause it further, or start it). | 1681 // the resource_queue_ (which may pause it further, or start it). |
| 1669 bool defer_start = false; | 1682 bool defer_start = false; |
| 1670 if (!info->resource_handler()->OnWillStart( | 1683 if (!info->resource_handler()->OnWillStart( |
| 1671 info->request_id(), request->url(), | 1684 info->GetRequestID(), request->url(), |
| 1672 &defer_start)) { | 1685 &defer_start)) { |
| 1673 CancelRequestInternal(request, false); | 1686 CancelRequestInternal(request, false); |
| 1674 return; | 1687 return; |
| 1675 } | 1688 } |
| 1676 | 1689 |
| 1677 if (!defer_start) | 1690 if (!defer_start) |
| 1678 StartRequest(request); | 1691 StartRequest(request); |
| 1679 } | 1692 } |
| 1680 | 1693 |
| 1681 void ResourceDispatcherHost::StartRequest(net::URLRequest* request) { | 1694 void ResourceDispatcherHost::StartRequest(net::URLRequest* request) { |
| 1682 request->Start(); | 1695 request->Start(); |
| 1683 | 1696 |
| 1684 // Make sure we have the load state monitor running | 1697 // Make sure we have the load state monitor running |
| 1685 if (!update_load_states_timer_.IsRunning()) { | 1698 if (!update_load_states_timer_.IsRunning()) { |
| 1686 update_load_states_timer_.Start(FROM_HERE, | 1699 update_load_states_timer_.Start(FROM_HERE, |
| 1687 TimeDelta::FromMilliseconds(kUpdateLoadStatesIntervalMsec), | 1700 TimeDelta::FromMilliseconds(kUpdateLoadStatesIntervalMsec), |
| 1688 this, &ResourceDispatcherHost::UpdateLoadStates); | 1701 this, &ResourceDispatcherHost::UpdateLoadStates); |
| 1689 } | 1702 } |
| 1690 } | 1703 } |
| 1691 | 1704 |
| 1692 bool ResourceDispatcherHost::PauseRequestIfNeeded( | 1705 bool ResourceDispatcherHost::PauseRequestIfNeeded( |
| 1693 ResourceDispatcherHostRequestInfo* info) { | 1706 ResourceRequestInfoImpl* info) { |
| 1694 if (info->pause_count() > 0) | 1707 if (info->pause_count() > 0) |
| 1695 info->set_is_paused(true); | 1708 info->set_is_paused(true); |
| 1696 return info->is_paused(); | 1709 return info->is_paused(); |
| 1697 } | 1710 } |
| 1698 | 1711 |
| 1699 void ResourceDispatcherHost::ResumeRequest(const GlobalRequestID& request_id) { | 1712 void ResourceDispatcherHost::ResumeRequest(const GlobalRequestID& request_id) { |
| 1700 PendingRequestList::iterator i = pending_requests_.find(request_id); | 1713 PendingRequestList::iterator i = pending_requests_.find(request_id); |
| 1701 if (i == pending_requests_.end()) // The request may have been destroyed | 1714 if (i == pending_requests_.end()) // The request may have been destroyed |
| 1702 return; | 1715 return; |
| 1703 | 1716 |
| 1704 net::URLRequest* request = i->second; | 1717 net::URLRequest* request = i->second; |
| 1705 ResourceDispatcherHostRequestInfo* info = InfoForRequest(request); | 1718 ResourceRequestInfoImpl* info = InfoForRequest(request); |
| 1706 | 1719 |
| 1707 // We may already be unpaused, or the pause count may have increased since we | 1720 // We may already be unpaused, or the pause count may have increased since we |
| 1708 // posted the task to call ResumeRequest. | 1721 // posted the task to call ResumeRequest. |
| 1709 if (!info->is_paused()) | 1722 if (!info->is_paused()) |
| 1710 return; | 1723 return; |
| 1711 info->set_is_paused(false); | 1724 info->set_is_paused(false); |
| 1712 if (PauseRequestIfNeeded(info)) | 1725 if (PauseRequestIfNeeded(info)) |
| 1713 return; | 1726 return; |
| 1714 | 1727 |
| 1715 VLOG(1) << "Resuming: \"" << i->second->url().spec() << "\"" | 1728 VLOG(1) << "Resuming: \"" << i->second->url().spec() << "\"" |
| (...skipping 18 matching lines...) Expand all Loading... |
| 1734 if (Read(request, &bytes_read)) { | 1747 if (Read(request, &bytes_read)) { |
| 1735 OnReadCompleted(request, bytes_read); | 1748 OnReadCompleted(request, bytes_read); |
| 1736 } else if (!request->status().is_io_pending()) { | 1749 } else if (!request->status().is_io_pending()) { |
| 1737 DCHECK(!InfoForRequest(request)->is_paused()); | 1750 DCHECK(!InfoForRequest(request)->is_paused()); |
| 1738 // If the error is not an IO pending, then we're done reading. | 1751 // If the error is not an IO pending, then we're done reading. |
| 1739 ResponseCompleted(request); | 1752 ResponseCompleted(request); |
| 1740 } | 1753 } |
| 1741 } | 1754 } |
| 1742 | 1755 |
| 1743 bool ResourceDispatcherHost::Read(net::URLRequest* request, int* bytes_read) { | 1756 bool ResourceDispatcherHost::Read(net::URLRequest* request, int* bytes_read) { |
| 1744 ResourceDispatcherHostRequestInfo* info = InfoForRequest(request); | 1757 ResourceRequestInfoImpl* info = InfoForRequest(request); |
| 1745 DCHECK(!info->is_paused()); | 1758 DCHECK(!info->is_paused()); |
| 1746 | 1759 |
| 1747 net::IOBuffer* buf; | 1760 net::IOBuffer* buf; |
| 1748 int buf_size; | 1761 int buf_size; |
| 1749 if (!info->resource_handler()->OnWillRead(info->request_id(), | 1762 if (!info->resource_handler()->OnWillRead(info->GetRequestID(), |
| 1750 &buf, &buf_size, -1)) { | 1763 &buf, &buf_size, -1)) { |
| 1751 return false; | 1764 return false; |
| 1752 } | 1765 } |
| 1753 | 1766 |
| 1754 DCHECK(buf); | 1767 DCHECK(buf); |
| 1755 DCHECK(buf_size > 0); | 1768 DCHECK(buf_size > 0); |
| 1756 | 1769 |
| 1757 info->set_has_started_reading(true); | 1770 info->set_has_started_reading(true); |
| 1758 return request->Read(buf, buf_size, bytes_read); | 1771 return request->Read(buf, buf_size, bytes_read); |
| 1759 } | 1772 } |
| 1760 | 1773 |
| 1761 void ResourceDispatcherHost::OnReadCompleted(net::URLRequest* request, | 1774 void ResourceDispatcherHost::OnReadCompleted(net::URLRequest* request, |
| 1762 int bytes_read) { | 1775 int bytes_read) { |
| 1763 DCHECK(request); | 1776 DCHECK(request); |
| 1764 VLOG(1) << "OnReadCompleted: \"" << request->url().spec() << "\"" | 1777 VLOG(1) << "OnReadCompleted: \"" << request->url().spec() << "\"" |
| 1765 << " bytes_read = " << bytes_read; | 1778 << " bytes_read = " << bytes_read; |
| 1766 ResourceDispatcherHostRequestInfo* info = InfoForRequest(request); | 1779 ResourceRequestInfoImpl* info = InfoForRequest(request); |
| 1767 | 1780 |
| 1768 // bytes_read == -1 always implies an error, so we want to skip the pause | 1781 // bytes_read == -1 always implies an error, so we want to skip the pause |
| 1769 // checks and just call ResponseCompleted. | 1782 // checks and just call ResponseCompleted. |
| 1770 if (bytes_read == -1) { | 1783 if (bytes_read == -1) { |
| 1771 DCHECK(!request->status().is_success()); | 1784 DCHECK(!request->status().is_success()); |
| 1772 | 1785 |
| 1773 ResponseCompleted(request); | 1786 ResponseCompleted(request); |
| 1774 return; | 1787 return; |
| 1775 } | 1788 } |
| 1776 | 1789 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 1795 CompleteRead(request, &bytes_read); | 1808 CompleteRead(request, &bytes_read); |
| 1796 } else { | 1809 } else { |
| 1797 // Force the next CompleteRead / Read pair to run as a separate task. | 1810 // Force the next CompleteRead / Read pair to run as a separate task. |
| 1798 // This avoids a fast, large network request from monopolizing the IO | 1811 // This avoids a fast, large network request from monopolizing the IO |
| 1799 // thread and starving other IO operations from running. | 1812 // thread and starving other IO operations from running. |
| 1800 VLOG(1) << "OnReadCompleted postponing: \"" | 1813 VLOG(1) << "OnReadCompleted postponing: \"" |
| 1801 << request->url().spec() << "\"" | 1814 << request->url().spec() << "\"" |
| 1802 << " bytes_read = " << bytes_read; | 1815 << " bytes_read = " << bytes_read; |
| 1803 info->set_paused_read_bytes(bytes_read); | 1816 info->set_paused_read_bytes(bytes_read); |
| 1804 info->set_is_paused(true); | 1817 info->set_is_paused(true); |
| 1805 GlobalRequestID id(info->child_id(), info->request_id()); | 1818 GlobalRequestID id(info->GetChildID(), info->GetRequestID()); |
| 1806 MessageLoop::current()->PostTask( | 1819 MessageLoop::current()->PostTask( |
| 1807 FROM_HERE, | 1820 FROM_HERE, |
| 1808 base::Bind( | 1821 base::Bind( |
| 1809 &ResourceDispatcherHost::ResumeRequest, | 1822 &ResourceDispatcherHost::ResumeRequest, |
| 1810 weak_factory_.GetWeakPtr(), id)); | 1823 weak_factory_.GetWeakPtr(), id)); |
| 1811 return; | 1824 return; |
| 1812 } | 1825 } |
| 1813 } | 1826 } |
| 1814 } | 1827 } |
| 1815 | 1828 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 1827 ResponseCompleted(request); | 1840 ResponseCompleted(request); |
| 1828 } | 1841 } |
| 1829 | 1842 |
| 1830 bool ResourceDispatcherHost::CompleteRead(net::URLRequest* request, | 1843 bool ResourceDispatcherHost::CompleteRead(net::URLRequest* request, |
| 1831 int* bytes_read) { | 1844 int* bytes_read) { |
| 1832 if (!request || !request->status().is_success()) { | 1845 if (!request || !request->status().is_success()) { |
| 1833 NOTREACHED(); | 1846 NOTREACHED(); |
| 1834 return false; | 1847 return false; |
| 1835 } | 1848 } |
| 1836 | 1849 |
| 1837 ResourceDispatcherHostRequestInfo* info = InfoForRequest(request); | 1850 ResourceRequestInfoImpl* info = InfoForRequest(request); |
| 1838 if (!info->resource_handler()->OnReadCompleted(info->request_id(), | 1851 if (!info->resource_handler()->OnReadCompleted(info->GetRequestID(), |
| 1839 bytes_read)) { | 1852 bytes_read)) { |
| 1840 CancelRequestInternal(request, false); | 1853 CancelRequestInternal(request, false); |
| 1841 return false; | 1854 return false; |
| 1842 } | 1855 } |
| 1843 | 1856 |
| 1844 return *bytes_read != 0; | 1857 return *bytes_read != 0; |
| 1845 } | 1858 } |
| 1846 | 1859 |
| 1847 void ResourceDispatcherHost::ResponseCompleted(net::URLRequest* request) { | 1860 void ResourceDispatcherHost::ResponseCompleted(net::URLRequest* request) { |
| 1848 VLOG(1) << "ResponseCompleted: " << request->url().spec(); | 1861 VLOG(1) << "ResponseCompleted: " << request->url().spec(); |
| 1849 ResourceDispatcherHostRequestInfo* info = InfoForRequest(request); | 1862 ResourceRequestInfoImpl* info = InfoForRequest(request); |
| 1850 | 1863 |
| 1851 // If the load for a main frame has failed, track it in a histogram, | 1864 // If the load for a main frame has failed, track it in a histogram, |
| 1852 // since it will probably cause the user to see an error page. | 1865 // since it will probably cause the user to see an error page. |
| 1853 if (!request->status().is_success() && | 1866 if (!request->status().is_success() && |
| 1854 info->resource_type() == ResourceType::MAIN_FRAME && | 1867 info->GetResourceType() == ResourceType::MAIN_FRAME && |
| 1855 request->status().error() != net::ERR_ABORTED) { | 1868 request->status().error() != net::ERR_ABORTED) { |
| 1856 // This enumeration has "2" appended to its name to distinguish it from | 1869 // This enumeration has "2" appended to its name to distinguish it from |
| 1857 // its original version. We changed the buckets at one point (added | 1870 // its original version. We changed the buckets at one point (added |
| 1858 // guard buckets by using CustomHistogram::ArrayToCustomRanges). | 1871 // guard buckets by using CustomHistogram::ArrayToCustomRanges). |
| 1859 UMA_HISTOGRAM_CUSTOM_ENUMERATION( | 1872 UMA_HISTOGRAM_CUSTOM_ENUMERATION( |
| 1860 "Net.ErrorCodesForMainFrame2", | 1873 "Net.ErrorCodesForMainFrame2", |
| 1861 -request->status().error(), | 1874 -request->status().error(), |
| 1862 base::CustomHistogram::ArrayToCustomRanges( | 1875 base::CustomHistogram::ArrayToCustomRanges( |
| 1863 kAllNetErrorCodes, arraysize(kAllNetErrorCodes))); | 1876 kAllNetErrorCodes, arraysize(kAllNetErrorCodes))); |
| 1864 | 1877 |
| 1865 if (request->url().SchemeIsSecure() && | 1878 if (request->url().SchemeIsSecure() && |
| 1866 request->url().host() == "www.google.com") { | 1879 request->url().host() == "www.google.com") { |
| 1867 UMA_HISTOGRAM_CUSTOM_ENUMERATION( | 1880 UMA_HISTOGRAM_CUSTOM_ENUMERATION( |
| 1868 "Net.ErrorCodesForHTTPSGoogleMainFrame", | 1881 "Net.ErrorCodesForHTTPSGoogleMainFrame", |
| 1869 -request->status().error(), | 1882 -request->status().error(), |
| 1870 base::CustomHistogram::ArrayToCustomRanges( | 1883 base::CustomHistogram::ArrayToCustomRanges( |
| 1871 kAllNetErrorCodes, arraysize(kAllNetErrorCodes))); | 1884 kAllNetErrorCodes, arraysize(kAllNetErrorCodes))); |
| 1872 } | 1885 } |
| 1873 } | 1886 } |
| 1874 | 1887 |
| 1875 std::string security_info; | 1888 std::string security_info; |
| 1876 const net::SSLInfo& ssl_info = request->ssl_info(); | 1889 const net::SSLInfo& ssl_info = request->ssl_info(); |
| 1877 if (ssl_info.cert != NULL) { | 1890 if (ssl_info.cert != NULL) { |
| 1878 int cert_id = CertStore::GetInstance()->StoreCert(ssl_info.cert, | 1891 int cert_id = CertStore::GetInstance()->StoreCert(ssl_info.cert, |
| 1879 info->child_id()); | 1892 info->GetChildID()); |
| 1880 security_info = content::SerializeSecurityInfo( | 1893 security_info = content::SerializeSecurityInfo( |
| 1881 cert_id, ssl_info.cert_status, ssl_info.security_bits, | 1894 cert_id, ssl_info.cert_status, ssl_info.security_bits, |
| 1882 ssl_info.connection_status); | 1895 ssl_info.connection_status); |
| 1883 } | 1896 } |
| 1884 | 1897 |
| 1885 if (info->resource_handler()->OnResponseCompleted(info->request_id(), | 1898 if (info->resource_handler()->OnResponseCompleted(info->GetRequestID(), |
| 1886 request->status(), | 1899 request->status(), |
| 1887 security_info)) { | 1900 security_info)) { |
| 1888 | 1901 |
| 1889 // The request is complete so we can remove it. | 1902 // The request is complete so we can remove it. |
| 1890 RemovePendingRequest(info->child_id(), info->request_id()); | 1903 RemovePendingRequest(info->GetChildID(), info->GetRequestID()); |
| 1891 } | 1904 } |
| 1892 // If the handler's OnResponseCompleted returns false, we are deferring the | 1905 // If the handler's OnResponseCompleted returns false, we are deferring the |
| 1893 // call until later. We will notify the world and clean up when we resume. | 1906 // call until later. We will notify the world and clean up when we resume. |
| 1894 } | 1907 } |
| 1895 | 1908 |
| 1896 void ResourceDispatcherHost::CallResponseCompleted(int child_id, | 1909 void ResourceDispatcherHost::CallResponseCompleted(int child_id, |
| 1897 int request_id) { | 1910 int request_id) { |
| 1898 PendingRequestList::iterator i = pending_requests_.find( | 1911 PendingRequestList::iterator i = pending_requests_.find( |
| 1899 GlobalRequestID(child_id, request_id)); | 1912 GlobalRequestID(child_id, request_id)); |
| 1900 if (i != pending_requests_.end()) | 1913 if (i != pending_requests_.end()) |
| 1901 ResponseCompleted(i->second); | 1914 ResponseCompleted(i->second); |
| 1902 } | 1915 } |
| 1903 | 1916 |
| 1904 void ResourceDispatcherHost::OnUserGesture(TabContents* tab) { | 1917 void ResourceDispatcherHost::OnUserGesture(TabContents* tab) { |
| 1905 last_user_gesture_time_ = TimeTicks::Now(); | 1918 last_user_gesture_time_ = TimeTicks::Now(); |
| 1906 } | 1919 } |
| 1907 | 1920 |
| 1908 // static | 1921 // static |
| 1909 ResourceDispatcherHostRequestInfo* ResourceDispatcherHost::InfoForRequest( | 1922 ResourceRequestInfoImpl* ResourceDispatcherHost::InfoForRequest( |
| 1910 net::URLRequest* request) { | 1923 net::URLRequest* request) { |
| 1911 // Avoid writing this function twice by casting the const version. | 1924 // Avoid writing this function twice by casting the const version. |
| 1912 const net::URLRequest* const_request = request; | 1925 const net::URLRequest* const_request = request; |
| 1913 return const_cast<ResourceDispatcherHostRequestInfo*>( | 1926 return const_cast<ResourceRequestInfoImpl*>( |
| 1914 InfoForRequest(const_request)); | 1927 InfoForRequest(const_request)); |
| 1915 } | 1928 } |
| 1916 | 1929 |
| 1917 // static | 1930 // static |
| 1918 const ResourceDispatcherHostRequestInfo* ResourceDispatcherHost::InfoForRequest( | 1931 const ResourceRequestInfoImpl* ResourceDispatcherHost::InfoForRequest( |
| 1919 const net::URLRequest* request) { | 1932 const net::URLRequest* request) { |
| 1920 const ResourceDispatcherHostRequestInfo* info = | 1933 return static_cast<const ResourceRequestInfoImpl*>( |
| 1921 static_cast<const ResourceDispatcherHostRequestInfo*>( | 1934 ResourceRequestInfo::ForRequest(request)); |
| 1922 request->GetUserData(NULL)); | |
| 1923 return info; | |
| 1924 } | 1935 } |
| 1925 | 1936 |
| 1926 // static | 1937 // static |
| 1927 bool ResourceDispatcherHost::RenderViewForRequest( | 1938 bool ResourceDispatcherHost::RenderViewForRequest( |
| 1928 const net::URLRequest* request, | 1939 const net::URLRequest* request, |
| 1929 int* render_process_host_id, | 1940 int* render_process_id, |
| 1930 int* render_view_host_id) { | 1941 int* render_view_id) { |
| 1931 const ResourceDispatcherHostRequestInfo* info = InfoForRequest(request); | 1942 const ResourceRequestInfoImpl* info = InfoForRequest(request); |
| 1932 if (!info) { | 1943 if (!info) { |
| 1933 *render_process_host_id = -1; | 1944 *render_process_id = -1; |
| 1934 *render_view_host_id = -1; | 1945 *render_view_id = -1; |
| 1935 return false; | 1946 return false; |
| 1936 } | 1947 } |
| 1937 | 1948 |
| 1938 // If the request is from the worker process, find a tab that owns the worker. | 1949 return info->GetAssociatedRenderView(render_process_id, render_view_id); |
| 1939 if (info->process_type() == content::PROCESS_TYPE_WORKER) { | |
| 1940 // Need to display some related UI for this network request - pick an | |
| 1941 // arbitrary parent to do so. | |
| 1942 if (!WorkerServiceImpl::GetInstance()->GetRendererForWorker( | |
| 1943 info->child_id(), render_process_host_id, render_view_host_id)) { | |
| 1944 *render_process_host_id = -1; | |
| 1945 *render_view_host_id = -1; | |
| 1946 return false; | |
| 1947 } | |
| 1948 } else { | |
| 1949 *render_process_host_id = info->child_id(); | |
| 1950 *render_view_host_id = info->route_id(); | |
| 1951 } | |
| 1952 return true; | |
| 1953 } | 1950 } |
| 1954 | 1951 |
| 1955 net::URLRequest* ResourceDispatcherHost::GetURLRequest( | 1952 net::URLRequest* ResourceDispatcherHost::GetURLRequest( |
| 1956 const GlobalRequestID& request_id) const { | 1953 const GlobalRequestID& request_id) const { |
| 1957 // This should be running in the IO loop. | 1954 // This should be running in the IO loop. |
| 1958 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 1955 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 1959 | 1956 |
| 1960 PendingRequestList::const_iterator i = pending_requests_.find(request_id); | 1957 PendingRequestList::const_iterator i = pending_requests_.find(request_id); |
| 1961 if (i == pending_requests_.end()) | 1958 if (i == pending_requests_.end()) |
| 1962 return NULL; | 1959 return NULL; |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2080 // thread where they can be passed along to the respective RVHs. | 2077 // thread where they can be passed along to the respective RVHs. |
| 2081 LoadInfoMap info_map; | 2078 LoadInfoMap info_map; |
| 2082 | 2079 |
| 2083 PendingRequestList::const_iterator i; | 2080 PendingRequestList::const_iterator i; |
| 2084 | 2081 |
| 2085 // Determine the largest upload size of all requests | 2082 // Determine the largest upload size of all requests |
| 2086 // in each View (good chance it's zero). | 2083 // in each View (good chance it's zero). |
| 2087 std::map<std::pair<int, int>, uint64> largest_upload_size; | 2084 std::map<std::pair<int, int>, uint64> largest_upload_size; |
| 2088 for (i = pending_requests_.begin(); i != pending_requests_.end(); ++i) { | 2085 for (i = pending_requests_.begin(); i != pending_requests_.end(); ++i) { |
| 2089 net::URLRequest* request = i->second; | 2086 net::URLRequest* request = i->second; |
| 2090 ResourceDispatcherHostRequestInfo* info = InfoForRequest(request); | 2087 ResourceRequestInfoImpl* info = InfoForRequest(request); |
| 2091 uint64 upload_size = info->upload_size(); | 2088 uint64 upload_size = info->GetUploadSize(); |
| 2092 if (request->GetLoadState().state != net::LOAD_STATE_SENDING_REQUEST) | 2089 if (request->GetLoadState().state != net::LOAD_STATE_SENDING_REQUEST) |
| 2093 upload_size = 0; | 2090 upload_size = 0; |
| 2094 std::pair<int, int> key(info->child_id(), info->route_id()); | 2091 std::pair<int, int> key(info->GetChildID(), info->GetRouteID()); |
| 2095 if (upload_size && largest_upload_size[key] < upload_size) | 2092 if (upload_size && largest_upload_size[key] < upload_size) |
| 2096 largest_upload_size[key] = upload_size; | 2093 largest_upload_size[key] = upload_size; |
| 2097 } | 2094 } |
| 2098 | 2095 |
| 2099 for (i = pending_requests_.begin(); i != pending_requests_.end(); ++i) { | 2096 for (i = pending_requests_.begin(); i != pending_requests_.end(); ++i) { |
| 2100 net::URLRequest* request = i->second; | 2097 net::URLRequest* request = i->second; |
| 2101 net::LoadStateWithParam load_state = request->GetLoadState(); | 2098 net::LoadStateWithParam load_state = request->GetLoadState(); |
| 2102 ResourceDispatcherHostRequestInfo* info = InfoForRequest(request); | 2099 ResourceRequestInfoImpl* info = InfoForRequest(request); |
| 2103 std::pair<int, int> key(info->child_id(), info->route_id()); | 2100 std::pair<int, int> key(info->GetChildID(), info->GetRouteID()); |
| 2104 | 2101 |
| 2105 // We also poll for upload progress on this timer and send upload | 2102 // We also poll for upload progress on this timer and send upload |
| 2106 // progress ipc messages to the plugin process. | 2103 // progress ipc messages to the plugin process. |
| 2107 MaybeUpdateUploadProgress(info, request); | 2104 MaybeUpdateUploadProgress(info, request); |
| 2108 | 2105 |
| 2109 // If a request is uploading data, ignore all other requests so that the | 2106 // If a request is uploading data, ignore all other requests so that the |
| 2110 // upload progress takes priority for being shown in the status bar. | 2107 // upload progress takes priority for being shown in the status bar. |
| 2111 if (largest_upload_size.find(key) != largest_upload_size.end() && | 2108 if (largest_upload_size.find(key) != largest_upload_size.end() && |
| 2112 info->upload_size() < largest_upload_size[key]) | 2109 info->GetUploadSize() < largest_upload_size[key]) |
| 2113 continue; | 2110 continue; |
| 2114 | 2111 |
| 2115 net::LoadStateWithParam to_insert = load_state; | 2112 net::LoadStateWithParam to_insert = load_state; |
| 2116 LoadInfoMap::iterator existing = info_map.find(key); | 2113 LoadInfoMap::iterator existing = info_map.find(key); |
| 2117 if (existing != info_map.end()) { | 2114 if (existing != info_map.end()) { |
| 2118 to_insert = | 2115 to_insert = |
| 2119 MoreInterestingLoadState(existing->second.load_state, load_state); | 2116 MoreInterestingLoadState(existing->second.load_state, load_state); |
| 2120 if (to_insert.state == existing->second.load_state.state) | 2117 if (to_insert.state == existing->second.load_state.state) |
| 2121 continue; | 2118 continue; |
| 2122 } | 2119 } |
| 2123 LoadInfo& load_info = info_map[key]; | 2120 LoadInfo& load_info = info_map[key]; |
| 2124 load_info.url = request->url(); | 2121 load_info.url = request->url(); |
| 2125 load_info.load_state = to_insert; | 2122 load_info.load_state = to_insert; |
| 2126 load_info.upload_size = info->upload_size(); | 2123 load_info.upload_size = info->GetUploadSize(); |
| 2127 load_info.upload_position = request->GetUploadProgress(); | 2124 load_info.upload_position = request->GetUploadProgress(); |
| 2128 } | 2125 } |
| 2129 | 2126 |
| 2130 if (info_map.empty()) | 2127 if (info_map.empty()) |
| 2131 return; | 2128 return; |
| 2132 | 2129 |
| 2133 BrowserThread::PostTask( | 2130 BrowserThread::PostTask( |
| 2134 BrowserThread::UI, FROM_HERE, | 2131 BrowserThread::UI, FROM_HERE, |
| 2135 base::Bind(&LoadInfoUpdateCallback, info_map)); | 2132 base::Bind(&LoadInfoUpdateCallback, info_map)); |
| 2136 } | 2133 } |
| 2137 | 2134 |
| 2138 // Calls the ResourceHandler to send upload progress messages to the renderer. | 2135 // Calls the ResourceHandler to send upload progress messages to the renderer. |
| 2139 void ResourceDispatcherHost::MaybeUpdateUploadProgress( | 2136 void ResourceDispatcherHost::MaybeUpdateUploadProgress( |
| 2140 ResourceDispatcherHostRequestInfo *info, | 2137 ResourceRequestInfoImpl *info, |
| 2141 net::URLRequest *request) { | 2138 net::URLRequest *request) { |
| 2142 | 2139 |
| 2143 if (!info->upload_size() || info->waiting_for_upload_progress_ack()) | 2140 if (!info->GetUploadSize() || info->waiting_for_upload_progress_ack()) |
| 2144 return; | 2141 return; |
| 2145 | 2142 |
| 2146 uint64 size = info->upload_size(); | 2143 uint64 size = info->GetUploadSize(); |
| 2147 uint64 position = request->GetUploadProgress(); | 2144 uint64 position = request->GetUploadProgress(); |
| 2148 if (position == info->last_upload_position()) | 2145 if (position == info->last_upload_position()) |
| 2149 return; // no progress made since last time | 2146 return; // no progress made since last time |
| 2150 | 2147 |
| 2151 const uint64 kHalfPercentIncrements = 200; | 2148 const uint64 kHalfPercentIncrements = 200; |
| 2152 const TimeDelta kOneSecond = TimeDelta::FromMilliseconds(1000); | 2149 const TimeDelta kOneSecond = TimeDelta::FromMilliseconds(1000); |
| 2153 | 2150 |
| 2154 uint64 amt_since_last = position - info->last_upload_position(); | 2151 uint64 amt_since_last = position - info->last_upload_position(); |
| 2155 TimeDelta time_since_last = TimeTicks::Now() - info->last_upload_ticks(); | 2152 TimeDelta time_since_last = TimeTicks::Now() - info->last_upload_ticks(); |
| 2156 | 2153 |
| 2157 bool is_finished = (size == position); | 2154 bool is_finished = (size == position); |
| 2158 bool enough_new_progress = (amt_since_last > (size / kHalfPercentIncrements)); | 2155 bool enough_new_progress = (amt_since_last > (size / kHalfPercentIncrements)); |
| 2159 bool too_much_time_passed = time_since_last > kOneSecond; | 2156 bool too_much_time_passed = time_since_last > kOneSecond; |
| 2160 | 2157 |
| 2161 if (is_finished || enough_new_progress || too_much_time_passed) { | 2158 if (is_finished || enough_new_progress || too_much_time_passed) { |
| 2162 if (request->load_flags() & net::LOAD_ENABLE_UPLOAD_PROGRESS) { | 2159 if (request->load_flags() & net::LOAD_ENABLE_UPLOAD_PROGRESS) { |
| 2163 info->resource_handler()->OnUploadProgress(info->request_id(), | 2160 info->resource_handler()->OnUploadProgress(info->GetRequestID(), |
| 2164 position, size); | 2161 position, size); |
| 2165 info->set_waiting_for_upload_progress_ack(true); | 2162 info->set_waiting_for_upload_progress_ack(true); |
| 2166 } | 2163 } |
| 2167 info->set_last_upload_ticks(TimeTicks::Now()); | 2164 info->set_last_upload_ticks(TimeTicks::Now()); |
| 2168 info->set_last_upload_position(position); | 2165 info->set_last_upload_position(position); |
| 2169 } | 2166 } |
| 2170 } | 2167 } |
| 2171 | 2168 |
| 2172 void ResourceDispatcherHost::BlockRequestsForRoute(int child_id, int route_id) { | 2169 void ResourceDispatcherHost::BlockRequestsForRoute(int child_id, int route_id) { |
| 2173 std::pair<int, int> key(child_id, route_id); | 2170 std::pair<int, int> key(child_id, route_id); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 2201 BlockedRequestsList* requests = iter->second; | 2198 BlockedRequestsList* requests = iter->second; |
| 2202 | 2199 |
| 2203 // Removing the vector from the map unblocks any subsequent requests. | 2200 // Removing the vector from the map unblocks any subsequent requests. |
| 2204 blocked_requests_map_.erase(iter); | 2201 blocked_requests_map_.erase(iter); |
| 2205 | 2202 |
| 2206 for (BlockedRequestsList::iterator req_iter = requests->begin(); | 2203 for (BlockedRequestsList::iterator req_iter = requests->begin(); |
| 2207 req_iter != requests->end(); ++req_iter) { | 2204 req_iter != requests->end(); ++req_iter) { |
| 2208 // Remove the memory credit that we added when pushing the request onto | 2205 // Remove the memory credit that we added when pushing the request onto |
| 2209 // the blocked list. | 2206 // the blocked list. |
| 2210 net::URLRequest* request = *req_iter; | 2207 net::URLRequest* request = *req_iter; |
| 2211 ResourceDispatcherHostRequestInfo* info = InfoForRequest(request); | 2208 ResourceRequestInfoImpl* info = InfoForRequest(request); |
| 2212 IncrementOutstandingRequestsMemoryCost(-1 * info->memory_cost(), | 2209 IncrementOutstandingRequestsMemoryCost(-1 * info->memory_cost(), |
| 2213 info->child_id()); | 2210 info->GetChildID()); |
| 2214 if (cancel_requests) | 2211 if (cancel_requests) |
| 2215 delete request; | 2212 delete request; |
| 2216 else | 2213 else |
| 2217 BeginRequestInternal(request); | 2214 BeginRequestInternal(request); |
| 2218 } | 2215 } |
| 2219 | 2216 |
| 2220 delete requests; | 2217 delete requests; |
| 2221 } | 2218 } |
| 2222 | 2219 |
| 2223 bool ResourceDispatcherHost::IsValidRequest(net::URLRequest* request) { | 2220 bool ResourceDispatcherHost::IsValidRequest(net::URLRequest* request) { |
| 2224 if (!request) | 2221 if (!request) |
| 2225 return false; | 2222 return false; |
| 2226 ResourceDispatcherHostRequestInfo* info = InfoForRequest(request); | 2223 ResourceRequestInfoImpl* info = InfoForRequest(request); |
| 2227 return pending_requests_.find( | 2224 return pending_requests_.find( |
| 2228 GlobalRequestID(info->child_id(), info->request_id())) != | 2225 GlobalRequestID(info->GetChildID(), info->GetRequestID())) != |
| 2229 pending_requests_.end(); | 2226 pending_requests_.end(); |
| 2230 } | 2227 } |
| 2231 | 2228 |
| 2232 // static | 2229 // static |
| 2233 bool ResourceDispatcherHost::is_prefetch_enabled() { | 2230 bool ResourceDispatcherHost::is_prefetch_enabled() { |
| 2234 return is_prefetch_enabled_; | 2231 return is_prefetch_enabled_; |
| 2235 } | 2232 } |
| 2236 | 2233 |
| 2237 // static | 2234 // static |
| 2238 void ResourceDispatcherHost::set_is_prefetch_enabled(bool value) { | 2235 void ResourceDispatcherHost::set_is_prefetch_enabled(bool value) { |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2272 net::URLRequest* transferred_request) { | 2269 net::URLRequest* transferred_request) { |
| 2273 transferred_navigations_[transferred_request_id] = transferred_request; | 2270 transferred_navigations_[transferred_request_id] = transferred_request; |
| 2274 | 2271 |
| 2275 // If a URLRequest is transferred to a new RenderViewHost, its | 2272 // If a URLRequest is transferred to a new RenderViewHost, its |
| 2276 // ResourceHandlers should not receive any notifications because they may | 2273 // ResourceHandlers should not receive any notifications because they may |
| 2277 // depend on the state of the old RVH. We set a ResourceHandler that only | 2274 // depend on the state of the old RVH. We set a ResourceHandler that only |
| 2278 // allows canceling requests, because on shutdown of the RDH all pending | 2275 // allows canceling requests, because on shutdown of the RDH all pending |
| 2279 // requests are canceled. The RVH of requests that are being transferred may | 2276 // requests are canceled. The RVH of requests that are being transferred may |
| 2280 // be gone by that time. If the request is resumed, the ResoureHandlers are | 2277 // be gone by that time. If the request is resumed, the ResoureHandlers are |
| 2281 // substituted again. | 2278 // substituted again. |
| 2282 ResourceDispatcherHostRequestInfo* info = InfoForRequest(transferred_request); | 2279 ResourceRequestInfoImpl* info = InfoForRequest(transferred_request); |
| 2283 scoped_refptr<ResourceHandler> transferred_resource_handler( | 2280 scoped_refptr<ResourceHandler> transferred_resource_handler( |
| 2284 new DoomedResourceHandler(info->resource_handler())); | 2281 new DoomedResourceHandler(info->resource_handler())); |
| 2285 info->set_resource_handler(transferred_resource_handler.get()); | 2282 info->set_resource_handler(transferred_resource_handler.get()); |
| 2286 } | 2283 } |
| 2287 | 2284 |
| 2288 bool ResourceDispatcherHost::IsTransferredNavigation( | 2285 bool ResourceDispatcherHost::IsTransferredNavigation( |
| 2289 const content::GlobalRequestID& transferred_request_id) const { | 2286 const content::GlobalRequestID& transferred_request_id) const { |
| 2290 return transferred_navigations_.find(transferred_request_id) != | 2287 return transferred_navigations_.find(transferred_request_id) != |
| 2291 transferred_navigations_.end(); | 2288 transferred_navigations_.end(); |
| 2292 } | 2289 } |
| OLD | NEW |