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->SetLoadFlags(request->load_flags() | extra_load_flags); | 476 request->set_load_flags(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 | |
1039 // Construct the request. | 1030 // Construct the request. |
1040 scoped_ptr<net::URLRequest> new_request; | 1031 scoped_ptr<net::URLRequest> new_request; |
1041 net::URLRequest* request; | 1032 net::URLRequest* request; |
1042 new_request = request_context->CreateRequest( | 1033 new_request = request_context->CreateRequest( |
1043 request_data.url, request_data.priority, NULL); | 1034 request_data.url, request_data.priority, NULL); |
1044 request = new_request.get(); | 1035 request = new_request.get(); |
1045 | 1036 |
1046 request->set_method(request_data.method); | 1037 request->set_method(request_data.method); |
1047 request->set_first_party_for_cookies(request_data.first_party_for_cookies); | 1038 request->set_first_party_for_cookies(request_data.first_party_for_cookies); |
1048 SetReferrerForRequest(request, referrer); | 1039 SetReferrerForRequest(request, referrer); |
1049 | 1040 |
1050 net::HttpRequestHeaders headers; | 1041 net::HttpRequestHeaders headers; |
1051 headers.AddHeadersFromString(request_data.headers); | 1042 headers.AddHeadersFromString(request_data.headers); |
1052 request->SetExtraRequestHeaders(headers); | 1043 request->SetExtraRequestHeaders(headers); |
1053 | 1044 |
1054 request->SetLoadFlags(load_flags); | 1045 request->set_load_flags(load_flags); |
1055 | 1046 |
1056 // Resolve elements from request_body and prepare upload data. | 1047 // Resolve elements from request_body and prepare upload data. |
1057 if (request_data.request_body.get()) { | 1048 if (request_data.request_body.get()) { |
1058 webkit_blob::BlobStorageContext* blob_context = NULL; | 1049 webkit_blob::BlobStorageContext* blob_context = NULL; |
1059 if (filter_->blob_storage_context()) | 1050 if (filter_->blob_storage_context()) |
1060 blob_context = filter_->blob_storage_context()->context(); | 1051 blob_context = filter_->blob_storage_context()->context(); |
1061 request->set_upload(UploadDataStreamBuilder::Build( | 1052 request->set_upload(UploadDataStreamBuilder::Build( |
1062 request_data.request_body.get(), | 1053 request_data.request_body.get(), |
1063 blob_context, | 1054 blob_context, |
1064 filter_->file_system_context(), | 1055 filter_->file_system_context(), |
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1287 return; | 1278 return; |
1288 } | 1279 } |
1289 | 1280 |
1290 scoped_ptr<net::URLRequest> request( | 1281 scoped_ptr<net::URLRequest> request( |
1291 request_context->CreateRequest(url, net::DEFAULT_PRIORITY, NULL)); | 1282 request_context->CreateRequest(url, net::DEFAULT_PRIORITY, NULL)); |
1292 request->set_method("GET"); | 1283 request->set_method("GET"); |
1293 SetReferrerForRequest(request.get(), referrer); | 1284 SetReferrerForRequest(request.get(), referrer); |
1294 | 1285 |
1295 // So far, for saving page, we need fetch content from cache, in the | 1286 // So far, for saving page, we need fetch content from cache, in the |
1296 // future, maybe we can use a configuration to configure this behavior. | 1287 // future, maybe we can use a configuration to configure this behavior. |
1297 request->SetLoadFlags(net::LOAD_PREFERRING_CACHE); | 1288 request->set_load_flags(net::LOAD_PREFERRING_CACHE); |
1298 | 1289 |
1299 // No need to get offline load flags for save files, but make sure | 1290 // No need to get offline load flags for save files, but make sure |
1300 // we have an OfflinePolicy to receive request completions. | 1291 // we have an OfflinePolicy to receive request completions. |
1301 GlobalRoutingID id(child_id, route_id); | 1292 GlobalRoutingID id(child_id, route_id); |
1302 if (!offline_policy_map_[id]) | 1293 if (!offline_policy_map_[id]) |
1303 offline_policy_map_[id] = new OfflinePolicy(); | 1294 offline_policy_map_[id] = new OfflinePolicy(); |
1304 | 1295 |
1305 // Since we're just saving some resources we need, disallow downloading. | 1296 // Since we're just saving some resources we need, disallow downloading. |
1306 ResourceRequestInfoImpl* extra_info = | 1297 ResourceRequestInfoImpl* extra_info = |
1307 CreateRequestInfo(child_id, route_id, false, context); | 1298 CreateRequestInfo(child_id, route_id, false, context); |
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1574 | 1565 |
1575 void ResourceDispatcherHostImpl::BeginRequestInternal( | 1566 void ResourceDispatcherHostImpl::BeginRequestInternal( |
1576 scoped_ptr<net::URLRequest> request, | 1567 scoped_ptr<net::URLRequest> request, |
1577 scoped_ptr<ResourceHandler> handler) { | 1568 scoped_ptr<ResourceHandler> handler) { |
1578 DCHECK(!request->is_pending()); | 1569 DCHECK(!request->is_pending()); |
1579 ResourceRequestInfoImpl* info = | 1570 ResourceRequestInfoImpl* info = |
1580 ResourceRequestInfoImpl::ForRequest(request.get()); | 1571 ResourceRequestInfoImpl::ForRequest(request.get()); |
1581 | 1572 |
1582 if ((TimeTicks::Now() - last_user_gesture_time_) < | 1573 if ((TimeTicks::Now() - last_user_gesture_time_) < |
1583 TimeDelta::FromMilliseconds(kUserGestureWindowMs)) { | 1574 TimeDelta::FromMilliseconds(kUserGestureWindowMs)) { |
1584 request->SetLoadFlags( | 1575 request->set_load_flags( |
1585 request->load_flags() | net::LOAD_MAYBE_USER_GESTURE); | 1576 request->load_flags() | net::LOAD_MAYBE_USER_GESTURE); |
1586 } | 1577 } |
1587 | 1578 |
1588 // Add the memory estimate that starting this request will consume. | 1579 // Add the memory estimate that starting this request will consume. |
1589 info->set_memory_cost(CalculateApproximateMemoryCost(request.get())); | 1580 info->set_memory_cost(CalculateApproximateMemoryCost(request.get())); |
1590 | 1581 |
1591 // If enqueing/starting this request will exceed our per-process memory | 1582 // If enqueing/starting this request will exceed our per-process memory |
1592 // bound, abort it right away. | 1583 // bound, abort it right away. |
1593 OustandingRequestsStats stats = IncrementOutstandingRequestsMemory(1, *info); | 1584 OustandingRequestsStats stats = IncrementOutstandingRequestsMemory(1, *info); |
1594 if (stats.memory_cost > max_outstanding_requests_cost_per_process_) { | 1585 if (stats.memory_cost > max_outstanding_requests_cost_per_process_) { |
(...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1924 if ((load_flags & net::LOAD_REPORT_RAW_HEADERS) | 1915 if ((load_flags & net::LOAD_REPORT_RAW_HEADERS) |
1925 && !policy->CanReadRawCookies(child_id)) { | 1916 && !policy->CanReadRawCookies(child_id)) { |
1926 VLOG(1) << "Denied unauthorized request for raw headers"; | 1917 VLOG(1) << "Denied unauthorized request for raw headers"; |
1927 load_flags &= ~net::LOAD_REPORT_RAW_HEADERS; | 1918 load_flags &= ~net::LOAD_REPORT_RAW_HEADERS; |
1928 } | 1919 } |
1929 | 1920 |
1930 return load_flags; | 1921 return load_flags; |
1931 } | 1922 } |
1932 | 1923 |
1933 } // namespace content | 1924 } // namespace content |
OLD | NEW |