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

Side by Side Diff: chrome/browser/renderer_host/resource_dispatcher_host.cc

Issue 5384002: net: Remove typedef net::URLRequest URLRequest; (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: review Created 10 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 "chrome/browser/renderer_host/resource_dispatcher_host.h" 7 #include "chrome/browser/renderer_host/resource_dispatcher_host.h"
8 8
9 #include <vector> 9 #include <vector>
10 10
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 NOTREACHED() << "Denied unauthorized upload of " 150 NOTREACHED() << "Denied unauthorized upload of "
151 << iter->file_path().value(); 151 << iter->file_path().value();
152 return false; 152 return false;
153 } 153 }
154 } 154 }
155 } 155 }
156 156
157 return true; 157 return true;
158 } 158 }
159 159
160 void PopulateResourceResponse(URLRequest* request, 160 void PopulateResourceResponse(net::URLRequest* request,
161 bool replace_extension_localization_templates, 161 bool replace_extension_localization_templates,
162 ResourceResponse* response) { 162 ResourceResponse* response) {
163 response->response_head.status = request->status(); 163 response->response_head.status = request->status();
164 response->response_head.request_time = request->request_time(); 164 response->response_head.request_time = request->request_time();
165 response->response_head.response_time = request->response_time(); 165 response->response_head.response_time = request->response_time();
166 response->response_head.headers = request->response_headers(); 166 response->response_head.headers = request->response_headers();
167 request->GetCharset(&response->response_head.charset); 167 request->GetCharset(&response->response_head.charset);
168 response->response_head.replace_extension_localization_templates = 168 response->response_head.replace_extension_localization_templates =
169 replace_extension_localization_templates; 169 replace_extension_localization_templates;
170 response->response_head.content_length = request->GetExpectedContentSize(); 170 response->response_head.content_length = request->GetExpectedContentSize();
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
239 BrowserThread::IO, FROM_HERE, 239 BrowserThread::IO, FROM_HERE,
240 NewRunnableFunction(&appcache::AppCacheInterceptor::EnsureRegistered)); 240 NewRunnableFunction(&appcache::AppCacheInterceptor::EnsureRegistered));
241 } 241 }
242 242
243 void ResourceDispatcherHost::Shutdown() { 243 void ResourceDispatcherHost::Shutdown() {
244 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 244 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
245 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, new ShutdownTask(this)); 245 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, new ShutdownTask(this));
246 } 246 }
247 247
248 void ResourceDispatcherHost::SetRequestInfo( 248 void ResourceDispatcherHost::SetRequestInfo(
249 URLRequest* request, 249 net::URLRequest* request,
250 ResourceDispatcherHostRequestInfo* info) { 250 ResourceDispatcherHostRequestInfo* info) {
251 request->SetUserData(NULL, info); 251 request->SetUserData(NULL, info);
252 } 252 }
253 253
254 void ResourceDispatcherHost::OnShutdown() { 254 void ResourceDispatcherHost::OnShutdown() {
255 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 255 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
256 is_shutdown_ = true; 256 is_shutdown_ = true;
257 resource_queue_.Shutdown(); 257 resource_queue_.Shutdown();
258 STLDeleteValues(&pending_requests_); 258 STLDeleteValues(&pending_requests_);
259 // Make sure we shutdown the timer now, otherwise by the time our destructor 259 // Make sure we shutdown the timer now, otherwise by the time our destructor
(...skipping 18 matching lines...) Expand all
278 CancelBlockedRequestsForRoute(iter->first, iter->second); 278 CancelBlockedRequestsForRoute(iter->first, iter->second);
279 } 279 }
280 } 280 }
281 281
282 bool ResourceDispatcherHost::HandleExternalProtocol(int request_id, 282 bool ResourceDispatcherHost::HandleExternalProtocol(int request_id,
283 int child_id, 283 int child_id,
284 int route_id, 284 int route_id,
285 const GURL& url, 285 const GURL& url,
286 ResourceType::Type type, 286 ResourceType::Type type,
287 ResourceHandler* handler) { 287 ResourceHandler* handler) {
288 if (!ResourceType::IsFrame(type) || URLRequest::IsHandledURL(url)) 288 if (!ResourceType::IsFrame(type) || net::URLRequest::IsHandledURL(url))
289 return false; 289 return false;
290 290
291 BrowserThread::PostTask( 291 BrowserThread::PostTask(
292 BrowserThread::UI, FROM_HERE, 292 BrowserThread::UI, FROM_HERE,
293 NewRunnableFunction( 293 NewRunnableFunction(
294 &ExternalProtocolHandler::LaunchUrl, url, child_id, route_id)); 294 &ExternalProtocolHandler::LaunchUrl, url, child_id, route_id));
295 295
296 handler->OnResponseCompleted(request_id, URLRequestStatus( 296 handler->OnResponseCompleted(request_id, URLRequestStatus(
297 URLRequestStatus::FAILED, 297 URLRequestStatus::FAILED,
298 net::ERR_ABORTED), 298 net::ERR_ABORTED),
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
423 if (request_data.download_to_file) 423 if (request_data.download_to_file)
424 handler = new RedirectToFileResourceHandler(handler, child_id, this); 424 handler = new RedirectToFileResourceHandler(handler, child_id, this);
425 425
426 if (HandleExternalProtocol(request_id, child_id, route_id, 426 if (HandleExternalProtocol(request_id, child_id, route_id,
427 request_data.url, request_data.resource_type, 427 request_data.url, request_data.resource_type,
428 handler)) { 428 handler)) {
429 return; 429 return;
430 } 430 }
431 431
432 // Construct the request. 432 // Construct the request.
433 URLRequest* request = new URLRequest(request_data.url, this); 433 net::URLRequest* request = new net::URLRequest(request_data.url, this);
434 request->set_method(request_data.method); 434 request->set_method(request_data.method);
435 request->set_first_party_for_cookies(request_data.first_party_for_cookies); 435 request->set_first_party_for_cookies(request_data.first_party_for_cookies);
436 request->set_referrer(CommandLine::ForCurrentProcess()->HasSwitch( 436 request->set_referrer(CommandLine::ForCurrentProcess()->HasSwitch(
437 switches::kNoReferrers) ? std::string() : request_data.referrer.spec()); 437 switches::kNoReferrers) ? std::string() : request_data.referrer.spec());
438 net::HttpRequestHeaders headers; 438 net::HttpRequestHeaders headers;
439 headers.AddHeadersFromString(request_data.headers); 439 headers.AddHeadersFromString(request_data.headers);
440 request->SetExtraRequestHeaders(headers); 440 request->SetExtraRequestHeaders(headers);
441 441
442 int load_flags = request_data.load_flags; 442 int load_flags = request_data.load_flags;
443 // Although EV status is irrelevant to sub-frames and sub-resources, we have 443 // Although EV status is irrelevant to sub-frames and sub-resources, we have
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after
700 if (!ChildProcessSecurityPolicy::GetInstance()-> 700 if (!ChildProcessSecurityPolicy::GetInstance()->
701 CanRequestURL(child_id, url)) { 701 CanRequestURL(child_id, url)) {
702 VLOG(1) << "Denied unauthorized download request for " 702 VLOG(1) << "Denied unauthorized download request for "
703 << url.possibly_invalid_spec(); 703 << url.possibly_invalid_spec();
704 return; 704 return;
705 } 705 }
706 706
707 // Ensure the Chrome plugins are loaded, as they may intercept network 707 // Ensure the Chrome plugins are loaded, as they may intercept network
708 // requests. Does nothing if they are already loaded. 708 // requests. Does nothing if they are already loaded.
709 PluginService::GetInstance()->LoadChromePlugins(this); 709 PluginService::GetInstance()->LoadChromePlugins(this);
710 URLRequest* request = new URLRequest(url, this); 710 net::URLRequest* request = new net::URLRequest(url, this);
711 711
712 request_id_--; 712 request_id_--;
713 713
714 scoped_refptr<ResourceHandler> handler( 714 scoped_refptr<ResourceHandler> handler(
715 new DownloadResourceHandler(this, 715 new DownloadResourceHandler(this,
716 child_id, 716 child_id,
717 route_id, 717 route_id,
718 request_id_, 718 request_id_,
719 url, 719 url,
720 download_file_manager_.get(), 720 download_file_manager_.get(),
721 request, 721 request,
722 prompt_for_save_location, 722 prompt_for_save_location,
723 save_info)); 723 save_info));
724 724
725 if (safe_browsing_->enabled()) { 725 if (safe_browsing_->enabled()) {
726 handler = CreateSafeBrowsingResourceHandler(handler, child_id, route_id, 726 handler = CreateSafeBrowsingResourceHandler(handler, child_id, route_id,
727 ResourceType::MAIN_FRAME); 727 ResourceType::MAIN_FRAME);
728 } 728 }
729 729
730 if (!URLRequest::IsHandledURL(url)) { 730 if (!net::URLRequest::IsHandledURL(url)) {
731 VLOG(1) << "Download request for unsupported protocol: " 731 VLOG(1) << "Download request for unsupported protocol: "
732 << url.possibly_invalid_spec(); 732 << url.possibly_invalid_spec();
733 return; 733 return;
734 } 734 }
735 735
736 request->set_method("GET"); 736 request->set_method("GET");
737 request->set_referrer(CommandLine::ForCurrentProcess()->HasSwitch( 737 request->set_referrer(CommandLine::ForCurrentProcess()->HasSwitch(
738 switches::kNoReferrers) ? std::string() : referrer.spec()); 738 switches::kNoReferrers) ? std::string() : referrer.spec());
739 request->set_context(request_context); 739 request->set_context(request_context);
740 request->set_load_flags(request->load_flags() | 740 request->set_load_flags(request->load_flags() |
(...skipping 20 matching lines...) Expand all
761 // requests. Does nothing if they are already loaded. 761 // requests. Does nothing if they are already loaded.
762 PluginService::GetInstance()->LoadChromePlugins(this); 762 PluginService::GetInstance()->LoadChromePlugins(this);
763 763
764 scoped_refptr<ResourceHandler> handler( 764 scoped_refptr<ResourceHandler> handler(
765 new SaveFileResourceHandler(child_id, 765 new SaveFileResourceHandler(child_id,
766 route_id, 766 route_id,
767 url, 767 url,
768 save_file_manager_.get())); 768 save_file_manager_.get()));
769 request_id_--; 769 request_id_--;
770 770
771 bool known_proto = URLRequest::IsHandledURL(url); 771 bool known_proto = net::URLRequest::IsHandledURL(url);
772 if (!known_proto) { 772 if (!known_proto) {
773 // Since any URLs which have non-standard scheme have been filtered 773 // Since any URLs which have non-standard scheme have been filtered
774 // by save manager(see GURL::SchemeIsStandard). This situation 774 // by save manager(see GURL::SchemeIsStandard). This situation
775 // should not happen. 775 // should not happen.
776 NOTREACHED(); 776 NOTREACHED();
777 return; 777 return;
778 } 778 }
779 779
780 URLRequest* request = new URLRequest(url, this); 780 net::URLRequest* request = new net::URLRequest(url, this);
781 request->set_method("GET"); 781 request->set_method("GET");
782 request->set_referrer(CommandLine::ForCurrentProcess()->HasSwitch( 782 request->set_referrer(CommandLine::ForCurrentProcess()->HasSwitch(
783 switches::kNoReferrers) ? std::string() : referrer.spec()); 783 switches::kNoReferrers) ? std::string() : referrer.spec());
784 // So far, for saving page, we need fetch content from cache, in the 784 // So far, for saving page, we need fetch content from cache, in the
785 // future, maybe we can use a configuration to configure this behavior. 785 // future, maybe we can use a configuration to configure this behavior.
786 request->set_load_flags(net::LOAD_PREFERRING_CACHE); 786 request->set_load_flags(net::LOAD_PREFERRING_CACHE);
787 request->set_context(request_context); 787 request->set_context(request_context);
788 788
789 // Since we're just saving some resources we need, disallow downloading. 789 // Since we're just saving some resources we need, disallow downloading.
790 ResourceDispatcherHostRequestInfo* extra_info = 790 ResourceDispatcherHostRequestInfo* extra_info =
(...skipping 28 matching lines...) Expand all
819 if (i == pending_requests_.end()) { 819 if (i == pending_requests_.end()) {
820 // The request may have been destroyed 820 // The request may have been destroyed
821 LOG(WARNING) << "Trying to resume a non-existent request (" 821 LOG(WARNING) << "Trying to resume a non-existent request ("
822 << process_unique_id << ", " << request_id << ")"; 822 << process_unique_id << ", " << request_id << ")";
823 return; 823 return;
824 } 824 }
825 825
826 // TODO(eroman): are there other considerations for paused or blocked 826 // TODO(eroman): are there other considerations for paused or blocked
827 // requests? 827 // requests?
828 828
829 URLRequest* request = i->second; 829 net::URLRequest* request = i->second;
830 InsertIntoResourceQueue(request, *InfoForRequest(request)); 830 InsertIntoResourceQueue(request, *InfoForRequest(request));
831 } 831 }
832 832
833 bool ResourceDispatcherHost::WillSendData(int child_id, 833 bool ResourceDispatcherHost::WillSendData(int child_id,
834 int request_id) { 834 int request_id) {
835 PendingRequestList::iterator i = pending_requests_.find( 835 PendingRequestList::iterator i = pending_requests_.find(
836 GlobalRequestID(child_id, request_id)); 836 GlobalRequestID(child_id, request_id));
837 if (i == pending_requests_.end()) { 837 if (i == pending_requests_.end()) {
838 NOTREACHED() << "WillSendData for invalid request"; 838 NOTREACHED() << "WillSendData for invalid request";
839 return false; 839 return false;
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
920 } 920 }
921 } 921 }
922 922
923 // Remove matches. 923 // Remove matches.
924 for (size_t i = 0; i < matching_requests.size(); ++i) { 924 for (size_t i = 0; i < matching_requests.size(); ++i) {
925 PendingRequestList::iterator iter = 925 PendingRequestList::iterator iter =
926 pending_requests_.find(matching_requests[i]); 926 pending_requests_.find(matching_requests[i]);
927 // Although every matching request was in pending_requests_ when we built 927 // Although every matching request was in pending_requests_ when we built
928 // matching_requests, it is normal for a matching request to be not found 928 // matching_requests, it is normal for a matching request to be not found
929 // in pending_requests_ after we have removed some matching requests from 929 // in pending_requests_ after we have removed some matching requests from
930 // pending_requests_. For example, deleting a URLRequest that has 930 // pending_requests_. For example, deleting a net::URLRequest that has
931 // exclusive (write) access to an HTTP cache entry may unblock another 931 // exclusive (write) access to an HTTP cache entry may unblock another
932 // URLRequest that needs exclusive access to the same cache entry, and 932 // net::URLRequest that needs exclusive access to the same cache entry, and
933 // that URLRequest may complete and remove itself from pending_requests_. 933 // that net::URLRequest may complete and remove itself from
934 // So we need to check that iter is not equal to pending_requests_.end(). 934 // pending_requests_. So we need to check that iter is not equal to
935 // pending_requests_.end().
935 if (iter != pending_requests_.end()) 936 if (iter != pending_requests_.end())
936 RemovePendingRequest(iter); 937 RemovePendingRequest(iter);
937 } 938 }
938 939
939 // Now deal with blocked requests if any. 940 // Now deal with blocked requests if any.
940 if (route_id != -1) { 941 if (route_id != -1) {
941 if (blocked_requests_map_.find(std::pair<int, int>(child_id, route_id)) != 942 if (blocked_requests_map_.find(std::pair<int, int>(child_id, route_id)) !=
942 blocked_requests_map_.end()) { 943 blocked_requests_map_.end()) {
943 CancelBlockedRequestsForRoute(child_id, route_id); 944 CancelBlockedRequestsForRoute(child_id, route_id);
944 } 945 }
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
989 resource_queue_.RemoveRequest(iter->first); 990 resource_queue_.RemoveRequest(iter->first);
990 991
991 delete iter->second; 992 delete iter->second;
992 pending_requests_.erase(iter); 993 pending_requests_.erase(iter);
993 994
994 // If we have no more pending requests, then stop the load state monitor 995 // If we have no more pending requests, then stop the load state monitor
995 if (pending_requests_.empty()) 996 if (pending_requests_.empty())
996 update_load_states_timer_.Stop(); 997 update_load_states_timer_.Stop();
997 } 998 }
998 999
999 // URLRequest::Delegate ------------------------------------------------------- 1000 // net::URLRequest::Delegate ---------------------------------------------------
1000 1001
1001 void ResourceDispatcherHost::OnReceivedRedirect(URLRequest* request, 1002 void ResourceDispatcherHost::OnReceivedRedirect(net::URLRequest* request,
1002 const GURL& new_url, 1003 const GURL& new_url,
1003 bool* defer_redirect) { 1004 bool* defer_redirect) {
1004 VLOG(1) << "OnReceivedRedirect: " << request->url().spec(); 1005 VLOG(1) << "OnReceivedRedirect: " << request->url().spec();
1005 ResourceDispatcherHostRequestInfo* info = InfoForRequest(request); 1006 ResourceDispatcherHostRequestInfo* info = InfoForRequest(request);
1006 1007
1007 DCHECK(request->status().is_success()); 1008 DCHECK(request->status().is_success());
1008 1009
1009 if (info->process_type() != ChildProcessInfo::PLUGIN_PROCESS && 1010 if (info->process_type() != ChildProcessInfo::PLUGIN_PROCESS &&
1010 !ChildProcessSecurityPolicy::GetInstance()-> 1011 !ChildProcessSecurityPolicy::GetInstance()->
1011 CanRequestURL(info->child_id(), new_url)) { 1012 CanRequestURL(info->child_id(), new_url)) {
(...skipping 18 matching lines...) Expand all
1030 scoped_refptr<ResourceResponse> response(new ResourceResponse); 1031 scoped_refptr<ResourceResponse> response(new ResourceResponse);
1031 PopulateResourceResponse(request, 1032 PopulateResourceResponse(request,
1032 info->replace_extension_localization_templates(), response); 1033 info->replace_extension_localization_templates(), response);
1033 if (!info->resource_handler()->OnRequestRedirected(info->request_id(), 1034 if (!info->resource_handler()->OnRequestRedirected(info->request_id(),
1034 new_url, 1035 new_url,
1035 response, defer_redirect)) 1036 response, defer_redirect))
1036 CancelRequestInternal(request, false); 1037 CancelRequestInternal(request, false);
1037 } 1038 }
1038 1039
1039 void ResourceDispatcherHost::OnAuthRequired( 1040 void ResourceDispatcherHost::OnAuthRequired(
1040 URLRequest* request, 1041 net::URLRequest* request,
1041 net::AuthChallengeInfo* auth_info) { 1042 net::AuthChallengeInfo* auth_info) {
1042 // Create a login dialog on the UI thread to get authentication data, 1043 // Create a login dialog on the UI thread to get authentication data,
1043 // or pull from cache and continue on the IO thread. 1044 // or pull from cache and continue on the IO thread.
1044 // TODO(mpcomplete): We should block the parent tab while waiting for 1045 // TODO(mpcomplete): We should block the parent tab while waiting for
1045 // authentication. 1046 // authentication.
1046 // That would also solve the problem of the URLRequest being cancelled 1047 // That would also solve the problem of the net::URLRequest being cancelled
1047 // before we receive authentication. 1048 // before we receive authentication.
1048 ResourceDispatcherHostRequestInfo* info = InfoForRequest(request); 1049 ResourceDispatcherHostRequestInfo* info = InfoForRequest(request);
1049 DCHECK(!info->login_handler()) << 1050 DCHECK(!info->login_handler()) <<
1050 "OnAuthRequired called with login_handler pending"; 1051 "OnAuthRequired called with login_handler pending";
1051 info->set_login_handler(CreateLoginPrompt(auth_info, request)); 1052 info->set_login_handler(CreateLoginPrompt(auth_info, request));
1052 } 1053 }
1053 1054
1054 void ResourceDispatcherHost::OnCertificateRequested( 1055 void ResourceDispatcherHost::OnCertificateRequested(
1055 URLRequest* request, 1056 net::URLRequest* request,
1056 net::SSLCertRequestInfo* cert_request_info) { 1057 net::SSLCertRequestInfo* cert_request_info) {
1057 DCHECK(request); 1058 DCHECK(request);
1058 1059
1059 if (cert_request_info->client_certs.empty()) { 1060 if (cert_request_info->client_certs.empty()) {
1060 // No need to query the user if there are no certs to choose from. 1061 // No need to query the user if there are no certs to choose from.
1061 request->ContinueWithCertificate(NULL); 1062 request->ContinueWithCertificate(NULL);
1062 return; 1063 return;
1063 } 1064 }
1064 1065
1065 ResourceDispatcherHostRequestInfo* info = InfoForRequest(request); 1066 ResourceDispatcherHostRequestInfo* info = InfoForRequest(request);
1066 DCHECK(!info->ssl_client_auth_handler()) << 1067 DCHECK(!info->ssl_client_auth_handler()) <<
1067 "OnCertificateRequested called with ssl_client_auth_handler pending"; 1068 "OnCertificateRequested called with ssl_client_auth_handler pending";
1068 info->set_ssl_client_auth_handler( 1069 info->set_ssl_client_auth_handler(
1069 new SSLClientAuthHandler(request, cert_request_info)); 1070 new SSLClientAuthHandler(request, cert_request_info));
1070 info->ssl_client_auth_handler()->SelectCertificate(); 1071 info->ssl_client_auth_handler()->SelectCertificate();
1071 } 1072 }
1072 1073
1073 void ResourceDispatcherHost::OnSSLCertificateError( 1074 void ResourceDispatcherHost::OnSSLCertificateError(
1074 URLRequest* request, 1075 net::URLRequest* request,
1075 int cert_error, 1076 int cert_error,
1076 net::X509Certificate* cert) { 1077 net::X509Certificate* cert) {
1077 DCHECK(request); 1078 DCHECK(request);
1078 SSLManager::OnSSLCertificateError(this, request, cert_error, cert); 1079 SSLManager::OnSSLCertificateError(this, request, cert_error, cert);
1079 } 1080 }
1080 1081
1081 void ResourceDispatcherHost::OnSetCookie(URLRequest* request, 1082 void ResourceDispatcherHost::OnSetCookie(net::URLRequest* request,
1082 const std::string& cookie_line, 1083 const std::string& cookie_line,
1083 const net::CookieOptions& options, 1084 const net::CookieOptions& options,
1084 bool blocked_by_policy) { 1085 bool blocked_by_policy) {
1085 VLOG(1) << "OnSetCookie: " << request->url().spec(); 1086 VLOG(1) << "OnSetCookie: " << request->url().spec();
1086 1087
1087 int render_process_id, render_view_id; 1088 int render_process_id, render_view_id;
1088 if (!RenderViewForRequest(request, &render_process_id, &render_view_id)) 1089 if (!RenderViewForRequest(request, &render_process_id, &render_view_id))
1089 return; 1090 return;
1090 1091
1091 CallRenderViewHostContentSettingsDelegate( 1092 CallRenderViewHostContentSettingsDelegate(
1092 render_process_id, render_view_id, 1093 render_process_id, render_view_id,
1093 &RenderViewHostDelegate::ContentSettings::OnCookieAccessed, 1094 &RenderViewHostDelegate::ContentSettings::OnCookieAccessed,
1094 request->url(), cookie_line, options, blocked_by_policy); 1095 request->url(), cookie_line, options, blocked_by_policy);
1095 } 1096 }
1096 1097
1097 void ResourceDispatcherHost::OnResponseStarted(URLRequest* request) { 1098 void ResourceDispatcherHost::OnResponseStarted(net::URLRequest* request) {
1098 VLOG(1) << "OnResponseStarted: " << request->url().spec(); 1099 VLOG(1) << "OnResponseStarted: " << request->url().spec();
1099 ResourceDispatcherHostRequestInfo* info = InfoForRequest(request); 1100 ResourceDispatcherHostRequestInfo* info = InfoForRequest(request);
1100 if (PauseRequestIfNeeded(info)) { 1101 if (PauseRequestIfNeeded(info)) {
1101 VLOG(1) << "OnResponseStarted pausing: " << request->url().spec(); 1102 VLOG(1) << "OnResponseStarted pausing: " << request->url().spec();
1102 return; 1103 return;
1103 } 1104 }
1104 1105
1105 if (request->status().is_success()) { 1106 if (request->status().is_success()) {
1106 // We want to send a final upload progress message prior to sending 1107 // We want to send a final upload progress message prior to sending
1107 // the response complete message even if we're waiting for an ack to 1108 // the response complete message even if we're waiting for an ack to
(...skipping 10 matching lines...) Expand all
1118 return; 1119 return;
1119 } 1120 }
1120 1121
1121 StartReading(request); 1122 StartReading(request);
1122 } 1123 }
1123 } else { 1124 } else {
1124 OnResponseCompleted(request); 1125 OnResponseCompleted(request);
1125 } 1126 }
1126 } 1127 }
1127 1128
1128 bool ResourceDispatcherHost::CompleteResponseStarted(URLRequest* request) { 1129 bool ResourceDispatcherHost::CompleteResponseStarted(net::URLRequest* request) {
1129 ResourceDispatcherHostRequestInfo* info = InfoForRequest(request); 1130 ResourceDispatcherHostRequestInfo* info = InfoForRequest(request);
1130 1131
1131 scoped_refptr<ResourceResponse> response(new ResourceResponse); 1132 scoped_refptr<ResourceResponse> response(new ResourceResponse);
1132 PopulateResourceResponse(request, 1133 PopulateResourceResponse(request,
1133 info->replace_extension_localization_templates(), response); 1134 info->replace_extension_localization_templates(), response);
1134 1135
1135 if (request->ssl_info().cert) { 1136 if (request->ssl_info().cert) {
1136 int cert_id = 1137 int cert_id =
1137 CertStore::GetSharedInstance()->StoreCert(request->ssl_info().cert, 1138 CertStore::GetSharedInstance()->StoreCert(request->ssl_info().cert,
1138 info->child_id()); 1139 info->child_id());
(...skipping 23 matching lines...) Expand all
1162 if (i == pending_requests_.end()) { 1163 if (i == pending_requests_.end()) {
1163 // We probably want to remove this warning eventually, but I wanted to be 1164 // We probably want to remove this warning eventually, but I wanted to be
1164 // able to notice when this happens during initial development since it 1165 // able to notice when this happens during initial development since it
1165 // should be rare and may indicate a bug. 1166 // should be rare and may indicate a bug.
1166 DLOG(WARNING) << "Canceling a request that wasn't found"; 1167 DLOG(WARNING) << "Canceling a request that wasn't found";
1167 return; 1168 return;
1168 } 1169 }
1169 CancelRequestInternal(i->second, from_renderer); 1170 CancelRequestInternal(i->second, from_renderer);
1170 } 1171 }
1171 1172
1172 void ResourceDispatcherHost::CancelRequestInternal(URLRequest* request, 1173 void ResourceDispatcherHost::CancelRequestInternal(net::URLRequest* request,
1173 bool from_renderer) { 1174 bool from_renderer) {
1174 VLOG(1) << "CancelRequest: " << request->url().spec(); 1175 VLOG(1) << "CancelRequest: " << request->url().spec();
1175 1176
1176 // WebKit will send us a cancel for downloads since it no longer handles them. 1177 // WebKit will send us a cancel for downloads since it no longer handles them.
1177 // In this case, ignore the cancel since we handle downloads in the browser. 1178 // In this case, ignore the cancel since we handle downloads in the browser.
1178 ResourceDispatcherHostRequestInfo* info = InfoForRequest(request); 1179 ResourceDispatcherHostRequestInfo* info = InfoForRequest(request);
1179 if (!from_renderer || !info->is_download()) { 1180 if (!from_renderer || !info->is_download()) {
1180 if (info->login_handler()) { 1181 if (info->login_handler()) {
1181 info->login_handler()->OnRequestCancelled(); 1182 info->login_handler()->OnRequestCancelled();
1182 info->set_login_handler(NULL); 1183 info->set_login_handler(NULL);
(...skipping 28 matching lines...) Expand all
1211 if (new_cost == 0) 1212 if (new_cost == 0)
1212 outstanding_requests_memory_cost_map_.erase(prev_entry); 1213 outstanding_requests_memory_cost_map_.erase(prev_entry);
1213 else 1214 else
1214 outstanding_requests_memory_cost_map_[child_id] = new_cost; 1215 outstanding_requests_memory_cost_map_[child_id] = new_cost;
1215 1216
1216 return new_cost; 1217 return new_cost;
1217 } 1218 }
1218 1219
1219 // static 1220 // static
1220 int ResourceDispatcherHost::CalculateApproximateMemoryCost( 1221 int ResourceDispatcherHost::CalculateApproximateMemoryCost(
1221 URLRequest* request) { 1222 net::URLRequest* request) {
1222 // The following fields should be a minor size contribution (experimentally 1223 // The following fields should be a minor size contribution (experimentally
1223 // on the order of 100). However since they are variable length, it could 1224 // on the order of 100). However since they are variable length, it could
1224 // in theory be a sizeable contribution. 1225 // in theory be a sizeable contribution.
1225 int strings_cost = request->extra_request_headers().ToString().size() + 1226 int strings_cost = request->extra_request_headers().ToString().size() +
1226 request->original_url().spec().size() + 1227 request->original_url().spec().size() +
1227 request->referrer().size() + 1228 request->referrer().size() +
1228 request->method().size(); 1229 request->method().size();
1229 1230
1230 int upload_cost = 0; 1231 int upload_cost = 0;
1231 1232
(...skipping 14 matching lines...) Expand all
1246 } 1247 }
1247 } 1248 }
1248 } 1249 }
1249 #endif 1250 #endif
1250 1251
1251 // Note that this expression will typically be dominated by: 1252 // Note that this expression will typically be dominated by:
1252 // |kAvgBytesPerOutstandingRequest|. 1253 // |kAvgBytesPerOutstandingRequest|.
1253 return kAvgBytesPerOutstandingRequest + strings_cost + upload_cost; 1254 return kAvgBytesPerOutstandingRequest + strings_cost + upload_cost;
1254 } 1255 }
1255 1256
1256 void ResourceDispatcherHost::BeginRequestInternal(URLRequest* request) { 1257 void ResourceDispatcherHost::BeginRequestInternal(net::URLRequest* request) {
1257 DCHECK(!request->is_pending()); 1258 DCHECK(!request->is_pending());
1258 ResourceDispatcherHostRequestInfo* info = InfoForRequest(request); 1259 ResourceDispatcherHostRequestInfo* info = InfoForRequest(request);
1259 1260
1260 // Add the memory estimate that starting this request will consume. 1261 // Add the memory estimate that starting this request will consume.
1261 info->set_memory_cost(CalculateApproximateMemoryCost(request)); 1262 info->set_memory_cost(CalculateApproximateMemoryCost(request));
1262 int memory_cost = IncrementOutstandingRequestsMemoryCost(info->memory_cost(), 1263 int memory_cost = IncrementOutstandingRequestsMemoryCost(info->memory_cost(),
1263 info->child_id()); 1264 info->child_id());
1264 1265
1265 // If enqueing/starting this request will exceed our per-process memory 1266 // If enqueing/starting this request will exceed our per-process memory
1266 // bound, abort it right away. 1267 // bound, abort it right away.
1267 if (memory_cost > max_outstanding_requests_cost_per_process_) { 1268 if (memory_cost > max_outstanding_requests_cost_per_process_) {
1268 // We call "SimulateError()" as a way of setting the URLRequest's 1269 // We call "SimulateError()" as a way of setting the net::URLRequest's
1269 // status -- it has no effect beyond this, since the request hasn't started. 1270 // status -- it has no effect beyond this, since the request hasn't started.
1270 request->SimulateError(net::ERR_INSUFFICIENT_RESOURCES); 1271 request->SimulateError(net::ERR_INSUFFICIENT_RESOURCES);
1271 1272
1272 // TODO(eroman): this is kinda funky -- we insert the unstarted request into 1273 // TODO(eroman): this is kinda funky -- we insert the unstarted request into
1273 // |pending_requests_| simply to please OnResponseCompleted(). 1274 // |pending_requests_| simply to please OnResponseCompleted().
1274 GlobalRequestID global_id(info->child_id(), info->request_id()); 1275 GlobalRequestID global_id(info->child_id(), info->request_id());
1275 pending_requests_[global_id] = request; 1276 pending_requests_[global_id] = request;
1276 OnResponseCompleted(request); 1277 OnResponseCompleted(request);
1277 return; 1278 return;
1278 } 1279 }
1279 1280
1280 std::pair<int, int> pair_id(info->child_id(), info->route_id()); 1281 std::pair<int, int> pair_id(info->child_id(), info->route_id());
1281 BlockedRequestMap::const_iterator iter = blocked_requests_map_.find(pair_id); 1282 BlockedRequestMap::const_iterator iter = blocked_requests_map_.find(pair_id);
1282 if (iter != blocked_requests_map_.end()) { 1283 if (iter != blocked_requests_map_.end()) {
1283 // The request should be blocked. 1284 // The request should be blocked.
1284 iter->second->push_back(request); 1285 iter->second->push_back(request);
1285 return; 1286 return;
1286 } 1287 }
1287 1288
1288 GlobalRequestID global_id(info->child_id(), info->request_id()); 1289 GlobalRequestID global_id(info->child_id(), info->request_id());
1289 pending_requests_[global_id] = request; 1290 pending_requests_[global_id] = request;
1290 1291
1291 // Give the resource handlers an opportunity to delay the URLRequest from 1292 // Give the resource handlers an opportunity to delay the net::URLRequest from
1292 // being started. 1293 // being started.
1293 // 1294 //
1294 // There are three cases: 1295 // There are three cases:
1295 // 1296 //
1296 // (1) if OnWillStart() returns false, the request is cancelled (regardless 1297 // (1) if OnWillStart() returns false, the request is cancelled (regardless
1297 // of whether |defer_start| was set). 1298 // of whether |defer_start| was set).
1298 // (2) If |defer_start| was set to true, then the request is not added 1299 // (2) If |defer_start| was set to true, then the request is not added
1299 // into the resource queue, and will only be started in response to 1300 // into the resource queue, and will only be started in response to
1300 // calling StartDeferredRequest(). 1301 // calling StartDeferredRequest().
1301 // (3) If |defer_start| is not set, then the request is inserted into 1302 // (3) If |defer_start| is not set, then the request is inserted into
1302 // the resource_queue_ (which may pause it further, or start it). 1303 // the resource_queue_ (which may pause it further, or start it).
1303 bool defer_start = false; 1304 bool defer_start = false;
1304 if (!info->resource_handler()->OnWillStart( 1305 if (!info->resource_handler()->OnWillStart(
1305 info->request_id(), request->url(), 1306 info->request_id(), request->url(),
1306 &defer_start)) { 1307 &defer_start)) {
1307 CancelRequestInternal(request, false); 1308 CancelRequestInternal(request, false);
1308 return; 1309 return;
1309 } 1310 }
1310 1311
1311 if (!defer_start) 1312 if (!defer_start)
1312 InsertIntoResourceQueue(request, *info); 1313 InsertIntoResourceQueue(request, *info);
1313 } 1314 }
1314 1315
1315 void ResourceDispatcherHost::InsertIntoResourceQueue( 1316 void ResourceDispatcherHost::InsertIntoResourceQueue(
1316 URLRequest* request, 1317 net::URLRequest* request,
1317 const ResourceDispatcherHostRequestInfo& request_info) { 1318 const ResourceDispatcherHostRequestInfo& request_info) {
1318 resource_queue_.AddRequest(request, request_info); 1319 resource_queue_.AddRequest(request, request_info);
1319 1320
1320 // Make sure we have the load state monitor running 1321 // Make sure we have the load state monitor running
1321 if (!update_load_states_timer_.IsRunning()) { 1322 if (!update_load_states_timer_.IsRunning()) {
1322 update_load_states_timer_.Start( 1323 update_load_states_timer_.Start(
1323 TimeDelta::FromMilliseconds(kUpdateLoadStatesIntervalMsec), 1324 TimeDelta::FromMilliseconds(kUpdateLoadStatesIntervalMsec),
1324 this, &ResourceDispatcherHost::UpdateLoadStates); 1325 this, &ResourceDispatcherHost::UpdateLoadStates);
1325 } 1326 }
1326 } 1327 }
1327 1328
1328 bool ResourceDispatcherHost::PauseRequestIfNeeded( 1329 bool ResourceDispatcherHost::PauseRequestIfNeeded(
1329 ResourceDispatcherHostRequestInfo* info) { 1330 ResourceDispatcherHostRequestInfo* info) {
1330 if (info->pause_count() > 0) 1331 if (info->pause_count() > 0)
1331 info->set_is_paused(true); 1332 info->set_is_paused(true);
1332 return info->is_paused(); 1333 return info->is_paused();
1333 } 1334 }
1334 1335
1335 void ResourceDispatcherHost::ResumeRequest(const GlobalRequestID& request_id) { 1336 void ResourceDispatcherHost::ResumeRequest(const GlobalRequestID& request_id) {
1336 PendingRequestList::iterator i = pending_requests_.find(request_id); 1337 PendingRequestList::iterator i = pending_requests_.find(request_id);
1337 if (i == pending_requests_.end()) // The request may have been destroyed 1338 if (i == pending_requests_.end()) // The request may have been destroyed
1338 return; 1339 return;
1339 1340
1340 URLRequest* request = i->second; 1341 net::URLRequest* request = i->second;
1341 ResourceDispatcherHostRequestInfo* info = InfoForRequest(request); 1342 ResourceDispatcherHostRequestInfo* info = InfoForRequest(request);
1342 if (!info->is_paused()) 1343 if (!info->is_paused())
1343 return; 1344 return;
1344 1345
1345 VLOG(1) << "Resuming: " << i->second->url().spec(); 1346 VLOG(1) << "Resuming: " << i->second->url().spec();
1346 1347
1347 info->set_is_paused(false); 1348 info->set_is_paused(false);
1348 1349
1349 if (info->called_on_response_started()) { 1350 if (info->called_on_response_started()) {
1350 if (info->has_started_reading()) { 1351 if (info->has_started_reading()) {
1351 OnReadCompleted(i->second, info->paused_read_bytes()); 1352 OnReadCompleted(i->second, info->paused_read_bytes());
1352 } else { 1353 } else {
1353 StartReading(request); 1354 StartReading(request);
1354 } 1355 }
1355 } else { 1356 } else {
1356 OnResponseStarted(i->second); 1357 OnResponseStarted(i->second);
1357 } 1358 }
1358 } 1359 }
1359 1360
1360 void ResourceDispatcherHost::StartReading(URLRequest* request) { 1361 void ResourceDispatcherHost::StartReading(net::URLRequest* request) {
1361 // Start reading. 1362 // Start reading.
1362 int bytes_read = 0; 1363 int bytes_read = 0;
1363 if (Read(request, &bytes_read)) { 1364 if (Read(request, &bytes_read)) {
1364 OnReadCompleted(request, bytes_read); 1365 OnReadCompleted(request, bytes_read);
1365 } else if (!request->status().is_io_pending()) { 1366 } else if (!request->status().is_io_pending()) {
1366 DCHECK(!InfoForRequest(request)->is_paused()); 1367 DCHECK(!InfoForRequest(request)->is_paused());
1367 // If the error is not an IO pending, then we're done reading. 1368 // If the error is not an IO pending, then we're done reading.
1368 OnResponseCompleted(request); 1369 OnResponseCompleted(request);
1369 } 1370 }
1370 } 1371 }
1371 1372
1372 bool ResourceDispatcherHost::Read(URLRequest* request, int* bytes_read) { 1373 bool ResourceDispatcherHost::Read(net::URLRequest* request, int* bytes_read) {
1373 ResourceDispatcherHostRequestInfo* info = InfoForRequest(request); 1374 ResourceDispatcherHostRequestInfo* info = InfoForRequest(request);
1374 DCHECK(!info->is_paused()); 1375 DCHECK(!info->is_paused());
1375 1376
1376 net::IOBuffer* buf; 1377 net::IOBuffer* buf;
1377 int buf_size; 1378 int buf_size;
1378 if (!info->resource_handler()->OnWillRead(info->request_id(), 1379 if (!info->resource_handler()->OnWillRead(info->request_id(),
1379 &buf, &buf_size, -1)) { 1380 &buf, &buf_size, -1)) {
1380 return false; 1381 return false;
1381 } 1382 }
1382 1383
1383 DCHECK(buf); 1384 DCHECK(buf);
1384 DCHECK(buf_size > 0); 1385 DCHECK(buf_size > 0);
1385 1386
1386 info->set_has_started_reading(true); 1387 info->set_has_started_reading(true);
1387 return request->Read(buf, buf_size, bytes_read); 1388 return request->Read(buf, buf_size, bytes_read);
1388 } 1389 }
1389 1390
1390 void ResourceDispatcherHost::OnReadCompleted(URLRequest* request, 1391 void ResourceDispatcherHost::OnReadCompleted(net::URLRequest* request,
1391 int bytes_read) { 1392 int bytes_read) {
1392 DCHECK(request); 1393 DCHECK(request);
1393 VLOG(1) << "OnReadCompleted: " << request->url().spec(); 1394 VLOG(1) << "OnReadCompleted: " << request->url().spec();
1394 ResourceDispatcherHostRequestInfo* info = InfoForRequest(request); 1395 ResourceDispatcherHostRequestInfo* info = InfoForRequest(request);
1395 1396
1396 // OnReadCompleted can be called without Read (e.g., for chrome:// URLs). 1397 // OnReadCompleted can be called without Read (e.g., for chrome:// URLs).
1397 // Make sure we know that a read has begun. 1398 // Make sure we know that a read has begun.
1398 info->set_has_started_reading(true); 1399 info->set_has_started_reading(true);
1399 1400
1400 if (PauseRequestIfNeeded(info)) { 1401 if (PauseRequestIfNeeded(info)) {
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
1433 << request->url().spec(); 1434 << request->url().spec();
1434 return; 1435 return;
1435 } 1436 }
1436 1437
1437 // If the status is not IO pending then we've either finished (success) or we 1438 // If the status is not IO pending then we've either finished (success) or we
1438 // had an error. Either way, we're done! 1439 // had an error. Either way, we're done!
1439 if (!request->status().is_io_pending()) 1440 if (!request->status().is_io_pending())
1440 OnResponseCompleted(request); 1441 OnResponseCompleted(request);
1441 } 1442 }
1442 1443
1443 bool ResourceDispatcherHost::CompleteRead(URLRequest* request, 1444 bool ResourceDispatcherHost::CompleteRead(net::URLRequest* request,
1444 int* bytes_read) { 1445 int* bytes_read) {
1445 if (!request || !request->status().is_success()) { 1446 if (!request || !request->status().is_success()) {
1446 NOTREACHED(); 1447 NOTREACHED();
1447 return false; 1448 return false;
1448 } 1449 }
1449 1450
1450 ResourceDispatcherHostRequestInfo* info = InfoForRequest(request); 1451 ResourceDispatcherHostRequestInfo* info = InfoForRequest(request);
1451 if (!info->resource_handler()->OnReadCompleted(info->request_id(), 1452 if (!info->resource_handler()->OnReadCompleted(info->request_id(),
1452 bytes_read)) { 1453 bytes_read)) {
1453 CancelRequestInternal(request, false); 1454 CancelRequestInternal(request, false);
1454 return false; 1455 return false;
1455 } 1456 }
1456 1457
1457 return *bytes_read != 0; 1458 return *bytes_read != 0;
1458 } 1459 }
1459 1460
1460 void ResourceDispatcherHost::OnResponseCompleted(URLRequest* request) { 1461 void ResourceDispatcherHost::OnResponseCompleted(net::URLRequest* request) {
1461 VLOG(1) << "OnResponseCompleted: " << request->url().spec(); 1462 VLOG(1) << "OnResponseCompleted: " << request->url().spec();
1462 ResourceDispatcherHostRequestInfo* info = InfoForRequest(request); 1463 ResourceDispatcherHostRequestInfo* info = InfoForRequest(request);
1463 1464
1464 // If the load for a main frame has failed, track it in a histogram, 1465 // If the load for a main frame has failed, track it in a histogram,
1465 // since it will probably cause the user to see an error page. 1466 // since it will probably cause the user to see an error page.
1466 if (!request->status().is_success() && 1467 if (!request->status().is_success() &&
1467 info->resource_type() == ResourceType::MAIN_FRAME) { 1468 info->resource_type() == ResourceType::MAIN_FRAME) {
1468 UMA_HISTOGRAM_CUSTOM_ENUMERATION("Net.ErrorCodesForMainFrame", 1469 UMA_HISTOGRAM_CUSTOM_ENUMERATION("Net.ErrorCodesForMainFrame",
1469 -request->status().os_error(), 1470 -request->status().os_error(),
1470 GetAllNetErrorCodes()); 1471 GetAllNetErrorCodes());
(...skipping 16 matching lines...) Expand all
1487 1488
1488 // The request is complete so we can remove it. 1489 // The request is complete so we can remove it.
1489 RemovePendingRequest(info->child_id(), info->request_id()); 1490 RemovePendingRequest(info->child_id(), info->request_id());
1490 } 1491 }
1491 // If the handler's OnResponseCompleted returns false, we are deferring the 1492 // If the handler's OnResponseCompleted returns false, we are deferring the
1492 // call until later. We will notify the world and clean up when we resume. 1493 // call until later. We will notify the world and clean up when we resume.
1493 } 1494 }
1494 1495
1495 // static 1496 // static
1496 ResourceDispatcherHostRequestInfo* ResourceDispatcherHost::InfoForRequest( 1497 ResourceDispatcherHostRequestInfo* ResourceDispatcherHost::InfoForRequest(
1497 URLRequest* request) { 1498 net::URLRequest* request) {
1498 // Avoid writing this function twice by casting the cosnt version. 1499 // Avoid writing this function twice by casting the cosnt version.
1499 const URLRequest* const_request = request; 1500 const net::URLRequest* const_request = request;
1500 return const_cast<ResourceDispatcherHostRequestInfo*>( 1501 return const_cast<ResourceDispatcherHostRequestInfo*>(
1501 InfoForRequest(const_request)); 1502 InfoForRequest(const_request));
1502 } 1503 }
1503 1504
1504 // static 1505 // static
1505 const ResourceDispatcherHostRequestInfo* ResourceDispatcherHost::InfoForRequest( 1506 const ResourceDispatcherHostRequestInfo* ResourceDispatcherHost::InfoForRequest(
1506 const URLRequest* request) { 1507 const net::URLRequest* request) {
1507 const ResourceDispatcherHostRequestInfo* info = 1508 const ResourceDispatcherHostRequestInfo* info =
1508 static_cast<const ResourceDispatcherHostRequestInfo*>( 1509 static_cast<const ResourceDispatcherHostRequestInfo*>(
1509 request->GetUserData(NULL)); 1510 request->GetUserData(NULL));
1510 DLOG_IF(WARNING, !info) << "Request doesn't seem to have our data"; 1511 DLOG_IF(WARNING, !info) << "Request doesn't seem to have our data";
1511 return info; 1512 return info;
1512 } 1513 }
1513 1514
1514 // static 1515 // static
1515 bool ResourceDispatcherHost::RenderViewForRequest(const URLRequest* request, 1516 bool ResourceDispatcherHost::RenderViewForRequest(
1516 int* render_process_host_id, 1517 const net::URLRequest* request,
1517 int* render_view_host_id) { 1518 int* render_process_host_id,
1519 int* render_view_host_id) {
1518 const ResourceDispatcherHostRequestInfo* info = InfoForRequest(request); 1520 const ResourceDispatcherHostRequestInfo* info = InfoForRequest(request);
1519 if (!info) { 1521 if (!info) {
1520 *render_process_host_id = -1; 1522 *render_process_host_id = -1;
1521 *render_view_host_id = -1; 1523 *render_view_host_id = -1;
1522 return false; 1524 return false;
1523 } 1525 }
1524 1526
1525 // If the request is from the worker process, find a tab that owns the worker. 1527 // If the request is from the worker process, find a tab that owns the worker.
1526 if (info->process_type() == ChildProcessInfo::WORKER_PROCESS) { 1528 if (info->process_type() == ChildProcessInfo::WORKER_PROCESS) {
1527 const WorkerProcessHost::WorkerInstance* worker_instance = 1529 const WorkerProcessHost::WorkerInstance* worker_instance =
(...skipping 18 matching lines...) Expand all
1546 } 1548 }
1547 1549
1548 void ResourceDispatcherHost::AddObserver(Observer* obs) { 1550 void ResourceDispatcherHost::AddObserver(Observer* obs) {
1549 observer_list_.AddObserver(obs); 1551 observer_list_.AddObserver(obs);
1550 } 1552 }
1551 1553
1552 void ResourceDispatcherHost::RemoveObserver(Observer* obs) { 1554 void ResourceDispatcherHost::RemoveObserver(Observer* obs) {
1553 observer_list_.RemoveObserver(obs); 1555 observer_list_.RemoveObserver(obs);
1554 } 1556 }
1555 1557
1556 URLRequest* ResourceDispatcherHost::GetURLRequest( 1558 net::URLRequest* ResourceDispatcherHost::GetURLRequest(
1557 const GlobalRequestID& request_id) const { 1559 const GlobalRequestID& request_id) const {
1558 // This should be running in the IO loop. 1560 // This should be running in the IO loop.
1559 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 1561 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
1560 1562
1561 PendingRequestList::const_iterator i = pending_requests_.find(request_id); 1563 PendingRequestList::const_iterator i = pending_requests_.find(request_id);
1562 if (i == pending_requests_.end()) 1564 if (i == pending_requests_.end())
1563 return NULL; 1565 return NULL;
1564 1566
1565 return i->second; 1567 return i->second;
1566 } 1568 }
1567 1569
1568 static int GetCertID(URLRequest* request, int child_id) { 1570 static int GetCertID(net::URLRequest* request, int child_id) {
1569 if (request->ssl_info().cert) { 1571 if (request->ssl_info().cert) {
1570 return CertStore::GetSharedInstance()->StoreCert(request->ssl_info().cert, 1572 return CertStore::GetSharedInstance()->StoreCert(request->ssl_info().cert,
1571 child_id); 1573 child_id);
1572 } 1574 }
1573 // If there is no SSL info attached to this request, we must either be a non 1575 // If there is no SSL info attached to this request, we must either be a non
1574 // secure request, or the request has been canceled or failed (before the SSL 1576 // secure request, or the request has been canceled or failed (before the SSL
1575 // info was populated), or the response is an error (we have seen 403, 404, 1577 // info was populated), or the response is an error (we have seen 403, 404,
1576 // and 501) made up by the proxy. 1578 // and 501) made up by the proxy.
1577 DCHECK(!request->url().SchemeIsSecure() || 1579 DCHECK(!request->url().SchemeIsSecure() ||
1578 (request->status().status() == URLRequestStatus::CANCELED) || 1580 (request->status().status() == URLRequestStatus::CANCELED) ||
1579 (request->status().status() == URLRequestStatus::FAILED) || 1581 (request->status().status() == URLRequestStatus::FAILED) ||
1580 ((request->response_headers()->response_code() >= 400) && 1582 ((request->response_headers()->response_code() >= 400) &&
1581 (request->response_headers()->response_code() <= 599))); 1583 (request->response_headers()->response_code() <= 599)));
1582 return 0; 1584 return 0;
1583 } 1585 }
1584 1586
1585 void ResourceDispatcherHost::NotifyResponseStarted(URLRequest* request, 1587 void ResourceDispatcherHost::NotifyResponseStarted(net::URLRequest* request,
1586 int child_id) { 1588 int child_id) {
1587 // Notify the observers on the IO thread. 1589 // Notify the observers on the IO thread.
1588 FOR_EACH_OBSERVER(Observer, observer_list_, OnRequestStarted(this, request)); 1590 FOR_EACH_OBSERVER(Observer, observer_list_, OnRequestStarted(this, request));
1589 1591
1590 int render_process_id, render_view_id; 1592 int render_process_id, render_view_id;
1591 if (!RenderViewForRequest(request, &render_process_id, &render_view_id)) 1593 if (!RenderViewForRequest(request, &render_process_id, &render_view_id))
1592 return; 1594 return;
1593 1595
1594 // Notify the observers on the UI thread. 1596 // Notify the observers on the UI thread.
1595 CallRenderViewHostResourceDelegate( 1597 CallRenderViewHostResourceDelegate(
1596 render_process_id, render_view_id, 1598 render_process_id, render_view_id,
1597 &RenderViewHostDelegate::Resource::DidStartReceivingResourceResponse, 1599 &RenderViewHostDelegate::Resource::DidStartReceivingResourceResponse,
1598 ResourceRequestDetails(request, GetCertID(request, child_id))); 1600 ResourceRequestDetails(request, GetCertID(request, child_id)));
1599 } 1601 }
1600 1602
1601 void ResourceDispatcherHost::NotifyResponseCompleted(URLRequest* request, 1603 void ResourceDispatcherHost::NotifyResponseCompleted(net::URLRequest* request,
1602 int child_id) { 1604 int child_id) {
1603 // Notify the observers on the IO thread. 1605 // Notify the observers on the IO thread.
1604 FOR_EACH_OBSERVER(Observer, observer_list_, 1606 FOR_EACH_OBSERVER(Observer, observer_list_,
1605 OnResponseCompleted(this, request)); 1607 OnResponseCompleted(this, request));
1606 } 1608 }
1607 1609
1608 void ResourceDispatcherHost::NotifyReceivedRedirect(URLRequest* request, 1610 void ResourceDispatcherHost::NotifyReceivedRedirect(net::URLRequest* request,
1609 int child_id, 1611 int child_id,
1610 const GURL& new_url) { 1612 const GURL& new_url) {
1611 // Notify the observers on the IO thread. 1613 // Notify the observers on the IO thread.
1612 FOR_EACH_OBSERVER(Observer, observer_list_, 1614 FOR_EACH_OBSERVER(Observer, observer_list_,
1613 OnReceivedRedirect(this, request, new_url)); 1615 OnReceivedRedirect(this, request, new_url));
1614 1616
1615 int render_process_id, render_view_id; 1617 int render_process_id, render_view_id;
1616 if (!RenderViewForRequest(request, &render_process_id, &render_view_id)) 1618 if (!RenderViewForRequest(request, &render_process_id, &render_view_id))
1617 return; 1619 return;
1618 1620
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
1680 // Populate this map with load state changes, and then send them on to the UI 1682 // Populate this map with load state changes, and then send them on to the UI
1681 // thread where they can be passed along to the respective RVHs. 1683 // thread where they can be passed along to the respective RVHs.
1682 LoadInfoMap info_map; 1684 LoadInfoMap info_map;
1683 1685
1684 PendingRequestList::const_iterator i; 1686 PendingRequestList::const_iterator i;
1685 1687
1686 // Determine the largest upload size of all requests 1688 // Determine the largest upload size of all requests
1687 // in each View (good chance it's zero). 1689 // in each View (good chance it's zero).
1688 std::map<std::pair<int, int>, uint64> largest_upload_size; 1690 std::map<std::pair<int, int>, uint64> largest_upload_size;
1689 for (i = pending_requests_.begin(); i != pending_requests_.end(); ++i) { 1691 for (i = pending_requests_.begin(); i != pending_requests_.end(); ++i) {
1690 URLRequest* request = i->second; 1692 net::URLRequest* request = i->second;
1691 ResourceDispatcherHostRequestInfo* info = InfoForRequest(request); 1693 ResourceDispatcherHostRequestInfo* info = InfoForRequest(request);
1692 uint64 upload_size = info->upload_size(); 1694 uint64 upload_size = info->upload_size();
1693 if (request->GetLoadState() != net::LOAD_STATE_SENDING_REQUEST) 1695 if (request->GetLoadState() != net::LOAD_STATE_SENDING_REQUEST)
1694 upload_size = 0; 1696 upload_size = 0;
1695 std::pair<int, int> key(info->child_id(), info->route_id()); 1697 std::pair<int, int> key(info->child_id(), info->route_id());
1696 if (upload_size && largest_upload_size[key] < upload_size) 1698 if (upload_size && largest_upload_size[key] < upload_size)
1697 largest_upload_size[key] = upload_size; 1699 largest_upload_size[key] = upload_size;
1698 } 1700 }
1699 1701
1700 for (i = pending_requests_.begin(); i != pending_requests_.end(); ++i) { 1702 for (i = pending_requests_.begin(); i != pending_requests_.end(); ++i) {
1701 URLRequest* request = i->second; 1703 net::URLRequest* request = i->second;
1702 net::LoadState load_state = request->GetLoadState(); 1704 net::LoadState load_state = request->GetLoadState();
1703 ResourceDispatcherHostRequestInfo* info = InfoForRequest(request); 1705 ResourceDispatcherHostRequestInfo* info = InfoForRequest(request);
1704 1706
1705 // We also poll for upload progress on this timer and send upload 1707 // We also poll for upload progress on this timer and send upload
1706 // progress ipc messages to the plugin process. 1708 // progress ipc messages to the plugin process.
1707 bool update_upload_progress = MaybeUpdateUploadProgress(info, request); 1709 bool update_upload_progress = MaybeUpdateUploadProgress(info, request);
1708 1710
1709 if (info->last_load_state() != load_state || update_upload_progress) { 1711 if (info->last_load_state() != load_state || update_upload_progress) {
1710 std::pair<int, int> key(info->child_id(), info->route_id()); 1712 std::pair<int, int> key(info->child_id(), info->route_id());
1711 1713
(...skipping 28 matching lines...) Expand all
1740 1742
1741 LoadInfoUpdateTask* task = new LoadInfoUpdateTask; 1743 LoadInfoUpdateTask* task = new LoadInfoUpdateTask;
1742 task->info_map.swap(info_map); 1744 task->info_map.swap(info_map);
1743 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, task); 1745 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, task);
1744 } 1746 }
1745 1747
1746 // Calls the ResourceHandler to send upload progress messages to the renderer. 1748 // Calls the ResourceHandler to send upload progress messages to the renderer.
1747 // Returns true iff an upload progress message should be sent to the UI thread. 1749 // Returns true iff an upload progress message should be sent to the UI thread.
1748 bool ResourceDispatcherHost::MaybeUpdateUploadProgress( 1750 bool ResourceDispatcherHost::MaybeUpdateUploadProgress(
1749 ResourceDispatcherHostRequestInfo *info, 1751 ResourceDispatcherHostRequestInfo *info,
1750 URLRequest *request) { 1752 net::URLRequest *request) {
1751 1753
1752 if (!info->upload_size() || info->waiting_for_upload_progress_ack()) 1754 if (!info->upload_size() || info->waiting_for_upload_progress_ack())
1753 return false; 1755 return false;
1754 1756
1755 uint64 size = info->upload_size(); 1757 uint64 size = info->upload_size();
1756 uint64 position = request->GetUploadProgress(); 1758 uint64 position = request->GetUploadProgress();
1757 if (position == info->last_upload_position()) 1759 if (position == info->last_upload_position())
1758 return false; // no progress made since last time 1760 return false; // no progress made since last time
1759 1761
1760 const uint64 kHalfPercentIncrements = 200; 1762 const uint64 kHalfPercentIncrements = 200;
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
1811 1813
1812 BlockedRequestsList* requests = iter->second; 1814 BlockedRequestsList* requests = iter->second;
1813 1815
1814 // Removing the vector from the map unblocks any subsequent requests. 1816 // Removing the vector from the map unblocks any subsequent requests.
1815 blocked_requests_map_.erase(iter); 1817 blocked_requests_map_.erase(iter);
1816 1818
1817 for (BlockedRequestsList::iterator req_iter = requests->begin(); 1819 for (BlockedRequestsList::iterator req_iter = requests->begin();
1818 req_iter != requests->end(); ++req_iter) { 1820 req_iter != requests->end(); ++req_iter) {
1819 // Remove the memory credit that we added when pushing the request onto 1821 // Remove the memory credit that we added when pushing the request onto
1820 // the blocked list. 1822 // the blocked list.
1821 URLRequest* request = *req_iter; 1823 net::URLRequest* request = *req_iter;
1822 ResourceDispatcherHostRequestInfo* info = InfoForRequest(request); 1824 ResourceDispatcherHostRequestInfo* info = InfoForRequest(request);
1823 IncrementOutstandingRequestsMemoryCost(-1 * info->memory_cost(), 1825 IncrementOutstandingRequestsMemoryCost(-1 * info->memory_cost(),
1824 info->child_id()); 1826 info->child_id());
1825 if (cancel_requests) 1827 if (cancel_requests)
1826 delete request; 1828 delete request;
1827 else 1829 else
1828 BeginRequestInternal(request); 1830 BeginRequestInternal(request);
1829 } 1831 }
1830 1832
1831 delete requests; 1833 delete requests;
1832 } 1834 }
1833 1835
1834 bool ResourceDispatcherHost::IsValidRequest(URLRequest* request) { 1836 bool ResourceDispatcherHost::IsValidRequest(net::URLRequest* request) {
1835 if (!request) 1837 if (!request)
1836 return false; 1838 return false;
1837 ResourceDispatcherHostRequestInfo* info = InfoForRequest(request); 1839 ResourceDispatcherHostRequestInfo* info = InfoForRequest(request);
1838 return pending_requests_.find( 1840 return pending_requests_.find(
1839 GlobalRequestID(info->child_id(), info->request_id())) != 1841 GlobalRequestID(info->child_id(), info->request_id())) !=
1840 pending_requests_.end(); 1842 pending_requests_.end();
1841 } 1843 }
1842 1844
1843 // static 1845 // static
1844 bool ResourceDispatcherHost::IsResourceDispatcherHostMessage( 1846 bool ResourceDispatcherHost::IsResourceDispatcherHostMessage(
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
1932 return is_prefetch_enabled_; 1934 return is_prefetch_enabled_;
1933 } 1935 }
1934 1936
1935 // static 1937 // static
1936 void ResourceDispatcherHost::set_is_prefetch_enabled(bool value) { 1938 void ResourceDispatcherHost::set_is_prefetch_enabled(bool value) {
1937 is_prefetch_enabled_ = value; 1939 is_prefetch_enabled_ = value;
1938 } 1940 }
1939 1941
1940 // static 1942 // static
1941 bool ResourceDispatcherHost::is_prefetch_enabled_ = false; 1943 bool ResourceDispatcherHost::is_prefetch_enabled_ = false;
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698