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

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

Issue 1970693002: Use mojo for Chrome Loading, Part 1 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 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 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 #include "content/browser/streams/stream.h" 70 #include "content/browser/streams/stream.h"
71 #include "content/browser/streams/stream_context.h" 71 #include "content/browser/streams/stream_context.h"
72 #include "content/browser/streams/stream_registry.h" 72 #include "content/browser/streams/stream_registry.h"
73 #include "content/browser/web_contents/web_contents_impl.h" 73 #include "content/browser/web_contents/web_contents_impl.h"
74 #include "content/common/appcache_interfaces.h" 74 #include "content/common/appcache_interfaces.h"
75 #include "content/common/navigation_params.h" 75 #include "content/common/navigation_params.h"
76 #include "content/common/net/url_request_service_worker_data.h" 76 #include "content/common/net/url_request_service_worker_data.h"
77 #include "content/common/resource_messages.h" 77 #include "content/common/resource_messages.h"
78 #include "content/common/site_isolation_policy.h" 78 #include "content/common/site_isolation_policy.h"
79 #include "content/common/ssl_status_serialization.h" 79 #include "content/common/ssl_status_serialization.h"
80 #include "content/common/url_loader_type_converters.h"
80 #include "content/common/view_messages.h" 81 #include "content/common/view_messages.h"
81 #include "content/public/browser/browser_thread.h" 82 #include "content/public/browser/browser_thread.h"
82 #include "content/public/browser/content_browser_client.h" 83 #include "content/public/browser/content_browser_client.h"
83 #include "content/public/browser/download_manager.h" 84 #include "content/public/browser/download_manager.h"
84 #include "content/public/browser/download_url_parameters.h" 85 #include "content/public/browser/download_url_parameters.h"
85 #include "content/public/browser/global_request_id.h" 86 #include "content/public/browser/global_request_id.h"
86 #include "content/public/browser/plugin_service.h" 87 #include "content/public/browser/plugin_service.h"
87 #include "content/public/browser/resource_dispatcher_host_delegate.h" 88 #include "content/public/browser/resource_dispatcher_host_delegate.h"
88 #include "content/public/browser/resource_request_details.h" 89 #include "content/public/browser/resource_request_details.h"
89 #include "content/public/browser/resource_throttle.h" 90 #include "content/public/browser/resource_throttle.h"
(...skipping 485 matching lines...) Expand 10 before | Expand all | Expand 10 after
575 // navigation becomes the default. crbug.com/561610 576 // navigation becomes the default. crbug.com/561610
576 if (!IsBrowserSideNavigationEnabled() && 577 if (!IsBrowserSideNavigationEnabled() &&
577 base::FeatureList::IsEnabled(features::kStaleWhileRevalidate)) { 578 base::FeatureList::IsEnabled(features::kStaleWhileRevalidate)) {
578 async_revalidation_manager_.reset(new AsyncRevalidationManager); 579 async_revalidation_manager_.reset(new AsyncRevalidationManager);
579 } 580 }
580 } 581 }
581 582
582 ResourceDispatcherHostImpl::~ResourceDispatcherHostImpl() { 583 ResourceDispatcherHostImpl::~ResourceDispatcherHostImpl() {
583 DCHECK(outstanding_requests_stats_map_.empty()); 584 DCHECK(outstanding_requests_stats_map_.empty());
584 DCHECK(g_resource_dispatcher_host); 585 DCHECK(g_resource_dispatcher_host);
586 DCHECK_CURRENTLY_ON(BrowserThread::UI);
585 g_resource_dispatcher_host = NULL; 587 g_resource_dispatcher_host = NULL;
586 } 588 }
587 589
588 // static 590 // static
589 ResourceDispatcherHostImpl* ResourceDispatcherHostImpl::Get() { 591 ResourceDispatcherHostImpl* ResourceDispatcherHostImpl::Get() {
590 return g_resource_dispatcher_host; 592 return g_resource_dispatcher_host;
591 } 593 }
592 594
593 // static 595 // static
594 void ResourceDispatcherHostImpl::ResumeBlockedRequestsForRouteFromUI( 596 void ResourceDispatcherHostImpl::ResumeBlockedRequestsForRouteFromUI(
(...skipping 573 matching lines...) Expand 10 before | Expand all | Expand 10 after
1168 for (const auto& routing_id : ids) { 1170 for (const auto& routing_id : ids) {
1169 CancelBlockedRequestsForRoute(routing_id); 1171 CancelBlockedRequestsForRoute(routing_id);
1170 } 1172 }
1171 1173
1172 scheduler_.reset(); 1174 scheduler_.reset();
1173 } 1175 }
1174 1176
1175 bool ResourceDispatcherHostImpl::OnMessageReceived( 1177 bool ResourceDispatcherHostImpl::OnMessageReceived(
1176 const IPC::Message& message, 1178 const IPC::Message& message,
1177 ResourceMessageFilter* filter) { 1179 ResourceMessageFilter* filter) {
1180 DCHECK_CURRENTLY_ON(BrowserThread::IO);
1178 filter_ = filter; 1181 filter_ = filter;
1179 bool handled = true; 1182 bool handled = true;
1180 IPC_BEGIN_MESSAGE_MAP(ResourceDispatcherHostImpl, message) 1183 IPC_BEGIN_MESSAGE_MAP(ResourceDispatcherHostImpl, message)
1181 IPC_MESSAGE_HANDLER(ResourceHostMsg_RequestResource, OnRequestResource) 1184 IPC_MESSAGE_HANDLER(ResourceHostMsg_RequestResource, OnRequestResource)
1182 IPC_MESSAGE_HANDLER_DELAY_REPLY(ResourceHostMsg_SyncLoad, OnSyncLoad) 1185 IPC_MESSAGE_HANDLER_DELAY_REPLY(ResourceHostMsg_SyncLoad, OnSyncLoad)
1183 IPC_MESSAGE_HANDLER(ResourceHostMsg_ReleaseDownloadedFile, 1186 IPC_MESSAGE_HANDLER(ResourceHostMsg_ReleaseDownloadedFile,
1184 OnReleaseDownloadedFile) 1187 OnReleaseDownloadedFile)
1185 IPC_MESSAGE_HANDLER(ResourceHostMsg_DataDownloaded_ACK, OnDataDownloadedACK) 1188 IPC_MESSAGE_HANDLER(ResourceHostMsg_DataDownloaded_ACK, OnDataDownloadedACK)
1186 IPC_MESSAGE_HANDLER(ResourceHostMsg_CancelRequest, OnCancelRequest) 1189 IPC_MESSAGE_HANDLER(ResourceHostMsg_CancelRequest, OnCancelRequest)
1187 IPC_MESSAGE_HANDLER(ResourceHostMsg_DidChangePriority, OnDidChangePriority) 1190 IPC_MESSAGE_HANDLER(ResourceHostMsg_DidChangePriority, OnDidChangePriority)
(...skipping 21 matching lines...) Expand all
1209 } 1212 }
1210 1213
1211 filter_ = NULL; 1214 filter_ = NULL;
1212 return handled; 1215 return handled;
1213 } 1216 }
1214 1217
1215 void ResourceDispatcherHostImpl::OnRequestResource( 1218 void ResourceDispatcherHostImpl::OnRequestResource(
1216 int routing_id, 1219 int routing_id,
1217 int request_id, 1220 int request_id,
1218 const ResourceHostMsg_Request& request_data) { 1221 const ResourceHostMsg_Request& request_data) {
1222 std::unique_ptr<mojom::URLLoader> loader =
1223 std::move(mojo_loader_for_next_load_request_);
1224 mojom::URLLoaderClientPtr client =
1225 std::move(mojo_loader_client_for_next_load_request_);
1226
1219 // TODO(pkasting): Remove ScopedTracker below once crbug.com/477117 is fixed. 1227 // TODO(pkasting): Remove ScopedTracker below once crbug.com/477117 is fixed.
1220 tracked_objects::ScopedTracker tracking_profile( 1228 tracked_objects::ScopedTracker tracking_profile(
1221 FROM_HERE_WITH_EXPLICIT_FUNCTION( 1229 FROM_HERE_WITH_EXPLICIT_FUNCTION(
1222 "477117 ResourceDispatcherHostImpl::OnRequestResource")); 1230 "477117 ResourceDispatcherHostImpl::OnRequestResource"));
1223 // When logging time-to-network only care about main frame and non-transfer 1231 // When logging time-to-network only care about main frame and non-transfer
1224 // navigations. 1232 // navigations.
1225 // PlzNavigate: this log happens from NavigationRequest::OnRequestStarted 1233 // PlzNavigate: this log happens from NavigationRequest::OnRequestStarted
1226 // instead. 1234 // instead.
1227 if (request_data.resource_type == RESOURCE_TYPE_MAIN_FRAME && 1235 if (request_data.resource_type == RESOURCE_TYPE_MAIN_FRAME &&
1228 request_data.transferred_request_request_id == -1 && 1236 request_data.transferred_request_request_id == -1 &&
1229 !IsBrowserSideNavigationEnabled()) { 1237 !IsBrowserSideNavigationEnabled()) {
1230 BrowserThread::PostTask( 1238 BrowserThread::PostTask(
1231 BrowserThread::UI, 1239 BrowserThread::UI,
1232 FROM_HERE, 1240 FROM_HERE,
1233 base::Bind(&LogResourceRequestTimeOnUI, 1241 base::Bind(&LogResourceRequestTimeOnUI,
1234 TimeTicks::Now(), 1242 TimeTicks::Now(),
1235 filter_->child_id(), 1243 filter_->child_id(),
1236 request_data.render_frame_id, 1244 request_data.render_frame_id,
1237 request_data.url)); 1245 request_data.url));
1238 } 1246 }
1239 BeginRequest(request_id, request_data, NULL, routing_id); 1247 BeginRequest(request_id, request_data, NULL, routing_id, std::move(loader),
1248 std::move(client));
1240 } 1249 }
1241 1250
1242 // Begins a resource request with the given params on behalf of the specified 1251 // Begins a resource request with the given params on behalf of the specified
1243 // child process. Responses will be dispatched through the given receiver. The 1252 // child process. Responses will be dispatched through the given receiver. The
1244 // process ID is used to lookup WebContentsImpl from routing_id's in the case of 1253 // process ID is used to lookup WebContentsImpl from routing_id's in the case of
1245 // a request from a renderer. request_context is the cookie/cache context to be 1254 // a request from a renderer. request_context is the cookie/cache context to be
1246 // used for this request. 1255 // used for this request.
1247 // 1256 //
1248 // If sync_result is non-null, then a SyncLoad reply will be generated, else 1257 // If sync_result is non-null, then a SyncLoad reply will be generated, else
1249 // a normal asynchronous set of response messages will be generated. 1258 // a normal asynchronous set of response messages will be generated.
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
1360 } 1369 }
1361 1370
1362 // We should have a CrossSiteResourceHandler to finish the transfer. 1371 // We should have a CrossSiteResourceHandler to finish the transfer.
1363 DCHECK(info->cross_site_handler()); 1372 DCHECK(info->cross_site_handler());
1364 } 1373 }
1365 1374
1366 void ResourceDispatcherHostImpl::BeginRequest( 1375 void ResourceDispatcherHostImpl::BeginRequest(
1367 int request_id, 1376 int request_id,
1368 const ResourceHostMsg_Request& request_data, 1377 const ResourceHostMsg_Request& request_data,
1369 IPC::Message* sync_result, // only valid for sync 1378 IPC::Message* sync_result, // only valid for sync
1370 int route_id) { 1379 int route_id,
1380 std::unique_ptr<mojom::URLLoader> url_loader,
1381 mojom::URLLoaderClientPtr client) {
1371 int process_type = filter_->process_type(); 1382 int process_type = filter_->process_type();
1372 int child_id = filter_->child_id(); 1383 int child_id = filter_->child_id();
1373 1384
1374 // Reject request id that's currently in use. 1385 // Reject request id that's currently in use.
1375 if (IsRequestIDInUse(GlobalRequestID(child_id, request_id))) { 1386 if (IsRequestIDInUse(GlobalRequestID(child_id, request_id))) {
1376 bad_message::ReceivedBadMessage(filter_, 1387 bad_message::ReceivedBadMessage(filter_,
1377 bad_message::RDH_INVALID_REQUEST_ID); 1388 bad_message::RDH_INVALID_REQUEST_ID);
1378 return; 1389 return;
1379 } 1390 }
1380 1391
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after
1619 } 1630 }
1620 1631
1621 // Have the appcache associate its extra info with the request. 1632 // Have the appcache associate its extra info with the request.
1622 AppCacheInterceptor::SetExtraRequestInfo( 1633 AppCacheInterceptor::SetExtraRequestInfo(
1623 new_request.get(), filter_->appcache_service(), child_id, 1634 new_request.get(), filter_->appcache_service(), child_id,
1624 request_data.appcache_host_id, request_data.resource_type, 1635 request_data.appcache_host_id, request_data.resource_type,
1625 request_data.should_reset_appcache); 1636 request_data.should_reset_appcache);
1626 1637
1627 std::unique_ptr<ResourceHandler> handler(CreateResourceHandler( 1638 std::unique_ptr<ResourceHandler> handler(CreateResourceHandler(
1628 new_request.get(), request_data, sync_result, route_id, process_type, 1639 new_request.get(), request_data, sync_result, route_id, process_type,
1629 child_id, resource_context)); 1640 child_id, resource_context, client));
1630 1641
1631 if (handler) 1642 if (handler)
1632 BeginRequestInternal(std::move(new_request), std::move(handler)); 1643 BeginRequestInternal(std::move(new_request), std::move(handler),
1644 std::move(url_loader), std::move(client));
1633 } 1645 }
1634 1646
1635 std::unique_ptr<ResourceHandler> 1647 std::unique_ptr<ResourceHandler>
1636 ResourceDispatcherHostImpl::CreateResourceHandler( 1648 ResourceDispatcherHostImpl::CreateResourceHandler(
1637 net::URLRequest* request, 1649 net::URLRequest* request,
1638 const ResourceHostMsg_Request& request_data, 1650 const ResourceHostMsg_Request& request_data,
1639 IPC::Message* sync_result, 1651 IPC::Message* sync_result,
1640 int route_id, 1652 int route_id,
1641 int process_type, 1653 int process_type,
1642 int child_id, 1654 int child_id,
1643 ResourceContext* resource_context) { 1655 ResourceContext* resource_context,
1656 bool using_mojo) {
1644 // TODO(pkasting): Remove ScopedTracker below once crbug.com/456331 is fixed. 1657 // TODO(pkasting): Remove ScopedTracker below once crbug.com/456331 is fixed.
1645 tracked_objects::ScopedTracker tracking_profile( 1658 tracked_objects::ScopedTracker tracking_profile(
1646 FROM_HERE_WITH_EXPLICIT_FUNCTION( 1659 FROM_HERE_WITH_EXPLICIT_FUNCTION(
1647 "456331 ResourceDispatcherHostImpl::CreateResourceHandler")); 1660 "456331 ResourceDispatcherHostImpl::CreateResourceHandler"));
1648 // Construct the IPC resource handler. 1661 // Construct the IPC resource handler.
1649 std::unique_ptr<ResourceHandler> handler; 1662 std::unique_ptr<ResourceHandler> handler;
1650 if (sync_result) { 1663 if (sync_result) {
1664 DCHECK(!using_mojo);
1651 // download_to_file is not supported for synchronous requests. 1665 // download_to_file is not supported for synchronous requests.
1652 if (request_data.download_to_file) { 1666 if (request_data.download_to_file) {
1653 bad_message::ReceivedBadMessage(filter_, bad_message::RDH_BAD_DOWNLOAD); 1667 bad_message::ReceivedBadMessage(filter_, bad_message::RDH_BAD_DOWNLOAD);
1654 return std::unique_ptr<ResourceHandler>(); 1668 return std::unique_ptr<ResourceHandler>();
1655 } 1669 }
1656 1670
1657 handler.reset(new SyncResourceHandler(request, sync_result, this)); 1671 handler.reset(new SyncResourceHandler(request, sync_result, this));
1658 } else { 1672 } else {
1659 handler.reset(new AsyncResourceHandler(request, this)); 1673 handler.reset(new AsyncResourceHandler(request, this, using_mojo));
1660 1674
1661 // The RedirectToFileResourceHandler depends on being next in the chain. 1675 // The RedirectToFileResourceHandler depends on being next in the chain.
1662 if (request_data.download_to_file) { 1676 if (request_data.download_to_file) {
1663 handler.reset( 1677 handler.reset(
1664 new RedirectToFileResourceHandler(std::move(handler), request)); 1678 new RedirectToFileResourceHandler(std::move(handler), request));
1665 } 1679 }
1666 } 1680 }
1667 1681
1668 // Prefetches and <a ping> requests outlive their child process. 1682 // Prefetches and <a ping> requests outlive their child process.
1669 if (!sync_result && IsDetachableResourceType(request_data.resource_type)) { 1683 if (!sync_result && IsDetachableResourceType(request_data.resource_type)) {
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
1770 ResourceLoader* loader = GetLoader(filter_->child_id(), request_id); 1784 ResourceLoader* loader = GetLoader(filter_->child_id(), request_id);
1771 // The request may go away before processing this message, so |loader| can 1785 // The request may go away before processing this message, so |loader| can
1772 // legitimately be null. 1786 // legitimately be null.
1773 if (!loader) 1787 if (!loader)
1774 return; 1788 return;
1775 1789
1776 scheduler_->ReprioritizeRequest(loader->request(), new_priority, 1790 scheduler_->ReprioritizeRequest(loader->request(), new_priority,
1777 intra_priority_value); 1791 intra_priority_value);
1778 } 1792 }
1779 1793
1794 void ResourceDispatcherHostImpl::OnReceivedResponseForMojo(
1795 int request_id,
1796 const ResourceResponseHead& head) {
1797 int child_id = filter_->child_id();
1798 ResourceLoader* loader = GetLoader(child_id, request_id);
1799 DCHECK(loader);
jam 2016/05/13 00:55:05 nit: here and below, and also in next method, thes
yhirano 2016/05/17 12:38:49 Done.
1800 mojom::URLLoaderClient* client = loader->client();
1801 DCHECK(client);
1802 mojom::URLResponsePtr response = mojom::URLResponse::From(head);
1803 response->body = loader->GetRequestInfo()->TakeBodyReader();
1804 client->OnReceiveResponse(std::move(response));
1805 }
1806
1807 void ResourceDispatcherHostImpl::OnRequestCompleteForMojo(
1808 int request_id,
1809 const ResourceMsg_RequestCompleteData& data) {
1810 int child_id = filter_->child_id();
1811 ResourceLoader* loader = GetLoader(child_id, request_id);
1812 DCHECK(loader);
1813 mojom::URLLoaderClient* client = loader->client();
1814 DCHECK(client);
1815
1816 client->OnComplete(mojom::URLLoaderStatus::From(data));
1817 }
1818
1780 void ResourceDispatcherHostImpl::OnDataDownloadedACK(int request_id) { 1819 void ResourceDispatcherHostImpl::OnDataDownloadedACK(int request_id) {
1781 // TODO(michaeln): maybe throttle DataDownloaded messages 1820 // TODO(michaeln): maybe throttle DataDownloaded messages
1782 } 1821 }
1783 1822
1784 void ResourceDispatcherHostImpl::RegisterDownloadedTempFile( 1823 void ResourceDispatcherHostImpl::RegisterDownloadedTempFile(
1785 int child_id, int request_id, const base::FilePath& file_path) { 1824 int child_id, int request_id, const base::FilePath& file_path) {
1786 scoped_refptr<ShareableFileReference> reference = 1825 scoped_refptr<ShareableFileReference> reference =
1787 ShareableFileReference::Get(file_path); 1826 ShareableFileReference::Get(file_path);
1788 DCHECK(reference.get()); 1827 DCHECK(reference.get());
1789 1828
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after
2055 // blocked_loaders_map_, as blocking requests modifies the map. 2094 // blocked_loaders_map_, as blocking requests modifies the map.
2056 std::set<GlobalFrameRoutingId> routing_ids; 2095 std::set<GlobalFrameRoutingId> routing_ids;
2057 for (const auto& blocked_loaders : blocked_loaders_map_) { 2096 for (const auto& blocked_loaders : blocked_loaders_map_) {
2058 if (blocked_loaders.first.child_id == child_id) 2097 if (blocked_loaders.first.child_id == child_id)
2059 routing_ids.insert(blocked_loaders.first); 2098 routing_ids.insert(blocked_loaders.first);
2060 } 2099 }
2061 for (const GlobalFrameRoutingId& route_id : routing_ids) { 2100 for (const GlobalFrameRoutingId& route_id : routing_ids) {
2062 CancelBlockedRequestsForRoute(route_id); 2101 CancelBlockedRequestsForRoute(route_id);
2063 } 2102 }
2064 } 2103 }
2104
2105 // Uninitiated URLLoader has no routing ID, so it should be deleted only when
2106 // cancel_all_routes is specified.
2107 if (cancel_all_routes) {
2108 auto it = uninitiated_url_loaders_.begin();
2109 while (it != uninitiated_url_loaders_.end()) {
2110 if (it->second.first == child_id) {
2111 it = uninitiated_url_loaders_.erase(it);
2112 } else {
2113 ++it;
2114 }
2115 }
2116 }
2065 } 2117 }
2066 2118
2067 // Cancels the request and removes it from the list. 2119 // Cancels the request and removes it from the list.
2068 void ResourceDispatcherHostImpl::RemovePendingRequest(int child_id, 2120 void ResourceDispatcherHostImpl::RemovePendingRequest(int child_id,
2069 int request_id) { 2121 int request_id) {
2070 LoaderMap::iterator i = pending_loaders_.find( 2122 LoaderMap::iterator i = pending_loaders_.find(
2071 GlobalRequestID(child_id, request_id)); 2123 GlobalRequestID(child_id, request_id));
2072 if (i == pending_loaders_.end()) { 2124 if (i == pending_loaders_.end()) {
2073 NOTREACHED() << "Trying to remove a request that's not here"; 2125 NOTREACHED() << "Trying to remove a request that's not here";
2074 return; 2126 return;
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after
2342 std::move(handler)); 2394 std::move(handler));
2343 2395
2344 BeginRequestInternal(std::move(new_request), std::move(handler)); 2396 BeginRequestInternal(std::move(new_request), std::move(handler));
2345 } 2397 }
2346 2398
2347 void ResourceDispatcherHostImpl::EnableStaleWhileRevalidateForTesting() { 2399 void ResourceDispatcherHostImpl::EnableStaleWhileRevalidateForTesting() {
2348 if (!async_revalidation_manager_) 2400 if (!async_revalidation_manager_)
2349 async_revalidation_manager_.reset(new AsyncRevalidationManager); 2401 async_revalidation_manager_.reset(new AsyncRevalidationManager);
2350 } 2402 }
2351 2403
2404 void ResourceDispatcherHostImpl::OnRequestResourceFromMojo(
2405 int routing_id,
2406 int request_id,
2407 mojom::URLLoaderClientPtr client,
2408 const ResourceHostMsg_Request& request_data,
2409 ResourceMessageFilter* filter) {
2410 filter_ = filter;
2411 OnRequestResource(routing_id, request_id, request_data);
2412 filter_ = nullptr;
2413 }
2414
2415 bool ResourceDispatcherHostImpl::SendWithMojoIfPossible(
2416 const IPC::Message& message,
2417 ResourceMessageFilter* filter) {
2418 if (IPC_MESSAGE_ID_CLASS(message.type()) != ResourceMsgStart)
2419 return false;
2420
2421 base::PickleIterator iter(message);
2422 int request_id = -1;
2423 bool ok = iter.ReadInt(&request_id);
2424 DCHECK(ok);
2425 ResourceLoader* loader = GetLoader(filter->child_id(), request_id);
2426 if (!loader || !loader->client())
2427 return false;
2428
2429 DCHECK(!filter_);
2430 filter_ = filter;
2431 bool handled = true;
2432 IPC_BEGIN_MESSAGE_MAP(ResourceDispatcherHostImpl, message)
2433 IPC_MESSAGE_HANDLER(ResourceMsg_ReceivedResponse, OnReceivedResponseForMojo)
2434 IPC_MESSAGE_HANDLER(ResourceMsg_RequestComplete, OnRequestCompleteForMojo)
2435 IPC_MESSAGE_UNHANDLED(handled = false)
2436 IPC_END_MESSAGE_MAP()
2437
2438 filter_ = nullptr;
2439 return handled;
2440 }
2441
2442 void ResourceDispatcherHostImpl::AddUninitiatedURLLoader(
2443 int child_id,
2444 std::unique_ptr<mojom::URLLoader> loader) {
2445 mojom::URLLoader* raw = loader.get();
2446 uninitiated_url_loaders_.insert(
2447 std::make_pair(raw, std::make_pair(child_id, std::move(loader))));
2448 }
2449
2450 std::unique_ptr<mojom::URLLoader>
2451 ResourceDispatcherHostImpl::TakeUninitiatedURLLoader(mojom::URLLoader* loader) {
2452 auto it = uninitiated_url_loaders_.find(loader);
2453 if (it == uninitiated_url_loaders_.end())
2454 return nullptr;
2455 std::unique_ptr<mojom::URLLoader> result = std::move(it->second.second);
2456 uninitiated_url_loaders_.erase(it);
2457 return result;
2458 }
2459
2460 void ResourceDispatcherHostImpl::SetMojoLoaderAndClientrForNextLoadRequest(
2461 std::unique_ptr<mojom::URLLoader> loader,
2462 mojom::URLLoaderClientPtr client) {
2463 mojo_loader_for_next_load_request_ = std::move(loader);
2464 mojo_loader_client_for_next_load_request_ = std::move(client);
2465 }
2466
2352 // static 2467 // static
2353 int ResourceDispatcherHostImpl::CalculateApproximateMemoryCost( 2468 int ResourceDispatcherHostImpl::CalculateApproximateMemoryCost(
2354 net::URLRequest* request) { 2469 net::URLRequest* request) {
2355 // The following fields should be a minor size contribution (experimentally 2470 // The following fields should be a minor size contribution (experimentally
2356 // on the order of 100). However since they are variable length, it could 2471 // on the order of 100). However since they are variable length, it could
2357 // in theory be a sizeable contribution. 2472 // in theory be a sizeable contribution.
2358 int strings_cost = request->extra_request_headers().ToString().size() + 2473 int strings_cost = request->extra_request_headers().ToString().size() +
2359 request->original_url().spec().size() + 2474 request->original_url().spec().size() +
2360 request->referrer().size() + 2475 request->referrer().size() +
2361 request->method().size(); 2476 request->method().size();
2362 2477
2363 // Note that this expression will typically be dominated by: 2478 // Note that this expression will typically be dominated by:
2364 // |kAvgBytesPerOutstandingRequest|. 2479 // |kAvgBytesPerOutstandingRequest|.
2365 return kAvgBytesPerOutstandingRequest + strings_cost; 2480 return kAvgBytesPerOutstandingRequest + strings_cost;
2366 } 2481 }
2367 2482
2368 void ResourceDispatcherHostImpl::BeginRequestInternal( 2483 void ResourceDispatcherHostImpl::BeginRequestInternal(
2369 std::unique_ptr<net::URLRequest> request, 2484 std::unique_ptr<net::URLRequest> request,
2370 std::unique_ptr<ResourceHandler> handler) { 2485 std::unique_ptr<ResourceHandler> handler,
2486 std::unique_ptr<mojom::URLLoader> url_loader,
2487 mojom::URLLoaderClientPtr client) {
2371 DCHECK(!request->is_pending()); 2488 DCHECK(!request->is_pending());
2372 ResourceRequestInfoImpl* info = 2489 ResourceRequestInfoImpl* info =
2373 ResourceRequestInfoImpl::ForRequest(request.get()); 2490 ResourceRequestInfoImpl::ForRequest(request.get());
2374 2491
2375 if ((TimeTicks::Now() - last_user_gesture_time_) < 2492 if ((TimeTicks::Now() - last_user_gesture_time_) <
2376 TimeDelta::FromMilliseconds(kUserGestureWindowMs)) { 2493 TimeDelta::FromMilliseconds(kUserGestureWindowMs)) {
2377 request->SetLoadFlags( 2494 request->SetLoadFlags(
2378 request->load_flags() | net::LOAD_MAYBE_USER_GESTURE); 2495 request->load_flags() | net::LOAD_MAYBE_USER_GESTURE);
2379 } 2496 }
2380 2497
(...skipping 15 matching lines...) Expand all
2396 NOTREACHED(); 2513 NOTREACHED();
2397 } 2514 }
2398 2515
2399 IncrementOutstandingRequestsMemory(-1, *info); 2516 IncrementOutstandingRequestsMemory(-1, *info);
2400 2517
2401 // A ResourceHandler must not outlive its associated URLRequest. 2518 // A ResourceHandler must not outlive its associated URLRequest.
2402 handler.reset(); 2519 handler.reset();
2403 return; 2520 return;
2404 } 2521 }
2405 2522
2406 std::unique_ptr<ResourceLoader> loader(new ResourceLoader( 2523 std::unique_ptr<ResourceLoader> loader(
2407 std::move(request), std::move(handler), GetCertStore(), this)); 2524 new ResourceLoader(std::move(request), std::move(handler), GetCertStore(),
2525 std::move(url_loader), std::move(client), this));
2408 2526
2409 GlobalFrameRoutingId id(info->GetChildID(), info->GetRenderFrameID()); 2527 GlobalFrameRoutingId id(info->GetChildID(), info->GetRenderFrameID());
2410 BlockedLoadersMap::const_iterator iter = blocked_loaders_map_.find(id); 2528 BlockedLoadersMap::const_iterator iter = blocked_loaders_map_.find(id);
2411 if (iter != blocked_loaders_map_.end()) { 2529 if (iter != blocked_loaders_map_.end()) {
2412 // The request should be blocked. 2530 // The request should be blocked.
2413 iter->second->push_back(std::move(loader)); 2531 iter->second->push_back(std::move(loader));
2414 return; 2532 return;
2415 } 2533 }
2416 2534
2417 StartLoading(info, std::move(loader)); 2535 StartLoading(info, std::move(loader));
(...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after
2688 ssl.cert_id = GetCertStore()->StoreCert(ssl_info.cert.get(), child_id); 2806 ssl.cert_id = GetCertStore()->StoreCert(ssl_info.cert.get(), child_id);
2689 response->head.security_info = SerializeSecurityInfo(ssl); 2807 response->head.security_info = SerializeSecurityInfo(ssl);
2690 } 2808 }
2691 2809
2692 CertStore* ResourceDispatcherHostImpl::GetCertStore() { 2810 CertStore* ResourceDispatcherHostImpl::GetCertStore() {
2693 return cert_store_for_testing_ ? cert_store_for_testing_ 2811 return cert_store_for_testing_ ? cert_store_for_testing_
2694 : CertStore::GetInstance(); 2812 : CertStore::GetInstance();
2695 } 2813 }
2696 2814
2697 } // namespace content 2815 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698