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

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

Issue 10644011: Revert r143458 (which re-applies r143341 and r142979). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // See http://dev.chromium.org/developers/design-documents/multi-process-resourc e-loading 5 // See http://dev.chromium.org/developers/design-documents/multi-process-resourc e-loading
6 6
7 #include "content/browser/renderer_host/resource_dispatcher_host_impl.h" 7 #include "content/browser/renderer_host/resource_dispatcher_host_impl.h"
8 8
9 #include <set> 9 #include <set>
10 #include <vector> 10 #include <vector>
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 92
93 namespace content { 93 namespace content {
94 94
95 namespace { 95 namespace {
96 96
97 static ResourceDispatcherHostImpl* g_resource_dispatcher_host; 97 static ResourceDispatcherHostImpl* g_resource_dispatcher_host;
98 98
99 // The interval for calls to ResourceDispatcherHostImpl::UpdateLoadStates 99 // The interval for calls to ResourceDispatcherHostImpl::UpdateLoadStates
100 const int kUpdateLoadStatesIntervalMsec = 100; 100 const int kUpdateLoadStatesIntervalMsec = 100;
101 101
102 // Maximum number of pending data messages sent to the renderer at any
103 // given time for a given request.
104 const int kMaxPendingDataMessages = 20;
105
106 // Maximum byte "cost" of all the outstanding requests for a renderer. 102 // Maximum byte "cost" of all the outstanding requests for a renderer.
107 // See delcaration of |max_outstanding_requests_cost_per_process_| for details. 103 // See delcaration of |max_outstanding_requests_cost_per_process_| for details.
108 // This bound is 25MB, which allows for around 6000 outstanding requests. 104 // This bound is 25MB, which allows for around 6000 outstanding requests.
109 const int kMaxOutstandingRequestsCostPerProcess = 26214400; 105 const int kMaxOutstandingRequestsCostPerProcess = 26214400;
110 106
111 // The number of milliseconds after noting a user gesture that we will 107 // The number of milliseconds after noting a user gesture that we will
112 // tag newly-created URLRequest objects with the 108 // tag newly-created URLRequest objects with the
113 // net::LOAD_MAYBE_USER_GESTURE load flag. This is a fairly arbitrary 109 // net::LOAD_MAYBE_USER_GESTURE load flag. This is a fairly arbitrary
114 // guess at how long to expect direct impact from a user gesture, but 110 // guess at how long to expect direct impact from a user gesture, but
115 // this should be OK as the load flag is a best-effort thing only, 111 // this should be OK as the load flag is a best-effort thing only,
(...skipping 807 matching lines...) Expand 10 before | Expand all | Expand 10 after
923 route_id, 919 route_id,
924 request_data.method, 920 request_data.method,
925 request_data.url, 921 request_data.url,
926 request_data.resource_type, 922 request_data.resource_type,
927 resource_context, 923 resource_context,
928 referrer)) { 924 referrer)) {
929 AbortRequestBeforeItStarts(filter_, sync_result, route_id, request_id); 925 AbortRequestBeforeItStarts(filter_, sync_result, route_id, request_id);
930 return; 926 return;
931 } 927 }
932 928
933 // Construct the event handler.
934 scoped_ptr<ResourceHandler> handler;
935 if (sync_result) {
936 handler.reset(new SyncResourceHandler(
937 filter_, request_data.url, sync_result, this));
938 } else {
939 handler.reset(new AsyncResourceHandler(
940 filter_, route_id, request_data.url, this));
941 }
942
943 // The RedirectToFileResourceHandler depends on being next in the chain.
944 if (request_data.download_to_file) {
945 handler.reset(
946 new RedirectToFileResourceHandler(handler.Pass(), child_id, this));
947 }
948
949 int load_flags = 929 int load_flags =
950 BuildLoadFlagsForRequest(request_data, child_id, sync_result != NULL); 930 BuildLoadFlagsForRequest(request_data, child_id, sync_result != NULL);
951 931
952 // Construct the request. 932 // Construct the request.
953 scoped_ptr<net::URLRequest> new_request; 933 scoped_ptr<net::URLRequest> new_request;
954 net::URLRequest* request; 934 net::URLRequest* request;
955 if (deferred_loader.get()) { 935 if (deferred_loader.get()) {
956 request = deferred_loader->request(); 936 request = deferred_loader->request();
957 } else { 937 } else {
958 new_request.reset(new net::URLRequest( 938 new_request.reset(new net::URLRequest(
(...skipping 21 matching lines...) Expand all
980 960
981 // Set upload data. 961 // Set upload data.
982 uint64 upload_size = 0; 962 uint64 upload_size = 0;
983 if (request_data.upload_data) { 963 if (request_data.upload_data) {
984 request->set_upload(request_data.upload_data); 964 request->set_upload(request_data.upload_data);
985 // This results in performing file IO. crbug.com/112607. 965 // This results in performing file IO. crbug.com/112607.
986 base::ThreadRestrictions::ScopedAllowIO allow_io; 966 base::ThreadRestrictions::ScopedAllowIO allow_io;
987 upload_size = request_data.upload_data->GetContentLengthSync(); 967 upload_size = request_data.upload_data->GetContentLengthSync();
988 } 968 }
989 969
970 bool allow_download = request_data.allow_download &&
971 ResourceType::IsFrame(request_data.resource_type);
972
973 // Make extra info and read footer (contains request ID).
974 ResourceRequestInfoImpl* extra_info =
975 new ResourceRequestInfoImpl(
976 process_type,
977 child_id,
978 route_id,
979 request_data.origin_pid,
980 request_id,
981 request_data.is_main_frame,
982 request_data.frame_id,
983 request_data.parent_is_main_frame,
984 request_data.parent_frame_id,
985 request_data.resource_type,
986 request_data.transition_type,
987 upload_size,
988 false, // is download
989 allow_download,
990 request_data.has_user_gesture,
991 request_data.referrer_policy,
992 resource_context);
993 extra_info->AssociateWithRequest(request); // Request takes ownership.
994
995 if (request->url().SchemeIs(chrome::kBlobScheme)) {
996 // Hang on to a reference to ensure the blob is not released prior
997 // to the job being started.
998 webkit_blob::BlobStorageController* controller =
999 GetBlobStorageControllerForResourceContext(resource_context);
1000 extra_info->set_requested_blob_data(
1001 controller->GetBlobDataFromUrl(request->url()));
1002 }
1003
1004 // Have the appcache associate its extra info with the request.
1005 appcache::AppCacheInterceptor::SetExtraRequestInfo(
1006 request, ResourceContext::GetAppCacheService(resource_context), child_id,
1007 request_data.appcache_host_id, request_data.resource_type);
1008
1009 // Construct the IPC resource handler.
1010 scoped_ptr<ResourceHandler> handler;
darin (slow to review) 2012/06/22 19:56:03 btw, the point of this code move is to just ensure
1011 if (sync_result) {
1012 handler.reset(new SyncResourceHandler(
1013 filter_, request, sync_result, this));
1014 } else {
1015 handler.reset(new AsyncResourceHandler(
1016 filter_, route_id, request, this));
1017 }
1018
1019 // The RedirectToFileResourceHandler depends on being next in the chain.
1020 if (request_data.download_to_file) {
1021 handler.reset(
1022 new RedirectToFileResourceHandler(handler.Pass(), child_id, this));
1023 }
1024
990 // Install a CrossSiteResourceHandler if this request is coming from a 1025 // Install a CrossSiteResourceHandler if this request is coming from a
991 // RenderViewHost with a pending cross-site request. We only check this for 1026 // RenderViewHost with a pending cross-site request. We only check this for
992 // MAIN_FRAME requests. Unblock requests only come from a blocked page, do 1027 // MAIN_FRAME requests. Unblock requests only come from a blocked page, do
993 // not count as cross-site, otherwise it gets blocked indefinitely. 1028 // not count as cross-site, otherwise it gets blocked indefinitely.
994 if (request_data.resource_type == ResourceType::MAIN_FRAME && 1029 if (request_data.resource_type == ResourceType::MAIN_FRAME &&
995 process_type == PROCESS_TYPE_RENDERER && 1030 process_type == PROCESS_TYPE_RENDERER &&
996 CrossSiteRequestManager::GetInstance()-> 1031 CrossSiteRequestManager::GetInstance()->
997 HasPendingCrossSiteRequest(child_id, route_id)) { 1032 HasPendingCrossSiteRequest(child_id, route_id)) {
998 // Wrap the event handler to be sure the current page's onunload handler 1033 // Wrap the event handler to be sure the current page's onunload handler
999 // has a chance to run before we render the new page. 1034 // has a chance to run before we render the new page.
1000 handler.reset( 1035 handler.reset(new CrossSiteResourceHandler(handler.Pass(), child_id,
1001 new CrossSiteResourceHandler(handler.Pass(), child_id, route_id, this)); 1036 route_id, request));
1002 } 1037 }
1003 1038
1004 // Insert a buffered event handler before the actual one. 1039 // Insert a buffered event handler before the actual one.
1005 handler.reset( 1040 handler.reset(
1006 new BufferedResourceHandler(handler.Pass(), this, request)); 1041 new BufferedResourceHandler(handler.Pass(), this, request));
1007 1042
1008 ScopedVector<ResourceThrottle> throttles; 1043 ScopedVector<ResourceThrottle> throttles;
1009 if (delegate_) { 1044 if (delegate_) {
1010 bool is_continuation_of_transferred_request = 1045 bool is_continuation_of_transferred_request =
1011 (deferred_loader.get() != NULL); 1046 (deferred_loader.get() != NULL);
(...skipping 12 matching lines...) Expand all
1024 throttles.begin(), 1059 throttles.begin(),
1025 new TransferNavigationResourceThrottle(request)); 1060 new TransferNavigationResourceThrottle(request));
1026 } 1061 }
1027 1062
1028 if (!throttles.empty()) { 1063 if (!throttles.empty()) {
1029 handler.reset( 1064 handler.reset(
1030 new ThrottlingResourceHandler(handler.Pass(), child_id, request_id, 1065 new ThrottlingResourceHandler(handler.Pass(), child_id, request_id,
1031 throttles.Pass())); 1066 throttles.Pass()));
1032 } 1067 }
1033 1068
1034 bool allow_download = request_data.allow_download &&
1035 ResourceType::IsFrame(request_data.resource_type);
1036 // Make extra info and read footer (contains request ID).
1037 ResourceRequestInfoImpl* extra_info =
1038 new ResourceRequestInfoImpl(
1039 process_type,
1040 child_id,
1041 route_id,
1042 request_data.origin_pid,
1043 request_id,
1044 request_data.is_main_frame,
1045 request_data.frame_id,
1046 request_data.parent_is_main_frame,
1047 request_data.parent_frame_id,
1048 request_data.resource_type,
1049 request_data.transition_type,
1050 upload_size,
1051 false, // is download
1052 allow_download,
1053 request_data.has_user_gesture,
1054 request_data.referrer_policy,
1055 resource_context);
1056 extra_info->AssociateWithRequest(request); // Request takes ownership.
1057
1058 if (request->url().SchemeIs(chrome::kBlobScheme)) {
1059 // Hang on to a reference to ensure the blob is not released prior
1060 // to the job being started.
1061 webkit_blob::BlobStorageController* controller =
1062 GetBlobStorageControllerForResourceContext(resource_context);
1063 extra_info->set_requested_blob_data(
1064 controller->GetBlobDataFromUrl(request->url()));
1065 }
1066
1067 // Have the appcache associate its extra info with the request.
1068 appcache::AppCacheInterceptor::SetExtraRequestInfo(
1069 request, ResourceContext::GetAppCacheService(resource_context), child_id,
1070 request_data.appcache_host_id, request_data.resource_type);
1071
1072 if (deferred_loader.get()) { 1069 if (deferred_loader.get()) {
1073 pending_loaders_[extra_info->GetGlobalRequestID()] = deferred_loader; 1070 pending_loaders_[extra_info->GetGlobalRequestID()] = deferred_loader;
1074 deferred_loader->CompleteTransfer(handler.Pass()); 1071 deferred_loader->CompleteTransfer(handler.Pass());
1075 } else { 1072 } else {
1076 BeginRequestInternal(new_request.Pass(), handler.Pass()); 1073 BeginRequestInternal(new_request.Pass(), handler.Pass());
1077 } 1074 }
1078 } 1075 }
1079 1076
1080 void ResourceDispatcherHostImpl::OnReleaseDownloadedFile(int request_id) { 1077 void ResourceDispatcherHostImpl::OnReleaseDownloadedFile(int request_id) {
1081 UnregisterDownloadedTempFile(filter_->child_id(), request_id); 1078 UnregisterDownloadedTempFile(filter_->child_id(), request_id);
1082 } 1079 }
1083 1080
1084 void ResourceDispatcherHostImpl::OnDataReceivedACK(int request_id) { 1081 void ResourceDispatcherHostImpl::OnDataReceivedACK(int request_id) {
1085 DataReceivedACK(filter_->child_id(), request_id); 1082 ResourceLoader* loader = GetLoader(filter_->child_id(), request_id);
1086 }
1087
1088 void ResourceDispatcherHostImpl::DataReceivedACK(int child_id,
1089 int request_id) {
1090 ResourceLoader* loader = GetLoader(child_id, request_id);
1091 if (!loader) 1083 if (!loader)
1092 return; 1084 return;
1093 1085
1094 ResourceRequestInfoImpl* info = loader->GetRequestInfo(); 1086 ResourceRequestInfoImpl* info = loader->GetRequestInfo();
1095 1087 if (info->async_handler())
1096 // Decrement the number of pending data messages. 1088 info->async_handler()->OnDataReceivedACK();
1097 info->DecrementPendingDataCount();
1098
1099 // If the pending data count was higher than the max, resume the request.
1100 if (info->pending_data_count() == kMaxPendingDataMessages) {
1101 // Decrement the pending data count one more time because we also
1102 // incremented it before pausing the request.
1103 info->DecrementPendingDataCount();
1104
1105 // Resume the request.
1106 //
1107 // TODO(darin): Make the AsyncResourceHandler be responsible for resuming
1108 // via its controller(). This static_cast is here as a temporary measure.
1109 //
1110 static_cast<ResourceController*>(loader)->Resume();
1111 }
1112 } 1089 }
1113 1090
1114 void ResourceDispatcherHostImpl::OnDataDownloadedACK(int request_id) { 1091 void ResourceDispatcherHostImpl::OnDataDownloadedACK(int request_id) {
1115 // TODO(michaeln): maybe throttle DataDownloaded messages 1092 // TODO(michaeln): maybe throttle DataDownloaded messages
1116 } 1093 }
1117 1094
1118 void ResourceDispatcherHostImpl::RegisterDownloadedTempFile( 1095 void ResourceDispatcherHostImpl::RegisterDownloadedTempFile(
1119 int child_id, int request_id, ShareableFileReference* reference) { 1096 int child_id, int request_id, ShareableFileReference* reference) {
1120 registered_temp_files_[child_id][request_id] = reference; 1097 registered_temp_files_[child_id][request_id] = reference;
1121 ChildProcessSecurityPolicyImpl::GetInstance()->GrantReadFile( 1098 ChildProcessSecurityPolicyImpl::GetInstance()->GrantReadFile(
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
1165 void ResourceDispatcherHostImpl::OnFollowRedirect( 1142 void ResourceDispatcherHostImpl::OnFollowRedirect(
1166 int request_id, 1143 int request_id,
1167 bool has_new_first_party_for_cookies, 1144 bool has_new_first_party_for_cookies,
1168 const GURL& new_first_party_for_cookies) { 1145 const GURL& new_first_party_for_cookies) {
1169 ResourceLoader* loader = GetLoader(filter_->child_id(), request_id); 1146 ResourceLoader* loader = GetLoader(filter_->child_id(), request_id);
1170 if (!loader) { 1147 if (!loader) {
1171 DVLOG(1) << "OnFollowRedirect for invalid request"; 1148 DVLOG(1) << "OnFollowRedirect for invalid request";
1172 return; 1149 return;
1173 } 1150 }
1174 1151
1175 loader->OnFollowRedirect(has_new_first_party_for_cookies, 1152 ResourceRequestInfoImpl* info = loader->GetRequestInfo();
1176 new_first_party_for_cookies); 1153 if (info->async_handler()) {
1154 info->async_handler()->OnFollowRedirect(
1155 has_new_first_party_for_cookies,
1156 new_first_party_for_cookies);
1157 }
1177 } 1158 }
1178 1159
1179 ResourceRequestInfoImpl* ResourceDispatcherHostImpl::CreateRequestInfo( 1160 ResourceRequestInfoImpl* ResourceDispatcherHostImpl::CreateRequestInfo(
1180 int child_id, 1161 int child_id,
1181 int route_id, 1162 int route_id,
1182 bool download, 1163 bool download,
1183 ResourceContext* context) { 1164 ResourceContext* context) {
1184 return new ResourceRequestInfoImpl( 1165 return new ResourceRequestInfoImpl(
1185 PROCESS_TYPE_RENDERER, 1166 PROCESS_TYPE_RENDERER,
1186 child_id, 1167 child_id,
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
1281 request->set_load_flags(net::LOAD_PREFERRING_CACHE); 1262 request->set_load_flags(net::LOAD_PREFERRING_CACHE);
1282 1263
1283 // Since we're just saving some resources we need, disallow downloading. 1264 // Since we're just saving some resources we need, disallow downloading.
1284 ResourceRequestInfoImpl* extra_info = 1265 ResourceRequestInfoImpl* extra_info =
1285 CreateRequestInfo(child_id, route_id, false, context); 1266 CreateRequestInfo(child_id, route_id, false, context);
1286 extra_info->AssociateWithRequest(request.get()); // Request takes ownership. 1267 extra_info->AssociateWithRequest(request.get()); // Request takes ownership.
1287 1268
1288 BeginRequestInternal(request.Pass(), handler.Pass()); 1269 BeginRequestInternal(request.Pass(), handler.Pass());
1289 } 1270 }
1290 1271
1291 bool ResourceDispatcherHostImpl::WillSendData(int child_id, int request_id,
1292 bool* defer) {
1293 ResourceLoader* loader = GetLoader(child_id, request_id);
1294 if (!loader) {
1295 NOTREACHED() << "WillSendData for invalid request";
1296 return false;
1297 }
1298
1299 ResourceRequestInfoImpl* info = loader->GetRequestInfo();
1300
1301 info->IncrementPendingDataCount();
1302 if (info->pending_data_count() > kMaxPendingDataMessages) {
1303 // We reached the max number of data messages that can be sent to
1304 // the renderer for a given request. Pause the request and wait for
1305 // the renderer to start processing them before resuming it.
1306 *defer = true;
1307 return false;
1308 }
1309
1310 return true;
1311 }
1312
1313 void ResourceDispatcherHostImpl::MarkAsTransferredNavigation( 1272 void ResourceDispatcherHostImpl::MarkAsTransferredNavigation(
1314 const GlobalRequestID& id) { 1273 const GlobalRequestID& id) {
1315 GetLoader(id)->MarkAsTransferring(); 1274 GetLoader(id)->MarkAsTransferring();
1316 } 1275 }
1317 1276
1318 int ResourceDispatcherHostImpl::GetOutstandingRequestsMemoryCost( 1277 int ResourceDispatcherHostImpl::GetOutstandingRequestsMemoryCost(
1319 int child_id) const { 1278 int child_id) const {
1320 OutstandingRequestsMemoryCostMap::const_iterator entry = 1279 OutstandingRequestsMemoryCostMap::const_iterator entry =
1321 outstanding_requests_memory_cost_map_.find(child_id); 1280 outstanding_requests_memory_cost_map_.find(child_id);
1322 return (entry == outstanding_requests_memory_cost_map_.end()) ? 1281 return (entry == outstanding_requests_memory_cost_map_.end()) ?
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
1511 request->CancelWithError(net::ERR_INSUFFICIENT_RESOURCES); 1470 request->CancelWithError(net::ERR_INSUFFICIENT_RESOURCES);
1512 1471
1513 if (!handler->OnResponseCompleted(info->GetRequestID(), request->status(), 1472 if (!handler->OnResponseCompleted(info->GetRequestID(), request->status(),
1514 std::string())) { 1473 std::string())) {
1515 // TODO(darin): The handler is not ready for us to kill the request. Oops! 1474 // TODO(darin): The handler is not ready for us to kill the request. Oops!
1516 NOTREACHED(); 1475 NOTREACHED();
1517 } 1476 }
1518 1477
1519 IncrementOutstandingRequestsMemoryCost(-1 * info->memory_cost(), 1478 IncrementOutstandingRequestsMemoryCost(-1 * info->memory_cost(),
1520 info->GetChildID()); 1479 info->GetChildID());
1480
1481 // A ResourceHandler must not outlive its associated URLRequest.
1482 handler.reset();
1521 return; 1483 return;
1522 } 1484 }
1523 1485
1524 linked_ptr<ResourceLoader> loader( 1486 linked_ptr<ResourceLoader> loader(
1525 new ResourceLoader(request.Pass(), handler.Pass(), this)); 1487 new ResourceLoader(request.Pass(), handler.Pass(), this));
1526 1488
1527 ProcessRouteIDs pair_id(info->GetChildID(), info->GetRouteID()); 1489 ProcessRouteIDs pair_id(info->GetChildID(), info->GetRouteID());
1528 BlockedLoadersMap::const_iterator iter = blocked_loaders_map_.find(pair_id); 1490 BlockedLoadersMap::const_iterator iter = blocked_loaders_map_.find(pair_id);
1529 if (iter != blocked_loaders_map_.end()) { 1491 if (iter != blocked_loaders_map_.end()) {
1530 // The request should be blocked. 1492 // The request should be blocked.
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after
1754 1716
1755 return i->second.get(); 1717 return i->second.get();
1756 } 1718 }
1757 1719
1758 ResourceLoader* ResourceDispatcherHostImpl::GetLoader(int child_id, 1720 ResourceLoader* ResourceDispatcherHostImpl::GetLoader(int child_id,
1759 int request_id) const { 1721 int request_id) const {
1760 return GetLoader(GlobalRequestID(child_id, request_id)); 1722 return GetLoader(GlobalRequestID(child_id, request_id));
1761 } 1723 }
1762 1724
1763 } // namespace content 1725 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698