| 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/loader/resource_dispatcher_host_impl.h" | 7 #include "content/browser/loader/resource_dispatcher_host_impl.h" |
| 8 | 8 |
| 9 #include <stddef.h> | 9 #include <stddef.h> |
| 10 | 10 |
| (...skipping 1105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1116 } | 1116 } |
| 1117 } | 1117 } |
| 1118 return false; | 1118 return false; |
| 1119 } | 1119 } |
| 1120 | 1120 |
| 1121 void ResourceDispatcherHostImpl::UpdateRequestForTransfer( | 1121 void ResourceDispatcherHostImpl::UpdateRequestForTransfer( |
| 1122 int child_id, | 1122 int child_id, |
| 1123 int route_id, | 1123 int route_id, |
| 1124 int request_id, | 1124 int request_id, |
| 1125 const ResourceRequest& request_data, | 1125 const ResourceRequest& request_data, |
| 1126 LoaderMap::iterator iter) { | 1126 LoaderMap::iterator iter, |
| 1127 mojom::URLLoaderAssociatedRequest mojo_request, |
| 1128 mojom::URLLoaderClientAssociatedPtr url_loader_client) { |
| 1127 ResourceRequestInfoImpl* info = iter->second->GetRequestInfo(); | 1129 ResourceRequestInfoImpl* info = iter->second->GetRequestInfo(); |
| 1128 GlobalFrameRoutingId old_routing_id(request_data.transferred_request_child_id, | 1130 GlobalFrameRoutingId old_routing_id(request_data.transferred_request_child_id, |
| 1129 info->GetRenderFrameID()); | 1131 info->GetRenderFrameID()); |
| 1130 GlobalRequestID old_request_id(request_data.transferred_request_child_id, | 1132 GlobalRequestID old_request_id(request_data.transferred_request_child_id, |
| 1131 request_data.transferred_request_request_id); | 1133 request_data.transferred_request_request_id); |
| 1132 GlobalFrameRoutingId new_routing_id(child_id, request_data.render_frame_id); | 1134 GlobalFrameRoutingId new_routing_id(child_id, request_data.render_frame_id); |
| 1133 GlobalRequestID new_request_id(child_id, request_id); | 1135 GlobalRequestID new_request_id(child_id, request_id); |
| 1134 | 1136 |
| 1135 // Clear out data that depends on |info| before updating it. | 1137 // Clear out data that depends on |info| before updating it. |
| 1136 // We always need to move the memory stats to the new process. In contrast, | 1138 // We always need to move the memory stats to the new process. In contrast, |
| 1137 // stats.num_requests is only tracked for some requests (those that require | 1139 // stats.num_requests is only tracked for some requests (those that require |
| 1138 // file descriptors for their shared memory buffer). | 1140 // file descriptors for their shared memory buffer). |
| 1139 IncrementOutstandingRequestsMemory(-1, *info); | 1141 IncrementOutstandingRequestsMemory(-1, *info); |
| 1140 bool should_update_count = info->counted_as_in_flight_request(); | 1142 bool should_update_count = info->counted_as_in_flight_request(); |
| 1141 if (should_update_count) | 1143 if (should_update_count) |
| 1142 IncrementOutstandingRequestsCount(-1, info); | 1144 IncrementOutstandingRequestsCount(-1, info); |
| 1143 | 1145 |
| 1144 DCHECK(pending_loaders_.find(old_request_id) == iter); | 1146 DCHECK(pending_loaders_.find(old_request_id) == iter); |
| 1145 std::unique_ptr<ResourceLoader> loader = std::move(iter->second); | 1147 std::unique_ptr<ResourceLoader> loader = std::move(iter->second); |
| 1146 ResourceLoader* loader_ptr = loader.get(); | 1148 ResourceLoader* loader_ptr = loader.get(); |
| 1147 pending_loaders_.erase(iter); | 1149 pending_loaders_.erase(iter); |
| 1148 | 1150 |
| 1149 // ResourceHandlers should always get state related to the request from the | 1151 // ResourceHandlers should always get state related to the request from the |
| 1150 // ResourceRequestInfo rather than caching it locally. This lets us update | 1152 // ResourceRequestInfo rather than caching it locally. This lets us update |
| 1151 // the info object when a transfer occurs. | 1153 // the info object when a transfer occurs. |
| 1152 info->UpdateForTransfer(child_id, route_id, request_data.render_frame_id, | 1154 info->UpdateForTransfer(child_id, route_id, request_data.render_frame_id, |
| 1153 request_data.origin_pid, request_id, | 1155 request_data.origin_pid, request_id, |
| 1154 filter_->GetWeakPtr()); | 1156 filter_->GetWeakPtr(), std::move(mojo_request), |
| 1157 std::move(url_loader_client)); |
| 1155 | 1158 |
| 1156 // Update maps that used the old IDs, if necessary. Some transfers in tests | 1159 // Update maps that used the old IDs, if necessary. Some transfers in tests |
| 1157 // do not actually use a different ID, so not all maps need to be updated. | 1160 // do not actually use a different ID, so not all maps need to be updated. |
| 1158 pending_loaders_[new_request_id] = std::move(loader); | 1161 pending_loaders_[new_request_id] = std::move(loader); |
| 1159 IncrementOutstandingRequestsMemory(1, *info); | 1162 IncrementOutstandingRequestsMemory(1, *info); |
| 1160 if (should_update_count) | 1163 if (should_update_count) |
| 1161 IncrementOutstandingRequestsCount(1, info); | 1164 IncrementOutstandingRequestsCount(1, info); |
| 1162 if (old_routing_id != new_routing_id) { | 1165 if (old_routing_id != new_routing_id) { |
| 1163 if (blocked_loaders_map_.find(old_routing_id) != | 1166 if (blocked_loaders_map_.find(old_routing_id) != |
| 1164 blocked_loaders_map_.end()) { | 1167 blocked_loaders_map_.end()) { |
| (...skipping 29 matching lines...) Expand all Loading... |
| 1194 } else { | 1197 } else { |
| 1195 handler->CompleteCrossSiteTransfer( | 1198 handler->CompleteCrossSiteTransfer( |
| 1196 child_id, request_data.service_worker_provider_id); | 1199 child_id, request_data.service_worker_provider_id); |
| 1197 } | 1200 } |
| 1198 } | 1201 } |
| 1199 } | 1202 } |
| 1200 | 1203 |
| 1201 void ResourceDispatcherHostImpl::CompleteTransfer( | 1204 void ResourceDispatcherHostImpl::CompleteTransfer( |
| 1202 int request_id, | 1205 int request_id, |
| 1203 const ResourceRequest& request_data, | 1206 const ResourceRequest& request_data, |
| 1204 int route_id) { | 1207 int route_id, |
| 1208 mojom::URLLoaderAssociatedRequest mojo_request, |
| 1209 mojom::URLLoaderClientAssociatedPtr url_loader_client) { |
| 1205 // Caller should ensure that |request_data| is associated with a transfer. | 1210 // Caller should ensure that |request_data| is associated with a transfer. |
| 1206 DCHECK(request_data.transferred_request_child_id != -1 || | 1211 DCHECK(request_data.transferred_request_child_id != -1 || |
| 1207 request_data.transferred_request_request_id != -1); | 1212 request_data.transferred_request_request_id != -1); |
| 1208 | 1213 |
| 1209 bool is_navigational_request = | 1214 bool is_navigational_request = |
| 1210 request_data.resource_type == RESOURCE_TYPE_MAIN_FRAME || | 1215 request_data.resource_type == RESOURCE_TYPE_MAIN_FRAME || |
| 1211 request_data.resource_type == RESOURCE_TYPE_SUB_FRAME; | 1216 request_data.resource_type == RESOURCE_TYPE_SUB_FRAME; |
| 1212 if (!is_navigational_request) { | 1217 if (!is_navigational_request) { |
| 1213 // Transfers apply only to navigational requests - the renderer seems to | 1218 // Transfers apply only to navigational requests - the renderer seems to |
| 1214 // have sent bogus IPC data. | 1219 // have sent bogus IPC data. |
| (...skipping 23 matching lines...) Expand all Loading... |
| 1238 // transferring loader on the browser side. | 1243 // transferring loader on the browser side. |
| 1239 base::debug::Alias(pending_loader); | 1244 base::debug::Alias(pending_loader); |
| 1240 bad_message::ReceivedBadMessage(filter_, | 1245 bad_message::ReceivedBadMessage(filter_, |
| 1241 bad_message::RDH_REQUEST_NOT_TRANSFERRING); | 1246 bad_message::RDH_REQUEST_NOT_TRANSFERRING); |
| 1242 return; | 1247 return; |
| 1243 } | 1248 } |
| 1244 | 1249 |
| 1245 // If the request is transferring to a new process, we can update our | 1250 // If the request is transferring to a new process, we can update our |
| 1246 // state and let it resume with its existing ResourceHandlers. | 1251 // state and let it resume with its existing ResourceHandlers. |
| 1247 UpdateRequestForTransfer(filter_->child_id(), route_id, request_id, | 1252 UpdateRequestForTransfer(filter_->child_id(), route_id, request_id, |
| 1248 request_data, it); | 1253 request_data, it, std::move(mojo_request), |
| 1254 std::move(url_loader_client)); |
| 1249 pending_loader->CompleteTransfer(); | 1255 pending_loader->CompleteTransfer(); |
| 1250 } | 1256 } |
| 1251 | 1257 |
| 1252 void ResourceDispatcherHostImpl::BeginRequest( | 1258 void ResourceDispatcherHostImpl::BeginRequest( |
| 1253 int request_id, | 1259 int request_id, |
| 1254 const ResourceRequest& request_data, | 1260 const ResourceRequest& request_data, |
| 1255 const SyncLoadResultCallback& sync_result_handler, // only valid for sync | 1261 const SyncLoadResultCallback& sync_result_handler, // only valid for sync |
| 1256 int route_id, | 1262 int route_id, |
| 1257 mojom::URLLoaderAssociatedRequest mojo_request, | 1263 mojom::URLLoaderAssociatedRequest mojo_request, |
| 1258 mojom::URLLoaderClientAssociatedPtr url_loader_client) { | 1264 mojom::URLLoaderClientAssociatedPtr url_loader_client) { |
| (...skipping 29 matching lines...) Expand all Loading... |
| 1288 // If we crash here, figure out what URL the renderer was requesting. | 1294 // If we crash here, figure out what URL the renderer was requesting. |
| 1289 // http://crbug.com/91398 | 1295 // http://crbug.com/91398 |
| 1290 char url_buf[128]; | 1296 char url_buf[128]; |
| 1291 base::strlcpy(url_buf, request_data.url.spec().c_str(), arraysize(url_buf)); | 1297 base::strlcpy(url_buf, request_data.url.spec().c_str(), arraysize(url_buf)); |
| 1292 base::debug::Alias(url_buf); | 1298 base::debug::Alias(url_buf); |
| 1293 | 1299 |
| 1294 // If the request that's coming in is being transferred from another process, | 1300 // If the request that's coming in is being transferred from another process, |
| 1295 // we want to reuse and resume the old loader rather than start a new one. | 1301 // we want to reuse and resume the old loader rather than start a new one. |
| 1296 if (request_data.transferred_request_child_id != -1 || | 1302 if (request_data.transferred_request_child_id != -1 || |
| 1297 request_data.transferred_request_request_id != -1) { | 1303 request_data.transferred_request_request_id != -1) { |
| 1298 // TODO(yhirano): Make mojo work for this case. | 1304 CompleteTransfer(request_id, request_data, route_id, |
| 1299 DCHECK(!url_loader_client); | 1305 std::move(mojo_request), std::move(url_loader_client)); |
| 1300 | |
| 1301 CompleteTransfer(request_id, request_data, route_id); | |
| 1302 return; | 1306 return; |
| 1303 } | 1307 } |
| 1304 | 1308 |
| 1305 ResourceContext* resource_context = NULL; | 1309 ResourceContext* resource_context = NULL; |
| 1306 net::URLRequestContext* request_context = NULL; | 1310 net::URLRequestContext* request_context = NULL; |
| 1307 filter_->GetContexts(request_data.resource_type, &resource_context, | 1311 filter_->GetContexts(request_data.resource_type, &resource_context, |
| 1308 &request_context); | 1312 &request_context); |
| 1309 | 1313 |
| 1310 // Parse the headers before calling ShouldServiceRequest, so that they are | 1314 // Parse the headers before calling ShouldServiceRequest, so that they are |
| 1311 // available to be validated. | 1315 // available to be validated. |
| (...skipping 1488 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2800 &throttles); | 2804 &throttles); |
| 2801 if (!throttles.empty()) { | 2805 if (!throttles.empty()) { |
| 2802 handler.reset(new ThrottlingResourceHandler(std::move(handler), request, | 2806 handler.reset(new ThrottlingResourceHandler(std::move(handler), request, |
| 2803 std::move(throttles))); | 2807 std::move(throttles))); |
| 2804 } | 2808 } |
| 2805 } | 2809 } |
| 2806 return handler; | 2810 return handler; |
| 2807 } | 2811 } |
| 2808 | 2812 |
| 2809 } // namespace content | 2813 } // namespace content |
| OLD | NEW |