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

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

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

Powered by Google App Engine
This is Rietveld 408576698