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. | |
845 // It is difficult to create a URLRequest with the correct flags and headers | |
846 // for redirect legs other than the first one. Since stale-while-revalidate in | |
847 // combination with redirects isn't needed for experimental use, punt on it | |
848 // for now. | |
849 // TODO(ricea): Fix this before launching the feature. | |
850 net::URLRequest* request = loader->request(); | |
851 if (request->load_flags() & net::LOAD_SUPPORT_ASYNC_REVALIDATION) { | |
852 int new_load_flags = | |
853 request->load_flags() & ~net::LOAD_SUPPORT_ASYNC_REVALIDATION; | |
854 request->SetLoadFlags(new_load_flags); | |
855 } | |
856 | |
827 // Notify the observers on the UI thread. | 857 // Notify the observers on the UI thread. |
828 scoped_ptr<ResourceRedirectDetails> detail(new ResourceRedirectDetails( | 858 scoped_ptr<ResourceRedirectDetails> detail(new ResourceRedirectDetails( |
829 loader->request(), | 859 loader->request(), |
830 GetCertID(loader->request(), info->GetChildID()), | 860 GetCertID(loader->request(), info->GetChildID()), |
831 new_url)); | 861 new_url)); |
832 BrowserThread::PostTask( | 862 BrowserThread::PostTask( |
833 BrowserThread::UI, FROM_HERE, | 863 BrowserThread::UI, FROM_HERE, |
834 base::Bind( | 864 base::Bind( |
835 &NotifyRedirectOnUI, | 865 &NotifyRedirectOnUI, |
836 render_process_id, render_frame_host, base::Passed(&detail))); | 866 render_process_id, render_frame_host, base::Passed(&detail))); |
837 } | 867 } |
838 | 868 |
839 void ResourceDispatcherHostImpl::DidReceiveResponse(ResourceLoader* loader) { | 869 void ResourceDispatcherHostImpl::DidReceiveResponse(ResourceLoader* loader) { |
840 ResourceRequestInfoImpl* info = loader->GetRequestInfo(); | 870 ResourceRequestInfoImpl* info = loader->GetRequestInfo(); |
841 net::URLRequest* request = loader->request(); | 871 net::URLRequest* request = loader->request(); |
842 if (request->was_fetched_via_proxy() && | 872 if (request->was_fetched_via_proxy() && |
843 request->was_fetched_via_spdy() && | 873 request->was_fetched_via_spdy() && |
844 request->url().SchemeIs(url::kHttpScheme)) { | 874 request->url().SchemeIs(url::kHttpScheme)) { |
845 scheduler_->OnReceivedSpdyProxiedHttpResponse( | 875 scheduler_->OnReceivedSpdyProxiedHttpResponse( |
846 info->GetChildID(), info->GetRouteID()); | 876 info->GetChildID(), info->GetRouteID()); |
847 } | 877 } |
848 | 878 |
879 if (request->response_info().async_revalidation_required && !is_shutdown_) { | |
880 DCHECK(async_revalidation_manager_); | |
881 async_revalidation_manager_->BeginAsyncRevalidation(request, | |
882 scheduler_.get()); | |
883 } | |
884 | |
849 int render_process_id, render_frame_host; | 885 int render_process_id, render_frame_host; |
850 if (!info->GetAssociatedRenderFrame(&render_process_id, &render_frame_host)) | 886 if (!info->GetAssociatedRenderFrame(&render_process_id, &render_frame_host)) |
851 return; | 887 return; |
852 | 888 |
853 // Notify the observers on the UI thread. | 889 // Notify the observers on the UI thread. |
854 scoped_ptr<ResourceRequestDetails> detail(new ResourceRequestDetails( | 890 scoped_ptr<ResourceRequestDetails> detail(new ResourceRequestDetails( |
855 request, GetCertID(request, info->GetChildID()))); | 891 request, GetCertID(request, info->GetChildID()))); |
856 BrowserThread::PostTask( | 892 BrowserThread::PostTask( |
857 BrowserThread::UI, FROM_HERE, | 893 BrowserThread::UI, FROM_HERE, |
858 base::Bind( | 894 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" | 1308 // 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 | 1309 // 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 | 1310 // 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 | 1311 // HTML sanitizer to do. Conversely, any HTML sanitizer that didn't |
1276 // filter sources for <script>, <link>, <embed>, <object>, <iframe> tags | 1312 // filter sources for <script>, <link>, <embed>, <object>, <iframe> tags |
1277 // would be considered vulnerable in and of itself. | 1313 // would be considered vulnerable in and of itself. |
1278 do_not_prompt_for_login = true; | 1314 do_not_prompt_for_login = true; |
1279 load_flags |= net::LOAD_DO_NOT_USE_EMBEDDED_IDENTITY; | 1315 load_flags |= net::LOAD_DO_NOT_USE_EMBEDDED_IDENTITY; |
1280 } | 1316 } |
1281 | 1317 |
1318 bool support_async_revalidation = | |
1319 (!is_sync_load && async_revalidation_manager_ && | |
1320 AsyncRevalidationManager::QualifiesForAsyncRevalidation(request_data)); | |
1321 | |
1322 if (support_async_revalidation) | |
1323 load_flags |= net::LOAD_SUPPORT_ASYNC_REVALIDATION; | |
1324 | |
1282 // Sync loads should have maximum priority and should be the only | 1325 // Sync loads should have maximum priority and should be the only |
1283 // requets that have the ignore limits flag set. | 1326 // requets that have the ignore limits flag set. |
1284 if (is_sync_load) { | 1327 if (is_sync_load) { |
1285 DCHECK_EQ(request_data.priority, net::MAXIMUM_PRIORITY); | 1328 DCHECK_EQ(request_data.priority, net::MAXIMUM_PRIORITY); |
1286 DCHECK_NE(load_flags & net::LOAD_IGNORE_LIMITS, 0); | 1329 DCHECK_NE(load_flags & net::LOAD_IGNORE_LIMITS, 0); |
1287 } else { | 1330 } else { |
1288 DCHECK_EQ(load_flags & net::LOAD_IGNORE_LIMITS, 0); | 1331 DCHECK_EQ(load_flags & net::LOAD_IGNORE_LIMITS, 0); |
1289 } | 1332 } |
1290 new_request->SetLoadFlags(load_flags); | 1333 new_request->SetLoadFlags(load_flags); |
1291 | 1334 |
(...skipping 13 matching lines...) Expand all Loading... | |
1305 false, // is download | 1348 false, // is download |
1306 false, // is stream | 1349 false, // is stream |
1307 allow_download, | 1350 allow_download, |
1308 request_data.has_user_gesture, | 1351 request_data.has_user_gesture, |
1309 request_data.enable_load_timing, | 1352 request_data.enable_load_timing, |
1310 request_data.enable_upload_progress, | 1353 request_data.enable_upload_progress, |
1311 do_not_prompt_for_login, | 1354 do_not_prompt_for_login, |
1312 request_data.referrer_policy, | 1355 request_data.referrer_policy, |
1313 request_data.visiblity_state, | 1356 request_data.visiblity_state, |
1314 resource_context, filter_->GetWeakPtr(), | 1357 resource_context, filter_->GetWeakPtr(), |
1315 !is_sync_load); | 1358 !is_sync_load, |
1359 support_async_revalidation ? request_data.headers : std::string()); | |
1316 // Request takes ownership. | 1360 // Request takes ownership. |
1317 extra_info->AssociateWithRequest(new_request.get()); | 1361 extra_info->AssociateWithRequest(new_request.get()); |
1318 | 1362 |
1319 if (new_request->url().SchemeIs(url::kBlobScheme)) { | 1363 if (new_request->url().SchemeIs(url::kBlobScheme)) { |
1320 // Hang on to a reference to ensure the blob is not released prior | 1364 // Hang on to a reference to ensure the blob is not released prior |
1321 // to the job being started. | 1365 // to the job being started. |
1322 storage::BlobProtocolHandler::SetRequestedBlobDataHandle( | 1366 storage::BlobProtocolHandler::SetRequestedBlobDataHandle( |
1323 new_request.get(), | 1367 new_request.get(), |
1324 filter_->blob_storage_context()->context()->GetBlobDataFromPublicURL( | 1368 filter_->blob_storage_context()->context()->GetBlobDataFromPublicURL( |
1325 new_request->url())); | 1369 new_request->url())); |
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1576 false, // is_stream | 1620 false, // is_stream |
1577 download, // allow_download | 1621 download, // allow_download |
1578 false, // has_user_gesture | 1622 false, // has_user_gesture |
1579 false, // enable_load_timing | 1623 false, // enable_load_timing |
1580 false, // enable_upload_progress | 1624 false, // enable_upload_progress |
1581 false, // do_not_prompt_for_login | 1625 false, // do_not_prompt_for_login |
1582 blink::WebReferrerPolicyDefault, | 1626 blink::WebReferrerPolicyDefault, |
1583 blink::WebPageVisibilityStateVisible, | 1627 blink::WebPageVisibilityStateVisible, |
1584 context, | 1628 context, |
1585 base::WeakPtr<ResourceMessageFilter>(), // filter | 1629 base::WeakPtr<ResourceMessageFilter>(), // filter |
1586 true); // is_async | 1630 true, // is_async |
1631 std::string()); // original_headers | |
1587 } | 1632 } |
1588 | 1633 |
1589 void ResourceDispatcherHostImpl::OnRenderViewHostCreated(int child_id, | 1634 void ResourceDispatcherHostImpl::OnRenderViewHostCreated(int child_id, |
1590 int route_id, | 1635 int route_id, |
1591 bool is_visible, | 1636 bool is_visible, |
1592 bool is_audible) { | 1637 bool is_audible) { |
1593 scheduler_->OnClientCreated(child_id, route_id, is_visible, is_audible); | 1638 scheduler_->OnClientCreated(child_id, route_id, is_visible, is_audible); |
1594 } | 1639 } |
1595 | 1640 |
1596 void ResourceDispatcherHostImpl::OnRenderViewHostDeleted( | 1641 void ResourceDispatcherHostImpl::OnRenderViewHostDeleted( |
(...skipping 422 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2019 true, // enable_load_timing | 2064 true, // enable_load_timing |
2020 false, // enable_upload_progress | 2065 false, // enable_upload_progress |
2021 false, // do_not_prompt_for_login | 2066 false, // do_not_prompt_for_login |
2022 info.common_params.referrer.policy, | 2067 info.common_params.referrer.policy, |
2023 // TODO(davidben): This is only used for prerenders. Replace | 2068 // TODO(davidben): This is only used for prerenders. Replace |
2024 // is_showing with something for that. Or maybe it just comes from the | 2069 // is_showing with something for that. Or maybe it just comes from the |
2025 // same mechanism as the cookie one. | 2070 // same mechanism as the cookie one. |
2026 blink::WebPageVisibilityStateVisible, | 2071 blink::WebPageVisibilityStateVisible, |
2027 resource_context, | 2072 resource_context, |
2028 base::WeakPtr<ResourceMessageFilter>(), // filter | 2073 base::WeakPtr<ResourceMessageFilter>(), // filter |
2029 true); | 2074 true, // is_async |
2075 std::string()); // original_headers | |
2030 // Request takes ownership. | 2076 // Request takes ownership. |
2031 extra_info->AssociateWithRequest(new_request.get()); | 2077 extra_info->AssociateWithRequest(new_request.get()); |
2032 | 2078 |
2033 if (new_request->url().SchemeIs(url::kBlobScheme)) { | 2079 if (new_request->url().SchemeIs(url::kBlobScheme)) { |
2034 // Hang on to a reference to ensure the blob is not released prior | 2080 // Hang on to a reference to ensure the blob is not released prior |
2035 // to the job being started. | 2081 // to the job being started. |
2036 ChromeBlobStorageContext* blob_context = | 2082 ChromeBlobStorageContext* blob_context = |
2037 GetChromeBlobStorageContextForResourceContext(resource_context); | 2083 GetChromeBlobStorageContextForResourceContext(resource_context); |
2038 storage::BlobProtocolHandler::SetRequestedBlobDataHandle( | 2084 storage::BlobProtocolHandler::SetRequestedBlobDataHandle( |
2039 new_request.get(), | 2085 new_request.get(), |
(...skipping 13 matching lines...) Expand all Loading... | |
2053 handler = AddStandardHandlers(new_request.get(), resource_type, | 2099 handler = AddStandardHandlers(new_request.get(), resource_type, |
2054 resource_context, | 2100 resource_context, |
2055 nullptr, // appcache_service | 2101 nullptr, // appcache_service |
2056 -1, // child_id | 2102 -1, // child_id |
2057 -1, // route_id | 2103 -1, // route_id |
2058 handler.Pass()); | 2104 handler.Pass()); |
2059 | 2105 |
2060 BeginRequestInternal(new_request.Pass(), handler.Pass()); | 2106 BeginRequestInternal(new_request.Pass(), handler.Pass()); |
2061 } | 2107 } |
2062 | 2108 |
2109 void ResourceDispatcherHostImpl::EnableStaleWhileRevalidateForTesting() { | |
2110 // Do nothing if it is enabled already. | |
kinuko
2015/11/19 07:00:29
nit: not very informative, maybe just remove this
Adam Rice
2015/11/19 21:13:52
Done.
| |
2111 if (!async_revalidation_manager_) | |
2112 async_revalidation_manager_.reset(new AsyncRevalidationManager); | |
2113 } | |
2114 | |
2063 // static | 2115 // static |
2064 int ResourceDispatcherHostImpl::CalculateApproximateMemoryCost( | 2116 int ResourceDispatcherHostImpl::CalculateApproximateMemoryCost( |
2065 net::URLRequest* request) { | 2117 net::URLRequest* request) { |
2066 // The following fields should be a minor size contribution (experimentally | 2118 // The following fields should be a minor size contribution (experimentally |
2067 // on the order of 100). However since they are variable length, it could | 2119 // on the order of 100). However since they are variable length, it could |
2068 // in theory be a sizeable contribution. | 2120 // in theory be a sizeable contribution. |
2069 int strings_cost = request->extra_request_headers().ToString().size() + | 2121 int strings_cost = request->extra_request_headers().ToString().size() + |
2070 request->original_url().spec().size() + | 2122 request->original_url().spec().size() + |
2071 request->referrer().size() + | 2123 request->referrer().size() + |
2072 request->method().size(); | 2124 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) | 2438 if ((load_flags & net::LOAD_REPORT_RAW_HEADERS) |
2387 && !policy->CanReadRawCookies(child_id)) { | 2439 && !policy->CanReadRawCookies(child_id)) { |
2388 VLOG(1) << "Denied unauthorized request for raw headers"; | 2440 VLOG(1) << "Denied unauthorized request for raw headers"; |
2389 load_flags &= ~net::LOAD_REPORT_RAW_HEADERS; | 2441 load_flags &= ~net::LOAD_REPORT_RAW_HEADERS; |
2390 } | 2442 } |
2391 | 2443 |
2392 return load_flags; | 2444 return load_flags; |
2393 } | 2445 } |
2394 | 2446 |
2395 } // namespace content | 2447 } // namespace content |
OLD | NEW |