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 <algorithm> | 9 #include <algorithm> |
10 #include <set> | 10 #include <set> |
(...skipping 959 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
970 } | 970 } |
971 | 971 |
972 filter_ = NULL; | 972 filter_ = NULL; |
973 return handled; | 973 return handled; |
974 } | 974 } |
975 | 975 |
976 void ResourceDispatcherHostImpl::OnRequestResource( | 976 void ResourceDispatcherHostImpl::OnRequestResource( |
977 int routing_id, | 977 int routing_id, |
978 int request_id, | 978 int request_id, |
979 const ResourceHostMsg_Request& request_data) { | 979 const ResourceHostMsg_Request& request_data) { |
| 980 // TODO(pkasting): Remove ScopedTracker below once crbug.com/456331 is fixed. |
| 981 tracked_objects::ScopedTracker tracking_profile( |
| 982 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 983 "456331 ResourceDispatcherHostImpl::OnRequestResource")); |
980 // When logging time-to-network only care about main frame and non-transfer | 984 // When logging time-to-network only care about main frame and non-transfer |
981 // navigations. | 985 // navigations. |
982 if (request_data.resource_type == RESOURCE_TYPE_MAIN_FRAME && | 986 if (request_data.resource_type == RESOURCE_TYPE_MAIN_FRAME && |
983 request_data.transferred_request_request_id == -1 && | 987 request_data.transferred_request_request_id == -1 && |
984 !base::CommandLine::ForCurrentProcess()->HasSwitch( | 988 !base::CommandLine::ForCurrentProcess()->HasSwitch( |
985 switches::kEnableBrowserSideNavigation)) { | 989 switches::kEnableBrowserSideNavigation)) { |
986 BrowserThread::PostTask( | 990 BrowserThread::PostTask( |
987 BrowserThread::UI, | 991 BrowserThread::UI, |
988 FROM_HERE, | 992 FROM_HERE, |
989 base::Bind(&LogResourceRequestTimeOnUI, | 993 base::Bind(&LogResourceRequestTimeOnUI, |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1085 | 1089 |
1086 // We should have a CrossSiteResourceHandler to finish the transfer. | 1090 // We should have a CrossSiteResourceHandler to finish the transfer. |
1087 DCHECK(info->cross_site_handler()); | 1091 DCHECK(info->cross_site_handler()); |
1088 } | 1092 } |
1089 | 1093 |
1090 void ResourceDispatcherHostImpl::BeginRequest( | 1094 void ResourceDispatcherHostImpl::BeginRequest( |
1091 int request_id, | 1095 int request_id, |
1092 const ResourceHostMsg_Request& request_data, | 1096 const ResourceHostMsg_Request& request_data, |
1093 IPC::Message* sync_result, // only valid for sync | 1097 IPC::Message* sync_result, // only valid for sync |
1094 int route_id) { | 1098 int route_id) { |
| 1099 // TODO(pkasting): Remove ScopedTracker below once crbug.com/456331 is fixed. |
| 1100 tracked_objects::ScopedTracker tracking_profile1( |
| 1101 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 1102 "456331 ResourceDispatcherHostImpl::BeginRequest1")); |
1095 int process_type = filter_->process_type(); | 1103 int process_type = filter_->process_type(); |
1096 int child_id = filter_->child_id(); | 1104 int child_id = filter_->child_id(); |
1097 | 1105 |
1098 // Reject invalid priority. | 1106 // Reject invalid priority. |
1099 if (request_data.priority < net::MINIMUM_PRIORITY || | 1107 if (request_data.priority < net::MINIMUM_PRIORITY || |
1100 request_data.priority > net::MAXIMUM_PRIORITY) { | 1108 request_data.priority > net::MAXIMUM_PRIORITY) { |
1101 RecordAction(base::UserMetricsAction("BadMessageTerminate_RDH")); | 1109 RecordAction(base::UserMetricsAction("BadMessageTerminate_RDH")); |
1102 filter_->BadMessageReceived(); | 1110 filter_->BadMessageReceived(); |
1103 return; | 1111 return; |
1104 } | 1112 } |
1105 | 1113 |
1106 // If we crash here, figure out what URL the renderer was requesting. | 1114 // If we crash here, figure out what URL the renderer was requesting. |
1107 // http://crbug.com/91398 | 1115 // http://crbug.com/91398 |
1108 char url_buf[128]; | 1116 char url_buf[128]; |
1109 base::strlcpy(url_buf, request_data.url.spec().c_str(), arraysize(url_buf)); | 1117 base::strlcpy(url_buf, request_data.url.spec().c_str(), arraysize(url_buf)); |
1110 base::debug::Alias(url_buf); | 1118 base::debug::Alias(url_buf); |
1111 | 1119 |
1112 // If the request that's coming in is being transferred from another process, | 1120 // If the request that's coming in is being transferred from another process, |
1113 // we want to reuse and resume the old loader rather than start a new one. | 1121 // we want to reuse and resume the old loader rather than start a new one. |
1114 { | 1122 { |
| 1123 // TODO(pkasting): Remove ScopedTracker below once crbug.com/456331 is |
| 1124 // fixed. |
| 1125 tracked_objects::ScopedTracker tracking_profile2( |
| 1126 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 1127 "456331 ResourceDispatcherHostImpl::BeginRequest2")); |
1115 LoaderMap::iterator it = pending_loaders_.find( | 1128 LoaderMap::iterator it = pending_loaders_.find( |
1116 GlobalRequestID(request_data.transferred_request_child_id, | 1129 GlobalRequestID(request_data.transferred_request_child_id, |
1117 request_data.transferred_request_request_id)); | 1130 request_data.transferred_request_request_id)); |
1118 if (it != pending_loaders_.end()) { | 1131 if (it != pending_loaders_.end()) { |
1119 // If the request is transferring to a new process, we can update our | 1132 // If the request is transferring to a new process, we can update our |
1120 // state and let it resume with its existing ResourceHandlers. | 1133 // state and let it resume with its existing ResourceHandlers. |
1121 if (it->second->is_transferring()) { | 1134 if (it->second->is_transferring()) { |
1122 linked_ptr<ResourceLoader> deferred_loader = it->second; | 1135 linked_ptr<ResourceLoader> deferred_loader = it->second; |
1123 UpdateRequestForTransfer(child_id, route_id, request_id, | 1136 UpdateRequestForTransfer(child_id, route_id, request_id, |
1124 request_data, deferred_loader); | 1137 request_data, deferred_loader); |
1125 | 1138 |
1126 deferred_loader->CompleteTransfer(); | 1139 deferred_loader->CompleteTransfer(); |
1127 } else { | 1140 } else { |
1128 RecordAction(base::UserMetricsAction("BadMessageTerminate_RDH")); | 1141 RecordAction(base::UserMetricsAction("BadMessageTerminate_RDH")); |
1129 filter_->BadMessageReceived(); | 1142 filter_->BadMessageReceived(); |
1130 } | 1143 } |
1131 return; | 1144 return; |
1132 } | 1145 } |
1133 } | 1146 } |
1134 | 1147 |
| 1148 // TODO(pkasting): Remove ScopedTracker below once crbug.com/456331 is fixed. |
| 1149 tracked_objects::ScopedTracker tracking_profile3( |
| 1150 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 1151 "456331 ResourceDispatcherHostImpl::BeginRequest3")); |
1135 ResourceContext* resource_context = NULL; | 1152 ResourceContext* resource_context = NULL; |
1136 net::URLRequestContext* request_context = NULL; | 1153 net::URLRequestContext* request_context = NULL; |
1137 filter_->GetContexts(request_data, &resource_context, &request_context); | 1154 filter_->GetContexts(request_data, &resource_context, &request_context); |
1138 // http://crbug.com/90971 | 1155 // http://crbug.com/90971 |
1139 CHECK(ContainsKey(active_resource_contexts_, resource_context)); | 1156 CHECK(ContainsKey(active_resource_contexts_, resource_context)); |
1140 | 1157 |
1141 if (is_shutdown_ || | 1158 if (is_shutdown_ || |
1142 !ShouldServiceRequest(process_type, child_id, request_data, | 1159 !ShouldServiceRequest(process_type, child_id, request_data, |
1143 filter_->file_system_context())) { | 1160 filter_->file_system_context())) { |
1144 AbortRequestBeforeItStarts(filter_, sync_result, request_id); | 1161 AbortRequestBeforeItStarts(filter_, sync_result, request_id); |
1145 return; | 1162 return; |
1146 } | 1163 } |
1147 | 1164 |
1148 // Allow the observer to block/handle the request. | 1165 // Allow the observer to block/handle the request. |
1149 if (delegate_ && !delegate_->ShouldBeginRequest(request_data.method, | 1166 if (delegate_ && !delegate_->ShouldBeginRequest(request_data.method, |
1150 request_data.url, | 1167 request_data.url, |
1151 request_data.resource_type, | 1168 request_data.resource_type, |
1152 resource_context)) { | 1169 resource_context)) { |
1153 AbortRequestBeforeItStarts(filter_, sync_result, request_id); | 1170 AbortRequestBeforeItStarts(filter_, sync_result, request_id); |
1154 return; | 1171 return; |
1155 } | 1172 } |
1156 | 1173 |
| 1174 // TODO(pkasting): Remove ScopedTracker below once crbug.com/456331 is fixed. |
| 1175 tracked_objects::ScopedTracker tracking_profile4( |
| 1176 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 1177 "456331 ResourceDispatcherHostImpl::BeginRequest4")); |
1157 // Construct the request. | 1178 // Construct the request. |
1158 net::CookieStore* cookie_store = | 1179 net::CookieStore* cookie_store = |
1159 GetContentClient()->browser()->OverrideCookieStoreForRenderProcess( | 1180 GetContentClient()->browser()->OverrideCookieStoreForRenderProcess( |
1160 child_id); | 1181 child_id); |
1161 scoped_ptr<net::URLRequest> new_request; | 1182 scoped_ptr<net::URLRequest> new_request; |
1162 new_request = request_context->CreateRequest( | 1183 new_request = request_context->CreateRequest( |
1163 request_data.url, request_data.priority, NULL, cookie_store); | 1184 request_data.url, request_data.priority, NULL, cookie_store); |
1164 | 1185 |
1165 new_request->set_method(request_data.method); | 1186 new_request->set_method(request_data.method); |
1166 new_request->set_first_party_for_cookies( | 1187 new_request->set_first_party_for_cookies( |
1167 request_data.first_party_for_cookies); | 1188 request_data.first_party_for_cookies); |
1168 | 1189 |
1169 // If the request is a MAIN_FRAME request, the first-party URL gets updated on | 1190 // If the request is a MAIN_FRAME request, the first-party URL gets updated on |
1170 // redirects. | 1191 // redirects. |
1171 if (request_data.resource_type == RESOURCE_TYPE_MAIN_FRAME) { | 1192 if (request_data.resource_type == RESOURCE_TYPE_MAIN_FRAME) { |
1172 new_request->set_first_party_url_policy( | 1193 new_request->set_first_party_url_policy( |
1173 net::URLRequest::UPDATE_FIRST_PARTY_URL_ON_REDIRECT); | 1194 net::URLRequest::UPDATE_FIRST_PARTY_URL_ON_REDIRECT); |
1174 } | 1195 } |
1175 | 1196 |
1176 const Referrer referrer(request_data.referrer, request_data.referrer_policy); | 1197 const Referrer referrer(request_data.referrer, request_data.referrer_policy); |
1177 SetReferrerForRequest(new_request.get(), referrer); | 1198 SetReferrerForRequest(new_request.get(), referrer); |
1178 | 1199 |
1179 net::HttpRequestHeaders headers; | 1200 net::HttpRequestHeaders headers; |
1180 headers.AddHeadersFromString(request_data.headers); | 1201 headers.AddHeadersFromString(request_data.headers); |
1181 new_request->SetExtraRequestHeaders(headers); | 1202 new_request->SetExtraRequestHeaders(headers); |
1182 | 1203 |
| 1204 // TODO(pkasting): Remove ScopedTracker below once crbug.com/456331 is fixed. |
| 1205 tracked_objects::ScopedTracker tracking_profile5( |
| 1206 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 1207 "456331 ResourceDispatcherHostImpl::BeginRequest5")); |
1183 storage::BlobStorageContext* blob_context = | 1208 storage::BlobStorageContext* blob_context = |
1184 GetBlobStorageContext(filter_->blob_storage_context()); | 1209 GetBlobStorageContext(filter_->blob_storage_context()); |
1185 // Resolve elements from request_body and prepare upload data. | 1210 // Resolve elements from request_body and prepare upload data. |
1186 if (request_data.request_body.get()) { | 1211 if (request_data.request_body.get()) { |
1187 // |blob_context| could be null when the request is from the plugins because | 1212 // |blob_context| could be null when the request is from the plugins because |
1188 // ResourceMessageFilters created in PluginProcessHost don't have the blob | 1213 // ResourceMessageFilters created in PluginProcessHost don't have the blob |
1189 // context. | 1214 // context. |
1190 if (blob_context) { | 1215 if (blob_context) { |
1191 // Attaches the BlobDataHandles to request_body not to free the blobs and | 1216 // Attaches the BlobDataHandles to request_body not to free the blobs and |
1192 // any attached shareable files until upload completion. These data will | 1217 // any attached shareable files until upload completion. These data will |
1193 // be used in UploadDataStream and ServiceWorkerURLRequestJob. | 1218 // be used in UploadDataStream and ServiceWorkerURLRequestJob. |
1194 AttachRequestBodyBlobDataHandles( | 1219 AttachRequestBodyBlobDataHandles( |
1195 request_data.request_body.get(), | 1220 request_data.request_body.get(), |
1196 blob_context); | 1221 blob_context); |
1197 } | 1222 } |
1198 new_request->set_upload(UploadDataStreamBuilder::Build( | 1223 new_request->set_upload(UploadDataStreamBuilder::Build( |
1199 request_data.request_body.get(), | 1224 request_data.request_body.get(), |
1200 blob_context, | 1225 blob_context, |
1201 filter_->file_system_context(), | 1226 filter_->file_system_context(), |
1202 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE) | 1227 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE) |
1203 .get())); | 1228 .get())); |
1204 } | 1229 } |
1205 | 1230 |
| 1231 // TODO(pkasting): Remove ScopedTracker below once crbug.com/456331 is fixed. |
| 1232 tracked_objects::ScopedTracker tracking_profile6( |
| 1233 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 1234 "456331 ResourceDispatcherHostImpl::BeginRequest6")); |
1206 bool allow_download = request_data.allow_download && | 1235 bool allow_download = request_data.allow_download && |
1207 IsResourceTypeFrame(request_data.resource_type); | 1236 IsResourceTypeFrame(request_data.resource_type); |
1208 bool do_not_prompt_for_login = request_data.do_not_prompt_for_login; | 1237 bool do_not_prompt_for_login = request_data.do_not_prompt_for_login; |
1209 bool is_sync_load = sync_result != NULL; | 1238 bool is_sync_load = sync_result != NULL; |
1210 int load_flags = | 1239 int load_flags = |
1211 BuildLoadFlagsForRequest(request_data, child_id, is_sync_load); | 1240 BuildLoadFlagsForRequest(request_data, child_id, is_sync_load); |
1212 if (request_data.resource_type == RESOURCE_TYPE_PREFETCH || | 1241 if (request_data.resource_type == RESOURCE_TYPE_PREFETCH || |
1213 request_data.resource_type == RESOURCE_TYPE_FAVICON) { | 1242 request_data.resource_type == RESOURCE_TYPE_FAVICON) { |
1214 do_not_prompt_for_login = true; | 1243 do_not_prompt_for_login = true; |
1215 } | 1244 } |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1271 | 1300 |
1272 if (new_request->url().SchemeIs(url::kBlobScheme)) { | 1301 if (new_request->url().SchemeIs(url::kBlobScheme)) { |
1273 // Hang on to a reference to ensure the blob is not released prior | 1302 // Hang on to a reference to ensure the blob is not released prior |
1274 // to the job being started. | 1303 // to the job being started. |
1275 storage::BlobProtocolHandler::SetRequestedBlobDataHandle( | 1304 storage::BlobProtocolHandler::SetRequestedBlobDataHandle( |
1276 new_request.get(), | 1305 new_request.get(), |
1277 filter_->blob_storage_context()->context()->GetBlobDataFromPublicURL( | 1306 filter_->blob_storage_context()->context()->GetBlobDataFromPublicURL( |
1278 new_request->url())); | 1307 new_request->url())); |
1279 } | 1308 } |
1280 | 1309 |
| 1310 // TODO(pkasting): Remove ScopedTracker below once crbug.com/456331 is fixed. |
| 1311 tracked_objects::ScopedTracker tracking_profile7( |
| 1312 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 1313 "456331 ResourceDispatcherHostImpl::BeginRequest7")); |
1281 // Initialize the service worker handler for the request. We don't use | 1314 // Initialize the service worker handler for the request. We don't use |
1282 // ServiceWorker for synchronous loads to avoid renderer deadlocks. | 1315 // ServiceWorker for synchronous loads to avoid renderer deadlocks. |
1283 ServiceWorkerRequestHandler::InitializeHandler( | 1316 ServiceWorkerRequestHandler::InitializeHandler( |
1284 new_request.get(), | 1317 new_request.get(), |
1285 filter_->service_worker_context(), | 1318 filter_->service_worker_context(), |
1286 blob_context, | 1319 blob_context, |
1287 child_id, | 1320 child_id, |
1288 request_data.service_worker_provider_id, | 1321 request_data.service_worker_provider_id, |
1289 request_data.skip_service_worker || is_sync_load, | 1322 request_data.skip_service_worker || is_sync_load, |
1290 request_data.fetch_request_mode, | 1323 request_data.fetch_request_mode, |
(...skipping 733 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2024 request->method().size(); | 2057 request->method().size(); |
2025 | 2058 |
2026 // Note that this expression will typically be dominated by: | 2059 // Note that this expression will typically be dominated by: |
2027 // |kAvgBytesPerOutstandingRequest|. | 2060 // |kAvgBytesPerOutstandingRequest|. |
2028 return kAvgBytesPerOutstandingRequest + strings_cost; | 2061 return kAvgBytesPerOutstandingRequest + strings_cost; |
2029 } | 2062 } |
2030 | 2063 |
2031 void ResourceDispatcherHostImpl::BeginRequestInternal( | 2064 void ResourceDispatcherHostImpl::BeginRequestInternal( |
2032 scoped_ptr<net::URLRequest> request, | 2065 scoped_ptr<net::URLRequest> request, |
2033 scoped_ptr<ResourceHandler> handler) { | 2066 scoped_ptr<ResourceHandler> handler) { |
| 2067 // TODO(pkasting): Remove ScopedTracker below once crbug.com/456331 is fixed. |
| 2068 tracked_objects::ScopedTracker tracking_profile( |
| 2069 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 2070 "456331 ResourceDispatcherHostImpl::BeginRequestInternal")); |
2034 DCHECK(!request->is_pending()); | 2071 DCHECK(!request->is_pending()); |
2035 ResourceRequestInfoImpl* info = | 2072 ResourceRequestInfoImpl* info = |
2036 ResourceRequestInfoImpl::ForRequest(request.get()); | 2073 ResourceRequestInfoImpl::ForRequest(request.get()); |
2037 | 2074 |
2038 if ((TimeTicks::Now() - last_user_gesture_time_) < | 2075 if ((TimeTicks::Now() - last_user_gesture_time_) < |
2039 TimeDelta::FromMilliseconds(kUserGestureWindowMs)) { | 2076 TimeDelta::FromMilliseconds(kUserGestureWindowMs)) { |
2040 request->SetLoadFlags( | 2077 request->SetLoadFlags( |
2041 request->load_flags() | net::LOAD_MAYBE_USER_GESTURE); | 2078 request->load_flags() | net::LOAD_MAYBE_USER_GESTURE); |
2042 } | 2079 } |
2043 | 2080 |
(...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2374 | 2411 |
2375 // Add a flag to selectively bypass the data reduction proxy if the resource | 2412 // Add a flag to selectively bypass the data reduction proxy if the resource |
2376 // type is not an image. | 2413 // type is not an image. |
2377 if (request_data.resource_type != RESOURCE_TYPE_IMAGE) | 2414 if (request_data.resource_type != RESOURCE_TYPE_IMAGE) |
2378 load_flags |= net::LOAD_BYPASS_DATA_REDUCTION_PROXY; | 2415 load_flags |= net::LOAD_BYPASS_DATA_REDUCTION_PROXY; |
2379 | 2416 |
2380 return load_flags; | 2417 return load_flags; |
2381 } | 2418 } |
2382 | 2419 |
2383 } // namespace content | 2420 } // namespace content |
OLD | NEW |