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/renderer_host/resource_dispatcher_host.h" | 7 #include "content/browser/renderer_host/resource_dispatcher_host.h" |
8 | 8 |
9 #include <set> | 9 #include <set> |
10 #include <vector> | 10 #include <vector> |
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
297 } | 297 } |
298 } | 298 } |
299 | 299 |
300 void OnSwapOutACKHelper(int render_process_id, int render_view_id) { | 300 void OnSwapOutACKHelper(int render_process_id, int render_view_id) { |
301 RenderViewHostImpl* rvh = RenderViewHostImpl::FromID(render_process_id, | 301 RenderViewHostImpl* rvh = RenderViewHostImpl::FromID(render_process_id, |
302 render_view_id); | 302 render_view_id); |
303 if (rvh) | 303 if (rvh) |
304 rvh->OnSwapOutACK(); | 304 rvh->OnSwapOutACK(); |
305 } | 305 } |
306 | 306 |
307 net::Error CallbackAndReturn( | |
308 const DownloadResourceHandler::OnStartedCallback& started_cb, | |
309 net::Error net_error) { | |
310 DCHECK(!started_cb.is_null()); | |
Randy Smith (Not in Mondays)
2012/03/09 19:14:02
Why the DCHECK? This may be a result of my not ye
ahendrickson
2012/03/09 20:50:08
Removed.
| |
311 if (started_cb.is_null()) | |
312 return net_error; | |
313 BrowserThread::PostTask( | |
314 BrowserThread::UI, FROM_HERE, | |
315 base::Bind(started_cb, content::DownloadId::Invalid(), net_error)); | |
316 | |
317 return net_error; | |
318 } | |
319 | |
307 } // namespace | 320 } // namespace |
308 | 321 |
309 ResourceDispatcherHost* ResourceDispatcherHost::Get() { | 322 ResourceDispatcherHost* ResourceDispatcherHost::Get() { |
310 return g_resource_dispatcher_host; | 323 return g_resource_dispatcher_host; |
311 } | 324 } |
312 | 325 |
313 ResourceDispatcherHost::ResourceDispatcherHost() | 326 ResourceDispatcherHost::ResourceDispatcherHost() |
314 : ALLOW_THIS_IN_INITIALIZER_LIST( | 327 : ALLOW_THIS_IN_INITIALIZER_LIST( |
315 download_file_manager_(new DownloadFileManager(this, NULL))), | 328 download_file_manager_(new DownloadFileManager(this, NULL))), |
316 ALLOW_THIS_IN_INITIALIZER_LIST( | 329 ALLOW_THIS_IN_INITIALIZER_LIST( |
(...skipping 600 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
917 // We are explicitly forcing the download of 'url'. | 930 // We are explicitly forcing the download of 'url'. |
918 net::Error ResourceDispatcherHost::BeginDownload( | 931 net::Error ResourceDispatcherHost::BeginDownload( |
919 scoped_ptr<net::URLRequest> request, | 932 scoped_ptr<net::URLRequest> request, |
920 bool prefer_cache, | 933 bool prefer_cache, |
921 const DownloadSaveInfo& save_info, | 934 const DownloadSaveInfo& save_info, |
922 const DownloadResourceHandler::OnStartedCallback& started_cb, | 935 const DownloadResourceHandler::OnStartedCallback& started_cb, |
923 int child_id, | 936 int child_id, |
924 int route_id, | 937 int route_id, |
925 content::ResourceContext* context) { | 938 content::ResourceContext* context) { |
926 if (is_shutdown_) | 939 if (is_shutdown_) |
927 return net::ERR_INSUFFICIENT_RESOURCES; | 940 return CallbackAndReturn(started_cb, net::ERR_INSUFFICIENT_RESOURCES); |
928 | 941 |
929 const GURL& url = request->original_url(); | 942 const GURL& url = request->original_url(); |
930 #if defined(OS_CHROMEOS) | 943 #if defined(OS_CHROMEOS) |
931 // crosbug.com/26646. | 944 // crosbug.com/26646. |
932 VLOG(1) << "BeginDownload: " << request->url().spec(); | 945 VLOG(1) << "BeginDownload: " << request->url().spec(); |
933 #endif | 946 #endif |
934 const net::URLRequestContext* request_context = context->GetRequestContext(); | 947 const net::URLRequestContext* request_context = context->GetRequestContext(); |
935 request->set_referrer(MaybeStripReferrer(GURL(request->referrer())).spec()); | 948 request->set_referrer(MaybeStripReferrer(GURL(request->referrer())).spec()); |
936 request->set_context(request_context); | 949 request->set_context(request_context); |
937 int extra_load_flags = net::LOAD_IS_DOWNLOAD; | 950 int extra_load_flags = net::LOAD_IS_DOWNLOAD; |
938 if (prefer_cache) { | 951 if (prefer_cache) { |
939 // If there is upload data attached, only retrieve from cache because there | 952 // If there is upload data attached, only retrieve from cache because there |
940 // is no current mechanism to prompt the user for their consent for a | 953 // is no current mechanism to prompt the user for their consent for a |
941 // re-post. For GETs, try to retrieve data from the cache and skip | 954 // re-post. For GETs, try to retrieve data from the cache and skip |
942 // validating the entry if present. | 955 // validating the entry if present. |
943 if (request->get_upload() != NULL) | 956 if (request->get_upload() != NULL) |
944 extra_load_flags |= net::LOAD_ONLY_FROM_CACHE; | 957 extra_load_flags |= net::LOAD_ONLY_FROM_CACHE; |
945 else | 958 else |
946 extra_load_flags |= net::LOAD_PREFERRING_CACHE; | 959 extra_load_flags |= net::LOAD_PREFERRING_CACHE; |
947 } else { | 960 } else { |
948 extra_load_flags |= net::LOAD_DISABLE_CACHE; | 961 extra_load_flags |= net::LOAD_DISABLE_CACHE; |
949 } | 962 } |
950 request->set_load_flags(request->load_flags() | extra_load_flags); | 963 request->set_load_flags(request->load_flags() | extra_load_flags); |
951 // Check if the renderer is permitted to request the requested URL. | 964 // Check if the renderer is permitted to request the requested URL. |
952 if (!ChildProcessSecurityPolicyImpl::GetInstance()-> | 965 if (!ChildProcessSecurityPolicyImpl::GetInstance()-> |
953 CanRequestURL(child_id, url)) { | 966 CanRequestURL(child_id, url)) { |
954 VLOG(1) << "Denied unauthorized download request for " | 967 VLOG(1) << "Denied unauthorized download request for " |
955 << url.possibly_invalid_spec(); | 968 << url.possibly_invalid_spec(); |
956 return net::ERR_ACCESS_DENIED; | 969 return CallbackAndReturn(started_cb, net::ERR_ACCESS_DENIED); |
957 } | 970 } |
958 | 971 |
959 request_id_--; | 972 request_id_--; |
960 | 973 |
974 // From this point forward, the |DownloadResourceHandler| is responsible for | |
975 // |started_cb|. | |
961 scoped_refptr<ResourceHandler> handler( | 976 scoped_refptr<ResourceHandler> handler( |
962 CreateResourceHandlerForDownload(request.get(), context, child_id, | 977 CreateResourceHandlerForDownload(request.get(), context, child_id, |
963 route_id, request_id_, save_info, | 978 route_id, request_id_, save_info, |
964 started_cb)); | 979 started_cb)); |
965 | 980 |
966 if (!request_context->job_factory()->IsHandledURL(url)) { | 981 if (!request_context->job_factory()->IsHandledURL(url)) { |
967 VLOG(1) << "Download request for unsupported protocol: " | 982 VLOG(1) << "Download request for unsupported protocol: " |
968 << url.possibly_invalid_spec(); | 983 << url.possibly_invalid_spec(); |
969 return net::ERR_ACCESS_DENIED; | 984 return net::ERR_ACCESS_DENIED; |
970 } | 985 } |
(...skipping 1308 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2279 scoped_refptr<ResourceHandler> transferred_resource_handler( | 2294 scoped_refptr<ResourceHandler> transferred_resource_handler( |
2280 new DoomedResourceHandler(info->resource_handler())); | 2295 new DoomedResourceHandler(info->resource_handler())); |
2281 info->set_resource_handler(transferred_resource_handler.get()); | 2296 info->set_resource_handler(transferred_resource_handler.get()); |
2282 } | 2297 } |
2283 | 2298 |
2284 bool ResourceDispatcherHost::IsTransferredNavigation( | 2299 bool ResourceDispatcherHost::IsTransferredNavigation( |
2285 const content::GlobalRequestID& transferred_request_id) const { | 2300 const content::GlobalRequestID& transferred_request_id) const { |
2286 return transferred_navigations_.find(transferred_request_id) != | 2301 return transferred_navigations_.find(transferred_request_id) != |
2287 transferred_navigations_.end(); | 2302 transferred_navigations_.end(); |
2288 } | 2303 } |
OLD | NEW |