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 #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" |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 #include "net/base/upload_bytes_element_reader.h" | 47 #include "net/base/upload_bytes_element_reader.h" |
48 #include "net/url_request/url_request_context.h" | 48 #include "net/url_request/url_request_context.h" |
49 #include "storage/browser/blob/blob_url_request_job_factory.h" | 49 #include "storage/browser/blob/blob_url_request_job_factory.h" |
50 #include "url/origin.h" | 50 #include "url/origin.h" |
51 | 51 |
52 namespace content { | 52 namespace content { |
53 namespace { | 53 namespace { |
54 | 54 |
55 std::unique_ptr<UrlDownloader, BrowserThread::DeleteOnIOThread> BeginDownload( | 55 std::unique_ptr<UrlDownloader, BrowserThread::DeleteOnIOThread> BeginDownload( |
56 std::unique_ptr<DownloadUrlParameters> params, | 56 std::unique_ptr<DownloadUrlParameters> params, |
| 57 content::ResourceContext* resource_context, |
57 uint32_t download_id, | 58 uint32_t download_id, |
58 base::WeakPtr<DownloadManagerImpl> download_manager) { | 59 base::WeakPtr<DownloadManagerImpl> download_manager) { |
59 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 60 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
60 | 61 |
61 std::unique_ptr<net::URLRequest> url_request = | 62 std::unique_ptr<net::URLRequest> url_request = |
62 DownloadRequestCore::CreateRequestOnIOThread(download_id, params.get()); | 63 DownloadRequestCore::CreateRequestOnIOThread(download_id, params.get()); |
63 std::unique_ptr<storage::BlobDataHandle> blob_data_handle = | 64 std::unique_ptr<storage::BlobDataHandle> blob_data_handle = |
64 params->GetBlobDataHandle(); | 65 params->GetBlobDataHandle(); |
65 if (blob_data_handle) { | 66 if (blob_data_handle) { |
66 storage::BlobProtocolHandler::SetRequestedBlobDataHandle( | 67 storage::BlobProtocolHandler::SetRequestedBlobDataHandle( |
67 url_request.get(), std::move(blob_data_handle)); | 68 url_request.get(), std::move(blob_data_handle)); |
68 } | 69 } |
69 | 70 |
70 // If there's a valid renderer process associated with the request, then the | 71 // If there's a valid renderer process associated with the request, then the |
71 // request should be driven by the ResourceLoader. Pass it over to the | 72 // request should be driven by the ResourceLoader. Pass it over to the |
72 // ResourceDispatcherHostImpl which will in turn pass it along to the | 73 // ResourceDispatcherHostImpl which will in turn pass it along to the |
73 // ResourceLoader. | 74 // ResourceLoader. |
74 if (params->render_process_host_id() != -1) { | 75 if (params->render_process_host_id() >= 0) { |
75 DownloadInterruptReason reason = | 76 DownloadInterruptReason reason = |
76 ResourceDispatcherHostImpl::Get()->BeginDownload( | 77 ResourceDispatcherHostImpl::Get()->BeginDownload( |
77 std::move(url_request), params->referrer(), | 78 std::move(url_request), params->referrer(), |
78 params->content_initiated(), params->resource_context(), | 79 params->content_initiated(), resource_context, |
79 params->render_process_host_id(), | 80 params->render_process_host_id(), |
80 params->render_view_host_routing_id(), | 81 params->render_view_host_routing_id(), |
81 params->render_frame_host_routing_id(), | 82 params->render_frame_host_routing_id(), |
82 params->do_not_prompt_for_login()); | 83 params->do_not_prompt_for_login()); |
83 | 84 |
84 // If the download was accepted, the DownloadResourceHandler is now | 85 // If the download was accepted, the DownloadResourceHandler is now |
85 // responsible for driving the request to completion. | 86 // responsible for driving the request to completion. |
86 if (reason == DOWNLOAD_INTERRUPT_REASON_NONE) | 87 if (reason == DOWNLOAD_INTERRUPT_REASON_NONE) |
87 return nullptr; | 88 return nullptr; |
88 | 89 |
(...skipping 24 matching lines...) Expand all Loading... |
113 ~DownloadItemFactoryImpl() override {} | 114 ~DownloadItemFactoryImpl() override {} |
114 | 115 |
115 DownloadItemImpl* CreatePersistedItem( | 116 DownloadItemImpl* CreatePersistedItem( |
116 DownloadItemImplDelegate* delegate, | 117 DownloadItemImplDelegate* delegate, |
117 const std::string& guid, | 118 const std::string& guid, |
118 uint32_t download_id, | 119 uint32_t download_id, |
119 const base::FilePath& current_path, | 120 const base::FilePath& current_path, |
120 const base::FilePath& target_path, | 121 const base::FilePath& target_path, |
121 const std::vector<GURL>& url_chain, | 122 const std::vector<GURL>& url_chain, |
122 const GURL& referrer_url, | 123 const GURL& referrer_url, |
| 124 const GURL& site_instance_url, |
123 const GURL& tab_url, | 125 const GURL& tab_url, |
124 const GURL& tab_refererr_url, | 126 const GURL& tab_refererr_url, |
125 const std::string& mime_type, | 127 const std::string& mime_type, |
126 const std::string& original_mime_type, | 128 const std::string& original_mime_type, |
127 const base::Time& start_time, | 129 const base::Time& start_time, |
128 const base::Time& end_time, | 130 const base::Time& end_time, |
129 const std::string& etag, | 131 const std::string& etag, |
130 const std::string& last_modified, | 132 const std::string& last_modified, |
131 int64_t received_bytes, | 133 int64_t received_bytes, |
132 int64_t total_bytes, | 134 int64_t total_bytes, |
133 const std::string& hash, | 135 const std::string& hash, |
134 DownloadItem::DownloadState state, | 136 DownloadItem::DownloadState state, |
135 DownloadDangerType danger_type, | 137 DownloadDangerType danger_type, |
136 DownloadInterruptReason interrupt_reason, | 138 DownloadInterruptReason interrupt_reason, |
137 bool opened, | 139 bool opened, |
138 const net::BoundNetLog& bound_net_log) override { | 140 const net::BoundNetLog& bound_net_log) override { |
139 return new DownloadItemImpl( | 141 return new DownloadItemImpl( |
140 delegate, guid, download_id, current_path, target_path, url_chain, | 142 delegate, guid, download_id, current_path, target_path, url_chain, |
141 referrer_url, tab_url, tab_refererr_url, mime_type, original_mime_type, | 143 referrer_url, site_instance_url, tab_url, tab_refererr_url, mime_type, |
142 start_time, end_time, etag, last_modified, received_bytes, total_bytes, | 144 original_mime_type, start_time, end_time, etag, last_modified, |
143 hash, state, danger_type, interrupt_reason, opened, bound_net_log); | 145 received_bytes, total_bytes, hash, state, danger_type, interrupt_reason, |
| 146 opened, bound_net_log); |
144 } | 147 } |
145 | 148 |
146 DownloadItemImpl* CreateActiveItem( | 149 DownloadItemImpl* CreateActiveItem( |
147 DownloadItemImplDelegate* delegate, | 150 DownloadItemImplDelegate* delegate, |
148 uint32_t download_id, | 151 uint32_t download_id, |
149 const DownloadCreateInfo& info, | 152 const DownloadCreateInfo& info, |
150 const net::BoundNetLog& bound_net_log) override { | 153 const net::BoundNetLog& bound_net_log) override { |
151 return new DownloadItemImpl(delegate, download_id, info, bound_net_log); | 154 return new DownloadItemImpl(delegate, download_id, info, bound_net_log); |
152 } | 155 } |
153 | 156 |
(...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
463 | 466 |
464 // Resume a download of a specific URL. We send the request to the | 467 // Resume a download of a specific URL. We send the request to the |
465 // ResourceDispatcherHost, and let it send us responses like a regular | 468 // ResourceDispatcherHost, and let it send us responses like a regular |
466 // download. | 469 // download. |
467 void DownloadManagerImpl::ResumeInterruptedDownload( | 470 void DownloadManagerImpl::ResumeInterruptedDownload( |
468 std::unique_ptr<content::DownloadUrlParameters> params, | 471 std::unique_ptr<content::DownloadUrlParameters> params, |
469 uint32_t id) { | 472 uint32_t id) { |
470 RecordDownloadSource(INITIATED_BY_RESUMPTION); | 473 RecordDownloadSource(INITIATED_BY_RESUMPTION); |
471 BrowserThread::PostTaskAndReplyWithResult( | 474 BrowserThread::PostTaskAndReplyWithResult( |
472 BrowserThread::IO, FROM_HERE, | 475 BrowserThread::IO, FROM_HERE, |
473 base::Bind(&BeginDownload, base::Passed(¶ms), id, | 476 base::Bind(&BeginDownload, base::Passed(¶ms), |
| 477 browser_context_->GetResourceContext(), id, |
474 weak_factory_.GetWeakPtr()), | 478 weak_factory_.GetWeakPtr()), |
475 base::Bind(&DownloadManagerImpl::AddUrlDownloader, | 479 base::Bind(&DownloadManagerImpl::AddUrlDownloader, |
476 weak_factory_.GetWeakPtr())); | 480 weak_factory_.GetWeakPtr())); |
477 } | 481 } |
478 | 482 |
479 void DownloadManagerImpl::SetDownloadItemFactoryForTesting( | 483 void DownloadManagerImpl::SetDownloadItemFactoryForTesting( |
480 std::unique_ptr<DownloadItemFactory> item_factory) { | 484 std::unique_ptr<DownloadItemFactory> item_factory) { |
481 item_factory_ = std::move(item_factory); | 485 item_factory_ = std::move(item_factory); |
482 } | 486 } |
483 | 487 |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
577 void DownloadManagerImpl::DownloadUrl( | 581 void DownloadManagerImpl::DownloadUrl( |
578 std::unique_ptr<DownloadUrlParameters> params) { | 582 std::unique_ptr<DownloadUrlParameters> params) { |
579 if (params->post_id() >= 0) { | 583 if (params->post_id() >= 0) { |
580 // Check this here so that the traceback is more useful. | 584 // Check this here so that the traceback is more useful. |
581 DCHECK(params->prefer_cache()); | 585 DCHECK(params->prefer_cache()); |
582 DCHECK_EQ("POST", params->method()); | 586 DCHECK_EQ("POST", params->method()); |
583 } | 587 } |
584 BrowserThread::PostTaskAndReplyWithResult( | 588 BrowserThread::PostTaskAndReplyWithResult( |
585 BrowserThread::IO, FROM_HERE, | 589 BrowserThread::IO, FROM_HERE, |
586 base::Bind(&BeginDownload, base::Passed(¶ms), | 590 base::Bind(&BeginDownload, base::Passed(¶ms), |
| 591 browser_context_->GetResourceContext(), |
587 content::DownloadItem::kInvalidId, weak_factory_.GetWeakPtr()), | 592 content::DownloadItem::kInvalidId, weak_factory_.GetWeakPtr()), |
588 base::Bind(&DownloadManagerImpl::AddUrlDownloader, | 593 base::Bind(&DownloadManagerImpl::AddUrlDownloader, |
589 weak_factory_.GetWeakPtr())); | 594 weak_factory_.GetWeakPtr())); |
590 } | 595 } |
591 | 596 |
592 void DownloadManagerImpl::AddObserver(Observer* observer) { | 597 void DownloadManagerImpl::AddObserver(Observer* observer) { |
593 observers_.AddObserver(observer); | 598 observers_.AddObserver(observer); |
594 } | 599 } |
595 | 600 |
596 void DownloadManagerImpl::RemoveObserver(Observer* observer) { | 601 void DownloadManagerImpl::RemoveObserver(Observer* observer) { |
597 observers_.RemoveObserver(observer); | 602 observers_.RemoveObserver(observer); |
598 } | 603 } |
599 | 604 |
600 DownloadItem* DownloadManagerImpl::CreateDownloadItem( | 605 DownloadItem* DownloadManagerImpl::CreateDownloadItem( |
601 const std::string& guid, | 606 const std::string& guid, |
602 uint32_t id, | 607 uint32_t id, |
603 const base::FilePath& current_path, | 608 const base::FilePath& current_path, |
604 const base::FilePath& target_path, | 609 const base::FilePath& target_path, |
605 const std::vector<GURL>& url_chain, | 610 const std::vector<GURL>& url_chain, |
606 const GURL& referrer_url, | 611 const GURL& referrer_url, |
| 612 const GURL& site_instance_url, |
607 const GURL& tab_url, | 613 const GURL& tab_url, |
608 const GURL& tab_refererr_url, | 614 const GURL& tab_refererr_url, |
609 const std::string& mime_type, | 615 const std::string& mime_type, |
610 const std::string& original_mime_type, | 616 const std::string& original_mime_type, |
611 const base::Time& start_time, | 617 const base::Time& start_time, |
612 const base::Time& end_time, | 618 const base::Time& end_time, |
613 const std::string& etag, | 619 const std::string& etag, |
614 const std::string& last_modified, | 620 const std::string& last_modified, |
615 int64_t received_bytes, | 621 int64_t received_bytes, |
616 int64_t total_bytes, | 622 int64_t total_bytes, |
617 const std::string& hash, | 623 const std::string& hash, |
618 DownloadItem::DownloadState state, | 624 DownloadItem::DownloadState state, |
619 DownloadDangerType danger_type, | 625 DownloadDangerType danger_type, |
620 DownloadInterruptReason interrupt_reason, | 626 DownloadInterruptReason interrupt_reason, |
621 bool opened) { | 627 bool opened) { |
622 if (ContainsKey(downloads_, id)) { | 628 if (ContainsKey(downloads_, id)) { |
623 NOTREACHED(); | 629 NOTREACHED(); |
624 return NULL; | 630 return NULL; |
625 } | 631 } |
626 DCHECK(!ContainsKey(downloads_by_guid_, guid)); | 632 DCHECK(!ContainsKey(downloads_by_guid_, guid)); |
627 DownloadItemImpl* item = item_factory_->CreatePersistedItem( | 633 DownloadItemImpl* item = item_factory_->CreatePersistedItem( |
628 this, guid, id, current_path, target_path, url_chain, referrer_url, | 634 this, guid, id, current_path, target_path, url_chain, referrer_url, |
629 tab_url, tab_refererr_url, mime_type, original_mime_type, start_time, | 635 site_instance_url, tab_url, tab_refererr_url, mime_type, |
630 end_time, etag, last_modified, received_bytes, total_bytes, hash, state, | 636 original_mime_type, start_time, end_time, etag, last_modified, |
631 danger_type, interrupt_reason, opened, | 637 received_bytes, total_bytes, hash, state, danger_type, interrupt_reason, |
632 net::BoundNetLog::Make(net_log_, net::NetLog::SOURCE_DOWNLOAD)); | 638 opened, net::BoundNetLog::Make(net_log_, net::NetLog::SOURCE_DOWNLOAD)); |
633 downloads_[id] = item; | 639 downloads_[id] = item; |
634 downloads_by_guid_[guid] = item; | 640 downloads_by_guid_[guid] = item; |
635 FOR_EACH_OBSERVER(Observer, observers_, OnDownloadCreated(this, item)); | 641 FOR_EACH_OBSERVER(Observer, observers_, OnDownloadCreated(this, item)); |
636 DVLOG(20) << __FUNCTION__ << "() download = " << item->DebugString(true); | 642 DVLOG(20) << __FUNCTION__ << "() download = " << item->DebugString(true); |
637 return item; | 643 return item; |
638 } | 644 } |
639 | 645 |
640 int DownloadManagerImpl::InProgressCount() const { | 646 int DownloadManagerImpl::InProgressCount() const { |
641 int count = 0; | 647 int count = 0; |
642 for (const auto& it : downloads_) { | 648 for (const auto& it : downloads_) { |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
691 if (delegate_) | 697 if (delegate_) |
692 delegate_->OpenDownload(download); | 698 delegate_->OpenDownload(download); |
693 } | 699 } |
694 | 700 |
695 void DownloadManagerImpl::ShowDownloadInShell(DownloadItemImpl* download) { | 701 void DownloadManagerImpl::ShowDownloadInShell(DownloadItemImpl* download) { |
696 if (delegate_) | 702 if (delegate_) |
697 delegate_->ShowDownloadInShell(download); | 703 delegate_->ShowDownloadInShell(download); |
698 } | 704 } |
699 | 705 |
700 } // namespace content | 706 } // namespace content |
OLD | NEW |