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

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

Issue 1418663010: Adding WebContent-free Download (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Cleaning up headers. Created 5 years, 1 month 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 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/callback.h" 10 #include "base/callback.h"
11 #include "base/debug/alias.h" 11 #include "base/debug/alias.h"
12 #include "base/i18n/case_conversion.h" 12 #include "base/i18n/case_conversion.h"
13 #include "base/logging.h" 13 #include "base/logging.h"
14 #include "base/message_loop/message_loop.h" 14 #include "base/message_loop/message_loop.h"
15 #include "base/stl_util.h" 15 #include "base/stl_util.h"
16 #include "base/strings/stringprintf.h" 16 #include "base/strings/stringprintf.h"
17 #include "base/strings/sys_string_conversions.h" 17 #include "base/strings/sys_string_conversions.h"
18 #include "base/supports_user_data.h" 18 #include "base/supports_user_data.h"
19 #include "base/synchronization/lock.h" 19 #include "base/synchronization/lock.h"
20 #include "build/build_config.h" 20 #include "build/build_config.h"
21 #include "content/browser/byte_stream.h" 21 #include "content/browser/byte_stream.h"
22 #include "content/browser/download/download_create_info.h" 22 #include "content/browser/download/download_create_info.h"
23 #include "content/browser/download/download_file_factory.h" 23 #include "content/browser/download/download_file_factory.h"
24 #include "content/browser/download/download_item_factory.h" 24 #include "content/browser/download/download_item_factory.h"
25 #include "content/browser/download/download_item_impl.h" 25 #include "content/browser/download/download_item_impl.h"
26 #include "content/browser/download/download_stats.h" 26 #include "content/browser/download/download_stats.h"
27 #include "content/browser/download/url_downloader.h"
27 #include "content/browser/loader/resource_dispatcher_host_impl.h" 28 #include "content/browser/loader/resource_dispatcher_host_impl.h"
28 #include "content/browser/renderer_host/render_view_host_impl.h" 29 #include "content/browser/renderer_host/render_view_host_impl.h"
29 #include "content/browser/web_contents/web_contents_impl.h" 30 #include "content/browser/web_contents/web_contents_impl.h"
30 #include "content/public/browser/browser_context.h" 31 #include "content/public/browser/browser_context.h"
31 #include "content/public/browser/browser_thread.h" 32 #include "content/public/browser/browser_thread.h"
32 #include "content/public/browser/content_browser_client.h" 33 #include "content/public/browser/content_browser_client.h"
33 #include "content/public/browser/download_interrupt_reasons.h" 34 #include "content/public/browser/download_interrupt_reasons.h"
34 #include "content/public/browser/download_manager_delegate.h" 35 #include "content/public/browser/download_manager_delegate.h"
35 #include "content/public/browser/download_url_parameters.h" 36 #include "content/public/browser/download_url_parameters.h"
36 #include "content/public/browser/notification_service.h" 37 #include "content/public/browser/notification_service.h"
37 #include "content/public/browser/notification_types.h" 38 #include "content/public/browser/notification_types.h"
38 #include "content/public/browser/render_process_host.h" 39 #include "content/public/browser/render_process_host.h"
39 #include "content/public/browser/resource_context.h" 40 #include "content/public/browser/resource_context.h"
40 #include "content/public/browser/web_contents_delegate.h" 41 #include "content/public/browser/web_contents_delegate.h"
41 #include "content/public/common/referrer.h" 42 #include "content/public/common/referrer.h"
42 #include "net/base/elements_upload_data_stream.h" 43 #include "net/base/elements_upload_data_stream.h"
43 #include "net/base/load_flags.h" 44 #include "net/base/load_flags.h"
44 #include "net/base/request_priority.h" 45 #include "net/base/request_priority.h"
45 #include "net/base/upload_bytes_element_reader.h" 46 #include "net/base/upload_bytes_element_reader.h"
46 #include "net/url_request/url_request_context.h" 47 #include "net/url_request/url_request_context.h"
47 #include "url/origin.h" 48 #include "url/origin.h"
48 49
49 namespace content { 50 namespace content {
50 namespace { 51 namespace {
51 52
52 void BeginDownload(scoped_ptr<DownloadUrlParameters> params, 53 void BeginDownload(scoped_ptr<DownloadUrlParameters> params,
53 uint32 download_id) { 54 uint32 download_id,
55 bool has_web_contents,
56 DownloadManager* download_manager) {
asanka 2015/11/20 19:57:46 Since this is in the download guts, you can use Do
svaldez 2015/11/23 15:18:56 Done.
54 DCHECK_CURRENTLY_ON(BrowserThread::IO); 57 DCHECK_CURRENTLY_ON(BrowserThread::IO);
55 // ResourceDispatcherHost{Base} is-not-a URLRequest::Delegate, and 58 // ResourceDispatcherHost{Base} is-not-a URLRequest::Delegate, and
56 // DownloadUrlParameters can-not include resource_dispatcher_host_impl.h, so 59 // DownloadUrlParameters can-not include resource_dispatcher_host_impl.h, so
57 // we must down cast. RDHI is the only subclass of RDH as of 2012 May 4. 60 // we must down cast. RDHI is the only subclass of RDH as of 2012 May 4.
58 scoped_ptr<net::URLRequest> request( 61 scoped_ptr<net::URLRequest> request(
59 params->resource_context()->GetRequestContext()->CreateRequest( 62 params->resource_context()->GetRequestContext()->CreateRequest(
60 params->url(), net::DEFAULT_PRIORITY, NULL)); 63 params->url(), net::DEFAULT_PRIORITY, NULL));
61 request->set_method(params->method()); 64 request->set_method(params->method());
62 if (!params->post_body().empty()) { 65 if (!params->post_body().empty()) {
63 const std::string& body = params->post_body(); 66 const std::string& body = params->post_body();
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 } 117 }
115 118
116 scoped_ptr<DownloadSaveInfo> save_info(new DownloadSaveInfo()); 119 scoped_ptr<DownloadSaveInfo> save_info(new DownloadSaveInfo());
117 save_info->file_path = params->file_path(); 120 save_info->file_path = params->file_path();
118 save_info->suggested_name = params->suggested_name(); 121 save_info->suggested_name = params->suggested_name();
119 save_info->offset = params->offset(); 122 save_info->offset = params->offset();
120 save_info->hash_state = params->hash_state(); 123 save_info->hash_state = params->hash_state();
121 save_info->prompt_for_save_location = params->prompt(); 124 save_info->prompt_for_save_location = params->prompt();
122 save_info->file = params->GetFile(); 125 save_info->file = params->GetFile();
123 126
124 ResourceDispatcherHost::Get()->BeginDownload( 127 if (has_web_contents) {
asanka 2015/11/20 19:57:46 Rather than passing around this boolean, you can c
svaldez 2015/11/23 15:18:56 Done.
125 request.Pass(), 128 ResourceDispatcherHost::Get()->BeginDownload(
126 params->referrer(), 129 request.Pass(), params->referrer(), params->content_initiated(),
127 params->content_initiated(), 130 params->resource_context(), params->render_process_host_id(),
128 params->resource_context(), 131 params->render_view_host_routing_id(),
129 params->render_process_host_id(), 132 params->render_frame_host_routing_id(), params->prefer_cache(),
130 params->render_view_host_routing_id(), 133 params->do_not_prompt_for_login(), save_info.Pass(), download_id,
131 params->render_frame_host_routing_id(), 134 params->callback());
132 params->prefer_cache(), 135 } else {
133 params->do_not_prompt_for_login(), 136 UrlDownloader::BeginDownload(
134 save_info.Pass(), 137 download_manager, request.Pass(), params->referrer(),
135 download_id, 138 params->content_initiated(), params->resource_context(),
asanka 2015/11/20 19:57:46 For this case, content_initiated should always be
svaldez 2015/11/23 15:18:56 Done.
136 params->callback()); 139 params->prefer_cache(), params->do_not_prompt_for_login(),
140 save_info.Pass(), download_id, params->callback());
141 }
137 } 142 }
138 143
139 class MapValueIteratorAdapter { 144 class MapValueIteratorAdapter {
140 public: 145 public:
141 explicit MapValueIteratorAdapter( 146 explicit MapValueIteratorAdapter(
142 base::hash_map<int64, DownloadItem*>::const_iterator iter) 147 base::hash_map<int64, DownloadItem*>::const_iterator iter)
143 : iter_(iter) { 148 : iter_(iter) {
144 } 149 }
145 ~MapValueIteratorAdapter() {} 150 ~MapValueIteratorAdapter() {}
146 151
(...skipping 383 matching lines...) Expand 10 before | Expand all | Expand 10 after
530 OnSavePackageSuccessfullyFinished(this, download_item)); 535 OnSavePackageSuccessfullyFinished(this, download_item));
531 } 536 }
532 537
533 // Resume a download of a specific URL. We send the request to the 538 // Resume a download of a specific URL. We send the request to the
534 // ResourceDispatcherHost, and let it send us responses like a regular 539 // ResourceDispatcherHost, and let it send us responses like a regular
535 // download. 540 // download.
536 void DownloadManagerImpl::ResumeInterruptedDownload( 541 void DownloadManagerImpl::ResumeInterruptedDownload(
537 scoped_ptr<content::DownloadUrlParameters> params, 542 scoped_ptr<content::DownloadUrlParameters> params,
538 uint32 id) { 543 uint32 id) {
539 RecordDownloadSource(INITIATED_BY_RESUMPTION); 544 RecordDownloadSource(INITIATED_BY_RESUMPTION);
540 BrowserThread::PostTask( 545 bool has_web_contents = params->render_process_host_id() != -1;
541 BrowserThread::IO, 546 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
542 FROM_HERE, 547 base::Bind(&BeginDownload, base::Passed(&params), id,
543 base::Bind(&BeginDownload, base::Passed(&params), id)); 548 has_web_contents, base::Unretained(this)));
544 } 549 }
545 550
546 void DownloadManagerImpl::SetDownloadItemFactoryForTesting( 551 void DownloadManagerImpl::SetDownloadItemFactoryForTesting(
547 scoped_ptr<DownloadItemFactory> item_factory) { 552 scoped_ptr<DownloadItemFactory> item_factory) {
548 item_factory_ = item_factory.Pass(); 553 item_factory_ = item_factory.Pass();
549 } 554 }
550 555
551 void DownloadManagerImpl::SetDownloadFileFactoryForTesting( 556 void DownloadManagerImpl::SetDownloadFileFactoryForTesting(
552 scoped_ptr<DownloadFileFactory> file_factory) { 557 scoped_ptr<DownloadFileFactory> file_factory) {
553 file_factory_ = file_factory.Pass(); 558 file_factory_ = file_factory.Pass();
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
630 return num_deleted; 635 return num_deleted;
631 } 636 }
632 637
633 void DownloadManagerImpl::DownloadUrl( 638 void DownloadManagerImpl::DownloadUrl(
634 scoped_ptr<DownloadUrlParameters> params) { 639 scoped_ptr<DownloadUrlParameters> params) {
635 if (params->post_id() >= 0) { 640 if (params->post_id() >= 0) {
636 // Check this here so that the traceback is more useful. 641 // Check this here so that the traceback is more useful.
637 DCHECK(params->prefer_cache()); 642 DCHECK(params->prefer_cache());
638 DCHECK_EQ("POST", params->method()); 643 DCHECK_EQ("POST", params->method());
639 } 644 }
640 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, base::Bind( 645 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
641 &BeginDownload, base::Passed(&params), 646 base::Bind(&BeginDownload, base::Passed(&params),
642 content::DownloadItem::kInvalidId)); 647 content::DownloadItem::kInvalidId, true,
648 base::Unretained(this)));
643 } 649 }
644 650
645 void DownloadManagerImpl::AddObserver(Observer* observer) { 651 void DownloadManagerImpl::AddObserver(Observer* observer) {
646 observers_.AddObserver(observer); 652 observers_.AddObserver(observer);
647 } 653 }
648 654
649 void DownloadManagerImpl::RemoveObserver(Observer* observer) { 655 void DownloadManagerImpl::RemoveObserver(Observer* observer) {
650 observers_.RemoveObserver(observer); 656 observers_.RemoveObserver(observer);
651 } 657 }
652 658
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
749 if (delegate_) 755 if (delegate_)
750 delegate_->OpenDownload(download); 756 delegate_->OpenDownload(download);
751 } 757 }
752 758
753 void DownloadManagerImpl::ShowDownloadInShell(DownloadItemImpl* download) { 759 void DownloadManagerImpl::ShowDownloadInShell(DownloadItemImpl* download) {
754 if (delegate_) 760 if (delegate_)
755 delegate_->ShowDownloadInShell(download); 761 delegate_->ShowDownloadInShell(download);
756 } 762 }
757 763
758 } // namespace content 764 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698