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

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

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

Powered by Google App Engine
This is Rietveld 408576698