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

Side by Side Diff: content/browser/renderer_host/resource_dispatcher_host.cc

Issue 9570005: Added callback to DownloadUrl() so we can find download failures. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Changes per Randy's comments. Created 8 years, 9 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 | Annotate | Revision Log
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/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
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 if (started_cb.is_null())
311 return net_error;
312 BrowserThread::PostTask(
313 BrowserThread::UI, FROM_HERE,
314 base::Bind(started_cb, content::DownloadId::Invalid(), net_error));
315
316 return net_error;
317 }
318
307 } // namespace 319 } // namespace
308 320
309 ResourceDispatcherHost* ResourceDispatcherHost::Get() { 321 ResourceDispatcherHost* ResourceDispatcherHost::Get() {
310 return g_resource_dispatcher_host; 322 return g_resource_dispatcher_host;
311 } 323 }
312 324
313 ResourceDispatcherHost::ResourceDispatcherHost() 325 ResourceDispatcherHost::ResourceDispatcherHost()
314 : ALLOW_THIS_IN_INITIALIZER_LIST( 326 : ALLOW_THIS_IN_INITIALIZER_LIST(
315 download_file_manager_(new DownloadFileManager(this, NULL))), 327 download_file_manager_(new DownloadFileManager(this, NULL))),
316 ALLOW_THIS_IN_INITIALIZER_LIST( 328 ALLOW_THIS_IN_INITIALIZER_LIST(
(...skipping 600 matching lines...) Expand 10 before | Expand all | Expand 10 after
917 // We are explicitly forcing the download of 'url'. 929 // We are explicitly forcing the download of 'url'.
918 net::Error ResourceDispatcherHost::BeginDownload( 930 net::Error ResourceDispatcherHost::BeginDownload(
919 scoped_ptr<net::URLRequest> request, 931 scoped_ptr<net::URLRequest> request,
920 bool prefer_cache, 932 bool prefer_cache,
921 const DownloadSaveInfo& save_info, 933 const DownloadSaveInfo& save_info,
922 const DownloadResourceHandler::OnStartedCallback& started_cb, 934 const DownloadResourceHandler::OnStartedCallback& started_cb,
923 int child_id, 935 int child_id,
924 int route_id, 936 int route_id,
925 content::ResourceContext* context) { 937 content::ResourceContext* context) {
926 if (is_shutdown_) 938 if (is_shutdown_)
927 return net::ERR_INSUFFICIENT_RESOURCES; 939 return CallbackAndReturn(started_cb, net::ERR_INSUFFICIENT_RESOURCES);
928 940
929 const GURL& url = request->original_url(); 941 const GURL& url = request->original_url();
930 #if defined(OS_CHROMEOS) 942 #if defined(OS_CHROMEOS)
931 // crosbug.com/26646. 943 // crosbug.com/26646.
932 VLOG(1) << "BeginDownload: " << request->url().spec(); 944 VLOG(1) << "BeginDownload: " << request->url().spec();
933 #endif 945 #endif
934 const net::URLRequestContext* request_context = context->GetRequestContext(); 946 const net::URLRequestContext* request_context = context->GetRequestContext();
935 request->set_referrer(MaybeStripReferrer(GURL(request->referrer())).spec()); 947 request->set_referrer(MaybeStripReferrer(GURL(request->referrer())).spec());
936 request->set_context(request_context); 948 request->set_context(request_context);
937 int extra_load_flags = net::LOAD_IS_DOWNLOAD; 949 int extra_load_flags = net::LOAD_IS_DOWNLOAD;
938 if (prefer_cache) { 950 if (prefer_cache) {
939 // If there is upload data attached, only retrieve from cache because there 951 // 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 952 // 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 953 // re-post. For GETs, try to retrieve data from the cache and skip
942 // validating the entry if present. 954 // validating the entry if present.
943 if (request->get_upload() != NULL) 955 if (request->get_upload() != NULL)
944 extra_load_flags |= net::LOAD_ONLY_FROM_CACHE; 956 extra_load_flags |= net::LOAD_ONLY_FROM_CACHE;
945 else 957 else
946 extra_load_flags |= net::LOAD_PREFERRING_CACHE; 958 extra_load_flags |= net::LOAD_PREFERRING_CACHE;
947 } else { 959 } else {
948 extra_load_flags |= net::LOAD_DISABLE_CACHE; 960 extra_load_flags |= net::LOAD_DISABLE_CACHE;
949 } 961 }
950 request->set_load_flags(request->load_flags() | extra_load_flags); 962 request->set_load_flags(request->load_flags() | extra_load_flags);
951 // Check if the renderer is permitted to request the requested URL. 963 // Check if the renderer is permitted to request the requested URL.
952 if (!ChildProcessSecurityPolicyImpl::GetInstance()-> 964 if (!ChildProcessSecurityPolicyImpl::GetInstance()->
953 CanRequestURL(child_id, url)) { 965 CanRequestURL(child_id, url)) {
954 VLOG(1) << "Denied unauthorized download request for " 966 VLOG(1) << "Denied unauthorized download request for "
955 << url.possibly_invalid_spec(); 967 << url.possibly_invalid_spec();
956 return net::ERR_ACCESS_DENIED; 968 return CallbackAndReturn(started_cb, net::ERR_ACCESS_DENIED);
957 } 969 }
958 970
959 request_id_--; 971 request_id_--;
960 972
973 // From this point forward, the |DownloadResourceHandler| is responsible for
974 // |started_cb|.
961 scoped_refptr<ResourceHandler> handler( 975 scoped_refptr<ResourceHandler> handler(
962 CreateResourceHandlerForDownload(request.get(), context, child_id, 976 CreateResourceHandlerForDownload(request.get(), context, child_id,
963 route_id, request_id_, save_info, 977 route_id, request_id_, save_info,
964 started_cb)); 978 started_cb));
965 979
966 if (!request_context->job_factory()->IsHandledURL(url)) { 980 if (!request_context->job_factory()->IsHandledURL(url)) {
967 VLOG(1) << "Download request for unsupported protocol: " 981 VLOG(1) << "Download request for unsupported protocol: "
968 << url.possibly_invalid_spec(); 982 << url.possibly_invalid_spec();
969 return net::ERR_ACCESS_DENIED; 983 return net::ERR_ACCESS_DENIED;
970 } 984 }
(...skipping 1308 matching lines...) Expand 10 before | Expand all | Expand 10 after
2279 scoped_refptr<ResourceHandler> transferred_resource_handler( 2293 scoped_refptr<ResourceHandler> transferred_resource_handler(
2280 new DoomedResourceHandler(info->resource_handler())); 2294 new DoomedResourceHandler(info->resource_handler()));
2281 info->set_resource_handler(transferred_resource_handler.get()); 2295 info->set_resource_handler(transferred_resource_handler.get());
2282 } 2296 }
2283 2297
2284 bool ResourceDispatcherHost::IsTransferredNavigation( 2298 bool ResourceDispatcherHost::IsTransferredNavigation(
2285 const content::GlobalRequestID& transferred_request_id) const { 2299 const content::GlobalRequestID& transferred_request_id) const {
2286 return transferred_navigations_.find(transferred_request_id) != 2300 return transferred_navigations_.find(transferred_request_id) !=
2287 transferred_navigations_.end(); 2301 transferred_navigations_.end();
2288 } 2302 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698