Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(101)

Side by Side Diff: content/browser/loader/resource_dispatcher_host_impl.cc

Issue 2847443002: PlzNavigate: make NavigationResourceHandler a LayeredResourceHandler (Closed)
Patch Set: Addressed comments Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 <stddef.h> 9 #include <stddef.h>
10 10
(...skipping 506 matching lines...) Expand 10 before | Expand all | Expand 10 after
517 GURL origin; 517 GURL origin;
518 if (!delegate_ || 518 if (!delegate_ ||
519 !delegate_->ShouldInterceptResourceAsStream( 519 !delegate_->ShouldInterceptResourceAsStream(
520 request, plugin_path, mime_type, &origin, payload)) { 520 request, plugin_path, mime_type, &origin, payload)) {
521 return std::unique_ptr<ResourceHandler>(); 521 return std::unique_ptr<ResourceHandler>();
522 } 522 }
523 523
524 StreamContext* stream_context = 524 StreamContext* stream_context =
525 GetStreamContextForResourceContext(info->GetContext()); 525 GetStreamContextForResourceContext(info->GetContext());
526 526
527 std::unique_ptr<StreamResourceHandler> handler( 527 std::unique_ptr<StreamResourceHandler> handler(new StreamResourceHandler(
528 new StreamResourceHandler(request, stream_context->registry(), origin)); 528 request, stream_context->registry(), origin, false));
529 529
530 info->set_is_stream(true); 530 info->set_is_stream(true);
531 std::unique_ptr<StreamInfo> stream_info(new StreamInfo); 531 std::unique_ptr<StreamInfo> stream_info(new StreamInfo);
532 stream_info->handle = handler->stream()->CreateHandle(); 532 stream_info->handle = handler->stream()->CreateHandle();
533 stream_info->original_url = request->url(); 533 stream_info->original_url = request->url();
534 stream_info->mime_type = mime_type; 534 stream_info->mime_type = mime_type;
535 // Make a copy of the response headers so it is safe to pass across threads; 535 // Make a copy of the response headers so it is safe to pass across threads;
536 // the old handler (AsyncResourceHandler) may modify it in parallel via the 536 // the old handler (AsyncResourceHandler) may modify it in parallel via the
537 // ResourceDispatcherHostDelegate. 537 // ResourceDispatcherHostDelegate.
538 if (response->head.headers.get()) { 538 if (response->head.headers.get()) {
(...skipping 931 matching lines...) Expand 10 before | Expand all | Expand 10 after
1470 IsResourceTypeFrame(request_data.resource_type)) { 1470 IsResourceTypeFrame(request_data.resource_type)) {
1471 DCHECK(request->url().SchemeIs(url::kBlobScheme)); 1471 DCHECK(request->url().SchemeIs(url::kBlobScheme));
1472 return handler; 1472 return handler;
1473 } 1473 }
1474 1474
1475 return AddStandardHandlers(request, request_data.resource_type, 1475 return AddStandardHandlers(request, request_data.resource_type,
1476 resource_context, 1476 resource_context,
1477 request_data.fetch_request_context_type, 1477 request_data.fetch_request_context_type,
1478 request_data.fetch_mixed_content_context_type, 1478 request_data.fetch_mixed_content_context_type,
1479 requester_info->appcache_service(), child_id, 1479 requester_info->appcache_service(), child_id,
1480 route_id, std::move(handler)); 1480 route_id, std::move(handler), nullptr, nullptr);
1481 } 1481 }
1482 1482
1483 std::unique_ptr<ResourceHandler> 1483 std::unique_ptr<ResourceHandler>
1484 ResourceDispatcherHostImpl::AddStandardHandlers( 1484 ResourceDispatcherHostImpl::AddStandardHandlers(
1485 net::URLRequest* request, 1485 net::URLRequest* request,
1486 ResourceType resource_type, 1486 ResourceType resource_type,
1487 ResourceContext* resource_context, 1487 ResourceContext* resource_context,
1488 RequestContextType fetch_request_context_type, 1488 RequestContextType fetch_request_context_type,
1489 blink::WebMixedContentContextType fetch_mixed_content_context_type, 1489 blink::WebMixedContentContextType fetch_mixed_content_context_type,
1490 AppCacheService* appcache_service, 1490 AppCacheService* appcache_service,
1491 int child_id, 1491 int child_id,
1492 int route_id, 1492 int route_id,
1493 std::unique_ptr<ResourceHandler> handler) { 1493 std::unique_ptr<ResourceHandler> handler,
1494 NavigationURLLoaderImplCore* navigation_loader_core,
1495 std::unique_ptr<StreamHandle> stream_handle) {
1494 // The InterceptingResourceHandler will replace its next handler with an 1496 // The InterceptingResourceHandler will replace its next handler with an
1495 // appropriate one based on the MIME type of the response if needed. It 1497 // appropriate one based on the MIME type of the response if needed. It
1496 // should be placed at the end of the chain, just before |handler|. 1498 // should be placed at the end of the chain, just before |handler|.
1497 handler.reset(new InterceptingResourceHandler(std::move(handler), request)); 1499 handler.reset(new InterceptingResourceHandler(std::move(handler), request));
1498 InterceptingResourceHandler* intercepting_handler = 1500 InterceptingResourceHandler* intercepting_handler =
1499 static_cast<InterceptingResourceHandler*>(handler.get()); 1501 static_cast<InterceptingResourceHandler*>(handler.get());
1500 1502
1501 std::vector<std::unique_ptr<ResourceThrottle>> throttles; 1503 std::vector<std::unique_ptr<ResourceThrottle>> throttles;
1502 1504
1503 // Add a NavigationResourceThrottle for navigations. 1505 // Add a NavigationResourceThrottle for navigations.
1504 // PlzNavigate: the throttle is unnecessary as communication with the UI 1506 // PlzNavigate: the throttle is unnecessary as communication with the UI
1505 // thread is handled by the NavigationURLloader. 1507 // thread is handled by the NavigationResourceHandler below.
1506 if (!IsBrowserSideNavigationEnabled() && IsResourceTypeFrame(resource_type)) { 1508 if (!IsBrowserSideNavigationEnabled() && IsResourceTypeFrame(resource_type)) {
1507 throttles.push_back(base::MakeUnique<NavigationResourceThrottle>( 1509 throttles.push_back(base::MakeUnique<NavigationResourceThrottle>(
1508 request, delegate_, fetch_request_context_type, 1510 request, delegate_, fetch_request_context_type,
1509 fetch_mixed_content_context_type)); 1511 fetch_mixed_content_context_type));
1510 } 1512 }
1511 1513
1512 if (delegate_) { 1514 if (delegate_) {
1513 delegate_->RequestBeginning(request, 1515 delegate_->RequestBeginning(request,
1514 resource_context, 1516 resource_context,
1515 appcache_service, 1517 appcache_service,
(...skipping 23 matching lines...) Expand all
1539 } else { 1541 } else {
1540 post_mime_sniffing_throttles.push_back(std::move(throttle)); 1542 post_mime_sniffing_throttles.push_back(std::move(throttle));
1541 } 1543 }
1542 } 1544 }
1543 throttles.clear(); 1545 throttles.clear();
1544 1546
1545 // Add the post mime sniffing throttles. 1547 // Add the post mime sniffing throttles.
1546 handler.reset(new ThrottlingResourceHandler( 1548 handler.reset(new ThrottlingResourceHandler(
1547 std::move(handler), request, std::move(post_mime_sniffing_throttles))); 1549 std::move(handler), request, std::move(post_mime_sniffing_throttles)));
1548 1550
1551 if (IsBrowserSideNavigationEnabled() && IsResourceTypeFrame(resource_type)) {
1552 DCHECK(navigation_loader_core);
1553 DCHECK(stream_handle);
1554 // PlzNavigate
1555 // Add a NavigationResourceHandler that will control the flow of navigation.
1556 handler.reset(new NavigationResourceHandler(
1557 request, std::move(handler), navigation_loader_core, delegate(),
1558 std::move(stream_handle)));
1559 } else {
1560 DCHECK(!navigation_loader_core);
1561 DCHECK(!stream_handle);
1562 }
1563
1549 PluginService* plugin_service = nullptr; 1564 PluginService* plugin_service = nullptr;
1550 #if BUILDFLAG(ENABLE_PLUGINS) 1565 #if BUILDFLAG(ENABLE_PLUGINS)
1551 plugin_service = PluginService::GetInstance(); 1566 plugin_service = PluginService::GetInstance();
1552 #endif 1567 #endif
1553 1568
1554 // Insert a buffered event handler to sniff the mime type. 1569 // Insert a buffered event handler to sniff the mime type.
1555 // Note: all ResourceHandler following the MimeSniffingResourceHandler 1570 // Note: all ResourceHandler following the MimeSniffingResourceHandler
1556 // should expect OnWillRead to be called *before* OnResponseStarted as 1571 // should expect OnWillRead to be called *before* OnResponseStarted as
1557 // part of the mime sniffing process. 1572 // part of the mime sniffing process.
1558 handler.reset(new MimeSniffingResourceHandler( 1573 handler.reset(new MimeSniffingResourceHandler(
(...skipping 507 matching lines...) Expand 10 before | Expand all | Expand 10 after
2066 info.begin_params.request_context_type, frame_type, 2081 info.begin_params.request_context_type, frame_type,
2067 info.are_ancestors_secure, info.common_params.post_data, 2082 info.are_ancestors_secure, info.common_params.post_data,
2068 extra_info->GetWebContentsGetterForRequest()); 2083 extra_info->GetWebContentsGetterForRequest());
2069 2084
2070 // Have the appcache associate its extra info with the request. 2085 // Have the appcache associate its extra info with the request.
2071 if (appcache_handle_core) { 2086 if (appcache_handle_core) {
2072 AppCacheInterceptor::SetExtraRequestInfoForHost( 2087 AppCacheInterceptor::SetExtraRequestInfoForHost(
2073 new_request.get(), appcache_handle_core->host(), resource_type, false); 2088 new_request.get(), appcache_handle_core->host(), resource_type, false);
2074 } 2089 }
2075 2090
2091 StreamContext* stream_context =
2092 GetStreamContextForResourceContext(resource_context);
2093 // Note: the stream should be created with immediate mode set to true to
2094 // ensure that data read will be flushed to the reader as soon as it's
2095 // available. Otherwise, we risk delaying transmitting the body of the
2096 // resource to the renderer, which will delay parsing accordingly.
2076 std::unique_ptr<ResourceHandler> handler( 2097 std::unique_ptr<ResourceHandler> handler(
2077 new NavigationResourceHandler(new_request.get(), loader, delegate())); 2098 new StreamResourceHandler(new_request.get(), stream_context->registry(),
2099 new_request->url().GetOrigin(), true));
2100 std::unique_ptr<StreamHandle> stream_handle =
2101 static_cast<StreamResourceHandler*>(handler.get())
2102 ->stream()
2103 ->CreateHandle();
2078 2104
2079 // TODO(davidben): Fix the dependency on child_id/route_id. Those are used 2105 // TODO(davidben): Fix the dependency on child_id/route_id. Those are used
2080 // by the ResourceScheduler. currently it's a no-op. 2106 // by the ResourceScheduler. currently it's a no-op.
2081 handler = AddStandardHandlers( 2107 handler = AddStandardHandlers(
2082 new_request.get(), resource_type, resource_context, 2108 new_request.get(), resource_type, resource_context,
2083 info.begin_params.request_context_type, 2109 info.begin_params.request_context_type,
2084 info.begin_params.mixed_content_context_type, 2110 info.begin_params.mixed_content_context_type,
2085 appcache_handle_core ? appcache_handle_core->GetAppCacheService() 2111 appcache_handle_core ? appcache_handle_core->GetAppCacheService()
2086 : nullptr, 2112 : nullptr,
2087 -1, // child_id 2113 -1, // child_id
2088 -1, // route_id 2114 -1, // route_id
2089 std::move(handler)); 2115 std::move(handler), loader, std::move(stream_handle));
2090 2116
2091 BeginRequestInternal(std::move(new_request), std::move(handler)); 2117 BeginRequestInternal(std::move(new_request), std::move(handler));
2092 } 2118 }
2093 2119
2094 void ResourceDispatcherHostImpl::SetLoaderDelegate( 2120 void ResourceDispatcherHostImpl::SetLoaderDelegate(
2095 LoaderDelegate* loader_delegate) { 2121 LoaderDelegate* loader_delegate) {
2096 loader_delegate_ = loader_delegate; 2122 loader_delegate_ = loader_delegate;
2097 } 2123 }
2098 2124
2099 void ResourceDispatcherHostImpl::OnRenderFrameDeleted( 2125 void ResourceDispatcherHostImpl::OnRenderFrameDeleted(
(...skipping 515 matching lines...) Expand 10 before | Expand all | Expand 10 after
2615 &throttles); 2641 &throttles);
2616 if (!throttles.empty()) { 2642 if (!throttles.empty()) {
2617 handler.reset(new ThrottlingResourceHandler(std::move(handler), request, 2643 handler.reset(new ThrottlingResourceHandler(std::move(handler), request,
2618 std::move(throttles))); 2644 std::move(throttles)));
2619 } 2645 }
2620 } 2646 }
2621 return handler; 2647 return handler;
2622 } 2648 }
2623 2649
2624 } // namespace content 2650 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/loader/resource_dispatcher_host_impl.h ('k') | content/browser/loader/resource_dispatcher_host_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698