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