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 455 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
466 // is no current mechanism to prompt the user for their consent for a | 466 // is no current mechanism to prompt the user for their consent for a |
467 // re-post. For GETs, try to retrieve data from the cache and skip | 467 // re-post. For GETs, try to retrieve data from the cache and skip |
468 // validating the entry if present. | 468 // validating the entry if present. |
469 if (request->get_upload() != NULL) | 469 if (request->get_upload() != NULL) |
470 extra_load_flags |= net::LOAD_ONLY_FROM_CACHE; | 470 extra_load_flags |= net::LOAD_ONLY_FROM_CACHE; |
471 else | 471 else |
472 extra_load_flags |= net::LOAD_PREFERRING_CACHE; | 472 extra_load_flags |= net::LOAD_PREFERRING_CACHE; |
473 } else { | 473 } else { |
474 extra_load_flags |= net::LOAD_DISABLE_CACHE; | 474 extra_load_flags |= net::LOAD_DISABLE_CACHE; |
475 } | 475 } |
476 request->set_load_flags(request->load_flags() | extra_load_flags); | 476 request->SetLoadFlags(request->load_flags() | extra_load_flags); |
477 | 477 |
478 // No need to get offline load flags for downloads, but make sure | 478 // No need to get offline load flags for downloads, but make sure |
479 // we have an OfflinePolicy to receive request completions. | 479 // we have an OfflinePolicy to receive request completions. |
480 GlobalRoutingID id(child_id, route_id); | 480 GlobalRoutingID id(child_id, route_id); |
481 if (!offline_policy_map_[id]) | 481 if (!offline_policy_map_[id]) |
482 offline_policy_map_[id] = new OfflinePolicy(); | 482 offline_policy_map_[id] = new OfflinePolicy(); |
483 | 483 |
484 // Check if the renderer is permitted to request the requested URL. | 484 // Check if the renderer is permitted to request the requested URL. |
485 if (!ChildProcessSecurityPolicyImpl::GetInstance()-> | 485 if (!ChildProcessSecurityPolicyImpl::GetInstance()-> |
486 CanRequestURL(child_id, url)) { | 486 CanRequestURL(child_id, url)) { |
(...skipping 533 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1020 bool is_sync_load = sync_result != NULL; | 1020 bool is_sync_load = sync_result != NULL; |
1021 int load_flags = | 1021 int load_flags = |
1022 BuildLoadFlagsForRequest(request_data, child_id, is_sync_load); | 1022 BuildLoadFlagsForRequest(request_data, child_id, is_sync_load); |
1023 | 1023 |
1024 GlobalRoutingID id(child_id, route_id); | 1024 GlobalRoutingID id(child_id, route_id); |
1025 if (!offline_policy_map_[id]) | 1025 if (!offline_policy_map_[id]) |
1026 offline_policy_map_[id] = new OfflinePolicy(); | 1026 offline_policy_map_[id] = new OfflinePolicy(); |
1027 load_flags |= offline_policy_map_[id]->GetAdditionalLoadFlags( | 1027 load_flags |= offline_policy_map_[id]->GetAdditionalLoadFlags( |
1028 load_flags, request_data.resource_type == ResourceType::MAIN_FRAME); | 1028 load_flags, request_data.resource_type == ResourceType::MAIN_FRAME); |
1029 | 1029 |
| 1030 // Sync loads should have maximum priority and should be the only |
| 1031 // requets that have the ignore limits flag set. |
| 1032 if (is_sync_load) { |
| 1033 DCHECK_EQ(request_data.priority, net::MAXIMUM_PRIORITY); |
| 1034 DCHECK_NE(load_flags & net::LOAD_IGNORE_LIMITS, 0); |
| 1035 } else { |
| 1036 DCHECK_EQ(load_flags & net::LOAD_IGNORE_LIMITS, 0); |
| 1037 } |
| 1038 |
1030 // Construct the request. | 1039 // Construct the request. |
1031 scoped_ptr<net::URLRequest> new_request; | 1040 scoped_ptr<net::URLRequest> new_request; |
1032 net::URLRequest* request; | 1041 net::URLRequest* request; |
1033 new_request = request_context->CreateRequest( | 1042 new_request = request_context->CreateRequest( |
1034 request_data.url, request_data.priority, NULL); | 1043 request_data.url, request_data.priority, NULL); |
1035 request = new_request.get(); | 1044 request = new_request.get(); |
1036 | 1045 |
1037 request->set_method(request_data.method); | 1046 request->set_method(request_data.method); |
1038 request->set_first_party_for_cookies(request_data.first_party_for_cookies); | 1047 request->set_first_party_for_cookies(request_data.first_party_for_cookies); |
1039 SetReferrerForRequest(request, referrer); | 1048 SetReferrerForRequest(request, referrer); |
1040 | 1049 |
1041 net::HttpRequestHeaders headers; | 1050 net::HttpRequestHeaders headers; |
1042 headers.AddHeadersFromString(request_data.headers); | 1051 headers.AddHeadersFromString(request_data.headers); |
1043 request->SetExtraRequestHeaders(headers); | 1052 request->SetExtraRequestHeaders(headers); |
1044 | 1053 |
1045 request->set_load_flags(load_flags); | 1054 request->SetLoadFlags(load_flags); |
1046 | 1055 |
1047 // Resolve elements from request_body and prepare upload data. | 1056 // Resolve elements from request_body and prepare upload data. |
1048 if (request_data.request_body.get()) { | 1057 if (request_data.request_body.get()) { |
1049 webkit_blob::BlobStorageContext* blob_context = NULL; | 1058 webkit_blob::BlobStorageContext* blob_context = NULL; |
1050 if (filter_->blob_storage_context()) | 1059 if (filter_->blob_storage_context()) |
1051 blob_context = filter_->blob_storage_context()->context(); | 1060 blob_context = filter_->blob_storage_context()->context(); |
1052 request->set_upload(UploadDataStreamBuilder::Build( | 1061 request->set_upload(UploadDataStreamBuilder::Build( |
1053 request_data.request_body.get(), | 1062 request_data.request_body.get(), |
1054 blob_context, | 1063 blob_context, |
1055 filter_->file_system_context(), | 1064 filter_->file_system_context(), |
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1278 return; | 1287 return; |
1279 } | 1288 } |
1280 | 1289 |
1281 scoped_ptr<net::URLRequest> request( | 1290 scoped_ptr<net::URLRequest> request( |
1282 request_context->CreateRequest(url, net::DEFAULT_PRIORITY, NULL)); | 1291 request_context->CreateRequest(url, net::DEFAULT_PRIORITY, NULL)); |
1283 request->set_method("GET"); | 1292 request->set_method("GET"); |
1284 SetReferrerForRequest(request.get(), referrer); | 1293 SetReferrerForRequest(request.get(), referrer); |
1285 | 1294 |
1286 // So far, for saving page, we need fetch content from cache, in the | 1295 // So far, for saving page, we need fetch content from cache, in the |
1287 // future, maybe we can use a configuration to configure this behavior. | 1296 // future, maybe we can use a configuration to configure this behavior. |
1288 request->set_load_flags(net::LOAD_PREFERRING_CACHE); | 1297 request->SetLoadFlags(net::LOAD_PREFERRING_CACHE); |
1289 | 1298 |
1290 // No need to get offline load flags for save files, but make sure | 1299 // No need to get offline load flags for save files, but make sure |
1291 // we have an OfflinePolicy to receive request completions. | 1300 // we have an OfflinePolicy to receive request completions. |
1292 GlobalRoutingID id(child_id, route_id); | 1301 GlobalRoutingID id(child_id, route_id); |
1293 if (!offline_policy_map_[id]) | 1302 if (!offline_policy_map_[id]) |
1294 offline_policy_map_[id] = new OfflinePolicy(); | 1303 offline_policy_map_[id] = new OfflinePolicy(); |
1295 | 1304 |
1296 // Since we're just saving some resources we need, disallow downloading. | 1305 // Since we're just saving some resources we need, disallow downloading. |
1297 ResourceRequestInfoImpl* extra_info = | 1306 ResourceRequestInfoImpl* extra_info = |
1298 CreateRequestInfo(child_id, route_id, false, context); | 1307 CreateRequestInfo(child_id, route_id, false, context); |
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1565 | 1574 |
1566 void ResourceDispatcherHostImpl::BeginRequestInternal( | 1575 void ResourceDispatcherHostImpl::BeginRequestInternal( |
1567 scoped_ptr<net::URLRequest> request, | 1576 scoped_ptr<net::URLRequest> request, |
1568 scoped_ptr<ResourceHandler> handler) { | 1577 scoped_ptr<ResourceHandler> handler) { |
1569 DCHECK(!request->is_pending()); | 1578 DCHECK(!request->is_pending()); |
1570 ResourceRequestInfoImpl* info = | 1579 ResourceRequestInfoImpl* info = |
1571 ResourceRequestInfoImpl::ForRequest(request.get()); | 1580 ResourceRequestInfoImpl::ForRequest(request.get()); |
1572 | 1581 |
1573 if ((TimeTicks::Now() - last_user_gesture_time_) < | 1582 if ((TimeTicks::Now() - last_user_gesture_time_) < |
1574 TimeDelta::FromMilliseconds(kUserGestureWindowMs)) { | 1583 TimeDelta::FromMilliseconds(kUserGestureWindowMs)) { |
1575 request->set_load_flags( | 1584 request->SetLoadFlags( |
1576 request->load_flags() | net::LOAD_MAYBE_USER_GESTURE); | 1585 request->load_flags() | net::LOAD_MAYBE_USER_GESTURE); |
1577 } | 1586 } |
1578 | 1587 |
1579 // Add the memory estimate that starting this request will consume. | 1588 // Add the memory estimate that starting this request will consume. |
1580 info->set_memory_cost(CalculateApproximateMemoryCost(request.get())); | 1589 info->set_memory_cost(CalculateApproximateMemoryCost(request.get())); |
1581 | 1590 |
1582 // If enqueing/starting this request will exceed our per-process memory | 1591 // If enqueing/starting this request will exceed our per-process memory |
1583 // bound, abort it right away. | 1592 // bound, abort it right away. |
1584 OustandingRequestsStats stats = IncrementOutstandingRequestsMemory(1, *info); | 1593 OustandingRequestsStats stats = IncrementOutstandingRequestsMemory(1, *info); |
1585 if (stats.memory_cost > max_outstanding_requests_cost_per_process_) { | 1594 if (stats.memory_cost > max_outstanding_requests_cost_per_process_) { |
(...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1915 if ((load_flags & net::LOAD_REPORT_RAW_HEADERS) | 1924 if ((load_flags & net::LOAD_REPORT_RAW_HEADERS) |
1916 && !policy->CanReadRawCookies(child_id)) { | 1925 && !policy->CanReadRawCookies(child_id)) { |
1917 VLOG(1) << "Denied unauthorized request for raw headers"; | 1926 VLOG(1) << "Denied unauthorized request for raw headers"; |
1918 load_flags &= ~net::LOAD_REPORT_RAW_HEADERS; | 1927 load_flags &= ~net::LOAD_REPORT_RAW_HEADERS; |
1919 } | 1928 } |
1920 | 1929 |
1921 return load_flags; | 1930 return load_flags; |
1922 } | 1931 } |
1923 | 1932 |
1924 } // namespace content | 1933 } // namespace content |
OLD | NEW |