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 <set> | 9 #include <set> |
10 #include <vector> | 10 #include <vector> |
(...skipping 467 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
478 // is no current mechanism to prompt the user for their consent for a | 478 // is no current mechanism to prompt the user for their consent for a |
479 // re-post. For GETs, try to retrieve data from the cache and skip | 479 // re-post. For GETs, try to retrieve data from the cache and skip |
480 // validating the entry if present. | 480 // validating the entry if present. |
481 if (request->get_upload() != NULL) | 481 if (request->get_upload() != NULL) |
482 extra_load_flags |= net::LOAD_ONLY_FROM_CACHE; | 482 extra_load_flags |= net::LOAD_ONLY_FROM_CACHE; |
483 else | 483 else |
484 extra_load_flags |= net::LOAD_PREFERRING_CACHE; | 484 extra_load_flags |= net::LOAD_PREFERRING_CACHE; |
485 } else { | 485 } else { |
486 extra_load_flags |= net::LOAD_DISABLE_CACHE; | 486 extra_load_flags |= net::LOAD_DISABLE_CACHE; |
487 } | 487 } |
488 request->set_load_flags(request->load_flags() | extra_load_flags); | 488 request->SetLoadFlags(request->load_flags() | extra_load_flags); |
489 | 489 |
490 // No need to get offline load flags for downloads, but make sure | 490 // No need to get offline load flags for downloads, but make sure |
491 // we have an OfflinePolicy to receive request completions. | 491 // we have an OfflinePolicy to receive request completions. |
492 GlobalRoutingID id(child_id, route_id); | 492 GlobalRoutingID id(child_id, route_id); |
493 if (!offline_policy_map_[id]) | 493 if (!offline_policy_map_[id]) |
494 offline_policy_map_[id] = new OfflinePolicy(); | 494 offline_policy_map_[id] = new OfflinePolicy(); |
495 | 495 |
496 // Check if the renderer is permitted to request the requested URL. | 496 // Check if the renderer is permitted to request the requested URL. |
497 if (!ChildProcessSecurityPolicyImpl::GetInstance()-> | 497 if (!ChildProcessSecurityPolicyImpl::GetInstance()-> |
498 CanRequestURL(child_id, url)) { | 498 CanRequestURL(child_id, url)) { |
(...skipping 534 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1033 bool is_sync_load = sync_result != NULL; | 1033 bool is_sync_load = sync_result != NULL; |
1034 int load_flags = | 1034 int load_flags = |
1035 BuildLoadFlagsForRequest(request_data, child_id, is_sync_load); | 1035 BuildLoadFlagsForRequest(request_data, child_id, is_sync_load); |
1036 | 1036 |
1037 GlobalRoutingID id(child_id, route_id); | 1037 GlobalRoutingID id(child_id, route_id); |
1038 if (!offline_policy_map_[id]) | 1038 if (!offline_policy_map_[id]) |
1039 offline_policy_map_[id] = new OfflinePolicy(); | 1039 offline_policy_map_[id] = new OfflinePolicy(); |
1040 load_flags |= offline_policy_map_[id]->GetAdditionalLoadFlags( | 1040 load_flags |= offline_policy_map_[id]->GetAdditionalLoadFlags( |
1041 load_flags, request_data.resource_type == ResourceType::MAIN_FRAME); | 1041 load_flags, request_data.resource_type == ResourceType::MAIN_FRAME); |
1042 | 1042 |
| 1043 // Sync loads should have maximum priority and should be the only |
| 1044 // requets that have the ignore limits flag set. |
| 1045 if (is_sync_load) { |
| 1046 DCHECK_EQ(request_data.priority, net::MAXIMUM_PRIORITY); |
| 1047 DCHECK_NE(load_flags & net::LOAD_IGNORE_LIMITS, 0); |
| 1048 } else { |
| 1049 DCHECK_EQ(load_flags & net::LOAD_IGNORE_LIMITS, 0); |
| 1050 } |
| 1051 |
1043 // Construct the request. | 1052 // Construct the request. |
1044 scoped_ptr<net::URLRequest> new_request; | 1053 scoped_ptr<net::URLRequest> new_request; |
1045 net::URLRequest* request; | 1054 net::URLRequest* request; |
1046 new_request = request_context->CreateRequest( | 1055 new_request = request_context->CreateRequest( |
1047 request_data.url, request_data.priority, NULL); | 1056 request_data.url, request_data.priority, NULL); |
1048 request = new_request.get(); | 1057 request = new_request.get(); |
1049 | 1058 |
1050 request->set_method(request_data.method); | 1059 request->set_method(request_data.method); |
1051 request->set_first_party_for_cookies(request_data.first_party_for_cookies); | 1060 request->set_first_party_for_cookies(request_data.first_party_for_cookies); |
1052 SetReferrerForRequest(request, referrer); | 1061 SetReferrerForRequest(request, referrer); |
1053 | 1062 |
1054 net::HttpRequestHeaders headers; | 1063 net::HttpRequestHeaders headers; |
1055 headers.AddHeadersFromString(request_data.headers); | 1064 headers.AddHeadersFromString(request_data.headers); |
1056 request->SetExtraRequestHeaders(headers); | 1065 request->SetExtraRequestHeaders(headers); |
1057 | 1066 |
1058 request->set_load_flags(load_flags); | 1067 request->SetLoadFlags(load_flags); |
1059 | 1068 |
1060 // Resolve elements from request_body and prepare upload data. | 1069 // Resolve elements from request_body and prepare upload data. |
1061 if (request_data.request_body.get()) { | 1070 if (request_data.request_body.get()) { |
1062 webkit_blob::BlobStorageContext* blob_context = NULL; | 1071 webkit_blob::BlobStorageContext* blob_context = NULL; |
1063 if (filter_->blob_storage_context()) | 1072 if (filter_->blob_storage_context()) |
1064 blob_context = filter_->blob_storage_context()->context(); | 1073 blob_context = filter_->blob_storage_context()->context(); |
1065 request->set_upload(UploadDataStreamBuilder::Build( | 1074 request->set_upload(UploadDataStreamBuilder::Build( |
1066 request_data.request_body.get(), | 1075 request_data.request_body.get(), |
1067 blob_context, | 1076 blob_context, |
1068 filter_->file_system_context(), | 1077 filter_->file_system_context(), |
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1295 return; | 1304 return; |
1296 } | 1305 } |
1297 | 1306 |
1298 scoped_ptr<net::URLRequest> request( | 1307 scoped_ptr<net::URLRequest> request( |
1299 request_context->CreateRequest(url, net::DEFAULT_PRIORITY, NULL)); | 1308 request_context->CreateRequest(url, net::DEFAULT_PRIORITY, NULL)); |
1300 request->set_method("GET"); | 1309 request->set_method("GET"); |
1301 SetReferrerForRequest(request.get(), referrer); | 1310 SetReferrerForRequest(request.get(), referrer); |
1302 | 1311 |
1303 // So far, for saving page, we need fetch content from cache, in the | 1312 // So far, for saving page, we need fetch content from cache, in the |
1304 // future, maybe we can use a configuration to configure this behavior. | 1313 // future, maybe we can use a configuration to configure this behavior. |
1305 request->set_load_flags(net::LOAD_PREFERRING_CACHE); | 1314 request->SetLoadFlags(net::LOAD_PREFERRING_CACHE); |
1306 | 1315 |
1307 // No need to get offline load flags for save files, but make sure | 1316 // No need to get offline load flags for save files, but make sure |
1308 // we have an OfflinePolicy to receive request completions. | 1317 // we have an OfflinePolicy to receive request completions. |
1309 GlobalRoutingID id(child_id, route_id); | 1318 GlobalRoutingID id(child_id, route_id); |
1310 if (!offline_policy_map_[id]) | 1319 if (!offline_policy_map_[id]) |
1311 offline_policy_map_[id] = new OfflinePolicy(); | 1320 offline_policy_map_[id] = new OfflinePolicy(); |
1312 | 1321 |
1313 // Since we're just saving some resources we need, disallow downloading. | 1322 // Since we're just saving some resources we need, disallow downloading. |
1314 ResourceRequestInfoImpl* extra_info = | 1323 ResourceRequestInfoImpl* extra_info = |
1315 CreateRequestInfo(child_id, route_id, false, context); | 1324 CreateRequestInfo(child_id, route_id, false, context); |
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1583 | 1592 |
1584 void ResourceDispatcherHostImpl::BeginRequestInternal( | 1593 void ResourceDispatcherHostImpl::BeginRequestInternal( |
1585 scoped_ptr<net::URLRequest> request, | 1594 scoped_ptr<net::URLRequest> request, |
1586 scoped_ptr<ResourceHandler> handler) { | 1595 scoped_ptr<ResourceHandler> handler) { |
1587 DCHECK(!request->is_pending()); | 1596 DCHECK(!request->is_pending()); |
1588 ResourceRequestInfoImpl* info = | 1597 ResourceRequestInfoImpl* info = |
1589 ResourceRequestInfoImpl::ForRequest(request.get()); | 1598 ResourceRequestInfoImpl::ForRequest(request.get()); |
1590 | 1599 |
1591 if ((TimeTicks::Now() - last_user_gesture_time_) < | 1600 if ((TimeTicks::Now() - last_user_gesture_time_) < |
1592 TimeDelta::FromMilliseconds(kUserGestureWindowMs)) { | 1601 TimeDelta::FromMilliseconds(kUserGestureWindowMs)) { |
1593 request->set_load_flags( | 1602 request->SetLoadFlags( |
1594 request->load_flags() | net::LOAD_MAYBE_USER_GESTURE); | 1603 request->load_flags() | net::LOAD_MAYBE_USER_GESTURE); |
1595 } | 1604 } |
1596 | 1605 |
1597 // Add the memory estimate that starting this request will consume. | 1606 // Add the memory estimate that starting this request will consume. |
1598 info->set_memory_cost(CalculateApproximateMemoryCost(request.get())); | 1607 info->set_memory_cost(CalculateApproximateMemoryCost(request.get())); |
1599 | 1608 |
1600 // If enqueing/starting this request will exceed our per-process memory | 1609 // If enqueing/starting this request will exceed our per-process memory |
1601 // bound, abort it right away. | 1610 // bound, abort it right away. |
1602 OustandingRequestsStats stats = IncrementOutstandingRequestsMemory(1, *info); | 1611 OustandingRequestsStats stats = IncrementOutstandingRequestsMemory(1, *info); |
1603 if (stats.memory_cost > max_outstanding_requests_cost_per_process_) { | 1612 if (stats.memory_cost > max_outstanding_requests_cost_per_process_) { |
(...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1933 if ((load_flags & net::LOAD_REPORT_RAW_HEADERS) | 1942 if ((load_flags & net::LOAD_REPORT_RAW_HEADERS) |
1934 && !policy->CanReadRawCookies(child_id)) { | 1943 && !policy->CanReadRawCookies(child_id)) { |
1935 VLOG(1) << "Denied unauthorized request for raw headers"; | 1944 VLOG(1) << "Denied unauthorized request for raw headers"; |
1936 load_flags &= ~net::LOAD_REPORT_RAW_HEADERS; | 1945 load_flags &= ~net::LOAD_REPORT_RAW_HEADERS; |
1937 } | 1946 } |
1938 | 1947 |
1939 return load_flags; | 1948 return load_flags; |
1940 } | 1949 } |
1941 | 1950 |
1942 } // namespace content | 1951 } // namespace content |
OLD | NEW |