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

Side by Side Diff: content/browser/renderer_host/resource_dispatcher_host_impl.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: Merged with trunk 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_impl.h" 7 #include "content/browser/renderer_host/resource_dispatcher_host_impl.h"
8 8
9 #include <set> 9 #include <set>
10 #include <vector> 10 #include <vector>
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after
288 } 288 }
289 } 289 }
290 290
291 void OnSwapOutACKHelper(int render_process_id, int render_view_id) { 291 void OnSwapOutACKHelper(int render_process_id, int render_view_id) {
292 RenderViewHostImpl* rvh = RenderViewHostImpl::FromID(render_process_id, 292 RenderViewHostImpl* rvh = RenderViewHostImpl::FromID(render_process_id,
293 render_view_id); 293 render_view_id);
294 if (rvh) 294 if (rvh)
295 rvh->OnSwapOutACK(); 295 rvh->OnSwapOutACK();
296 } 296 }
297 297
298 net::Error CallbackAndReturn(
299 const DownloadResourceHandler::OnStartedCallback& started_cb,
300 net::Error net_error) {
301 if (started_cb.is_null())
302 return net_error;
303 BrowserThread::PostTask(
304 BrowserThread::UI, FROM_HERE,
305 base::Bind(started_cb, content::DownloadId::Invalid(), net_error));
306
307 return net_error;
308 }
309
298 } // namespace 310 } // namespace
299 311
300 // static 312 // static
301 ResourceDispatcherHost* ResourceDispatcherHost::Get() { 313 ResourceDispatcherHost* ResourceDispatcherHost::Get() {
302 return g_resource_dispatcher_host; 314 return g_resource_dispatcher_host;
303 } 315 }
304 316
305 ResourceDispatcherHostImpl::ResourceDispatcherHostImpl() 317 ResourceDispatcherHostImpl::ResourceDispatcherHostImpl()
306 : download_file_manager_(new DownloadFileManager(NULL)), 318 : download_file_manager_(new DownloadFileManager(NULL)),
307 save_file_manager_(new SaveFileManager()), 319 save_file_manager_(new SaveFileManager()),
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
445 457
446 net::Error ResourceDispatcherHostImpl::BeginDownload( 458 net::Error ResourceDispatcherHostImpl::BeginDownload(
447 scoped_ptr<net::URLRequest> request, 459 scoped_ptr<net::URLRequest> request,
448 ResourceContext* context, 460 ResourceContext* context,
449 int child_id, 461 int child_id,
450 int route_id, 462 int route_id,
451 bool prefer_cache, 463 bool prefer_cache,
452 const DownloadSaveInfo& save_info, 464 const DownloadSaveInfo& save_info,
453 const DownloadStartedCallback& started_callback) { 465 const DownloadStartedCallback& started_callback) {
454 if (is_shutdown_) 466 if (is_shutdown_)
455 return net::ERR_INSUFFICIENT_RESOURCES; 467 return CallbackAndReturn(started_callback, net::ERR_INSUFFICIENT_RESOURCES);
456 468
457 const GURL& url = request->original_url(); 469 const GURL& url = request->original_url();
458 #if defined(OS_CHROMEOS) 470 #if defined(OS_CHROMEOS)
459 // crosbug.com/26646. 471 // crosbug.com/26646.
460 VLOG(1) << "BeginDownload: " << request->url().spec(); 472 VLOG(1) << "BeginDownload: " << request->url().spec();
461 #endif 473 #endif
462 const net::URLRequestContext* request_context = context->GetRequestContext(); 474 const net::URLRequestContext* request_context = context->GetRequestContext();
463 request->set_referrer(MaybeStripReferrer(GURL(request->referrer())).spec()); 475 request->set_referrer(MaybeStripReferrer(GURL(request->referrer())).spec());
464 request->set_context(request_context); 476 request->set_context(request_context);
465 int extra_load_flags = net::LOAD_IS_DOWNLOAD; 477 int extra_load_flags = net::LOAD_IS_DOWNLOAD;
466 if (prefer_cache) { 478 if (prefer_cache) {
467 // If there is upload data attached, only retrieve from cache because there 479 // If there is upload data attached, only retrieve from cache because there
468 // is no current mechanism to prompt the user for their consent for a 480 // is no current mechanism to prompt the user for their consent for a
469 // re-post. For GETs, try to retrieve data from the cache and skip 481 // re-post. For GETs, try to retrieve data from the cache and skip
470 // validating the entry if present. 482 // validating the entry if present.
471 if (request->get_upload() != NULL) 483 if (request->get_upload() != NULL)
472 extra_load_flags |= net::LOAD_ONLY_FROM_CACHE; 484 extra_load_flags |= net::LOAD_ONLY_FROM_CACHE;
473 else 485 else
474 extra_load_flags |= net::LOAD_PREFERRING_CACHE; 486 extra_load_flags |= net::LOAD_PREFERRING_CACHE;
475 } else { 487 } else {
476 extra_load_flags |= net::LOAD_DISABLE_CACHE; 488 extra_load_flags |= net::LOAD_DISABLE_CACHE;
477 } 489 }
478 request->set_load_flags(request->load_flags() | extra_load_flags); 490 request->set_load_flags(request->load_flags() | extra_load_flags);
479 // Check if the renderer is permitted to request the requested URL. 491 // Check if the renderer is permitted to request the requested URL.
480 if (!ChildProcessSecurityPolicyImpl::GetInstance()-> 492 if (!ChildProcessSecurityPolicyImpl::GetInstance()->
481 CanRequestURL(child_id, url)) { 493 CanRequestURL(child_id, url)) {
482 VLOG(1) << "Denied unauthorized download request for " 494 VLOG(1) << "Denied unauthorized download request for "
483 << url.possibly_invalid_spec(); 495 << url.possibly_invalid_spec();
484 return net::ERR_ACCESS_DENIED; 496 return CallbackAndReturn(started_callback, net::ERR_ACCESS_DENIED);
485 } 497 }
486 498
487 request_id_--; 499 request_id_--;
488 500
501 // From this point forward, the |DownloadResourceHandler| is responsible for
502 // |started_callback|.
489 scoped_refptr<ResourceHandler> handler( 503 scoped_refptr<ResourceHandler> handler(
490 CreateResourceHandlerForDownload(request.get(), context, child_id, 504 CreateResourceHandlerForDownload(request.get(), context, child_id,
491 route_id, request_id_, save_info, 505 route_id, request_id_, save_info,
492 started_callback)); 506 started_callback));
493 507
494 if (!request_context->job_factory()->IsHandledURL(url)) { 508 if (!request_context->job_factory()->IsHandledURL(url)) {
495 VLOG(1) << "Download request for unsupported protocol: " 509 VLOG(1) << "Download request for unsupported protocol: "
496 << url.possibly_invalid_spec(); 510 << url.possibly_invalid_spec();
497 return net::ERR_ACCESS_DENIED; 511 return net::ERR_ACCESS_DENIED;
498 } 512 }
(...skipping 1741 matching lines...) Expand 10 before | Expand all | Expand 10 after
2240 return allow_cross_origin_auth_prompt_; 2254 return allow_cross_origin_auth_prompt_;
2241 } 2255 }
2242 2256
2243 bool ResourceDispatcherHostImpl::IsTransferredNavigation( 2257 bool ResourceDispatcherHostImpl::IsTransferredNavigation(
2244 const GlobalRequestID& transferred_request_id) const { 2258 const GlobalRequestID& transferred_request_id) const {
2245 return transferred_navigations_.find(transferred_request_id) != 2259 return transferred_navigations_.find(transferred_request_id) !=
2246 transferred_navigations_.end(); 2260 transferred_navigations_.end();
2247 } 2261 }
2248 2262
2249 } // namespace content 2263 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/download/drag_download_file.cc ('k') | content/browser/tab_contents/tab_contents.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698