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> |
11 #include <vector> | 11 #include <vector> |
12 | 12 |
13 #include "base/bind.h" | 13 #include "base/bind.h" |
14 #include "base/bind_helpers.h" | 14 #include "base/bind_helpers.h" |
15 #include "base/command_line.h" | 15 #include "base/command_line.h" |
16 #include "base/compiler_specific.h" | 16 #include "base/compiler_specific.h" |
17 #include "base/debug/alias.h" | 17 #include "base/debug/alias.h" |
18 #include "base/logging.h" | 18 #include "base/logging.h" |
19 #include "base/memory/scoped_ptr.h" | 19 #include "base/memory/scoped_ptr.h" |
20 #include "base/memory/shared_memory.h" | 20 #include "base/memory/shared_memory.h" |
21 #include "base/message_loop/message_loop.h" | 21 #include "base/message_loop/message_loop.h" |
22 #include "base/metrics/field_trial.h" | |
22 #include "base/metrics/histogram_macros.h" | 23 #include "base/metrics/histogram_macros.h" |
23 #include "base/metrics/sparse_histogram.h" | 24 #include "base/metrics/sparse_histogram.h" |
24 #include "base/profiler/scoped_tracker.h" | 25 #include "base/profiler/scoped_tracker.h" |
25 #include "base/stl_util.h" | 26 #include "base/stl_util.h" |
26 #include "base/third_party/dynamic_annotations/dynamic_annotations.h" | 27 #include "base/third_party/dynamic_annotations/dynamic_annotations.h" |
27 #include "base/time/time.h" | 28 #include "base/time/time.h" |
28 #include "content/browser/appcache/appcache_interceptor.h" | 29 #include "content/browser/appcache/appcache_interceptor.h" |
29 #include "content/browser/appcache/chrome_appcache_service.h" | 30 #include "content/browser/appcache/chrome_appcache_service.h" |
30 #include "content/browser/bad_message.h" | 31 #include "content/browser/bad_message.h" |
31 #include "content/browser/cert_store_impl.h" | 32 #include "content/browser/cert_store_impl.h" |
(...skipping 434 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
466 &last_user_gesture_time_, | 467 &last_user_gesture_time_, |
467 "We don't care about the precise value, see http://crbug.com/92889"); | 468 "We don't care about the precise value, see http://crbug.com/92889"); |
468 | 469 |
469 BrowserThread::PostTask(BrowserThread::IO, | 470 BrowserThread::PostTask(BrowserThread::IO, |
470 FROM_HERE, | 471 FROM_HERE, |
471 base::Bind(&ResourceDispatcherHostImpl::OnInit, | 472 base::Bind(&ResourceDispatcherHostImpl::OnInit, |
472 base::Unretained(this))); | 473 base::Unretained(this))); |
473 | 474 |
474 update_load_states_timer_.reset( | 475 update_load_states_timer_.reset( |
475 new base::RepeatingTimer<ResourceDispatcherHostImpl>()); | 476 new base::RepeatingTimer<ResourceDispatcherHostImpl>()); |
477 | |
478 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | |
479 if (base::FieldTrialList::FindFullName("StaleWhileRevalidate") == "Enabled" || | |
480 command_line->HasSwitch(switches::kEnableStaleWhileRevalidate)) { | |
481 async_revalidation_manager_.reset(new AsyncRevalidationManager); | |
482 } | |
476 } | 483 } |
477 | 484 |
478 ResourceDispatcherHostImpl::~ResourceDispatcherHostImpl() { | 485 ResourceDispatcherHostImpl::~ResourceDispatcherHostImpl() { |
479 DCHECK(outstanding_requests_stats_map_.empty()); | 486 DCHECK(outstanding_requests_stats_map_.empty()); |
487 // It's not safe to destroy this object while AsyncRevalidationDriver objects | |
488 // have callbacks referencing it. | |
489 async_revalidation_manager_.reset(); | |
480 DCHECK(g_resource_dispatcher_host); | 490 DCHECK(g_resource_dispatcher_host); |
481 g_resource_dispatcher_host = NULL; | 491 g_resource_dispatcher_host = NULL; |
482 } | 492 } |
483 | 493 |
484 // static | 494 // static |
485 ResourceDispatcherHostImpl* ResourceDispatcherHostImpl::Get() { | 495 ResourceDispatcherHostImpl* ResourceDispatcherHostImpl::Get() { |
486 return g_resource_dispatcher_host; | 496 return g_resource_dispatcher_host; |
487 } | 497 } |
488 | 498 |
489 void ResourceDispatcherHostImpl::SetDelegate( | 499 void ResourceDispatcherHostImpl::SetDelegate( |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
571 (*i)->GetRequestInfo()->is_stream() || | 581 (*i)->GetRequestInfo()->is_stream() || |
572 ((*i)->GetRequestInfo()->detachable_handler() && | 582 ((*i)->GetRequestInfo()->detachable_handler() && |
573 (*i)->GetRequestInfo()->detachable_handler()->is_detached()) || | 583 (*i)->GetRequestInfo()->detachable_handler()->is_detached()) || |
574 (*i)->GetRequestInfo()->GetProcessType() == PROCESS_TYPE_BROWSER || | 584 (*i)->GetRequestInfo()->GetProcessType() == PROCESS_TYPE_BROWSER || |
575 (*i)->is_transferring()); | 585 (*i)->is_transferring()); |
576 } | 586 } |
577 #endif | 587 #endif |
578 | 588 |
579 loaders_to_cancel.clear(); | 589 loaders_to_cancel.clear(); |
580 | 590 |
591 if (async_revalidation_manager_) { | |
592 // Cancelling async revalidations should not result in the creation of new | |
593 // requests, but do it before the checks just to be on the safe side. | |
594 async_revalidation_manager_->CancelAsyncRevalidationsForResourceContext( | |
595 context); | |
596 } | |
597 | |
581 // Validate that no more requests for this context were added. | 598 // Validate that no more requests for this context were added. |
582 for (LoaderMap::const_iterator i = pending_loaders_.begin(); | 599 for (LoaderMap::const_iterator i = pending_loaders_.begin(); |
583 i != pending_loaders_.end(); ++i) { | 600 i != pending_loaders_.end(); ++i) { |
584 // http://crbug.com/90971 | 601 // http://crbug.com/90971 |
585 CHECK_NE(i->second->GetRequestInfo()->GetContext(), context); | 602 CHECK_NE(i->second->GetRequestInfo()->GetContext(), context); |
586 } | 603 } |
587 | 604 |
588 for (BlockedLoadersMap::const_iterator i = blocked_loaders_map_.begin(); | 605 for (BlockedLoadersMap::const_iterator i = blocked_loaders_map_.begin(); |
589 i != blocked_loaders_map_.end(); ++i) { | 606 i != blocked_loaders_map_.end(); ++i) { |
590 BlockedLoadersList* loaders = i->second; | 607 BlockedLoadersList* loaders = i->second; |
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
817 } | 834 } |
818 | 835 |
819 void ResourceDispatcherHostImpl::DidReceiveRedirect(ResourceLoader* loader, | 836 void ResourceDispatcherHostImpl::DidReceiveRedirect(ResourceLoader* loader, |
820 const GURL& new_url) { | 837 const GURL& new_url) { |
821 ResourceRequestInfoImpl* info = loader->GetRequestInfo(); | 838 ResourceRequestInfoImpl* info = loader->GetRequestInfo(); |
822 | 839 |
823 int render_process_id, render_frame_host; | 840 int render_process_id, render_frame_host; |
824 if (!info->GetAssociatedRenderFrame(&render_process_id, &render_frame_host)) | 841 if (!info->GetAssociatedRenderFrame(&render_process_id, &render_frame_host)) |
825 return; | 842 return; |
826 | 843 |
844 // Remove the LOAD_SUPPORT_ASYNC_REVALIDATION flag if it is present. | |
Bence
2015/11/17 13:12:23
Please explain briefly why you do this for redirec
Adam Rice
2015/11/17 17:45:53
Done.
| |
845 net::URLRequest* request = loader->request(); | |
846 if (request->load_flags() & net::LOAD_SUPPORT_ASYNC_REVALIDATION) { | |
847 int new_load_flags = request->load_flags() & | |
848 ~net::LOAD_SUPPORT_ASYNC_REVALIDATION; | |
849 request->SetLoadFlags(new_load_flags); | |
850 } | |
851 | |
827 // Notify the observers on the UI thread. | 852 // Notify the observers on the UI thread. |
828 scoped_ptr<ResourceRedirectDetails> detail(new ResourceRedirectDetails( | 853 scoped_ptr<ResourceRedirectDetails> detail(new ResourceRedirectDetails( |
829 loader->request(), | 854 loader->request(), |
830 GetCertID(loader->request(), info->GetChildID()), | 855 GetCertID(loader->request(), info->GetChildID()), |
831 new_url)); | 856 new_url)); |
832 BrowserThread::PostTask( | 857 BrowserThread::PostTask( |
833 BrowserThread::UI, FROM_HERE, | 858 BrowserThread::UI, FROM_HERE, |
834 base::Bind( | 859 base::Bind( |
835 &NotifyRedirectOnUI, | 860 &NotifyRedirectOnUI, |
836 render_process_id, render_frame_host, base::Passed(&detail))); | 861 render_process_id, render_frame_host, base::Passed(&detail))); |
837 } | 862 } |
838 | 863 |
839 void ResourceDispatcherHostImpl::DidReceiveResponse(ResourceLoader* loader) { | 864 void ResourceDispatcherHostImpl::DidReceiveResponse(ResourceLoader* loader) { |
840 ResourceRequestInfoImpl* info = loader->GetRequestInfo(); | 865 ResourceRequestInfoImpl* info = loader->GetRequestInfo(); |
841 net::URLRequest* request = loader->request(); | 866 net::URLRequest* request = loader->request(); |
842 if (request->was_fetched_via_proxy() && | 867 if (request->was_fetched_via_proxy() && |
843 request->was_fetched_via_spdy() && | 868 request->was_fetched_via_spdy() && |
844 request->url().SchemeIs(url::kHttpScheme)) { | 869 request->url().SchemeIs(url::kHttpScheme)) { |
845 scheduler_->OnReceivedSpdyProxiedHttpResponse( | 870 scheduler_->OnReceivedSpdyProxiedHttpResponse( |
846 info->GetChildID(), info->GetRouteID()); | 871 info->GetChildID(), info->GetRouteID()); |
847 } | 872 } |
848 | 873 |
874 if (request->response_info().async_revalidation_required && !is_shutdown_) { | |
875 DCHECK(async_revalidation_manager_); | |
876 async_revalidation_manager_->BeginAsyncRevalidation(request, | |
877 scheduler_.get()); | |
878 } | |
879 | |
849 int render_process_id, render_frame_host; | 880 int render_process_id, render_frame_host; |
850 if (!info->GetAssociatedRenderFrame(&render_process_id, &render_frame_host)) | 881 if (!info->GetAssociatedRenderFrame(&render_process_id, &render_frame_host)) |
851 return; | 882 return; |
852 | 883 |
853 // Notify the observers on the UI thread. | 884 // Notify the observers on the UI thread. |
854 scoped_ptr<ResourceRequestDetails> detail(new ResourceRequestDetails( | 885 scoped_ptr<ResourceRequestDetails> detail(new ResourceRequestDetails( |
855 request, GetCertID(request, info->GetChildID()))); | 886 request, GetCertID(request, info->GetChildID()))); |
856 BrowserThread::PostTask( | 887 BrowserThread::PostTask( |
857 BrowserThread::UI, FROM_HERE, | 888 BrowserThread::UI, FROM_HERE, |
858 base::Bind( | 889 base::Bind( |
(...skipping 413 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1272 // Only block image loads, as the attack applies largely to the "src" | 1303 // Only block image loads, as the attack applies largely to the "src" |
1273 // property of the <img> tag. It is common for web properties to allow | 1304 // property of the <img> tag. It is common for web properties to allow |
1274 // untrusted values for <img src>; this is considered a fair thing for an | 1305 // untrusted values for <img src>; this is considered a fair thing for an |
1275 // HTML sanitizer to do. Conversely, any HTML sanitizer that didn't | 1306 // HTML sanitizer to do. Conversely, any HTML sanitizer that didn't |
1276 // filter sources for <script>, <link>, <embed>, <object>, <iframe> tags | 1307 // filter sources for <script>, <link>, <embed>, <object>, <iframe> tags |
1277 // would be considered vulnerable in and of itself. | 1308 // would be considered vulnerable in and of itself. |
1278 do_not_prompt_for_login = true; | 1309 do_not_prompt_for_login = true; |
1279 load_flags |= net::LOAD_DO_NOT_USE_EMBEDDED_IDENTITY; | 1310 load_flags |= net::LOAD_DO_NOT_USE_EMBEDDED_IDENTITY; |
1280 } | 1311 } |
1281 | 1312 |
1313 // Check if request is eligible for async revalidation. | |
Bence
2015/11/17 13:12:23
Optional: this comment seems to be redundant with
Adam Rice
2015/11/17 17:45:53
Done.
| |
1314 bool support_async_revalidation = | |
1315 (!is_sync_load && async_revalidation_manager_ && | |
1316 AsyncRevalidationManager::QualifiesForAsyncRevalidation(request_data)); | |
1317 | |
1318 if (support_async_revalidation) | |
1319 load_flags |= net::LOAD_SUPPORT_ASYNC_REVALIDATION; | |
1320 | |
1282 // Sync loads should have maximum priority and should be the only | 1321 // Sync loads should have maximum priority and should be the only |
1283 // requets that have the ignore limits flag set. | 1322 // requets that have the ignore limits flag set. |
1284 if (is_sync_load) { | 1323 if (is_sync_load) { |
1285 DCHECK_EQ(request_data.priority, net::MAXIMUM_PRIORITY); | 1324 DCHECK_EQ(request_data.priority, net::MAXIMUM_PRIORITY); |
1286 DCHECK_NE(load_flags & net::LOAD_IGNORE_LIMITS, 0); | 1325 DCHECK_NE(load_flags & net::LOAD_IGNORE_LIMITS, 0); |
1287 } else { | 1326 } else { |
1288 DCHECK_EQ(load_flags & net::LOAD_IGNORE_LIMITS, 0); | 1327 DCHECK_EQ(load_flags & net::LOAD_IGNORE_LIMITS, 0); |
1289 } | 1328 } |
1290 new_request->SetLoadFlags(load_flags); | 1329 new_request->SetLoadFlags(load_flags); |
1291 | 1330 |
(...skipping 13 matching lines...) Expand all Loading... | |
1305 false, // is download | 1344 false, // is download |
1306 false, // is stream | 1345 false, // is stream |
1307 allow_download, | 1346 allow_download, |
1308 request_data.has_user_gesture, | 1347 request_data.has_user_gesture, |
1309 request_data.enable_load_timing, | 1348 request_data.enable_load_timing, |
1310 request_data.enable_upload_progress, | 1349 request_data.enable_upload_progress, |
1311 do_not_prompt_for_login, | 1350 do_not_prompt_for_login, |
1312 request_data.referrer_policy, | 1351 request_data.referrer_policy, |
1313 request_data.visiblity_state, | 1352 request_data.visiblity_state, |
1314 resource_context, filter_->GetWeakPtr(), | 1353 resource_context, filter_->GetWeakPtr(), |
1315 !is_sync_load); | 1354 !is_sync_load, |
1355 support_async_revalidation ? request_data.headers : std::string()); | |
1316 // Request takes ownership. | 1356 // Request takes ownership. |
1317 extra_info->AssociateWithRequest(new_request.get()); | 1357 extra_info->AssociateWithRequest(new_request.get()); |
1318 | 1358 |
1319 if (new_request->url().SchemeIs(url::kBlobScheme)) { | 1359 if (new_request->url().SchemeIs(url::kBlobScheme)) { |
1320 // Hang on to a reference to ensure the blob is not released prior | 1360 // Hang on to a reference to ensure the blob is not released prior |
1321 // to the job being started. | 1361 // to the job being started. |
1322 storage::BlobProtocolHandler::SetRequestedBlobDataHandle( | 1362 storage::BlobProtocolHandler::SetRequestedBlobDataHandle( |
1323 new_request.get(), | 1363 new_request.get(), |
1324 filter_->blob_storage_context()->context()->GetBlobDataFromPublicURL( | 1364 filter_->blob_storage_context()->context()->GetBlobDataFromPublicURL( |
1325 new_request->url())); | 1365 new_request->url())); |
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1576 false, // is_stream | 1616 false, // is_stream |
1577 download, // allow_download | 1617 download, // allow_download |
1578 false, // has_user_gesture | 1618 false, // has_user_gesture |
1579 false, // enable_load_timing | 1619 false, // enable_load_timing |
1580 false, // enable_upload_progress | 1620 false, // enable_upload_progress |
1581 false, // do_not_prompt_for_login | 1621 false, // do_not_prompt_for_login |
1582 blink::WebReferrerPolicyDefault, | 1622 blink::WebReferrerPolicyDefault, |
1583 blink::WebPageVisibilityStateVisible, | 1623 blink::WebPageVisibilityStateVisible, |
1584 context, | 1624 context, |
1585 base::WeakPtr<ResourceMessageFilter>(), // filter | 1625 base::WeakPtr<ResourceMessageFilter>(), // filter |
1586 true); // is_async | 1626 true, // is_async |
1627 std::string()); // original_headers | |
1587 } | 1628 } |
1588 | 1629 |
1589 void ResourceDispatcherHostImpl::OnRenderViewHostCreated(int child_id, | 1630 void ResourceDispatcherHostImpl::OnRenderViewHostCreated(int child_id, |
1590 int route_id, | 1631 int route_id, |
1591 bool is_visible, | 1632 bool is_visible, |
1592 bool is_audible) { | 1633 bool is_audible) { |
1593 scheduler_->OnClientCreated(child_id, route_id, is_visible, is_audible); | 1634 scheduler_->OnClientCreated(child_id, route_id, is_visible, is_audible); |
1594 } | 1635 } |
1595 | 1636 |
1596 void ResourceDispatcherHostImpl::OnRenderViewHostDeleted( | 1637 void ResourceDispatcherHostImpl::OnRenderViewHostDeleted( |
(...skipping 422 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2019 true, // enable_load_timing | 2060 true, // enable_load_timing |
2020 false, // enable_upload_progress | 2061 false, // enable_upload_progress |
2021 false, // do_not_prompt_for_login | 2062 false, // do_not_prompt_for_login |
2022 info.common_params.referrer.policy, | 2063 info.common_params.referrer.policy, |
2023 // TODO(davidben): This is only used for prerenders. Replace | 2064 // TODO(davidben): This is only used for prerenders. Replace |
2024 // is_showing with something for that. Or maybe it just comes from the | 2065 // is_showing with something for that. Or maybe it just comes from the |
2025 // same mechanism as the cookie one. | 2066 // same mechanism as the cookie one. |
2026 blink::WebPageVisibilityStateVisible, | 2067 blink::WebPageVisibilityStateVisible, |
2027 resource_context, | 2068 resource_context, |
2028 base::WeakPtr<ResourceMessageFilter>(), // filter | 2069 base::WeakPtr<ResourceMessageFilter>(), // filter |
2029 true); | 2070 true, // is_async |
2071 std::string()); // original_headers | |
2030 // Request takes ownership. | 2072 // Request takes ownership. |
2031 extra_info->AssociateWithRequest(new_request.get()); | 2073 extra_info->AssociateWithRequest(new_request.get()); |
2032 | 2074 |
2033 if (new_request->url().SchemeIs(url::kBlobScheme)) { | 2075 if (new_request->url().SchemeIs(url::kBlobScheme)) { |
2034 // Hang on to a reference to ensure the blob is not released prior | 2076 // Hang on to a reference to ensure the blob is not released prior |
2035 // to the job being started. | 2077 // to the job being started. |
2036 ChromeBlobStorageContext* blob_context = | 2078 ChromeBlobStorageContext* blob_context = |
2037 GetChromeBlobStorageContextForResourceContext(resource_context); | 2079 GetChromeBlobStorageContextForResourceContext(resource_context); |
2038 storage::BlobProtocolHandler::SetRequestedBlobDataHandle( | 2080 storage::BlobProtocolHandler::SetRequestedBlobDataHandle( |
2039 new_request.get(), | 2081 new_request.get(), |
(...skipping 13 matching lines...) Expand all Loading... | |
2053 handler = AddStandardHandlers(new_request.get(), resource_type, | 2095 handler = AddStandardHandlers(new_request.get(), resource_type, |
2054 resource_context, | 2096 resource_context, |
2055 nullptr, // appcache_service | 2097 nullptr, // appcache_service |
2056 -1, // child_id | 2098 -1, // child_id |
2057 -1, // route_id | 2099 -1, // route_id |
2058 handler.Pass()); | 2100 handler.Pass()); |
2059 | 2101 |
2060 BeginRequestInternal(new_request.Pass(), handler.Pass()); | 2102 BeginRequestInternal(new_request.Pass(), handler.Pass()); |
2061 } | 2103 } |
2062 | 2104 |
2105 void ResourceDispatcherHostImpl::EnableStaleWhileRevalidateForTesting() { | |
2106 // Do nothing if it is enabled already. | |
2107 if (!async_revalidation_manager_) | |
2108 async_revalidation_manager_.reset(new AsyncRevalidationManager); | |
2109 } | |
2110 | |
2063 // static | 2111 // static |
2064 int ResourceDispatcherHostImpl::CalculateApproximateMemoryCost( | 2112 int ResourceDispatcherHostImpl::CalculateApproximateMemoryCost( |
2065 net::URLRequest* request) { | 2113 net::URLRequest* request) { |
2066 // The following fields should be a minor size contribution (experimentally | 2114 // The following fields should be a minor size contribution (experimentally |
2067 // on the order of 100). However since they are variable length, it could | 2115 // on the order of 100). However since they are variable length, it could |
2068 // in theory be a sizeable contribution. | 2116 // in theory be a sizeable contribution. |
2069 int strings_cost = request->extra_request_headers().ToString().size() + | 2117 int strings_cost = request->extra_request_headers().ToString().size() + |
2070 request->original_url().spec().size() + | 2118 request->original_url().spec().size() + |
2071 request->referrer().size() + | 2119 request->referrer().size() + |
2072 request->method().size(); | 2120 request->method().size(); |
(...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2386 if ((load_flags & net::LOAD_REPORT_RAW_HEADERS) | 2434 if ((load_flags & net::LOAD_REPORT_RAW_HEADERS) |
2387 && !policy->CanReadRawCookies(child_id)) { | 2435 && !policy->CanReadRawCookies(child_id)) { |
2388 VLOG(1) << "Denied unauthorized request for raw headers"; | 2436 VLOG(1) << "Denied unauthorized request for raw headers"; |
2389 load_flags &= ~net::LOAD_REPORT_RAW_HEADERS; | 2437 load_flags &= ~net::LOAD_REPORT_RAW_HEADERS; |
2390 } | 2438 } |
2391 | 2439 |
2392 return load_flags; | 2440 return load_flags; |
2393 } | 2441 } |
2394 | 2442 |
2395 } // namespace content | 2443 } // namespace content |
OLD | NEW |