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 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
113 const std::vector<GURL>& url_chain, | 113 const std::vector<GURL>& url_chain, |
114 const GURL& referrer_url, | 114 const GURL& referrer_url, |
115 const std::string& mime_type, | 115 const std::string& mime_type, |
116 const std::string& original_mime_type, | 116 const std::string& original_mime_type, |
117 const base::Time& start_time, | 117 const base::Time& start_time, |
118 const base::Time& end_time, | 118 const base::Time& end_time, |
119 const std::string& etag, | 119 const std::string& etag, |
120 const std::string& last_modified, | 120 const std::string& last_modified, |
121 int64_t received_bytes, | 121 int64_t received_bytes, |
122 int64_t total_bytes, | 122 int64_t total_bytes, |
| 123 const std::string& hash, |
123 DownloadItem::DownloadState state, | 124 DownloadItem::DownloadState state, |
124 DownloadDangerType danger_type, | 125 DownloadDangerType danger_type, |
125 DownloadInterruptReason interrupt_reason, | 126 DownloadInterruptReason interrupt_reason, |
126 bool opened, | 127 bool opened, |
127 const net::BoundNetLog& bound_net_log) override { | 128 const net::BoundNetLog& bound_net_log) override { |
128 return new DownloadItemImpl(delegate, | 129 return new DownloadItemImpl(delegate, |
129 guid, | 130 guid, |
130 download_id, | 131 download_id, |
131 current_path, | 132 current_path, |
132 target_path, | 133 target_path, |
133 url_chain, | 134 url_chain, |
134 referrer_url, | 135 referrer_url, |
135 mime_type, | 136 mime_type, |
136 original_mime_type, | 137 original_mime_type, |
137 start_time, | 138 start_time, |
138 end_time, | 139 end_time, |
139 etag, | 140 etag, |
140 last_modified, | 141 last_modified, |
141 received_bytes, | 142 received_bytes, |
142 total_bytes, | 143 total_bytes, |
| 144 hash, |
143 state, | 145 state, |
144 danger_type, | 146 danger_type, |
145 interrupt_reason, | 147 interrupt_reason, |
146 opened, | 148 opened, |
147 bound_net_log); | 149 bound_net_log); |
148 } | 150 } |
149 | 151 |
150 DownloadItemImpl* CreateActiveItem( | 152 DownloadItemImpl* CreateActiveItem( |
151 DownloadItemImplDelegate* delegate, | 153 DownloadItemImplDelegate* delegate, |
152 uint32_t download_id, | 154 uint32_t download_id, |
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
357 base::FilePath website_save_directory; // Unused | 359 base::FilePath website_save_directory; // Unused |
358 bool skip_dir_check = false; // Unused | 360 bool skip_dir_check = false; // Unused |
359 delegate_->GetSaveDir(GetBrowserContext(), &website_save_directory, | 361 delegate_->GetSaveDir(GetBrowserContext(), &website_save_directory, |
360 &default_download_directory, &skip_dir_check); | 362 &default_download_directory, &skip_dir_check); |
361 } | 363 } |
362 | 364 |
363 scoped_ptr<DownloadFile> download_file; | 365 scoped_ptr<DownloadFile> download_file; |
364 | 366 |
365 if (info->result == DOWNLOAD_INTERRUPT_REASON_NONE) { | 367 if (info->result == DOWNLOAD_INTERRUPT_REASON_NONE) { |
366 DCHECK(stream.get()); | 368 DCHECK(stream.get()); |
367 download_file.reset(file_factory_->CreateFile( | 369 download_file.reset( |
368 *info->save_info, default_download_directory, info->url(), | 370 file_factory_->CreateFile(std::move(info->save_info), |
369 info->referrer_url, delegate_ && delegate_->GenerateFileHash(), | 371 default_download_directory, |
370 std::move(info->save_info->file), std::move(stream), | 372 std::move(stream), |
371 download->GetBoundNetLog(), download->DestinationObserverAsWeakPtr())); | 373 download->GetBoundNetLog(), |
372 | 374 download->DestinationObserverAsWeakPtr())); |
373 if (download_file.get() && delegate_) { | |
374 download_file->SetClientGuid( | |
375 delegate_->ApplicationClientIdForFileScanning()); | |
376 } | |
377 } | 375 } |
| 376 // It is important to leave info->save_info intact in the case of an interrupt |
| 377 // so that the DownloadItem can salvage what it can out of a failed resumption |
| 378 // attempt. |
378 | 379 |
379 download->Start(std::move(download_file), std::move(info->request_handle), | 380 download->Start(std::move(download_file), std::move(info->request_handle), |
380 *info); | 381 *info); |
381 | 382 |
382 // For interrupted downloads, Start() will transition the state to | 383 // For interrupted downloads, Start() will transition the state to |
383 // IN_PROGRESS and consumers will be notified via OnDownloadUpdated(). | 384 // IN_PROGRESS and consumers will be notified via OnDownloadUpdated(). |
384 // For new downloads, we notify here, rather than earlier, so that | 385 // For new downloads, we notify here, rather than earlier, so that |
385 // the download_file is bound to download and all the usual | 386 // the download_file is bound to download and all the usual |
386 // setters (e.g. Cancel) work. | 387 // setters (e.g. Cancel) work. |
387 if (new_download) | 388 if (new_download) |
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
610 const std::vector<GURL>& url_chain, | 611 const std::vector<GURL>& url_chain, |
611 const GURL& referrer_url, | 612 const GURL& referrer_url, |
612 const std::string& mime_type, | 613 const std::string& mime_type, |
613 const std::string& original_mime_type, | 614 const std::string& original_mime_type, |
614 const base::Time& start_time, | 615 const base::Time& start_time, |
615 const base::Time& end_time, | 616 const base::Time& end_time, |
616 const std::string& etag, | 617 const std::string& etag, |
617 const std::string& last_modified, | 618 const std::string& last_modified, |
618 int64_t received_bytes, | 619 int64_t received_bytes, |
619 int64_t total_bytes, | 620 int64_t total_bytes, |
| 621 const std::string& hash, |
620 DownloadItem::DownloadState state, | 622 DownloadItem::DownloadState state, |
621 DownloadDangerType danger_type, | 623 DownloadDangerType danger_type, |
622 DownloadInterruptReason interrupt_reason, | 624 DownloadInterruptReason interrupt_reason, |
623 bool opened) { | 625 bool opened) { |
624 if (ContainsKey(downloads_, id)) { | 626 if (ContainsKey(downloads_, id)) { |
625 NOTREACHED(); | 627 NOTREACHED(); |
626 return NULL; | 628 return NULL; |
627 } | 629 } |
628 DCHECK(!ContainsKey(downloads_by_guid_, guid)); | 630 DCHECK(!ContainsKey(downloads_by_guid_, guid)); |
629 DownloadItemImpl* item = item_factory_->CreatePersistedItem( | 631 DownloadItemImpl* item = item_factory_->CreatePersistedItem( |
630 this, | 632 this, |
631 guid, | 633 guid, |
632 id, | 634 id, |
633 current_path, | 635 current_path, |
634 target_path, | 636 target_path, |
635 url_chain, | 637 url_chain, |
636 referrer_url, | 638 referrer_url, |
637 mime_type, | 639 mime_type, |
638 original_mime_type, | 640 original_mime_type, |
639 start_time, | 641 start_time, |
640 end_time, | 642 end_time, |
641 etag, | 643 etag, |
642 last_modified, | 644 last_modified, |
643 received_bytes, | 645 received_bytes, |
644 total_bytes, | 646 total_bytes, |
| 647 hash, |
645 state, | 648 state, |
646 danger_type, | 649 danger_type, |
647 interrupt_reason, | 650 interrupt_reason, |
648 opened, | 651 opened, |
649 net::BoundNetLog::Make(net_log_, net::NetLog::SOURCE_DOWNLOAD)); | 652 net::BoundNetLog::Make(net_log_, net::NetLog::SOURCE_DOWNLOAD)); |
650 downloads_[id] = item; | 653 downloads_[id] = item; |
651 downloads_by_guid_[guid] = item; | 654 downloads_by_guid_[guid] = item; |
652 FOR_EACH_OBSERVER(Observer, observers_, OnDownloadCreated(this, item)); | 655 FOR_EACH_OBSERVER(Observer, observers_, OnDownloadCreated(this, item)); |
653 DVLOG(20) << __FUNCTION__ << "() download = " << item->DebugString(true); | 656 DVLOG(20) << __FUNCTION__ << "() download = " << item->DebugString(true); |
654 return item; | 657 return item; |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
708 if (delegate_) | 711 if (delegate_) |
709 delegate_->OpenDownload(download); | 712 delegate_->OpenDownload(download); |
710 } | 713 } |
711 | 714 |
712 void DownloadManagerImpl::ShowDownloadInShell(DownloadItemImpl* download) { | 715 void DownloadManagerImpl::ShowDownloadInShell(DownloadItemImpl* download) { |
713 if (delegate_) | 716 if (delegate_) |
714 delegate_->ShowDownloadInShell(download); | 717 delegate_->ShowDownloadInShell(download); |
715 } | 718 } |
716 | 719 |
717 } // namespace content | 720 } // namespace content |
OLD | NEW |