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

Side by Side Diff: content/browser/download/download_manager_impl.cc

Issue 2251643003: Remove the BeginSaveFile and BeginDownload methods from ResourceDispatcherHostImpl (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Move the blob code to RDHI::BeginURLRequest Created 4 years, 3 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 #include "content/browser/download/download_manager_impl.h" 5 #include "content/browser/download/download_manager_impl.h"
6 6
7 #include <iterator> 7 #include <iterator>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
11 #include "base/callback.h" 11 #include "base/callback.h"
12 #include "base/debug/alias.h" 12 #include "base/debug/alias.h"
13 #include "base/i18n/case_conversion.h" 13 #include "base/i18n/case_conversion.h"
14 #include "base/logging.h" 14 #include "base/logging.h"
15 #include "base/memory/ptr_util.h" 15 #include "base/memory/ptr_util.h"
16 #include "base/memory/weak_ptr.h" 16 #include "base/memory/weak_ptr.h"
17 #include "base/message_loop/message_loop.h" 17 #include "base/message_loop/message_loop.h"
18 #include "base/stl_util.h" 18 #include "base/stl_util.h"
19 #include "base/strings/stringprintf.h" 19 #include "base/strings/stringprintf.h"
20 #include "base/strings/sys_string_conversions.h" 20 #include "base/strings/sys_string_conversions.h"
21 #include "base/supports_user_data.h" 21 #include "base/supports_user_data.h"
22 #include "base/synchronization/lock.h" 22 #include "base/synchronization/lock.h"
23 #include "build/build_config.h" 23 #include "build/build_config.h"
24 #include "content/browser/byte_stream.h" 24 #include "content/browser/byte_stream.h"
25 #include "content/browser/child_process_security_policy_impl.h"
25 #include "content/browser/download/download_create_info.h" 26 #include "content/browser/download/download_create_info.h"
26 #include "content/browser/download/download_file_factory.h" 27 #include "content/browser/download/download_file_factory.h"
27 #include "content/browser/download/download_item_factory.h" 28 #include "content/browser/download/download_item_factory.h"
28 #include "content/browser/download/download_item_impl.h" 29 #include "content/browser/download/download_item_impl.h"
29 #include "content/browser/download/download_stats.h" 30 #include "content/browser/download/download_stats.h"
30 #include "content/browser/loader/resource_dispatcher_host_impl.h" 31 #include "content/browser/loader/resource_dispatcher_host_impl.h"
32 #include "content/browser/loader/resource_request_info_impl.h"
33 #include "content/browser/loader/throttling_resource_handler.h"
Randy Smith (Not in Mondays) 2016/08/25 20:58:49 Are these still needed?
ananta 2016/08/25 22:20:49 Removed
31 #include "content/browser/renderer_host/render_view_host_impl.h" 34 #include "content/browser/renderer_host/render_view_host_impl.h"
35 #include "content/browser/resource_context_impl.h"
Randy Smith (Not in Mondays) 2016/08/25 20:58:49 I think this could be replaced by a forward decl?
ananta 2016/08/25 22:20:49 Removed
32 #include "content/browser/web_contents/web_contents_impl.h" 36 #include "content/browser/web_contents/web_contents_impl.h"
33 #include "content/public/browser/browser_context.h" 37 #include "content/public/browser/browser_context.h"
34 #include "content/public/browser/content_browser_client.h" 38 #include "content/public/browser/content_browser_client.h"
35 #include "content/public/browser/download_interrupt_reasons.h" 39 #include "content/public/browser/download_interrupt_reasons.h"
36 #include "content/public/browser/download_manager_delegate.h" 40 #include "content/public/browser/download_manager_delegate.h"
37 #include "content/public/browser/download_url_parameters.h" 41 #include "content/public/browser/download_url_parameters.h"
38 #include "content/public/browser/notification_service.h" 42 #include "content/public/browser/notification_service.h"
39 #include "content/public/browser/notification_types.h" 43 #include "content/public/browser/notification_types.h"
40 #include "content/public/browser/render_process_host.h" 44 #include "content/public/browser/render_process_host.h"
41 #include "content/public/browser/resource_context.h" 45 #include "content/public/browser/resource_context.h"
46 #include "content/public/browser/resource_dispatcher_host_delegate.h"
47 #include "content/public/browser/resource_throttle.h"
Randy Smith (Not in Mondays) 2016/08/25 20:58:49 Still needed?
ananta 2016/08/25 22:20:50 Removed
42 #include "content/public/browser/web_contents_delegate.h" 48 #include "content/public/browser/web_contents_delegate.h"
43 #include "content/public/common/referrer.h" 49 #include "content/public/common/referrer.h"
44 #include "net/base/elements_upload_data_stream.h" 50 #include "net/base/elements_upload_data_stream.h"
45 #include "net/base/load_flags.h" 51 #include "net/base/load_flags.h"
46 #include "net/base/request_priority.h" 52 #include "net/base/request_priority.h"
47 #include "net/base/upload_bytes_element_reader.h" 53 #include "net/base/upload_bytes_element_reader.h"
48 #include "net/url_request/url_request_context.h" 54 #include "net/url_request/url_request_context.h"
49 #include "storage/browser/blob/blob_url_request_job_factory.h" 55 #include "storage/browser/blob/blob_url_request_job_factory.h"
50 #include "url/origin.h" 56 #include "url/origin.h"
51 57
(...skipping 14 matching lines...) Expand all
66 if (blob_data_handle) { 72 if (blob_data_handle) {
67 storage::BlobProtocolHandler::SetRequestedBlobDataHandle( 73 storage::BlobProtocolHandler::SetRequestedBlobDataHandle(
68 url_request.get(), std::move(blob_data_handle)); 74 url_request.get(), std::move(blob_data_handle));
69 } 75 }
70 76
71 // If there's a valid renderer process associated with the request, then the 77 // If there's a valid renderer process associated with the request, then the
72 // request should be driven by the ResourceLoader. Pass it over to the 78 // request should be driven by the ResourceLoader. Pass it over to the
73 // ResourceDispatcherHostImpl which will in turn pass it along to the 79 // ResourceDispatcherHostImpl which will in turn pass it along to the
74 // ResourceLoader. 80 // ResourceLoader.
75 if (params->render_process_host_id() >= 0) { 81 if (params->render_process_host_id() >= 0) {
76 DownloadInterruptReason reason = 82 DownloadInterruptReason reason = DownloadManagerImpl::BeginDownloadRequest(
77 ResourceDispatcherHostImpl::Get()->BeginDownload( 83 std::move(url_request), params->referrer(), resource_context,
78 std::move(url_request), params->referrer(), 84 params->content_initiated(), params->render_process_host_id(),
79 params->content_initiated(), resource_context, 85 params->render_view_host_routing_id(),
80 params->render_process_host_id(), 86 params->render_frame_host_routing_id(),
81 params->render_view_host_routing_id(), 87 params->do_not_prompt_for_login());
82 params->render_frame_host_routing_id(),
83 params->do_not_prompt_for_login());
84 88
85 // If the download was accepted, the DownloadResourceHandler is now 89 // If the download was accepted, the DownloadResourceHandler is now
86 // responsible for driving the request to completion. 90 // responsible for driving the request to completion.
87 if (reason == DOWNLOAD_INTERRUPT_REASON_NONE) 91 if (reason == DOWNLOAD_INTERRUPT_REASON_NONE)
88 return nullptr; 92 return nullptr;
89 93
90 // Otherwise, create an interrupted download. 94 // Otherwise, create an interrupted download.
91 std::unique_ptr<DownloadCreateInfo> failed_created_info( 95 std::unique_ptr<DownloadCreateInfo> failed_created_info(
92 new DownloadCreateInfo(base::Time::Now(), net::BoundNetLog(), 96 new DownloadCreateInfo(base::Time::Now(), net::BoundNetLog(),
93 base::WrapUnique(new DownloadSaveInfo))); 97 base::WrapUnique(new DownloadSaveInfo)));
(...skipping 420 matching lines...) Expand 10 before | Expand all | Expand 10 after
514 void DownloadManagerImpl::RemoveUrlDownloader(UrlDownloader* downloader) { 518 void DownloadManagerImpl::RemoveUrlDownloader(UrlDownloader* downloader) {
515 for (auto ptr = url_downloaders_.begin(); ptr != url_downloaders_.end(); 519 for (auto ptr = url_downloaders_.begin(); ptr != url_downloaders_.end();
516 ++ptr) { 520 ++ptr) {
517 if (ptr->get() == downloader) { 521 if (ptr->get() == downloader) {
518 url_downloaders_.erase(ptr); 522 url_downloaders_.erase(ptr);
519 return; 523 return;
520 } 524 }
521 } 525 }
522 } 526 }
523 527
528 // static
529 DownloadInterruptReason DownloadManagerImpl::BeginDownloadRequest(
530 std::unique_ptr<net::URLRequest> url_request,
531 const Referrer& referrer,
532 ResourceContext* resource_context,
533 bool is_content_initiated,
534 int render_process_id,
535 int render_view_route_id,
536 int render_frame_route_id,
537 bool do_not_prompt_for_login) {
538 if (ResourceDispatcherHostImpl::Get()->is_shutdown())
539 return DOWNLOAD_INTERRUPT_REASON_USER_SHUTDOWN;
540
541 // The URLRequest needs to be initialized with the referrer and other
542 // information prior to issuing it.
543 ResourceDispatcherHostImpl::Get()->InitializeURLRequest(
544 url_request.get(), referrer,
545 true, // download.
546 render_process_id, render_view_route_id, render_frame_route_id,
547 resource_context);
548
549 // We treat a download as a main frame load, and thus update the policy URL on
550 // redirects.
551 //
552 // TODO(davidben): Is this correct? If this came from a
553 // ViewHostMsg_DownloadUrl in a frame, should it have first-party URL set
554 // appropriately?
555 url_request->set_first_party_url_policy(
556 net::URLRequest::UPDATE_FIRST_PARTY_URL_ON_REDIRECT);
557
558 const GURL& url = url_request->original_url();
559
560 // Check if the renderer is permitted to request the requested URL.
561 if (!ChildProcessSecurityPolicyImpl::GetInstance()->CanRequestURL(
562 render_process_id, url)) {
563 DVLOG(1) << "Denied unauthorized download request for "
564 << url.possibly_invalid_spec();
565 return DOWNLOAD_INTERRUPT_REASON_NETWORK_INVALID_REQUEST;
566 }
567
568 const net::URLRequestContext* request_context = url_request->context();
569 if (!request_context->job_factory()->IsHandledURL(url)) {
570 DVLOG(1) << "Download request for unsupported protocol: "
571 << url.possibly_invalid_spec();
572 return DOWNLOAD_INTERRUPT_REASON_NETWORK_INVALID_REQUEST;
573 }
mmenke 2016/08/25 21:03:09 Seems like this check should probably also go in R
Randy Smith (Not in Mondays) 2016/08/25 21:17:45 Yes, except that then BeginUrlRequest() would have
ananta 2016/08/25 22:20:50 Will look into this in a followup patch
574
575 // From this point forward, the |DownloadResourceHandler| is responsible for
576 // |started_callback|.
577 // TODO(ananta)
578 // Find a better way to create the DownloadResourceHandler instance.
579 std::unique_ptr<ResourceHandler> handler(
580 DownloadResourceHandler::Create(url_request.get()));
581
582 ResourceDispatcherHostImpl::Get()->BeginURLRequest(
583 std::move(url_request), std::move(handler), true, // download
584 is_content_initiated, do_not_prompt_for_login, resource_context);
585 return DOWNLOAD_INTERRUPT_REASON_NONE;
586 }
587
524 namespace { 588 namespace {
525 589
526 bool EmptyFilter(const GURL& url) { 590 bool EmptyFilter(const GURL& url) {
527 return true; 591 return true;
528 } 592 }
529 593
530 bool RemoveDownloadByURLAndTime( 594 bool RemoveDownloadByURLAndTime(
531 const base::Callback<bool(const GURL&)>& url_filter, 595 const base::Callback<bool(const GURL&)>& url_filter,
532 base::Time remove_begin, 596 base::Time remove_begin,
533 base::Time remove_end, 597 base::Time remove_end,
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
695 if (delegate_) 759 if (delegate_)
696 delegate_->OpenDownload(download); 760 delegate_->OpenDownload(download);
697 } 761 }
698 762
699 void DownloadManagerImpl::ShowDownloadInShell(DownloadItemImpl* download) { 763 void DownloadManagerImpl::ShowDownloadInShell(DownloadItemImpl* download) {
700 if (delegate_) 764 if (delegate_)
701 delegate_->ShowDownloadInShell(download); 765 delegate_->ShowDownloadInShell(download);
702 } 766 }
703 767
704 } // namespace content 768 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698