Chromium Code Reviews| 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 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 294 } | 294 } |
| 295 } | 295 } |
| 296 | 296 |
| 297 void OnSwapOutACKHelper(int render_process_id, int render_view_id) { | 297 void OnSwapOutACKHelper(int render_process_id, int render_view_id) { |
| 298 RenderViewHostImpl* rvh = RenderViewHostImpl::FromID(render_process_id, | 298 RenderViewHostImpl* rvh = RenderViewHostImpl::FromID(render_process_id, |
| 299 render_view_id); | 299 render_view_id); |
| 300 if (rvh) | 300 if (rvh) |
| 301 rvh->OnSwapOutACK(); | 301 rvh->OnSwapOutACK(); |
| 302 } | 302 } |
| 303 | 303 |
| 304 void CallbackOnUIThread( | |
| 305 const DownloadResourceHandler::OnStartedCallback& started_cb, | |
| 306 net::Error net_error) { | |
| 307 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 308 | |
| 309 started_cb.Run(content::DownloadId::Invalid(), net_error); | |
| 310 } | |
| 311 | |
| 312 net::Error CallbackAndReturn( | |
| 313 const DownloadResourceHandler::OnStartedCallback& started_cb, | |
| 314 net::Error net_error) { | |
| 315 BrowserThread::PostTask( | |
|
cbentzel
2012/03/08 17:58:48
Skip this if started_cb.is_null()?
ahendrickson
2012/03/08 21:33:07
Done.
| |
| 316 BrowserThread::UI, FROM_HERE, | |
| 317 base::Bind(&CallbackOnUIThread, started_cb, net_error)); | |
|
Randy Smith (Not in Mondays)
2012/03/07 21:16:57
Can you just bind started_cb to content::DownloadI
ahendrickson
2012/03/08 21:33:07
Done.
| |
| 318 | |
| 319 return net_error; | |
| 320 } | |
| 321 | |
| 304 } // namespace | 322 } // namespace |
| 305 | 323 |
| 306 ResourceDispatcherHost* ResourceDispatcherHost::Get() { | 324 ResourceDispatcherHost* ResourceDispatcherHost::Get() { |
| 307 return g_resource_dispatcher_host; | 325 return g_resource_dispatcher_host; |
| 308 } | 326 } |
| 309 | 327 |
| 310 ResourceDispatcherHost::ResourceDispatcherHost() | 328 ResourceDispatcherHost::ResourceDispatcherHost() |
| 311 : ALLOW_THIS_IN_INITIALIZER_LIST( | 329 : ALLOW_THIS_IN_INITIALIZER_LIST( |
| 312 download_file_manager_(new DownloadFileManager(this, NULL))), | 330 download_file_manager_(new DownloadFileManager(this, NULL))), |
| 313 ALLOW_THIS_IN_INITIALIZER_LIST( | 331 ALLOW_THIS_IN_INITIALIZER_LIST( |
| (...skipping 595 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 909 // We are explicitly forcing the download of 'url'. | 927 // We are explicitly forcing the download of 'url'. |
| 910 net::Error ResourceDispatcherHost::BeginDownload( | 928 net::Error ResourceDispatcherHost::BeginDownload( |
| 911 scoped_ptr<net::URLRequest> request, | 929 scoped_ptr<net::URLRequest> request, |
| 912 bool prefer_cache, | 930 bool prefer_cache, |
| 913 const DownloadSaveInfo& save_info, | 931 const DownloadSaveInfo& save_info, |
| 914 const DownloadResourceHandler::OnStartedCallback& started_cb, | 932 const DownloadResourceHandler::OnStartedCallback& started_cb, |
| 915 int child_id, | 933 int child_id, |
| 916 int route_id, | 934 int route_id, |
| 917 content::ResourceContext* context) { | 935 content::ResourceContext* context) { |
| 918 if (is_shutdown_) | 936 if (is_shutdown_) |
| 919 return net::ERR_INSUFFICIENT_RESOURCES; | 937 return CallbackAndReturn(started_cb, net::ERR_INSUFFICIENT_RESOURCES); |
| 920 | 938 |
| 921 const GURL& url = request->original_url(); | 939 const GURL& url = request->original_url(); |
| 922 const net::URLRequestContext* request_context = context->GetRequestContext(); | 940 const net::URLRequestContext* request_context = context->GetRequestContext(); |
| 923 request->set_referrer(MaybeStripReferrer(GURL(request->referrer())).spec()); | 941 request->set_referrer(MaybeStripReferrer(GURL(request->referrer())).spec()); |
| 924 request->set_context(request_context); | 942 request->set_context(request_context); |
| 925 int extra_load_flags = net::LOAD_IS_DOWNLOAD; | 943 int extra_load_flags = net::LOAD_IS_DOWNLOAD; |
| 926 if (prefer_cache) { | 944 if (prefer_cache) { |
| 927 // If there is upload data attached, only retrieve from cache because there | 945 // If there is upload data attached, only retrieve from cache because there |
| 928 // is no current mechanism to prompt the user for their consent for a | 946 // is no current mechanism to prompt the user for their consent for a |
| 929 // re-post. For GETs, try to retrieve data from the cache and skip | 947 // re-post. For GETs, try to retrieve data from the cache and skip |
| 930 // validating the entry if present. | 948 // validating the entry if present. |
| 931 if (request->get_upload() != NULL) | 949 if (request->get_upload() != NULL) |
| 932 extra_load_flags |= net::LOAD_ONLY_FROM_CACHE; | 950 extra_load_flags |= net::LOAD_ONLY_FROM_CACHE; |
| 933 else | 951 else |
| 934 extra_load_flags |= net::LOAD_PREFERRING_CACHE; | 952 extra_load_flags |= net::LOAD_PREFERRING_CACHE; |
| 935 } else { | 953 } else { |
| 936 extra_load_flags |= net::LOAD_DISABLE_CACHE; | 954 extra_load_flags |= net::LOAD_DISABLE_CACHE; |
| 937 } | 955 } |
| 938 request->set_load_flags(request->load_flags() | extra_load_flags); | 956 request->set_load_flags(request->load_flags() | extra_load_flags); |
| 939 // Check if the renderer is permitted to request the requested URL. | 957 // Check if the renderer is permitted to request the requested URL. |
| 940 if (!ChildProcessSecurityPolicyImpl::GetInstance()-> | 958 if (!ChildProcessSecurityPolicyImpl::GetInstance()-> |
| 941 CanRequestURL(child_id, url)) { | 959 CanRequestURL(child_id, url)) { |
| 942 VLOG(1) << "Denied unauthorized download request for " | 960 VLOG(1) << "Denied unauthorized download request for " |
| 943 << url.possibly_invalid_spec(); | 961 << url.possibly_invalid_spec(); |
| 944 return net::ERR_ACCESS_DENIED; | 962 return CallbackAndReturn(started_cb, net::ERR_ACCESS_DENIED); |
| 945 } | 963 } |
| 946 | 964 |
| 947 request_id_--; | 965 request_id_--; |
| 948 | 966 |
| 949 scoped_refptr<ResourceHandler> handler( | 967 scoped_refptr<ResourceHandler> handler( |
| 950 CreateResourceHandlerForDownload(request.get(), context, child_id, | 968 CreateResourceHandlerForDownload(request.get(), context, child_id, |
| 951 route_id, request_id_, save_info, | 969 route_id, request_id_, save_info, |
| 952 started_cb)); | 970 started_cb)); |
| 953 | 971 |
| 954 if (!request_context->job_factory()->IsHandledURL(url)) { | 972 if (!request_context->job_factory()->IsHandledURL(url)) { |
| 955 VLOG(1) << "Download request for unsupported protocol: " | 973 VLOG(1) << "Download request for unsupported protocol: " |
| 956 << url.possibly_invalid_spec(); | 974 << url.possibly_invalid_spec(); |
| 957 return net::ERR_ACCESS_DENIED; | 975 return CallbackAndReturn(started_cb, net::ERR_ACCESS_DENIED); |
|
Randy Smith (Not in Mondays)
2012/03/07 21:16:57
Since you've already created the resource handler
ahendrickson
2012/03/08 21:33:07
Done.
| |
| 958 } | 976 } |
| 959 | 977 |
| 960 ResourceDispatcherHostRequestInfo* extra_info = | 978 ResourceDispatcherHostRequestInfo* extra_info = |
| 961 CreateRequestInfo(handler, child_id, route_id, true, context); | 979 CreateRequestInfo(handler, child_id, route_id, true, context); |
| 962 SetRequestInfo(request.get(), extra_info); // Request takes ownership. | 980 SetRequestInfo(request.get(), extra_info); // Request takes ownership. |
| 963 | 981 |
| 964 BeginRequestInternal(request.release()); | 982 BeginRequestInternal(request.release()); |
| 965 | 983 |
| 966 return net::OK; | 984 return net::OK; |
| 967 } | 985 } |
| (...skipping 1315 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2283 scoped_refptr<ResourceHandler> transferred_resource_handler( | 2301 scoped_refptr<ResourceHandler> transferred_resource_handler( |
| 2284 new DoomedResourceHandler(info->resource_handler())); | 2302 new DoomedResourceHandler(info->resource_handler())); |
| 2285 info->set_resource_handler(transferred_resource_handler.get()); | 2303 info->set_resource_handler(transferred_resource_handler.get()); |
| 2286 } | 2304 } |
| 2287 | 2305 |
| 2288 bool ResourceDispatcherHost::IsTransferredNavigation( | 2306 bool ResourceDispatcherHost::IsTransferredNavigation( |
| 2289 const content::GlobalRequestID& transferred_request_id) const { | 2307 const content::GlobalRequestID& transferred_request_id) const { |
| 2290 return transferred_navigations_.find(transferred_request_id) != | 2308 return transferred_navigations_.find(transferred_request_id) != |
| 2291 transferred_navigations_.end(); | 2309 transferred_navigations_.end(); |
| 2292 } | 2310 } |
| OLD | NEW |